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