mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Add road flag container
This commit is contained in:
parent
c5ec8e1931
commit
2910176b97
@ -343,8 +343,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
Plot plot = location.getOwnedPlot();
|
Plot plot = location.getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (area.isRoadRespectingGlobalFlags() && area.
|
if (area.isRoadFlags() && area.getRoadFlag(RedstoneFlag.class)) {
|
||||||
getFlag(RedstoneFlag.class)) {
|
|
||||||
event.setNewCurrent(0);
|
event.setNewCurrent(0);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -578,7 +577,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plot == null && !area.isRoadRespectingGlobalFlags()) {
|
if (plot == null && !area.isRoadFlags()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,8 +630,6 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
String perm;
|
String perm;
|
||||||
if (plot != null && plot.isAdded(plotPlayer.getUUID())) {
|
if (plot != null && plot.isAdded(plotPlayer.getUUID())) {
|
||||||
perm = "plots.admin.command.blocked-cmds.shared";
|
perm = "plots.admin.command.blocked-cmds.shared";
|
||||||
} else if (!area.isRoadRespectingGlobalFlags()) {
|
|
||||||
perm = "plots.admin.command.blocked-cmds.other";
|
|
||||||
} else {
|
} else {
|
||||||
perm = "plots.admin.command.blocked-cmds.road";
|
perm = "plots.admin.command.blocked-cmds.road";
|
||||||
}
|
}
|
||||||
@ -1745,13 +1742,11 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PlotArea area = pp.getPlotAreaAbs();
|
PlotArea area = pp.getPlotAreaAbs();
|
||||||
if (area != null && area.isRoadRespectingGlobalFlags() && area
|
if (area != null && area.isRoadFlags() && area
|
||||||
.getFlag(PreventCreativeCopyFlag.class)) {
|
.getRoadFlag(PreventCreativeCopyFlag.class)) {
|
||||||
final ItemStack newStack =
|
final ItemStack newStack =
|
||||||
new ItemStack(newItem.getType(), newItem.getAmount());
|
new ItemStack(newItem.getType(), newItem.getAmount());
|
||||||
event.setCursor(newStack);
|
event.setCursor(newStack);
|
||||||
plot.debug(player.getName()
|
|
||||||
+ " could not creative-copy an item because prevent-creative-copy = true");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -1869,7 +1864,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
Plot plot = location.getPlotAbs();
|
Plot plot = location.getPlotAbs();
|
||||||
BukkitPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
|
BukkitPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (!area.isRoadRespectingGlobalFlags() && !area.getFlag(MiscInteractFlag.class)
|
if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class)
|
||||||
&& !Permissions.hasPermission(pp, "plots.admin.interact.road")) {
|
&& !Permissions.hasPermission(pp, "plots.admin.interact.road")) {
|
||||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.road");
|
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.road");
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
@ -1883,8 +1878,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!plot.hasOwner() && !area.isRoadRespectingGlobalFlags() && !area
|
if (!plot.hasOwner() && !area.isRoadFlags() && !area
|
||||||
.getFlag(MiscInteractFlag.class)) {
|
.getRoadFlag(MiscInteractFlag.class)) {
|
||||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
|
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
|
||||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
||||||
"plots.admin.interact.unowned");
|
"plots.admin.interact.unowned");
|
||||||
@ -2235,7 +2230,9 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
|
|
||||||
Plot plot = location.getOwnedPlot();
|
Plot plot = location.getOwnedPlot();
|
||||||
if (plot == null || !plot.getFlag(BlockBurnFlag.class)) {
|
if (plot == null || !plot.getFlag(BlockBurnFlag.class)) {
|
||||||
|
if (plot != null) {
|
||||||
plot.debug("Block burning was cancelled because block-burn = false");
|
plot.debug("Block burning was cancelled because block-burn = false");
|
||||||
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2592,7 +2589,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
Player p = event.getPlayer();
|
Player p = event.getPlayer();
|
||||||
BukkitPlayer pp = BukkitUtil.getPlayer(p);
|
BukkitPlayer pp = BukkitUtil.getPlayer(p);
|
||||||
Plot plot = area.getPlot(location);
|
Plot plot = area.getPlot(location);
|
||||||
if (plot == null && !area.isRoadRespectingGlobalFlags()) {
|
if (plot == null && !area.isRoadFlags()) {
|
||||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
||||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
||||||
Captions.PERMISSION_ADMIN_INTERACT_ROAD);
|
Captions.PERMISSION_ADMIN_INTERACT_ROAD);
|
||||||
@ -2605,14 +2602,14 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
} else if ((plot != null && !plot.isAdded(pp.getUUID())) || area
|
} else if ((plot != null && !plot.isAdded(pp.getUUID())) || area
|
||||||
.isRoadRespectingGlobalFlags()) {
|
.isRoadFlags()) {
|
||||||
final Entity entity = event.getRightClicked();
|
final Entity entity = event.getRightClicked();
|
||||||
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
||||||
BukkitAdapter.adapt(entity.getType());
|
BukkitAdapter.adapt(entity.getType());
|
||||||
|
|
||||||
FlagContainer flagContainer;
|
FlagContainer flagContainer;
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
flagContainer = area.getFlagContainer();
|
flagContainer = area.getRoadFlagContainer();
|
||||||
} else {
|
} else {
|
||||||
flagContainer = plot.getFlagContainer();
|
flagContainer = plot.getFlagContainer();
|
||||||
}
|
}
|
||||||
@ -2839,9 +2836,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
stub = "unowned";
|
stub = "unowned";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean roadFlags = vArea != null ?
|
boolean roadFlags = vArea != null ? vArea.isRoadFlags() : dArea.isRoadFlags();
|
||||||
vArea.isRoadRespectingGlobalFlags() :
|
|
||||||
dArea.isRoadRespectingGlobalFlags();
|
|
||||||
PlotArea area = vArea != null ? vArea : dArea;
|
PlotArea area = vArea != null ? vArea : dArea;
|
||||||
|
|
||||||
Player player;
|
Player player;
|
||||||
@ -2913,7 +2908,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
.isAdded(plotPlayer.getUUID())) {
|
.isAdded(plotPlayer.getUUID())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (roadFlags && (area.getFlag(HostileAttackFlag.class) || area
|
} else if (roadFlags && (area.getRoadFlag(HostileAttackFlag.class) || area
|
||||||
.getFlag(PveFlag.class))) {
|
.getFlag(PveFlag.class))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -2932,7 +2927,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
.isAdded(plotPlayer.getUUID())) {
|
.isAdded(plotPlayer.getUUID())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (roadFlags && (area.getFlag(TamedAttackFlag.class) || area
|
} else if (roadFlags && (area.getRoadFlag(TamedAttackFlag.class) || area
|
||||||
.getFlag(PveFlag.class))) {
|
.getFlag(PveFlag.class))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -2957,7 +2952,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (roadFlags && area.getFlag(PvpFlag.class)) {
|
} else if (roadFlags && area.getRoadFlag(PvpFlag.class)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
|
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");
|
+ " because pve = false OR animal-attack = false");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (roadFlags && (area.getFlag(AnimalAttackFlag.class) || area
|
} else if (roadFlags && (area.getRoadFlag(AnimalAttackFlag.class) || area
|
||||||
.getFlag(PveFlag.class))) {
|
.getFlag(PveFlag.class))) {
|
||||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
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())) {
|
if (plot.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (roadFlags && area.getFlag(PveFlag.class)) {
|
} else if (roadFlags && area.getRoadFlag(PveFlag.class)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||||
@ -3014,7 +3009,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (vplot == null && roadFlags && area.getFlag(PveFlag.class)) {
|
if (vplot == null && roadFlags && area.getRoadFlag(PveFlag.class)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow
|
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();
|
Plot plot = location.getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (area.isRoadRespectingGlobalFlags() && area.getFlag(InvincibleFlag.class)) {
|
if (area.isRoadFlags() && area.getRoadFlag(InvincibleFlag.class)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -3150,7 +3145,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
Plot plot = location.getOwnedPlot();
|
Plot plot = location.getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (area.isRoadRespectingGlobalFlags() && area.getFlag(ItemDropFlag.class)) {
|
if (area.isRoadFlags() && area.getRoadFlag(ItemDropFlag.class)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -3176,7 +3171,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
Plot plot = location.getOwnedPlot();
|
Plot plot = location.getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (area.isRoadRespectingGlobalFlags() && area.getFlag(DropProtectionFlag.class)) {
|
if (area.isRoadFlags() && area.getRoadFlag(DropProtectionFlag.class)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -3198,7 +3193,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
Plot plot = location.getOwnedPlot();
|
Plot plot = location.getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (area.isRoadRespectingGlobalFlags() && area.getFlag(KeepInventoryFlag.class)) {
|
if (area.isRoadFlags() && area.getRoadFlag(KeepInventoryFlag.class)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -118,7 +118,7 @@ public abstract class PlotArea {
|
|||||||
@Getter private GameMode gameMode = GameModes.CREATIVE;
|
@Getter private GameMode gameMode = GameModes.CREATIVE;
|
||||||
@Getter private Map<String, Expression<Double>> prices = new HashMap<>();
|
@Getter private Map<String, Expression<Double>> prices = new HashMap<>();
|
||||||
@Getter(AccessLevel.PROTECTED) private List<String> schematics = new ArrayList<>();
|
@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 worldBorder = false;
|
||||||
private boolean useEconomy = false;
|
private boolean useEconomy = false;
|
||||||
private int hash;
|
private int hash;
|
||||||
@ -128,7 +128,9 @@ public abstract class PlotArea {
|
|||||||
/**
|
/**
|
||||||
* Area flag container
|
* 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());
|
new FlagContainer(GlobalFlagContainer.getInstance());
|
||||||
|
|
||||||
public PlotArea(@NotNull final String worldName, @Nullable final String id,
|
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.spawnEggs = config.getBoolean("event.spawn.egg");
|
||||||
this.spawnCustom = config.getBoolean("event.spawn.custom");
|
this.spawnCustom = config.getBoolean("event.spawn.custom");
|
||||||
this.spawnBreeding = config.getBoolean("event.spawn.breeding");
|
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);
|
loadConfiguration(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +450,7 @@ public abstract class PlotArea {
|
|||||||
options.put("world.max_height", this.getMaxBuildHeight());
|
options.put("world.max_height", this.getMaxBuildHeight());
|
||||||
options.put("world.min_height", this.getMinBuildHeight());
|
options.put("world.min_height", this.getMinBuildHeight());
|
||||||
options.put("world.gamemode", this.getGameMode().getName().toLowerCase());
|
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) {
|
if (this.getType() != PlotAreaType.NORMAL) {
|
||||||
options.put("generator.terrain", this.getTerrain());
|
options.put("generator.terrain", this.getTerrain());
|
||||||
@ -437,6 +472,9 @@ public abstract class PlotArea {
|
|||||||
config.set("flags.use",
|
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");
|
"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() {
|
@NotNull @Override public String toString() {
|
||||||
@ -1096,4 +1134,28 @@ public abstract class PlotArea {
|
|||||||
final PlotFlag<?, ?> flagInstance = this.flagContainer.getFlagErased(flagClass);
|
final PlotFlag<?, ?> flagInstance = this.flagContainer.getFlagErased(flagClass);
|
||||||
return FlagContainer.<T, V>castUnsafe(flagInstance).getValue();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user