From 31ce825224ad781f3ef8bd2b8bcb95de64f5aaa5 Mon Sep 17 00:00:00 2001 From: Zrips Date: Sun, 5 Feb 2017 12:11:17 +0200 Subject: [PATCH] Fix for double sign click issue with off hand double event --- com/gamingmesh/jobs/Gui/GuiManager.java | 18 ++++--- com/gamingmesh/jobs/PermissionManager.java | 1 - com/gamingmesh/jobs/commands/list/browse.java | 1 + .../jobs/listeners/JobsListener.java | 48 +++++++++++-------- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/com/gamingmesh/jobs/Gui/GuiManager.java b/com/gamingmesh/jobs/Gui/GuiManager.java index c8b80676..7af0a3be 100644 --- a/com/gamingmesh/jobs/Gui/GuiManager.java +++ b/com/gamingmesh/jobs/Gui/GuiManager.java @@ -21,6 +21,7 @@ import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobInfo; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.Perm; public class GuiManager { @@ -70,8 +71,9 @@ public class GuiManager { guiInfo.setJobList(JobsList); Inventory topinv = player.getOpenInventory().getTopInventory(); - if (topinv != null && !GuiList.containsKey(player.getName())) + if (topinv != null && !GuiList.containsKey(player.getName())) { player.closeInventory(); + } GuiList.put(player.getName(), guiInfo); @@ -153,12 +155,14 @@ public class GuiManager { i++; } - ItemStack filler = Jobs.getGCManager().guiFiller; + } - for (int y = 0; y < GuiInv.getContents().length; y++) { - ItemStack item = GuiInv.getItem(y); - if (item == null || item.getType() == Material.AIR) - GuiInv.setItem(y, filler); + ItemStack filler = Jobs.getGCManager().guiFiller; + + for (int y = 0; y < GuiInv.getSize(); y++) { + ItemStack item = GuiInv.getItem(y); + if (item == null || item.getType() == Material.AIR) { + GuiInv.setItem(y, filler); } } return GuiInv; @@ -269,7 +273,7 @@ public class GuiManager { ItemStack filler = Jobs.getGCManager().guiFiller; - for (int y = 0; y < GuiInv.getContents().length; y++) { + for (int y = 0; y < GuiInv.getSize(); y++) { ItemStack item = GuiInv.getItem(y); if (item == null || item.getType() == Material.AIR) GuiInv.setItem(y, filler); diff --git a/com/gamingmesh/jobs/PermissionManager.java b/com/gamingmesh/jobs/PermissionManager.java index ee2141bd..8b232956 100644 --- a/com/gamingmesh/jobs/PermissionManager.java +++ b/com/gamingmesh/jobs/PermissionManager.java @@ -1,6 +1,5 @@ /** * Jobs Plugin for Bukkit - * Copyright (C) 2011 Zak Ford * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/com/gamingmesh/jobs/commands/list/browse.java b/com/gamingmesh/jobs/commands/list/browse.java index 05c4752c..e36d4964 100644 --- a/com/gamingmesh/jobs/commands/list/browse.java +++ b/com/gamingmesh/jobs/commands/list/browse.java @@ -11,6 +11,7 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.stuff.ChatColor; +import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.Perm; public class browse implements Cmd { diff --git a/com/gamingmesh/jobs/listeners/JobsListener.java b/com/gamingmesh/jobs/listeners/JobsListener.java index 9be90088..c170623d 100644 --- a/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/com/gamingmesh/jobs/listeners/JobsListener.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.UUID; import java.util.regex.Pattern; import org.bukkit.Bukkit; @@ -68,15 +69,30 @@ import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobLimitedItems; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.stuff.Debug; public class JobsListener implements Listener { // hook to the main plugin private Jobs plugin; + private HashMap interactDelay = new HashMap(); + public JobsListener(Jobs plugin) { this.plugin = plugin; } + private boolean isInteractOk(Player player) { + if (!interactDelay.containsKey(player.getUniqueId())) { + interactDelay.put(player.getUniqueId(), System.currentTimeMillis()); + return true; + } + long time = System.currentTimeMillis() - interactDelay.get(player.getUniqueId()); + interactDelay.put(player.getUniqueId(), System.currentTimeMillis()); + if (time > 100) + return true; + return false; + } + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onSelection(PlayerInteractEvent event) { if (event.getPlayer() == null) @@ -87,6 +103,7 @@ public class JobsListener implements Listener { if (event.getAction() != Action.LEFT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_BLOCK) return; Player player = event.getPlayer(); + ItemStack iih = Jobs.getNms().getItemInMainHand(player); if (iih == null || iih.getType() == Material.AIR) return; @@ -143,15 +160,13 @@ public class JobsListener implements Listener { } - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) - public void onShopClose(InventoryCloseEvent event) { - if (Jobs.getShopManager().GuiList.isEmpty()) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onGuiClose(InventoryCloseEvent event) { + if (Jobs.getGUIManager().GuiList.isEmpty()) return; - Player player = (Player) event.getPlayer(); - - if (Jobs.getShopManager().GuiList.containsKey(player.getName())) - Jobs.getShopManager().GuiList.remove(player.getName()); + if (Jobs.getGUIManager().GuiList.containsKey(player.getName())) + Jobs.getGUIManager().GuiList.remove(player.getName()); } @EventHandler(priority = EventPriority.LOWEST) @@ -199,17 +214,6 @@ public class JobsListener implements Listener { } } - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) - public void onGuiClose(InventoryCloseEvent event) { - if (Jobs.getGUIManager().GuiList.isEmpty()) - return; - - Player player = (Player) event.getPlayer(); - - if (Jobs.getGUIManager().GuiList.containsKey(player.getName())) - Jobs.getGUIManager().GuiList.remove(player.getName()); - } - @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerJoin(final PlayerJoinEvent event) { @@ -261,7 +265,7 @@ public class JobsListener implements Listener { Jobs.getPermissionHandler().recalculatePermissions(jPlayer); } - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSignInteract(PlayerInteractEvent event) { if (!plugin.isEnabled()) @@ -281,6 +285,11 @@ public class JobsListener implements Listener { if (!(block.getState() instanceof Sign)) return; + Player player = event.getPlayer(); + + if (!isInteractOk(player)) + return; + Sign sign = (Sign) block.getState(); String FirstLine = sign.getLine(0); @@ -296,7 +305,6 @@ public class JobsListener implements Listener { } } - Player player = event.getPlayer(); player.performCommand("jobs " + command + " " + ChatColor.stripColor(sign.getLine(2)) + " " + ChatColor.stripColor(sign.getLine(3))); }