mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
2/15
This commit is contained in:
1 parent
207eee3576
commit
71b4de471d
5 files changed
+65
-33
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
package net.draycia.carbon.commands;
|
package net.draycia.carbon.commands;
|
||||||
|
|
||||||
import co.aikar.commands.annotation.*;
|
|
||||||
import dev.jorel.commandapi.CommandAPICommand;
|
import dev.jorel.commandapi.CommandAPICommand;
|
||||||
|
import dev.jorel.commandapi.CommandPermission;
|
||||||
import dev.jorel.commandapi.arguments.Argument;
|
import dev.jorel.commandapi.arguments.Argument;
|
||||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||||
import net.draycia.carbon.CarbonChat;
|
import net.draycia.carbon.CarbonChat;
|
||||||
@@ -12,8 +12,6 @@ import org.bukkit.entity.Player;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandAlias("reply|r")
|
|
||||||
@CommandPermission("carbonchat.reply")
|
|
||||||
public class ReplyCommand {
|
public class ReplyCommand {
|
||||||
|
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
@@ -30,6 +28,7 @@ public class ReplyCommand {
|
|||||||
new CommandAPICommand(commandName)
|
new CommandAPICommand(commandName)
|
||||||
.withArguments(arguments)
|
.withArguments(arguments)
|
||||||
.withAliases(commandAliases.toArray(new String[0]))
|
.withAliases(commandAliases.toArray(new String[0]))
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.reply"))
|
||||||
.executesPlayer(this::execute)
|
.executesPlayer(this::execute)
|
||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +1,72 @@
|
|||||||
package net.draycia.carbon.commands;
|
package net.draycia.carbon.commands;
|
||||||
|
|
||||||
import co.aikar.commands.BaseCommand;
|
import dev.jorel.commandapi.CommandAPICommand;
|
||||||
import co.aikar.commands.ConditionFailedException;
|
import dev.jorel.commandapi.CommandPermission;
|
||||||
import co.aikar.commands.annotation.*;
|
import dev.jorel.commandapi.arguments.*;
|
||||||
import net.draycia.carbon.CarbonChat;
|
import net.draycia.carbon.CarbonChat;
|
||||||
import net.draycia.carbon.channels.ChatChannel;
|
import net.draycia.carbon.channels.ChatChannel;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
import net.draycia.carbon.storage.UserChannelSettings;
|
import net.draycia.carbon.storage.UserChannelSettings;
|
||||||
import net.draycia.carbon.util.CarbonUtils;
|
import net.draycia.carbon.util.CarbonUtils;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@CommandAlias("setcolor|setcolour")
|
import java.util.LinkedHashMap;
|
||||||
@CommandPermission("carbonchat.setcolor")
|
import java.util.List;
|
||||||
public class SetColorCommand extends BaseCommand {
|
|
||||||
|
|
||||||
@Dependency
|
public class SetColorCommand {
|
||||||
private CarbonChat carbonChat;
|
|
||||||
|
|
||||||
@Default
|
private final CarbonChat carbonChat;
|
||||||
@CommandCompletion("@chatchannel @nothing")
|
|
||||||
@Syntax("<channel> <color>")
|
public SetColorCommand(CarbonChat carbonChat) {
|
||||||
public void baseCommand(Player player, @Conditions("canuse:true") ChatChannel channel, String input) {
|
this.carbonChat = carbonChat;
|
||||||
if (channel == null || input == null) {
|
|
||||||
throw new ConditionFailedException("Channel or Color not supplied!");
|
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 MessageCommand());
|
||||||
this.commandManager.registerCommand(new NicknameCommand());
|
this.commandManager.registerCommand(new NicknameCommand());
|
||||||
new ReplyCommand(carbonChat);
|
new ReplyCommand(carbonChat);
|
||||||
this.commandManager.registerCommand(new SetColorCommand());
|
new SetColorCommand(carbonChat);
|
||||||
this.commandManager.registerCommand(new SpyChannelCommand());
|
this.commandManager.registerCommand(new SpyChannelCommand());
|
||||||
|
|
||||||
this.commandManager.registerCommand(new ClearChatCommand());
|
this.commandManager.registerCommand(new ClearChatCommand());
|
||||||
|
|||||||
@@ -150,3 +150,6 @@ commands:
|
|||||||
reply:
|
reply:
|
||||||
name: 'reply'
|
name: 'reply'
|
||||||
aliases: ['r']
|
aliases: ['r']
|
||||||
|
setcolor:
|
||||||
|
name: 'setcolor'
|
||||||
|
aliases: ['setcolor']
|
||||||
@@ -22,6 +22,8 @@ unavailable-channels-list: '<red>Unavailable Channels:<reset> <list>.'
|
|||||||
channel-list-separator: ', '
|
channel-list-separator: ', '
|
||||||
user-must-be-online: '<red><player> must be online!'
|
user-must-be-online: '<red><player> must be online!'
|
||||||
reply-message-blank: '<red>Your reply message was blank!'
|
reply-message-blank: '<red>Your reply message was blank!'
|
||||||
|
invalid-color: '<red>The input <input> is not a valid color!'
|
||||||
|
cannot-set-color: '<red>You do not have permission to set a color for this channel!'
|
||||||
|
|
||||||
# The following messages are compatible with PlaceholderAPI and MiniMessage/MineDown
|
# The following messages are compatible with PlaceholderAPI and MiniMessage/MineDown
|
||||||
me: '<italic><dark_purple>*<displayname> <reset><message>*</dark_purple></italic>'
|
me: '<italic><dark_purple>*<displayname> <reset><message>*</dark_purple></italic>'
|
||||||
|
|||||||
Reference in new issue
Block a user