mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
Add ChannelSettings, allow commands to be disabled
This commit is contained in:
1 parent
349fa385e8
commit
addef98b8e
20 files changed
+255
-159
No files matched your search
@@ -39,6 +39,7 @@ public final class CarbonChat extends JavaPlugin {
|
||||
|
||||
private YamlConfiguration modConfig;
|
||||
private YamlConfiguration languageConfig;
|
||||
private YamlConfiguration commandsConfig;
|
||||
|
||||
public static final LegacyComponentSerializer LEGACY =
|
||||
LegacyComponentSerializer.builder()
|
||||
@@ -65,6 +66,10 @@ public final class CarbonChat extends JavaPlugin {
|
||||
saveResource("language.yml", false);
|
||||
}
|
||||
|
||||
if (!(new File(getDataFolder(), "commands.yml").exists())) {
|
||||
saveResource("commands.yml", false);
|
||||
}
|
||||
|
||||
loadModConfig();
|
||||
loadLanguage();
|
||||
|
||||
@@ -149,6 +154,7 @@ public final class CarbonChat extends JavaPlugin {
|
||||
|
||||
loadModConfig();
|
||||
loadLanguage();
|
||||
loadCommandsConfig();
|
||||
}
|
||||
|
||||
private void loadModConfig() {
|
||||
@@ -159,6 +165,10 @@ public final class CarbonChat extends JavaPlugin {
|
||||
languageConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "language.yml"));
|
||||
}
|
||||
|
||||
private void loadCommandsConfig() {
|
||||
commandsConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "commands.yml"));
|
||||
}
|
||||
|
||||
private void registerContexts() {
|
||||
getContextManager().register("distance", new DistanceContext());
|
||||
}
|
||||
@@ -167,6 +177,10 @@ public final class CarbonChat extends JavaPlugin {
|
||||
return modConfig;
|
||||
}
|
||||
|
||||
public YamlConfiguration getCommandsConfig() {
|
||||
return commandsConfig;
|
||||
}
|
||||
|
||||
public YamlConfiguration getLanguage() {
|
||||
return languageConfig;
|
||||
}
|
||||
|
||||
@@ -7,29 +7,30 @@ import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ChannelCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelCommand(CarbonChat carbonChat) {
|
||||
public ChannelCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.channel.name", "channel");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.channel.aliases");
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
||||
setChannelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(setChannelArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel"))
|
||||
.executesPlayer(this::setChannel)
|
||||
.register();
|
||||
@@ -38,9 +39,9 @@ public class ChannelCommand {
|
||||
sendMessageArguments.put("channel", CarbonUtils.channelArgument());
|
||||
sendMessageArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(sendMessageArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
|
||||
.executesPlayer(this::sendMessage)
|
||||
.register();
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.jorel.commandapi.arguments.Argument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -23,17 +24,18 @@ public class ChannelListCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelListCommand(CarbonChat carbonChat) {
|
||||
public ChannelListCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.channellist.name", "channellist");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.channellist.aliases");
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channellist"))
|
||||
.executesPlayer(this::executeSelf)
|
||||
.register();
|
||||
@@ -41,9 +43,9 @@ public class ChannelListCommand {
|
||||
LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
||||
argumentsOther.put("player", CarbonUtils.onlineChatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(argumentsOther)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channellist.other"))
|
||||
.executes(this::executeOther)
|
||||
.register();
|
||||
@@ -92,7 +94,7 @@ public class ChannelListCommand {
|
||||
|
||||
String availableFormat = carbonChat.getLanguage().getString("available-channels-list");
|
||||
Component availableComponent = carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
|
||||
availableComponent = ((TextComponent)availableComponent).replaceFirst(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
|
||||
availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
|
||||
|
||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||
|
||||
@@ -107,7 +109,7 @@ public class ChannelListCommand {
|
||||
|
||||
String unavailableFormat = carbonChat.getLanguage().getString("unavailable-channels-list");
|
||||
Component unavailableComponent = carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
|
||||
unavailableComponent = ((TextComponent)unavailableComponent).replaceFirst(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
|
||||
unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
|
||||
|
||||
audience.sendMessage(unavailableComponent);
|
||||
}
|
||||
|
||||
@@ -4,29 +4,30 @@ import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatReloadCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChatReloadCommand(CarbonChat carbonChat) {
|
||||
public ChatReloadCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.reload.name", "chatreload");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.reload.aliases");
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.reload"))
|
||||
.executes(this::execute)
|
||||
.register();
|
||||
|
||||
@@ -5,25 +5,25 @@ import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ClearChatCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ClearChatCommand(CarbonChat carbonChat) {
|
||||
public ClearChatCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.clearchat.name", "clearchat");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.clearchat.aliases");
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.clearchat.clear"))
|
||||
.executes(this::execute)
|
||||
.register();
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
@@ -18,18 +19,19 @@ public class IgnoreCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public IgnoreCommand(CarbonChat carbonChat) {
|
||||
public IgnoreCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.ignore.name", "ignore");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.ignore.aliases");
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.ignore"))
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
|
||||
@@ -7,6 +7,7 @@ import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -18,18 +19,19 @@ public class MeCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MeCommand(CarbonChat carbonChat) {
|
||||
public MeCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.me.name", "me");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.me.aliases");
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.me"))
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -15,18 +16,19 @@ public class MessageCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MessageCommand(CarbonChat carbonChat) {
|
||||
public MessageCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.message.name", "message");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.message.aliases");
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.message"))
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -19,18 +20,19 @@ public class MuteCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MuteCommand(CarbonChat carbonChat) {
|
||||
public MuteCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.mute.name", "mute");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.mute.aliases");
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(arguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.mute"))
|
||||
.executes(this::execute)
|
||||
.register();
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -18,18 +19,19 @@ public class NicknameCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public NicknameCommand(CarbonChat carbonChat) {
|
||||
public NicknameCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.nickname.name", "nickname");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.nickname.aliases");
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> selfArguments = new LinkedHashMap<>();
|
||||
selfArguments.put("nickname", new StringArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(selfArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.nickname"))
|
||||
.executesPlayer(this::executeSelf)
|
||||
.register();
|
||||
@@ -38,9 +40,9 @@ public class NicknameCommand {
|
||||
otherArguments.put("player", CarbonUtils.chatUserArgument());
|
||||
otherArguments.put("nickname", new StringArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(otherArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.nickname.others"))
|
||||
.executes(this::executeOther)
|
||||
.register();
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -16,18 +17,19 @@ public class ReplyCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ReplyCommand(CarbonChat carbonChat) {
|
||||
public ReplyCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("message", new GreedyStringArgument());
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.reply.name", "reply");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.reply.aliases");
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(arguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.reply"))
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.jorel.commandapi.arguments.*;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.storage.UserChannelSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
@@ -17,20 +18,21 @@ public class SetColorCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SetColorCommand(CarbonChat carbonChat) {
|
||||
public SetColorCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.setcolor.name", "setcolor");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.setcolor.aliases");
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
|
||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("channel", new LiteralArgument(channel.getKey()));
|
||||
arguments.put("color", CarbonUtils.textColorArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(arguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.setcolor"))
|
||||
.executesPlayer((player, args) -> {
|
||||
TextColor color = (TextColor)args[1];
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -19,18 +20,19 @@ public class ShadowMuteCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ShadowMuteCommand(CarbonChat carbonChat) {
|
||||
public ShadowMuteCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.shadowmute.name", "shadowmute");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.shadowmute.aliases");
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(arguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.shadowmute"))
|
||||
.executes(this::execute)
|
||||
.register();
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.jorel.commandapi.arguments.LiteralArgument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.storage.UserChannelSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -19,18 +20,19 @@ public class SpyChannelCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SpyChannelCommand(CarbonChat carbonChat) {
|
||||
public SpyChannelCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.spy.name", "spy");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.spy.aliases");
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
@@ -38,9 +40,9 @@ public class SpyChannelCommand {
|
||||
LinkedHashMap<String, Argument> whisperArguments = new LinkedHashMap<>();
|
||||
whisperArguments.put("channel", new LiteralArgument("whispers"));
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(whisperArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
||||
.executesPlayer(this::executeWhispers)
|
||||
.register();
|
||||
@@ -49,9 +51,9 @@ public class SpyChannelCommand {
|
||||
everythingArguments.put("channel", new LiteralArgument("*"));
|
||||
everythingArguments.put("should-spy", new BooleanArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(everythingArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
||||
.executesPlayer(this::executeEverything) // lul
|
||||
.register();
|
||||
|
||||
@@ -7,6 +7,7 @@ import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -18,23 +19,20 @@ public class SudoChannelCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SudoChannelCommand(CarbonChat carbonChat) {
|
||||
public SudoChannelCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!carbonChat.getConfig().getBoolean("commands.sudochannel.enabled")) {
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.sudochannel.name", "sudochannel");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.sudochannel.aliases");
|
||||
|
||||
LinkedHashMap<String, Argument> setOtherChannelArguments = new LinkedHashMap<>();
|
||||
setOtherChannelArguments.put("player", CarbonUtils.onlineChatUserArgument());
|
||||
setOtherChannelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(setOtherChannelArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel.others"))
|
||||
.executes((sender, args) -> { this.setOtherChannel(sender, (ChatUser) args[0], (ChatChannel) args[1]); })
|
||||
.register();
|
||||
@@ -44,9 +42,9 @@ public class SudoChannelCommand {
|
||||
sendMessageOtherArguments.put("channel", CarbonUtils.channelArgument());
|
||||
sendMessageOtherArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(sendMessageOtherArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel.others.message"))
|
||||
.executes((sender, args) -> { this.sendMessageOther(sender, (ChatUser) args[0], (ChatChannel) args[1], (String) args[2]); })
|
||||
.register();
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.jorel.commandapi.arguments.Argument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import net.draycia.carbon.storage.UserChannelSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -18,18 +19,19 @@ public class ToggleCommand {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ToggleCommand(CarbonChat carbonChat) {
|
||||
public ToggleCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.toggle.name", "toggle");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.toggle.aliases");
|
||||
if (!commandSettings.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.toggle"))
|
||||
.executesPlayer(this::executeSelf)
|
||||
.register();
|
||||
@@ -38,9 +40,9 @@ public class ToggleCommand {
|
||||
argumentsOther.put("players", CarbonUtils.chatUserArgument());
|
||||
argumentsOther.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
new CommandAPICommand(commandSettings.getName())
|
||||
.withArguments(argumentsOther)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withAliases(commandSettings.getAliasesArray())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.toggle"))
|
||||
.executes(this::executeOther)
|
||||
.register();
|
||||
|
||||
@@ -2,29 +2,41 @@ package net.draycia.carbon.managers;
|
||||
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.commands.*;
|
||||
import net.draycia.carbon.storage.CommandSettings;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public CommandManager(CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
reloadCommands(carbonChat);
|
||||
}
|
||||
|
||||
public void reloadCommands(CarbonChat carbonChat) {
|
||||
new ChannelCommand(carbonChat);
|
||||
new ChannelListCommand(carbonChat);
|
||||
new ChatReloadCommand(carbonChat);
|
||||
new ClearChatCommand(carbonChat);
|
||||
new IgnoreCommand(carbonChat);
|
||||
new MeCommand(carbonChat);
|
||||
new MessageCommand(carbonChat);
|
||||
new MuteCommand(carbonChat);
|
||||
new NicknameCommand(carbonChat);
|
||||
new ReplyCommand(carbonChat);
|
||||
new SetColorCommand(carbonChat);
|
||||
new ShadowMuteCommand(carbonChat);
|
||||
new SpyChannelCommand(carbonChat);
|
||||
new SudoChannelCommand(carbonChat);
|
||||
new ToggleCommand(carbonChat);
|
||||
new ChannelCommand(carbonChat, getCommandSettings("channel"));
|
||||
new ChannelListCommand(carbonChat, getCommandSettings("channellist"));
|
||||
new ChatReloadCommand(carbonChat, getCommandSettings("chatreload"));
|
||||
new ClearChatCommand(carbonChat, getCommandSettings("clearchat"));
|
||||
new IgnoreCommand(carbonChat, getCommandSettings("ignore"));
|
||||
new MeCommand(carbonChat, getCommandSettings("me"));
|
||||
new MessageCommand(carbonChat, getCommandSettings("message"));
|
||||
new MuteCommand(carbonChat, getCommandSettings("mute"));
|
||||
new NicknameCommand(carbonChat, getCommandSettings("nickname"));
|
||||
new ReplyCommand(carbonChat, getCommandSettings("reply"));
|
||||
new SetColorCommand(carbonChat, getCommandSettings("setcolor"));
|
||||
new ShadowMuteCommand(carbonChat, getCommandSettings("shadowmute"));
|
||||
new SpyChannelCommand(carbonChat, getCommandSettings("spy"));
|
||||
new SudoChannelCommand(carbonChat, getCommandSettings("sudochannel"));
|
||||
new ToggleCommand(carbonChat, getCommandSettings("toggle"));
|
||||
}
|
||||
|
||||
private CommandSettings getCommandSettings(String command) {
|
||||
ConfigurationSection section = carbonChat.getCommandsConfig().getConfigurationSection(command);
|
||||
|
||||
return new CommandSettings(section.getBoolean("enabled"), section.getString("name"),
|
||||
section.getStringList("aliases"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.draycia.carbon.storage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSettings {
|
||||
|
||||
private boolean enabled;
|
||||
private String name;
|
||||
private List<String> aliases;
|
||||
|
||||
public CommandSettings(boolean enabled, String name, List<String> aliases) {
|
||||
this.enabled = enabled;
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
public String[] getAliasesArray() {
|
||||
return aliases.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user