1
0
mirror of https://e.coding.net/circlecloud/ProtectItem.git synced 2024-12-27 20:48:51 +00:00

update Main class name...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-05-30 21:26:14 +08:00
parent 0b5b0212d6
commit e9b8630284
3 changed files with 61 additions and 56 deletions

View File

@ -12,31 +12,42 @@ import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.ProtectItem.listen.DropItemListen; import cn.citycraft.ProtectItem.listen.DropItemListen;
import cn.citycraft.ProtectItem.listen.PickupItemListen; 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 servername;
public String pluginname; public String pluginname;
public void onLoad() { public boolean checkevent(Player p, ItemStack i, String type) {
saveDefaultConfig(); if (p.hasPermission("pi.bypass"))
reloadConfig(); return false;
servername = getmessage("servername"); String iname = getItemName(i);
pluginname = getmessage("pluginname") + " "; 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() { public String getmessage(String path) {
if (getConfig().getBoolean("Protect.Drop", true)) String message = getConfig().getString(path).replaceAll("&", "§");
Bukkit.getPluginManager().registerEvents(new DropItemListen(this), return message;
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 @Override
@ -61,36 +72,30 @@ public class Main extends JavaPlugin {
return false; return false;
} }
public boolean checkevent(Player p, ItemStack i, String type) { @Override
if (p.hasPermission("pi.bypass")) public void onEnable() {
return false; if (getConfig().getBoolean("Protect.Drop", true)) {
String iname = getItemName(i); Bukkit.getPluginManager().registerEvents(new DropItemListen(this),
Location l = p.getLocation(); this);
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; 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) { @Override
String name = i.getType().name(); public void onLoad() {
int dur = i.getDurability(); saveDefaultConfig();
String dura = i.getMaxStackSize() != 1 ? dur != 0 ? "_" + dur : "" : ""; reloadConfig();
String iname = name + dura; servername = getmessage("servername");
return iname; pluginname = getmessage("pluginname") + " ";
}
public String getmessage(String path) {
String message = getConfig().getString(path).replaceAll("&", "§");
return message;
} }
} }

View File

@ -6,12 +6,12 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import cn.citycraft.ProtectItem.Main; import cn.citycraft.ProtectItem.ProtectItem;
public class DropItemListen implements Listener { public class DropItemListen implements Listener {
Main plugin; ProtectItem plugin;
public DropItemListen(Main main) { public DropItemListen(ProtectItem main) {
plugin = main; plugin = main;
} }
@ -19,6 +19,6 @@ public class DropItemListen implements Listener {
public void onDropItem(PlayerDropItemEvent e) { public void onDropItem(PlayerDropItemEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
ItemStack i = e.getItemDrop().getItemStack(); ItemStack i = e.getItemDrop().getItemStack();
e.setCancelled(plugin.checkevent(p, i, "Drop")); e.setCancelled(plugin.checkevent(p, i, "Drop"));
} }
} }

View File

@ -6,12 +6,12 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import cn.citycraft.ProtectItem.Main; import cn.citycraft.ProtectItem.ProtectItem;
public class PickupItemListen implements Listener { public class PickupItemListen implements Listener {
Main plugin; ProtectItem plugin;
public PickupItemListen(Main main) { public PickupItemListen(ProtectItem main) {
plugin = main; plugin = main;
} }
@ -19,7 +19,7 @@ public class PickupItemListen implements Listener {
public void onPickupItem(PlayerPickupItemEvent e) { public void onPickupItem(PlayerPickupItemEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
ItemStack i = e.getItem().getItemStack(); ItemStack i = e.getItem().getItemStack();
e.setCancelled(plugin.checkevent(p, i, "Pickup")); e.setCancelled(plugin.checkevent(p, i, "Pickup"));
} }
} }