2019-10-19 19:29:46 +02:00
|
|
|
package com.songoda.ultimatemoderation.commands;
|
2019-02-27 02:50:18 +01:00
|
|
|
|
2023-07-20 17:41:31 +02:00
|
|
|
import com.craftaro.core.commands.AbstractCommand;
|
2019-02-27 02:50:18 +01:00
|
|
|
import com.songoda.ultimatemoderation.UltimateModeration;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
2019-03-08 01:08:40 +01:00
|
|
|
import java.util.Collections;
|
2019-02-27 02:50:18 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class CommandClearChat extends AbstractCommand {
|
2020-09-08 22:51:25 +02:00
|
|
|
private final UltimateModeration plugin;
|
2019-10-19 19:29:46 +02:00
|
|
|
|
2020-09-08 22:51:25 +02:00
|
|
|
public CommandClearChat(UltimateModeration plugin) {
|
2019-10-19 19:29:46 +02:00
|
|
|
super(CommandType.PLAYER_ONLY, "ClearChat");
|
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) {
|
2023-07-20 17:32:46 +02:00
|
|
|
if (args.length != 0 && !args[0].equalsIgnoreCase("force")) {
|
2019-02-27 15:46:14 +01:00
|
|
|
return ReturnType.SYNTAX_ERROR;
|
2023-07-20 17:32:46 +02:00
|
|
|
}
|
2019-02-27 15:46:14 +01:00
|
|
|
|
2019-02-27 02:50:18 +01:00
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
|
|
if (!player.hasPermission("um.clearchat.bypass") || isForced(args)) {
|
|
|
|
String[] toSend = new String[250];
|
|
|
|
Arrays.fill(toSend, "");
|
|
|
|
player.sendMessage(toSend);
|
|
|
|
}
|
|
|
|
|
2023-07-20 17:32:46 +02:00
|
|
|
this.plugin.getLocale().getMessage("command.clearchat.cleared")
|
2019-07-25 18:15:42 +02:00
|
|
|
.processPlaceholder("player", sender.getName()).sendPrefixedMessage(player);
|
2019-02-27 02:50:18 +01:00
|
|
|
|
|
|
|
if (player.hasPermission("um.clearchat.bypass") && !isForced(args)) {
|
2023-07-20 17:32:46 +02:00
|
|
|
this.plugin.getLocale().getMessage("command.clearchat.immune").sendMessage(player);
|
2019-02-27 02:50:18 +01:00
|
|
|
}
|
|
|
|
}
|
2023-07-20 17:32:46 +02:00
|
|
|
|
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-03-08 01:08:40 +01:00
|
|
|
if (args.length == 1) {
|
|
|
|
return Collections.singletonList("force");
|
|
|
|
}
|
2019-02-27 02:50:18 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isForced(String[] args) {
|
|
|
|
return args.length != 0 && args[0].equals("force");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getPermissionNode() {
|
|
|
|
return "um.clearchat";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getSyntax() {
|
|
|
|
return "/clearChat [force]";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDescription() {
|
|
|
|
return "Allows you to clear the chat.";
|
|
|
|
}
|
|
|
|
}
|