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;
import co.aikar.commands.BaseCommand;
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.LiteralArgument;
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 org.bukkit.entity.Player;
@CommandAlias("spych|spychannel|spy")
@CommandPermission("carbonchat.spy")
public class SpyChannelCommand extends BaseCommand {
import java.util.LinkedHashMap;
import java.util.List;
@Dependency
private CarbonChat carbonChat;
public class SpyChannelCommand {
@Default
@CommandCompletion("@channel @nothing")
@Syntax("<channel>")
public void baseCommand(Player player, @Conditions("exists:true") ChatChannel channel) {
private final CarbonChat carbonChat;
public SpyChannelCommand(CarbonChat carbonChat) {
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);
String message;
UserChannelSettings settings = user.getChannelSettings(channel);
UserChannelSettings settings = user.getChannelSettings(chatChannel);
if (settings.isSpying()) {
settings.setSpying(false);
@@ -34,11 +62,10 @@ public class SpyChannelCommand extends BaseCommand {
}
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")
public void whispersCommand(Player player) {
private void executeWhispers(Player player, Object[] args) {
ChatUser user = carbonChat.getUserService().wrap(player);
String message;
@@ -93,7 +93,7 @@ public class CommandManager {
new ReplyCommand(carbonChat);
new SetColorCommand(carbonChat);
new ShadowMuteCommand(carbonChat);
this.commandManager.registerCommand(new SpyChannelCommand());
new SpyChannelCommand(carbonChat);
this.commandManager.registerCommand(new ToggleCommand());
}
@@ -24,6 +24,7 @@ import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.CustomArgument;
import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.kyori.adventure.platform.bukkit.MinecraftComponentSerializer;
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.TextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -158,4 +160,32 @@ public final class CarbonUtils {
}).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.");
}
}