fix config null and add command color...

Signed-off-by: j502647092 <jtb1@163.com>
master
j502647092 2015-10-24 23:12:29 +08:00
parent 8d627c0443
commit 6341c07819
3 changed files with 20 additions and 18 deletions

View File

@ -30,16 +30,16 @@ public class CommandBan extends BaseCommand {
switch (args.length) { switch (args.length) {
case 0: case 0:
plugin.getItemManager().banItem(item); plugin.getItemManager().banItem(item);
p.sendMessage("当前物品 " + itemname + " 已被禁封!"); p.sendMessage(plugin.pluginname + "§c当前物品 §a" + itemname + " §c已被禁封!");
return; return;
case 1: case 1:
try { try {
final ActionType action = Enum.valueOf(ActionType.class, args[0]); final ActionType action = Enum.valueOf(ActionType.class, args[0]);
plugin.getItemManager().banItem(item, action); plugin.getItemManager().banItem(item, action);
p.sendMessage("当前物品 " + itemname + " 已被禁封 操作" + action.toString() + "!"); p.sendMessage(plugin.pluginname + "§c当前物品 §a" + itemname + " §c已被禁封 §c操作 §b" + action.toString() + "!");
} catch (final Exception e) { } catch (final Exception e) {
p.sendMessage("未知的操作类型" + args[0] + "!"); p.sendMessage(plugin.pluginname + "§c未知的操作类型" + args[0] + "!");
} }
} }
} }

View File

@ -30,16 +30,16 @@ public class CommandUnban extends BaseCommand {
switch (args.length) { switch (args.length) {
case 0: case 0:
plugin.getItemManager().unBanItem(item); plugin.getItemManager().unBanItem(item);
p.sendMessage("当前物品 " + itemname + " 已被解禁!"); p.sendMessage(plugin.pluginname + "§a当前物品 " + itemname + " 已被解禁!");
return; return;
case 1: case 1:
try { try {
final ActionType action = Enum.valueOf(ActionType.class, args[0]); final ActionType action = Enum.valueOf(ActionType.class, args[0]);
plugin.getItemManager().unBanItem(item, action); plugin.getItemManager().unBanItem(item, action);
p.sendMessage("当前物品 " + itemname + " 已被解禁 操作" + action.toString() + "!"); p.sendMessage(plugin.pluginname + "§a当前物品 " + itemname + " 已被解禁 操作 §b" + action.toString() + "!");
} catch (final Exception e) { } catch (final Exception e) {
p.sendMessage("未知的操作类型" + args[0] + "!"); p.sendMessage(plugin.pluginname + "§c未知的操作类型" + args[0] + "!");
} }
} }
} }

View File

@ -8,6 +8,7 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -22,21 +23,22 @@ public class ItemManager {
public ItemManager(final ProtectItem main) { public ItemManager(final ProtectItem main) {
plugin = main; plugin = main;
itemconfig = new FileConfig(plugin, "banitems.yml"); itemconfig = new FileConfig(plugin, "banitems.yml");
final Set<String> items = itemconfig.getConfigurationSection("banitems").getKeys(false); final ConfigurationSection cfg = itemconfig.getConfigurationSection("banitems");
if (items != null) { if (cfg != null) {
for (final String banitem : items) { final Set<String> items = itemconfig.getConfigurationSection("banitems").getKeys(false);
final List<ActionType> actlist = new ArrayList<ActionType>(); if (items != null) {
for (final String action : itemconfig.getStringList("banitems." + banitem)) { for (final String banitem : items) {
try { final List<ActionType> actlist = new ArrayList<ActionType>();
final ActionType act = Enum.valueOf(ActionType.class, action); for (final String action : itemconfig.getStringList("banitems." + banitem)) {
actlist.add(act); try {
} catch (final Exception e) { final ActionType act = Enum.valueOf(ActionType.class, action);
actlist.add(act);
} catch (final Exception e) {
}
} }
itemlist.put(banitem, actlist);
} }
itemlist.put(banitem, actlist);
} }
} else {
itemlist = new HashMap<String, List<ActionType>>();
} }
} }