use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class MobsGameParser method parseNode.
@Override
protected ParserResult<MobsGame.Config> parseNode(Node node, String name, String value) throws ParserException {
List<MobSpawnRule.Config> rules = new ArrayList<>();
for (Node ruleNode : node.children("rule")) {
rules.add(this.ruleParser.parse(ruleNode).orFail());
}
boolean denyNatural = this.denyNautralParser.parse(node.property("deny-natural")).orDefault(false);
if (!denyNatural && ParserUtils.ensureNotEmpty(rules)) {
throw this.fail(node, name, value, "No rules defined");
}
return ParserResult.fine(node, name, value, new MobsGame.Config() {
public List<MobSpawnRule.Config> rules() {
return rules;
}
public boolean denyNatural() {
return denyNatural;
}
});
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class ArcadePlugin method loadModules.
private void loadModules() {
Node ignoredModules = this.getSettings().getData().child("ignored-modules");
if (ignoredModules == null) {
ignoredModules = Node.empty();
}
List<String> ignoredModuleList = new ArrayList<>();
for (Node ignoredModule : ignoredModules.children("module")) {
String id = ignoredModule.getValue();
if (id != null && !id.isEmpty()) {
ignoredModuleList.add(id);
}
}
List<Module<?>> moduleList = new ArrayList<>();
try (InputStream input = this.getClass().getClassLoader().getResourceAsStream(ModulesFile.DEFAULT_FILENAME)) {
ModulesFile file = new ModulesFile(this, input);
for (Module<?> module : file.getModules()) {
ModuleInfo infoAnnotation = module.getClass().getAnnotation(ModuleInfo.class);
if (infoAnnotation == null) {
continue;
}
if (!ignoredModuleList.contains(infoAnnotation.id().toLowerCase())) {
moduleList.add(module);
}
}
} catch (DOMException | IOException ex) {
ex.printStackTrace();
}
ModulesLoadEvent loadEvent = new ModulesLoadEvent(this, moduleList);
this.getEventBus().publish(loadEvent);
List<Module<?>> success = new ArrayList<>();
for (Module<?> module : loadEvent.getModules()) {
try {
module.initialize(this);
module.registerCommandObject(module);
success.add(module);
} catch (Throwable th) {
this.getLogger().log(Level.SEVERE, "Could not load module '" + module.getId() + "': " + th.getMessage(), th);
}
}
this.getLogger().info("Successfully loaded " + success.size() + " of " + loadEvent.getModules().size() + " available modules.");
this.getModules().register(success.toArray(new Module<?>[success.size()]));
Node globalModules = this.getSettings().getData().child("modules");
if (globalModules == null) {
globalModules = Node.empty();
}
for (Module<?> module : this.getModules().getModules()) {
try {
Node moduleNode = globalModules.child(module.getId());
module.setGlobal(moduleNode != null);
module.registerListeners();
module.onEnable(moduleNode);
} catch (Throwable th) {
this.getLogger().log(Level.SEVERE, "Could not enable module '" + module.getId() + "': " + th.getMessage(), th);
}
}
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class ArcadePlugin method loadServer.
private void loadServer() {
Node node = this.getSettings().getData().child("server");
if (node == null) {
node = Node.empty();
}
String name = node.propertyValue("name");
if (name != null && this.serverName.equals(DEFAULT_SERVER_NAME)) {
this.serverName = name;
}
this.registerListenerObject(new BlockTransformListeners(this));
this.registerListenerObject(new GeneralListeners(this));
this.registerListenerObject(new ProtectionListeners(this));
// dead events
this.registerListenerObject(new DeadListeners(this));
// sessions
this.registerListenerObject(new Sessions(this));
// windows
this.registerListenerObject(new WindowListeners(this));
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class ItemStackParser method parseTree.
@Override
protected ParserResult<ItemStack> parseTree(Node node, String name) throws ParserException {
Property amountProperty = node.property("amount", "total");
Property durabilityProperty = node.property("durability");
MaterialData type = this.typeParser.parse(node.property(MaterialParser.MATERIAL_ELEMENT_NAMES)).orFail();
int amount = this.amountParser.parse(amountProperty).orDefault(1);
String displayName = this.displayNameParser.parse(node.firstChild("name", "display-name")).orDefaultNull();
List<String> description = this.parseDescription(node);
short durability = this.durabilityParser.parse(durabilityProperty).orDefault((short) 0);
List<ItemEnchantment> enchantments = this.parseEnchantments(node);
List<Material> canDestroy = this.parseDestroy(node);
List<Material> canPlaceOn = this.parseCanPlaceOn(node);
boolean unbreakable = this.unbreakableParser.parse(node.property("unbreakable", "permanent")).orDefault(false);
List<ItemFlag> flags = this.parseFlags(node);
if (amount <= 0) {
throw this.fail(amountProperty, "Amount must be positive (greater than 0)");
} else if (type.getData() != 0 && durability != 0) {
// Notch made a huge mistake here... :(
throw this.fail(durabilityProperty, "Sorry! Durability cannot be combined with material data!");
}
ItemStack itemStack = new ItemStack(type.getItemType());
itemStack.setData(type);
itemStack.setAmount(amount);
itemStack.setDurability(durability);
for (ItemEnchantment enchantment : enchantments) {
enchantment.apply(itemStack);
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (displayName != null) {
itemMeta.setDisplayName(displayName);
}
if (!description.isEmpty()) {
itemMeta.setLore(description);
}
if (!canDestroy.isEmpty()) {
itemMeta.setCanDestroy(canDestroy);
}
if (!canPlaceOn.isEmpty()) {
itemMeta.setCanPlaceOn(canPlaceOn);
}
for (Node modifierNode : node.children("modifier", "attribute-modifier", "attributemodifier", "attribute")) {
BoundedItemModifier modifier = this.modifierParser.parse(modifierNode).orFail();
itemMeta.addAttributeModifier(modifier.getKey().key(), modifier.getItemModifier());
}
itemMeta.setUnbreakable(unbreakable);
itemMeta.addItemFlags(flags.toArray(new ItemFlag[flags.size()]));
itemStack.setItemMeta(this.itemMetaParser.parse(node, itemStack, itemMeta));
return ParserResult.fine(node, name, itemStack);
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class BookMetaParser method parse.
@Override
public BookMeta parse(Node root, ItemStack itemStack, BookMeta itemMeta) throws ParserException {
Node node = root.firstChild("book");
if (node != null) {
Property author = root.property("author", "signed", "signed-as");
if (author != null) {
itemMeta.setAuthor(this.authorParser.parse(author).orFail());
}
Property generation = root.property("generation");
if (generation != null) {
itemMeta.setGeneration(this.generationParser.parse(generation).orFail());
}
Property title = root.property("title", "name");
if (title != null) {
itemMeta.setTitle(this.titleParser.parse(title).orFail());
}
List<String> pages = new ArrayList<>();
for (Node page : node.children("page")) {
pages.add(this.pageParser.parse(page).orFail());
}
itemMeta.setPages(pages);
}
return itemMeta;
}
Aggregations