SteamWar/BauSystem2.0
Archiviert
12
0

Add EventType.DropItem
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Update FF Event

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-02-02 09:34:04 +01:00
Ursprung e24970f947
Commit e8fa5ead91
4 geänderte Dateien mit 45 neuen und 40 gelöschten Zeilen

Datei anzeigen

@ -440,8 +440,9 @@ SCRIPT_GUI_CUSTOM_EVENTS_LORE_16 = §eTNTExplode §8-§7 x, y, z
SCRIPT_GUI_CUSTOM_EVENTS_LORE_17 = §eTNTExplodeInBuild §8-§7 x, y, z
SCRIPT_GUI_CUSTOM_EVENTS_LORE_18 = §eSelfJoin §8-§7 x, y, z, playerName
SCRIPT_GUI_CUSTOM_EVENTS_LORE_19 = §eSelfLeave §8-§7 x, y, z, playerName
SCRIPT_GUI_CUSTOM_EVENTS_LORE_20 = §eDropItem §8-§7 material, x, y, z
SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1 = §e* §8-§7 Alles in den Klammern ist nur gesetzt,
SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_2 = §7wenn die Variable dafür gesetzt ist.
SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_2 = §7wenn die Variable davor auf §etrue§7 gesetzt ist.
SCRIPT_GUI_OTHER = §eOther
SCRIPT_GUI_OTHER_LORE_1 = §7Kommentare fangen mit §e#§7 an.

Datei anzeigen

@ -21,15 +21,13 @@ package de.steamwar.bausystem.features.script;
import de.steamwar.bausystem.features.script.variables.Value;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.event.player.*;
import java.util.HashMap;
import java.util.Map;
@ -40,17 +38,13 @@ public enum EventType {
FF(PlayerSwapHandItemsEvent.class, event -> null),
PlaceBlock(BlockPlaceEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
valueMap.put("blockX", new Value.LongValue(event.getBlockPlaced().getX()));
valueMap.put("blockY", new Value.LongValue(event.getBlockPlaced().getY()));
valueMap.put("blockZ", new Value.LongValue(event.getBlockPlaced().getZ()));
addBlockXYZ(valueMap, event.getBlockPlaced().getLocation());
valueMap.put("blockType", new Value.StringValue(event.getBlockPlaced().getType().name()));
return valueMap;
}),
BreakBlock(BlockBreakEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
valueMap.put("blockX", new Value.LongValue(event.getBlock().getX()));
valueMap.put("blockY", new Value.LongValue(event.getBlock().getY()));
valueMap.put("blockZ", new Value.LongValue(event.getBlock().getZ()));
addBlockXYZ(valueMap, event.getBlock().getLocation());
valueMap.put("blockType", new Value.StringValue(event.getBlock().getType().name()));
return valueMap;
}),
@ -61,9 +55,7 @@ public enum EventType {
valueMap.put("handType", new Value.StringValue(event.getMaterial().name()));
valueMap.put("hasBlock", new Value.BooleanValue(event.hasBlock()));
if (event.hasBlock()) {
valueMap.put("blockX", new Value.LongValue(event.getClickedBlock().getX()));
valueMap.put("blockY", new Value.LongValue(event.getClickedBlock().getY()));
valueMap.put("blockZ", new Value.LongValue(event.getClickedBlock().getZ()));
addBlockXYZ(valueMap, event.getClickedBlock().getLocation());
valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name()));
}
return valueMap;
@ -75,9 +67,7 @@ public enum EventType {
valueMap.put("handType", new Value.StringValue(event.getMaterial().name()));
valueMap.put("hasBlock", new Value.BooleanValue(event.hasBlock()));
if (event.hasBlock()) {
valueMap.put("blockX", new Value.LongValue(event.getClickedBlock().getX()));
valueMap.put("blockY", new Value.LongValue(event.getClickedBlock().getY()));
valueMap.put("blockZ", new Value.LongValue(event.getClickedBlock().getZ()));
addBlockXYZ(valueMap, event.getClickedBlock().getLocation());
valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name()));
}
return valueMap;
@ -85,33 +75,43 @@ public enum EventType {
TNTSpawn(EntitySpawnEvent.class, event -> null),
TNTExplode(EntityExplodeEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
valueMap.put("x", new Value.DoubleValue(event.getLocation().getX()));
valueMap.put("y", new Value.DoubleValue(event.getLocation().getY()));
valueMap.put("z", new Value.DoubleValue(event.getLocation().getZ()));
addXYZ(valueMap, event.getLocation());
return valueMap;
}),
TNTExplodeInBuild(EntityExplodeEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
valueMap.put("x", new Value.DoubleValue(event.getLocation().getX()));
valueMap.put("y", new Value.DoubleValue(event.getLocation().getY()));
valueMap.put("z", new Value.DoubleValue(event.getLocation().getZ()));
addXYZ(valueMap, event.getLocation());
return valueMap;
}),
SelfJoin(PlayerJoinEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
valueMap.put("x", new Value.DoubleValue(event.getPlayer().getLocation().getX()));
valueMap.put("y", new Value.DoubleValue(event.getPlayer().getLocation().getY()));
valueMap.put("z", new Value.DoubleValue(event.getPlayer().getLocation().getZ()));
addXYZ(valueMap, event.getPlayer().getLocation());
return valueMap;
}),
SelfLeave(PlayerQuitEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
valueMap.put("x", new Value.DoubleValue(event.getPlayer().getLocation().getX()));
valueMap.put("y", new Value.DoubleValue(event.getPlayer().getLocation().getY()));
valueMap.put("z", new Value.DoubleValue(event.getPlayer().getLocation().getZ()));
addXYZ(valueMap, event.getPlayer().getLocation());
return valueMap;
}),
DropItem(PlayerDropItemEvent.class, event -> {
Map<String, Value> valueMap = new HashMap<>();
valueMap.put("material", new Value.StringValue(event.getItemDrop().getItemStack().getType().name()));
addXYZ(valueMap, event.getItemDrop().getLocation());
return valueMap;
});
private static void addXYZ(Map<String, Value> valueMap, Location location) {
valueMap.put("x", new Value.DoubleValue(location.getX()));
valueMap.put("y", new Value.DoubleValue(location.getY()));
valueMap.put("z", new Value.DoubleValue(location.getZ()));
}
private static void addBlockXYZ(Map<String, Value> valueMap, Location location) {
valueMap.put("blockX", new Value.LongValue(location.getBlockX()));
valueMap.put("blockY", new Value.LongValue(location.getBlockY()));
valueMap.put("blockZ", new Value.LongValue(location.getBlockZ()));
}
private Class<? extends Event> eventType;
private Function<Event, Map<String, Value>> eventValues;

Datei anzeigen

@ -55,7 +55,7 @@ public class ScriptCommand extends SWCommand {
}
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.BOOK, BauSystem.MESSAGE.parse("SCRIPT_GUI_CUSTOM_COMMANDS", p), loreBuilder(p, "SCRIPT_GUI_CUSTOM_COMMANDS_LORE_", 1, 13), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.BOOK, BauSystem.MESSAGE.parse("SCRIPT_GUI_CUSTOM_EVENTS", p), loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_", 1, 19, loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_", 1, 2)), false, clickType -> {
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.BOOK, BauSystem.MESSAGE.parse("SCRIPT_GUI_CUSTOM_EVENTS", p), loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_", 1, 20, loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_", 1, 2)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.BOOK, BauSystem.MESSAGE.parse("SCRIPT_GUI_OTHER", p), loreBuilder(p, "SCRIPT_GUI_OTHER_LORE_", 1, 9), false, clickType -> {
}), null));

Datei anzeigen

@ -36,13 +36,10 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.event.player.*;
import java.util.HashSet;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;
@Linked(LinkageType.LISTENER)
public class ScriptEventListener implements Listener {
@ -50,10 +47,12 @@ public class ScriptEventListener implements Listener {
@LinkedInstance
private CustomScriptManager customScriptManager;
private static final Set<Player> LAST_FS = new HashSet<>();
private static final Map<Player, Long> LAST_FS = new HashMap<>();
{
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), LAST_FS::clear, 20, 20);
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
LAST_FS.entrySet().removeIf(entry -> System.currentTimeMillis() - entry.getValue() > 200);
}, 2, 2);
}
@EventHandler
@ -68,10 +67,10 @@ public class ScriptEventListener implements Listener {
@EventHandler
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
if (LAST_FS.contains(event.getPlayer())) {
if (LAST_FS.containsKey(event.getPlayer())) {
customScriptManager.callEvent(EventType.FF, event.getPlayer(), event);
} else {
LAST_FS.add(event.getPlayer());
LAST_FS.put(event.getPlayer(), System.currentTimeMillis());
}
}
@ -122,4 +121,9 @@ public class ScriptEventListener implements Listener {
}
}
}
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
customScriptManager.callEvent(EventType.DropItem, event.getPlayer(), event);
}
}