Skip to content

Commit

Permalink
Fix HologramClickEvent being called for invalid clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
d0by1 committed Jun 15, 2023
1 parent 6b9e7aa commit 9940d60
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,17 +498,20 @@ 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(@NonNull Player player, int entityId, @NonNull ClickType clickType) {
if (this.hasFlag(EnumFlag.DISABLE_ACTIONS)) {
public boolean onClick(final @NonNull Player player, final int entityId, final @NonNull ClickType clickType) {
HologramPage page = getPage(player);
if (page == null || !page.hasEntity(entityId)) {
return false;
}
HologramPage page = getPage(player);
boolean clickedThisHologram = page != null && page.hasEntity(entityId);

boolean eventNotCancelled = EventFactory.handleHologramClickEvent(player, this, page, clickType, entityId);
if (clickedThisHologram && eventNotCancelled) {
page.executeActions(player, clickType);
if (eventNotCancelled) {
if (!hasFlag(EnumFlag.DISABLE_ACTIONS)) {
page.executeActions(player, clickType);
}
return true;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public HologramLine spawnTemporaryHologramLine(@NonNull Location location, Strin
* @param clickType Click type.
* @return True if the click was processed, false otherwise.
*/
public boolean onClick(@NonNull Player player, int entityId, @NonNull ClickType clickType) {
public boolean onClick(final @NonNull Player player, final int entityId, final @NonNull ClickType clickType) {
final UUID uid = player.getUniqueId();

// Check if the player is on cooldown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,15 @@ public int getClickableEntityId(int index) {
return clickableEntityIds.get(index);
}

public boolean hasEntity(int eid) {
return clickableEntityIds.contains(eid) || lines.stream().anyMatch(line -> line.getEntityIds()[0] == eid || line.getEntityIds()[1] == eid);
public boolean hasEntity(final int eid) {
return clickableEntityIds.contains(eid) || lines.stream().anyMatch(line -> {
for (int entityId : line.getEntityIds()) {
if (entityId == eid) {
return true;
}
}
return false;
});
}

public void addAction(@NonNull ClickType clickType, @NonNull Action action) {
Expand Down

0 comments on commit 9940d60

Please sign in to comment.