diff --git a/src/cn/citycraft/ProtectItem/Main.java b/src/cn/citycraft/ProtectItem/Main.java index 52e8236..5e4e341 100644 --- a/src/cn/citycraft/ProtectItem/Main.java +++ b/src/cn/citycraft/ProtectItem/Main.java @@ -9,10 +9,8 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; -import cn.citycraft.ProtectItem.listen.BreakBlockListen; import cn.citycraft.ProtectItem.listen.DropItemListen; import cn.citycraft.ProtectItem.listen.PickupItemListen; -import cn.citycraft.ProtectItem.listen.PlaceBlockListen; public class Main extends JavaPlugin { public String servername; @@ -32,12 +30,12 @@ public class Main extends JavaPlugin { if (getConfig().getBoolean("Protect.Pickup", true)) Bukkit.getPluginManager().registerEvents( new PickupItemListen(this), this); - if (getConfig().getBoolean("Protect.Break", true)) - Bukkit.getPluginManager().registerEvents( - new BreakBlockListen(this), this); - if (getConfig().getBoolean("Protect.Place", true)) - Bukkit.getPluginManager().registerEvents( - new PlaceBlockListen(this), this); + // if (getConfig().getBoolean("Protect.Break", true)) + // Bukkit.getPluginManager().registerEvents( + // new BreakBlockListen(this), this); + // if (getConfig().getBoolean("Protect.Place", true)) + // Bukkit.getPluginManager().registerEvents( + // new PlaceBlockListen(this), this); getLogger().info("ProtectItem已加载!"); } @@ -48,30 +46,32 @@ public class Main extends JavaPlugin { switch (args.length) { case 0: ItemStack item = p.getItemInHand(); - p.sendMessage("手上物品类型名称为: " + item.getType().name()); + p.sendMessage("\u00a7a手上物品类型名称为: \u00a76" + getItemName(item)); return true; case 1: - if (args[0].equalsIgnoreCase("reload")) { - this.reloadConfig(); - p.sendMessage("\u00a7a配置文件已重载..."); - return true; - } + if (p.hasPermission("pi.bypass")) + if (args[0].equalsIgnoreCase("reload")) { + this.reloadConfig(); + p.sendMessage("\u00a7a配置文件已重载..."); + return true; + } break; default: } return false; } - public boolean checkevent(Player p, String i, String type) { + public boolean checkevent(Player p, ItemStack i, String type) { if (p.hasPermission("pi.bypass")) return false; + String iname = getItemName(i); Location l = p.getLocation(); World pw = l.getWorld(); for (String protectworld : getConfig().getStringList("ProtectWorld")) { if (pw.getName().equalsIgnoreCase(protectworld)) for (String protectitem : getConfig().getStringList( "ProtectItem")) { - if (i.equalsIgnoreCase(protectitem)) { + if (iname.equalsIgnoreCase(protectitem)) { p.sendMessage(pluginname + getmessage("Message." + type)); return true; @@ -81,6 +81,14 @@ public class Main extends JavaPlugin { return false; } + public static String getItemName(ItemStack i) { + String name = i.getType().name(); + int dur = i.getDurability(); + String dura = i.getMaxStackSize() != 1 ? dur != 0 ? "_" + dur : "" : ""; + String iname = name + dura; + return iname; + } + public String getmessage(String path) { String message = getConfig().getString(path).replaceAll("&", "§"); return message; diff --git a/src/cn/citycraft/ProtectItem/listen/BreakBlockListen.java b/src/cn/citycraft/ProtectItem/listen/BreakBlockListen.java deleted file mode 100644 index 7238c3a..0000000 --- a/src/cn/citycraft/ProtectItem/listen/BreakBlockListen.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.citycraft.ProtectItem.listen; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; - -import cn.citycraft.ProtectItem.Main; - -public class BreakBlockListen implements Listener { - Main plugin; - - public BreakBlockListen(Main main) { - plugin = main; - } - - @EventHandler(ignoreCancelled = true) - public void onBreakItem(BlockBreakEvent e) { - Player p = e.getPlayer(); - String i = e.getBlock().getType().name(); - e.setCancelled(plugin.checkevent(p, i, "Break")); - } -} diff --git a/src/cn/citycraft/ProtectItem/listen/DropItemListen.java b/src/cn/citycraft/ProtectItem/listen/DropItemListen.java index 6466a6d..d63abec 100644 --- a/src/cn/citycraft/ProtectItem/listen/DropItemListen.java +++ b/src/cn/citycraft/ProtectItem/listen/DropItemListen.java @@ -4,6 +4,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.inventory.ItemStack; import cn.citycraft.ProtectItem.Main; @@ -17,7 +18,7 @@ public class DropItemListen implements Listener { @EventHandler(ignoreCancelled = true) public void onDropItem(PlayerDropItemEvent e) { Player p = e.getPlayer(); - String i = e.getItemDrop().getItemStack().getType().name(); + ItemStack i = e.getItemDrop().getItemStack(); e.setCancelled(plugin.checkevent(p, i, "Drop")); } } diff --git a/src/cn/citycraft/ProtectItem/listen/PickupItemListen.java b/src/cn/citycraft/ProtectItem/listen/PickupItemListen.java index 84aa9c1..88e8cb2 100644 --- a/src/cn/citycraft/ProtectItem/listen/PickupItemListen.java +++ b/src/cn/citycraft/ProtectItem/listen/PickupItemListen.java @@ -4,6 +4,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.inventory.ItemStack; import cn.citycraft.ProtectItem.Main; @@ -17,7 +18,7 @@ public class PickupItemListen implements Listener { @EventHandler(ignoreCancelled = true) public void onPickupItem(PlayerPickupItemEvent e) { Player p = e.getPlayer(); - String i = e.getItem().getItemStack().getType().name(); + ItemStack i = e.getItem().getItemStack(); e.setCancelled(plugin.checkevent(p, i, "Pickup")); } diff --git a/src/cn/citycraft/ProtectItem/listen/PlaceBlockListen.java b/src/cn/citycraft/ProtectItem/listen/PlaceBlockListen.java deleted file mode 100644 index 47e0898..0000000 --- a/src/cn/citycraft/ProtectItem/listen/PlaceBlockListen.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.citycraft.ProtectItem.listen; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPlaceEvent; - -import cn.citycraft.ProtectItem.Main; - -public class PlaceBlockListen implements Listener { - Main plugin; - - public PlaceBlockListen(Main main) { - plugin = main; - } - - @EventHandler(ignoreCancelled = true) - public void onPlaceItem(BlockPlaceEvent e) { - Player p = e.getPlayer(); - String i = e.getBlock().getType().name(); - e.setCancelled(plugin.checkevent(p, i, "Place")); - } -} diff --git a/src/config.yml b/src/config.yml index 6f29313..9cfe674 100644 --- a/src/config.yml +++ b/src/config.yml @@ -10,15 +10,15 @@ Message: #鰲ȫʾ Drop: '&cǰֹƷ' Pickup: '&cǰֹʰȡƷ' - Place: '&cǰֹøƷ' - Break: '&cǰֹƻƷ' +# Place: '&cǰֹøƷ' +# Break: '&cǰֹƻƷ' #ܵ Protect: Drop: true - Pickup: true - Place: true - Break: true + Pickup: false +##Place: false +##Break: false #ܵ(ִСд) ProtectWorld: @@ -26,6 +26,7 @@ ProtectWorld: #Ʒ(ִСд) ProtectItem: + - XXXX #(Ʒ,/pishow鿴Ʒ) # - DIRT # - GRASS