1
0
mirror of https://e.coding.net/circlecloud/ProtectItem.git synced 2024-11-17 14:18:46 +00:00

remove block listen change config class...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-05-11 14:59:54 +08:00
parent 35ed36c8a0
commit 0b5b0212d6
6 changed files with 34 additions and 69 deletions

View File

@ -9,10 +9,8 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.ProtectItem.listen.BreakBlockListen;
import cn.citycraft.ProtectItem.listen.DropItemListen; import cn.citycraft.ProtectItem.listen.DropItemListen;
import cn.citycraft.ProtectItem.listen.PickupItemListen; import cn.citycraft.ProtectItem.listen.PickupItemListen;
import cn.citycraft.ProtectItem.listen.PlaceBlockListen;
public class Main extends JavaPlugin { public class Main extends JavaPlugin {
public String servername; public String servername;
@ -32,12 +30,12 @@ public class Main extends JavaPlugin {
if (getConfig().getBoolean("Protect.Pickup", true)) if (getConfig().getBoolean("Protect.Pickup", true))
Bukkit.getPluginManager().registerEvents( Bukkit.getPluginManager().registerEvents(
new PickupItemListen(this), this); new PickupItemListen(this), this);
if (getConfig().getBoolean("Protect.Break", true)) // if (getConfig().getBoolean("Protect.Break", true))
Bukkit.getPluginManager().registerEvents( // Bukkit.getPluginManager().registerEvents(
new BreakBlockListen(this), this); // new BreakBlockListen(this), this);
if (getConfig().getBoolean("Protect.Place", true)) // if (getConfig().getBoolean("Protect.Place", true))
Bukkit.getPluginManager().registerEvents( // Bukkit.getPluginManager().registerEvents(
new PlaceBlockListen(this), this); // new PlaceBlockListen(this), this);
getLogger().info("ProtectItem已加载!"); getLogger().info("ProtectItem已加载!");
} }
@ -48,30 +46,32 @@ public class Main extends JavaPlugin {
switch (args.length) { switch (args.length) {
case 0: case 0:
ItemStack item = p.getItemInHand(); ItemStack item = p.getItemInHand();
p.sendMessage("手上物品类型名称为: " + item.getType().name()); p.sendMessage("\u00a7a手上物品类型名称为: \u00a76" + getItemName(item));
return true; return true;
case 1: case 1:
if (args[0].equalsIgnoreCase("reload")) { if (p.hasPermission("pi.bypass"))
this.reloadConfig(); if (args[0].equalsIgnoreCase("reload")) {
p.sendMessage("\u00a7a配置文件已重载..."); this.reloadConfig();
return true; p.sendMessage("\u00a7a配置文件已重载...");
} return true;
}
break; break;
default: default:
} }
return false; 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")) if (p.hasPermission("pi.bypass"))
return false; return false;
String iname = getItemName(i);
Location l = p.getLocation(); Location l = p.getLocation();
World pw = l.getWorld(); World pw = l.getWorld();
for (String protectworld : getConfig().getStringList("ProtectWorld")) { for (String protectworld : getConfig().getStringList("ProtectWorld")) {
if (pw.getName().equalsIgnoreCase(protectworld)) if (pw.getName().equalsIgnoreCase(protectworld))
for (String protectitem : getConfig().getStringList( for (String protectitem : getConfig().getStringList(
"ProtectItem")) { "ProtectItem")) {
if (i.equalsIgnoreCase(protectitem)) { if (iname.equalsIgnoreCase(protectitem)) {
p.sendMessage(pluginname p.sendMessage(pluginname
+ getmessage("Message." + type)); + getmessage("Message." + type));
return true; return true;
@ -81,6 +81,14 @@ public class Main extends JavaPlugin {
return false; 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) { public String getmessage(String path) {
String message = getConfig().getString(path).replaceAll("&", "§"); String message = getConfig().getString(path).replaceAll("&", "§");
return message; return message;

View File

@ -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"));
}
}

View File

@ -4,6 +4,7 @@ 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;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.ProtectItem.Main; import cn.citycraft.ProtectItem.Main;
@ -17,7 +18,7 @@ public class DropItemListen implements Listener {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onDropItem(PlayerDropItemEvent e) { public void onDropItem(PlayerDropItemEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
String i = e.getItemDrop().getItemStack().getType().name(); ItemStack i = e.getItemDrop().getItemStack();
e.setCancelled(plugin.checkevent(p, i, "Drop")); e.setCancelled(plugin.checkevent(p, i, "Drop"));
} }
} }

View File

@ -4,6 +4,7 @@ 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;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.ProtectItem.Main; import cn.citycraft.ProtectItem.Main;
@ -17,7 +18,7 @@ public class PickupItemListen implements Listener {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPickupItem(PlayerPickupItemEvent e) { public void onPickupItem(PlayerPickupItemEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
String i = e.getItem().getItemStack().getType().name(); ItemStack i = e.getItem().getItemStack();
e.setCancelled(plugin.checkevent(p, i, "Pickup")); e.setCancelled(plugin.checkevent(p, i, "Pickup"));
} }

View File

@ -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"));
}
}

View File

@ -10,15 +10,15 @@ Message:
#方块安全提示 #方块安全提示
Drop: '&c当前世界禁止丢弃该物品' Drop: '&c当前世界禁止丢弃该物品'
Pickup: '&c当前世界禁止拾取该物品' Pickup: '&c当前世界禁止拾取该物品'
Place: '&c当前世界禁止放置该物品' # Place: '&c当前世界禁止放置该物品'
Break: '&c当前世界禁止破坏该物品' # Break: '&c当前世界禁止破坏该物品'
#受到保护的类型 #受到保护的类型
Protect: Protect:
Drop: true Drop: true
Pickup: true Pickup: false
Place: true ##Place: false
Break: true ##Break: false
#受到保护的世界(不区分大小写) #受到保护的世界(不区分大小写)
ProtectWorld: ProtectWorld:
@ -26,6 +26,7 @@ ProtectWorld:
#保护的物品(不区分大小写) #保护的物品(不区分大小写)
ProtectItem: ProtectItem:
- XXXX
#例如(请输入物品类型名称,/pishow查看物品名称) #例如(请输入物品类型名称,/pishow查看物品名称)
# - DIRT # - DIRT
# - GRASS # - GRASS