Script System Lua #178
@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.script.event;
|
|||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.script.ScriptRunner;
|
import de.steamwar.bausystem.features.script.ScriptRunner;
|
||||||
import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin;
|
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.Region;
|
||||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||||
import de.steamwar.bausystem.region.utils.RegionType;
|
import de.steamwar.bausystem.region.utils.RegionType;
|
||||||
@ -53,9 +54,9 @@ public class EventListener implements Listener {
|
|||||||
|
|
||||||
private static final Map<Player, Long> LAST_FS = new HashMap<>();
|
private static final Map<Player, Long> LAST_FS = new HashMap<>();
|
||||||
|
|
||||||
{
|
static {
|
||||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||||
Chaoscaot markierte diese Unterhaltung als gelöst
|
|||||||
LAST_FS.entrySet().removeIf(entry -> System.currentTimeMillis() - entry.getValue() > 200);
|
LAST_FS.entrySet().removeIf(entry -> TPSUtils.currentTick.get() - entry.getValue() > 4);
|
||||||
}, 2, 2);
|
}, 2, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,21 +65,21 @@ public class EventListener implements Listener {
|
|||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfJoin, LuaValue.NIL);
|
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfJoin, LuaValue.NIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL);
|
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||||
if (LAST_FS.containsKey(event.getPlayer())) {
|
if (LAST_FS.containsKey(event.getPlayer())) {
|
||||||
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DoubleSwap, LuaValue.NIL));
|
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DoubleSwap, LuaValue.NIL));
|
||||||
} else {
|
} 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) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
LuaTable table = new LuaTable();
|
LuaTable table = new LuaTable();
|
||||||
table.set("x", event.getBlock().getX());
|
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));
|
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.PlaceBlock, table));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
LuaTable table = new LuaTable();
|
LuaTable table = new LuaTable();
|
||||||
table.set("x", event.getBlock().getX());
|
table.set("x", event.getBlock().getX());
|
||||||
@ -100,7 +101,7 @@ public class EventListener implements Listener {
|
|||||||
|
|
||||||
private final Set<Player> ignore = new HashSet<>();
|
private final Set<Player> ignore = new HashSet<>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (ignore.remove(event.getPlayer())) {
|
if (ignore.remove(event.getPlayer())) {
|
||||||
return;
|
return;
|
||||||
@ -126,7 +127,7 @@ public class EventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntitySpawn(EntitySpawnEvent event) {
|
public void onEntitySpawn(EntitySpawnEvent event) {
|
||||||
if (event.getEntityType() != EntityType.PRIMED_TNT) {
|
if (event.getEntityType() != EntityType.PRIMED_TNT) {
|
||||||
return;
|
return;
|
||||||
@ -140,7 +141,7 @@ public class EventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
if (event.getEntityType() != EntityType.PRIMED_TNT) {
|
if (event.getEntityType() != EntityType.PRIMED_TNT) {
|
||||||
return;
|
return;
|
||||||
@ -165,7 +166,7 @@ public class EventListener implements Listener {
|
|||||||
event.setCancelled(cancel);
|
event.setCancelled(cancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||||
ignore.add(event.getPlayer());
|
ignore.add(event.getPlayer());
|
||||||
LuaTable table = new LuaTable();
|
LuaTable table = new LuaTable();
|
||||||
@ -173,7 +174,7 @@ public class EventListener implements Listener {
|
|||||||
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DropItem, table));
|
event.setCancelled(ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DropItem, table));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
LuaTable table = new LuaTable();
|
LuaTable table = new LuaTable();
|
||||||
|
@ -41,17 +41,17 @@ public class PlayerLib implements LuaLib {
|
|||||||
table.set("chat", new Print(player));
|
table.set("chat", new Print(player));
|
||||||
table.set("actionbar", new SendActionbar(player));
|
table.set("actionbar", new SendActionbar(player));
|
||||||
|
|
||||||
table.set("x", getterAndSetter(player.getLocation()::getX, player.getLocation()::setX));
|
table.set("x", getterAndSetter(() -> player.getLocation().getX(), player.getLocation()::setX));
|
||||||
table.set("y", getterAndSetter(player.getLocation()::getY, player.getLocation()::setY));
|
table.set("y", getterAndSetter(() -> player.getLocation().getY(), player.getLocation()::setY));
|
||||||
table.set("z", getterAndSetter(player.getLocation()::getZ, player.getLocation()::setZ));
|
table.set("z", getterAndSetter(() -> player.getLocation().getZ(), player.getLocation()::setZ));
|
||||||
table.set("yaw", getterAndSetter(player.getLocation()::getYaw, player.getLocation()::setYaw));
|
table.set("yaw", getterAndSetter(() -> player.getLocation().getYaw(), player.getLocation()::setYaw));
|
||||||
table.set("pitch", getterAndSetter(player.getLocation()::getPitch, player.getLocation()::setPitch));
|
table.set("pitch", getterAndSetter(() -> player.getLocation().getPitch(), player.getLocation()::setPitch));
|
||||||
|
|
||||||
table.set("sneaking", getter(player::isSneaking));
|
table.set("sneaking", getter(player::isSneaking));
|
||||||
table.set("sprinting", getter(player::isSprinting));
|
table.set("sprinting", getter(player::isSprinting));
|
||||||
table.set("slot", getterAndSetter(player.getInventory()::getHeldItemSlot, player.getInventory()::setHeldItemSlot));
|
table.set("slot", getterAndSetter(() -> player.getInventory().getHeldItemSlot(), player.getInventory()::setHeldItemSlot));
|
||||||
table.set("item", getter(player.getInventory().getItemInMainHand().getType()::name));
|
table.set("item", getter(() -> player.getInventory().getItemInMainHand().getType().name()));
|
||||||
table.set("offHandItem", getter(player.getInventory().getItemInOffHand().getType()::name));
|
table.set("offHandItem", getter(() -> player.getInventory().getItemInOffHand().getType().name()));
|
||||||
Chaoscaot markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Ich weiß nicht, ob das so richtig ist, aber durch diesen Befehlsaufruf wird immer das Material (auch die anderen getter betroffen) ausgegeben, der zum Zeitpunkt der Tableerstellung zurückgegeben. Ich weiß nicht, ob das so richtig ist, aber durch diesen Befehlsaufruf wird immer das Material (auch die anderen getter betroffen) ausgegeben, der zum Zeitpunkt der Tableerstellung zurückgegeben.
YoyoNow
hat
Sollte so richtig sein, geht aber halt nicht überall mit ner method reference. Muss man mal im decompilat anschauen vllt. Sollte so richtig sein, geht aber halt nicht überall mit ner method reference. Muss man mal im decompilat anschauen vllt.
|
|||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
SCRIPT.md
14
SCRIPT.md
@ -18,6 +18,8 @@
|
|||||||
* [BlockEvent](#blockevent)
|
* [BlockEvent](#blockevent)
|
||||||
* [InteractEvent](#interactevent)
|
* [InteractEvent](#interactevent)
|
||||||
* [Position](#position)
|
* [Position](#position)
|
||||||
|
* [Instabile APIs](#instabile-apis)
|
||||||
|
* [_worldedit](#worldedit)
|
||||||
* [Beispiele](#beispiele)
|
* [Beispiele](#beispiele)
|
||||||
* [Hello, World!](#hello-world)
|
* [Hello, World!](#hello-world)
|
||||||
* [Code](#code)
|
* [Code](#code)
|
||||||
@ -173,7 +175,7 @@ Es gibt folgende Variablen:
|
|||||||
|
|
||||||
| Name | Beschreibung |
|
| Name | Beschreibung |
|
||||||
|----------|----------------------------------|
|
|----------|----------------------------------|
|
||||||
| `events` | Siehe: [Event Type](#event-type) |
|
| `events` | Siehe: [Event Type](#eventtypen) |
|
||||||
|
|
||||||
## Hotkeys
|
## Hotkeys
|
||||||
|
|
||||||
@ -242,6 +244,16 @@ Die Position ist ein Objekt mit folgenden Variablen:
|
|||||||
| `y` | Die Y-Koordinate |
|
| `y` | Die Y-Koordinate |
|
||||||
| `z` | Die Z-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\<Pos>), selection(): {min: Pos, max: Pos} | Die aktuelle auswahl des Spielers |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Beispiele
|
# Beispiele
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Nur ein Aufruf von System.currentTimeMillis() pro Tick. Zeit abzufragen kann (relativ) teuer sein.
FunFact: Das hab ich aus dem Live-Code kopiert
kann man aber noch fixen