diff --git a/pom.xml b/pom.xml index ae632f1..fc12200 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.eldoria BigDoorsOpener - 2.1.1-BETA + 2.2-BETA BigDoorsOpener https://github.com/eldoriarpg/BigDoorOpener Open and close doors automatically on certain conditions diff --git a/src/main/java/de/eldoria/bigdoorsopener/BigDoorsOpener.java b/src/main/java/de/eldoria/bigdoorsopener/BigDoorsOpener.java index 25a1697..1783aee 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/BigDoorsOpener.java +++ b/src/main/java/de/eldoria/bigdoorsopener/BigDoorsOpener.java @@ -13,6 +13,7 @@ import de.eldoria.bigdoorsopener.doors.conditions.item.interacting.ItemClick; import de.eldoria.bigdoorsopener.doors.conditions.location.Proximity; import de.eldoria.bigdoorsopener.doors.conditions.location.Region; +import de.eldoria.bigdoorsopener.doors.conditions.location.SimpleRegion; import de.eldoria.bigdoorsopener.doors.conditions.standalone.Permission; import de.eldoria.bigdoorsopener.doors.conditions.standalone.Placeholder; import de.eldoria.bigdoorsopener.doors.conditions.standalone.Time; @@ -53,18 +54,16 @@ public class BigDoorsOpener extends JavaPlugin { private static Logger logger; + private static CachingJSEngine JS; + private static boolean placeholderEnabled = false; + @Getter + private static RegionContainer regionContainer = null; private final BukkitScheduler scheduler = Bukkit.getScheduler(); private Config config; private boolean initialized; private Localizer localizer; - private static CachingJSEngine JS; - private static boolean placeholderEnabled = false; - - // External instances. private BigDoors doors; - @Getter - private static RegionContainer regionContainer = null; private Commander commander; // scheduler @@ -74,6 +73,26 @@ public class BigDoorsOpener extends JavaPlugin { private WeatherListener weatherListener; private RegisterInteraction registerInteraction; + /** + * Get the plugin logger instance. + * + * @return plugin logger instance + */ + @SuppressWarnings("StaticVariableUsedBeforeInitialization") + @NotNull + public static Logger logger() { + return logger; + } + + @SuppressWarnings("StaticVariableUsedBeforeInitialization") + public static CachingJSEngine JS() { + return JS; + } + + public static boolean isPlaceholderEnabled() { + return placeholderEnabled; + } + @Override public void onDisable() { super.onDisable(); @@ -173,14 +192,20 @@ private void loadExternalSources() throws InstantiationException { // check if world guard is loaded if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) { logger().info("World Guard found. Trying to get a hook."); - regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer(); - if (regionContainer != null) { - logger().info("Hooked into world guard successfully."); + + String worldGuard = Bukkit.getPluginManager().getPlugin("WorldGuard").getDescription().getVersion(); + if (worldGuard.startsWith("7")) { + regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer(); + if (regionContainer != null) { + logger().info("Hooked into world guard successfully."); + } else { + logger().warning("Failed to hook into world guard."); + } } else { - logger().warning("Failed to hook into world guard."); + logger().info("Found legacy World Guard Version. Region conditions can't be used."); } } else { - logger().info("World guard not found. Region conditions cant be used."); + logger().info("World guard not found. Region conditions can't be used."); } // check if placeholder api is present. @@ -192,6 +217,9 @@ private void loadExternalSources() throws InstantiationException { } } + private void worldGuardHook() throws ClassNotFoundException { + } + /** * Register the serializer classes. * When a provided alias should be used the class needs the {@link org.bukkit.configuration.serialization.SerializableAs} @@ -208,6 +236,7 @@ private void buildSerializer() { ConfigurationSerialization.registerClass(ItemOwning.class, "itemOwningCondition"); ConfigurationSerialization.registerClass(Proximity.class, "proximityCondition"); ConfigurationSerialization.registerClass(Region.class, "regionCondition"); + ConfigurationSerialization.registerClass(SimpleRegion.class, "simpleRegionCondition"); ConfigurationSerialization.registerClass(Permission.class, "permissionCondition"); ConfigurationSerialization.registerClass(Time.class, "timeCondition"); ConfigurationSerialization.registerClass(Weather.class, "weatherCondition"); @@ -279,24 +308,4 @@ private Pair getDoorsVersion(String ver) { } return new Pair<>(versionString, buildString); } - - /** - * Get the plugin logger instance. - * - * @return plugin logger instance - */ - @SuppressWarnings("StaticVariableUsedBeforeInitialization") - @NotNull - public static Logger logger() { - return logger; - } - - @SuppressWarnings("StaticVariableUsedBeforeInitialization") - public static CachingJSEngine JS() { - return JS; - } - - public static boolean isPlaceholderEnabled() { - return placeholderEnabled; - } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/commands/BigDoorsOpenerCommand.java b/src/main/java/de/eldoria/bigdoorsopener/commands/BigDoorsOpenerCommand.java index a6b859d..92d8baf 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/commands/BigDoorsOpenerCommand.java +++ b/src/main/java/de/eldoria/bigdoorsopener/commands/BigDoorsOpenerCommand.java @@ -16,10 +16,12 @@ import de.eldoria.bigdoorsopener.doors.conditions.item.interacting.ItemClick; import de.eldoria.bigdoorsopener.doors.conditions.location.Proximity; import de.eldoria.bigdoorsopener.doors.conditions.location.Region; +import de.eldoria.bigdoorsopener.doors.conditions.location.SimpleRegion; import de.eldoria.bigdoorsopener.doors.conditions.standalone.Permission; import de.eldoria.bigdoorsopener.doors.conditions.standalone.Placeholder; import de.eldoria.bigdoorsopener.doors.conditions.standalone.Time; import de.eldoria.bigdoorsopener.doors.conditions.standalone.Weather; +import de.eldoria.bigdoorsopener.listener.registration.InteractionRegistrationObject; import de.eldoria.bigdoorsopener.listener.registration.RegisterInteraction; import de.eldoria.bigdoorsopener.scheduler.DoorChecker; import de.eldoria.bigdoorsopener.util.C; @@ -52,6 +54,7 @@ import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.util.BlockVector; @@ -69,6 +72,13 @@ import java.util.stream.Collectors; public class BigDoorsOpenerCommand implements TabExecutor { + private static final CachingJSEngine ENGINE; + // Tabcomplete utils + private static final String[] CONDITION_TYPES; + private static final String[] CONDITION_GROUPS; + private static final String[] PROXIMITY_FORM; + private static final String[] WEATHER_TYPE; + private static final String[] EVALUATOR_TYPES; private final BigDoorsOpener plugin; private final Commander commander; private final Config config; @@ -77,18 +87,8 @@ public class BigDoorsOpenerCommand implements TabExecutor { private final MessageSender messageSender; private final RegisterInteraction registerInteraction; private final RegionContainer regionContainer; - private final BukkitAudiences bukkitAudiences; - private static final CachingJSEngine ENGINE; - - // Tabcomplete utils - private static final String[] CONDITION_TYPES; - private static final String[] CONDITION_GROUPS; - private static final String[] PROXIMITY_FORM; - private static final String[] WEATHER_TYPE; - private static final String[] EVALUATOR_TYPES; - static { ENGINE = BigDoorsOpener.JS(); CONDITION_TYPES = Arrays.stream(ConditionType.values()) @@ -358,10 +358,10 @@ private boolean setCondition(Player player, String[] args) { return true; } - if (argumentsInvalid(player, args, 3, + if (argumentsInvalid(player, args, 2, "<" + localizer.getMessage("syntax.doorId") + "> <" - + localizer.getMessage("syntax.condition") + "> <" - + localizer.getMessage("syntax.conditionValues") + ">")) { + + localizer.getMessage("syntax.condition") + "> [" + + localizer.getMessage("syntax.conditionValues") + "]")) { return true; } @@ -395,8 +395,10 @@ private boolean setCondition(Player player, String[] args) { ConditionChain conditionChain = conditionalDoor.getConditionChain(); - - String[] conditionArgs = Arrays.copyOfRange(args, 2, args.length); + String[] conditionArgs = new String[0]; + if (args.length > 2) { + conditionArgs = Arrays.copyOfRange(args, 2, args.length); + } switch (type) { // @@ -556,6 +558,33 @@ private boolean setCondition(Player player, String[] args) { conditionChain.setLocation(new Region(region, player.getWorld())); messageSender.sendMessage(player, localizer.getMessage("setCondition.region")); break; + case SIMPLE_REGION: + messageSender.sendMessage(player, localizer.getMessage("setCondition.firstPoint")); + registerInteraction.register(player, new InteractionRegistrationObject() { + private String world; + private BlockVector first; + + @Override + public boolean register(PlayerInteractEvent event) { + if (event.getAction() != Action.LEFT_CLICK_BLOCK) { + return false; + } + BlockVector vec = event.getClickedBlock().getLocation().toVector().toBlockVector(); + if (first == null) { + world = event.getPlayer().getWorld().getName(); + first = vec; + event.setCancelled(true); + messageSender.sendMessage(player, localizer.getMessage("setCondition.secondPoint")); + return false; + } + conditionalDoor.getConditionChain().setLocation(new SimpleRegion(first, vec, world)); + config.safeConfig(); + event.setCancelled(true); + messageSender.sendMessage(player, localizer.getMessage("setCondition.simpleRegionRegisterd")); + return true; + } + }); + break; // permission case PERMISSION: if (argumentsInvalid(player, conditionArgs, 1, @@ -1437,6 +1466,10 @@ private boolean denyAccess(CommandSender sender, boolean silent, String... permi public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { String cmd = args[0]; + if (args.length > 10) { + return Collections.singletonList("(╯°□°)╯︵ ┻━┻"); + } + if (args.length == 1) { return ArrayUtil.startingWithInArray(cmd, new String[] {"help", "about", @@ -1450,7 +1483,7 @@ public List onTabComplete(CommandSender sender, Command command, String if (args.length == 2) { - return Collections.singletonList(localizer.getMessage("tabcomplete.doorId")); + return Collections.singletonList("<" + localizer.getMessage("syntax.doorId") + ">"); } if (args.length == 3) { return ArrayUtil.startingWithInArray(args[2], CONDITION_TYPES).collect(Collectors.toList()); @@ -1476,7 +1509,7 @@ public List onTabComplete(CommandSender sender, Command command, String } if (args.length == 5) { if (args[4].isEmpty()) { - return Arrays.asList("true", "false"); + return Arrays.asList("true", "false"); } return Arrays.asList("[" + localizer.getMessage("tabcomplete.consumed") + "]", "true", "false"); } @@ -1622,6 +1655,7 @@ public List onTabComplete(CommandSender sender, Command command, String return Collections.singletonList("<" + localizer.getMessage("syntax.amount") + ">"); } } + return Collections.emptyList(); } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/config/Config.java b/src/main/java/de/eldoria/bigdoorsopener/config/Config.java index 7714614..0ad7245 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/config/Config.java +++ b/src/main/java/de/eldoria/bigdoorsopener/config/Config.java @@ -35,6 +35,26 @@ public Config(Plugin plugin) { loadConfig(); } + private static void setIfAbsent(FileConfiguration config, String path, Object value) { + if (!config.isSet(path)) { + config.set(path, value); + } + } + + private static void setIfAbsent(ConfigurationSection section, String path, Object value) { + if (!section.isSet(path)) { + section.set(path, value); + } + } + + private static ConfigurationSection createSectionIfAbsent(FileConfiguration config, String path) { + ConfigurationSection section = config.getConfigurationSection(path); + if (section == null) { + return config.createSection(path); + } + return section; + } + public void loadConfig() { updateConfig(); reloadConfig(); @@ -186,24 +206,4 @@ public void safeConfig() { plugin.saveConfig(); } - private static void setIfAbsent(FileConfiguration config, String path, Object value) { - if (!config.isSet(path)) { - config.set(path, value); - } - } - - private static void setIfAbsent(ConfigurationSection section, String path, Object value) { - if (!section.isSet(path)) { - section.set(path, value); - } - } - - private static ConfigurationSection createSectionIfAbsent(FileConfiguration config, String path) { - ConfigurationSection section = config.getConfigurationSection(path); - if (section == null) { - return config.createSection(path); - } - return section; - } - } diff --git a/src/main/java/de/eldoria/bigdoorsopener/config/TimedDoor.java b/src/main/java/de/eldoria/bigdoorsopener/config/TimedDoor.java index 7163496..5545774 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/config/TimedDoor.java +++ b/src/main/java/de/eldoria/bigdoorsopener/config/TimedDoor.java @@ -68,6 +68,19 @@ public TimedDoor(long doorUID, String world, Vector position, String permission, this.invertOpen = invertOpen; } + public static TimedDoor deserialize(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + long doorUID = Long.parseLong(resolvingMap.getValue("doorUID")); + String world = resolvingMap.getValue("world"); + Vector position = resolvingMap.getValue("position"); + String permission = resolvingMap.getValue("permission"); + int ticksClose = resolvingMap.getValue("ticksClose"); + int ticksOpen = resolvingMap.getValue("ticksOpen"); + double range = resolvingMap.getValue("range"); + boolean invertOpen = resolvingMap.getValue("invertOpen"); + return new TimedDoor(doorUID, world, position, permission, ticksClose, ticksOpen, range, invertOpen); + } + @Override public Map serialize() { return SerializationUtil.newBuilder() @@ -82,19 +95,6 @@ public Map serialize() { .build(); } - public static TimedDoor deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - long doorUID = Long.parseLong(resolvingMap.getValue("doorUID")); - String world = resolvingMap.getValue("world"); - Vector position = resolvingMap.getValue("position"); - String permission = resolvingMap.getValue("permission"); - int ticksClose = resolvingMap.getValue("ticksClose"); - int ticksOpen = resolvingMap.getValue("ticksOpen"); - double range = resolvingMap.getValue("range"); - boolean invertOpen = resolvingMap.getValue("invertOpen"); - return new TimedDoor(doorUID, world, position,permission, ticksClose, ticksOpen, range, invertOpen); - } - public boolean shouldBeOpen(long fulltime) { // This is a permanent closed door. if (isPermanentlyClosed()) { diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/ConditionalDoor.java b/src/main/java/de/eldoria/bigdoorsopener/doors/ConditionalDoor.java index e781c66..1ef91b1 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/ConditionalDoor.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/ConditionalDoor.java @@ -3,7 +3,6 @@ import com.google.common.base.Objects; import de.eldoria.bigdoorsopener.BigDoorsOpener; import de.eldoria.bigdoorsopener.doors.conditions.ConditionChain; -import de.eldoria.bigdoorsopener.util.CachingJSEngine; import de.eldoria.eldoutilities.serialization.SerializationUtil; import de.eldoria.eldoutilities.serialization.TypeResolvingMap; import de.eldoria.eldoutilities.utils.EnumUtil; @@ -95,6 +94,19 @@ public ConditionalDoor(long doorUID, String world, Vector position, boolean inve this.stayOpen = stayOpen; } + public static ConditionalDoor deserialize(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + int doorUID = resolvingMap.getValue("doorUID"); + String world = resolvingMap.getValue("world"); + Vector position = resolvingMap.getValue("position"); + boolean invertOpen = resolvingMap.getValue("invertOpen"); + String evaluator = resolvingMap.getValue("evaluator"); + EvaluationType evaluationType = EnumUtil.parse(resolvingMap.getValue("evaluationType"), EvaluationType.class); + ConditionChain conditionChain = resolvingMap.getValue("conditionChain"); + int stayOpen = resolvingMap.getValue("stayOpen"); + return new ConditionalDoor(doorUID, world, position, invertOpen, evaluator, evaluationType, conditionChain, stayOpen); + } + /** * Get the state of the door. * @@ -165,19 +177,6 @@ public void evaluated() { .build(); } - public static ConditionalDoor deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - int doorUID = resolvingMap.getValue("doorUID"); - String world = resolvingMap.getValue("world"); - Vector position = resolvingMap.getValue("position"); - boolean invertOpen = resolvingMap.getValue("invertOpen"); - String evaluator = resolvingMap.getValue("evaluator"); - EvaluationType evaluationType = EnumUtil.parse(resolvingMap.getValue("evaluationType"), EvaluationType.class); - ConditionChain conditionChain = resolvingMap.getValue("conditionChain"); - int stayOpen = resolvingMap.getValue("stayOpen"); - return new ConditionalDoor(doorUID, world, position, invertOpen, evaluator, evaluationType, conditionChain, stayOpen); - } - public boolean requiresPlayerEvaluation() { return conditionChain.requiresPlayerEvaluation(); } diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/ConditionChain.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/ConditionChain.java index b81183a..e3757af 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/ConditionChain.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/ConditionChain.java @@ -50,6 +50,17 @@ private ConditionChain(Item item, Location location, Permission permission, Time this.weather = weather; } + public static ConditionChain deserialize(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + Item item = resolvingMap.getValue("item"); + Location location = resolvingMap.getValue("location"); + Permission permission = resolvingMap.getValue("permission"); + Time time = resolvingMap.getValue("time"); + Weather weather = resolvingMap.getValue("weather"); + Placeholder placeholder = resolvingMap.getValueOrDefault("placeholder", null); + return new ConditionChain(item, location, permission, time, weather, placeholder); + } + /** * Evaluates the conditions with an or operator. * @@ -161,17 +172,6 @@ public void opened(Player player) { } - public static ConditionChain deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - Item item = resolvingMap.getValue("item"); - Location location = resolvingMap.getValue("location"); - Permission permission = resolvingMap.getValue("permission"); - Time time = resolvingMap.getValue("time"); - Weather weather = resolvingMap.getValue("weather"); - Placeholder placeholder = resolvingMap.getValueOrDefault("placeholder", null); - return new ConditionChain(item, location, permission, time, weather, placeholder); - } - /** * Checks if all conditions are null. * diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/ConditionType.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/ConditionType.java index fbfd9fa..0457d69 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/ConditionType.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/ConditionType.java @@ -16,6 +16,7 @@ public enum ConditionType { ITEM_OWNING(ConditionGroup.ITEM), PROXIMITY(ConditionGroup.LOCATION), REGION(ConditionGroup.LOCATION), + SIMPLE_REGION(ConditionGroup.LOCATION), PERMISSION(ConditionGroup.PERMISSION), TIME(ConditionGroup.TIME), WEATHER(ConditionGroup.WEATHER), @@ -44,6 +45,15 @@ public static ConditionType getType(String keyType) { return null; } + public static ConditionGroup getType(Class keyClass) { + for (ConditionGroup value : ConditionGroup.values()) { + if (value.keyClass.isAssignableFrom(keyClass)) { + return value; + } + } + return null; + } + public enum ConditionGroup { ITEM("item", "item", "info.itemCondition", Item.class, Permissions.ITEM_CONDITION), LOCATION("location", "", "info.location", Location.class, Permissions.LOCATION_CONDITION), @@ -52,11 +62,11 @@ public enum ConditionGroup { WEATHER("weather", "weather", "info.weather", Weather.class, Permissions.WEATHER_CONDITION), PLACEHOLDER("placeholder", "placeholder", "info.placeholder", Placeholder.class, Permissions.PLACEHOLDER_CONDITION); - private final String baseSetCommand; public final String conditionParameter; public final String infoKey; public final Class keyClass; public final String permission; + private final String baseSetCommand; ConditionGroup(String conditionParameter, String baseSetCommand, String infoKey, Class keyClass, String permission) { this.conditionParameter = conditionParameter; @@ -70,13 +80,4 @@ public String getBaseSetCommand(ConditionalDoor door) { return "/bdo setCondition " + door.getDoorUID() + " " + baseSetCommand; } } - - public static ConditionGroup getType(Class keyClass) { - for (ConditionGroup value : ConditionGroup.values()) { - if (value.keyClass.isAssignableFrom(keyClass)) { - return value; - } - } - return null; - } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/Item.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/Item.java index 79406fb..6a7a218 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/Item.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/Item.java @@ -1,13 +1,12 @@ package de.eldoria.bigdoorsopener.doors.conditions.item; -import com.google.gson.Gson; import de.eldoria.bigdoorsopener.doors.ConditionalDoor; import de.eldoria.bigdoorsopener.doors.conditions.DoorCondition; import de.eldoria.bigdoorsopener.util.C; import de.eldoria.bigdoorsopener.util.TextColors; import de.eldoria.eldoutilities.crossversion.ServerVersion; -import de.eldoria.eldoutilities.crossversion.functionbuilder.VersionFunctionBuilder; import de.eldoria.eldoutilities.crossversion.function.VersionFunction; +import de.eldoria.eldoutilities.crossversion.functionbuilder.VersionFunctionBuilder; import de.eldoria.eldoutilities.localization.Localizer; import de.eldoria.eldoutilities.serialization.SerializationUtil; import lombok.Getter; diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/ItemHolding.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/ItemHolding.java index 8a0581a..1d2cb49 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/ItemHolding.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/ItemHolding.java @@ -25,6 +25,13 @@ public ItemHolding(ItemStack item, boolean consumed) { super(item, consumed); } + public static ItemClick deserialize(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + ItemStack stack = resolvingMap.getValue("item"); + boolean consumed = resolvingMap.getValue("consumed"); + return new ItemClick(stack, consumed); + } + @Override public void used(Player player) { if (!isConsumed()) return; @@ -50,11 +57,4 @@ public TextComponent getDescription(Localizer localizer) { public String getCreationCommand(ConditionalDoor door) { return SET_COMMAND + door.getDoorUID() + " itemHolding " + getItem().getAmount() + " " + isConsumed(); } - - public static ItemClick deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - ItemStack stack = resolvingMap.getValue("item"); - boolean consumed = resolvingMap.getValue("consumed"); - return new ItemClick(stack, consumed); - } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/ItemOwning.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/ItemOwning.java index 3646cd5..8f0d5a6 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/ItemOwning.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/ItemOwning.java @@ -36,7 +36,7 @@ public Boolean isOpen(Player player, World world, ConditionalDoor door, boolean return hasPlayerItemInInventory(player); } - public static ItemClick deserialize(Map map) { + public ItemClick deserialize(Map map) { TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); ItemStack stack = resolvingMap.getValue("item"); boolean consumed = resolvingMap.getValue("consumed"); diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/interacting/ItemBlock.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/interacting/ItemBlock.java index d512184..55c8fb1 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/interacting/ItemBlock.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/interacting/ItemBlock.java @@ -53,6 +53,14 @@ private ItemBlock(BlockVector position, ItemStack stack, boolean consumed) { this.position = position; } + public static ItemBlock deserialize(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + BlockVector position = resolvingMap.getValue("position"); + ItemStack stack = resolvingMap.getValue("item"); + boolean consumed = resolvingMap.getValue("consumed"); + return new ItemBlock(position, stack, consumed); + } + @Override public void used(Player player) { if (!isConsumed()) return; @@ -84,14 +92,6 @@ public void clicked(PlayerInteractEvent event, boolean available) { .build(); } - public static ItemBlock deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - BlockVector position = resolvingMap.getValue("position"); - ItemStack stack = resolvingMap.getValue("item"); - boolean consumed = resolvingMap.getValue("consumed"); - return new ItemBlock(position, stack, consumed); - } - @Override public TextComponent getDescription(Localizer localizer) { return TextComponent.builder( diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/interacting/ItemClick.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/interacting/ItemClick.java index 3a7b839..70fed89 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/interacting/ItemClick.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/item/interacting/ItemClick.java @@ -24,6 +24,13 @@ public ItemClick(ItemStack item, boolean consumed) { super(item, consumed); } + public static ItemClick deserialize(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + ItemStack stack = resolvingMap.getValue("item"); + boolean consumed = resolvingMap.getValue("consumed"); + return new ItemClick(stack, consumed); + } + @Override public Boolean isOpen(Player player, World world, ConditionalDoor door, boolean currentState) { if (hasPlayerItemInHand(player)) { @@ -53,12 +60,5 @@ public String getCreationCommand(ConditionalDoor door) { return SET_COMMAND + door.getDoorUID() + " itemClick " + getItem().getAmount() + " " + isConsumed(); } - public static ItemClick deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - ItemStack stack = resolvingMap.getValue("item"); - boolean consumed = resolvingMap.getValue("consumed"); - return new ItemClick(stack, consumed); - } - } diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Location.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Location.java index 7555310..5d6e8a8 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Location.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Location.java @@ -7,6 +7,5 @@ public interface Location extends DoorCondition { @Override default String getRemoveCommand(ConditionalDoor door) { return REMOVE_COMMAND + door.getDoorUID() + " location"; - } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Proximity.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Proximity.java index 43a5fad..e15f2b8 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Proximity.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Proximity.java @@ -33,6 +33,14 @@ public Proximity(Vector dimensions, ProximityForm proximityForm) { this.proximityForm = proximityForm; } + public Proximity(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + dimensions = resolvingMap.getValue("dimensions"); + String formString = resolvingMap.getValue("proximityForm"); + formString = formString.replaceAll("(?i)elipsoid", "ellipsoid"); + proximityForm = EnumUtil.parse(formString, ProximityForm.class); + } + @Override public Boolean isOpen(Player player, World world, ConditionalDoor door, boolean currentState) { return proximityForm.check.apply(door.getPosition(), player.getLocation().toVector(), dimensions); @@ -67,15 +75,6 @@ public String getCreationCommand(ConditionalDoor door) { .build(); } - public static Proximity deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - Vector vector = resolvingMap.getValue("dimensions"); - String formString = resolvingMap.getValue("proximityForm"); - formString = formString.replaceAll("(?i)elipsoid", "ellipsoid"); - ProximityForm proximityForm = EnumUtil.parse(formString, ProximityForm.class); - return new Proximity(vector, proximityForm); - } - public enum ProximityForm { CUBOID("conditionDesc.proximityForm.cuboid", (point, target, dimensions) -> { @@ -96,8 +95,8 @@ public enum ProximityForm { + Math.pow(target.getZ() - point.getZ(), 2) / Math.pow(dimensions.getZ(), 2) <= 1; }); - public final String localKey; public TriFunction check; + public final String localKey; ProximityForm(String localKey, TriFunction check) { this.localKey = localKey; diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Region.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Region.java index 36bad7e..1b58ff8 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Region.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/Region.java @@ -44,8 +44,27 @@ private Region(World world, ProtectedRegion region, String regionId, String worl this.regionId = regionId; } + public Region(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + worldName = resolvingMap.getValue("world"); + regionId = resolvingMap.getValue("region"); + if (BigDoorsOpener.getRegionContainer() != null) { + world = Bukkit.getWorld(worldName); + if (world == null) { + region = null; + return; + } + region = BigDoorsOpener.getRegionContainer().get(BukkitAdapter.adapt(world)).getRegion(regionId); + return; + } + world = null; + region = null; + BigDoorsOpener.logger().warning("A region key is used but world guard was not found."); + } + @Override public Boolean isOpen(Player player, World world, ConditionalDoor door, boolean currentState) { + if (world != this.world) return false; if (region == null) return null; return region.contains(BukkitAdapter.asBlockVector(player.getLocation())); } @@ -58,6 +77,9 @@ public TextComponent getDescription(Localizer localizer) { .append(TextComponent.newline()) .append(TextComponent.builder(localizer.getMessage("conditionDesc.region") + " ").color(C.baseColor)) .append(TextComponent.builder(regionId)).color(C.highlightColor) + .append(TextComponent.newline()) + .append(TextComponent.builder(localizer.getMessage("conditionDesc.world") + " ").color(C.baseColor)) + .append(TextComponent.builder(worldName)).color(C.highlightColor) .build(); } @@ -73,20 +95,4 @@ public String getCreationCommand(ConditionalDoor door) { .add("region", regionId) .build(); } - - public static Region deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - String worldName = resolvingMap.getValue("world"); - String regionName = resolvingMap.getValue("region"); - if (BigDoorsOpener.getRegionContainer() != null) { - World world = Bukkit.getWorld(worldName); - if (world == null) { - return new Region(null, null, regionName, worldName); - } - ProtectedRegion region = BigDoorsOpener.getRegionContainer().get(BukkitAdapter.adapt(world)).getRegion(regionName); - return new Region(world, region, regionName, worldName); - } - BigDoorsOpener.logger().warning("A region key is used but world guard was not found."); - return new Region(null, null, regionName, worldName); - } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/SimpleRegion.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/SimpleRegion.java new file mode 100644 index 0000000..982dce5 --- /dev/null +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/location/SimpleRegion.java @@ -0,0 +1,77 @@ +package de.eldoria.bigdoorsopener.doors.conditions.location; + +import de.eldoria.bigdoorsopener.doors.ConditionalDoor; +import de.eldoria.bigdoorsopener.doors.conditions.ConditionType; +import de.eldoria.bigdoorsopener.util.C; +import de.eldoria.bigdoorsopener.util.TextColors; +import de.eldoria.eldoutilities.localization.Localizer; +import de.eldoria.eldoutilities.localization.Replacement; +import de.eldoria.eldoutilities.serialization.SerializationUtil; +import de.eldoria.eldoutilities.serialization.TypeResolvingMap; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.World; +import org.bukkit.configuration.serialization.SerializableAs; +import org.bukkit.entity.Player; +import org.bukkit.util.BlockVector; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +@SerializableAs("simpleRegionCondition") +public class SimpleRegion implements Location { + private final BlockVector minimum; + private final BlockVector maximum; + private final String world; + + public SimpleRegion(BlockVector first, BlockVector second, String world) { + this.world = world; + this.minimum = BlockVector.getMinimum(first, second).toBlockVector(); + this.maximum = BlockVector.getMaximum(first, second).toBlockVector(); + } + + public SimpleRegion(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + minimum = resolvingMap.getValue("minimum"); + maximum = resolvingMap.getValue("maximum"); + world = resolvingMap.getValue("world"); + } + + @Override + public Boolean isOpen(Player player, World world, ConditionalDoor door, boolean currentState) { + if (!world.getName().equals(this.world)) return false; + + Vector pos = player.getLocation().toVector(); + if (pos.getX() > maximum.getX() || pos.getX() < minimum.getX()) return false; + if (pos.getY() > maximum.getY() || pos.getY() < minimum.getY()) return false; + return !(pos.getZ() > maximum.getZ()) && !(pos.getZ() < minimum.getZ()); + } + + @Override + public TextComponent getDescription(Localizer localizer) { + return TextComponent.builder( + localizer.getMessage("conditionDesc.type.simpleRegion", + Replacement.create("NAME", ConditionType.SIMPLE_REGION.conditionName))).color(TextColors.AQUA) + .append(TextComponent.newline()) + .append(TextComponent.builder(localizer.getMessage("conditionDesc.minPoint") + " ").color(C.baseColor)) + .append(TextComponent.builder(minimum.toString())).color(C.highlightColor) + .append(TextComponent.newline()) + .append(TextComponent.builder(localizer.getMessage("conditionDesc.maxPoint") + " ").color(C.baseColor)) + .append(TextComponent.builder(maximum.toString())).color(C.highlightColor) + .build(); + } + + @Override + public String getCreationCommand(ConditionalDoor door) { + return SET_COMMAND + door.getDoorUID() + " simpleRegion"; + } + + @Override + public @NotNull Map serialize() { + return SerializationUtil.newBuilder() + .add("minimum", minimum) + .add("maximum", maximum) + .add("world", world) + .build(); + } +} diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Permission.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Permission.java index 101ce2a..00ce6ae 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Permission.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Permission.java @@ -28,6 +28,11 @@ public Permission(String permission) { this.permission = permission; } + public Permission(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + permission = resolvingMap.getValue("permission"); + } + @Override public Boolean isOpen(Player player, World world, ConditionalDoor door, boolean currentState) { return player.hasPermission(permission); @@ -60,10 +65,4 @@ public String getRemoveCommand(ConditionalDoor door) { .add("permission", permission) .build(); } - - public static Permission deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - String permission = resolvingMap.getValue("permission"); - return new Permission(permission); - } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Placeholder.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Placeholder.java index 9fafd03..cce5ad2 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Placeholder.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Placeholder.java @@ -31,6 +31,11 @@ public Placeholder(String evaluator) { this.evaluator = evaluator; } + public Placeholder(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + evaluator = resolvingMap.getValue("evaluator"); + } + @Override public Boolean isOpen(Player player, World world, ConditionalDoor door, boolean currentState) { if (BigDoorsOpener.isPlaceholderEnabled()) { @@ -68,9 +73,4 @@ public String getRemoveCommand(ConditionalDoor door) { .add("evaluator", evaluator) .build(); } - - public static Placeholder deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - return new Placeholder(resolvingMap.getValue("evaluator")); - } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Time.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Time.java index e8a617b..399bc26 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Time.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Time.java @@ -53,6 +53,13 @@ public Time(int openTick, int closeTick, boolean forceState) { this.forceState = forceState; } + public Time(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + openTick = resolvingMap.getValue("openTick"); + closeTick = resolvingMap.getValue("closeTick"); + forceState = resolvingMap.getValue("forceState"); + } + @Override public Boolean isOpen(@Nullable Player player, World world, @Nullable ConditionalDoor door, boolean currentState) { return shouldBeOpen(world.getFullTime()); @@ -125,12 +132,4 @@ private long getDiff(long fullTime, long nextTime) { .build(); } - public static Time deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - int openTick = resolvingMap.getValue("openTick"); - int closeTick = resolvingMap.getValue("closeTick"); - boolean forceState = resolvingMap.getValue("forceState"); - return new Time(openTick, closeTick, forceState); - } - } diff --git a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Weather.java b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Weather.java index 2b7a2ec..1051dd7 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Weather.java +++ b/src/main/java/de/eldoria/bigdoorsopener/doors/conditions/standalone/Weather.java @@ -36,6 +36,12 @@ public Weather(WeatherType weatherType, boolean forceState) { this.weatherType = weatherType; } + public Weather(Map map) { + TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); + weatherType = EnumUtil.parse(resolvingMap.getValue("weatherType"), WeatherType.class); + forceState = resolvingMap.getValueOrDefault("forceState", false); + } + @Override public Boolean isOpen(@Nullable Player player, World world, ConditionalDoor door, boolean currentState) { Vector pos = door.getPosition(); @@ -122,11 +128,4 @@ private double getTemperature(World world, Vector pos) { .add("forceState", forceState) .build(); } - - public static Weather deserialize(Map map) { - TypeResolvingMap resolvingMap = SerializationUtil.mapOf(map); - WeatherType type = EnumUtil.parse(resolvingMap.getValue("weatherType"), WeatherType.class); - boolean forceState = resolvingMap.getValueOrDefault("forceState", false); - return new Weather(type, forceState); - } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/listener/WeatherListener.java b/src/main/java/de/eldoria/bigdoorsopener/listener/WeatherListener.java index b64b97f..a407ae5 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/listener/WeatherListener.java +++ b/src/main/java/de/eldoria/bigdoorsopener/listener/WeatherListener.java @@ -5,9 +5,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.weather.WeatherChangeEvent; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -19,18 +16,19 @@ public class WeatherListener implements Listener { private static Map weatherMap = new HashMap<>(); - @EventHandler - public void onWeatherChange(WeatherChangeEvent event) { - weatherMap.put(event.getWorld().getUID(), event.toWeatherState()); - } - /** * Get if its raining in a world. * Is only really correct if the weather changed after plugin initialization. + * * @param world world to check * @return true if its currently raining in the world */ public static boolean isRaining(World world) { return weatherMap.computeIfAbsent(world.getUID(), (k) -> world.hasStorm()); } + + @EventHandler + public void onWeatherChange(WeatherChangeEvent event) { + weatherMap.put(event.getWorld().getUID(), event.toWeatherState()); + } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/listener/registration/RegisterInteraction.java b/src/main/java/de/eldoria/bigdoorsopener/listener/registration/RegisterInteraction.java index 91f2540..cfe5617 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/listener/registration/RegisterInteraction.java +++ b/src/main/java/de/eldoria/bigdoorsopener/listener/registration/RegisterInteraction.java @@ -3,7 +3,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import java.util.HashMap; @@ -18,7 +17,6 @@ public class RegisterInteraction implements Listener { @EventHandler public void onPlayerInteraction(PlayerInteractEvent event) { - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (registerObjects.containsKey(event.getPlayer().getUniqueId())) { InteractionRegistrationObject registrationObject = registerObjects.get(event.getPlayer().getUniqueId()); boolean register = registrationObject.register(event); diff --git a/src/main/java/de/eldoria/bigdoorsopener/scheduler/BigDoorsAdapter.java b/src/main/java/de/eldoria/bigdoorsopener/scheduler/BigDoorsAdapter.java index 5eb4d8b..8f5b0bf 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/scheduler/BigDoorsAdapter.java +++ b/src/main/java/de/eldoria/bigdoorsopener/scheduler/BigDoorsAdapter.java @@ -29,7 +29,8 @@ public BigDoorsAdapter(BigDoors bigDoors, Localizer localizer) { /** * Set the state of the door. - * @param open true if the door should be open. + * + * @param open true if the door should be open. * @param door door to set the state * @return true if the door state was changed succesfully which is indicated by {@link BigDoors#toggleDoor(long)} */ @@ -73,14 +74,15 @@ protected boolean doorExists(ConditionalDoor door) { /** * Checks if a door is availbale. * A door is considered available if its not open and not busy + * * @param door door to check * @return true if the door is available */ - protected boolean isAvailableToOpen(ConditionalDoor door){ + protected boolean isAvailableToOpen(ConditionalDoor door) { return !isOpen(door) && !isBusy(door); } - protected boolean isBusy(ConditionalDoor door){ + protected boolean isBusy(ConditionalDoor door) { return getCommander().isDoorBusy(door.getDoorUID()); } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/util/C.java b/src/main/java/de/eldoria/bigdoorsopener/util/C.java index 7673589..f7f5599 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/util/C.java +++ b/src/main/java/de/eldoria/bigdoorsopener/util/C.java @@ -6,9 +6,8 @@ * Pure utility class to save some global constants. */ public final class C { + public static TextColor baseColor = TextColor.of(0, 170, 0); + public static TextColor highlightColor = TextColor.of(255, 170, 0); private C() { } - - public static TextColor baseColor = TextColor.of(0,170,0); - public static TextColor highlightColor = TextColor.of(255,170,0); } diff --git a/src/main/java/de/eldoria/bigdoorsopener/util/CachingJSEngine.java b/src/main/java/de/eldoria/bigdoorsopener/util/CachingJSEngine.java index 50d0b7d..26a112f 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/util/CachingJSEngine.java +++ b/src/main/java/de/eldoria/bigdoorsopener/util/CachingJSEngine.java @@ -18,8 +18,8 @@ * As a key the evaluated string is used. This assumes that a result is deterministic, which it should be anyway. */ public class CachingJSEngine { - private ScriptEngine engine; private final Cache cache; + private ScriptEngine engine; public CachingJSEngine(int cacheSize) { try { diff --git a/src/main/java/de/eldoria/bigdoorsopener/util/ConditionChainEvaluator.java b/src/main/java/de/eldoria/bigdoorsopener/util/ConditionChainEvaluator.java index 1e77ded..b98efac 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/util/ConditionChainEvaluator.java +++ b/src/main/java/de/eldoria/bigdoorsopener/util/ConditionChainEvaluator.java @@ -9,6 +9,44 @@ public class ConditionChainEvaluator { private Boolean current; + /** + * Evaluates the conditions with an or operator. + * + * @param player player to check the condition for + * @param world world the door is in + * @param door the acutal door which is checked + * @param currentState the current state of the door + * @param conditions conditions to evaluate + * @return the result of the chain evaluator + */ + public static boolean or(Player player, World world, ConditionalDoor door, boolean currentState, ConditionChain conditions) { + ConditionChainEvaluator evaluator = new ConditionChainEvaluator(); + for (DoorCondition doorCondition : conditions.getConditions()) { + evaluator.or(doorCondition, player, world, door, currentState); + } + + return evaluator.result(currentState); + } + + /** + * Evaluates the conditions with an AND operator. + * + * @param player player to check the condition for + * @param world world the door is in + * @param door the acutal door which is checked + * @param currentState the current state of the door + * @param conditions conditions to evaluate + * @return the result of the chain evaluator + */ + public static boolean and(Player player, World world, ConditionalDoor door, boolean currentState, ConditionChain conditions) { + ConditionChainEvaluator evaluator = new ConditionChainEvaluator(); + for (DoorCondition doorCondition : conditions.getConditions()) { + evaluator.and(doorCondition, player, world, door, currentState); + } + + return evaluator.result(currentState); + } + /** * Evaluates the condition of a door with an OR operator. * @@ -74,42 +112,4 @@ public ConditionChainEvaluator and(DoorCondition doorCondition, Player player, W public boolean result(boolean currentState) { return current == null ? currentState : current; } - - /** - * Evaluates the conditions with an or operator. - * - * @param player player to check the condition for - * @param world world the door is in - * @param door the acutal door which is checked - * @param currentState the current state of the door - * @param conditions conditions to evaluate - * @return the result of the chain evaluator - */ - public static boolean or(Player player, World world, ConditionalDoor door, boolean currentState, ConditionChain conditions) { - ConditionChainEvaluator evaluator = new ConditionChainEvaluator(); - for (DoorCondition doorCondition : conditions.getConditions()) { - evaluator.or(doorCondition, player, world, door, currentState); - } - - return evaluator.result(currentState); - } - - /** - * Evaluates the conditions with an AND operator. - * - * @param player player to check the condition for - * @param world world the door is in - * @param door the acutal door which is checked - * @param currentState the current state of the door - * @param conditions conditions to evaluate - * @return the result of the chain evaluator - */ - public static boolean and(Player player, World world, ConditionalDoor door, boolean currentState, ConditionChain conditions) { - ConditionChainEvaluator evaluator = new ConditionChainEvaluator(); - for (DoorCondition doorCondition : conditions.getConditions()) { - evaluator.and(doorCondition, player, world, door, currentState); - } - - return evaluator.result(currentState); - } } diff --git a/src/main/java/de/eldoria/bigdoorsopener/util/Permissions.java b/src/main/java/de/eldoria/bigdoorsopener/util/Permissions.java index a5a276c..334f304 100644 --- a/src/main/java/de/eldoria/bigdoorsopener/util/Permissions.java +++ b/src/main/java/de/eldoria/bigdoorsopener/util/Permissions.java @@ -6,9 +6,6 @@ */ public final class Permissions { - private Permissions() { - } - // permission to use all commands except reload public static final String USE = "bdo.command.use"; // permission to reload the plugin @@ -31,4 +28,6 @@ private Permissions() { public static final String PLACEHOLDER_CONDITION = "bdo.condition.placeholder"; // permission to access all conditions public static final String ALL_CONDITION = "bdo.condition.all"; + private Permissions() { + } } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index d02dece..467bce8 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -8,6 +8,8 @@ conditionDesc.evaluator=Evaluator conditionDesc.forceState=Force State: conditionDesc.item=Item: conditionDesc.keyhole=Block: +conditionDesc.maxPoint=Max Point: +conditionDesc.minPoint=Min Point: conditionDesc.open=Open at: conditionDesc.openWhen=Open when: conditionDesc.permission=Permission: @@ -25,8 +27,10 @@ conditionDesc.type.permission=Permission (%NAME%) conditionDesc.type.placeholder=Placeholder (%NAME%) conditionDesc.type.proximity=Proximity (%NAME%) conditionDesc.type.region=Region (%NAME%) +conditionDesc.type.simpleRegion=Simple Region (%NAME%) conditionDesc.type.time=Time (%NAME%) conditionDesc.type.weather=Weather (%NAME%) +conditionDesc.world=World: copyCondition.copiedAll=Copied all conditions from %SOURCE% to %TARGET%. copyCondition.copiedSingle=Copied condition %CONDITION% from %SOURCE% to %TARGET%. error.ambiguousDoorName=The entered door name is ambiguous. @@ -103,6 +107,7 @@ removeCondition.permission=Permission condition removed. removeCondition.placeholder=Placeholder condition removed. removeCondition.time=Time condition removed. removeCondition.weather=Weather condition removed. +setCondition.firstPoint=Please click on the first point. setCondition.itemBlockRegistered=Item condition set to Item Block. setCondition.itemClick=Item condition set to Item Click. setCondition.itemHolding=Item condition set to Item Holding. @@ -112,6 +117,8 @@ setCondition.permission=Permission condition set. setCondition.placeholder=Placeholder condition set. setCondition.proximity=Location condition set to Proximity. setCondition.region=Location condition set to Region. +setCondition.secondPoint=Please click on the second point. +setCondition.simpleRegionRegisterd=Location condition set to simple region. setCondition.time=Time condition set.\nOpen at: %OPEN%\nClose at: %CLOSE% setCondition.weather=Weather condition set.\nOpen at: %OPEN% setEvaluator.and=Using AND operator. Door will open if all conditions are true. diff --git a/src/main/resources/messages_de_DE.properties b/src/main/resources/messages_de_DE.properties index b15a7f6..b151251 100644 --- a/src/main/resources/messages_de_DE.properties +++ b/src/main/resources/messages_de_DE.properties @@ -8,6 +8,8 @@ conditionDesc.evaluator=Evaluator conditionDesc.forceState=Erzwinge Zustand: conditionDesc.item=Item: conditionDesc.keyhole=Schlüsselblock: +conditionDesc.maxPoint=Größter Punkt: +conditionDesc.minPoint=Kleinster Punkt: conditionDesc.open=Öffnet um: conditionDesc.openWhen=Öffnet wenn: conditionDesc.permission=Berechtigung: @@ -25,8 +27,10 @@ conditionDesc.type.permission=Permission (%NAME%) conditionDesc.type.placeholder=Placeholder (%NAME%) conditionDesc.type.proximity=Umgebung (%NAME%) conditionDesc.type.region=Region (%NAME%) +conditionDesc.type.simpleRegion=Einfache Region (%NAME%) conditionDesc.type.time=Zeit (%NAME%) conditionDesc.type.weather=Wetter (%NAME%) +conditionDesc.world=Welt: copyCondition.copiedAll=Alle Bedingungen von %SOURCE% wurden auf %TARGET% kopiert. copyCondition.copiedSingle=%CONDITION% wurde von %SOURCE% auf %TARGET% kopiert. error.ambiguousDoorName=Der Torname ist nicht eindeutig. @@ -103,6 +107,7 @@ removeCondition.permission=Berechtigungs Bedingung entfernt. removeCondition.placeholder=Placeholder Bedingung entfernt. removeCondition.time=Zeit Bedingung entfernt. removeCondition.weather=Wetter Bedingung entfernt. +setCondition.firstPoint=Bitte klicke auf den ersten Punkt. setCondition.itemBlockRegistered=Item Bedingung gesetzt auf Item Block. setCondition.itemClick=Item Bedingung gesetzt auf Item Klick. setCondition.itemHolding=Item Bedingung gesetzt auf Item Halten. @@ -112,6 +117,8 @@ setCondition.permission=Berechtigungs Bedingungen gesetzt. setCondition.placeholder=Placeholder Bedingung aktiviert. setCondition.proximity=Ortsbedinung gesetzt zu Umgebung. setCondition.region=Ortbedingung zu World Guard Region gesetzt. +setCondition.secondPoint=Bitte klicke auf den zweiten Punkt. +setCondition.simpleRegionRegisterd=Ortsbedingung gesetzt auf einfache Region. setCondition.time=Zeit Bedingung gesetzt.\nÖffnet um: %OPEN%\nSchließt um: %CLOSE% setCondition.weather=Wetter Bedingung gesetzt.\nÖffnet bei: %OPEN% setEvaluator.and=Nutze UND Operator. Tor wird sich öffnen, wenn alle Bedingungen zutreffen. @@ -142,6 +149,6 @@ tabcomplete.setTimed.close= tabcomplete.setTimed.open=<Öffnen bei Tick (0-24000) oder Zeit (HH:mm)> tabcomplete.validValues=Gültige Werte unregister.message=Tor %DOOR_NAME% wurde entfernt. -warning.chainIsEmpty=Dieses Tor hat derzeite keine Bedingungen. Der Zustand wird sich nicht verändern. Vielleicht möchtest du sie lieber entfernen. +warning.chainIsEmpty=Dieses Tor hat derzeit keine Bedingungen. Der Zustand wird sich nicht verändern. Vielleicht möchtest du sie lieber entfernen. warning.valueNotInEvaluator=Der Bedingung %VALUE% fehlt in der aktuellen Formel. Sie wird derzeit keinerlei Auswirkungen haben. warning.valueStillUsed=Die Bedingung %VALUE% wird noch in der Formel benutzt. Der berechnete Zustand wird eventuell nicht korrekt sein. diff --git a/src/main/resources/messages_en_US.properties b/src/main/resources/messages_en_US.properties index d02dece..467bce8 100644 --- a/src/main/resources/messages_en_US.properties +++ b/src/main/resources/messages_en_US.properties @@ -8,6 +8,8 @@ conditionDesc.evaluator=Evaluator conditionDesc.forceState=Force State: conditionDesc.item=Item: conditionDesc.keyhole=Block: +conditionDesc.maxPoint=Max Point: +conditionDesc.minPoint=Min Point: conditionDesc.open=Open at: conditionDesc.openWhen=Open when: conditionDesc.permission=Permission: @@ -25,8 +27,10 @@ conditionDesc.type.permission=Permission (%NAME%) conditionDesc.type.placeholder=Placeholder (%NAME%) conditionDesc.type.proximity=Proximity (%NAME%) conditionDesc.type.region=Region (%NAME%) +conditionDesc.type.simpleRegion=Simple Region (%NAME%) conditionDesc.type.time=Time (%NAME%) conditionDesc.type.weather=Weather (%NAME%) +conditionDesc.world=World: copyCondition.copiedAll=Copied all conditions from %SOURCE% to %TARGET%. copyCondition.copiedSingle=Copied condition %CONDITION% from %SOURCE% to %TARGET%. error.ambiguousDoorName=The entered door name is ambiguous. @@ -103,6 +107,7 @@ removeCondition.permission=Permission condition removed. removeCondition.placeholder=Placeholder condition removed. removeCondition.time=Time condition removed. removeCondition.weather=Weather condition removed. +setCondition.firstPoint=Please click on the first point. setCondition.itemBlockRegistered=Item condition set to Item Block. setCondition.itemClick=Item condition set to Item Click. setCondition.itemHolding=Item condition set to Item Holding. @@ -112,6 +117,8 @@ setCondition.permission=Permission condition set. setCondition.placeholder=Placeholder condition set. setCondition.proximity=Location condition set to Proximity. setCondition.region=Location condition set to Region. +setCondition.secondPoint=Please click on the second point. +setCondition.simpleRegionRegisterd=Location condition set to simple region. setCondition.time=Time condition set.\nOpen at: %OPEN%\nClose at: %CLOSE% setCondition.weather=Weather condition set.\nOpen at: %OPEN% setEvaluator.and=Using AND operator. Door will open if all conditions are true.