From a5c37a884b6d698d1d61c1a50d1fd65e15fe6373 Mon Sep 17 00:00:00 2001 From: asofold Date: Mon, 8 Oct 2012 04:28:39 +0200 Subject: [PATCH] Small optimization for violation handling. --- src/fr/neatmonster/nocheatplus/checks/ViolationData.java | 4 ++++ .../nocheatplus/checks/blockbreak/FastBreak.java | 2 +- .../nocheatplus/checks/moving/CreativeFly.java | 8 +++++--- .../neatmonster/nocheatplus/checks/moving/Passable.java | 2 +- .../nocheatplus/checks/moving/SurvivalFly.java | 8 +++++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/ViolationData.java b/src/fr/neatmonster/nocheatplus/checks/ViolationData.java index f8bc172d..b170809d 100644 --- a/src/fr/neatmonster/nocheatplus/checks/ViolationData.java +++ b/src/fr/neatmonster/nocheatplus/checks/ViolationData.java @@ -150,5 +150,9 @@ public class ViolationData { public void setParameter(final ParameterName parameterName, String value){ if (parameters != null) parameters.put(parameterName, value); } + + public boolean needsParameters() { + return parameters != null; + } } diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java index 37ff2e6a..2c773f51 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java @@ -78,7 +78,7 @@ public class FastBreak extends Check { // TODO: maybe add one absolute penalty time for big amounts to stop breaking until then data.fastBreakVL += missingTime; final ViolationData vd = new ViolationData(this, player, data.fastBreakVL, missingTime, cc.fastBreakActions); - vd.setParameter(ParameterName.BLOCK_ID, "" + id); + if (vd.needsParameters()) vd.setParameter(ParameterName.BLOCK_ID, "" + id); cancel = executeActions(vd); } // else: still within contention limits. diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java b/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java index 6dcd7efa..0dfc397d 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java @@ -132,9 +132,11 @@ public class CreativeFly extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we // should cancel the event. final ViolationData vd = new ViolationData(this, player, data.creativeFlyVL, result, cc.creativeFlyActions); - vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ())); - vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ())); - vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", to.getLocation().distance(from.getLocation()))); + if (vd.needsParameters()){ + vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ())); + vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ())); + vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", to.getLocation().distance(from.getLocation()))); + } if (executeActions(vd)) // Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" // to allow the player to look somewhere else despite getting pulled back by NoCheatPlus. diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/Passable.java b/src/fr/neatmonster/nocheatplus/checks/moving/Passable.java index a2e1f48c..de3f7587 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/Passable.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/Passable.java @@ -29,7 +29,7 @@ public class Passable extends Check { // Return the reset position. data.passableVL += 1d; final ViolationData vd = new ViolationData(this, player, data.passableVL, 1, cc.passableActions); - vd.setParameter(ParameterName.BLOCK_ID, "" + toId); + if (vd.needsParameters()) vd.setParameter(ParameterName.BLOCK_ID, "" + toId); if (executeActions(vd)){ final Location newTo = from.getLocation(); newTo.setYaw(to.getYaw()); diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index 43cde8a4..db395013 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -330,9 +330,11 @@ public class SurvivalFly extends Check { // If the other plugins haven't decided to cancel the execution of the actions, then do it. If one of the // actions was a cancel, cancel it. final ViolationData vd = new ViolationData(this, player, data.survivalFlyVL, result, cc.survivalFlyActions); - vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ())); - vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ())); - vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", to.getLocation().distance(from.getLocation()))); + if (vd.needsParameters()){ + vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ())); + vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ())); + vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", to.getLocation().distance(from.getLocation()))); + } if (executeActions(vd)){ // Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" to // allow the player to look somewhere else despite getting pulled back by NoCheatPlus.