1
0
mirror of https://e.coding.net/circlecloud/GuiShopManager.git synced 2024-11-16 01:08:52 +00:00

fix can't open shop while click air...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-07-10 20:02:32 +08:00
parent 769fd577ec
commit bc9aafb687

View File

@ -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<ItemStack> toRemove = new ArrayList<ItemStack>();
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<ItemStack> toRemove = new ArrayList<ItemStack>();
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);
}
}