1
0
mirror of https://e.coding.net/circlecloud/ProtectItem.git synced 2024-12-28 20:58:50 +00:00

fix check error...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-10-24 20:02:12 +08:00
parent 2b515ca77d
commit 83c808d362
7 changed files with 28 additions and 19 deletions

View File

@ -5,6 +5,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.ProtectItem.commands.ProtectItemCommand; import cn.citycraft.ProtectItem.commands.ProtectItemCommand;
import cn.citycraft.ProtectItem.listen.ClickItemListen; import cn.citycraft.ProtectItem.listen.ClickItemListen;
import cn.citycraft.ProtectItem.listen.DropItemListen; import cn.citycraft.ProtectItem.listen.DropItemListen;
@ -16,15 +17,20 @@ import cn.citycraft.ProtectItem.utils.ItemManager;
public class ProtectItem extends JavaPlugin { public class ProtectItem extends JavaPlugin {
public ItemManager itemManager; public ItemManager itemManager;
public FileConfig msgcfg;
public FileConfig config;
public String pluginname;
public boolean actionCheck(final Player p, final ItemStack i, final ActionType action) { public boolean isCantAction(final Player p, final ItemStack i, final ActionType action) {
if (itemManager.canAction(i, action)) { if (itemManager.canAction(i, action) && !itemManager.hasActionPerm(p, i, action)) {
return false; final String message = msgcfg.getMessage("Message." + action.toString());
} else if (itemManager.hasActionPerm(p, i, action)) { if (message != null && !message.isEmpty()) {
return false; p.sendMessage(pluginname + " " + message);
} }
return true; return true;
} }
return false;
}
public ItemManager getItemManager() { public ItemManager getItemManager() {
return itemManager; return itemManager;
@ -42,4 +48,11 @@ public class ProtectItem extends JavaPlugin {
this.getCommand("pi").setExecutor(new ProtectItemCommand(this)); this.getCommand("pi").setExecutor(new ProtectItemCommand(this));
} }
@Override
public void onLoad() {
this.config = new FileConfig(this);
this.msgcfg = new FileConfig(this, "messages.yml");
pluginname = config.getMessage("pluginname");
}
} }

View File

@ -22,7 +22,7 @@ public class ClickItemListen implements Listener {
final Player p = (Player) e.getWhoClicked(); final Player p = (Player) e.getWhoClicked();
final ItemStack i = e.getCurrentItem(); final ItemStack i = e.getCurrentItem();
if (i != null && i.getType() != Material.AIR) { if (i != null && i.getType() != Material.AIR) {
e.setCancelled(plugin.actionCheck(p, i, ActionType.Click)); e.setCancelled(plugin.isCantAction(p, i, ActionType.Click));
} }
} }
} }

View File

@ -20,6 +20,6 @@ public class DropItemListen implements Listener {
public void onDropItem(final PlayerDropItemEvent e) { public void onDropItem(final PlayerDropItemEvent e) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final ItemStack i = e.getItemDrop().getItemStack(); final ItemStack i = e.getItemDrop().getItemStack();
e.setCancelled(plugin.actionCheck(p, i, ActionType.Drop)); e.setCancelled(plugin.isCantAction(p, i, ActionType.Drop));
} }
} }

View File

@ -20,6 +20,6 @@ public class InteractItemListen implements Listener {
public void onPickupItem(final PlayerInteractEvent e) { public void onPickupItem(final PlayerInteractEvent e) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final ItemStack i = p.getItemInHand(); final ItemStack i = p.getItemInHand();
e.setCancelled(plugin.actionCheck(p, i, ActionType.Interact)); e.setCancelled(plugin.isCantAction(p, i, ActionType.Interact));
} }
} }

View File

@ -1,6 +1,5 @@
package cn.citycraft.ProtectItem.listen; package cn.citycraft.ProtectItem.listen;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -24,9 +23,6 @@ public class ItemHeldListen implements Listener {
final Inventory inv = p.getInventory(); final Inventory inv = p.getInventory();
final int slot = e.getNewSlot(); final int slot = e.getNewSlot();
final ItemStack i = inv.getItem(slot); final ItemStack i = inv.getItem(slot);
if (plugin.actionCheck(p, i, ActionType.Held)) { e.setCancelled(plugin.isCantAction(p, i, ActionType.Held));
inv.setItem(slot, new ItemStack(Material.AIR));
}
inv.addItem(i);
} }
} }

View File

@ -20,6 +20,6 @@ public class PickupItemListen implements Listener {
public void onPickupItem(final PlayerPickupItemEvent e) { public void onPickupItem(final PlayerPickupItemEvent e) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final ItemStack i = e.getItem().getItemStack(); final ItemStack i = e.getItem().getItemStack();
e.setCancelled(plugin.actionCheck(p, i, ActionType.Pickup)); e.setCancelled(plugin.isCantAction(p, i, ActionType.Pickup));
} }
} }

View File

@ -1,10 +1,10 @@
Version: 1.0
#提示消息 #提示消息
Message: Message:
Reload: '&a配置文件已重新载入' Reload: '&a配置文件已重新载入'
#方块安全提示 #方块安全提示
Drop: '&c当前世界禁止丢弃该物品' Drop: '&c当前世界禁止丢弃该物品'
Pickup: '&c当前世界禁止拾取该物品' Pickup: '&c当前世界禁止拾取该物品'
Place: '&c当前世界禁止放置该物品' Interact: '&c当前世界禁止使用该物品!'
Break: '&c当前世界禁止破坏该物品'
Use: '&c当前世界禁止使用该物品!'
Held: '&c当前世界禁止使用该物品!' Held: '&c当前世界禁止使用该物品!'
Click: '&c当前世界禁止点击该物品!'