This commit is contained in:
Draycia committed 2020-08-26 05:28:29 -07:00
1 parent 207eee3576
commit 71b4de471d
5 files changed
+66 -34

No files matched your search

@@ -1,7 +1,7 @@
package net.draycia.carbon.commands;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import net.draycia.carbon.CarbonChat;
@@ -12,8 +12,6 @@ import org.bukkit.entity.Player;
import java.util.LinkedHashMap;
import java.util.List;
@CommandAlias("reply|r")
@CommandPermission("carbonchat.reply")
public class ReplyCommand {
private final CarbonChat carbonChat;
@@ -30,6 +28,7 @@ public class ReplyCommand {
new CommandAPICommand(commandName)
.withArguments(arguments)
.withAliases(commandAliases.toArray(new String[0]))
.withPermission(CommandPermission.fromString("carbonchat.reply"))
.executesPlayer(this::execute)
.register();
}
@@ -1,44 +1,72 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.ConditionFailedException;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
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.UserChannelSettings;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.entity.Player;
@CommandAlias("setcolor|setcolour")
@CommandPermission("carbonchat.setcolor")
public class SetColorCommand extends BaseCommand {
import java.util.LinkedHashMap;
import java.util.List;
@Dependency
private CarbonChat carbonChat;
public class SetColorCommand {
@Default
@CommandCompletion("@chatchannel @nothing")
@Syntax("<channel> <color>")
public void baseCommand(Player player, @Conditions("canuse:true") ChatChannel channel, String input) {
if (channel == null || input == null) {
throw new ConditionFailedException("Channel or Color not supplied!");
private final CarbonChat carbonChat;
public SetColorCommand(CarbonChat carbonChat) {
this.carbonChat = carbonChat;
String commandName = carbonChat.getConfig().getString("commands.setcolor.name", "setcolor");
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.setcolor.aliases");
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
arguments.put("channel", new LiteralArgument(channel.getKey()));
arguments.put("color", new StringArgument());
new CommandAPICommand(commandName)
.withArguments(arguments)
.withAliases(commandAliases.toArray(new String[0]))
.withPermission(CommandPermission.fromString("carbonchat.setcolor"))
.executesPlayer((player, args) -> {
String colorInput = (String) args[1];
ChatUser user = carbonChat.getUserService().wrap(player);
if (!player.hasPermission("carbonchat.setcolor." + channel.getKey())) {
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
carbonChat.getLanguage().getString("cannot-set-color"),
"br", "\n", "input", colorInput,
"channel", channel.getName()));
return;
}
UserChannelSettings settings = user.getChannelSettings(channel);
TextColor color = CarbonUtils.parseColor(user, colorInput);
if (color == null) {
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
carbonChat.getLanguage().getString("invalid-color"),
"br", "\n", "input", colorInput,
"channel", channel.getName()));
return;
}
settings.setColor(color);
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
carbonChat.getLanguage().getString("channel-color-set"),
"br", "\n", "color", "<color:" + color.asHexString() + ">", "channel",
channel.getName(), "hex", color.asHexString()));
})
.register();
}
ChatUser user = carbonChat.getUserService().wrap(player);
if (!player.hasPermission("carbonchat.setcolor." + channel.getKey())) {
throw new ConditionFailedException("You can't set colors for this channel!");
}
UserChannelSettings settings = user.getChannelSettings(channel);
TextColor color = CarbonUtils.parseColor(user, input);
settings.setColor(color);
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, carbonChat.getLanguage().getString("channel-color-set"),
"br", "\n", "color", "<color:" + color.asHexString() + ">", "channel", channel.getName(), "hex", color.asHexString()));
}
}
@@ -90,7 +90,7 @@ public class CommandManager {
this.commandManager.registerCommand(new MessageCommand());
this.commandManager.registerCommand(new NicknameCommand());
new ReplyCommand(carbonChat);
this.commandManager.registerCommand(new SetColorCommand());
new SetColorCommand(carbonChat);
this.commandManager.registerCommand(new SpyChannelCommand());
this.commandManager.registerCommand(new ClearChatCommand());