Search in sources :

Example 46 with TranslationContainer

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

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

Example 47 with TranslationContainer

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

the class GamemodeCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }
    int gameMode = Server.getGamemodeFromString(args[0]);
    if (gameMode == -1) {
        sender.sendMessage("Unknown game mode");
        return true;
    }
    CommandSender target = sender;
    if (args.length > 1) {
        if (sender.hasPermission("nukkit.command.gamemode.other")) {
            target = sender.getServer().getPlayer(args[1]);
            if (target == null) {
                sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
                return true;
            }
        } else {
            sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
            return true;
        }
    } else if (!(sender instanceof Player)) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    if ((gameMode == 0 && !sender.hasPermission("nukkit.command.gamemode.survival")) || (gameMode == 1 && !sender.hasPermission("nukkit.command.gamemode.creative")) || (gameMode == 2 && !sender.hasPermission("nukkit.command.gamemode.adventure")) || (gameMode == 3 && !sender.hasPermission("nukkit.command.gamemode.spectator"))) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
        return true;
    }
    if (!((Player) target).setGamemode(gameMode)) {
        sender.sendMessage("Game mode update for " + target.getName() + " failed");
    } else {
        if (target.equals(sender)) {
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.gamemode.success.self", Server.getGamemodeString(gameMode)));
        } else {
            target.sendMessage(new TranslationContainer("gameMode.changed"));
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.gamemode.success.other", new String[] { target.getName(), Server.getGamemodeString(gameMode) }));
        }
    }
    return true;
}
Also used : Player(cn.nukkit.Player) TranslationContainer(cn.nukkit.lang.TranslationContainer) CommandSender(cn.nukkit.command.CommandSender)

Example 48 with TranslationContainer

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

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

Example 49 with TranslationContainer

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

the class BanIpCommand 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 value = 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);
    }
    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)) {
        this.processIPBan(value, sender, reason);
        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.banip.success", value));
    } else {
        Player player = sender.getServer().getPlayer(value);
        if (player != null) {
            this.processIPBan(player.getAddress(), sender, reason);
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.banip.success.players", new String[] { player.getAddress(), player.getName() }));
        } else {
            String name = value.toLowerCase();
            String path = sender.getServer().getDataPath() + "players/";
            File file = new File(path + name + ".dat");
            CompoundTag nbt = null;
            if (file.exists()) {
                try {
                    nbt = NBTIO.readCompressed(new FileInputStream(file));
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (nbt != null && nbt.contains("lastIP") && 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 = nbt.getString("lastIP")))) {
                this.processIPBan(value, sender, reason);
                Command.broadcastCommandMessage(sender, new TranslationContainer("commands.banip.success", value));
            } else {
                sender.sendMessage(new TranslationContainer("commands.banip.invalid"));
                return false;
            }
        }
    }
    return true;
}
Also used : Player(cn.nukkit.Player) TranslationContainer(cn.nukkit.lang.TranslationContainer) IOException(java.io.IOException) File(java.io.File) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) FileInputStream(java.io.FileInputStream)

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