1
0
mirror of https://e.coding.net/circlecloud/ProtectItem.git synced 2024-12-26 20:38:49 +00:00

fix can't load this plugin...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-05-05 22:09:20 +08:00
parent 57fc847fe6
commit 7b65793c44
7 changed files with 229 additions and 198 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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

View File

@ -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