use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class SeedCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
long seed;
if (sender instanceof Player) {
seed = ((Player) sender).getLevel().getSeed();
} else {
seed = sender.getServer().getDefaultLevel().getSeed();
}
sender.sendMessage(new TranslationContainer("commands.seed.success", String.valueOf(seed)));
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class SetWorldSpawnCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
Level level;
Vector3 pos;
if (args.length == 0) {
if (sender instanceof Player) {
level = ((Player) sender).getLevel();
pos = ((Player) sender).round();
} else {
sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
return true;
}
} else if (args.length == 3) {
level = sender.getServer().getDefaultLevel();
try {
pos = new Vector3(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]));
} catch (NumberFormatException e1) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
} else {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
level.setSpawnLocation(pos);
DecimalFormat round2 = new DecimalFormat("##0.00");
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.setworldspawn.success", new String[] { round2.format(pos.x), round2.format(pos.y), round2.format(pos.z) }));
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class SpawnpointCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
Player target;
if (args.length == 0) {
if (sender instanceof Player) {
target = (Player) sender;
} else {
sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
return true;
}
} else {
target = sender.getServer().getPlayer(args[0]);
if (target == null) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
return true;
}
}
Level level = target.getLevel();
DecimalFormat round2 = new DecimalFormat("##0.00");
if (args.length == 4) {
if (level != null) {
int x;
int y;
int z;
try {
x = Integer.parseInt(args[1]);
y = Integer.parseInt(args[2]);
z = Integer.parseInt(args[3]);
} catch (NumberFormatException e1) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
if (y < 0)
y = 0;
if (y > 256)
y = 256;
target.setSpawn(new Position(x, y, z, level));
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.spawnpoint.success", new String[] { target.getName(), round2.format(x), round2.format(y), round2.format(z) }));
return true;
}
} else if (args.length <= 1) {
if (sender instanceof Player) {
Position pos = (Position) sender;
target.setSpawn(pos);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.spawnpoint.success", new String[] { target.getName(), round2.format(pos.x), round2.format(pos.y), round2.format(pos.z) }));
return true;
} else {
sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
return true;
}
}
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class StopCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.stop.start"));
sender.getServer().shutdown();
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class HelpCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
String command = "";
int pageNumber = 1;
int pageHeight = 5;
if (args.length != 0) {
try {
pageNumber = Integer.valueOf(args[args.length - 1]);
if (pageNumber <= 0) {
pageNumber = 1;
}
String[] newargs = new String[args.length - 1];
System.arraycopy(args, 0, newargs, 0, newargs.length);
args = newargs;
/*if (args.length > 1) {
args = Arrays.copyOfRange(args, 0, args.length - 2);
} else {
args = new String[0];
}*/
for (String arg : args) {
if (!command.equals("")) {
command += " ";
}
command += arg;
}
} catch (NumberFormatException e) {
pageNumber = 1;
for (String arg : args) {
if (!command.equals("")) {
command += " ";
}
command += arg;
}
}
}
if (sender instanceof ConsoleCommandSender) {
pageHeight = Integer.MAX_VALUE;
}
if (command.equals("")) {
Map<String, Command> commands = new TreeMap<>();
for (Command cmd : sender.getServer().getCommandMap().getCommands().values()) {
if (cmd.testPermissionSilent(sender)) {
commands.put(cmd.getName(), cmd);
}
}
int totalPage = commands.size() % pageHeight == 0 ? commands.size() / pageHeight : commands.size() / pageHeight + 1;
pageNumber = Math.min(pageNumber, totalPage);
if (pageNumber < 1) {
pageNumber = 1;
}
sender.sendMessage(new TranslationContainer("commands.help.header", new String[] { String.valueOf(pageNumber), String.valueOf(totalPage) }));
int i = 1;
for (Command command1 : commands.values()) {
if (i >= (pageNumber - 1) * pageHeight + 1 && i <= Math.min(commands.size(), pageNumber * pageHeight)) {
sender.sendMessage(TextFormat.DARK_GREEN + "/" + command1.getName() + ": " + TextFormat.WHITE + command1.getDescription());
}
i++;
}
return true;
} else {
Command cmd = sender.getServer().getCommandMap().getCommand(command.toLowerCase());
if (cmd != null) {
if (cmd.testPermissionSilent(sender)) {
String message = TextFormat.YELLOW + "--------- " + TextFormat.WHITE + " Help: /" + cmd.getName() + TextFormat.YELLOW + " ---------\n";
message += TextFormat.GOLD + "Description: " + TextFormat.WHITE + cmd.getDescription() + "\n";
String usage = "";
String[] usages = cmd.getUsage().split("\n");
for (String u : usages) {
if (!usage.equals("")) {
usage += "\n" + TextFormat.WHITE;
}
usage += u;
}
message += TextFormat.GOLD + "Usage: " + TextFormat.WHITE + usage + "\n";
sender.sendMessage(message);
return true;
}
}
sender.sendMessage(TextFormat.RED + "No help for " + command.toLowerCase());
return true;
}
}
Aggregations