From 2264925f6adc8a2e70ec4ece104e974dab7d9541 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Tue, 28 Apr 2015 15:31:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: j502647092 --- .gitignore | 7 +++ .../github/j502647092/BanDropDirt/Main.java | 60 +++++++++++++++++++ .../BanDropDirt/listen/BreakBlockListen.java | 24 ++++++++ .../BanDropDirt/listen/DropItemListen.java | 25 ++++++++ .../BanDropDirt/listen/PickupItemListen.java | 26 ++++++++ .../BanDropDirt/listen/PlaceBlockListen.java | 24 ++++++++ src/config.yml | 25 ++++++++ src/plugin.yml | 3 + 8 files changed, 194 insertions(+) create mode 100644 .gitignore create mode 100644 src/com/github/j502647092/BanDropDirt/Main.java create mode 100644 src/com/github/j502647092/BanDropDirt/listen/BreakBlockListen.java create mode 100644 src/com/github/j502647092/BanDropDirt/listen/DropItemListen.java create mode 100644 src/com/github/j502647092/BanDropDirt/listen/PickupItemListen.java create mode 100644 src/com/github/j502647092/BanDropDirt/listen/PlaceBlockListen.java create mode 100644 src/config.yml create mode 100644 src/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..78186a5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.class +.metadata +.recommenders +.classpath +.settings +.project +bin/ \ No newline at end of file diff --git a/src/com/github/j502647092/BanDropDirt/Main.java b/src/com/github/j502647092/BanDropDirt/Main.java new file mode 100644 index 0000000..6532a81 --- /dev/null +++ b/src/com/github/j502647092/BanDropDirt/Main.java @@ -0,0 +1,60 @@ +package com.github.j502647092.BanDropDirt; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import com.github.j502647092.BanDropDirt.listen.BreakBlockListen; +import com.github.j502647092.BanDropDirt.listen.DropItemListen; +import com.github.j502647092.BanDropDirt.listen.PickupItemListen; +import com.github.j502647092.BanDropDirt.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() { + Bukkit.getPluginManager() + .registerEvents(new DropItemListen(this), this); + Bukkit.getPluginManager().registerEvents(new PickupItemListen(this), + this); + Bukkit.getPluginManager().registerEvents(new BreakBlockListen(this), + this); + Bukkit.getPluginManager().registerEvents(new PlaceBlockListen(this), + this); + getLogger().info("BanDropDirt已加载!"); + } + + public boolean checkevent(Player p, String i, String type) { + if (p.hasPermission("bdd.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/com/github/j502647092/BanDropDirt/listen/BreakBlockListen.java b/src/com/github/j502647092/BanDropDirt/listen/BreakBlockListen.java new file mode 100644 index 0000000..875216a --- /dev/null +++ b/src/com/github/j502647092/BanDropDirt/listen/BreakBlockListen.java @@ -0,0 +1,24 @@ +package com.github.j502647092.BanDropDirt.listen; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; + +import com.github.j502647092.BanDropDirt.Main; + +public class BreakBlockListen implements Listener { + Main plugin; + + public BreakBlockListen(Main main) { + // TODO Auto-generated constructor stub + plugin = main; + } + + @EventHandler(ignoreCancelled = true) + public void onDropItem(BlockBreakEvent e) { + Player p = e.getPlayer(); + String i = e.getBlock().getType().name(); + e.setCancelled(plugin.checkevent(p, i, "Break")); + } +} diff --git a/src/com/github/j502647092/BanDropDirt/listen/DropItemListen.java b/src/com/github/j502647092/BanDropDirt/listen/DropItemListen.java new file mode 100644 index 0000000..53cafbe --- /dev/null +++ b/src/com/github/j502647092/BanDropDirt/listen/DropItemListen.java @@ -0,0 +1,25 @@ +package com.github.j502647092.BanDropDirt.listen; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerDropItemEvent; + +import com.github.j502647092.BanDropDirt.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(); + if (plugin.checkevent(p, i, "Drop")) + e.getItemDrop().remove(); + } +} diff --git a/src/com/github/j502647092/BanDropDirt/listen/PickupItemListen.java b/src/com/github/j502647092/BanDropDirt/listen/PickupItemListen.java new file mode 100644 index 0000000..eed921b --- /dev/null +++ b/src/com/github/j502647092/BanDropDirt/listen/PickupItemListen.java @@ -0,0 +1,26 @@ +package com.github.j502647092.BanDropDirt.listen; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerPickupItemEvent; + +import com.github.j502647092.BanDropDirt.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(); + if (plugin.checkevent(p, i, "Pickup")) + e.getItem().remove(); + } + +} diff --git a/src/com/github/j502647092/BanDropDirt/listen/PlaceBlockListen.java b/src/com/github/j502647092/BanDropDirt/listen/PlaceBlockListen.java new file mode 100644 index 0000000..c7732b8 --- /dev/null +++ b/src/com/github/j502647092/BanDropDirt/listen/PlaceBlockListen.java @@ -0,0 +1,24 @@ +package com.github.j502647092.BanDropDirt.listen; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; + +import com.github.j502647092.BanDropDirt.Main; + +public class PlaceBlockListen implements Listener { + Main plugin; + + public PlaceBlockListen(Main main) { + // TODO Auto-generated constructor stub + plugin = main; + } + + @EventHandler(ignoreCancelled = true) + public void onDropItem(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 new file mode 100644 index 0000000..a8119c2 --- /dev/null +++ b/src/config.yml @@ -0,0 +1,25 @@ +#±¾ÎļþΪ±£»¤²å¼þµÄÖ÷ÅäÖÃÎļþ +#·þÎñÆ÷Ãû³Æ +servername: '' +#²å¼þÃû³Æ +pluginname: '&6[&3º£µº±£»¤&6]&r' + +#ÌáʾÏûÏ¢ +Message: + Reload: '&aÅäÖÃÎļþÒÑÖØÐÂÔØÈ룡' +#·½¿é°²È«Ìáʾ + Drop: '&cµ±Ç°ÊÀ½ç½ûÖ¹¶ªÆúÄàÍÁ,¶ªÆúµÄÄàÍÁÒÑÇå¿Õ£¡' + Pickup: '&cµ±Ç°ÊÀ½ç½ûֹʰȡÄàÍÁ,Ê°È¡µÄÄàÍÁÒÑÇå¿Õ£¡' + Place: '&cµ±Ç°ÊÀ½ç½ûÖ¹·ÅÖÃÄàÍÁ,Ïä×Ó£¡' + Break: '&cµ±Ç°ÊÀ½ç½ûÖ¹ÆÆ»µÄàÍÁ,Ïä×Ó£¡' +#Êܵ½±£»¤µÄÊÀ½ç(²»Çø·Ö´óСд) +ProtectWorld: + - world + - AcidIsland_nether + +#±£»¤µÄ·½¿é(²»Çø·Ö´óСд) +ProtectItem: + - DIRT + - GRASS + - CHEST + - TRAPPED_CHEST diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..535bb67 --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,3 @@ +name: BanDropDirt +main: com.github.j502647092.BanDropDirt.Main +version: 1.0 \ No newline at end of file