Add road flag container

This commit is contained in:
dordsor21 2020-07-01 14:53:57 +01:00
parent c5ec8e1931
commit 2910176b97
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
2 changed files with 90 additions and 33 deletions

View File

@ -343,8 +343,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadRespectingGlobalFlags() && area.
getFlag(RedstoneFlag.class)) {
if (area.isRoadFlags() && area.getRoadFlag(RedstoneFlag.class)) {
event.setNewCurrent(0);
}
return;
@ -578,7 +577,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
}
if (plot == null && !area.isRoadRespectingGlobalFlags()) {
if (plot == null && !area.isRoadFlags()) {
return;
}
@ -631,8 +630,6 @@ public class PlayerEvents extends PlotListener implements Listener {
String perm;
if (plot != null && plot.isAdded(plotPlayer.getUUID())) {
perm = "plots.admin.command.blocked-cmds.shared";
} else if (!area.isRoadRespectingGlobalFlags()) {
perm = "plots.admin.command.blocked-cmds.other";
} else {
perm = "plots.admin.command.blocked-cmds.road";
}
@ -1745,13 +1742,11 @@ public class PlayerEvents extends PlotListener implements Listener {
}
} else {
PlotArea area = pp.getPlotAreaAbs();
if (area != null && area.isRoadRespectingGlobalFlags() && area
.getFlag(PreventCreativeCopyFlag.class)) {
if (area != null && area.isRoadFlags() && area
.getRoadFlag(PreventCreativeCopyFlag.class)) {
final ItemStack newStack =
new ItemStack(newItem.getType(), newItem.getAmount());
event.setCursor(newStack);
plot.debug(player.getName()
+ " could not creative-copy an item because prevent-creative-copy = true");
}
}
return;
@ -1869,7 +1864,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Plot plot = location.getPlotAbs();
BukkitPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
if (plot == null) {
if (!area.isRoadRespectingGlobalFlags() && !area.getFlag(MiscInteractFlag.class)
if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class)
&& !Permissions.hasPermission(pp, "plots.admin.interact.road")) {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.road");
e.setCancelled(true);
@ -1883,8 +1878,8 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
}
if (!plot.hasOwner() && !area.isRoadRespectingGlobalFlags() && !area
.getFlag(MiscInteractFlag.class)) {
if (!plot.hasOwner() && !area.isRoadFlags() && !area
.getRoadFlag(MiscInteractFlag.class)) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
"plots.admin.interact.unowned");
@ -2235,7 +2230,9 @@ public class PlayerEvents extends PlotListener implements Listener {
Plot plot = location.getOwnedPlot();
if (plot == null || !plot.getFlag(BlockBurnFlag.class)) {
plot.debug("Block burning was cancelled because block-burn = false");
if (plot != null) {
plot.debug("Block burning was cancelled because block-burn = false");
}
event.setCancelled(true);
}
@ -2592,7 +2589,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Player p = event.getPlayer();
BukkitPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = area.getPlot(location);
if (plot == null && !area.isRoadRespectingGlobalFlags()) {
if (plot == null && !area.isRoadFlags()) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_ROAD)) {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_INTERACT_ROAD);
@ -2605,14 +2602,14 @@ public class PlayerEvents extends PlotListener implements Listener {
event.setCancelled(true);
}
} else if ((plot != null && !plot.isAdded(pp.getUUID())) || area
.isRoadRespectingGlobalFlags()) {
.isRoadFlags()) {
final Entity entity = event.getRightClicked();
final com.sk89q.worldedit.world.entity.EntityType entityType =
BukkitAdapter.adapt(entity.getType());
FlagContainer flagContainer;
if (plot == null) {
flagContainer = area.getFlagContainer();
flagContainer = area.getRoadFlagContainer();
} else {
flagContainer = plot.getFlagContainer();
}
@ -2839,9 +2836,7 @@ public class PlayerEvents extends PlotListener implements Listener {
stub = "unowned";
}
}
boolean roadFlags = vArea != null ?
vArea.isRoadRespectingGlobalFlags() :
dArea.isRoadRespectingGlobalFlags();
boolean roadFlags = vArea != null ? vArea.isRoadFlags() : dArea.isRoadFlags();
PlotArea area = vArea != null ? vArea : dArea;
Player player;
@ -2913,7 +2908,7 @@ public class PlayerEvents extends PlotListener implements Listener {
.isAdded(plotPlayer.getUUID())) {
return true;
}
} else if (roadFlags && (area.getFlag(HostileAttackFlag.class) || area
} else if (roadFlags && (area.getRoadFlag(HostileAttackFlag.class) || area
.getFlag(PveFlag.class))) {
return true;
}
@ -2932,7 +2927,7 @@ public class PlayerEvents extends PlotListener implements Listener {
.isAdded(plotPlayer.getUUID())) {
return true;
}
} else if (roadFlags && (area.getFlag(TamedAttackFlag.class) || area
} else if (roadFlags && (area.getRoadFlag(TamedAttackFlag.class) || area
.getFlag(PveFlag.class))) {
return true;
}
@ -2957,7 +2952,7 @@ public class PlayerEvents extends PlotListener implements Listener {
} else {
return true;
}
} else if (roadFlags && area.getFlag(PvpFlag.class)) {
} else if (roadFlags && area.getRoadFlag(PvpFlag.class)) {
return true;
}
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
@ -2973,7 +2968,7 @@ public class PlayerEvents extends PlotListener implements Listener {
+ " because pve = false OR animal-attack = false");
return true;
}
} else if (roadFlags && (area.getFlag(AnimalAttackFlag.class) || area
} else if (roadFlags && (area.getRoadFlag(AnimalAttackFlag.class) || area
.getFlag(PveFlag.class))) {
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
@ -2989,7 +2984,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (plot.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID())) {
return true;
}
} else if (roadFlags && area.getFlag(PveFlag.class)) {
} else if (roadFlags && area.getRoadFlag(PveFlag.class)) {
return true;
}
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
@ -3014,7 +3009,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return false;
}
}
if (vplot == null && roadFlags && area.getFlag(PveFlag.class)) {
if (vplot == null && roadFlags && area.getRoadFlag(PveFlag.class)) {
return true;
}
return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow
@ -3128,7 +3123,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadRespectingGlobalFlags() && area.getFlag(InvincibleFlag.class)) {
if (area.isRoadFlags() && area.getRoadFlag(InvincibleFlag.class)) {
event.setCancelled(true);
}
return;
@ -3150,7 +3145,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadRespectingGlobalFlags() && area.getFlag(ItemDropFlag.class)) {
if (area.isRoadFlags() && area.getRoadFlag(ItemDropFlag.class)) {
event.setCancelled(true);
}
return;
@ -3176,7 +3171,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadRespectingGlobalFlags() && area.getFlag(DropProtectionFlag.class)) {
if (area.isRoadFlags() && area.getRoadFlag(DropProtectionFlag.class)) {
event.setCancelled(true);
}
return;
@ -3198,7 +3193,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (area.isRoadRespectingGlobalFlags() && area.getFlag(KeepInventoryFlag.class)) {
if (area.isRoadFlags() && area.getRoadFlag(KeepInventoryFlag.class)) {
event.setCancelled(true);
}
return;

View File

@ -118,7 +118,7 @@ public abstract class PlotArea {
@Getter private GameMode gameMode = GameModes.CREATIVE;
@Getter private Map<String, Expression<Double>> prices = new HashMap<>();
@Getter(AccessLevel.PROTECTED) private List<String> schematics = new ArrayList<>();
@Getter private boolean roadRespectingGlobalFlags = false;
@Getter private boolean roadFlags = false;
private boolean worldBorder = false;
private boolean useEconomy = false;
private int hash;
@ -128,7 +128,9 @@ public abstract class PlotArea {
/**
* Area flag container
*/
@Getter private FlagContainer flagContainer =
@Getter private final FlagContainer flagContainer =
new FlagContainer(GlobalFlagContainer.getInstance());
@Getter private final FlagContainer roadFlagContainer =
new FlagContainer(GlobalFlagContainer.getInstance());
public PlotArea(@NotNull final String worldName, @Nullable final String id,
@ -371,7 +373,40 @@ public abstract class PlotArea {
this.spawnEggs = config.getBoolean("event.spawn.egg");
this.spawnCustom = config.getBoolean("event.spawn.custom");
this.spawnBreeding = config.getBoolean("event.spawn.breeding");
this.roadRespectingGlobalFlags = config.getBoolean("road.respect-global-flags");
List<String> roadflags = config.getStringList("flags.default");
if (roadflags.isEmpty()) {
roadflags = config.getStringList("road.flags");
if (roadflags.isEmpty()) {
roadflags = new ArrayList<>();
ConfigurationSection section = config.getConfigurationSection("road.flags");
Set<String> keys = section.getKeys(false);
for (String key : keys) {
if (!"default".equals(key)) {
roadflags.add(key + ';' + section.get(key));
}
}
}
}
this.getRoadFlagContainer().addAll(parseFlags(roadflags));
StringBuilder roadFlagBuilder = new StringBuilder();
Collection<PlotFlag<?, ?>> roadFlagCollection = this.getFlagContainer().getFlagMap().values();
if (roadFlagCollection.isEmpty()) {
roadFlagBuilder.append(Captions.NONE.getTranslated());
} else {
roadFlags = true;
String prefix = " ";
for (final PlotFlag<?, ?> flag : roadFlagCollection) {
Object value = flag.toString();
roadFlagBuilder.append(prefix).append(CaptionUtility
.format(null, Captions.PLOT_FLAG_LIST.getTranslated(), flag.getName(),
CaptionUtility.formatRaw(null, value.toString(), "")));
prefix = ", ";
}
}
PlotSquared.log(Captions.PREFIX + "&3 - road flags: &7" + roadFlagBuilder.toString());
loadConfiguration(config);
}
@ -415,7 +450,7 @@ public abstract class PlotArea {
options.put("world.max_height", this.getMaxBuildHeight());
options.put("world.min_height", this.getMinBuildHeight());
options.put("world.gamemode", this.getGameMode().getName().toLowerCase());
options.put("road.respect-global-flags", this.isRoadRespectingGlobalFlags());
options.put("road.flags.default", null);
if (this.getType() != PlotAreaType.NORMAL) {
options.put("generator.terrain", this.getTerrain());
@ -437,6 +472,9 @@ public abstract class PlotArea {
config.set("flags.use",
"63,64,68,69,71,77,96,143,167,193,194,195,196,197,77,143,69,70,72,147,148,107,183,184,185,186,187,132");
}
if (!config.contains("road.flags")) {
config.set("road.flags.liquid-flow", false);
}
}
@NotNull @Override public String toString() {
@ -1096,4 +1134,28 @@ public abstract class PlotArea {
final PlotFlag<?, ?> flagInstance = this.flagContainer.getFlagErased(flagClass);
return FlagContainer.<T, V>castUnsafe(flagInstance).getValue();
}
/**
* Get the value associated with the specified road flag. This will look at
* the default values stored in {@link GlobalFlagContainer}.
*
* @param flagClass The flag type (Class)
* @return The flag value
*/
public <T> T getRoadFlag(final Class<? extends PlotFlag<T, ?>> flagClass) {
return this.roadFlagContainer.getFlag(flagClass).getValue();
}
/**
* Get the value associated with the specified road flag. This will look at
* the default values stored in {@link GlobalFlagContainer}.
*
* @param flag The flag type (Any instance of the flag)
* @return The flag value
*/
public <T, V extends PlotFlag<T, ?>> T getRoadFlag(final V flag) {
final Class<?> flagClass = flag.getClass();
final PlotFlag<?, ?> flagInstance = this.roadFlagContainer.getFlagErased(flagClass);
return FlagContainer.<T, V>castUnsafe(flagInstance).getValue();
}
}