Search in sources :

Example 1 with ExperienceHolderData

use of org.spongepowered.api.data.manipulator.mutable.entity.ExperienceHolderData in project LanternServer by LanternPowered.

the class SelectorResolver method addLevelFilters.

private void addLevelFilters(List<Predicate<Entity>> filters) {
    Selector sel = this.selector;
    Optional<Integer> levelMin = sel.get(ArgumentTypes.LEVEL.minimum());
    Optional<Integer> levelMax = sel.get(ArgumentTypes.LEVEL.maximum());
    if (levelMin.isPresent()) {
        final int actualMin = levelMin.get();
        filters.add(input -> {
            Optional<ExperienceHolderData> xp = input.get(ExperienceHolderData.class);
            return xp.isPresent() && xp.get().level().get() >= actualMin;
        });
    }
    if (levelMax.isPresent()) {
        final int actualMax = levelMax.get();
        filters.add(input -> {
            Optional<ExperienceHolderData> xp = input.get(ExperienceHolderData.class);
            return xp.isPresent() && xp.get().level().get() <= actualMax;
        });
    }
}
Also used : ExperienceHolderData(org.spongepowered.api.data.manipulator.mutable.entity.ExperienceHolderData) Selector(org.spongepowered.api.text.selector.Selector)

Example 2 with ExperienceHolderData

use of org.spongepowered.api.data.manipulator.mutable.entity.ExperienceHolderData in project Nucleus by NucleusPowered.

the class ExperienceCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Player pl = args.<Player>getOne(playerKey).get();
    ExperienceHolderData ehd = pl.get(ExperienceHolderData.class).get();
    int exp = ehd.totalExperience().get();
    int lv = ehd.level().get();
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.exp.info", pl.getName(), String.valueOf(exp), String.valueOf(lv)));
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ExperienceHolderData(org.spongepowered.api.data.manipulator.mutable.entity.ExperienceHolderData)

Example 3 with ExperienceHolderData

use of org.spongepowered.api.data.manipulator.mutable.entity.ExperienceHolderData in project SpongeCommon by SpongePowered.

the class SelectorResolver method addLevelFilters.

private void addLevelFilters(List<Predicate<Entity>> filters) {
    Selector sel = this.selector;
    Optional<Integer> levelMin = sel.get(ArgumentTypes.LEVEL.minimum());
    Optional<Integer> levelMax = sel.get(ArgumentTypes.LEVEL.maximum());
    if (levelMin.isPresent()) {
        final int actualMin = levelMin.get();
        filters.add(input -> {
            Optional<ExperienceHolderData> xp = input.get(ExperienceHolderData.class);
            return xp.isPresent() && xp.get().level().get() >= actualMin;
        });
    }
    if (levelMax.isPresent()) {
        final int actualMax = levelMax.get();
        filters.add(input -> {
            Optional<ExperienceHolderData> xp = input.get(ExperienceHolderData.class);
            return xp.isPresent() && xp.get().level().get() <= actualMax;
        });
    }
}
Also used : ExperienceHolderData(org.spongepowered.api.data.manipulator.mutable.entity.ExperienceHolderData) Selector(org.spongepowered.api.text.selector.Selector)

Example 4 with ExperienceHolderData

use of org.spongepowered.api.data.manipulator.mutable.entity.ExperienceHolderData in project Nucleus by NucleusPowered.

the class TakeExperience method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Player pl = this.getUserFromArgs(Player.class, src, ExperienceCommand.playerKey, args);
    if (!ExperienceCommand.checkGameMode(pl, src)) {
        return CommandResult.empty();
    }
    // int currentExp = pl.get(Keys.TOTAL_EXPERIENCE).get();
    int toOffer = 0;
    if (args.hasAny(ExperienceCommand.levelKey)) {
        ExperienceHolderData data = pl.get(ExperienceHolderData.class).get();
        int currentLevel = data.level().get();
        int levelReduction = args.<Integer>getOne(ExperienceCommand.levelKey).get();
        // If this will take us down to below zero, we just let this continue to the return line. Else...
        if (currentLevel >= levelReduction) {
            int extra = data.experienceSinceLevel().get();
            data.set(data.level().set(currentLevel - levelReduction));
            data.set(data.experienceSinceLevel().set(Math.min(extra, data.getExperienceBetweenLevels().getMaxValue())));
            return ExperienceCommand.tellUserAboutExperience(src, pl, pl.offer(data).isSuccessful());
        }
    } else {
        toOffer = pl.get(Keys.TOTAL_EXPERIENCE).get() - args.<Integer>getOne(ExperienceCommand.experienceKey).get();
    }
    return ExperienceCommand.tellUserAboutExperience(src, pl, pl.offer(Keys.TOTAL_EXPERIENCE, Math.max(0, toOffer)).isSuccessful());
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ExperienceHolderData(org.spongepowered.api.data.manipulator.mutable.entity.ExperienceHolderData)

Aggregations

ExperienceHolderData (org.spongepowered.api.data.manipulator.mutable.entity.ExperienceHolderData)4 Player (org.spongepowered.api.entity.living.player.Player)2 Selector (org.spongepowered.api.text.selector.Selector)2