cn.nukkit.command.Command Java Examples

The following examples show how to use cn.nukkit.command.Command. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SaveCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.start"));

    for (Player player : sender.getServer().getOnlinePlayers().values()) {
        player.save();
    }

    for (Level level : sender.getServer().getLevels().values()) {
        level.save(true);
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.success"));
    return true;
}
 
Example #2
Source File: PardonIpCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String value = args[0];

    if (Pattern.matches("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", value)) {
        sender.getServer().getIPBans().remove(value);

        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.unbanip.success", value));
    } else {

        sender.sendMessage(new TranslationContainer("commands.unbanip.invalid"));
    }

    return true;
}
 
Example #3
Source File: PardonCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    sender.getServer().getNameBans().remove(args[0]);

    Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.unban.success", args[0]));

    return true;
}
 
Example #4
Source File: SaveCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.start"));

    for (Player player : sender.getServer().getOnlinePlayers().values()) {
        player.save();
    }

    for (Level level : sender.getServer().getLevels().values()) {
        level.save(true);
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.success"));
    return true;
}
 
Example #5
Source File: DeopCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String playerName = args[0];
    IPlayer player = sender.getServer().getOfflinePlayer(playerName);
    player.setOp(false);

    if (player instanceof Player) {
        ((Player) player).sendMessage(new TranslationContainer(TextFormat.GRAY + "%commands.deop.message"));
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.deop.success", new String[]{player.getName()}));

    return true;
}
 
Example #6
Source File: PardonIpCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String value = args[0];

    if (Pattern.matches("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", value)) {
        sender.getServer().getIPBans().remove(value);
        sender.getServer().getNetwork().unblockAddress(value);

        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.unbanip.success", value));
    } else {

        sender.sendMessage(new TranslationContainer("commands.unbanip.invalid"));
    }

    return true;
}
 
Example #7
Source File: DeopCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String playerName = args[0];
    IPlayer player = sender.getServer().getOfflinePlayer(playerName);
    player.setOp(false);

    if (player instanceof Player) {
        ((Player) player).sendMessage(new TranslationContainer(TextFormat.GRAY + "%commands.deop.message"));
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.deop.success", new String[]{player.getName()}));

    return true;
}
 
Example #8
Source File: OpCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }

    String name = args[0];
    IPlayer player = sender.getServer().getOfflinePlayer(name);

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.op.success", player.getName()));
    if (player instanceof Player) {
        ((Player) player).sendMessage(TextFormat.GRAY + "You are now op!");
    }

    player.setOp(true);

    return true;
}
 
Example #9
Source File: OpCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }

    String name = args[0];
    IPlayer player = sender.getServer().getOfflinePlayer(name);

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.op.success", player.getName()));
    if (player instanceof Player) {
        ((Player) player).sendMessage(new TranslationContainer(TextFormat.GRAY + "%commands.op.message"));
    }

    player.setOp(true);

    return true;
}
 
Example #10
Source File: PardonCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    sender.getServer().getNameBans().remove(args[0]);

    Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.unban.success", args[0]));

    return true;
}
 
Example #11
Source File: DeopCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String playerName = args[0];
    IPlayer player = sender.getServer().getOfflinePlayer(playerName);
    player.setOp(false);

    if (player instanceof Player) {
        ((Player) player).sendMessage(TextFormat.GRAY + "You are no longer op!");
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.deop.success", new String[]{player.getName()}));

    return true;
}
 
Example #12
Source File: PardonCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    sender.getServer().getNameBans().remove(args[0]);

    Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.unban.success", args[0]));

    return true;
}
 
Example #13
Source File: SaveCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.start"));

    for (Player player : sender.getServer().getOnlinePlayers().values()) {
        player.save();
    }

    for (Level level : sender.getServer().getLevels().values()) {
        level.save(true);
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.success"));
    return true;
}
 
Example #14
Source File: OpCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.op.usage", this.usageMessage));
        return false;
    }

    String name = args[0];
    IPlayer player = sender.getServer().getOfflinePlayer(name);

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.op.success", player.getName()));
    if (player instanceof Player) {
        ((Player) player).sendMessage(new TranslationContainer(TextFormat.GRAY + "%commands.op.message"));
    }

    player.setOp(true);

    return true;
}
 
Example #15
Source File: PardonIpCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String value = args[0];

    if (Pattern.matches("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", value)) {
        sender.getServer().getIPBans().remove(value);
        sender.getServer().getNetwork().unblockAddress(value);

        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.unbanip.success", value));
    } else {

        sender.sendMessage(new TranslationContainer("commands.unbanip.invalid"));
    }

    return true;
}
 
Example #16
Source File: SaveOffCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    sender.getServer().setAutoSave(false);
    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.disabled"));
    return true;
}
 
Example #17
Source File: KickCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }

    String name = args[0];

    String reason = "";
    for (int i = 1; i < args.length; i++) {
        reason += args[i] + " ";
    }

    if (reason.length() > 0) {
        reason = reason.substring(0, reason.length() - 1);
    }

    Player player = sender.getServer().getPlayer(name);
    if (player != null) {
        player.kick(PlayerKickEvent.Reason.KICKED_BY_ADMIN, reason);
        if (reason.length() >= 1) {
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success.reason", new String[]{player.getName(), reason})
            );
        } else {
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success", player.getName()));
        }
    } else {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
    }

    return true;
}
 
Example #18
Source File: StopCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.stop.start"));

    sender.getServer().shutdown();

    return true;
}
 
Example #19
Source File: SynapsePlayer.java    From SynapseAPI with GNU General Public License v3.0 5 votes vote down vote up
public void sendCommandData() {
    AvailableCommandsPacket pk = new AvailableCommandsPacket();
    Map<String, CommandDataVersions> data = new HashMap<>();
    for (Command command : this.server.getCommandMap().getCommands().values()) {
        if (!command.testPermissionSilent(this)) {
            continue;
        }
        CommandDataVersions data0 = command.generateCustomCommandData(this);
        data.put(command.getName(), data0);
    }
    pk.commands = data;
    this.dataPacket(pk, true);
}
 
Example #20
Source File: EnchantCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length < 2) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    Player player = sender.getServer().getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
        return true;
    }
    int enchantId;
    int enchantLevel;
    try {
        enchantId = getIdByName(args[1]);
        enchantLevel = args.length == 3 ? Integer.parseInt(args[2]) : 1;
    } catch (NumberFormatException e) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    Enchantment enchantment = Enchantment.getEnchantment(enchantId);
    if (enchantment == null) {
        sender.sendMessage(new TranslationContainer("commands.enchant.notFound", String.valueOf(enchantId)));
        return true;
    }
    enchantment.setLevel(enchantLevel);
    Item item = player.getInventory().getItemInHand();
    if (item.getId() <= 0) {
        sender.sendMessage(new TranslationContainer("commands.enchant.noItem"));
        return true;
    }
    item.addEnchantment(enchantment);
    player.getInventory().setItemInHand(item);
    Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.enchant.success"));
    return true;
}
 
Example #21
Source File: BanCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String name = args[0];
    String reason = "";
    for (int i = 1; i < args.length; i++) {
        reason += args[i] + " ";
    }

    if (reason.length() > 0) {
        reason = reason.substring(0, reason.length() - 1);
    }

    sender.getServer().getNameBans().addBan(name, reason, null, sender.getName());

    Player player = sender.getServer().getPlayerExact(name);
    if (player != null) {
        player.kick(PlayerKickEvent.Reason.NAME_BANNED, !reason.isEmpty() ? "Banned by admin. Reason: " + reason : "Banned by admin");
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.ban.success", player != null ? player.getName() : name));

    return true;
}
 
Example #22
Source File: Player.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendCommandData() {
    AvailableCommandsPacket pk = new AvailableCommandsPacket();
    Map<String, CommandDataVersions> data = new HashMap<>();
    int count = 0;
    for (Command command : this.server.getCommandMap().getCommands().values()) {
        if (!command.testPermissionSilent(this)) {
            continue;
        }
        ++count;
        CommandDataVersions data0 = command.generateCustomCommandData(this);
        data.put(command.getName(), data0);
    }
    if (count > 0) {
        //TODO: structure checking
        pk.commands = data;
        int identifier = this.dataPacket(pk, true); // We *need* ACK so we can be sure that the client received the packet or not
        Thread t = new Thread() {
            public void run() {
                // We are going to wait 3 seconds, if after 3 seconds we didn't receive a reply from the client, resend the packet.
                try {
                    Thread.sleep(3000);
                    Boolean status = needACK.get(identifier);
                    if ((status == null || !status) && isOnline()) {
                        sendCommandData();
                        return;
                    }
                } catch (InterruptedException e) {
                }
            }
        };
        t.start();
    }
}
 
Example #23
Source File: DifficultyCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }

    int difficulty = Server.getDifficultyFromString(args[0]);

    if (sender.getServer().isHardcore()) {
        difficulty = 3;
    }

    if (difficulty != -1) {
        sender.getServer().setPropertyInt("difficulty", difficulty);

        SetDifficultyPacket pk = new SetDifficultyPacket();
        pk.difficulty = sender.getServer().getDifficulty();
        Server.broadcastPacket(new ArrayList<>(sender.getServer().getOnlinePlayers().values()), pk);

        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.difficulty.success", String.valueOf(difficulty)));
    } else {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    return true;
}
 
Example #24
Source File: SaveOnCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    sender.getServer().setAutoSave(true);
    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.enabled"));
    return true;
}
 
Example #25
Source File: NukkitCommandExecutor.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    Sender wrapped = this.plugin.getSenderFactory().wrap(sender);
    List<String> arguments = ArgumentTokenizer.EXECUTE.tokenizeInput(args);
    executeCommand(wrapped, label, arguments);
    return true;
}
 
Example #26
Source File: NukkitPlugin.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    CommandNode found = commands.get(command.getName());
    if (found == null) return false;

    found.onCommand(new NukkitCMDSender(sender), label, args);
    return true;
}
 
Example #27
Source File: SaveOffCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    sender.getServer().setAutoSave(false);
    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.disabled"));
    return true;
}
 
Example #28
Source File: KickCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }

    String name = args[0];

    String reason = "";
    for (int i = 1; i < args.length; i++) {
        reason += args[i] + " ";
    }

    if (reason.length() > 0) {
        reason = reason.substring(0, reason.length() - 1);
    }

    Player player = sender.getServer().getPlayer(name);
    if (player != null) {
        player.kick(PlayerKickEvent.Reason.KICKED_BY_ADMIN, reason);
        if (reason.length() >= 1) {
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success.reason", player.getName(), reason)
            );
        } else {
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success", player.getName()));
        }
    } else {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
    }

    return true;
}
 
Example #29
Source File: StopCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.stop.start"));

    sender.getServer().shutdown();

    return true;
}
 
Example #30
Source File: EnchantCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length < 2) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    Player player = sender.getServer().getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
        return true;
    }
    int enchantId;
    int enchantLevel;
    try {
        enchantId = getIdByName(args[1]);
        enchantLevel = args.length == 3 ? Integer.parseInt(args[2]) : 1;
    } catch (NumberFormatException e) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    Enchantment enchantment = Enchantment.getEnchantment(enchantId);
    if (enchantment == null) {
        sender.sendMessage(new TranslationContainer("commands.enchant.notFound", String.valueOf(enchantId)));
        return true;
    }
    enchantment.setLevel(enchantLevel);
    Item item = player.getInventory().getItemInHand();
    if (item.getId() <= 0) {
        sender.sendMessage(new TranslationContainer("commands.enchant.noItem"));
        return true;
    }
    item.addEnchantment(enchantment);
    player.getInventory().setItemInHand(item);
    Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.enchant.success"));
    return true;
}