mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
1/15
This commit is contained in:
1 parent
f17168f68f
commit
207eee3576
5 files changed
+46
-15
No files matched your search
@@ -1,39 +1,61 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.*;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
@CommandAlias("reply|r")
|
||||
@CommandPermission("carbonchat.reply")
|
||||
public class ReplyCommand extends BaseCommand {
|
||||
public class ReplyCommand {
|
||||
|
||||
@Dependency
|
||||
private CarbonChat carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@Default
|
||||
@Syntax("<message>")
|
||||
public void baseCommand(Player player, String... args) {
|
||||
if (args.length == 0) {
|
||||
return;
|
||||
}
|
||||
public ReplyCommand(CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("message", new GreedyStringArgument());
|
||||
|
||||
String commandName = carbonChat.getConfig().getString("commands.reply.name", "reply");
|
||||
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.reply.aliases");
|
||||
|
||||
new CommandAPICommand(commandName)
|
||||
.withArguments(arguments)
|
||||
.withAliases(commandAliases.toArray(new String[0]))
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(Player player, Object[] args) {
|
||||
String input = (String) args[0];
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
|
||||
if (input == null || input.isEmpty()) {
|
||||
String message = carbonChat.getLanguage().getString("reply-message-blank");
|
||||
Component component = carbonChat.getAdventureManager().processMessage(message, "br", "\n");
|
||||
user.sendMessage(component);
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.getReplyTarget() == null) {
|
||||
String message = carbonChat.getLanguage().getString("no-reply-target");
|
||||
Component component = carbonChat.getAdventureManager().processMessage(message, "br", "\n");
|
||||
user.sendMessage(component);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ChatUser targetUser = carbonChat.getUserService().wrap(user.getReplyTarget());
|
||||
|
||||
targetUser.sendMessage(user, String.join(" ", args));
|
||||
targetUser.sendMessage(user, input);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -77,10 +77,10 @@ public class CommandManager {
|
||||
}
|
||||
});
|
||||
|
||||
reloadCommands();
|
||||
reloadCommands(carbonChat);
|
||||
}
|
||||
|
||||
public void reloadCommands() {
|
||||
public void reloadCommands(CarbonChat carbonChat) {
|
||||
this.commandManager.registerCommand(new ToggleCommand());
|
||||
this.commandManager.registerCommand(new ChannelCommand());
|
||||
this.commandManager.registerCommand(new ChannelListCommand());
|
||||
@@ -89,7 +89,7 @@ public class CommandManager {
|
||||
this.commandManager.registerCommand(new MeCommand());
|
||||
this.commandManager.registerCommand(new MessageCommand());
|
||||
this.commandManager.registerCommand(new NicknameCommand());
|
||||
this.commandManager.registerCommand(new ReplyCommand());
|
||||
new ReplyCommand(carbonChat);
|
||||
this.commandManager.registerCommand(new SetColorCommand());
|
||||
this.commandManager.registerCommand(new SpyChannelCommand());
|
||||
|
||||
|
||||
Reference in new issue
Block a user