This commit is contained in:
Draycia committed 2020-08-27 05:08:13 -07:00
1 parent 570edcffc0
commit 9a450e6c22
4 files changed
+77 -17

No files matched your search

@@ -1,29 +1,57 @@
package net.draycia.carbon.commands; package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand; import dev.jorel.commandapi.CommandAPICommand;
import co.aikar.commands.annotation.*; import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.LiteralArgument;
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 org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandAlias("spych|spychannel|spy") import java.util.LinkedHashMap;
@CommandPermission("carbonchat.spy") import java.util.List;
public class SpyChannelCommand extends BaseCommand {
@Dependency public class SpyChannelCommand {
private CarbonChat carbonChat;
@Default private final CarbonChat carbonChat;
@CommandCompletion("@channel @nothing")
@Syntax("<channel>") public SpyChannelCommand(CarbonChat carbonChat) {
public void baseCommand(Player player, @Conditions("exists:true") ChatChannel channel) { this.carbonChat = carbonChat;
String commandName = carbonChat.getConfig().getString("commands.spy.name", "spy");
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.spy.aliases");
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
channelArguments.put("channel", CarbonUtils.channelArgument());
new CommandAPICommand(commandName)
.withArguments(channelArguments)
.withAliases(commandAliases.toArray(new String[0]))
.withPermission(CommandPermission.fromString("carbonchat.spy"))
.executesPlayer(this::execute)
.register();
LinkedHashMap<String, Argument> whisperArguments = new LinkedHashMap<>();
whisperArguments.put("channel", new LiteralArgument("whispers"));
new CommandAPICommand(commandName)
.withArguments(whisperArguments)
.withAliases(commandAliases.toArray(new String[0]))
.withPermission(CommandPermission.fromString("carbonchat.spy"))
.executesPlayer(this::executeWhispers)
.register();
}
private void execute(Player player, Object[] args) {
ChatChannel chatChannel = (ChatChannel) args[0];
ChatUser user = carbonChat.getUserService().wrap(player); ChatUser user = carbonChat.getUserService().wrap(player);
String message; String message;
UserChannelSettings settings = user.getChannelSettings(channel); UserChannelSettings settings = user.getChannelSettings(chatChannel);
if (settings.isSpying()) { if (settings.isSpying()) {
settings.setSpying(false); settings.setSpying(false);
@@ -34,11 +62,10 @@ public class SpyChannelCommand extends BaseCommand {
} }
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n", user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName())); "color", "<color:" + chatChannel.getChannelColor(user).toString() + ">", "channel", chatChannel.getName()));
} }
@Subcommand("whispers") private void executeWhispers(Player player, Object[] args) {
public void whispersCommand(Player player) {
ChatUser user = carbonChat.getUserService().wrap(player); ChatUser user = carbonChat.getUserService().wrap(player);
String message; String message;
@@ -93,7 +93,7 @@ public class CommandManager {
new ReplyCommand(carbonChat); new ReplyCommand(carbonChat);
new SetColorCommand(carbonChat); new SetColorCommand(carbonChat);
new ShadowMuteCommand(carbonChat); new ShadowMuteCommand(carbonChat);
this.commandManager.registerCommand(new SpyChannelCommand()); new SpyChannelCommand(carbonChat);
this.commandManager.registerCommand(new ToggleCommand()); this.commandManager.registerCommand(new ToggleCommand());
} }
@@ -24,6 +24,7 @@ import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.CustomArgument; import dev.jorel.commandapi.arguments.CustomArgument;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.carbon.CarbonChat; import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser; import net.draycia.carbon.storage.ChatUser;
import net.kyori.adventure.platform.bukkit.MinecraftComponentSerializer; import net.kyori.adventure.platform.bukkit.MinecraftComponentSerializer;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@@ -31,6 +32,7 @@ import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -158,4 +160,32 @@ public final class CarbonUtils {
}).overrideSuggestions(colors); }).overrideSuggestions(colors);
} }
public static Argument channelArgument() {
return new CustomArgument<>((input) -> {
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(input);
if (channel == null) {
throw new CustomArgument.CustomArgumentException("Invalid channel for input (" + input + ")");
}
return channel;
}).overrideSuggestions((sender, args) -> {
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
ArrayList<String> channels = new ArrayList<>();
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
channels.add(channel.getKey());
}
return channels.toArray(new String[0]);
});
}
public static Argument usableChannelArgument() {
throw new NotImplementedException("Not implemented yet.");
}
} }
+4 -1
View File
@@ -164,4 +164,7 @@ commands:
aliases: ['m'] aliases: ['m']
clearchat: clearchat:
name: 'clearchat' name: 'clearchat'
aliases: ['clear', 'cc'] aliases: ['clear', 'cc']
spy:
name: 'spy'
aliases: ['spych', 'spychannel']