Search in sources :

Example 26 with LocalizedStringImpl

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;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) ResourceBundle(java.util.ResourceBundle) BanEntry(org.bukkit.BanEntry) BanList(org.bukkit.BanList) Collator(java.text.Collator)

Example 27 with LocalizedStringImpl

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;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) GlowServer(net.glowstone.GlowServer)

Example 28 with LocalizedStringImpl

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;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) GlowWorld(net.glowstone.GlowWorld)

Example 29 with LocalizedStringImpl

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;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) ResourceBundle(java.util.ResourceBundle) World(org.bukkit.World)

Example 30 with LocalizedStringImpl

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;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl)

Aggregations

LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)37 Location (org.bukkit.Location)15 ResourceBundle (java.util.ResourceBundle)11 CommandTarget (net.glowstone.command.CommandTarget)11 Entity (org.bukkit.entity.Entity)10 Player (org.bukkit.entity.Player)10 ArrayList (java.util.ArrayList)7 Material (org.bukkit.Material)6 GlowWorld (net.glowstone.GlowWorld)5 GlowPlayer (net.glowstone.entity.GlowPlayer)5 CompoundTag (net.glowstone.util.nbt.CompoundTag)5 World (org.bukkit.World)5 GlowServer (net.glowstone.GlowServer)4 GlowBlock (net.glowstone.block.GlowBlock)4 MojangsonParseException (net.glowstone.util.mojangson.ex.MojangsonParseException)4 BlockCommandSender (org.bukkit.command.BlockCommandSender)3 ItemStack (org.bukkit.inventory.ItemStack)3 BlockStateData (net.glowstone.block.state.BlockStateData)2 InvalidBlockStateException (net.glowstone.block.state.InvalidBlockStateException)2 GlowEntity (net.glowstone.entity.GlowEntity)2