faster checks

This commit is contained in:
2022-05-28 11:05:01 +02:00
parent 956abd5ef0
commit 2e0b137666
2 changed files with 12 additions and 5 deletions
@@ -16,13 +16,15 @@ public class JebSheep implements EntiddyInterface {
if (location.getWorld() == null) { if (location.getWorld() == null) {
throw new NullPointerException("World cannot be null"); throw new NullPointerException("World cannot be null");
} }
return location.getWorld().spawnEntity(location, EntityType.SHEEP, spawnReason, return location.getWorld().spawnEntity(location, EntityType.SHEEP, spawnReason, (entity) -> {
(entity) -> entity.customName(Component.text("jeb_"))); entity.customName(Component.text("jeb_"));
entity.setCustomNameVisible(false);
});
} }
@Override @Override
public boolean isInstance(@NotNull LivingEntity entity) { public boolean isInstance(@NotNull LivingEntity entity) {
if (!(entity instanceof Sheep)) return false; if (!(entity instanceof Sheep)) return false;
return entity.customName() != null && Objects.equals(entity.customName(), Component.text("jeb_")); return Objects.equals(entity.customName(), Component.text("jeb_"));
} }
} }
@@ -10,6 +10,8 @@ import org.bukkit.entity.Rabbit;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class Toast implements EntiddyInterface { public class Toast implements EntiddyInterface {
@Override @Override
@@ -18,12 +20,15 @@ public class Toast implements EntiddyInterface {
throw new NullPointerException("World cannot be null"); throw new NullPointerException("World cannot be null");
} }
return location.getWorld().spawnEntity(location, EntityType.RABBIT, spawnReason, return location.getWorld().spawnEntity(location, EntityType.RABBIT, spawnReason,
(entity) -> entity.customName(Component.text("Toast"))); (entity) -> {
entity.customName(Component.text("Toast"));
entity.setCustomNameVisible(false);
});
} }
@Override @Override
public boolean isInstance(@NotNull LivingEntity entity) { public boolean isInstance(@NotNull LivingEntity entity) {
if (!(entity instanceof Rabbit)) return false; if (!(entity instanceof Rabbit)) return false;
return entity.getCustomName() != null && entity.getCustomName().equals("Toast"); return Objects.equals(entity.customName(), Component.text("Toast"));
} }
} }