From 0ea494ec89ca105705b80b394e84145740bc85dc Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Thu, 3 Aug 2023 00:19:05 -0400 Subject: [PATCH] bug fixes --- pom.xml | 2 +- .../dev/tylerm/khs/command/util/CommandGroup.java | 2 +- src/main/java/dev/tylerm/khs/game/Game.java | 6 +----- .../dev/tylerm/khs/game/listener/DisguiseHandler.java | 11 ++++++++--- .../tylerm/khs/game/listener/InventoryHandler.java | 2 ++ src/main/java/dev/tylerm/khs/util/PAPIExpansion.java | 2 +- src/main/resources/plugin.yml | 2 +- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 90ee803..a157781 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 dev.tylerm KenshinsHideAndSeek - 1.7.5 + 1.7.6 Hide and Seek Plugin diff --git a/src/main/java/dev/tylerm/khs/command/util/CommandGroup.java b/src/main/java/dev/tylerm/khs/command/util/CommandGroup.java index 02777a3..444922c 100644 --- a/src/main/java/dev/tylerm/khs/command/util/CommandGroup.java +++ b/src/main/java/dev/tylerm/khs/command/util/CommandGroup.java @@ -49,7 +49,7 @@ public class CommandGroup { if (data == null) { player.sendMessage( - String.format("%s%sKenshin's Hide and Seek %s(%s1.7.5%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY, ChatColor.WHITE, ChatColor.GRAY) + + String.format("%s%sKenshin's Hide and Seek %s(%s1.7.6%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY, ChatColor.WHITE, ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); diff --git a/src/main/java/dev/tylerm/khs/game/Game.java b/src/main/java/dev/tylerm/khs/game/Game.java index ac7e808..3de09ef 100644 --- a/src/main/java/dev/tylerm/khs/game/Game.java +++ b/src/main/java/dev/tylerm/khs/game/Game.java @@ -60,8 +60,6 @@ public class Game { private int gameTimer; private boolean hiderLeft; - private Random random; - public Game(Map map, Board board) { this.currentMap = map; @@ -78,8 +76,6 @@ public class Game { this.startingTimer = -1; this.gameTimer = 0; this.hiderLeft = false; - - this.random = new Random(); } public Status getStatus(){ @@ -107,7 +103,7 @@ public class Game { List pool = board.getPlayers(); for (int i = 0; i < startingSeekerCount; i++) { try { - int rand = random.nextInt(0, pool.size()); + int rand = (int)(Math.random() * pool.size()); seekers.add(pool.remove(rand)); } catch (Exception e){ Main.getInstance().getLogger().warning("Failed to select random seeker."); diff --git a/src/main/java/dev/tylerm/khs/game/listener/DisguiseHandler.java b/src/main/java/dev/tylerm/khs/game/listener/DisguiseHandler.java index 5883387..a09aded 100644 --- a/src/main/java/dev/tylerm/khs/game/listener/DisguiseHandler.java +++ b/src/main/java/dev/tylerm/khs/game/listener/DisguiseHandler.java @@ -8,7 +8,6 @@ import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.EnumWrappers; -import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction; import dev.tylerm.khs.Main; import dev.tylerm.khs.game.util.Disguise; import org.bukkit.Bukkit; @@ -51,15 +50,19 @@ public class DisguiseHandler implements Listener { PacketContainer packet = event.getPacket(); // only left click attacks - EntityUseAction action = packet.getEntityUseActions().getValues().stream().findFirst().orElse(null); + EnumWrappers.EntityUseAction action = packet.getEntityUseActions().getValues().stream().findFirst().orElse(null); if (action == null) return; - if (action != EnumWrappers.EntityUseAction.ATTACK) return; + //noinspection ComparatorResultComparison + if (action.compareTo(EnumWrappers.EntityUseAction.INTERACT) == 2) { + return; + } Player player = event.getPlayer(); int id = packet.getIntegers().read(0); Disguise disguise = Main.getInstance().getDisguiser().getByEntityID(id); if(disguise == null) disguise = Main.getInstance().getDisguiser().getByHitBoxID(id); if(disguise == null) return; + if(disguise.getPlayer().getGameMode() == GameMode.CREATIVE) return; event.setCancelled(true); handleAttack(disguise, player); @@ -82,7 +85,9 @@ public class DisguiseHandler implements Listener { disguise.setSolidify(false); if(debounce.contains(disguise.getPlayer())) return; + debounce.add(disguise.getPlayer()); + Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> { EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(seeker, disguise.getPlayer(), EntityDamageEvent.DamageCause.ENTITY_ATTACK, amount); diff --git a/src/main/java/dev/tylerm/khs/game/listener/InventoryHandler.java b/src/main/java/dev/tylerm/khs/game/listener/InventoryHandler.java index bf40896..bb87a50 100644 --- a/src/main/java/dev/tylerm/khs/game/listener/InventoryHandler.java +++ b/src/main/java/dev/tylerm/khs/game/listener/InventoryHandler.java @@ -39,6 +39,7 @@ public class InventoryHandler implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onInventoryClick(InventoryClickEvent event) { + if (event.getCurrentItem() == null) return; if (!(event.getWhoClicked() instanceof Player)) return; checkForInventoryMove(event); checkForSpectatorTeleportMenu(event); @@ -56,6 +57,7 @@ public class InventoryHandler implements Listener { Player player = (Player) event.getWhoClicked(); ItemStack item = event.getCurrentItem(); + ItemMeta meta = item.getItemMeta(); String name = meta.getDisplayName(); diff --git a/src/main/java/dev/tylerm/khs/util/PAPIExpansion.java b/src/main/java/dev/tylerm/khs/util/PAPIExpansion.java index e29a098..2cdd85a 100644 --- a/src/main/java/dev/tylerm/khs/util/PAPIExpansion.java +++ b/src/main/java/dev/tylerm/khs/util/PAPIExpansion.java @@ -31,7 +31,7 @@ public class PAPIExpansion extends PlaceholderExpansion { @Override public @NotNull String getVersion() { - return "1.7.5"; + return "1.7.6"; } @Override diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5e681d0..2d510d6 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: KenshinsHideAndSeek main: dev.tylerm.khs.Main -version: 1.7.5 +version: 1.7.6 author: KenshinEto load: STARTUP api-version: 1.13