All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.command.selector.args.impl.M Maven / Gradle / Ivy

There is a newer version: 1.20.40-r1
Show newest version
package cn.nukkit.command.selector.args.impl;

import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.exceptions.SelectorSyntaxException;
import cn.nukkit.command.selector.ParseUtils;
import cn.nukkit.command.selector.SelectorType;
import cn.nukkit.command.selector.args.CachedSimpleSelectorArgument;
import cn.nukkit.entity.Entity;
import cn.nukkit.level.Location;

import java.util.function.Predicate;

@PowerNukkitXOnly
@Since("1.19.60-r1")
public class M extends CachedSimpleSelectorArgument {
    @Override
    protected Predicate cache(SelectorType selectorType, CommandSender sender, Location basePos, String... arguments) throws SelectorSyntaxException {
        ParseUtils.singleArgument(arguments, getKeyName());
        var gmStr = arguments[0];
        boolean reversed = ParseUtils.checkReversed(gmStr);
        if (reversed) gmStr = gmStr.substring(1);
        final var gm = ParseUtils.parseGameMode(gmStr);
        return entity -> entity instanceof Player player && (reversed != (player.getGamemode() == gm));
    }

    @Override
    public String getKeyName() {
        return "m";
    }

    @Override
    public int getPriority() {
        return 3;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy