Improve last fly active tracker

This commit is contained in:
Olof Larsson 2017-07-18 10:01:34 +02:00
parent 1b0b7455dd
commit 482151aa9a

View File

@ -88,19 +88,32 @@ public class EngineMassiveCorePlayerUpdate extends Engine
} }
// -------------------------------------------- // // -------------------------------------------- //
// FIX NO CHEAT PLUS BUG // LAST FLY ACTIVE
// -------------------------------------------- // // -------------------------------------------- //
public static Map<UUID, Long> idToLastFlyActive = new HashMap<>(); public static Map<UUID, Long> idToLastFlyActive = new HashMap<>();
public static Long getLastFlyActive(Player player) public static Long getLastFlyActive(Player player)
{ {
return idToLastFlyActive.get(player.getUniqueId()); return idToLastFlyActive.get(player.getUniqueId());
} }
public static void setLastFlyActive(Player player, Long millis) public static void setLastFlyActive(Player player, Long millis)
{ {
idToLastFlyActive.put(player.getUniqueId(), millis); idToLastFlyActive.put(player.getUniqueId(), millis);
} }
public static boolean isFlyActiveRecently(Player player)
{
Long lastActive = getLastFlyActive(player);
if (lastActive == null) return false;
return (System.currentTimeMillis() - lastActive < 2000);
}
// -------------------------------------------- //
// FIX NO CHEAT PLUS BUG
// -------------------------------------------- //
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void fixNoCheatPlusBug(EntityDamageEvent event) public void fixNoCheatPlusBug(EntityDamageEvent event)
{ {
@ -111,10 +124,8 @@ public class EngineMassiveCorePlayerUpdate extends Engine
// ... is taking fall damage ... // ... is taking fall damage ...
if (event.getCause() != DamageCause.FALL) return; if (event.getCause() != DamageCause.FALL) return;
// ... within 2 seconds of flying ... // ... after recently flying ...
Long lastActive = getLastFlyActive(player); if (!isFlyActiveRecently(player)) return;
if (lastActive == null) return;
if (System.currentTimeMillis() - lastActive > 2000) return;
// ... cancel the event. // ... cancel the event.
event.setCancelled(true); event.setCancelled(true);