use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class ArcadePlugin method loadEnvironment.
private void loadEnvironment() throws DOMException {
Node node = this.getSettings().getData().child("environment");
Parser<Environment> parser;
try {
parser = this.parsers.forType(Environment.class);
} catch (ParserNotSupportedException ex) {
throw new RuntimeException("No " + Environment.class.getSimpleName() + " parser installed");
}
this.environment = parser.parse(node).orFail();
this.environment.initialize(this);
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class FireworkMetaParser method parse.
@Override
public FireworkMeta parse(Node root, ItemStack itemStack, FireworkMeta itemMeta) throws ParserException {
Node node = root.firstChild("firework", "firework");
if (node != null) {
Property power = node.property("power");
if (power != null) {
int powerInt = this.powerParser.parse(power).orFail();
if (powerInt > 127) {
throw this.fail(power, "Power cannot be greater than 127");
} else if (powerInt <= 0) {
throw this.fail(power, "Power cannot be smaller than 0");
}
itemMeta.setPower(this.powerParser.parse(power).orFail());
}
for (Node effect : node.children("effect", "firework-effect", "fireworkeffect")) {
itemMeta.addEffect(this.fireworkEffectParser.parse(effect).orFail());
}
}
return itemMeta;
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class PotionMetaParser method parse.
@Override
public PotionMeta parse(Node root, ItemStack itemStack, PotionMeta itemMeta) throws ParserException {
Node node = root.firstChild("potion");
if (node != null) {
Property type = node.property("type", "of");
if (type != null) {
PotionType value = this.typeParser.parse(type).orFail();
boolean extended = this.extendedParser.parse(node.property("extended")).orDefault(false);
boolean upgraded = this.upgradedParser.parse(node.property("upgraded")).orDefault(false);
if (extended && !value.isUpgradeable()) {
throw this.fail(type, "Potion is not extendable");
} else if (upgraded && !value.isUpgradeable()) {
throw this.fail(type, "Potion is not upgradeable");
} else if (extended && upgraded) {
throw this.fail(type, "Potion cannot be both extended and upgraded");
}
itemMeta.setBasePotionData(new PotionData(value, extended, upgraded));
}
Property color = node.property("color");
if (color != null) {
itemMeta.setColor(this.colorParser.parse(color).orFail());
}
for (Node effect : node.children("effect", "potion-effect", "potioneffect")) {
PotionEffect value = this.potionEffectParser.parse(effect).orFail();
if (!itemMeta.hasCustomEffect(value.getType())) {
itemMeta.addCustomEffect(value, false);
}
}
}
return itemMeta;
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class MapLoaderModule method onEnable.
@Override
public void onEnable(Node options) throws DOMException {
for (Node directory : options.children("directory")) {
String path = directory.propertyValue("path");
List<Node> exclude = directory.children("exclude");
List<Node> include = directory.children("include");
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (!exclude.isEmpty()) {
for (Node node : exclude) {
if (name.equals(node.getValue())) {
return false;
}
}
return true;
} else if (!include.isEmpty()) {
for (Node node : include) {
if (name.equals(node.getValue())) {
return true;
}
}
return false;
}
return true;
}
};
File file = new File(path);
if (file.exists()) {
for (File worldFile : file.listFiles(filter)) {
if (!this.worldFiles.contains(worldFile)) {
this.worldFiles.add(worldFile);
}
}
}
}
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class ArchiveModule method onEnable.
@Override
public void onEnable(Node options) {
if (options == null) {
return;
}
Node directoryNode = options.firstChild("directory");
if (directoryNode == null) {
directoryNode = Node.ofPrimitive(null, "directory", DEFAULT_DIRECTORY_NAME);
}
File file = new File(directoryNode.getValue());
if (!file.isDirectory()) {
FileUtils.deleteQuietly(file);
} else if (!file.exists()) {
file.mkdir();
}
this.directory = file;
}
Aggregations