Search in sources :

Example 16 with LocalizedStringImpl

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

Example 17 with LocalizedStringImpl

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

Example 18 with LocalizedStringImpl

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

Example 19 with LocalizedStringImpl

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

Example 20 with LocalizedStringImpl

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;
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) CommandTarget(net.glowstone.command.CommandTarget) LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) Location(org.bukkit.Location)

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