Extract duplicated switch statement in EntityUtil

This commit is contained in:
sauilitired 2018-11-15 00:08:32 +01:00
parent 06f64aeff0
commit a4a923c23c

View File

@ -4,6 +4,7 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flag.IntegerFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
/**
@ -12,35 +13,40 @@ import lombok.experimental.UtilityClass;
@UtilityClass
public final class EntityUtil {
private static int capNumeral(@NonNull final String flagName) {
int i;
switch (flagName) {
case "entity-cap":
i = 0;
break;
case "mob-cap":
i = 3;
break;
case "hostile-cap":
i = 2;
break;
case "animal-cap":
i = 1;
break;
case "vehicle-cap":
i = 4;
break;
case "misc-cap":
i = 5;
break;
default:
i = 0;
}
return i;
}
public static boolean checkEntity(Plot plot, IntegerFlag... flags) {
if (Settings.Done.RESTRICT_BUILDING && Flags.DONE.isSet(plot)) {
return true;
}
int[] mobs = null;
for (IntegerFlag flag : flags) {
int i;
switch (flag.getName()) {
case "entity-cap":
i = 0;
break;
case "mob-cap":
i = 3;
break;
case "hostile-cap":
i = 2;
break;
case "animal-cap":
i = 1;
break;
case "vehicle-cap":
i = 4;
break;
case "misc-cap":
i = 5;
break;
default:
i = 0;
}
final int i = capNumeral(flag.getName());
int cap = plot.getFlag(flag, Integer.MAX_VALUE);
if (cap == Integer.MAX_VALUE) {
continue;
@ -59,29 +65,7 @@ public final class EntityUtil {
}
if (mobs != null) {
for (IntegerFlag flag : flags) {
int i;
switch (flag.getName()) {
case "entity-cap":
i = 0;
break;
case "mob-cap":
i = 3;
break;
case "hostile-cap":
i = 2;
break;
case "animal-cap":
i = 1;
break;
case "vehicle-cap":
i = 4;
break;
case "misc-cap":
i = 5;
break;
default:
i = 0;
}
final int i = capNumeral(flag.getName());
mobs[i]++;
}
plot.setMeta("EntityCount", mobs);