use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class BanListCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args, CommandMessages messages) {
if (!testPermission(sender, messages.getPermissionMessage())) {
return true;
}
final ResourceBundle resourceBundle = messages.getResourceBundle();
BanList.Type banType;
if (args.length > 0) {
Collator caseInsensitive = Collator.getInstance(messages.getLocale());
caseInsensitive.setStrength(Collator.PRIMARY);
if (caseInsensitive.compare(args[0], "ips") == 0) {
// NON-NLS
banType = BanList.Type.IP;
} else if (caseInsensitive.compare(args[0], "players") == 0) {
// NON-NLS
banType = BanList.Type.NAME;
} else {
sendUsageMessage(sender, messages);
return false;
}
} else {
banType = BanList.Type.NAME;
}
final Set<BanEntry> banEntries = Bukkit.getBanList(banType).getBanEntries();
if (banEntries.isEmpty()) {
new LocalizedStringImpl("banlist.empty", resourceBundle).send(sender);
} else {
final Stream<String> targets = banEntries.stream().map(BanEntry::getTarget);
new LocalizedStringImpl("banlist.non-empty", resourceBundle).send(sender, banEntries.size());
sender.sendMessage(messages.joinList(targets));
}
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class DeopCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages messages) {
if (!testPermission(sender, messages.getPermissionMessage())) {
return true;
}
if (args.length != 1) {
sendUsageMessage(sender, messages);
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("deop.failed", messages.getResourceBundle()).sendInColor(ChatColor.RED, sender, name, ex.getMessage());
ConsoleMessages.Error.Command.DEOP_FAILED.log(ex, name);
return;
}
if (player.isOp()) {
player.setOp(false);
new LocalizedStringImpl("deop.done", messages.getResourceBundle()).send(sender, name);
} else {
new LocalizedStringImpl("deop.not-op", messages.getResourceBundle()).sendInColor(ChatColor.RED, sender, name);
}
});
// todo: asynchronous command callbacks?
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class GameRuleCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
GlowWorld world = CommandUtils.getWorld(sender);
if (args.length == 0) {
sender.sendMessage(commandMessages.joinList(world.getGameRules()));
return true;
}
if (args.length == 1) {
String gamerule = args[0];
if (world.getGameRuleMap().isGameRule(gamerule)) {
String value = world.getGameRuleValue(gamerule);
if (value == null) {
value = "-";
}
sender.sendMessage(gamerule + " = " + value);
return true;
} else {
new LocalizedStringImpl("gamerule.unknown", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, gamerule);
return false;
}
}
String value = StringUtils.join(args, " ", 1, args.length);
world.setGameRuleValue(args[0], value);
// TODO: Should we use the actual value, in case the type conversion was messy?
new LocalizedStringImpl("gamerule.done", commandMessages.getResourceBundle()).send(sender, args[0], value);
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class SaveAllCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
ResourceBundle bundle = commandMessages.getResourceBundle();
new LocalizedStringImpl("save-all.starting", bundle).send(sender);
LocalizedStringImpl doneWorld = new LocalizedStringImpl("save-all.done.world", bundle);
for (World world : sender.getServer().getWorlds()) {
world.save();
doneWorld.send(sender, world.getName());
}
new LocalizedStringImpl("save-all.done", bundle).send(sender);
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class SetIdleTimeoutCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length == 0) {
sendUsageMessage(sender, commandMessages);
return false;
}
final String stringTimeout = args[0];
int timeout;
try {
timeout = Integer.parseInt(stringTimeout);
} catch (NumberFormatException ex) {
commandMessages.getGeneric(GenericMessage.NAN).sendInColor(ChatColor.RED, sender, stringTimeout);
return false;
}
if (timeout <= 0) {
new LocalizedStringImpl("setidletimeout.too-low", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, timeout);
return false;
}
ServerProvider.getServer().setIdleTimeout(timeout);
new LocalizedStringImpl("setidletimeout.done", commandMessages.getResourceBundle()).send(sender, timeout);
return true;
}
Aggregations