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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations