From 3f23fcb67511e4aae60f530141e2c91ba9cef12c Mon Sep 17 00:00:00 2001 From: david Date: Thu, 23 Jan 2025 16:32:43 +0100 Subject: [PATCH] Refactor method positions for better organization Reordered methods in `PaperCharacter` to improve readability and maintainability. The functionality remains unchanged as all affected methods were simply relocated within the class. --- .../plugin/character/PaperCharacter.java | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/src/main/java/net/thenextlvl/character/plugin/character/PaperCharacter.java b/src/main/java/net/thenextlvl/character/plugin/character/PaperCharacter.java index 120a291..35a390e 100644 --- a/src/main/java/net/thenextlvl/character/plugin/character/PaperCharacter.java +++ b/src/main/java/net/thenextlvl/character/plugin/character/PaperCharacter.java @@ -89,40 +89,6 @@ public PaperCharacter(CharacterPlugin plugin, String name, EntityType type) { this.type = type; } - @Override - public boolean addAction(String name, ClickAction action) { - return !action.equals(actions.put(name, action)); - } - - @Override - public boolean addViewer(UUID player) { - if (!viewers.add(player)) return false; - if (entity == null || isVisibleByDefault()) return true; - var online = plugin.getServer().getPlayer(player); - if (online != null) online.showEntity(plugin, entity); - return true; - } - - @Override - public boolean addViewers(Collection players) { - return players.stream().map(this::addViewer).reduce(false, Boolean::logicalOr); - } - - @Override - public boolean canSee(Player player) { - if (entity == null || !isSpawned()) return false; - if (!player.getWorld().equals(entity.getWorld())) return false; - return isVisibleByDefault() || isViewer(player.getUniqueId()); - } - - @Override - public boolean despawn() { - if (entity == null) return false; - entity.remove(); - entity = null; - return true; - } - @Override public ClickAction getAction(String name) { return actions.get(name); @@ -198,6 +164,40 @@ public EntityType getType() { return getEntity().map(Entity::getWorld).orElse(null); } + @Override + public boolean addAction(String name, ClickAction action) { + return !action.equals(actions.put(name, action)); + } + + @Override + public boolean addViewer(UUID player) { + if (!viewers.add(player)) return false; + if (entity == null || isVisibleByDefault()) return true; + var online = plugin.getServer().getPlayer(player); + if (online != null) online.showEntity(plugin, entity); + return true; + } + + @Override + public boolean addViewers(Collection players) { + return players.stream().map(this::addViewer).reduce(false, Boolean::logicalOr); + } + + @Override + public boolean canSee(Player player) { + if (entity == null || !isSpawned()) return false; + if (!player.getWorld().equals(entity.getWorld())) return false; + return isVisibleByDefault() || isViewer(player.getUniqueId()); + } + + @Override + public boolean despawn() { + if (entity == null) return false; + entity.remove(); + entity = null; + return true; + } + @Override public boolean hasAI() { return ai; @@ -538,25 +538,6 @@ public void deserialize(Tag tag) throws ParserException { root.optional("visibleByDefault").map(Tag::getAsBoolean).ifPresent(this::setVisibleByDefault); } - public static boolean canHavePose(EntityType type, Pose pose) { - return switch (pose) { - case EMERGING, ROARING, DIGGING, SNIFFING -> type == EntityType.WARDEN; - case FALL_FLYING, SPIN_ATTACK, SWIMMING -> type == EntityType.PLAYER; - case INHALING, SHOOTING, SLIDING -> type == EntityType.BREEZE; - case LONG_JUMPING -> switch (type) { - case GOAT, FROG, BREEZE -> true; - default -> false; - }; - case SITTING -> type == EntityType.CAMEL; - case SNEAKING -> switch (type) { - case CAT, OCELOT, PLAYER -> true; - default -> false; - }; - case USING_TONGUE, CROAKING -> type == EntityType.FROG; - default -> true; - }; - } - protected void preSpawn(T entity) { if (entity instanceof Attributable attributable) { var scale = attributable.getAttribute(Attribute.SCALE); @@ -599,6 +580,25 @@ private File file() { return new File(plugin.savesFolder(), this.name + ".dat"); } + public static boolean canHavePose(EntityType type, Pose pose) { + return switch (pose) { + case EMERGING, ROARING, DIGGING, SNIFFING -> type == EntityType.WARDEN; + case FALL_FLYING, SPIN_ATTACK, SWIMMING -> type == EntityType.PLAYER; + case INHALING, SHOOTING, SLIDING -> type == EntityType.BREEZE; + case LONG_JUMPING -> switch (type) { + case GOAT, FROG, BREEZE -> true; + default -> false; + }; + case SITTING -> type == EntityType.CAMEL; + case SNEAKING -> switch (type) { + case CAT, OCELOT, PLAYER -> true; + default -> false; + }; + case USING_TONGUE, CROAKING -> type == EntityType.FROG; + default -> true; + }; + } + private class PaperTagOptions implements TagOptions { private @Nullable Brightness brightness = new Brightness(15, 0); private @Nullable Color backgroundColor = null;