Get rid of the switch statements over enums altogether, just to be

sure.
This commit is contained in:
Evenprime 2011-12-05 22:19:45 +01:00
parent bb636d774f
commit 5900ba2275
18 changed files with 53 additions and 123 deletions

View File

@ -30,9 +30,7 @@ public abstract class BlockPlaceCheck extends Check {
@Override
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case PLACE_LOCATION: {
if(wildcard == ParameterName.PLACE_LOCATION) {
SimpleLocation l = player.getData().blockplace.blockPlaced;
if(l.isSet()) {
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
@ -41,7 +39,7 @@ public abstract class BlockPlaceCheck extends Check {
}
}
case PLACE_AGAINST: {
else if(wildcard == ParameterName.PLACE_AGAINST) {
SimpleLocation l = player.getData().blockplace.blockPlacedAgainst;
if(l.isSet()) {
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
@ -50,8 +48,7 @@ public abstract class BlockPlaceCheck extends Check {
}
}
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -24,14 +24,10 @@ public abstract class ChatCheck extends Check {
@Override
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case TEXT: {
if(wildcard == ParameterName.TEXT)
return player.getData().chat.message;
}
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -10,8 +10,8 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
import cc.co.evenprime.bukkit.nocheat.actions.types.ConsolecommandAction;
import cc.co.evenprime.bukkit.nocheat.actions.types.DummyAction;
import cc.co.evenprime.bukkit.nocheat.actions.types.LogAction;
import cc.co.evenprime.bukkit.nocheat.actions.types.SpecialAction;
import cc.co.evenprime.bukkit.nocheat.actions.types.ParameterName;
import cc.co.evenprime.bukkit.nocheat.actions.types.SpecialAction;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
@ -79,24 +79,17 @@ public abstract class Check {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case PLAYER:
if(wildcard == ParameterName.PLAYER)
return player.getName();
case CHECK:
else if(wildcard == ParameterName.CHECK)
return getName();
case LOCATION: {
else if(wildcard == ParameterName.LOCATION) {
Location l = player.getPlayer().getLocation();
return String.format(Locale.US, "%.2f,%.2f,%.2f", l.getX(), l.getY(), l.getZ());
}
case WORLD: {
} else if(wildcard == ParameterName.WORLD)
return player.getPlayer().getWorld().getName();
}
default:
else
return "Evenprime was lazy and forgot to define " + wildcard + ".";
}
}
}

View File

@ -34,25 +34,18 @@ public abstract class MovingCheck extends Check {
@Override
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case LOCATION: {
if(wildcard == ParameterName.LOCATION) {
PreciseLocation from = player.getData().moving.from;
return String.format(Locale.US, "%.2f,%.2f,%.2f", from.x, from.y, from.z);
}
case MOVEDISTANCE: {
} else if(wildcard == ParameterName.MOVEDISTANCE) {
PreciseLocation from = player.getData().moving.from;
PreciseLocation to = player.getData().moving.to;
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x - from.x, to.y - from.y, to.z - from.z);
}
case LOCATION_TO:
} else if(wildcard == ParameterName.LOCATION_TO) {
PreciseLocation to = player.getData().moving.to;
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x, to.y, to.z);
default:
} else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -81,14 +81,9 @@ public class DirectionCheck extends BlockBreakCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().blockbreak.directionVL);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -41,15 +41,10 @@ public class NoswingCheck extends BlockBreakCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().blockbreak.noswingVL);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -54,16 +54,11 @@ public class ReachCheck extends BlockBreakCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().blockbreak.reachVL);
case REACHDISTANCE:
else if(wildcard == ParameterName.REACHDISTANCE)
return String.format(Locale.US, "%.2f", player.getData().blockbreak.reachDistance);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -95,13 +95,9 @@ public class DirectionCheck extends BlockPlaceCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().blockplace.directionVL);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -55,16 +55,11 @@ public class ReachCheck extends BlockPlaceCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().blockplace.reachVL);
case REACHDISTANCE:
else if(wildcard == ParameterName.REACHDISTANCE)
return String.format(Locale.US, "%.2f", player.getData().blockplace.reachdistance);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -39,12 +39,9 @@ public class EmptyCheck extends ChatCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", player.getData().chat.emptyVL);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -55,12 +55,9 @@ public class SpamCheck extends ChatCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", player.getData().chat.spamVL);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -77,12 +77,9 @@ public class DirectionCheck extends FightCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().fight.directionVL);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -42,12 +42,9 @@ public class NoswingCheck extends FightCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().fight.noswingVL);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -42,12 +42,9 @@ public class SelfhitCheck extends FightCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().fight.selfhitVL);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -69,10 +69,10 @@ public class FlyingCheck extends MovingCheck {
}
resultHoriz *= 100;
// super simple, just check distance compared to max distance
resultVert = Math.max(0.0D, yDistance - data.vertFreedom - ccmoving.flyingSpeedLimitVertical) * 100;
result = resultHoriz + resultVert;
if(result > 0) {
@ -83,7 +83,7 @@ public class FlyingCheck extends MovingCheck {
data.runflyRunningTotalVL += resultHoriz;
data.runflyRunningFailed++;
}
if(resultVert > 0) {
data.runflyFlyingTotalVL += resultVert;
data.runflyFlyingFailed++;
@ -115,12 +115,9 @@ public class FlyingCheck extends MovingCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().moving.runflyVL);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -109,13 +109,11 @@ public class MorePacketsCheck extends MovingCheck {
@Override
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().moving.morePacketsVL);
case PACKETS:
else if(wildcard == ParameterName.PACKETS)
return String.valueOf(player.getData().moving.packets);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -106,13 +106,11 @@ public class NoFallCheck extends MovingCheck {
@Override
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().moving.nofallVL);
case FALLDISTANCE:
else if(wildcard == ParameterName.FALLDISTANCE)
return String.format(Locale.US, "%.2f", player.getData().moving.fallDistance);
default:
else
return super.getParameter(wildcard, player);
}
}
}

View File

@ -228,15 +228,12 @@ public class RunningCheck extends MovingCheck {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case CHECK:
if(wildcard == ParameterName.CHECK)
// Workaround for something until I find a better way to do it
return getName() + "." + player.getData().moving.checknamesuffix;
case VIOLATIONS:
else if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) player.getData().moving.runflyVL);
default:
else
return super.getParameter(wildcard, player);
}
}
}