From af82fa01528ea007072146b62e334686dffbbd6c Mon Sep 17 00:00:00 2001 From: Fernando Pettinelli Date: Thu, 30 Sep 2021 18:21:02 -0300 Subject: [PATCH] Add HopperBreakEvent and HopperPlaceEvent --- .../api/events/HopperBreakEvent.java | 24 +++++++++++++++++++ .../api/events/HopperPlaceEvent.java | 24 +++++++++++++++++++ .../epichoppers/listeners/BlockListeners.java | 10 ++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/main/java/com/songoda/epichoppers/api/events/HopperBreakEvent.java create mode 100644 src/main/java/com/songoda/epichoppers/api/events/HopperPlaceEvent.java diff --git a/src/main/java/com/songoda/epichoppers/api/events/HopperBreakEvent.java b/src/main/java/com/songoda/epichoppers/api/events/HopperBreakEvent.java new file mode 100644 index 0000000..87e207f --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/api/events/HopperBreakEvent.java @@ -0,0 +1,24 @@ +package com.songoda.epichoppers.api.events; + +import com.songoda.epichoppers.hopper.Hopper; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; + +public class HopperBreakEvent extends HopperEvent { + + private static final HandlerList HANDLERS = new HandlerList(); + + public HopperBreakEvent(Player player, Hopper hopper) { + super(player, hopper); + } + + @Override + public HandlerList getHandlers() { + return HANDLERS; + } + + public static HandlerList getHandlerList() { + return HANDLERS; + } + +} diff --git a/src/main/java/com/songoda/epichoppers/api/events/HopperPlaceEvent.java b/src/main/java/com/songoda/epichoppers/api/events/HopperPlaceEvent.java new file mode 100644 index 0000000..c7e1c5f --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/api/events/HopperPlaceEvent.java @@ -0,0 +1,24 @@ +package com.songoda.epichoppers.api.events; + +import com.songoda.epichoppers.hopper.Hopper; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; + +public class HopperPlaceEvent extends HopperEvent { + + private static final HandlerList HANDLERS = new HandlerList(); + + public HopperPlaceEvent(Player player, Hopper hopper) { + super(player, hopper); + } + + @Override + public HandlerList getHandlers() { + return HANDLERS; + } + + public static HandlerList getHandlerList() { + return HANDLERS; + } + +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java b/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java index 8b7acda..b4b1339 100644 --- a/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java +++ b/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java @@ -1,10 +1,13 @@ package com.songoda.epichoppers.listeners; import com.songoda.epichoppers.EpicHoppers; +import com.songoda.epichoppers.api.events.HopperBreakEvent; +import com.songoda.epichoppers.api.events.HopperPlaceEvent; import com.songoda.epichoppers.hopper.Hopper; import com.songoda.epichoppers.hopper.HopperBuilder; import com.songoda.epichoppers.hopper.levels.Level; import com.songoda.epichoppers.settings.Settings; +import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.block.Block; @@ -64,6 +67,10 @@ public class BlockListeners implements Listener { .setLevel(plugin.getLevelManager().getLevel(item)) .setPlacedBy(player) .setLastPlayerOpened(player).build()); + + HopperPlaceEvent hopperPlaceEvent = new HopperPlaceEvent(player, hopper); + Bukkit.getPluginManager().callEvent(hopperPlaceEvent); + EpicHoppers.getInstance().getDataManager().createHopper(hopper); } @@ -112,6 +119,9 @@ public class BlockListeners implements Listener { Level level = hopper.getLevel(); if (level.getLevel() > 1 || Settings.ALLOW_NORMAL_HOPPERS.getBoolean()) { + HopperBreakEvent hopperBreakEvent = new HopperBreakEvent(player, hopper); + Bukkit.getPluginManager().callEvent(hopperBreakEvent); + event.setCancelled(true); ItemStack item = plugin.newHopperItem(level);