diff --git a/src/cn/citycraft/ProtectItem/Main.java b/src/cn/citycraft/ProtectItem/Main.java index 22f82ce..81f5f87 100644 --- a/src/cn/citycraft/ProtectItem/Main.java +++ b/src/cn/citycraft/ProtectItem/Main.java @@ -1,64 +1,93 @@ -package cn.citycraft.ProtectItem; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; -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; - public String pluginname; - - public void onLoad() { - saveDefaultConfig(); - reloadConfig(); - servername = getmessage("servername"); - pluginname = getmessage("pluginname") + " "; - } - - 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 boolean checkevent(Player p, String i, String type) { - if (p.hasPermission("pi.bypass")) - return false; - 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)) { - p.sendMessage(pluginname - + getmessage("Message." + type)); - return true; - } - } - } - return false; - } - - public String getmessage(String path) { - String message = getConfig().getString(path).replaceAll("&", "§"); - return message; - } -} +package cn.citycraft.ProtectItem; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +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; + public String pluginname; + + public void onLoad() { + saveDefaultConfig(); + reloadConfig(); + servername = getmessage("servername"); + pluginname = getmessage("pluginname") + " "; + } + + 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已加载!"); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String string, + String[] args) { + Player p = (Player) sender; + switch (args.length) { + case 0: + ItemStack item = p.getItemInHand(); + p.sendMessage("手上物品类型名称为: " + item.getType().name()); + return true; + case 1: + switch (args[0]) { + case "reload": + this.reloadConfig(); + p.sendMessage("\u00a7a配置文件已重载..."); + return true; + case "add": + case "del": + return true; + default: + } + break; + default: + } + return false; + } + + public boolean checkevent(Player p, String i, String type) { + if (p.hasPermission("pi.bypass")) + return false; + 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)) { + p.sendMessage(pluginname + + getmessage("Message." + type)); + return true; + } + } + } + return false; + } + + 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 index 5ea578a..7238c3a 100644 --- a/src/cn/citycraft/ProtectItem/listen/BreakBlockListen.java +++ b/src/cn/citycraft/ProtectItem/listen/BreakBlockListen.java @@ -1,24 +1,23 @@ -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) { - // TODO Auto-generated constructor stub - 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")); - } -} +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 d23a41b..6466a6d 100644 --- a/src/cn/citycraft/ProtectItem/listen/DropItemListen.java +++ b/src/cn/citycraft/ProtectItem/listen/DropItemListen.java @@ -1,24 +1,23 @@ -package cn.citycraft.ProtectItem.listen; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerDropItemEvent; - -import cn.citycraft.ProtectItem.Main; - -public class DropItemListen implements Listener { - Main plugin; - - public DropItemListen(Main main) { - // TODO Auto-generated constructor stub - plugin = main; - } - - @EventHandler(ignoreCancelled = true) - public void onDropItem(PlayerDropItemEvent e) { - Player p = e.getPlayer(); - String i = e.getItemDrop().getItemStack().getType().name(); - e.setCancelled(plugin.checkevent(p, i, "Drop")); - } -} +package cn.citycraft.ProtectItem.listen; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerDropItemEvent; + +import cn.citycraft.ProtectItem.Main; + +public class DropItemListen implements Listener { + Main plugin; + + public DropItemListen(Main main) { + plugin = main; + } + + @EventHandler(ignoreCancelled = true) + public void onDropItem(PlayerDropItemEvent e) { + Player p = e.getPlayer(); + String i = e.getItemDrop().getItemStack().getType().name(); + 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 a7f5953..84aa9c1 100644 --- a/src/cn/citycraft/ProtectItem/listen/PickupItemListen.java +++ b/src/cn/citycraft/ProtectItem/listen/PickupItemListen.java @@ -1,25 +1,24 @@ -package cn.citycraft.ProtectItem.listen; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerPickupItemEvent; - -import cn.citycraft.ProtectItem.Main; - -public class PickupItemListen implements Listener { - Main plugin; - - public PickupItemListen(Main main) { - // TODO Auto-generated constructor stub - plugin = main; - } - - @EventHandler(ignoreCancelled = true) - public void onPickupItem(PlayerPickupItemEvent e) { - Player p = e.getPlayer(); - String i = e.getItem().getItemStack().getType().name(); - e.setCancelled(plugin.checkevent(p, i, "Pickup")); - } - -} +package cn.citycraft.ProtectItem.listen; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerPickupItemEvent; + +import cn.citycraft.ProtectItem.Main; + +public class PickupItemListen implements Listener { + Main plugin; + + public PickupItemListen(Main main) { + plugin = main; + } + + @EventHandler(ignoreCancelled = true) + public void onPickupItem(PlayerPickupItemEvent e) { + Player p = e.getPlayer(); + String i = e.getItem().getItemStack().getType().name(); + 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 index 3272448..47e0898 100644 --- a/src/cn/citycraft/ProtectItem/listen/PlaceBlockListen.java +++ b/src/cn/citycraft/ProtectItem/listen/PlaceBlockListen.java @@ -1,24 +1,23 @@ -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) { - // TODO Auto-generated constructor stub - 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")); - } -} +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 e6c0e3f..6f29313 100644 --- a/src/config.yml +++ b/src/config.yml @@ -1,32 +1,33 @@ -#ļΪļ -# -servername: '' -# -pluginname: '&6[&3Ʒ&6]&r' - -#ʾϢ -Message: - Reload: '&aļ룡' -#鰲ȫʾ - Drop: '&cǰֹƷ' - Pickup: '&cǰֹʰȡƷ' - Place: '&cǰֹøƷ' - Break: '&cǰֹƻƷ' - -#ܵ -Protect: - Drop: true - Pickup: true - Place: true - Break: true - -#ܵ(ִСд) -ProtectWorld: - - world - -#Ʒ(ִСд) -ProtectItem: - - DIRT - - GRASS - - CHEST - - TRAPPED_CHEST +#ļΪļ +# +servername: '' +# +pluginname: '&6[&3Ʒ&6]&r' + +#ʾϢ +Message: + Reload: '&aļ룡' +#鰲ȫʾ + Drop: '&cǰֹƷ' + Pickup: '&cǰֹʰȡƷ' + Place: '&cǰֹøƷ' + Break: '&cǰֹƻƷ' + +#ܵ +Protect: + Drop: true + Pickup: true + Place: true + Break: true + +#ܵ(ִСд) +ProtectWorld: + - world + +#Ʒ(ִСд) +ProtectItem: +#(Ʒ,/pishow鿴Ʒ) +# - DIRT +# - GRASS +# - CHEST +# - TRAPPED_CHEST diff --git a/src/plugin.yml b/src/plugin.yml index 818b47f..4df4980 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,11 @@ -name: ProtectItem -main: cn.CityCraft.ProtectItem.Main -version: 1.0 -permissions: - pi.bypass: +name: ProtectItem +main: cn.citycraft.ProtectItem.Main +version: 1.0 +auther: 喵♂呜 +commands: + pishow: + description: 物品保护插件 + usage: 使用/pishow 查看物品名称! +permissions: + pi.bypass: default: op \ No newline at end of file