Search in sources :

Example 16 with TranslationContainer

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

the class GiveCommand 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 true;
    }
    Player player = sender.getServer().getPlayer(args[0]);
    Item item;
    try {
        item = Item.fromString(args[1]);
    } catch (Exception e) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    try {
        item.setCount(Integer.parseInt(args[2]));
    } catch (Exception e) {
        item.setCount(item.getMaxStackSize());
    }
    if (player != null) {
        if (item.getId() == 0) {
            sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.give.item.notFound", args[1]));
            return true;
        }
        player.getInventory().addItem(item.clone());
    } else {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
        return true;
    }
    Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.give.success", new String[] { item.getName() + " (" + item.getId() + ":" + item.getDamage() + ")", String.valueOf(item.getCount()), player.getName() }));
    return true;
}
Also used : Item(cn.nukkit.item.Item) Player(cn.nukkit.Player) TranslationContainer(cn.nukkit.lang.TranslationContainer)

Example 17 with TranslationContainer

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

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

Example 18 with TranslationContainer

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

the class ParticleCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length < 7) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    Level level;
    if (sender instanceof Player) {
        level = ((Player) sender).getLevel();
    } else {
        level = sender.getServer().getDefaultLevel();
    }
    String name = args[0].toLowerCase();
    float[] floats = new float[6];
    for (int i = 0; i < floats.length; i++) {
        try {
            double d = Double.valueOf(args[i + 1]);
            floats[i] = (float) d;
        } catch (Exception e) {
            return false;
        }
    }
    Vector3 pos = new Vector3(floats[0], floats[1], floats[2]);
    float xd = floats[3];
    float yd = floats[4];
    float zd = floats[5];
    int count = 1;
    if (args.length > 7) {
        try {
            double c = Double.valueOf(args[7]);
            count = (int) c;
        } catch (Exception e) {
        // ignore
        }
    }
    count = Math.max(1, count);
    Integer data = null;
    if (args.length > 8) {
        try {
            double d = Double.valueOf(args[8]);
            data = (int) d;
        } catch (Exception e) {
        // ignore
        }
    }
    Particle particle = this.getParticle(name, pos, xd, yd, zd, data);
    if (particle == null) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.particle.notFound", name));
        return true;
    }
    sender.sendMessage(new TranslationContainer("commands.particle.success", new String[] { name, String.valueOf(count) }));
    Random random = new Random(System.currentTimeMillis());
    for (int i = 0; i < count; i++) {
        particle.setComponents(pos.x + (random.nextFloat() * 2 - 1) * xd, pos.y + (random.nextFloat() * 2 - 1) * yd, pos.z + (random.nextFloat() * 2 - 1) * zd);
        level.addParticle(particle);
    }
    return true;
}
Also used : Player(cn.nukkit.Player) Vector3(cn.nukkit.math.Vector3) Random(java.util.Random) TranslationContainer(cn.nukkit.lang.TranslationContainer) Level(cn.nukkit.level.Level)

Example 19 with TranslationContainer

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

the class ReloadCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    Command.broadcastCommandMessage(sender, new TranslationContainer(TextFormat.YELLOW + "%nukkit.command.reload.reloading" + TextFormat.WHITE));
    sender.getServer().reload();
    Command.broadcastCommandMessage(sender, new TranslationContainer(TextFormat.YELLOW + "%nukkit.command.reload.reloaded" + TextFormat.WHITE));
    return true;
}
Also used : TranslationContainer(cn.nukkit.lang.TranslationContainer)

Example 20 with TranslationContainer

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

the class SaveCommand method execute.

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

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