Revert "Made each "basic" listeners register themselves on instanciation"

This reverts commit 53137b526d.
This commit is contained in:
Florian CUNY 2019-02-16 10:48:39 +01:00
parent 44729ae9cb
commit 0d7836ff12
9 changed files with 27 additions and 47 deletions

View File

@ -5,6 +5,7 @@ import java.util.Optional;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
@ -198,29 +199,24 @@ public class BentoBox extends JavaPlugin {
* Registers listeners.
*/
private void registerListeners() {
// Player join/leave events
new JoinLeaveListener(this);
PluginManager manager = getServer().getPluginManager();
// Player join events
manager.registerEvents(new JoinLeaveListener(this), this);
// Panel listener manager
new PanelListenerManager(this);
manager.registerEvents(new PanelListenerManager(), this);
// Nether portals
new NetherPortals(this);
manager.registerEvents(new NetherPortals(this), this);
// Nether trees conversion
new NetherTreesListener(this);
manager.registerEvents(new NetherTreesListener(this), this);
// End dragon blocking
new BlockEndDragon(this);
manager.registerEvents(new BlockEndDragon(this), this);
// Banned visitor commands
new BannedVisitorCommands(this);
manager.registerEvents(new BannedVisitorCommands(this), this);
// Death counter
new DeathListener(this);
// Island Deletion Manager
manager.registerEvents(new DeathListener(this), this);
// Island Delete Manager
islandDeletionManager = new IslandDeletionManager(this);
manager.registerEvents(islandDeletionManager, this);
}
@Override

View File

@ -5,7 +5,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
@ -22,9 +21,8 @@ public class BannedVisitorCommands implements Listener {
/**
* @param plugin - plugin
*/
public BannedVisitorCommands(@NonNull BentoBox plugin) {
public BannedVisitorCommands(BentoBox plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**

View File

@ -9,17 +9,16 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.lists.Flags;
public class BlockEndDragon implements Listener {
private BentoBox plugin;
public BlockEndDragon(@NonNull BentoBox plugin) {
public BlockEndDragon(BentoBox plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**

View File

@ -5,7 +5,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
/**
@ -17,9 +16,9 @@ public class DeathListener implements Listener {
private BentoBox plugin;
public DeathListener(@NonNull BentoBox plugin) {
public DeathListener(BentoBox plugin) {
super();
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)

View File

@ -12,7 +12,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
@ -30,10 +29,9 @@ public class JoinLeaveListener implements Listener {
/**
* @param plugin - plugin object
*/
public JoinLeaveListener(@NonNull BentoBox plugin) {
public JoinLeaveListener(BentoBox plugin) {
this.plugin = plugin;
this.players = plugin.getPlayers();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
players = plugin.getPlayers();
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)

View File

@ -1,8 +1,11 @@
package world.bentobox.bentobox.listeners;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -15,9 +18,9 @@ import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
@ -29,9 +32,8 @@ public class NetherPortals implements Listener {
private static final String SPAWN_PROTECTED = "protection.spawn-protected";
private final BentoBox plugin;
public NetherPortals(@NonNull BentoBox plugin) {
public NetherPortals(BentoBox plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**

View File

@ -8,7 +8,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.StructureGrowEvent;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.configuration.WorldSettings;
@ -21,9 +20,8 @@ public class NetherTreesListener implements Listener {
private BentoBox plugin;
public NetherTreesListener(@NonNull BentoBox plugin) {
public NetherTreesListener(BentoBox plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**

View File

@ -13,7 +13,6 @@ import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.panels.Panel;
import world.bentobox.bentobox.api.panels.PanelItem;
@ -23,13 +22,6 @@ public class PanelListenerManager implements Listener {
private static HashMap<UUID, Panel> openPanels = new HashMap<>();
private BentoBox plugin;
public PanelListenerManager(@NonNull BentoBox plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClick(InventoryClickEvent event) {
User user = User.getInstance(event.getWhoClicked()); // The player that clicked the item
@ -39,7 +31,7 @@ public class PanelListenerManager implements Listener {
// Check the name of the panel
if (inventory.getName().equals(openPanels.get(user.getUniqueId()).getInventory().getName())) {
// Close inventory if clicked outside and if setting is true
if (plugin.getSettings().isClosePanelOnClickOutside() && event.getSlotType().equals(SlotType.OUTSIDE)) {
if (BentoBox.getInstance().getSettings().isClosePanelOnClickOutside() && event.getSlotType().equals(SlotType.OUTSIDE)) {
event.getWhoClicked().closeInventory();
return;
}

View File

@ -9,7 +9,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent.IslandDeleteChunksEvent;
@ -33,9 +32,8 @@ public class IslandDeletionManager implements Listener {
private Database<IslandDeletion> handler;
private Set<Location> inDeletion;
public IslandDeletionManager(@NonNull BentoBox plugin) {
public IslandDeletionManager(BentoBox plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
handler = new Database<>(plugin, IslandDeletion.class);
inDeletion = new HashSet<>();
}