diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/InstantHeal.java b/src/fr/neatmonster/nocheatplus/checks/fight/InstantHeal.java index dadb0af3..d76dd67d 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/InstantHeal.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/InstantHeal.java @@ -35,17 +35,20 @@ public class InstantHeal extends Check { * @return true, if successful */ public boolean check(final Player player) { + // Take time once. + final long time = System.currentTimeMillis(); + final FightData data = FightData.getData(player); boolean cancel = false; // Security check if system time ran backwards. - if (data.instantHealLastTime > System.currentTimeMillis()) { + if (data.instantHealLastTime > time) { data.instantHealLastTime = 0L; return false; } - final long delta = System.currentTimeMillis() - (data.instantHealLastTime + 3000L); + final long delta = time - (data.instantHealLastTime + 3000L); data.instantHealBuffer += delta; if (data.instantHealBuffer < 0) { @@ -69,7 +72,7 @@ public class InstantHeal extends Check { if (!cancel) // New reference time. - data.instantHealLastTime = System.currentTimeMillis(); + data.instantHealLastTime = time; return cancel; } diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/Drop.java b/src/fr/neatmonster/nocheatplus/checks/inventory/Drop.java index 953d3565..8a0a1ed4 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/Drop.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/Drop.java @@ -35,20 +35,23 @@ public class Drop extends Check { * @return true, if successful */ public boolean check(final Player player) { + // Take time once. + final long time = System.currentTimeMillis(); + final InventoryConfig cc = InventoryConfig.getConfig(player); final InventoryData data = InventoryData.getData(player); boolean cancel = false; // Has the configured time passed? If so, reset the counter. - if (data.dropLastTime + cc.dropTimeFrame <= System.currentTimeMillis()) { - data.dropLastTime = System.currentTimeMillis(); + if (data.dropLastTime + cc.dropTimeFrame <= time) { + data.dropLastTime = time; data.dropCount = 0; data.dropVL = 0D; } // Security check, if the system time changes. - else if (data.dropLastTime > System.currentTimeMillis()) + else if (data.dropLastTime > time) data.dropLastTime = Integer.MIN_VALUE; data.dropCount++; diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/FastClick.java b/src/fr/neatmonster/nocheatplus/checks/inventory/FastClick.java index 823e39d5..d59b8e68 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/FastClick.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/FastClick.java @@ -34,16 +34,19 @@ public class FastClick extends Check { * @return true, if successful */ public boolean check(final Player player) { + // Take time once. + final long time = System.currentTimeMillis(); + final InventoryData data = InventoryData.getData(player); boolean cancel = false; // If the last inventory click has been made within 45 milliseconds. - if (System.currentTimeMillis() - data.fastClickLastTime < 45L) { + if (time - data.fastClickLastTime < 45L) { if (data.fastClickLastCancelled) { // Calculate the difference between the limit and the time elapsed. - final double difference = 45L - System.currentTimeMillis() + data.fastClickLastTime; + final double difference = 45L - time + data.fastClickLastTime; // Increment the violation level. data.fastClickVL += difference; @@ -61,7 +64,7 @@ public class FastClick extends Check { } // Remember the current time.s - data.fastClickLastTime = System.currentTimeMillis(); + data.fastClickLastTime = time; return cancel; } diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java b/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java index 1e730218..154aaf9c 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java @@ -36,6 +36,9 @@ public class InstantBow extends Check { * @return true, if successful */ public boolean check(final Player player, final float force) { + // Take time once. + final long time = System.currentTimeMillis(); + final InventoryData data = InventoryData.getData(player); boolean cancel = false; @@ -43,14 +46,14 @@ public class InstantBow extends Check { // Rough estimation of how long pulling the string should've taken. final long expectedTimeWhenStringDrawn = data.instantBowLastTime + (int) (force * force * 700F); - if (expectedTimeWhenStringDrawn < System.currentTimeMillis()) + if (expectedTimeWhenStringDrawn < time) // The player was slow enough, reward him by lowering his violation level. data.instantBowVL *= 0.9D; - else if (data.instantBowLastTime > System.currentTimeMillis()) + else if (data.instantBowLastTime > time) // Security check if time ran backwards, reset data.instantBowLastTime = 0L; else { - final double difference = (expectedTimeWhenStringDrawn - System.currentTimeMillis()) / 100D; + final double difference = (expectedTimeWhenStringDrawn - time) / 100D; // Player was too fast, increase his violation level. data.instantBowVL += difference; diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/InstantEat.java b/src/fr/neatmonster/nocheatplus/checks/inventory/InstantEat.java index 3e8ff629..f57aca43 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/InstantEat.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/InstantEat.java @@ -38,6 +38,9 @@ public class InstantEat extends Check { * @return true, if successful */ public boolean check(final Player player, final int level) { + // Take time once. + final long time = System.currentTimeMillis(); + final InventoryData data = InventoryData.getData(player); boolean cancel = false; @@ -49,14 +52,14 @@ public class InstantEat extends Check { // Rough estimation about how long it should take to eat final long expectedTimeWhenEatingFinished = data.instantEatLastTime + 700L; - if (expectedTimeWhenEatingFinished < System.currentTimeMillis()) + if (expectedTimeWhenEatingFinished < time) // Acceptable, reduce VL to reward the player. data.instantEatVL *= 0.6D; - else if (data.instantEatLastTime > System.currentTimeMillis()) + else if (data.instantEatLastTime > time) // Security test, if time ran backwards, reset. data.instantEatLastTime = 0; else { - final double difference = (expectedTimeWhenEatingFinished - System.currentTimeMillis()) / 100D; + final double difference = (expectedTimeWhenEatingFinished - time) / 100D; // Player was too fast, increase his violation level. data.instantEatVL += difference; diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java b/src/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java index 141e0306..9fe37df0 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java @@ -59,6 +59,9 @@ public class MorePackets extends Check { * @return the location */ public Location check(final Player player, final PlayerLocation from, final PlayerLocation to) { + // Take time once, first: + final long time = System.currentTimeMillis(); + final MovingData data = MovingData.getData(player); Location newTo = null; @@ -66,8 +69,6 @@ public class MorePackets extends Check { if (data.morePacketsSetback == null) data.morePacketsSetback = from.getLocation(); - final long time = System.currentTimeMillis(); - // Take a packet from the buffer. data.morePacketsBuffer--; diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MorePacketsVehicle.java b/src/fr/neatmonster/nocheatplus/checks/moving/MorePacketsVehicle.java index 22d82fdb..cab00e18 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MorePacketsVehicle.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MorePacketsVehicle.java @@ -58,6 +58,9 @@ public class MorePacketsVehicle extends Check { * @return the location */ public Location check(final Player player, final Location from, final Location to) { + // Take time once, first: + final long time = System.currentTimeMillis(); + final MovingData data = MovingData.getData(player); Location newTo = null; @@ -65,8 +68,6 @@ public class MorePacketsVehicle extends Check { if (data.morePacketsVehicleSetback == null) data.morePacketsVehicleSetback = from; - final long time = System.currentTimeMillis(); - // Take a packet from the buffer. data.morePacketsVehicleBuffer--;