use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class KickCommand 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);
}
Player player = sender.getServer().getPlayer(name);
if (player != null) {
player.kick(PlayerKickEvent.Reason.KICKED_BY_ADMIN, reason);
if (reason.length() >= 1) {
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success.reason", new String[] { player.getName(), reason }));
} else {
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success", player.getName()));
}
} else {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
}
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class KillCommand 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;
}
if (args.length == 1) {
if (!sender.hasPermission("nukkit.command.kill.other")) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
return true;
}
Player player = sender.getServer().getPlayer(args[0]);
if (player != null) {
EntityDamageEvent ev = new EntityDamageEvent(player, DamageCause.SUICIDE, 1000);
sender.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return true;
}
player.setLastDamageCause(ev);
player.setHealth(0);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kill.successful", player.getName()));
} else {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
}
return true;
}
if (sender instanceof Player) {
if (!sender.hasPermission("nukkit.command.kill.self")) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
return true;
}
EntityDamageEvent ev = new EntityDamageEvent((Player) sender, DamageCause.SUICIDE, 1000);
sender.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return true;
}
((Player) sender).setLastDamageCause(ev);
((Player) sender).setHealth(0);
sender.sendMessage(new TranslationContainer("commands.kill.successful", sender.getName()));
} else {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class ListCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
String online = "";
int onlineCount = 0;
for (Player player : sender.getServer().getOnlinePlayers().values()) {
if (player.isOnline() && (!(sender instanceof Player) || ((Player) sender).canSee(player))) {
online += player.getDisplayName() + ", ";
++onlineCount;
}
}
if (online.length() > 0) {
online = online.substring(0, online.length() - 2);
}
sender.sendMessage(new TranslationContainer("commands.players.list", new String[] { String.valueOf(onlineCount), String.valueOf(sender.getServer().getMaxPlayers()) }));
sender.sendMessage(online);
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class MeCommand 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;
if (sender instanceof Player) {
name = ((Player) sender).getDisplayName();
} else {
name = sender.getName();
}
String msg = "";
for (String arg : args) {
msg += arg + " ";
}
if (msg.length() > 0) {
msg = msg.substring(0, msg.length() - 1);
}
sender.getServer().broadcastMessage(new TranslationContainer("chat.type.emote", new String[] { name, TextFormat.WHITE + msg }));
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class PardonCommand 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;
}
sender.getServer().getNameBans().remove(args[0]);
Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.unban.success", args[0]));
return true;
}
Aggregations