Skip to content

Commit

Permalink
assorted minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 10, 2022
1 parent 005e4ab commit b9a0361
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 33 deletions.
Expand Up @@ -519,6 +519,7 @@ public List<LocationTag> getBlocks_internal(Predicate<Location> test) {
if (test == null) {
return getBlockLocationsUnfiltered(true);
}
int yMin = getWorld().getWorld().getMinHeight(), yMax = getWorld().getWorld().getMaxHeight();
int max = Settings.blockTagsMaxBlocks();
LocationTag loc;
List<LocationTag> list = new ArrayList<>();
Expand All @@ -530,18 +531,17 @@ public List<LocationTag> getBlocks_internal(Predicate<Location> 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;
}
}
}
}
Expand All @@ -559,12 +559,11 @@ public List<LocationTag> 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;
}
}
Expand Down
Expand Up @@ -154,14 +154,7 @@ public EllipsoidTag(LocationTag center, LocationTag size) {

@Override
public ListTag getBlocks(Predicate<Location> test) {
List<LocationTag> 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<LocationTag> getBlockLocationsUnfiltered(boolean doMax) {
Expand Down
Expand Up @@ -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();
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
}
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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())) {
Expand Down Expand Up @@ -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);
}
}
Expand Down
Expand Up @@ -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;
}
Expand Down

0 comments on commit b9a0361

Please sign in to comment.