Bungee and refactoring

This commit is contained in:
Draycia committed 2020-06-24 01:24:40 -07:00
1 parent 707556d9f9
commit 5eefb5dda8
14 files changed
+997 -675

No files matched your search

@@ -0,0 +1,61 @@
package net.draycia.simplechat.managers;
import co.aikar.commands.BukkitCommandManager;
import co.aikar.commands.ConditionFailedException;
import net.draycia.simplechat.SimpleChat;
import net.draycia.simplechat.channels.ChatChannel;
import net.draycia.simplechat.commands.ChannelCommand;
import net.draycia.simplechat.commands.IgnoreCommand;
import net.draycia.simplechat.commands.ToggleCommand;
import java.util.ArrayList;
public class CommandManager {
private SimpleChat simpleChat;
public CommandManager(SimpleChat simpleChat) {
this.simpleChat = simpleChat;
BukkitCommandManager manager = new BukkitCommandManager(simpleChat);
manager.getCommandCompletions().registerCompletion("chatchannel", (context) -> {
ArrayList<String> completions = new ArrayList<>();
for (ChatChannel chatChannel : simpleChat.getChannels()) {
if (chatChannel.canPlayerUse(context.getPlayer())) {
completions.add(chatChannel.getName());
}
}
return completions;
});
manager.getCommandContexts().registerContext(ChatChannel.class, (context) -> {
String name = context.popFirstArg();
for (ChatChannel chatChannel : simpleChat.getChannels()) {
if (chatChannel.getName().equalsIgnoreCase(name)) {
return chatChannel;
}
}
return null;
});
manager.getCommandConditions().addCondition(ChatChannel.class,"canuse", (context, execution, value) -> {
if (!value.canPlayerUse(context.getIssuer().getPlayer())) {
throw new ConditionFailedException("You cannot use that channel!");
}
});
setupCommands(manager);
}
private void setupCommands(BukkitCommandManager manager) {
manager.registerCommand(new ToggleCommand(simpleChat));
manager.registerCommand(new ChannelCommand(simpleChat));
manager.registerCommand(new IgnoreCommand(simpleChat));
}
}