Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
d0by1 committed Jun 27, 2024
1 parent 59a2b65 commit cbca692
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,17 @@ public static Hologram fromFile(final @NotNull String filePath) throws LocationP
*/
protected final Object visibilityMutex = new Object();

protected final @NonNull String name;
protected final String name;
protected boolean saveToFile;
protected final @Nullable FileConfig config;
protected final @NonNull Map<UUID, Integer> viewerPages = new ConcurrentHashMap<>();
protected final @NonNull Set<UUID> hidePlayers = ConcurrentHashMap.newKeySet();
protected final @NonNull Set<UUID> showPlayers = ConcurrentHashMap.newKeySet();
protected final FileConfig config;
protected final Map<UUID, Integer> viewerPages = new ConcurrentHashMap<>();
protected final Set<UUID> hidePlayers = ConcurrentHashMap.newKeySet();
protected final Set<UUID> showPlayers = ConcurrentHashMap.newKeySet();
protected boolean defaultVisibleState = true;
protected final @NonNull DList<HologramPage> pages = new DList<>();
protected final DList<HologramPage> pages = new DList<>();
protected boolean downOrigin = Settings.DEFAULT_DOWN_ORIGIN;
protected boolean alwaysFacePlayer = false;
private final @NonNull AtomicInteger tickCounter;
private final AtomicInteger tickCounter;

/*
* Constructors
Expand Down Expand Up @@ -334,7 +334,7 @@ public String toString() {
}

/**
* This method calls {@link #destroy()} before deleting the holograms file.
* This method calls {@link #destroy()} before deleting the hologram file.
*/
@Override
public void delete() {
Expand Down Expand Up @@ -499,7 +499,7 @@ public Hologram clone(@NonNull String name, @NonNull Location location, boolean
* @param clickType The type of the click.
* @return True if the click was handled, false otherwise.
*/
public boolean onClick(final @NonNull Player player, final int entityId, final @NonNull ClickType clickType) {
public boolean onClick(@NonNull Player player, int entityId, @NonNull ClickType clickType) {
HologramPage page = getPage(player);
if (page == null || !page.hasEntity(entityId)) {
return false;
Expand Down Expand Up @@ -783,7 +783,7 @@ public void hideClickableEntities(@NonNull Player player) {
return;
}

// Despawn clickable entities
// De-spawn clickable entities
NMS nms = NMS.getInstance();
page.getClickableEntityIds().forEach(id -> nms.hideFakeEntities(player, id));
}
Expand Down Expand Up @@ -820,43 +820,35 @@ public void teleportClickableEntitiesAll() {


/**
* Check whether the given player is in display range of this hologram object.
* Check whether the given player is in the display range of this hologram object.
*
* @param player Given player.
* @return Boolean whether the given player is in display range of this hologram object.
* @return Boolean whether the given player is in the display range of this hologram object.
*/
public boolean isInDisplayRange(@NonNull Player player) {
/*
* Some forks (e.g., Pufferfish) throw an exception, when we try to get
* the world of a location, which is not loaded. We catch this exception
* and return false, because the player is not in range.
*/
try {
if (player.getWorld().equals(location.getWorld())) {
return player.getLocation().distanceSquared(location) <= displayRange * displayRange;
}
} catch (Exception ignored) {
// Ignored
}
return false;
return isInRange(player, displayRange);
}

/**
* Check whether the given player is in update range of this hologram object.
* Check whether the given player is in the update range of this hologram object.
*
* @param player Given player.
* @return Boolean whether the given player is in update range of this hologram object.
* @return Boolean whether the given player is in the update range of this hologram object.
*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean isInUpdateRange(@NonNull Player player) {
return isInRange(player, updateRange);
}

private boolean isInRange(@NonNull Player player, double range) {
/*
* Some forks (e.g., Pufferfish) throw an exception, when we try to get
* the world of a location, which is not loaded. We catch this exception
* and return false, because the player is not in range.
* the world of a location, which is not loaded.
* We catch this exception and return false, because the player is not in range.
*/
try {
if (player.getWorld().equals(location.getWorld())) {
return player.getLocation().distanceSquared(location) <= updateRange * updateRange;
return player.getLocation().distanceSquared(location) <= range * range;
}
} catch (Exception ignored) {
// Ignored
Expand Down Expand Up @@ -893,7 +885,7 @@ public Set<Player> getViewerPlayers(int pageIndex) {
*/

/**
* Re-Align the lines in this hologram putting them to the right place.
* Re-Align the lines in this hologram, putting them to the right place.
* <p>
* This method is good to use after teleporting the hologram.
* </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@AllArgsConstructor
public class HologramItem {

public static final String ENCHANTED_INDICATOR = "!ENCHANTED";
private static final String ENCHANTED_INDICATOR = "!ENCHANTED";
private final String content;
private String nbt;
private String extras;
Expand Down

0 comments on commit cbca692

Please sign in to comment.