Skip to content

Commit

Permalink
- Fixed ChunkNotifications in the action_bar set to last for 3 or less
Browse files Browse the repository at this point in the history
seconds causing NPEs.
    - Closes #3923.
  • Loading branch information
LlmDl committed Apr 18, 2020
1 parent 6fa8e87 commit 95286eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
4 changes: 3 additions & 1 deletion resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4498,4 +4498,6 @@ v0.92.0.11:
- Should not be possible to duplicate any block ever again.
- Fixed loading townblocks that do not use the config's current town_block_size.
- These townblocks will not be loaded into memory, but will remain in the database in case someone switches their town_block_size without realizing what it would do.
- Closes #3924.
- Closes #3924.
- Fixed ChunkNotifications in the action_bar set to last for 3 or less seconds causing NPEs.
- Closes #3923.
29 changes: 15 additions & 14 deletions src/com/palmergames/bukkit/towny/listeners/TownyCustomListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,17 @@ public void onPlayerChangePlotEvent(PlayerChangePlotEvent event) {
System.out.println(" Player: " + player.getName() + " To: " + to.getWorldName() + "," + to.getX() + "," + to.getZ() + " From: " + from.getWorldName() + "," + from.getX() + "," + from.getZ());
e.printStackTrace();
}

int seconds = TownySettings.getInt(ConfigNodes.NOTIFICATION_ACTIONBAR_DURATION);
if (seconds > 3) { // Vanilla action bar displays for 3 seconds, so we shouldn't bother with any scheduling.
// Cancel any older tasks running to prevent them from leaking over.
if (playerActionTasks.get(player) != null) {
Bukkit.getScheduler().cancelTask(playerActionTasks.get(player));
playerActionTasks.remove(player);
}
if (msg != null) {
if (Towny.isSpigot && TownySettings.isNotificationsAppearingInActionBar()) {
int seconds = TownySettings.getInt(ConfigNodes.NOTIFICATION_ACTIONBAR_DURATION);
if (seconds > 3) {
// Vanilla action bar displays for 3 seconds, so we shouldn't bother with any scheduling.
// Cancel any older tasks running to prevent them from leaking over.
if (playerActionTasks.get(player) != null) {
Bukkit.getScheduler().cancelTask(playerActionTasks.get(player));
playerActionTasks.remove(player);
}

if (msg != null)
if (Towny.isSpigot && TownySettings.isNotificationsAppearingInActionBar()) {

final String message = msg;
AtomicInteger remainingSeconds = new AtomicInteger(seconds);
int taskID = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
Expand All @@ -103,10 +102,12 @@ public void onPlayerChangePlotEvent(PlayerChangePlotEvent event) {

playerActionTasks.put(player, taskID);
} else {
player.sendMessage(msg);
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(msg));
}
} else
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(msg));
} else {
player.sendMessage(msg);
}
}
}
} catch (NotRegisteredException e) {
// likely Citizens' NPC
Expand Down

0 comments on commit 95286eb

Please sign in to comment.