Add EventType.SelfLeave Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
57feb5936c
Commit
399ae8b0ea
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.bausystem.features.region;
|
package de.steamwar.bausystem.features.region;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.script.CustomScriptListener;
|
import de.steamwar.bausystem.features.script.CustomScriptListener;
|
||||||
|
import de.steamwar.bausystem.features.script.EventType;
|
||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.linkage.LinkedInstance;
|
import de.steamwar.bausystem.linkage.LinkedInstance;
|
||||||
@ -68,7 +69,7 @@ public class TNTListener implements Listener {
|
|||||||
Region region = Region.getRegion(event.getLocation());
|
Region region = Region.getRegion(event.getLocation());
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
if (region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
||||||
customScriptListener.callEvent(CustomScriptListener.EventType.TNTExplodeInBuild, player, event);
|
customScriptListener.callEvent(EventType.TNTExplodeInBuild, player, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,29 +24,20 @@ import de.steamwar.bausystem.SWUtils;
|
|||||||
import de.steamwar.bausystem.features.script.variables.Value;
|
import de.steamwar.bausystem.features.script.variables.Value;
|
||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
|
||||||
import de.steamwar.bausystem.region.utils.RegionType;
|
|
||||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.inventory.SWListInv;
|
import de.steamwar.inventory.SWListInv;
|
||||||
import de.steamwar.sql.UserConfig;
|
import de.steamwar.sql.UserConfig;
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
|
||||||
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.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
import yapion.hierarchy.output.LengthOutput;
|
import yapion.hierarchy.output.LengthOutput;
|
||||||
@ -58,7 +49,6 @@ import yapion.hierarchy.types.YAPIONValue;
|
|||||||
import yapion.parser.YAPIONParser;
|
import yapion.parser.YAPIONParser;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Linked(LinkageType.LISTENER)
|
@Linked(LinkageType.LISTENER)
|
||||||
@ -258,78 +248,6 @@ public class CustomScriptListener implements Listener {
|
|||||||
openCommandsMenu(p);
|
openCommandsMenu(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
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()));
|
|
||||||
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()));
|
|
||||||
valueMap.put("blockType", new Value.StringValue(event.getBlock().getType().name()));
|
|
||||||
return valueMap;
|
|
||||||
}),
|
|
||||||
RightClick(PlayerInteractEvent.class, event -> {
|
|
||||||
Map<String, Value> valueMap = new HashMap<>();
|
|
||||||
valueMap.put("blockInHand", new Value.BooleanValue(event.isBlockInHand()));
|
|
||||||
valueMap.put("action", new Value.StringValue(event.getAction().name()));
|
|
||||||
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()));
|
|
||||||
valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name()));
|
|
||||||
}
|
|
||||||
return valueMap;
|
|
||||||
}),
|
|
||||||
LeftClick(PlayerInteractEvent.class, event -> {
|
|
||||||
Map<String, Value> valueMap = new HashMap<>();
|
|
||||||
valueMap.put("blockInHand", new Value.BooleanValue(event.isBlockInHand()));
|
|
||||||
valueMap.put("action", new Value.StringValue(event.getAction().name()));
|
|
||||||
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()));
|
|
||||||
valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name()));
|
|
||||||
}
|
|
||||||
return valueMap;
|
|
||||||
}),
|
|
||||||
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()));
|
|
||||||
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()));
|
|
||||||
return valueMap;
|
|
||||||
});
|
|
||||||
|
|
||||||
private Class<? extends Event> eventType;
|
|
||||||
private Function<Event, Map<String, Value>> eventValues;
|
|
||||||
|
|
||||||
<T extends Event> EventType(Class<T> eventType, Function<T, Map<String, Value>> eventValues) {
|
|
||||||
this.eventType = eventType;
|
|
||||||
this.eventValues = event -> eventValues.apply((T) event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void callEvent(EventType eventType, Player p, Event e) {
|
public void callEvent(EventType eventType, Player p, Event e) {
|
||||||
if (!eventType.getEventType().equals(e.getClass())) {
|
if (!eventType.getEventType().equals(e.getClass())) {
|
||||||
return;
|
return;
|
||||||
@ -354,9 +272,6 @@ public class CustomScriptListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EventListener for Commands as well as Events
|
|
||||||
|
|
||||||
// Event Command
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) {
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) {
|
||||||
if (e.getMessage().startsWith("/script:")) {
|
if (e.getMessage().startsWith("/script:")) {
|
||||||
@ -430,68 +345,4 @@ public class CustomScriptListener implements Listener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Event FF
|
|
||||||
private static final Set<Player> LAST_FS = new HashSet<>();
|
|
||||||
|
|
||||||
{
|
|
||||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), LAST_FS::clear, 20, 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
|
||||||
if (LAST_FS.contains(event.getPlayer())) {
|
|
||||||
callEvent(EventType.FF, event.getPlayer(), event);
|
|
||||||
} else {
|
|
||||||
LAST_FS.add(event.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
|
||||||
callEvent(EventType.PlaceBlock, event.getPlayer(), event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
|
||||||
callEvent(EventType.BreakBlock, event.getPlayer(), event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
|
||||||
callEvent(EventType.RightClick, event.getPlayer(), event);
|
|
||||||
}
|
|
||||||
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
|
||||||
callEvent(EventType.LeftClick, event.getPlayer(), event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onEntitySpawn(EntitySpawnEvent event) {
|
|
||||||
if (event.getEntityType() != EntityType.PRIMED_TNT) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Region tntRegion = Region.getRegion(event.getLocation());
|
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
||||||
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
|
||||||
callEvent(EventType.TNTSpawn, player, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
|
||||||
if (event.getEntityType() != EntityType.PRIMED_TNT) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Region tntRegion = Region.getRegion(event.getLocation());
|
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
||||||
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
|
||||||
callEvent(EventType.TNTExplode, player, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
122
BauSystem_Main/src/de/steamwar/bausystem/features/script/EventType.java
Normale Datei
122
BauSystem_Main/src/de/steamwar/bausystem/features/script/EventType.java
Normale Datei
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2022 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.features.script;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.script.variables.Value;
|
||||||
|
import lombok.Getter;
|
||||||
|
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 java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
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()));
|
||||||
|
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()));
|
||||||
|
valueMap.put("blockType", new Value.StringValue(event.getBlock().getType().name()));
|
||||||
|
return valueMap;
|
||||||
|
}),
|
||||||
|
RightClick(PlayerInteractEvent.class, event -> {
|
||||||
|
Map<String, Value> valueMap = new HashMap<>();
|
||||||
|
valueMap.put("blockInHand", new Value.BooleanValue(event.isBlockInHand()));
|
||||||
|
valueMap.put("action", new Value.StringValue(event.getAction().name()));
|
||||||
|
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()));
|
||||||
|
valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name()));
|
||||||
|
}
|
||||||
|
return valueMap;
|
||||||
|
}),
|
||||||
|
LeftClick(PlayerInteractEvent.class, event -> {
|
||||||
|
Map<String, Value> valueMap = new HashMap<>();
|
||||||
|
valueMap.put("blockInHand", new Value.BooleanValue(event.isBlockInHand()));
|
||||||
|
valueMap.put("action", new Value.StringValue(event.getAction().name()));
|
||||||
|
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()));
|
||||||
|
valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name()));
|
||||||
|
}
|
||||||
|
return valueMap;
|
||||||
|
}),
|
||||||
|
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()));
|
||||||
|
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()));
|
||||||
|
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()));
|
||||||
|
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()));
|
||||||
|
return valueMap;
|
||||||
|
});
|
||||||
|
|
||||||
|
private Class<? extends Event> eventType;
|
||||||
|
private Function<Event, Map<String, Value>> eventValues;
|
||||||
|
|
||||||
|
<T extends Event> EventType(Class<T> eventType, Function<T, Map<String, Value>> eventValues) {
|
||||||
|
this.eventType = eventType;
|
||||||
|
this.eventValues = event -> eventValues.apply((T) event);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2022 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.features.script;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkedInstance;
|
||||||
|
import de.steamwar.bausystem.region.Region;
|
||||||
|
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||||
|
import de.steamwar.bausystem.region.utils.RegionType;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
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 java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Linked(LinkageType.LISTENER)
|
||||||
|
public class ScriptEventListener implements Listener {
|
||||||
|
|
||||||
|
@LinkedInstance
|
||||||
|
private CustomScriptListener customScriptListener;
|
||||||
|
|
||||||
|
private static final Set<Player> LAST_FS = new HashSet<>();
|
||||||
|
|
||||||
|
{
|
||||||
|
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), LAST_FS::clear, 20, 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
customScriptListener.callEvent(EventType.SelfJoin, event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
customScriptListener.callEvent(EventType.SelfLeave, event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||||
|
if (LAST_FS.contains(event.getPlayer())) {
|
||||||
|
customScriptListener.callEvent(EventType.FF, event.getPlayer(), event);
|
||||||
|
} else {
|
||||||
|
LAST_FS.add(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
|
customScriptListener.callEvent(EventType.PlaceBlock, event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
|
customScriptListener.callEvent(EventType.BreakBlock, event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
|
customScriptListener.callEvent(EventType.RightClick, event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||||
|
customScriptListener.callEvent(EventType.LeftClick, event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntitySpawn(EntitySpawnEvent event) {
|
||||||
|
if (event.getEntityType() != EntityType.PRIMED_TNT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Region tntRegion = Region.getRegion(event.getLocation());
|
||||||
|
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
||||||
|
customScriptListener.callEvent(EventType.TNTSpawn, player, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
|
if (event.getEntityType() != EntityType.PRIMED_TNT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Region tntRegion = Region.getRegion(event.getLocation());
|
||||||
|
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
||||||
|
customScriptListener.callEvent(EventType.TNTExplode, player, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren