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 @Override
public String getParameter(ParameterName wildcard, NoCheatPlayer player) { public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) { if(wildcard == ParameterName.PLACE_LOCATION) {
case PLACE_LOCATION: {
SimpleLocation l = player.getData().blockplace.blockPlaced; SimpleLocation l = player.getData().blockplace.blockPlaced;
if(l.isSet()) { if(l.isSet()) {
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z); 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; SimpleLocation l = player.getData().blockplace.blockPlacedAgainst;
if(l.isSet()) { if(l.isSet()) {
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z); 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); return super.getParameter(wildcard, player);
}
} }
} }

View File

@ -24,14 +24,10 @@ public abstract class ChatCheck extends Check {
@Override @Override
public String getParameter(ParameterName wildcard, NoCheatPlayer player) { public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) {
case TEXT: { if(wildcard == ParameterName.TEXT)
return player.getData().chat.message; return player.getData().chat.message;
} else
default:
return super.getParameter(wildcard, player); 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.ConsolecommandAction;
import cc.co.evenprime.bukkit.nocheat.actions.types.DummyAction; 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.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.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.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
@ -79,24 +79,17 @@ public abstract class Check {
public String getParameter(ParameterName wildcard, NoCheatPlayer player) { public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
switch (wildcard) { if(wildcard == ParameterName.PLAYER)
case PLAYER:
return player.getName(); return player.getName();
else if(wildcard == ParameterName.CHECK)
case CHECK:
return getName(); return getName();
else if(wildcard == ParameterName.LOCATION) {
case LOCATION: {
Location l = player.getPlayer().getLocation(); Location l = player.getPlayer().getLocation();
return String.format(Locale.US, "%.2f,%.2f,%.2f", l.getX(), l.getY(), l.getZ()); return String.format(Locale.US, "%.2f,%.2f,%.2f", l.getX(), l.getY(), l.getZ());
} } else if(wildcard == ParameterName.WORLD)
case WORLD: {
return player.getPlayer().getWorld().getName(); return player.getPlayer().getWorld().getName();
} else
default:
return "Evenprime was lazy and forgot to define " + wildcard + "."; return "Evenprime was lazy and forgot to define " + wildcard + ".";
}
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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