/**
* initModule enables the module called by {@link TerraCraftTools}
*/
public void initModule(TerraCraftTools sst) {
plugin = sst;
kits = new HashMap<String, List<ItemStack>>();
cooldowns = new HashMap<Player, Long>();
File[] kitFiles = plugin.getDataFolder().listFiles(new IsYML());
if (kitFiles.length == 0) {
return;
}
//This is prone to throw some exceptions if the config is poorly written.
//If you feel like cleaning it up, feel free to Pull Request.
for (File kit : kitFiles) {
FileConfiguration kitConf = YamlConfiguration.loadConfiguration(kit);
List<String> desc = kitConf.getStringList("description");
List<ItemStack> items = new LinkedList<ItemStack>();
List<String> itemConfs = kitConf.getStringList("items");
for (String itemConf : itemConfs) {
ItemStack itemStack = null;
String[] bits = itemConf.split(" ");
for (String bit : bits) {
if (bit.startsWith("id:")) {
itemStack = new ItemStack(Integer.valueOf(bit.substring(3)), 1);
}
if (itemStack == null) {
continue;
}
if (bit.startsWith("count:")) {
itemStack.setAmount(Integer.valueOf(bit.substring(6)));
} else if (bit.startsWith("!tagged")) {
ItemMeta im = itemStack.getItemMeta();
im.setLore(desc);
itemStack.setItemMeta(im);
} else if (bit.startsWith("data:")) {
itemStack.setDurability(Short.valueOf(bit.substring(5)));
} else if (bit.startsWith("ench:")) {
String ench = bit.substring(5);
String[] bites = ench.split(":");
//I don't want to deal with cosmetic names.
itemStack.addUnsafeEnchantment(Enchantment.getByName(bites[0]), Integer.valueOf(bites[1]));
} else if (bit.startsWith("anvilCost:")) {
Repairable r = (Repairable) itemStack.getItemMeta();
r.setRepairCost(Integer.valueOf(bit.substring(10)));
itemStack.setItemMeta((ItemMeta) r);
}
}
items.add(itemStack);
}
kits.put(kitConf.getString("kitName").toLowerCase(), items);
}
plugin.commandRegistrar.registerCommand("kit", this);
plugin.commandRegistrar.registerCommand("identify", this);
plugin.logger.info("[TerraCraftTools][GuardKits] GuardKits Module Enabled!");
}
GuardKits.java 文件源码
java
阅读 24
收藏 0
点赞 0
评论 0
项目:TerraCraftTools
作者:
评论列表
文章目录