From 780c4f0b8e9a7d8f41d9e391f02640586b8ef62f Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Mon, 21 Mar 2016 18:10:08 -0500 Subject: [PATCH] Fix #95 and #114 Change to clay brick & prevent double clicking due to a Spigot bug. --- src/main/java/com/graywolf336/jail/Util.java | 2 +- .../jail/listeners/PlayerListener.java | 21 +++++++++++++++++-- .../jail/steps/CellCreationSteps.java | 1 - 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/Util.java b/src/main/java/com/graywolf336/jail/Util.java index 0cc11de..0b01bc1 100644 --- a/src/main/java/com/graywolf336/jail/Util.java +++ b/src/main/java/com/graywolf336/jail/Util.java @@ -205,7 +205,7 @@ public class Util { * @return The {@link ItemStack} to use for creation */ public static ItemStack getWand() { - ItemStack wand = new ItemStack(Material.WOOD_SWORD); + ItemStack wand = new ItemStack(Material.CLAY_BRICK); ItemMeta meta = wand.getItemMeta(); meta.setDisplayName(ChatColor.AQUA + "Jail Wand"); LinkedList lore = new LinkedList(); diff --git a/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java b/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java index 39604de..eb3effb 100644 --- a/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java +++ b/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java @@ -1,7 +1,9 @@ package com.graywolf336.jail.listeners; +import java.util.HashMap; import java.util.HashSet; import java.util.Set; +import java.util.UUID; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -36,9 +38,11 @@ import com.graywolf336.jail.interfaces.ICell; public class PlayerListener implements Listener { private JailMain pl; + private HashMap clicks; public PlayerListener(JailMain plugin) { this.pl = plugin; + this.clicks = new HashMap(); } @EventHandler(ignoreCancelled=true) @@ -50,6 +54,19 @@ public class PlayerListener implements Listener { if(p.getInventory().getItemInMainHand().isSimilar(Util.getWand())) { if(jm.isCreatingSomething(p.getName())) { + + long current = System.currentTimeMillis(); + if(clicks.containsKey(p.getUniqueId())) { + if(current - clicks.get(p.getUniqueId()) > 500) { + clicks.put(p.getUniqueId(), current); + }else { + pl.debug("Prevented a double click for " + p.getName() + "!"); + return; + } + }else { + clicks.put(p.getUniqueId(), current); + } + if(jm.isCreatingAJail(p.getName())) { pl.debug("Stepping into creating a jail."); jm.getJailCreationSteps().step(jm, p, jm.getJailCreationPlayer(p.getName()), loc); @@ -57,8 +74,6 @@ public class PlayerListener implements Listener { pl.debug("Stepping into creating a cell."); jm.getCellCreationSteps().step(jm, p, jm.getCellCreationPlayer(p.getName()), loc); } - - event.setCancelled(true); } } } @@ -173,6 +188,8 @@ public class PlayerListener implements Listener { pl.getScoreBoardManager().removeScoreBoard(event.getPlayer()); } } + + clicks.remove(event.getPlayer().getUniqueId()); } @EventHandler(priority = EventPriority.LOW) diff --git a/src/main/java/com/graywolf336/jail/steps/CellCreationSteps.java b/src/main/java/com/graywolf336/jail/steps/CellCreationSteps.java index f44aec6..4361c1d 100644 --- a/src/main/java/com/graywolf336/jail/steps/CellCreationSteps.java +++ b/src/main/java/com/graywolf336/jail/steps/CellCreationSteps.java @@ -26,7 +26,6 @@ import com.graywolf336.jail.enums.Lang; * @version 1.0.1 */ public class CellCreationSteps { - /** Sends the Cell Creation message for starting out. */ public void startStepping(Player player){ player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation (tp) ----------");