UltimateModeration/src/main/java/com/craftaro/ultimatemoderation/commands/CommandToggleChat.java

71 lines
1.9 KiB
Java
Raw Normal View History

2023-08-02 18:57:10 +02:00
package com.craftaro.ultimatemoderation.commands;
2019-02-27 02:50:18 +01:00
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.locale.Message;
2023-08-02 18:57:10 +02:00
import com.craftaro.ultimatemoderation.UltimateModeration;
import com.craftaro.ultimatemoderation.listeners.ChatListener;
2019-02-27 02:50:18 +01:00
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class CommandToggleChat extends AbstractCommand {
2020-09-08 22:51:25 +02:00
private final UltimateModeration plugin;
2019-10-19 19:29:46 +02:00
2019-02-27 02:50:18 +01:00
/*
* Chat is enabled by default ;)
*/
private boolean toggled = true;
2020-09-08 22:51:25 +02:00
public CommandToggleChat(UltimateModeration plugin) {
2019-10-19 19:29:46 +02:00
super(CommandType.PLAYER_ONLY, "togglechat");
2020-09-08 22:51:25 +02:00
this.plugin = plugin;
2019-02-27 02:50:18 +01:00
}
@Override
2019-10-19 19:29:46 +02:00
protected ReturnType runCommand(CommandSender sender, String... args) {
this.toggled = !this.toggled;
2019-02-27 02:50:18 +01:00
Message message = this.toggled ? this.plugin.getLocale().getMessage("command.togglechat.toggledOn")
: this.plugin.getLocale().getMessage("command.togglechat.toggledOff");
2019-02-27 02:50:18 +01:00
ChatListener.setChatToggled(this.toggled);
2019-02-27 02:50:18 +01:00
for (Player player : Bukkit.getOnlinePlayers()) {
2019-07-25 18:15:42 +02:00
message.sendPrefixedMessage(player);
2019-02-27 02:50:18 +01:00
if (!player.hasPermission(getPermissionNode() + ".bypass")) {
2019-02-27 02:50:18 +01:00
continue;
}
this.plugin.getLocale().getMessage("command.togglechat.bypass").sendMessage(player);
2019-02-27 02:50:18 +01:00
}
if (!(sender instanceof Player)) {
2019-07-25 18:15:42 +02:00
message.sendPrefixedMessage(sender);
}
2019-02-27 02:50:18 +01:00
return ReturnType.SUCCESS;
}
@Override
2019-10-19 19:29:46 +02:00
protected List<String> onTab(CommandSender sender, String... args) {
2019-02-27 02:50:18 +01:00
return null;
}
@Override
public String getPermissionNode() {
return "um.togglechat";
}
@Override
public String getSyntax() {
return "/ToggleChat";
}
@Override
public String getDescription() {
return "Toggle chat for the entire server";
}
}