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

cn.nukkit.command.defaults.ClearSpawnPointCommand Maven / Gradle / Ivy

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

import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.data.CommandParamType;
import cn.nukkit.command.data.CommandParameter;
import cn.nukkit.command.tree.ParamList;
import cn.nukkit.command.tree.node.PlayersNode;
import cn.nukkit.command.utils.CommandLogger;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@PowerNukkitXOnly
@Since("1.6.0.0-PNX")
public class ClearSpawnPointCommand extends VanillaCommand {

    public ClearSpawnPointCommand(String name) {
        super(name, "commands.clearspawnpoint.description");
        this.setPermission("nukkit.command.clearspawnpoint");
        this.getCommandParameters().clear();
        this.addCommandParameters("default", new CommandParameter[]{
                CommandParameter.newType("player", true, CommandParamType.TARGET, new PlayersNode()),
        });
        this.enableParamTree();
    }

    @Override
    public int execute(CommandSender sender, String commandLabel, Map.Entry result, CommandLogger log) {
            var list = result.getValue();
            List players = sender.isPlayer() ? List.of(sender.asPlayer()) : null;
            if (list.hasResult(0)) players = list.getResult(0);
            if (players == null || players.isEmpty()) {
                log.addNoTargetMatch().output();
                return 0;
            }
            for (Player player : players) {
                player.setSpawn(null);
                player.setSpawnBlock(null);
            }
            String players_str = players.stream().map(Player::getName).collect(Collectors.joining(" "));
            if (players.size() > 1) {
                log.addSuccess("commands.clearspawnpoint.success.multiple", players_str);
            } else {
                log.addSuccess("commands.clearspawnpoint.success.single", players_str);
            }
            log.successCount(players.size()).output();
            return players.size();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy