forked from Upstream/mmocore
Fixed DROP forcing a left click with key combo casting
This commit is contained in:
parent
36b5be13be
commit
f6d094fb6e
@ -127,6 +127,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
|
|
||||||
// NON-FINAL player data stuff made public to facilitate field change
|
// NON-FINAL player data stuff made public to facilitate field change
|
||||||
public boolean noCooldown;
|
public boolean noCooldown;
|
||||||
|
public long lastDropEvent;
|
||||||
|
|
||||||
public PlayerData(MMOPlayerData mmoData) {
|
public PlayerData(MMOPlayerData mmoData) {
|
||||||
super(mmoData);
|
super(mmoData);
|
||||||
|
@ -31,19 +31,37 @@ public class PlayerPressKeyListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recent bukkit builds automatically send an interact packet
|
||||||
|
* when dropping an item, by pressing Q or from any inventory.
|
||||||
|
* <p>
|
||||||
|
* Simple implementation of a Xms timeout after drop events
|
||||||
|
* where all interact events are nulled. This timeout should
|
||||||
|
* be lower slightly lower than one tick, if the TPS gets
|
||||||
|
* really close to 20 it could cause a loss of true clicks.
|
||||||
|
* Finally, it should only cancel ONE click event at most
|
||||||
|
* and get reset by the first cancelled click event.
|
||||||
|
*/
|
||||||
|
private static final long CLICK_EVENT_TIMEOUT = 30;
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void registerClickKey(PlayerInteractEvent event) {
|
public void registerClickKey(PlayerInteractEvent event) {
|
||||||
if (event.useItemInHand() != Event.Result.DENY && event.getAction().name().contains("CLICK") && event.getHand().equals(EquipmentSlot.HAND)) {
|
if (event.useItemInHand() != Event.Result.DENY && event.getAction().name().contains("CLICK") && event.getHand().equals(EquipmentSlot.HAND)) {
|
||||||
boolean rightClick = event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK;
|
final PlayerData playerData = PlayerData.get(event.getPlayer());
|
||||||
PlayerKeyPressEvent called = new PlayerKeyPressEvent(PlayerData.get(event.getPlayer()), rightClick ? PlayerKey.RIGHT_CLICK : PlayerKey.LEFT_CLICK, event);
|
if (System.currentTimeMillis() - playerData.lastDropEvent < CLICK_EVENT_TIMEOUT) {
|
||||||
Bukkit.getPluginManager().callEvent(called);
|
playerData.lastDropEvent = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final boolean rightClick = event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK;
|
||||||
|
Bukkit.getPluginManager().callEvent(new PlayerKeyPressEvent(playerData, rightClick ? PlayerKey.RIGHT_CLICK : PlayerKey.LEFT_CLICK, event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void registerDropKey(PlayerDropItemEvent event) {
|
public void registerDropKey(PlayerDropItemEvent event) {
|
||||||
PlayerKeyPressEvent called = new PlayerKeyPressEvent(PlayerData.get(event.getPlayer()), PlayerKey.DROP, event);
|
final PlayerData playerData = PlayerData.get(event.getPlayer());
|
||||||
Bukkit.getPluginManager().callEvent(called);
|
Bukkit.getPluginManager().callEvent(new PlayerKeyPressEvent(playerData, PlayerKey.DROP, event));
|
||||||
|
playerData.lastDropEvent = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
Loading…
Reference in New Issue
Block a user