From b9a0361ab601074c145e6341b27132bc0202840e Mon Sep 17 00:00:00 2001 From: "Alex \"mcmonkey\" Goodwin" Date: Thu, 10 Feb 2022 09:48:28 -0800 Subject: [PATCH] assorted minor fixes --- .../denizen/objects/CuboidTag.java | 19 +++++++++---------- .../denizen/objects/EllipsoidTag.java | 9 +-------- .../denizen/objects/EntityTag.java | 2 +- .../denizenscript/denizen/objects/NPCTag.java | 2 +- .../denizen/objects/PlayerTag.java | 2 +- .../properties/entity/EntityColor.java | 13 ++++--------- .../denizen/utilities/Utilities.java | 3 --- 7 files changed, 17 insertions(+), 33 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/CuboidTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/CuboidTag.java index 409527f0eb..d88b2b01c4 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/CuboidTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/CuboidTag.java @@ -519,6 +519,7 @@ public List getBlocks_internal(Predicate test) { if (test == null) { return getBlockLocationsUnfiltered(true); } + int yMin = getWorld().getWorld().getMinHeight(), yMax = getWorld().getWorld().getMaxHeight(); int max = Settings.blockTagsMaxBlocks(); LocationTag loc; List list = new ArrayList<>(); @@ -530,18 +531,17 @@ public List getBlocks_internal(Predicate test) { int x_distance = pair.xDistance(); for (int x = 0; x != x_distance + 1; x++) { for (int y = 0; y != y_distance + 1; y++) { + if (loc_1.getY() + y < yMin || loc_1.getY() + y > yMax) { + continue; + } for (int z = 0; z != z_distance + 1; z++) { loc = new LocationTag(loc_1.clone().add(x, y, z)); - if (!Utilities.isLocationYSafe(loc)) { - continue; + if (index++ > max) { + return list; } if (test.test(loc)) { list.add(loc); } - index++; - if (index > max) { - return list; - } } } } @@ -559,12 +559,11 @@ public List getBlockLocationsUnfiltered(boolean doMax) { int z_distance = pair.zDistance(); int x_distance = pair.xDistance(); for (int x = 0; x <= x_distance; x++) { - for (int z = 0; z <= z_distance; z++) { - for (int y = 0; y <= y_distance; y++) { + for (int y = 0; y <= y_distance; y++) { + for (int z = 0; z <= z_distance; z++) { LocationTag loc = new LocationTag(loc_1.clone().add(x, y, z)); list.add(loc); - index++; - if (index > max) { + if (index++ > max) { return list; } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/EllipsoidTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/EllipsoidTag.java index 98cd194aac..eb77b61d29 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/EllipsoidTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/EllipsoidTag.java @@ -154,14 +154,7 @@ public EllipsoidTag(LocationTag center, LocationTag size) { @Override public ListTag getBlocks(Predicate test) { - List initial = getCuboidBoundary().getBlocks_internal(test); - ListTag list = new ListTag(); - for (LocationTag loc : initial) { - if (contains(loc)) { - list.addObject(loc); - } - } - return list; + return getCuboidBoundary().getBlocks(test == null ? this::contains : (l) -> (test.test(l) && contains(l))); } public List getBlockLocationsUnfiltered(boolean doMax) { diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java index 1099d0486a..9c49585d5c 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java @@ -1635,7 +1635,7 @@ else if (mtr.angle == BlockFace.EAST) { // Optionally, specify a maximum range to find the location from (defaults to 200). // This uses logic equivalent to <@link tag LocationTag.precise_cursor_on_block[(range)]>. // Note that this will return null if there is no block in range. - // This uses all blocks, ie it includes passable blocks like tall-grass and water. Use <@link tag EntityTag.cursor_on_solid> to include passable blocks. + // This uses all blocks, ie it includes passable blocks like tall-grass and water. Use <@link tag EntityTag.cursor_on_solid> to exclude passable blocks. // --> registerSpawnedOnlyTag(LocationTag.class, "cursor_on", (attribute, object) -> { double range = attribute.getDoubleParam(); diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java index daf932b5e1..c0ec99f6c2 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java @@ -822,7 +822,7 @@ else if (attribute.startsWith("list", 2)) { return null; } OfflinePlayer player = Bukkit.getOfflinePlayer(owner); - if (player.hasPlayedBefore()) { + if (player.isOnline() || player.hasPlayedBefore()) { return new PlayerTag(player); } return null; diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/PlayerTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/PlayerTag.java index 47b93e68e4..3a11fa0c5b 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/PlayerTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/PlayerTag.java @@ -183,7 +183,7 @@ public static boolean matches(String arg) { UUID uuid = UUID.fromString(arg); if (uuid != null) { OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); - if (player != null && player.hasPlayedBefore()) { + if (player != null && (player.isOnline() || player.hasPlayedBefore())) { return true; } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityColor.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityColor.java index 1b0c144d09..074f25f71f 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityColor.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityColor.java @@ -110,8 +110,7 @@ public String getColor(boolean includeDeprecated) { return null; } } - if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) - && MultiVersionHelper1_17.colorIsApplicable(type)) { + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && MultiVersionHelper1_17.colorIsApplicable(type)) { return MultiVersionHelper1_17.getColor(colored.getBukkitEntity()); } return null; @@ -158,8 +157,7 @@ public ListTag getAllowedColors() { case VILLAGER: return listForEnum(Villager.Type.values()); } - if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) - && MultiVersionHelper1_17.colorIsApplicable(type)) { + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && MultiVersionHelper1_17.colorIsApplicable(type)) { return MultiVersionHelper1_17.getAllowedColors(type); } return null; // includes Ocelot (deprecated) and arrow (ColorTag) @@ -257,7 +255,6 @@ public void adjust(Mechanism mechanism) { // --> if (mechanism.matches("color")) { EntityType type = colored.getBukkitEntityType(); - if (type == EntityType.HORSE && mechanism.requireObject(ListTag.class)) { ListTag list = mechanism.valueAsType(ListTag.class); Horse horse = (Horse) colored.getBukkitEntity(); @@ -290,8 +287,7 @@ else if (type == EntityType.OCELOT && mechanism.requireEnum(false, Ocelot.Type.v else if (type == EntityType.RABBIT && mechanism.requireEnum(false, Rabbit.Type.values())) { ((Rabbit) colored.getBukkitEntity()).setRabbitType(Rabbit.Type.valueOf(mechanism.getValue().asString().toUpperCase())); } - else if ((type == EntityType.LLAMA || type == EntityType.TRADER_LLAMA) - && mechanism.requireEnum(false, Llama.Color.values())) { + else if ((type == EntityType.LLAMA || type == EntityType.TRADER_LLAMA) && mechanism.requireEnum(false, Llama.Color.values())) { ((Llama) colored.getBukkitEntity()).setColor(Llama.Color.valueOf(mechanism.getValue().asString().toUpperCase())); } else if (type == EntityType.PARROT && mechanism.requireEnum(false, Parrot.Variant.values())) { @@ -381,8 +377,7 @@ else if (type == EntityType.VILLAGER && mechanism.requireEnum(false, Villager.Ty else if (type == EntityType.ARROW && mechanism.requireObject(ColorTag.class)) { ((Arrow) colored.getBukkitEntity()).setColor(mechanism.valueAsType(ColorTag.class).getColor()); } - else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) - && MultiVersionHelper1_17.colorIsApplicable(type)) { + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && MultiVersionHelper1_17.colorIsApplicable(type)) { MultiVersionHelper1_17.setColor(colored.getBukkitEntity(), mechanism); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/Utilities.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/Utilities.java index 4e7bbf692d..208853bdcf 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/Utilities.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/Utilities.java @@ -467,9 +467,6 @@ public static boolean isLocationYSafe(Location loc) { } public static boolean isLocationYSafe(double y, World world) { - if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_16)) { - return y >= 0 && y <= 255; - } if (world == null) { return true; }