From 91a1b47054fa59e68a440e88ef2a31e353907782 Mon Sep 17 00:00:00 2001 From: mathiascode Date: Wed, 11 Dec 2019 03:36:35 +0200 Subject: [PATCH] Move lists --- src/main/java/pw/kaboom/extras/Main.java | 7 +------ .../java/pw/kaboom/extras/commands/CommandUsername.java | 2 +- .../java/pw/kaboom/extras/helpers/SkinDownloader.java | 6 +++--- .../pw/kaboom/extras/modules/block/BlockPhysics.java | 8 +++++--- .../java/pw/kaboom/extras/modules/player/PlayerChat.java | 6 +++--- .../pw/kaboom/extras/modules/player/PlayerCommand.java | 9 ++++++--- .../kaboom/extras/modules/player/PlayerConnection.java | 6 +++--- .../pw/kaboom/extras/modules/player/PlayerInteract.java | 9 ++++++--- 8 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index a29be43..710a01f 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -1,7 +1,6 @@ package pw.kaboom.extras; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.UUID; @@ -11,11 +10,8 @@ import org.bukkit.plugin.java.JavaPlugin; import com.destroystokyo.paper.profile.PlayerProfile; public class Main extends JavaPlugin { - static int fallingBlockCount; static HashSet skinInProgress = new HashSet<>(); - static HashSet usernameInProgress = new HashSet<>(); - static HashMap commandMillisList = new HashMap<>(); - static HashMap interactMillisList = new HashMap<>(); + static HashSet consoleCommandBlacklist = new HashSet<>(); static HashSet faces = new HashSet<>(); @@ -408,7 +404,6 @@ public class Main extends JavaPlugin { /* Block-related modules */ this.getServer().getPluginManager().registerEvents(new BlockCheck(), this); - /*new TileEntityCheck(this).runTaskTimerAsynchronously(this, 0, 400);*/ this.getServer().getPluginManager().registerEvents(new BlockPhysics(), this); /* Entity-related modules */ diff --git a/src/main/java/pw/kaboom/extras/commands/CommandUsername.java b/src/main/java/pw/kaboom/extras/commands/CommandUsername.java index 6ffbfc4..22a0e0a 100644 --- a/src/main/java/pw/kaboom/extras/commands/CommandUsername.java +++ b/src/main/java/pw/kaboom/extras/commands/CommandUsername.java @@ -18,7 +18,7 @@ class CommandUsername implements CommandExecutor { if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); - } else if (!Main.usernameInProgress.contains(player.getUniqueId())) { + } else if (!Main.skinInProgress.contains(player.getUniqueId())) { final String nameColor = ChatColor.translateAlternateColorCodes('&', String.join(" ", args)); final String name = nameColor.substring(0, Math.min(16, nameColor.length())); final boolean shouldChangeUsername = true; diff --git a/src/main/java/pw/kaboom/extras/helpers/SkinDownloader.java b/src/main/java/pw/kaboom/extras/helpers/SkinDownloader.java index 0167151..2c740bb 100644 --- a/src/main/java/pw/kaboom/extras/helpers/SkinDownloader.java +++ b/src/main/java/pw/kaboom/extras/helpers/SkinDownloader.java @@ -21,7 +21,7 @@ class SkinDownloader { private String signature; public void applySkin(Player player, String name, boolean shouldChangeName, boolean shouldSendMessage) { - Main.usernameInProgress.add(player.getUniqueId()); + Main.skinInProgress.add(player.getUniqueId()); new BukkitRunnable() { public void run() { @@ -39,7 +39,7 @@ class SkinDownloader { } } else if (!shouldChangeName && shouldSendMessage) { player.sendMessage("A player with that username doesn't exist"); - Main.usernameInProgress.remove(player.getUniqueId()); + Main.skinInProgress.remove(player.getUniqueId()); return; } @@ -52,7 +52,7 @@ class SkinDownloader { player.sendMessage("Successfully set your username to \"" + name + "\""); } } - Main.usernameInProgress.remove(player.getUniqueId()); + Main.skinInProgress.remove(player.getUniqueId()); } }.runTask(JavaPlugin.getPlugin(Main.class)); } diff --git a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java index 81454bc..dc939da 100644 --- a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java +++ b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java @@ -89,15 +89,17 @@ class BlockPhysics implements Listener { } } + int fallingBlockCount; + @EventHandler void onEntityChangeBlock(EntityChangeBlockEvent event) { if (event.getEntityType() == EntityType.FALLING_BLOCK && event.getTo() == Material.AIR) { - Main.fallingBlockCount++; + fallingBlockCount++; - if (Main.fallingBlockCount == 10) { + if (fallingBlockCount == 10) { event.setCancelled(true); - Main.fallingBlockCount = 0; + fallingBlockCount = 0; } } } diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java index 9ac0eb5..3793972 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java @@ -23,15 +23,15 @@ class PlayerChat implements Listener { final Player player = event.getPlayer(); final UUID playerUuid = event.getPlayer().getUniqueId(); - if (Main.commandMillisList.get(playerUuid) != null) { - final long millisDifference = System.currentTimeMillis() - Main.commandMillisList.get(playerUuid); + if (PlayerCommand.commandMillisList.get(playerUuid) != null) { + final long millisDifference = System.currentTimeMillis() - PlayerCommand.commandMillisList.get(playerUuid); if (millisDifference < 5) { event.setCancelled(true); } } - Main.commandMillisList.put(playerUuid, System.currentTimeMillis()); + PlayerCommand.commandMillisList.put(playerUuid, System.currentTimeMillis()); if (event.isCancelled()) { return; diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java index be704bd..98f943f 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java @@ -1,5 +1,6 @@ package pw.kaboom.extras; +import java.util.HashMap; import java.util.UUID; import org.bukkit.Bukkit; @@ -17,21 +18,23 @@ import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.plugin.java.JavaPlugin; class PlayerCommand implements Listener { + static HashMap commandMillisList = new HashMap<>(); + @EventHandler void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { final String[] arr = event.getMessage().split(" "); final String command = event.getMessage(); final UUID playerUuid = event.getPlayer().getUniqueId(); - if (Main.commandMillisList.get(playerUuid) != null) { - final long millisDifference = System.currentTimeMillis() - Main.commandMillisList.get(playerUuid); + if (commandMillisList.get(playerUuid) != null) { + final long millisDifference = System.currentTimeMillis() - commandMillisList.get(playerUuid); if (millisDifference < 75) { event.setCancelled(true); } } - Main.commandMillisList.put(playerUuid, System.currentTimeMillis()); + commandMillisList.put(playerUuid, System.currentTimeMillis()); if (event.isCancelled()) { return; diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java index 9460202..4dd293f 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java @@ -42,9 +42,9 @@ class PlayerConnection implements Listener { @EventHandler void onPlayerConnectionClose(final PlayerConnectionCloseEvent event) { - Main.commandMillisList.remove(event.getPlayerUniqueId()); - Main.interactMillisList.remove(event.getPlayerUniqueId()); - Main.usernameInProgress.remove(event.getPlayerUniqueId()); + PlayerCommand.commandMillisList.remove(event.getPlayerUniqueId()); + PlayerInteract.interactMillisList.remove(event.getPlayerUniqueId()); + Main.skinInProgress.remove(event.getPlayerUniqueId()); } @EventHandler diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java index b27215f..7d37e96 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java @@ -1,5 +1,6 @@ package pw.kaboom.extras; +import java.util.HashMap; import java.util.UUID; import org.bukkit.entity.Player; @@ -10,19 +11,21 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; class PlayerInteract implements Listener { + static HashMap interactMillisList = new HashMap<>(); + @EventHandler void onPlayerInteract(PlayerInteractEvent event) { final Player player = event.getPlayer(); final UUID playerUuid = event.getPlayer().getUniqueId(); - if (Main.interactMillisList.get(playerUuid) != null) { - final long millisDifference = System.currentTimeMillis() - Main.interactMillisList.get(playerUuid); + if (interactMillisList.get(playerUuid) != null) { + final long millisDifference = System.currentTimeMillis() - interactMillisList.get(playerUuid); if (millisDifference < 150) { event.setCancelled(true); } } - Main.interactMillisList.put(playerUuid, System.currentTimeMillis()); + interactMillisList.put(playerUuid, System.currentTimeMillis()); } }