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
runCommand(panel, player, command);
Bukkit.getGlobalRegionScheduler().run(
ctx.plugin,
task -> runCommand(panel, player, command)
);
// Move to the next command
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);
if (teleportedPlayer != null) {
teleportedPlayer.teleport(teleportLocation);
player.teleportAsync(teleportLocation);
}
} catch (Exception ex) {
ctx.text.sendError(player, Message.TELEPORT_ERROR);

View File

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

View File

@ -67,14 +67,14 @@ public class ClickEvents implements Listener {
e.setResult(Event.Result.DENY);
// 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");
Integer lastOpen = player.getPersistentDataContainer().get(lastClickTick, PersistentDataType.INTEGER);
int currentTick = Bukkit.getCurrentTick();
if (lastOpen != null && currentTick - lastOpen < 2) {
NamespacedKey lastClick = new NamespacedKey(ctx.plugin, "last_click_time");
Long lastOpenMillis = player.getPersistentDataContainer().get(lastClick, PersistentDataType.LONG);
long currentMillis = System.currentTimeMillis();
if (lastOpenMillis != null && currentMillis - lastOpenMillis < 100L) {
return;
}
player.getPersistentDataContainer().set(lastClickTick, PersistentDataType.INTEGER, currentTick);
player.getPersistentDataContainer().set(lastClick, PersistentDataType.LONG, currentMillis);
String itemId = container.get(baseIdKey, PersistentDataType.STRING);
// Check valid interaction types