mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
14/15
This commit is contained in:
1 parent
c4ea3e2182
commit
1d162393bf
3 files changed
+104
-33
No files matched your search
@@ -1,55 +1,101 @@
|
||||
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.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.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandAlias("ch|channel|switch")
|
||||
@CommandPermission("carbonchat.switch")
|
||||
public class ChannelCommand extends BaseCommand {
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Dependency
|
||||
private CarbonChat carbonChat;
|
||||
public class ChannelCommand {
|
||||
|
||||
@Default
|
||||
@CommandCompletion("@chatchannel @nothing")
|
||||
@Syntax("<channel> [message]")
|
||||
public void baseCommand(Player player, @Conditions("canuse:true") ChatChannel channel, @Optional String[] args) {
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelCommand(CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.switch.name", "switch");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.switch.aliases");
|
||||
|
||||
LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
||||
setChannelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
.withArguments(setChannelArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withPermission(CommandPermission.fromString("carbonchat.switch"))
|
||||
.executesPlayer(this::setChannel)
|
||||
.register();
|
||||
|
||||
LinkedHashMap<String, Argument> setOtherChannelArguments = new LinkedHashMap<>();
|
||||
setOtherChannelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
setOtherChannelArguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
.withArguments(setOtherChannelArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withPermission(CommandPermission.fromString("carbonchat.switch.other"))
|
||||
.executes(this::setOtherChannel)
|
||||
.register();
|
||||
|
||||
LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
|
||||
sendMessageArguments.put("channel", CarbonUtils.channelArgument());
|
||||
sendMessageArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
.withArguments(sendMessageArguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.withPermission(CommandPermission.fromString("carbonchat.switch.message"))
|
||||
.executesPlayer(this::sendMessage)
|
||||
.register();
|
||||
|
||||
LinkedHashMap<String, Argument> sendMessageOtherArguments = new LinkedHashMap<>();
|
||||
sendMessageOtherArguments.put("user", CarbonUtils.chatUserArgument());
|
||||
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.switch.other.message"))
|
||||
.executes(this::sendMessageOther)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void setChannel(Player player, Object[] args) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
ChatChannel channel = (ChatChannel) args[0];
|
||||
|
||||
if (user.getChannelSettings(channel).isIgnored()) {
|
||||
throw new ConditionFailedException(channel.getCannotUseMessage());
|
||||
}
|
||||
|
||||
if (args == null || args.length == 0) {
|
||||
user.setSelectedChannel(channel);
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getSwitchMessage(),
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getCannotUseMessage(),
|
||||
"br", "\n",
|
||||
"color", "<" + channel.getChannelColor(user).toString() + ">",
|
||||
"channel", channel.getName()));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
Component component = channel.sendMessage(user, String.join(" ", args), false);
|
||||
|
||||
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
|
||||
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
user.setSelectedChannel(channel);
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getSwitchMessage(),
|
||||
"br", "\n",
|
||||
"color", "<" + channel.getChannelColor(user).toString() + ">",
|
||||
"channel", channel.getName()));
|
||||
}
|
||||
|
||||
@CommandPermission("carbonchat.switch.others")
|
||||
@Subcommand("other")
|
||||
@CommandCompletion("@chatchannel @players")
|
||||
@Syntax("<channel> <user>")
|
||||
public void baseCommand(CommandSender sender, @Conditions("exists:true") ChatChannel channel, ChatUser user) {
|
||||
private void setOtherChannel(CommandSender sender, Object[] args) {
|
||||
// @CommandPermission("carbonchat.switch.others")
|
||||
ChatUser user = (ChatUser) args[0];
|
||||
ChatChannel channel = (ChatChannel) args[1];
|
||||
|
||||
user.setSelectedChannel(channel);
|
||||
|
||||
String message = channel.getSwitchMessage();
|
||||
@@ -63,4 +109,26 @@ public class ChannelCommand extends BaseCommand {
|
||||
"player", user.asOfflinePlayer().getName()));
|
||||
}
|
||||
|
||||
private void sendMessage(Player player, Object[] args) {
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
ChatChannel channel = (ChatChannel) args[0];
|
||||
String message = (String) args[1];
|
||||
|
||||
Component component = channel.sendMessage(user, message, false);
|
||||
|
||||
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
|
||||
.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)", "%%"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public class CommandManager {
|
||||
}
|
||||
|
||||
public void reloadCommands(CarbonChat carbonChat) {
|
||||
this.commandManager.registerCommand(new ChannelCommand());
|
||||
new ChannelCommand(carbonChat);
|
||||
new ChannelListCommand(carbonChat);
|
||||
new ChatReloadCommand(carbonChat);
|
||||
new ClearChatCommand(carbonChat);
|
||||
|
||||
Reference in new issue
Block a user