mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +00:00
14/15
This commit is contained in:
1 parent
c4ea3e2182
commit
1d162393bf
3 files changed
+103
-32
No files matched your search
@@ -1,55 +1,101 @@
|
|||||||
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.Argument;
|
||||||
|
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||||
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.util.CarbonUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandAlias("ch|channel|switch")
|
import java.util.LinkedHashMap;
|
||||||
@CommandPermission("carbonchat.switch")
|
import java.util.List;
|
||||||
public class ChannelCommand extends BaseCommand {
|
|
||||||
|
|
||||||
@Dependency
|
public class ChannelCommand {
|
||||||
private CarbonChat carbonChat;
|
|
||||||
|
|
||||||
@Default
|
private final CarbonChat carbonChat;
|
||||||
@CommandCompletion("@chatchannel @nothing")
|
|
||||||
@Syntax("<channel> [message]")
|
public ChannelCommand(CarbonChat carbonChat) {
|
||||||
public void baseCommand(Player player, @Conditions("canuse:true") ChatChannel channel, @Optional String[] args) {
|
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);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
ChatChannel channel = (ChatChannel) args[0];
|
||||||
|
|
||||||
if (user.getChannelSettings(channel).isIgnored()) {
|
if (user.getChannelSettings(channel).isIgnored()) {
|
||||||
throw new ConditionFailedException(channel.getCannotUseMessage());
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getCannotUseMessage(),
|
||||||
}
|
|
||||||
|
|
||||||
if (args == null || args.length == 0) {
|
|
||||||
user.setSelectedChannel(channel);
|
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getSwitchMessage(),
|
|
||||||
"br", "\n",
|
"br", "\n",
|
||||||
"color", "<" + channel.getChannelColor(user).toString() + ">",
|
"color", "<" + channel.getChannelColor(user).toString() + ">",
|
||||||
"channel", channel.getName()));
|
"channel", channel.getName()));
|
||||||
} else {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
|
||||||
Component component = channel.sendMessage(user, String.join(" ", args), false);
|
|
||||||
|
|
||||||
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
|
return;
|
||||||
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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")
|
private void setOtherChannel(CommandSender sender, Object[] args) {
|
||||||
@Subcommand("other")
|
// @CommandPermission("carbonchat.switch.others")
|
||||||
@CommandCompletion("@chatchannel @players")
|
ChatUser user = (ChatUser) args[0];
|
||||||
@Syntax("<channel> <user>")
|
ChatChannel channel = (ChatChannel) args[1];
|
||||||
public void baseCommand(CommandSender sender, @Conditions("exists:true") ChatChannel channel, ChatUser user) {
|
|
||||||
user.setSelectedChannel(channel);
|
user.setSelectedChannel(channel);
|
||||||
|
|
||||||
String message = channel.getSwitchMessage();
|
String message = channel.getSwitchMessage();
|
||||||
@@ -63,4 +109,26 @@ public class ChannelCommand extends BaseCommand {
|
|||||||
"player", user.asOfflinePlayer().getName()));
|
"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) {
|
public void reloadCommands(CarbonChat carbonChat) {
|
||||||
this.commandManager.registerCommand(new ChannelCommand());
|
new ChannelCommand(carbonChat);
|
||||||
new ChannelListCommand(carbonChat);
|
new ChannelListCommand(carbonChat);
|
||||||
new ChatReloadCommand(carbonChat);
|
new ChatReloadCommand(carbonChat);
|
||||||
new ClearChatCommand(carbonChat);
|
new ClearChatCommand(carbonChat);
|
||||||
|
|||||||
@@ -183,3 +183,6 @@ commands:
|
|||||||
channellist:
|
channellist:
|
||||||
name: 'channellist'
|
name: 'channellist'
|
||||||
aliases: ['chlist']
|
aliases: ['chlist']
|
||||||
|
channel:
|
||||||
|
name: 'channel'
|
||||||
|
aliases: ['ch', 'switch', 'join']
|
||||||
Reference in new issue
Block a user