Search in sources :

Example 36 with TranslationContainer

use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.

the class KickCommand method execute.

@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;
}
Also used : Player(cn.nukkit.Player) TranslationContainer(cn.nukkit.lang.TranslationContainer)

Example 37 with TranslationContainer

use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.

the class KillCommand method execute.

@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 false;
    }
    if (args.length == 1) {
        if (!sender.hasPermission("nukkit.command.kill.other")) {
            sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
            return true;
        }
        Player player = sender.getServer().getPlayer(args[0]);
        if (player != null) {
            EntityDamageEvent ev = new EntityDamageEvent(player, DamageCause.SUICIDE, 1000);
            sender.getServer().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                return true;
            }
            player.setLastDamageCause(ev);
            player.setHealth(0);
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kill.successful", player.getName()));
        } else {
            sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
        }
        return true;
    }
    if (sender instanceof Player) {
        if (!sender.hasPermission("nukkit.command.kill.self")) {
            sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
            return true;
        }
        EntityDamageEvent ev = new EntityDamageEvent((Player) sender, DamageCause.SUICIDE, 1000);
        sender.getServer().getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            return true;
        }
        ((Player) sender).setLastDamageCause(ev);
        ((Player) sender).setHealth(0);
        sender.sendMessage(new TranslationContainer("commands.kill.successful", sender.getName()));
    } else {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }
    return true;
}
Also used : Player(cn.nukkit.Player) TranslationContainer(cn.nukkit.lang.TranslationContainer) EntityDamageEvent(cn.nukkit.event.entity.EntityDamageEvent)

Example 38 with TranslationContainer

use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.

the class ListCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    String online = "";
    int onlineCount = 0;
    for (Player player : sender.getServer().getOnlinePlayers().values()) {
        if (player.isOnline() && (!(sender instanceof Player) || ((Player) sender).canSee(player))) {
            online += player.getDisplayName() + ", ";
            ++onlineCount;
        }
    }
    if (online.length() > 0) {
        online = online.substring(0, online.length() - 2);
    }
    sender.sendMessage(new TranslationContainer("commands.players.list", new String[] { String.valueOf(onlineCount), String.valueOf(sender.getServer().getMaxPlayers()) }));
    sender.sendMessage(online);
    return true;
}
Also used : Player(cn.nukkit.Player) TranslationContainer(cn.nukkit.lang.TranslationContainer)

Example 39 with TranslationContainer

use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.

the class MeCommand method execute.

@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", new String[] { name, TextFormat.WHITE + msg }));
    return true;
}
Also used : Player(cn.nukkit.Player) TranslationContainer(cn.nukkit.lang.TranslationContainer)

Example 40 with TranslationContainer

use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.

the class PardonCommand method execute.

@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;
}
Also used : TranslationContainer(cn.nukkit.lang.TranslationContainer)

Aggregations

TranslationContainer (cn.nukkit.lang.TranslationContainer)49 Player (cn.nukkit.Player)24 Level (cn.nukkit.level.Level)6 BlockEntity (cn.nukkit.blockentity.BlockEntity)3 CommandSender (cn.nukkit.command.CommandSender)3 ConsoleCommandSender (cn.nukkit.command.ConsoleCommandSender)3 EntityDamageEvent (cn.nukkit.event.entity.EntityDamageEvent)3 Plugin (cn.nukkit.plugin.Plugin)3 IPlayer (cn.nukkit.IPlayer)2 Command (cn.nukkit.command.Command)2 RemoteConsoleCommandSender (cn.nukkit.command.RemoteConsoleCommandSender)2 EntityDamageByBlockEvent (cn.nukkit.event.entity.EntityDamageByBlockEvent)2 EntityDamageByEntityEvent (cn.nukkit.event.entity.EntityDamageByEntityEvent)2 Item (cn.nukkit.item.Item)2 Enchantment (cn.nukkit.item.enchantment.Enchantment)2 Effect (cn.nukkit.potion.Effect)2 DecimalFormat (java.text.DecimalFormat)2 Type (cn.nukkit.AdventureSettings.Type)1 cn.nukkit.block (cn.nukkit.block)1 BlockEntityItemFrame (cn.nukkit.blockentity.BlockEntityItemFrame)1