Towny Classic

Towny Classic

3.2k Downloads

Towny Scheduler issues: repeating timer tasks don't run.

PainOchoco opened this issue ยท 6 comments

commented

What steps will reproduce the problem?

  1. Have notifications_appear_as set to action_bar
  2. Walk in a town
  3. Notice there is no notification in the action bar
Screen.Recording.2023-12-22.at.16.14.01.mov

What is the expected output?

The notification should be displayed

Towny version

0.100.0.12

Server version

purpur-2094 (1.20.2)

Please use Pastebin.com to link the following files

  # This setting controls where chunk notifications are displayed for players.
  # By default, notifications appear in the player's action bar.
  # Available options: action_bar, chat, bossbar, or none.
  notifications_appear_as: action_bar

  # This settings sets the duration the actionbar (The text above the inventory bar) or the bossbar lasts in seconds
  notification_actionbar_duration: "15"
commented

From the above branch this method is failing:

	private static void sendActionBarChunkNotification(Player player, Component msgComponent) {
		Towny.getPlugin().getLogger().info(String.format("ChunkNotificationUtil#sendActionBarChunkNotification | %s is being sent a sendActionBarChunkNotification.", player.getName()));
		int seconds = TownySettings.getInt(ConfigNodes.NOTIFICATION_DURATION);
		if (seconds > 3) {
			// Towny is showing the actionbar message longer than vanilla MC allows, using a scheduled task.
			// Cancel any older tasks running to prevent them from leaking over.
			if (playerActionTasks.get(player.getUniqueId()) != null)
				removePlayerActionTasks(player);
	
			AtomicInteger remainingSeconds = new AtomicInteger(seconds);
			final ScheduledTask task = Towny.getPlugin().getScheduler().runAsyncRepeating(() -> {
				TownyMessaging.sendActionBarMessageToPlayer(player, msgComponent);
				remainingSeconds.getAndDecrement();
				
				if (remainingSeconds.get() == 0 && playerActionTasks.containsKey(player.getUniqueId())) 
					removePlayerActionTasks(player);
			}, 0, 20L);

			playerActionTasks.put(player.getUniqueId(), task);
		} else {
			// Vanilla action bar displays for 3 seconds, so we shouldn't bother with any scheduling.
			TownyMessaging.sendActionBarMessageToPlayer(player, msgComponent);
		}
	}

seconds is 15.

The following method's debug message is never seen:

	public static void sendActionBarMessageToPlayer(Player player, Component component) {
		Towny.getPlugin().getLogger().info(String.format("%s is being sent an action bar component: '%s'", player.getName(), TownyComponents.plain(component)));
		Towny.getAdventure().player(player).sendActionBar(component); 
	}

Likewise, the /res toggle townborder smoke task is using the same scheduler:

	public static void toggleDrawSmokeTask(boolean on) {
		if (on && !isDrawSmokeTaskRunning()) {
			drawSmokeTask = plugin.getScheduler().runAsyncRepeating(new DrawSmokeTask(plugin), 1, 40);
		} else if (!on && isDrawSmokeTaskRunning()) {
			drawSmokeTask.cancel();
			drawSmokeTask = null;
		}
	}
commented

This server is also having issues with jail hours not deprecating which makes sense, since that uses the same type of task.

commented

Plot notifications in the action bar appear just fine for me on the latest versions of paper & towny

commented

Yeah I've been in talks with PainOchoco, giving him a test jar in order to debug. Something is definitely up on his production server, while the test server is not experiencing the issue. Only immediate difference between test and production is that test is on flatfile and prod server uses mysql.

Another symptom on the prod server is that /res toggle townborder doesn't work. Not sure how this is related yet.

commented

Daily taxes are not triggered too, and everything related to the Towny scheduler it seems.

commented

Purpur has been ruled out as a factor (it was not really a contender to begin with.)