Add SudoChannel command

This commit is contained in:
Draycia committed 2020-09-02 23:18:43 -07:00
1 parent c234dfe5e5
commit 349fa385e8
5 files changed
+81 -99

No files matched your search

@@ -8,7 +8,6 @@ import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.LinkedHashMap;
@@ -33,15 +32,6 @@ public class AliasedChannelCommand {
.executesPlayer(this::setChannel)
.register();
// LinkedHashMap<String, Argument> setOtherChannelArguments = new LinkedHashMap<>();
// setOtherChannelArguments.put("player", CarbonUtils.chatUserArgument());
//
// new CommandAPICommand(commandName)
// .withArguments(setOtherChannelArguments)
// .withPermission(dev.jorel.commandapi.CommandPermission.fromString("carbonchat.channel.others"))
// .executes(this::setOtherChannel)
// .register();
LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
sendMessageArguments.put("message", new GreedyStringArgument());
@@ -50,16 +40,6 @@ public class AliasedChannelCommand {
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
.executesPlayer(this::sendMessage)
.register();
// LinkedHashMap<String, Argument> sendMessageOtherArguments = new LinkedHashMap<>();
// sendMessageOtherArguments.put("player", CarbonUtils.onlineChatUserArgument());
// sendMessageOtherArguments.put("message", new GreedyStringArgument());
//
// new CommandAPICommand(commandName)
// .withArguments(sendMessageOtherArguments)
// .withPermission(dev.jorel.commandapi.CommandPermission.fromString("carbonchat.channel.others.message"))
// .executes(this::sendMessageOther)
// .register();
}
private void setChannel(Player player, Object[] args) {
@@ -82,22 +62,6 @@ public class AliasedChannelCommand {
"channel", getChatChannel().getName()));
}
private void setOtherChannel(CommandSender sender, Object[] args) {
ChatUser user = (ChatUser) args[0];
user.setSelectedChannel(getChatChannel());
String message = getChatChannel().getSwitchMessage();
String otherMessage = getChatChannel().getSwitchOtherMessage();
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
"color", "<color:" + getChatChannel().getChannelColor(user).toString() + ">", "channel", getChatChannel().getName()));
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n",
"color", "<color:" + getChatChannel().getChannelColor(user).toString() + ">", "channel", getChatChannel().getName(),
"player", user.asOfflinePlayer().getName()));
}
private void sendMessage(Player player, Object[] args) {
ChatUser user = carbonChat.getUserService().wrap(player);
String message = (String) args[0];
@@ -108,16 +72,6 @@ public class AliasedChannelCommand {
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
}
private void sendMessageOther(CommandSender sender, Object[] args) {
ChatUser user = (ChatUser) args[0];
String message = (String) args[1];
Component component = getChatChannel().sendMessage(user, message, false);
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
}
public ChatChannel getChatChannel() {
return chatChannel;
}
@@ -9,7 +9,6 @@ import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.LinkedHashMap;
@@ -35,17 +34,6 @@ public class ChannelCommand {
.executesPlayer(this::setChannel)
.register();
// LinkedHashMap<String, Argument> setOtherChannelArguments = new LinkedHashMap<>();
// setOtherChannelArguments.put("channel", CarbonUtils.channelArgument());
// setOtherChannelArguments.put("player", CarbonUtils.onlineChatUserArgument());
//
// new CommandAPICommand(commandName)
// .withArguments(setOtherChannelArguments)
// .withAliases(commandAliases.toArray(new String[0]))
// .withPermission(CommandPermission.fromString("carbonchat.channel.others"))
// .executes(this::setOtherChannel)
// .register();
LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
sendMessageArguments.put("channel", CarbonUtils.channelArgument());
sendMessageArguments.put("message", new GreedyStringArgument());
@@ -56,18 +44,6 @@ public class ChannelCommand {
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
.executesPlayer(this::sendMessage)
.register();
// LinkedHashMap<String, Argument> sendMessageOtherArguments = new LinkedHashMap<>();
// sendMessageOtherArguments.put("player", CarbonUtils.onlineChatUserArgument());
// sendMessageOtherArguments.put("channel", CarbonUtils.channelArgument());
// sendMessageOtherArguments.put("message", new GreedyStringArgument());
//
// new CommandAPICommand(commandName)
// .withArguments(sendMessageOtherArguments)
// .withAliases(commandAliases.toArray(new String[0]))
// .withPermission(CommandPermission.fromString("carbonchat.channel.others.message"))
// .executes(this::sendMessageOther)
// .register();
}
private void setChannel(Player player, Object[] args) {
@@ -91,23 +67,6 @@ public class ChannelCommand {
"channel", channel.getName()));
}
private void setOtherChannel(CommandSender sender, Object[] args) {
ChatUser user = (ChatUser) args[0];
ChatChannel channel = (ChatChannel) args[1];
user.setSelectedChannel(channel);
String message = channel.getSwitchMessage();
String otherMessage = channel.getSwitchOtherMessage();
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n",
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName(),
"player", user.asOfflinePlayer().getName()));
}
private void sendMessage(Player player, Object[] args) {
ChatUser user = carbonChat.getUserService().wrap(player);
ChatChannel channel = (ChatChannel) args[0];
@@ -119,15 +78,4 @@ public class ChannelCommand {
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
}
private void sendMessageOther(CommandSender sender, Object[] args) {
ChatUser user = (ChatUser) args[0];
ChatChannel channel = (ChatChannel) args[1];
String message = (String) args[2];
Component component = channel.sendMessage(user, message, false);
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
}
}
@@ -0,0 +1,76 @@
package net.draycia.carbon.commands;
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;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
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 SudoChannelCommand {
private final CarbonChat carbonChat;
public SudoChannelCommand(CarbonChat carbonChat) {
this.carbonChat = carbonChat;
if (!carbonChat.getConfig().getBoolean("commands.sudochannel.enabled")) {
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)
.withArguments(setOtherChannelArguments)
.withAliases(commandAliases.toArray(new String[0]))
.withPermission(CommandPermission.fromString("carbonchat.channel.others"))
.executes((sender, args) -> { this.setOtherChannel(sender, (ChatUser) args[0], (ChatChannel) args[1]); })
.register();
LinkedHashMap<String, Argument> sendMessageOtherArguments = new LinkedHashMap<>();
sendMessageOtherArguments.put("player", CarbonUtils.onlineChatUserArgument());
sendMessageOtherArguments.put("channel", CarbonUtils.channelArgument());
sendMessageOtherArguments.put("message", new GreedyStringArgument());
new CommandAPICommand(commandName)
.withArguments(sendMessageOtherArguments)
.withAliases(commandAliases.toArray(new String[0]))
.withPermission(CommandPermission.fromString("carbonchat.channel.others.message"))
.executes((sender, args) -> { this.sendMessageOther(sender, (ChatUser) args[0], (ChatChannel) args[1], (String) args[2]); })
.register();
}
private void setOtherChannel(CommandSender sender, ChatUser user, ChatChannel channel) {
user.setSelectedChannel(channel);
String message = channel.getSwitchMessage();
String otherMessage = channel.getSwitchOtherMessage();
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n",
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName(),
"player", user.asOfflinePlayer().getName()));
}
private void sendMessageOther(CommandSender sender, ChatUser user, ChatChannel channel, String message) {
Component component = channel.sendMessage(user, message, false);
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
}
}
@@ -23,6 +23,7 @@ public class CommandManager {
new SetColorCommand(carbonChat);
new ShadowMuteCommand(carbonChat);
new SpyChannelCommand(carbonChat);
new SudoChannelCommand(carbonChat);
new ToggleCommand(carbonChat);
}