use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class PardonIpCommand 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;
}
String value = args[0];
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)) {
sender.getServer().getIPBans().remove(value);
sender.getServer().getNetwork().unblockAddress(value);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.unbanip.success", value));
} else {
sender.sendMessage(new TranslationContainer("commands.unbanip.invalid"));
}
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class TellCommand 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;
}
String name = args[0].toLowerCase();
Player player = sender.getServer().getPlayer(name);
if (player == null) {
sender.sendMessage(new TranslationContainer("commands.generic.player.notFound"));
return true;
}
if (Objects.equals(player, sender)) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.message.sameTarget"));
return true;
}
String msg = "";
for (int i = 1; i < args.length; i++) {
msg += args[i] + " ";
}
if (msg.length() > 0) {
msg = msg.substring(0, msg.length() - 1);
}
String displayName = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName());
sender.sendMessage("[" + sender.getName() + " -> " + player.getDisplayName() + "] " + msg);
player.sendMessage("[" + displayName + " -> " + player.getName() + "] " + msg);
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class TimeCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (args.length < 1) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
if ("start".equals(args[0])) {
if (!sender.hasPermission("nukkit.command.time.start")) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
return true;
}
for (Level level : sender.getServer().getLevels().values()) {
level.checkTime();
level.startTime();
level.checkTime();
}
Command.broadcastCommandMessage(sender, "Restarted the time");
return true;
} else if ("stop".equals(args[0])) {
if (!sender.hasPermission("nukkit.command.time.stop")) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
return true;
}
for (Level level : sender.getServer().getLevels().values()) {
level.checkTime();
level.stopTime();
level.checkTime();
}
Command.broadcastCommandMessage(sender, "Stopped the time");
return true;
} else if ("query".equals(args[0])) {
if (!sender.hasPermission("nukkit.command.time.query")) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
return true;
}
Level level;
if (sender instanceof Player) {
level = ((Player) sender).getLevel();
} else {
level = sender.getServer().getDefaultLevel();
}
sender.sendMessage(new TranslationContainer("commands.time.query", String.valueOf(level.getTime())));
return true;
}
if (args.length < 2) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
if ("set".equals(args[0])) {
if (!sender.hasPermission("nukkit.command.time.set")) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
return true;
}
int value;
if ("day".equals(args[1])) {
value = Level.TIME_DAY;
} else if ("night".equals(args[1])) {
value = Level.TIME_NIGHT;
} else {
try {
value = Math.max(0, Integer.parseInt(args[1]));
} catch (Exception e) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
}
for (Level level : sender.getServer().getLevels().values()) {
level.checkTime();
level.setTime(value);
level.checkTime();
}
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.time.set", String.valueOf(value)));
} else if ("add".equals(args[0])) {
if (!sender.hasPermission("nukkit.command.time.add")) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
return true;
}
int value;
try {
value = Math.max(0, Integer.parseInt(args[1]));
} catch (Exception e) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
for (Level level : sender.getServer().getLevels().values()) {
level.checkTime();
level.setTime(level.getTime() + value);
level.checkTime();
}
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.time.added", String.valueOf(value)));
} else {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
}
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class WhitelistCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length == 0 || args.length > 2) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
if (args.length == 1) {
if (this.badPerm(sender, args[0].toLowerCase())) {
return false;
}
switch(args[0].toLowerCase()) {
case "reload":
sender.getServer().reloadWhitelist();
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.whitelist.reloaded"));
return true;
case "on":
sender.getServer().setPropertyBoolean("white-list", true);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.whitelist.enabled"));
return true;
case "off":
sender.getServer().setPropertyBoolean("white-list", false);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.whitelist.disabled"));
return true;
case "list":
String result = "";
int count = 0;
for (String player : sender.getServer().getWhitelist().getAll().keySet()) {
result += player + ", ";
++count;
}
sender.sendMessage(new TranslationContainer("commands.whitelist.list", new String[] { String.valueOf(count), String.valueOf(count) }));
sender.sendMessage(result.length() > 0 ? result.substring(0, result.length() - 2) : "");
return true;
case "add":
sender.sendMessage(new TranslationContainer("commands.generic.usage", "%commands.whitelist.add.usage"));
return true;
case "remove":
sender.sendMessage(new TranslationContainer("commands.generic.usage", "%commands.whitelist.remove.usage"));
return true;
}
} else if (args.length == 2) {
if (this.badPerm(sender, args[0].toLowerCase())) {
return false;
}
switch(args[0].toLowerCase()) {
case "add":
sender.getServer().getOfflinePlayer(args[1]).setWhitelisted(true);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.whitelist.add.success", args[1]));
return true;
case "remove":
sender.getServer().getOfflinePlayer(args[1]).setWhitelisted(false);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.whitelist.remove.success", args[1]));
return true;
}
}
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class XpCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
// "/xp <amount> [player]" for adding exp
// "/xp <amount>L [player]" for adding exp level
String amountString;
String playerName;
Player player;
if (!(sender instanceof Player)) {
if (args.length != 2) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
amountString = args[0];
playerName = args[1];
player = sender.getServer().getPlayer(playerName);
} else {
if (args.length == 1) {
amountString = args[0];
player = (Player) sender;
} else if (args.length == 2) {
amountString = args[0];
playerName = args[1];
player = sender.getServer().getPlayer(playerName);
} else {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
}
if (player == null) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
return true;
}
int amount;
boolean isLevel = false;
if (amountString.endsWith("l") || amountString.endsWith("L")) {
amountString = amountString.substring(0, amountString.length() - 1);
isLevel = true;
}
try {
amount = Integer.parseInt(amountString);
} catch (NumberFormatException e1) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
if (isLevel) {
int newLevel = player.getExperienceLevel();
newLevel += amount;
if (newLevel > 24791)
newLevel = 24791;
if (newLevel < 0) {
player.setExperience(0, 0);
} else {
player.setExperience(player.getExperience(), newLevel);
}
if (amount > 0) {
sender.sendMessage(new TranslationContainer("commands.xp.success.levels", new String[] { String.valueOf(amount), player.getName() }));
} else {
sender.sendMessage(new TranslationContainer("commands.xp.success.levels.minus", new String[] { String.valueOf(-amount), player.getName() }));
}
return true;
} else {
if (amount < 0) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
player.addExperience(amount);
sender.sendMessage(new TranslationContainer("commands.xp.success", new String[] { String.valueOf(amount), player.getName() }));
return true;
}
}
Aggregations