command and teleport tag fix folia

This commit is contained in:
rockyhawk64 2025-10-12 14:31:00 +11:00
parent 7d27cc133b
commit 732995f2f2
4 changed files with 16 additions and 13 deletions

View File

@ -70,7 +70,10 @@ public class CommandRunner {
} }
// Run the command // Run the command
runCommand(panel, player, command); Bukkit.getGlobalRegionScheduler().run(
ctx.plugin,
task -> runCommand(panel, player, command)
);
// Move to the next command // Move to the next command
runCommands(panel, player, commands, index + 1); runCommands(panel, player, commands, index + 1);

View File

@ -47,7 +47,7 @@ public class TeleportTag implements CommandTagResolver {
} }
Location teleportLocation = new Location(teleportedWorld, x, y, z, yaw, pitch); Location teleportLocation = new Location(teleportedWorld, x, y, z, yaw, pitch);
if (teleportedPlayer != null) { if (teleportedPlayer != null) {
teleportedPlayer.teleport(teleportLocation); player.teleportAsync(teleportLocation);
} }
} catch (Exception ex) { } catch (Exception ex) {
ctx.text.sendError(player, Message.TELEPORT_ERROR); ctx.text.sendError(player, Message.TELEPORT_ERROR);

View File

@ -52,10 +52,10 @@ public abstract class Panel {
// Checks for opening fresh panels // Checks for opening fresh panels
public boolean canOpen(Player p, Context ctx) { public boolean canOpen(Player p, Context ctx) {
// Do not open if user is in cooldown period // Do not open if user is in cooldown period
NamespacedKey keyTime = new NamespacedKey(ctx.plugin, "last_open_tick"); NamespacedKey keyTime = new NamespacedKey(ctx.plugin, "last_open_time");
Integer lastOpenTick = p.getPersistentDataContainer().get(keyTime, PersistentDataType.INTEGER); Long lastOpenTime = p.getPersistentDataContainer().get(keyTime, PersistentDataType.LONG);
int cooldownTicks = ctx.fileHandler.config.getInt("cooldown-ticks"); long cooldownMillis = ctx.fileHandler.config.getLong("cooldown-ticks") * 50L;
if (lastOpenTick != null && Bukkit.getCurrentTick() - lastOpenTick < cooldownTicks) { if (lastOpenTime != null && System.currentTimeMillis() - lastOpenTime < cooldownMillis) {
ctx.text.sendError(p, Message.COOLDOWN_ERROR); ctx.text.sendError(p, Message.COOLDOWN_ERROR);
return false; return false;
} }
@ -69,11 +69,11 @@ public abstract class Panel {
public void updatePanelData(Context ctx, Player p) { public void updatePanelData(Context ctx, Player p) {
NamespacedKey keyCurrent = new NamespacedKey(ctx.plugin, "current"); NamespacedKey keyCurrent = new NamespacedKey(ctx.plugin, "current");
NamespacedKey keyPrevious = new NamespacedKey(ctx.plugin, "previous"); NamespacedKey keyPrevious = new NamespacedKey(ctx.plugin, "previous");
NamespacedKey keyTick = new NamespacedKey(ctx.plugin, "last_open_tick"); NamespacedKey keyMillis = new NamespacedKey(ctx.plugin, "last_open_time");
PersistentDataContainer container = p.getPersistentDataContainer(); PersistentDataContainer container = p.getPersistentDataContainer();
// Time the player last opened any panel // Time the player last opened any panel
container.set(keyTick, PersistentDataType.INTEGER, Bukkit.getCurrentTick()); container.set(keyMillis, PersistentDataType.LONG, System.currentTimeMillis());
// Move current previous // Move current previous
String current = container.get(keyCurrent, PersistentDataType.STRING); String current = container.get(keyCurrent, PersistentDataType.STRING);

View File

@ -67,14 +67,14 @@ public class ClickEvents implements Listener {
e.setResult(Event.Result.DENY); e.setResult(Event.Result.DENY);
// Do not run commands if user is in cooldown (item click cooldown should match heartbeat updater speed) // Do not run commands if user is in cooldown (item click cooldown should match heartbeat updater speed)
NamespacedKey lastClickTick = new NamespacedKey(ctx.plugin, "last_click_tick"); NamespacedKey lastClick = new NamespacedKey(ctx.plugin, "last_click_time");
Integer lastOpen = player.getPersistentDataContainer().get(lastClickTick, PersistentDataType.INTEGER); Long lastOpenMillis = player.getPersistentDataContainer().get(lastClick, PersistentDataType.LONG);
int currentTick = Bukkit.getCurrentTick(); long currentMillis = System.currentTimeMillis();
if (lastOpen != null && currentTick - lastOpen < 2) { if (lastOpenMillis != null && currentMillis - lastOpenMillis < 100L) {
return; return;
} }
player.getPersistentDataContainer().set(lastClickTick, PersistentDataType.INTEGER, currentTick); player.getPersistentDataContainer().set(lastClick, PersistentDataType.LONG, currentMillis);
String itemId = container.get(baseIdKey, PersistentDataType.STRING); String itemId = container.get(baseIdKey, PersistentDataType.STRING);
// Check valid interaction types // Check valid interaction types