Search in sources :

Example 11 with LocalizedStringImpl

use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.

the class DifficultyCommand 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;
    }
    GlowWorld world = CommandUtils.getWorld(sender);
    String difficultyId = args[0];
    Difficulty difficulty = DIFFICULTIES.nameToValue(messages.getLocale(), difficultyId);
    if (difficulty == null) {
        new LocalizedStringImpl("difficulty.unknown", messages.getResourceBundle()).sendInColor(ChatColor.RED, sender, difficultyId);
        return false;
    }
    world.setDifficulty(difficulty);
    new LocalizedStringImpl("difficulty.done", messages.getResourceBundle()).send(sender, world, DIFFICULTIES.valueToName(messages.getLocale(), difficulty));
    return true;
}
Also used : Difficulty(org.bukkit.Difficulty) LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) GlowWorld(net.glowstone.GlowWorld)

Example 12 with LocalizedStringImpl

use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.

the class GameModeCommand method execute.

@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages messages) {
    if (!testPermission(sender, messages.getPermissionMessage())) {
        return true;
    }
    if (args.length == 0 || args.length == 1 && !(sender instanceof Player)) {
        sendUsageMessage(sender, messages);
        return false;
    }
    final ResourceBundle bundle = messages.getResourceBundle();
    String gm = args[0];
    GameMode gamemode = GameModeUtils.build(gm, messages.getLocale());
    if (gamemode == null) {
        new LocalizedStringImpl("gamemode.unknown", bundle).sendInColor(ChatColor.RED, sender, gm);
        return false;
    }
    if (args.length == 1) {
        // self
        Player player = (Player) sender;
        updateGameMode(sender, player, gamemode, bundle);
        return true;
    }
    String name = args[1];
    if (name.startsWith("@") && name.length() >= 2 && CommandUtils.isPhysical(sender)) {
        Location location = CommandUtils.getLocation(sender);
        CommandTarget target = new CommandTarget(sender, name);
        Entity[] matched = target.getMatched(location);
        for (Entity entity : matched) {
            if (entity instanceof Player) {
                Player player = (Player) entity;
                updateGameMode(sender, player, gamemode, bundle);
            }
        }
    } else {
        Player player = Bukkit.getPlayerExact(name);
        if (player == null) {
            messages.getGeneric(GenericMessage.OFFLINE).sendInColor(ChatColor.RED, sender, name);
        } else {
            updateGameMode(sender, player, gamemode, bundle);
        }
    }
    return true;
}
Also used : GameMode(org.bukkit.GameMode) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) CommandTarget(net.glowstone.command.CommandTarget) LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) ResourceBundle(java.util.ResourceBundle) Location(org.bukkit.Location)

Example 13 with LocalizedStringImpl

use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.

the class GameModeCommand method updateGameMode.

private void updateGameMode(CommandSender sender, Player who, GameMode gameMode, ResourceBundle bundle) {
    String gameModeName = GameModeUtils.prettyPrint(gameMode, bundle.getLocale());
    who.setGameMode(gameMode);
    if (!sender.equals(who)) {
        new LocalizedStringImpl("gamemode.done", bundle).send(sender, who.getDisplayName(), gameModeName);
        // switch to target's locale for gamemode.done.to-you
        bundle = getBundle(who);
    }
    new LocalizedStringImpl("gamemode.done.to-you", bundle).send(who, gameModeName);
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl)

Example 14 with LocalizedStringImpl

use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.

the class GiveCommand method execute.

@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
    if (!testPermission(sender, commandMessages.getPermissionMessage())) {
        return true;
    }
    if (args.length < 2) {
        sendUsageMessage(sender, commandMessages);
        return false;
    }
    String itemName = CommandUtils.toNamespaced(args[1]);
    Material type = ItemIds.getItem(itemName);
    if (type == null) {
        new LocalizedStringImpl("give.unknown", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, itemName);
        return false;
    }
    ItemStack stack = new ItemStack(type);
    if (args.length >= 3) {
        String amountString = args[2];
        try {
            int amount = Integer.valueOf(amountString);
            if (amount > 64) {
                new LocalizedStringImpl("give.too-many", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, amount);
                return false;
            } else if (amount < 1) {
                new LocalizedStringImpl("give.too-few", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, amount);
                return false;
            }
            stack.setAmount(amount);
        } catch (NumberFormatException ex) {
            commandMessages.getGeneric(GenericMessage.NAN).sendInColor(ChatColor.RED, sender, amountString);
            return false;
        }
    }
    String name = args[0];
    if (name.startsWith("@") && name.length() >= 2 && CommandUtils.isPhysical(sender)) {
        Location location = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation();
        CommandTarget target = new CommandTarget(sender, name);
        Entity[] matched = target.getMatched(location);
        for (Entity entity : matched) {
            if (entity instanceof Player) {
                Player player = (Player) entity;
                giveItem(sender, player, stack, commandMessages.getResourceBundle());
            }
        }
    } else {
        Player player = Bukkit.getPlayerExact(name);
        if (player == null) {
            commandMessages.getGeneric(GenericMessage.OFFLINE).sendInColor(ChatColor.RED, sender, name);
            return false;
        } else {
            giveItem(sender, player, stack, commandMessages.getResourceBundle());
        }
    }
    return true;
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) CommandTarget(net.glowstone.command.CommandTarget) LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location) BlockCommandSender(org.bukkit.command.BlockCommandSender)

Example 15 with LocalizedStringImpl

use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.

the class GiveCommand method giveItem.

private void giveItem(CommandSender sender, Player player, ItemStack stack, ResourceBundle resourceBundle) {
    player.getInventory().addItem(stack);
    new LocalizedStringImpl("give.done", resourceBundle).send(sender, ItemIds.getName(stack.getType()), stack.getAmount(), player.getName());
}
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