Split toggleglobalchat into another command

This commit is contained in:
destro174 2021-07-18 00:56:33 +02:00
parent 96dbdc6dd0
commit 04ac327365
4 changed files with 39 additions and 9 deletions

View File

@ -3,6 +3,7 @@ package com.alttd.chat;
import com.alttd.chat.commands.GlobalChat;
import com.alttd.chat.commands.Message;
import com.alttd.chat.commands.Reply;
import com.alttd.chat.commands.ToggleGlobalChat;
import com.alttd.chat.config.Config;
import com.alttd.chat.database.DatabaseConnection;
import com.alttd.chat.handler.ChatHandler;
@ -32,6 +33,7 @@ public class ChatPlugin extends JavaPlugin {
DatabaseConnection.initialize();
registerListener(new PlayerListener(), new ChatListener());
registerCommand("globalchat", new GlobalChat());
registerCommand("toggleglobalchat", new ToggleGlobalChat());
registerCommand("message", new Message());
registerCommand("reply", new Reply());

View File

@ -20,15 +20,6 @@ public class GlobalChat implements CommandExecutor {
}
Player player = (Player) sender;
if(args.length == 0) return false;
if(args[0].equalsIgnoreCase("togglegc")) {
new BukkitRunnable() {
@Override
public void run() {
Objects.requireNonNull(ChatUserManager.getChatUser(((Player) sender).getUniqueId())).toggleGc();
}
}.runTask(ChatPlugin.getInstance());
return false;
}
String message = StringUtils.join(args, " ", 0, args.length);
ChatPlugin.getInstance().getChatHandler().globalChat(player, message);

View File

@ -0,0 +1,33 @@
package com.alttd.chat.commands;
import com.alttd.chat.ChatPlugin;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.objects.ChatUser;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Objects;
public class ToggleGlobalChat implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) { // must be a player
return true;
}
new BukkitRunnable() {
@Override
public void run() {
ChatUser chatUser = ChatUserManager.getChatUser(((Player) sender).getUniqueId());
chatUser.toggleGc();
sender.sendMessage("You have turned globalchat " + (chatUser.isGcOn() ? "<green>on." : "<red>off.")); // TODO load from config and minimessage
}
}.runTask(ChatPlugin.getInstance());
return false;
}
}

View File

@ -9,6 +9,10 @@ commands:
permission: command.globalchat
permission-message: You do not have permission!
aliases: gc
toggleglobalchat:
permission: command.globalchat
permission-message: You do not have permission!
aliases: togglegc
message:
permission: command.message
aliases: msg