From 5a09ece591d69e21412955a0c7129294305219ce Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 7 Jun 2023 21:46:38 +0200 Subject: [PATCH] Fixing... Signed-off-by: Chaoscaot --- .../features/script/event/EventListener.java | 25 ++++++++++--------- .../features/script/lua/libs/PlayerLib.java | 16 ++++++------ SCRIPT.md | 14 ++++++++++- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java index 32bf4a3f..2254c927 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.script.event; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.script.ScriptRunner; import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; @@ -53,9 +54,9 @@ public class EventListener implements Listener { private static final Map LAST_FS = new HashMap<>(); - { + static { Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { - LAST_FS.entrySet().removeIf(entry -> System.currentTimeMillis() - entry.getValue() > 200); + LAST_FS.entrySet().removeIf(entry -> TPSUtils.currentTick.get() - entry.getValue() > 4); }, 2, 2); } @@ -64,21 +65,21 @@ public class EventListener implements Listener { ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfJoin, LuaValue.NIL); } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onPlayerQuit(PlayerQuitEvent event) { ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL); } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { if (LAST_FS.containsKey(event.getPlayer())) { event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DoubleSwap, LuaValue.NIL)); } else { - LAST_FS.put(event.getPlayer(), System.currentTimeMillis()); + LAST_FS.put(event.getPlayer(), TPSUtils.currentTick.get()); } } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent event) { LuaTable table = new LuaTable(); table.set("x", event.getBlock().getX()); @@ -88,7 +89,7 @@ public class EventListener implements Listener { event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.PlaceBlock, table)); } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onBlockBreak(BlockBreakEvent event) { LuaTable table = new LuaTable(); table.set("x", event.getBlock().getX()); @@ -100,7 +101,7 @@ public class EventListener implements Listener { private final Set ignore = new HashSet<>(); - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onPlayerInteract(PlayerInteractEvent event) { if (ignore.remove(event.getPlayer())) { return; @@ -126,7 +127,7 @@ public class EventListener implements Listener { } } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onEntitySpawn(EntitySpawnEvent event) { if (event.getEntityType() != EntityType.PRIMED_TNT) { return; @@ -140,7 +141,7 @@ public class EventListener implements Listener { } } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onEntityExplode(EntityExplodeEvent event) { if (event.getEntityType() != EntityType.PRIMED_TNT) { return; @@ -165,7 +166,7 @@ public class EventListener implements Listener { event.setCancelled(cancel); } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onPlayerDropItem(PlayerDropItemEvent event) { ignore.add(event.getPlayer()); LuaTable table = new LuaTable(); @@ -173,7 +174,7 @@ public class EventListener implements Listener { event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DropItem, table)); } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onEntityDeath(EntityDeathEvent event) { for (Player player : Bukkit.getOnlinePlayers()) { LuaTable table = new LuaTable(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java index 7a88cdc3..0823409d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java @@ -41,17 +41,17 @@ public class PlayerLib implements LuaLib { table.set("chat", new Print(player)); table.set("actionbar", new SendActionbar(player)); - table.set("x", getterAndSetter(player.getLocation()::getX, player.getLocation()::setX)); - table.set("y", getterAndSetter(player.getLocation()::getY, player.getLocation()::setY)); - table.set("z", getterAndSetter(player.getLocation()::getZ, player.getLocation()::setZ)); - table.set("yaw", getterAndSetter(player.getLocation()::getYaw, player.getLocation()::setYaw)); - table.set("pitch", getterAndSetter(player.getLocation()::getPitch, player.getLocation()::setPitch)); + table.set("x", getterAndSetter(() -> player.getLocation().getX(), player.getLocation()::setX)); + table.set("y", getterAndSetter(() -> player.getLocation().getY(), player.getLocation()::setY)); + table.set("z", getterAndSetter(() -> player.getLocation().getZ(), player.getLocation()::setZ)); + table.set("yaw", getterAndSetter(() -> player.getLocation().getYaw(), player.getLocation()::setYaw)); + table.set("pitch", getterAndSetter(() -> player.getLocation().getPitch(), player.getLocation()::setPitch)); table.set("sneaking", getter(player::isSneaking)); table.set("sprinting", getter(player::isSprinting)); - table.set("slot", getterAndSetter(player.getInventory()::getHeldItemSlot, player.getInventory()::setHeldItemSlot)); - table.set("item", getter(player.getInventory().getItemInMainHand().getType()::name)); - table.set("offHandItem", getter(player.getInventory().getItemInOffHand().getType()::name)); + table.set("slot", getterAndSetter(() -> player.getInventory().getHeldItemSlot(), player.getInventory()::setHeldItemSlot)); + table.set("item", getter(() -> player.getInventory().getItemInMainHand().getType().name())); + table.set("offHandItem", getter(() -> player.getInventory().getItemInOffHand().getType().name())); return table; } diff --git a/SCRIPT.md b/SCRIPT.md index 7ced745f..07bd4e41 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -18,6 +18,8 @@ * [BlockEvent](#blockevent) * [InteractEvent](#interactevent) * [Position](#position) +* [Instabile APIs](#instabile-apis) + * [_worldedit](#worldedit) * [Beispiele](#beispiele) * [Hello, World!](#hello-world) * [Code](#code) @@ -173,7 +175,7 @@ Es gibt folgende Variablen: | Name | Beschreibung | |----------|----------------------------------| -| `events` | Siehe: [Event Type](#event-type) | +| `events` | Siehe: [Event Type](#eventtypen) | ## Hotkeys @@ -242,6 +244,16 @@ Die Position ist ein Objekt mit folgenden Variablen: | `y` | Die Y-Koordinate | | `z` | Die Z-Koordinate | +# Instabile APIs +Hier sind einige APIs aufgelistet, die nicht stabil sind und sich jederzeit ändern können. + +## _worldedit + +| Name | Signatur | Beschreibung | +|-------------|-----------------------------------------------------------|-----------------------------------| +| `selection` | selection(Liste\), selection(): {min: Pos, max: Pos} | Die aktuelle auswahl des Spielers | + + # Beispiele