extras/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java

53 lines
1.7 KiB
Java
Raw Normal View History

2019-12-17 12:37:59 +00:00
package pw.kaboom.extras.modules.player;
2019-07-30 17:14:24 +00:00
2019-12-11 01:36:35 +00:00
import java.util.HashMap;
2019-07-30 17:14:24 +00:00
import java.util.UUID;
2019-12-14 18:47:26 +00:00
import org.bukkit.command.CommandSender;
2019-07-30 17:14:24 +00:00
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
2019-12-17 12:37:59 +00:00
import pw.kaboom.extras.modules.server.ServerCommand;
2019-12-02 22:47:05 +00:00
2019-12-21 14:12:26 +00:00
public final class PlayerCommand implements Listener {
2022-05-20 02:35:48 +00:00
private static HashMap<UUID, Long> commandMillisList = new HashMap<UUID, Long>();
2019-12-14 18:47:26 +00:00
2022-05-20 02:35:48 +00:00
@EventHandler
void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
final UUID playerUuid = event.getPlayer().getUniqueId();
2019-12-17 18:23:24 +00:00
2022-05-20 02:35:48 +00:00
if (getCommandMillisList().get(playerUuid) != null) {
final long lastCommandTime = getCommandMillisList().get(playerUuid);
final long millisDifference = System.currentTimeMillis() - lastCommandTime;
2019-12-17 18:23:24 +00:00
2022-05-20 02:35:48 +00:00
if (millisDifference < 75) {
event.setCancelled(true);
}
}
2019-12-17 18:23:24 +00:00
2022-05-20 02:35:48 +00:00
getCommandMillisList().put(playerUuid, System.currentTimeMillis());
2019-12-17 18:23:24 +00:00
2022-05-20 02:35:48 +00:00
if (event.isCancelled()) {
return;
}
2019-12-17 18:23:24 +00:00
2022-05-20 02:35:48 +00:00
final CommandSender sender = event.getPlayer();
final String command = event.getMessage();
final boolean isConsoleCommand = false;
final String checkedCommand = ServerCommand.checkCommand(sender, command, isConsoleCommand);
2019-12-14 19:01:22 +00:00
2022-05-20 02:35:48 +00:00
if (checkedCommand != null) {
if ("cancel".equals(checkedCommand)) {
event.setCancelled(true);
} else {
event.setMessage(checkedCommand);
}
}
}
2020-02-27 15:08:10 +00:00
2022-05-20 02:35:48 +00:00
public static HashMap<UUID, Long> getCommandMillisList() {
return commandMillisList;
}
2019-07-30 17:14:24 +00:00
}