mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-30 13:14:06 +01:00
Port deny-teleport
This commit is contained in:
parent
085dfbf735
commit
3df7d3cde9
@ -8,10 +8,12 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
|||||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flag.TeleportDenyFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalAttackFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalAttackFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalInteractFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalInteractFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockBurnFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockBurnFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockIgnitionFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockIgnitionFlag;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyTeleportFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DisablePhysicsFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DisablePhysicsFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag;
|
||||||
@ -818,7 +820,7 @@ import java.util.regex.Pattern;
|
|||||||
}
|
}
|
||||||
Plot plot = area.getPlot(location);
|
Plot plot = area.getPlot(location);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
final boolean result = Flags.DENY_TELEPORT.allowsTeleport(pp, plot);
|
final boolean result = DenyTeleportFlag.allowsTeleport(pp, plot);
|
||||||
// there is one possibility to still allow teleportation:
|
// there is one possibility to still allow teleportation:
|
||||||
// to is identical to the plot's home location, and untrusted-visit is true
|
// to is identical to the plot's home location, and untrusted-visit is true
|
||||||
// i.e. untrusted-visit can override deny-teleport
|
// i.e. untrusted-visit can override deny-teleport
|
||||||
|
@ -626,6 +626,7 @@ public enum Captions implements Caption {
|
|||||||
FLAG_DESCRIPTION_VEHICLE_USE("Set to `true` to allow guests to use vehicles in the plot.", "Flags"),
|
FLAG_DESCRIPTION_VEHICLE_USE("Set to `true` to allow guests to use vehicles in the plot.", "Flags"),
|
||||||
FLAG_DESCRIPTION_VILLAGER_INTERACT("Set to `true` to allow guests to interact with villagers in the plot.", "Flags"),
|
FLAG_DESCRIPTION_VILLAGER_INTERACT("Set to `true` to allow guests to interact with villagers in the plot.", "Flags"),
|
||||||
FLAG_DESCRIPTION_VINE_GROW("Set to `true` to allow vines to grow within the plot.", "Flags"),
|
FLAG_DESCRIPTION_VINE_GROW("Set to `true` to allow vines to grow within the plot.", "Flags"),
|
||||||
|
FLAG_DESCRIPTION_DENY_TELEPORT("Deny a certain group from teleporting to the plot. Available groups: members, nonmembers, trusted, nontrusted, nonowners", "Flags"),
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
//<editor-fold desc="Flag category errors">
|
//<editor-fold desc="Flag category errors">
|
||||||
FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"),
|
FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"),
|
||||||
|
@ -37,6 +37,4 @@ public final class Flags {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final TeleportDenyFlag DENY_TELEPORT = new TeleportDenyFlag("deny-teleport");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,10 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.flag;
|
package com.github.intellectualsites.plotsquared.plot.flag;
|
||||||
|
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
|
||||||
|
|
||||||
public class TeleportDenyFlag extends EnumFlag {
|
public class TeleportDenyFlag extends EnumFlag {
|
||||||
|
|
||||||
public TeleportDenyFlag(String name) {
|
public TeleportDenyFlag(String name) {
|
||||||
super(name, "trusted", "members", "nonmembers", "nontrusted", "nonowners");
|
super(name, "trusted", "members", "nonmembers", "nontrusted", "nonowners");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean allowsTeleport(PlotPlayer player, Plot plot) {
|
|
||||||
String value = plot.getFlag(this, null);
|
|
||||||
if (value == null || !plot.hasOwner()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
boolean result;
|
|
||||||
switch (plot.getFlag(this, null)) {
|
|
||||||
case "trusted":
|
|
||||||
result = !plot.getTrusted().contains(player.getUUID());
|
|
||||||
break;
|
|
||||||
case "members":
|
|
||||||
result = !plot.getMembers().contains(player.getUUID());
|
|
||||||
break;
|
|
||||||
case "nonmembers":
|
|
||||||
result = plot.isAdded(player.getUUID());
|
|
||||||
break;
|
|
||||||
case "nontrusted":
|
|
||||||
result = plot.getTrusted().contains(player.getUUID()) || plot
|
|
||||||
.isOwner(player.getUUID());
|
|
||||||
break;
|
|
||||||
case "nonowners":
|
|
||||||
result = plot.isOwner(player.getUUID());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return result || player.hasPermission("plots.admin.entry.denied");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Anima
|
|||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockBurnFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockBurnFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockIgnitionFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockIgnitionFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyExitFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyExitFlag;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyTeleportFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DeviceInteractFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DeviceInteractFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DisablePhysicsFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DisablePhysicsFlag;
|
||||||
@ -92,7 +93,6 @@ public final class GlobalFlagContainer extends FlagContainer {
|
|||||||
this.addFlag(DescriptionFlag.DESCRIPTION_FLAG_EMPTY);
|
this.addFlag(DescriptionFlag.DESCRIPTION_FLAG_EMPTY);
|
||||||
this.addFlag(GreetingFlag.GREETING_FLAG_EMPTY);
|
this.addFlag(GreetingFlag.GREETING_FLAG_EMPTY);
|
||||||
this.addFlag(FarewellFlag.FAREWELL_FLAG_EMPTY);
|
this.addFlag(FarewellFlag.FAREWELL_FLAG_EMPTY);
|
||||||
this.addFlag(PlotWeatherFlag.PLOT_WEATHER_FLAG_OFF);
|
|
||||||
this.addFlag(AnimalAttackFlag.ANIMAL_ATTACK_FALSE);
|
this.addFlag(AnimalAttackFlag.ANIMAL_ATTACK_FALSE);
|
||||||
this.addFlag(AnimalInteractFlag.ANIMAL_INTERACT_FALSE);
|
this.addFlag(AnimalInteractFlag.ANIMAL_INTERACT_FALSE);
|
||||||
this.addFlag(BlockBurnFlag.BLOCK_BURN_FALSE);
|
this.addFlag(BlockBurnFlag.BLOCK_BURN_FALSE);
|
||||||
@ -137,6 +137,10 @@ public final class GlobalFlagContainer extends FlagContainer {
|
|||||||
this.addFlag(InstabreakFlag.INSTABREAK_FALSE);
|
this.addFlag(InstabreakFlag.INSTABREAK_FALSE);
|
||||||
this.addFlag(InvincibleFlag.INVINCIBLE_FALSE);
|
this.addFlag(InvincibleFlag.INVINCIBLE_FALSE);
|
||||||
|
|
||||||
|
// Enum Flags
|
||||||
|
this.addFlag(PlotWeatherFlag.PLOT_WEATHER_FLAG_OFF);
|
||||||
|
this.addFlag(DenyTeleportFlag.DENY_TELEPORT_FLAG_NONE);
|
||||||
|
|
||||||
// Integer flags
|
// Integer flags
|
||||||
this.addFlag(AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
|
this.addFlag(AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
|
||||||
this.addFlag(EntityCapFlag.ENTITY_CAP_UNLIMITED);
|
this.addFlag(EntityCapFlag.ENTITY_CAP_UNLIMITED);
|
||||||
|
@ -0,0 +1,99 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.plot.flags.implementations;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class DenyTeleportFlag extends PlotFlag<DenyTeleportFlag.DeniedGroup, DenyTeleportFlag> {
|
||||||
|
|
||||||
|
public static final DenyTeleportFlag DENY_TELEPORT_FLAG_NONE = new DenyTeleportFlag(DeniedGroup.NONE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new flag instance.
|
||||||
|
*
|
||||||
|
* @param value Flag value
|
||||||
|
*/
|
||||||
|
protected DenyTeleportFlag(@NotNull DeniedGroup value) {
|
||||||
|
super(value, Captions.FLAG_CATEGORY_ENUM, Captions.FLAG_DESCRIPTION_DENY_TELEPORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public DenyTeleportFlag parse(@NotNull String input) throws FlagParseException {
|
||||||
|
final DeniedGroup group = DeniedGroup.fromString(input);
|
||||||
|
if (group == null) {
|
||||||
|
throw new FlagParseException(this, input, Captions.FLAG_ERROR_ENUM, "members, nonmembers,"
|
||||||
|
+ " trusted, nontrusted, nonowners");
|
||||||
|
}
|
||||||
|
return flagOf(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public DenyTeleportFlag merge(@NotNull DeniedGroup newValue) {
|
||||||
|
if (getValue().ordinal() < newValue.ordinal()) {
|
||||||
|
return flagOf(newValue);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String toString() {
|
||||||
|
return this.getValue().name();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getExample() {
|
||||||
|
return "trusted";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected DenyTeleportFlag flagOf(@NotNull DeniedGroup value) {
|
||||||
|
return new DenyTeleportFlag(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean allowsTeleport(PlotPlayer player, Plot plot) {
|
||||||
|
final DeniedGroup value = plot.getFlag(DenyTeleportFlag.class);
|
||||||
|
if (value == DeniedGroup.NONE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
final boolean result;
|
||||||
|
switch (value) {
|
||||||
|
case TRUSTED:
|
||||||
|
result = !plot.getTrusted().contains(player.getUUID());
|
||||||
|
break;
|
||||||
|
case MEMBERS:
|
||||||
|
result = !plot.getMembers().contains(player.getUUID());
|
||||||
|
break;
|
||||||
|
case NONMEMBERS:
|
||||||
|
result = plot.isAdded(player.getUUID());
|
||||||
|
break;
|
||||||
|
case NONTRUSTED:
|
||||||
|
result = plot.getTrusted().contains(player.getUUID()) || plot
|
||||||
|
.isOwner(player.getUUID());
|
||||||
|
break;
|
||||||
|
case NONOWNERS:
|
||||||
|
result = plot.isOwner(player.getUUID());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return result || player.hasPermission("plots.admin.entry.denied");
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DeniedGroup {
|
||||||
|
NONE,
|
||||||
|
MEMBERS,
|
||||||
|
TRUSTED,
|
||||||
|
NONMEMBERS,
|
||||||
|
NONTRUSTED,
|
||||||
|
NONOWNERS;
|
||||||
|
|
||||||
|
@Nullable public static DeniedGroup fromString(@NotNull final String string) {
|
||||||
|
for (final DeniedGroup group : values()) {
|
||||||
|
if (group.name().equalsIgnoreCase(string)) {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user