diff --git a/src/org/black_ixx/bossshop/addon/guishopmanager/PlayerListener.java b/src/org/black_ixx/bossshop/addon/guishopmanager/PlayerListener.java index 96ee81e..5ea772a 100644 --- a/src/org/black_ixx/bossshop/addon/guishopmanager/PlayerListener.java +++ b/src/org/black_ixx/bossshop/addon/guishopmanager/PlayerListener.java @@ -1,110 +1,107 @@ -package org.black_ixx.bossshop.addon.guishopmanager; - -import java.util.ArrayList; -import java.util.List; - -import org.black_ixx.bossshop.addon.guishopmanager.GuiShopManager; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.inventory.ItemStack; - -public class PlayerListener implements Listener, Reloadable { - private GuiShopManager plugin; - private boolean drop; - private boolean move; - private boolean place; - private boolean death; - private boolean respawn; - - public PlayerListener(GuiShopManager plugin) { - this.plugin = plugin; - loadSettings(plugin); - } - - private void loadSettings(GuiShopManager plugin) { - ConfigurationSection s = plugin.getConfig().getConfigurationSection("Settings"); - - this.drop = s.getBoolean("AllowDropItems"); - this.move = s.getBoolean("AllowMoveItems"); - this.place = s.getBoolean("AllowPlaceItems"); - this.death = s.getBoolean("DropItemsOnDeath"); - this.respawn = s.getBoolean("GetItemsOnRespawn"); - } - - @EventHandler(ignoreCancelled = true) - public void onDeath(PlayerDeathEvent event) { - if (!this.death) { - List toRemove = new ArrayList(); - - for (ItemStack i : event.getDrops()) { - if (this.plugin.getGSMItems().isShopItem(i)) { - toRemove.add(i); - } - - } - - for (ItemStack i : toRemove) { - event.getDrops().remove(i); - } - toRemove.clear(); - } - } - - @EventHandler(ignoreCancelled = true) - public void onDrop(PlayerDropItemEvent event) { - if ((!this.drop) - && (this.plugin.getGSMItems().isShopItem(event.getItemDrop().getItemStack()))) { - event.setCancelled(true); - } - } - - @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) - public void onInteract(PlayerInteractEvent event) { - this.plugin.getGSMItems().playerClicked(event); - } - - @EventHandler(ignoreCancelled = true) - public void onJoin(PlayerJoinEvent event) { - this.plugin.getGSMItems().giveJoinItems(event.getPlayer()); - } - - @EventHandler(ignoreCancelled = true) - public void onMove(InventoryClickEvent event) { - if (event.getWhoClicked().isOp()) - return; - if (!this.move) { - if (this.plugin.getGSMItems().isShopItem(event.getCurrentItem()) - || this.plugin.getGSMItems().isShopItem(event.getCursor())) { - event.setCancelled(true); - } - } - } - - @EventHandler(ignoreCancelled = true) - public void onPlace(BlockPlaceEvent event) { - if ((!this.place) && (this.plugin.getGSMItems().isShopItem(event.getItemInHand()))) { - event.setCancelled(true); - } - } - - @EventHandler - public void onRespawn(PlayerRespawnEvent event) { - if (this.respawn) { - this.plugin.getGSMItems().giveJoinItems(event.getPlayer()); - } - } - - @Override - public void reload(GuiShopManager plugin) { - loadSettings(plugin); - } +package org.black_ixx.bossshop.addon.guishopmanager; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.inventory.ItemStack; + +public class PlayerListener implements Listener, Reloadable { + private GuiShopManager plugin; + private boolean drop; + private boolean move; + private boolean place; + private boolean death; + private boolean respawn; + + public PlayerListener(GuiShopManager plugin) { + this.plugin = plugin; + loadSettings(plugin); + } + + private void loadSettings(GuiShopManager plugin) { + ConfigurationSection s = plugin.getConfig().getConfigurationSection("Settings"); + + this.drop = s.getBoolean("AllowDropItems"); + this.move = s.getBoolean("AllowMoveItems"); + this.place = s.getBoolean("AllowPlaceItems"); + this.death = s.getBoolean("DropItemsOnDeath"); + this.respawn = s.getBoolean("GetItemsOnRespawn"); + } + + @EventHandler(ignoreCancelled = true) + public void onDeath(PlayerDeathEvent event) { + if (!this.death) { + List toRemove = new ArrayList(); + + for (ItemStack i : event.getDrops()) { + if (this.plugin.getGSMItems().isShopItem(i)) { + toRemove.add(i); + } + + } + + for (ItemStack i : toRemove) { + event.getDrops().remove(i); + } + toRemove.clear(); + } + } + + @EventHandler(ignoreCancelled = true) + public void onDrop(PlayerDropItemEvent event) { + if ((!this.drop) + && (this.plugin.getGSMItems().isShopItem(event.getItemDrop().getItemStack()))) { + event.setCancelled(true); + } + } + + public void onInteract(PlayerInteractEvent event) { + this.plugin.getGSMItems().playerClicked(event); + } + + @EventHandler(ignoreCancelled = true) + public void onJoin(PlayerJoinEvent event) { + this.plugin.getGSMItems().giveJoinItems(event.getPlayer()); + } + + @EventHandler(ignoreCancelled = true) + public void onMove(InventoryClickEvent event) { + if (event.getWhoClicked().isOp()) + return; + if (!this.move) { + if (this.plugin.getGSMItems().isShopItem(event.getCurrentItem()) + || this.plugin.getGSMItems().isShopItem(event.getCursor())) { + event.setCancelled(true); + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onPlace(BlockPlaceEvent event) { + if ((!this.place) && (this.plugin.getGSMItems().isShopItem(event.getItemInHand()))) { + event.setCancelled(true); + } + } + + @EventHandler + public void onRespawn(PlayerRespawnEvent event) { + if (this.respawn) { + this.plugin.getGSMItems().giveJoinItems(event.getPlayer()); + } + } + + @Override + public void reload(GuiShopManager plugin) { + loadSettings(plugin); + } } \ No newline at end of file