Skip to content

Commit

Permalink
Refactor method positions for better organization
Browse files Browse the repository at this point in the history
Reordered methods in `PaperCharacter` to improve readability and maintainability. The functionality remains unchanged as all affected methods were simply relocated within the class.
  • Loading branch information
NonSwag committed Jan 23, 2025
1 parent 5a58f21 commit 3f23fcb
Showing 1 changed file with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID> 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);
Expand Down Expand Up @@ -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<UUID> 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3f23fcb

Please sign in to comment.