From e9b86302847a49a4528a3edc31a987616a9259a5 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Sat, 30 May 2015 21:26:14 +0800 Subject: [PATCH] update Main class name... Signed-off-by: j502647092 --- .../{Main.java => ProtectItem.java} | 101 +++++++++--------- .../ProtectItem/listen/DropItemListen.java | 8 +- .../ProtectItem/listen/PickupItemListen.java | 8 +- 3 files changed, 61 insertions(+), 56 deletions(-) rename src/cn/citycraft/ProtectItem/{Main.java => ProtectItem.java} (88%) diff --git a/src/cn/citycraft/ProtectItem/Main.java b/src/cn/citycraft/ProtectItem/ProtectItem.java similarity index 88% rename from src/cn/citycraft/ProtectItem/Main.java rename to src/cn/citycraft/ProtectItem/ProtectItem.java index 5e4e341..f9c5676 100644 --- a/src/cn/citycraft/ProtectItem/Main.java +++ b/src/cn/citycraft/ProtectItem/ProtectItem.java @@ -12,31 +12,42 @@ import org.bukkit.plugin.java.JavaPlugin; import cn.citycraft.ProtectItem.listen.DropItemListen; import cn.citycraft.ProtectItem.listen.PickupItemListen; -public class Main extends JavaPlugin { +public class ProtectItem extends JavaPlugin { + 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 servername; + public String pluginname; - public void onLoad() { - saveDefaultConfig(); - reloadConfig(); - servername = getmessage("servername"); - pluginname = getmessage("pluginname") + " "; + 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 (iname.equalsIgnoreCase(protectitem)) { + p.sendMessage(pluginname + + getmessage("Message." + type)); + return true; + } + } + } + } + return false; } - public void onEnable() { - if (getConfig().getBoolean("Protect.Drop", true)) - Bukkit.getPluginManager().registerEvents(new DropItemListen(this), - this); - 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); - getLogger().info("ProtectItem已加载!"); + public String getmessage(String path) { + String message = getConfig().getString(path).replaceAll("&", "§"); + return message; } @Override @@ -61,36 +72,30 @@ public class Main extends JavaPlugin { return false; } - 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 (iname.equalsIgnoreCase(protectitem)) { - p.sendMessage(pluginname - + getmessage("Message." + type)); - return true; - } - } + @Override + public void onEnable() { + if (getConfig().getBoolean("Protect.Drop", true)) { + Bukkit.getPluginManager().registerEvents(new DropItemListen(this), + this); } - return false; + 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); + getLogger().info("ProtectItem已加载!"); } - 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; + @Override + public void onLoad() { + saveDefaultConfig(); + reloadConfig(); + servername = getmessage("servername"); + pluginname = getmessage("pluginname") + " "; } } diff --git a/src/cn/citycraft/ProtectItem/listen/DropItemListen.java b/src/cn/citycraft/ProtectItem/listen/DropItemListen.java index d63abec..b12d9d3 100644 --- a/src/cn/citycraft/ProtectItem/listen/DropItemListen.java +++ b/src/cn/citycraft/ProtectItem/listen/DropItemListen.java @@ -6,12 +6,12 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.ItemStack; -import cn.citycraft.ProtectItem.Main; +import cn.citycraft.ProtectItem.ProtectItem; public class DropItemListen implements Listener { - Main plugin; + ProtectItem plugin; - public DropItemListen(Main main) { + public DropItemListen(ProtectItem main) { plugin = main; } @@ -19,6 +19,6 @@ public class DropItemListen implements Listener { public void onDropItem(PlayerDropItemEvent e) { Player p = e.getPlayer(); ItemStack i = e.getItemDrop().getItemStack(); - e.setCancelled(plugin.checkevent(p, i, "Drop")); + 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 88e8cb2..223ebdc 100644 --- a/src/cn/citycraft/ProtectItem/listen/PickupItemListen.java +++ b/src/cn/citycraft/ProtectItem/listen/PickupItemListen.java @@ -6,12 +6,12 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; -import cn.citycraft.ProtectItem.Main; +import cn.citycraft.ProtectItem.ProtectItem; public class PickupItemListen implements Listener { - Main plugin; + ProtectItem plugin; - public PickupItemListen(Main main) { + public PickupItemListen(ProtectItem main) { plugin = main; } @@ -19,7 +19,7 @@ public class PickupItemListen implements Listener { public void onPickupItem(PlayerPickupItemEvent e) { Player p = e.getPlayer(); ItemStack i = e.getItem().getItemStack(); - e.setCancelled(plugin.checkevent(p, i, "Pickup")); + e.setCancelled(plugin.checkevent(p, i, "Pickup")); } }