mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 18:24:43 +02:00
Extract duplicated method declaration
This commit is contained in:
@ -0,0 +1,93 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.util;
|
||||
|
||||
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.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* Entity related general utility methods
|
||||
*/
|
||||
@UtilityClass
|
||||
public final class EntityUtil {
|
||||
|
||||
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;
|
||||
}
|
||||
int cap = plot.getFlag(flag, Integer.MAX_VALUE);
|
||||
if (cap == Integer.MAX_VALUE) {
|
||||
continue;
|
||||
}
|
||||
if (cap == 0) {
|
||||
return true;
|
||||
}
|
||||
if (mobs == null) {
|
||||
mobs = plot.countEntities();
|
||||
}
|
||||
if (mobs[i] >= cap) {
|
||||
plot.setMeta("EntityCount", mobs);
|
||||
plot.setMeta("EntityCountTime", System.currentTimeMillis());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
mobs[i]++;
|
||||
}
|
||||
plot.setMeta("EntityCount", mobs);
|
||||
plot.setMeta("EntityCountTime", System.currentTimeMillis());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user