Search in sources :

Example 1 with Ref

use of pl.themolka.arcade.config.Ref in project Arcade2 by ShootGame.

the class MatchGameParser method parseNode.

@Override
protected ParserResult<MatchGame.Config> parseNode(Node node, String name, String value) throws ParserException {
    boolean autoCycle = this.autoCycleParser.parse(node.property("auto-cycle", "autocycle")).orDefault(MatchGame.Config.DEFAULT_IS_AUTO_CYCLE);
    boolean autoStart = this.autoStartParser.parse(node.property("auto-start", "autostart")).orDefault(MatchGame.Config.DEFAULT_IS_AUTO_START);
    Time startCountdown = this.startCountdownParser.parse(node.property("start-countdown", "startcountdown")).orDefault(MatchGame.Config.DEFAULT_START_COUNTDOWN);
    Observers.Config observers = this.observersParser.parse(node.firstChild("observers")).orFail();
    return ParserResult.fine(node, name, value, new MatchGame.Config() {

        public boolean autoCycle() {
            return autoCycle;
        }

        public boolean autoStart() {
            return autoStart;
        }

        public Time startCountdown() {
            return startCountdown;
        }

        public Ref<Observers.Config> observers() {
            return Ref.ofProvided(observers);
        }
    });
}
Also used : Ref(pl.themolka.arcade.config.Ref) Time(pl.themolka.arcade.time.Time)

Example 2 with Ref

use of pl.themolka.arcade.config.Ref in project Arcade2 by ShootGame.

the class FilterSetParser method parseTree.

@Override
protected ParserResult<FilterSet.Config> parseTree(Node node, String name) throws ParserException {
    String id = this.parseRequiredId(node);
    Set<Filter.Config<?>> filters = new HashSet<>();
    for (Node filterNode : node.children()) {
        filters.add(this.filterParser.parse(filterNode).orFail());
    }
    if (ParserUtils.ensureNotEmpty(filters)) {
        throw this.fail(node, name, null, "No filters defined");
    }
    return ParserResult.fine(node, name, new FilterSet.Config() {

        public String id() {
            return id;
        }

        public Ref<Set<Filter.Config<?>>> filters() {
            return Ref.ofProvided(filters);
        }
    });
}
Also used : Ref(pl.themolka.arcade.config.Ref) Node(pl.themolka.arcade.dom.Node) HashSet(java.util.HashSet)

Example 3 with Ref

use of pl.themolka.arcade.config.Ref in project Arcade2 by ShootGame.

the class DamageRuleParser method parsePrimitive.

@Override
protected ParserResult<DamageRule.Config> parsePrimitive(Node node, String name, String value) throws ParserException {
    String id = this.parseOptionalId(node);
    Ref<Filter.Config<?>> entityFilter = this.entityFilterParser.parse(node.property("entity-filter", "filter")).orDefault(Ref.empty());
    Ref<Filter.Config<?>> playerFilter = this.playerFilterParser.parse(node.property("player-filter", "filter")).orDefault(Ref.empty());
    boolean notDenied = this.denyParser.parse(node).orDefault(true);
    double damage = notDenied ? this.damageParser.parse(node).orFail() : DamageRule.Config.DENY_DAMAGE;
    Percentage multiplier = this.multiplierParser.parse(node.property("multiplier", "multiply")).orDefault(Percentage.DONE);
    return ParserResult.fine(node, name, value, new DamageRule.Config() {

        public String id() {
            return id;
        }

        public double damage() {
            return damage;
        }

        public Ref<Filter.Config<?>> entityFilter() {
            return entityFilter;
        }

        public Percentage multiplier() {
            return multiplier;
        }

        public Ref<Filter.Config<?>> playerFilter() {
            return playerFilter;
        }
    });
}
Also used : Ref(pl.themolka.arcade.config.Ref) Percentage(pl.themolka.arcade.util.Percentage) Filter(pl.themolka.arcade.filter.Filter)

Example 4 with Ref

use of pl.themolka.arcade.config.Ref in project Arcade2 by ShootGame.

the class LivesGameParser method parseNode.

@Override
protected ParserResult<LivesGame.Config> parseNode(Node node, String name, String value) throws ParserException {
    ParserResult<Integer> livesResult = this.livesParser.parse(node);
    int lives = node.getName().equals("life") ? livesResult.orDefault(1) : livesResult.orFail();
    // ^ 1 is the default if the node name is singular form
    Ref<Team.Config> fallbackTeam = this.fallbackParser.parse(node.property("fallback", "return")).orDefault(Ref.empty());
    boolean announce = this.announceParser.parse(node.property("announce", "message")).orDefault(true);
    Sound sound = this.soundParser.parse(node.property("sound")).orDefault(LivesGame.DEFAULT_SOUND);
    return ParserResult.fine(node, name, value, new LivesGame.Config() {

        public int lives() {
            return lives;
        }

        public Ref<Team.Config> fallbackTeam() {
            return fallbackTeam;
        }

        public boolean announce() {
            return announce;
        }

        public Sound sound() {
            return sound;
        }
    });
}
Also used : Ref(pl.themolka.arcade.config.Ref) Sound(org.bukkit.Sound) Team(pl.themolka.arcade.team.Team)

Example 5 with Ref

use of pl.themolka.arcade.config.Ref in project Arcade2 by ShootGame.

the class PortalParser method parseNode.

@Override
protected ParserResult<Portal.Config> parseNode(Node node, String name, String value) throws ParserException {
    SpawnApply destination = this.parseDestination(node, name, value);
    Ref<Filter> filter = this.filterParser.parse(node.property("filter")).orDefault(Ref.empty());
    String id = this.parseOptionalId(node);
    Ref<Kit> kit = this.kitParser.parse(node.property("kit")).orDefault(Ref.empty());
    AbstractRegion.Config<?> region = this.regionParser.parseWithDefinition(node, name, value).orFail();
    return ParserResult.fine(node, name, value, new Portal.Config() {

        public SpawnApply destination() {
            return destination;
        }

        public Ref<Filter> filter() {
            return filter;
        }

        public String id() {
            return id;
        }

        public Ref<Kit> kit() {
            return kit;
        }

        public Ref<AbstractRegion.Config<?>> region() {
            return Ref.ofProvided(region);
        }
    });
}
Also used : Ref(pl.themolka.arcade.config.Ref) Filter(pl.themolka.arcade.filter.Filter) SpawnApply(pl.themolka.arcade.spawn.SpawnApply) Kit(pl.themolka.arcade.kit.Kit) AbstractRegion(pl.themolka.arcade.region.AbstractRegion)

Aggregations

Ref (pl.themolka.arcade.config.Ref)7 Filter (pl.themolka.arcade.filter.Filter)3 Node (pl.themolka.arcade.dom.Node)2 Time (pl.themolka.arcade.time.Time)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Sound (org.bukkit.Sound)1 Kit (pl.themolka.arcade.kit.Kit)1 AbstractRegion (pl.themolka.arcade.region.AbstractRegion)1 SpawnApply (pl.themolka.arcade.spawn.SpawnApply)1 Team (pl.themolka.arcade.team.Team)1 Percentage (pl.themolka.arcade.util.Percentage)1