2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.util;
|
2018-11-15 00:06:20 +01:00
|
|
|
|
2020-04-16 06:14:33 +02:00
|
|
|
import com.plotsquared.core.configuration.Settings;
|
2020-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.plot.Plot;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.plot.flag.PlotFlag;
|
|
|
|
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
2018-11-15 00:06:20 +01:00
|
|
|
|
2020-04-16 06:11:03 +02:00
|
|
|
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ANIMAL;
|
|
|
|
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ENTITY;
|
|
|
|
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MISC;
|
|
|
|
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MOB;
|
|
|
|
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER;
|
|
|
|
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
2020-04-12 19:30:50 +02:00
|
|
|
|
2018-11-15 00:06:20 +01:00
|
|
|
/**
|
|
|
|
* Entity related general utility methods
|
|
|
|
*/
|
2020-07-11 20:03:55 +02:00
|
|
|
public class EntityUtil {
|
2018-11-15 00:06:20 +01:00
|
|
|
|
2020-07-17 17:24:45 +02:00
|
|
|
private EntityUtil() {
|
|
|
|
throw new UnsupportedOperationException(
|
2021-01-09 22:28:41 +01:00
|
|
|
"This is a utility class and cannot be instantiated");
|
2020-07-17 17:24:45 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
private static int capNumeral(final @NonNull String flagName) {
|
2018-11-15 00:08:32 +01:00
|
|
|
int i;
|
|
|
|
switch (flagName) {
|
|
|
|
case "mob-cap":
|
2020-04-12 19:30:50 +02:00
|
|
|
i = CAP_MOB;
|
2018-11-15 00:08:32 +01:00
|
|
|
break;
|
|
|
|
case "hostile-cap":
|
2020-04-12 19:30:50 +02:00
|
|
|
i = CAP_MONSTER;
|
2018-11-15 00:08:32 +01:00
|
|
|
break;
|
|
|
|
case "animal-cap":
|
2020-04-12 19:30:50 +02:00
|
|
|
i = CAP_ANIMAL;
|
2018-11-15 00:08:32 +01:00
|
|
|
break;
|
|
|
|
case "vehicle-cap":
|
2020-04-12 19:30:50 +02:00
|
|
|
i = CAP_VEHICLE;
|
2018-11-15 00:08:32 +01:00
|
|
|
break;
|
|
|
|
case "misc-cap":
|
2020-04-12 19:30:50 +02:00
|
|
|
i = CAP_MISC;
|
2018-11-15 00:08:32 +01:00
|
|
|
break;
|
2019-05-18 00:49:09 +02:00
|
|
|
case "entity-cap":
|
2018-11-15 00:08:32 +01:00
|
|
|
default:
|
2020-04-12 19:30:50 +02:00
|
|
|
i = CAP_ENTITY;
|
2018-11-15 00:08:32 +01:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2022-01-20 12:39:40 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2020-02-24 18:42:02 +01:00
|
|
|
public static boolean checkEntity(Plot plot, PlotFlag<Integer, ?>... flags) {
|
|
|
|
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
2018-11-15 00:06:20 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
int[] mobs = null;
|
2020-02-24 18:42:02 +01:00
|
|
|
for (PlotFlag<Integer, ?> flag : flags) {
|
2018-11-15 00:08:32 +01:00
|
|
|
final int i = capNumeral(flag.getName());
|
2020-02-24 18:42:02 +01:00
|
|
|
int cap = plot.getFlag(flag);
|
2018-11-15 00:06:20 +01:00
|
|
|
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());
|
2020-06-21 15:50:49 +02:00
|
|
|
plot.debug("Prevented spawning of mob because it would exceed " + flag.getName());
|
2018-11-15 00:06:20 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mobs != null) {
|
2020-02-24 18:42:02 +01:00
|
|
|
for (PlotFlag<Integer, ?> flag : flags) {
|
2018-11-15 00:08:32 +01:00
|
|
|
final int i = capNumeral(flag.getName());
|
2018-11-15 00:06:20 +01:00
|
|
|
mobs[i]++;
|
|
|
|
}
|
|
|
|
plot.setMeta("EntityCount", mobs);
|
|
|
|
plot.setMeta("EntityCountTime", System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|