cn.nukkit.utils.TextFormat Java Examples

The following examples show how to use cn.nukkit.utils.TextFormat. 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: RealNameCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (args.length != 1) {
        this.sendUsage(sender);
        return false;
    }
    Player player = api.getServer().getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.player.notfound", args[0]));
        return false;
    }
    sender.sendMessage(Language.translate("commands.realname.success", player.getDisplayName(), player.getName()));
    return true;
}
 
Example #2
Source File: SetWarpCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 1) {
        this.sendUsage(sender);
        return false;
    }
    if (args[0].trim().equals("")) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.setwarp.empty"));
        return false;
    }
    sender.sendMessage(api.setWarp(args[0].toLowerCase(), (Player) sender) ? Language.translate("commands.setwarp.replaced", args[0]) : Language.translate("commands.setwarp.success", args[0]));
    return true;
}
 
Example #3
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
/**
 * コマンドを実行します。
 * @param sender 対象のCommandSender
 * @param commandLine 送るパケット
 * @return boolean trueが完了/falseが失敗
 */
public boolean dispatchCommand(CommandSender sender, String commandLine) throws ServerException {
    // First we need to check if this command is on the main thread or not, if not, warn the user
    if (!this.isPrimaryThread()) {
        getLogger().warning("Command Dispatched Async: " + commandLine);
        getLogger().warning("Please notify author of plugin causing this execution to fix this bug!", new Throwable());
        // TODO: We should sync the command to the main thread too!
    }
    if (sender == null) {
        throw new ServerException("CommandSender is not valid");
    }

    if (this.commandMap.dispatch(sender, commandLine)) {
        return true;
    }

    sender.sendMessage(TextFormat.RED + this.getLanguage().translateString("commands.generic.notFound"));

    return false;
}
 
Example #4
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 #5
Source File: MuteCommand.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(sender instanceof ConsoleCommandSender){
    	sender.sendMessage(TextFormat.RED + "コンソールはミュートできません。");
    	return true;
    }

    Player p = (Player)sender;

    if(p.mute){
    	p.setMute(false);
    	p.sendImportantMessage(TextFormat.GREEN + "ミュートを解除しました。");
    	return true;
    }else{
    	p.setMute(true);
    	p.sendImportantMessage(TextFormat.RED + "ミュートを有効にしました。");
    	return true;
    }
}
 
Example #6
Source File: Command.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) {
    Set<Permissible> users = source.getServer().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);

    TranslationContainer result = new TranslationContainer("chat.type.admin", new String[]{source.getName(), message});

    TranslationContainer colored = new TranslationContainer(TextFormat.GRAY + "" + TextFormat.ITALIC + "%chat.type.admin", new String[]{source.getName(), message});

    if (sendToSource && !(source instanceof ConsoleCommandSender)) {
        source.sendMessage(message);
    }

    for (Permissible user : users) {
        if (user instanceof CommandSender) {
            if (user instanceof ConsoleCommandSender) {
                ((ConsoleCommandSender) user).sendMessage(result);
            } else if (!user.equals(source)) {
                ((CommandSender) user).sendMessage(colored);
            }
        }
    }
}
 
Example #7
Source File: TimingsExport.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private String getResponse(HttpURLConnection con) throws IOException {
    try (InputStream is = con.getInputStream()) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        byte[] b = new byte[1024];
        int bytesRead;
        while ((bytesRead = is.read(b)) != -1) {
            bos.write(b, 0, bytesRead);
        }
        return bos.toString();

    } catch (IOException exception) {
        this.sender.sendMessage(TextFormat.RED + "" + new TranslationContainer("nukkit.command.timings.reportError"));
        Server.getInstance().getLogger().warning(con.getResponseMessage(), exception);
        return null;
    }
}
 
Example #8
Source File: RCON.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void check() {
    if (this.serverThread == null) {
        return;
    } else if (!this.serverThread.isAlive()) {
        return;
    }

    RCONCommand command;
    while ((command = serverThread.receive()) != null) {
        RemoteConsoleCommandSender sender = new RemoteConsoleCommandSender();
        RemoteServerCommandEvent event = new RemoteServerCommandEvent(sender, command.getCommand());
        this.server.getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
            this.server.dispatchCommand(sender, command.getCommand());
        }

        this.serverThread.respond(command.getSender(), command.getId(), TextFormat.clean(sender.getMessages()));
    }
}
 
Example #9
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 #10
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 #11
Source File: WorldCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 1) {
        this.sendUsage(sender);
        return false;
    }
    if (!api.getServer().isLevelGenerated(args[0])) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.world.notfound", args[0]));
        return false;
    } else if (!api.getServer().isLevelLoaded(args[0])) {
        sender.sendMessage(Language.translate("commands.world.loading"));
        if (!api.getServer().loadLevel(args[0])) {
            sender.sendMessage(TextFormat.RED + Language.translate("commands.world.unloadable"));
            return false;
        }
    }
    ((Player) sender).teleport(api.getServer().getLevelByName(args[0]).getSpawnLocation());
    sender.sendMessage(Language.translate("commands.generic.teleporting"));
    return true;
}
 
Example #12
Source File: MoreCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 0) {
        this.sendUsage(sender);
        return false;
    }
    Player player = (Player) sender;
    if (player.isCreative() || player.isSpectator()) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.more.notavalible"));
        return false;
    }
    Item item = player.getInventory().getItemInHand();
    if (item.getId() == Item.AIR) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.more.air"));
        return false;
    }
    item.setCount(item.getMaxStackSize());
    player.getInventory().setItemInHand(item);
    sender.sendMessage(Language.translate("commands.more.success"));
    return true;
}
 
Example #13
Source File: NukkitCMDSender.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void sendMessage(String message) {
    if (!(cs instanceof Player)) {
        cs.sendMessage(message);
        return;
    }
    final int length = message.length();
    if (length > 60) {
        int i = 59;
        while (i < length && message.charAt(i) != ' ') {
            i++;
        }
        String shortened = message.substring(0, i);
        String lastCols = TextFormat.getLastColors(message);
        cs.sendMessage(shortened);
        String leftover = lastCols + message.substring(i);
        sendMessage(leftover);
    } else {
        if (TextFormat.clean(message).isEmpty()) {
            return;
        }
        cs.sendMessage(message);
    }
}
 
Example #14
Source File: RCON.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void check() {
    if (this.serverThread == null) {
        return;
    } else if (!this.serverThread.isAlive()) {
        return;
    }

    RCONCommand command;
    while ((command = serverThread.receive()) != null) {
        RemoteConsoleCommandSender sender = new RemoteConsoleCommandSender();
        RemoteServerCommandEvent event = new RemoteServerCommandEvent(sender, command.getCommand());
        this.server.getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
            this.server.dispatchCommand(sender, command.getCommand());
        }

        this.serverThread.respond(command.getSender(), command.getId(), TextFormat.clean(sender.getMessages()));
    }
}
 
Example #15
Source File: BreakCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 0) {
        this.sendUsage(sender);
        return false;
    }
    Player player = (Player) sender;
    Block block = player.getTargetBlock(120, new Integer[]{Block.AIR});
    if (block == null) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.break.unreachable"));
        return false;
    }
    if (block.getId() == Block.BEDROCK && !sender.hasPermission("essentialsnk.break.bedrock")) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.break.bedrock"));
        return false;
    }
    player.getLevel().setBlock(block, new BlockAir(), true, true);
    return true;
}
 
Example #16
Source File: DelWarpCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (args.length != 1) {
        this.sendUsage(sender);
        return false;
    }
    if (!api.isWarpExists(args[0].toLowerCase())) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.warp.notexists"));
        return false;
    }
    api.removeWarp(args[0].toLowerCase());
    sender.sendMessage(Language.translate("commands.delwarp.success"));
    return true;
}
 
Example #17
Source File: TPACommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 1) {
        this.sendUsage(sender);
        return false;
    }
    Player player = api.getServer().getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.player.notfound", args[0]));
        return false;
    }
    if (sender == player) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.tpa.self"));
        return false;
    }
    api.requestTP((Player) sender, player, true);
    player.sendMessage(Language.translate("commands.tpa.invite", ((Player) sender).getName()));
    sender.sendMessage(Language.translate("commands.tpa.success", player.getDisplayName()));
    return true;
}
 
Example #18
Source File: TPHereCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 1) {
        this.sendUsage(sender);
        return false;
    }
    Player player = api.getServer().getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.player.notfound", args[0]));
        return false;
    }
    player.teleport((Player) sender);
    player.sendMessage(Language.translate("commands.tphere.other", ((Player) sender).getDisplayName()));
    sender.sendMessage(Language.translate("commands.tphere.success", player.getDisplayName()));
    return true;
}
 
Example #19
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 #20
Source File: SetHomeCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 1) {
        this.sendUsage(sender);
        return false;
    }
    if (args[0].toLowerCase().equals("bed")) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.sethome.bed"));
        return false;
    } else if (args[0].trim().equals("")) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.sethome.empty"));
        return false;
    }
    sender.sendMessage(api.setHome((Player) sender, args[0].toLowerCase(), (Player) sender) ? Language.translate("commands.sethome.updated", args[0]) : Language.translate("commands.sethome.success", args[0]));
    return true;
}
 
Example #21
Source File: DelHomeCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 1) {
        this.sendUsage(sender);
        return false;
    }
    if (!api.isHomeExists((Player) sender, args[0].toLowerCase())) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.home.notexists", args[0]));
        return false;
    }
    api.removeHome((Player) sender, args[0].toLowerCase());
    sender.sendMessage(Language.translate("commands.delhome.success", args[0]));
    return true;
}
 
Example #22
Source File: BackCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 0) {
        this.sendUsage(sender);
        return false;
    }
    Player player = (Player) sender;
    Location pos = api.getLastLocation(player);
    if (pos == null) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.back.notavalible"));
        return false;
    }
    player.teleport(pos);
    sender.sendMessage(Language.translate("commands.generic.teleporting"));
    return true;
}
 
Example #23
Source File: MyMoneyCommand.java    From EconomyAPI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.mymoney")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(!(sender instanceof Player)){
		sender.sendMessage(TextFormat.RED+"Please use this command in-game.");
		return true;
	}
	Player player = (Player) sender;
	sender.sendMessage(this.plugin.getMessage("mymoney-mymoney", new String[]{Double.toString(this.plugin.myMoney(player))}, player));
	return true;
}
 
Example #24
Source File: SetLangCommand.java    From EconomyAPI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.setlang")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(args.length < 1){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	String lang = args[0];
	
	// TODO
	return true;
}
 
Example #25
Source File: TimingsExport.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private String getResponse(HttpURLConnection con) throws IOException {
    InputStream is = null;
    try {
        is = con.getInputStream();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        byte[] b = new byte[1024];
        int bytesRead;
        while ((bytesRead = is.read(b)) != -1) {
            bos.write(b, 0, bytesRead);
        }
        return bos.toString();

    } catch (IOException exception) {
        this.sender.sendMessage(TextFormat.RED + "" + new TranslationContainer("nukkit.command.timings.reportError"));
        Server.getInstance().getLogger().warning(con.getResponseMessage(), exception);
        return null;
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
 
Example #26
Source File: SayCommand.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 senderString;
    if (sender instanceof Player) {
        senderString = ((Player) sender).getDisplayName();
    } else if (sender instanceof ConsoleCommandSender) {
        senderString = "Server";
    } else {
        senderString = sender.getName();
    }

    String msg = "";
    for (String arg : args) {
        msg += arg + " ";
    }
    if (msg.length() > 0) {
        msg = msg.substring(0, msg.length() - 1);
    }


    sender.getServer().broadcastMessage(new TranslationContainer(
            TextFormat.LIGHT_PURPLE + "%chat.type.announcement",
            new String[]{senderString, TextFormat.LIGHT_PURPLE + msg}
    ));
    return true;
}
 
Example #27
Source File: MeCommand.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;
    if (sender instanceof Player) {
        name = ((Player) sender).getDisplayName();
    } else {
        name = sender.getName();
    }

    String msg = "";
    for (String arg : args) {
        msg += arg + " ";
    }

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

    sender.getServer().broadcastMessage(new TranslationContainer("chat.type.emote", name, TextFormat.WHITE + msg));

    return true;
}
 
Example #28
Source File: SimpleCommandMap.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean dispatch(CommandSender sender, String cmdLine) {
    ArrayList<String> parsed = parseArguments(cmdLine);
    if (parsed.size() == 0) {
        return false;
    }

    String sentCommandLabel = parsed.remove(0).toLowerCase();
    String[] args = parsed.toArray(new String[0]);
    Command target = this.getCommand(sentCommandLabel);

    if (target == null) {
        return false;
    }

    target.timing.startTiming();
    try {
        target.execute(sender, sentCommandLabel, args);
    } catch (Exception e) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.exception"));
        this.server.getLogger().critical(this.server.getLanguage().translateString("nukkit.command.exception", cmdLine, target.toString(), Utils.getExceptionMessage(e)));
        MainLogger logger = sender.getServer().getLogger();
        if (logger != null) {
            logger.logException(e);
        }
    }
    target.timing.stopTiming();

    return true;
}
 
Example #29
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 #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;
}