use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class ListCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
Collection<String> messages = new ArrayList<>(players.size() + 1);
messages.add(new LocalizedStringImpl("list.header", commandMessages.getResourceBundle()).get(players.size(), Bukkit.getMaxPlayers()));
if (args.length > 0 && (Objects.equals(args[0], "uuids") || Objects.equals(args[0], "ids"))) {
LocalizedStringImpl nameAndUuidMessage = new LocalizedStringImpl("list.name-and-uuid", commandMessages.getResourceBundle());
Bukkit.getOnlinePlayers().forEach(p -> messages.add(nameAndUuidMessage.get(p.getName(), UuidUtils.toString(p.getUniqueId()))));
} else {
Bukkit.getOnlinePlayers().forEach(p -> messages.add(p.getName()));
}
messages.forEach(sender::sendMessage);
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class OpCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length != 1) {
sendUsageMessage(sender, commandMessages);
return false;
}
String name = args[0];
GlowServer server = (GlowServer) ServerProvider.getServer();
// asynchronously lookup player
server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
if (ex != null) {
new LocalizedStringImpl("op.failed", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, name, ex.getMessage());
ConsoleMessages.Error.Command.OP_FAILED.log(ex, name);
return;
}
player.setOp(true);
new LocalizedStringImpl("op.done", commandMessages.getResourceBundle()).send(sender, name);
});
// todo: asynchronous command callbacks?
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class PardonCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length != 1) {
sendUsageMessage(sender, commandMessages);
return false;
}
String name = args[0];
final GlowServer server = (GlowServer) ServerProvider.getServer();
// asynchronously lookup player
server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
if (ex != null) {
new LocalizedStringImpl("pardon.exception", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, name, ex.getMessage());
ex.printStackTrace();
return;
}
BanList banList = server.getBanList(BanList.Type.NAME);
String exactName = player.getName();
if (!banList.isBanned(exactName)) {
new LocalizedStringImpl("pardon.not-banned", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, exactName);
return;
}
banList.pardon(exactName);
new LocalizedStringImpl("pardon.done", commandMessages.getResourceBundle()).send(sender, exactName);
});
// todo: asynchronous command callbacks?
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class PardonIpCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length != 1) {
sendUsageMessage(sender, commandMessages);
return false;
}
String ip = args[0];
if (!InetAddresses.isInetAddress(ip)) {
new LocalizedStringImpl("pardon-ip.invalid", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, ip);
return false;
}
ServerProvider.getServer().unbanIP(ip);
new LocalizedStringImpl("pardon-ip.done", commandMessages.getResourceBundle()).send(sender, ip);
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class TeleportCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length < 4 || args.length == 5) {
sendUsageMessage(sender, commandMessages);
return false;
}
if (!CommandUtils.isPhysical(sender)) {
commandMessages.getGeneric(GenericMessage.NOT_PHYSICAL).sendInColor(ChatColor.RED, sender);
return false;
}
Location location = CommandUtils.getLocation(sender);
Entity[] targets;
if (args[0].startsWith("@")) {
targets = new CommandTarget(sender, args[0]).getMatched(location);
} else {
Player targetPlayer = Bukkit.getPlayerExact(args[0]);
if (targetPlayer != null) {
location = targetPlayer.getLocation();
}
targets = targetPlayer == null ? NO_ENTITY : new Entity[] { targetPlayer };
}
if (targets.length == 0) {
commandMessages.getGeneric(GenericMessage.NO_MATCHES).sendInColor(ChatColor.RED, sender, args[0]);
} else {
for (Entity target : targets) {
String x = args[1];
String y = args[2];
String z = args[3];
Location targetLocation = CommandUtils.getLocation(location, x, y, z);
if (args.length > 4) {
String yaw = args[4];
String pitch = args[5];
targetLocation = CommandUtils.getRotation(target.getLocation(), yaw, pitch);
} else {
targetLocation.setYaw(target.getLocation().getYaw());
targetLocation.setPitch(target.getLocation().getPitch());
}
target.teleport(targetLocation, PlayerTeleportEvent.TeleportCause.COMMAND);
new LocalizedStringImpl("teleport.done", commandMessages.getResourceBundle()).send(sender, target.getName(), targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
}
}
return true;
}
Aggregations