Improves the double click prevention by accounting for heavy concurrent usage and server lag
This commit is contained in:
		@@ -401,6 +401,7 @@ portalInfoServer=Server: %server%
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
- Adds a config option to set the exit velocity of any players exiting a stargate
 | 
					- Adds a config option to set the exit velocity of any players exiting a stargate
 | 
				
			||||||
- Adjusts vehicle teleportation a bit to prevent passengers' exit rotation from being wrong
 | 
					- Adjusts vehicle teleportation a bit to prevent passengers' exit rotation from being wrong
 | 
				
			||||||
 | 
					- Improves the checking for buggy double-clicks on non-button blocks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### \[Version 0.9.3.1] EpicKnarvik97 fork
 | 
					#### \[Version 0.9.3.1] EpicKnarvik97 fork
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,14 +34,16 @@ import org.bukkit.event.player.PlayerMoveEvent;
 | 
				
			|||||||
import org.bukkit.inventory.EquipmentSlot;
 | 
					import org.bukkit.inventory.EquipmentSlot;
 | 
				
			||||||
import org.bukkit.inventory.ItemStack;
 | 
					import org.bukkit.inventory.ItemStack;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.HashMap;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * This listener listens to any player-related events related to stargates
 | 
					 * This listener listens to any player-related events related to stargates
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@SuppressWarnings("unused")
 | 
					@SuppressWarnings("unused")
 | 
				
			||||||
public class PlayerEventListener implements Listener {
 | 
					public class PlayerEventListener implements Listener {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static long eventTime;
 | 
					    private static final Map<Player, Long> previousEventTimes = new HashMap<>();
 | 
				
			||||||
    private static PlayerInteractEvent previousEvent;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * This event handler handles detection of any player teleporting through a bungee gate
 | 
					     * This event handler handles detection of any player teleporting through a bungee gate
 | 
				
			||||||
@@ -295,7 +297,7 @@ public class PlayerEventListener implements Listener {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Prevent a double click caused by a Spigot bug
 | 
					        //Prevent a double click caused by a Spigot bug
 | 
				
			||||||
        if (clickIsBug(event, block)) {
 | 
					        if (clickIsBug(event.getPlayer(), block)) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -366,19 +368,17 @@ public class PlayerEventListener implements Listener {
 | 
				
			|||||||
     * immediately, or causing portal information printing twice. This fix should detect the bug without breaking
 | 
					     * immediately, or causing portal information printing twice. This fix should detect the bug without breaking
 | 
				
			||||||
     * clicking once the bug is fixed.</p>
 | 
					     * clicking once the bug is fixed.</p>
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param event <p>The event causing the right click</p>
 | 
					     * @param player <p>The player performing the right-click</p>
 | 
				
			||||||
     * @param block <p>The block to check</p>
 | 
					     * @param block  <p>The block to check</p>
 | 
				
			||||||
     * @return <p>True if the click is a bug and should be cancelled</p>
 | 
					     * @return <p>True if the click is a bug and should be cancelled</p>
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private boolean clickIsBug(PlayerInteractEvent event, Block block) {
 | 
					    private boolean clickIsBug(Player player, Block block) {
 | 
				
			||||||
        if (previousEvent != null &&
 | 
					        Long previousEventTime = previousEventTimes.get(player);
 | 
				
			||||||
                event.getPlayer() == previousEvent.getPlayer() && eventTime + 15 > System.currentTimeMillis()) {
 | 
					        if (previousEventTime != null && previousEventTime + 50 > System.currentTimeMillis()) {
 | 
				
			||||||
            previousEvent = null;
 | 
					            previousEventTimes.put(player, null);
 | 
				
			||||||
            eventTime = 0;
 | 
					 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        previousEvent = event;
 | 
					        previousEventTimes.put(player, System.currentTimeMillis());
 | 
				
			||||||
        eventTime = System.currentTimeMillis();
 | 
					 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user