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:
parent
35ed36c8a0
commit
0b5b0212d6
@ -9,10 +9,8 @@ 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;
|
||||
@ -32,12 +30,12 @@ public class Main extends JavaPlugin {
|
||||
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);
|
||||
// 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已加载!");
|
||||
}
|
||||
|
||||
@ -48,9 +46,10 @@ public class Main extends JavaPlugin {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
ItemStack item = p.getItemInHand();
|
||||
p.sendMessage("手上物品类型名称为: " + item.getType().name());
|
||||
p.sendMessage("\u00a7a手上物品类型名称为: \u00a76" + getItemName(item));
|
||||
return true;
|
||||
case 1:
|
||||
if (p.hasPermission("pi.bypass"))
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
this.reloadConfig();
|
||||
p.sendMessage("\u00a7a配置文件已重载...");
|
||||
@ -62,16 +61,17 @@ public class Main extends JavaPlugin {
|
||||
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"))
|
||||
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 (i.equalsIgnoreCase(protectitem)) {
|
||||
if (iname.equalsIgnoreCase(protectitem)) {
|
||||
p.sendMessage(pluginname
|
||||
+ getmessage("Message." + type));
|
||||
return true;
|
||||
@ -81,6 +81,14 @@ public class Main extends JavaPlugin {
|
||||
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) {
|
||||
String message = getConfig().getString(path).replaceAll("&", "§");
|
||||
return message;
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import cn.citycraft.ProtectItem.Main;
|
||||
|
||||
@ -17,7 +18,7 @@ public class DropItemListen implements Listener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onDropItem(PlayerDropItemEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
String i = e.getItemDrop().getItemStack().getType().name();
|
||||
ItemStack i = e.getItemDrop().getItemStack();
|
||||
e.setCancelled(plugin.checkevent(p, i, "Drop"));
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import cn.citycraft.ProtectItem.Main;
|
||||
|
||||
@ -17,7 +18,7 @@ public class PickupItemListen implements Listener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPickupItem(PlayerPickupItemEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
String i = e.getItem().getItemStack().getType().name();
|
||||
ItemStack i = e.getItem().getItemStack();
|
||||
e.setCancelled(plugin.checkevent(p, i, "Pickup"));
|
||||
}
|
||||
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
@ -10,15 +10,15 @@ Message:
|
||||
#方块安全提示
|
||||
Drop: '&c当前世界禁止丢弃该物品!'
|
||||
Pickup: '&c当前世界禁止拾取该物品!'
|
||||
Place: '&c当前世界禁止放置该物品!'
|
||||
Break: '&c当前世界禁止破坏该物品!'
|
||||
# Place: '&c当前世界禁止放置该物品!'
|
||||
# Break: '&c当前世界禁止破坏该物品!'
|
||||
|
||||
#受到保护的类型
|
||||
Protect:
|
||||
Drop: true
|
||||
Pickup: true
|
||||
Place: true
|
||||
Break: true
|
||||
Pickup: false
|
||||
##Place: false
|
||||
##Break: false
|
||||
|
||||
#受到保护的世界(不区分大小写)
|
||||
ProtectWorld:
|
||||
@ -26,6 +26,7 @@ ProtectWorld:
|
||||
|
||||
#保护的物品(不区分大小写)
|
||||
ProtectItem:
|
||||
- XXXX
|
||||
#例如(请输入物品类型名称,/pishow查看物品名称)
|
||||
# - DIRT
|
||||
# - GRASS
|
||||
|
Loading…
Reference in New Issue
Block a user