cn.nukkit.lang.TranslationContainer Java Examples

The following examples show how to use cn.nukkit.lang.TranslationContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }

    String name = args[0];
    IPlayer player = sender.getServer().getOfflinePlayer(name);

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.op.success", player.getName()));
    if (player instanceof Player) {
        ((Player) player).sendMessage(TextFormat.GRAY + "You are now op!");
    }

    player.setOp(true);

    return true;
}
 
Example #2
Source File: DeopCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String playerName = args[0];
    IPlayer player = sender.getServer().getOfflinePlayer(playerName);
    player.setOp(false);

    if (player instanceof Player) {
        ((Player) player).sendMessage(new TranslationContainer(TextFormat.GRAY + "%commands.deop.message"));
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.deop.success", new String[]{player.getName()}));

    return true;
}
 
Example #3
Source File: ListCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    String online = "";
    int onlineCount = 0;
    for (Player player : sender.getServer().getOnlinePlayers().values()) {
        if (player.isOnline() && (!(sender instanceof Player) || ((Player) sender).canSee(player))) {
            online += player.getDisplayName() + ", ";
            ++onlineCount;
        }
    }

    if (online.length() > 0) {
        online = online.substring(0, online.length() - 2);
    }

    sender.sendMessage(new TranslationContainer("commands.players.list",
            String.valueOf(onlineCount), String.valueOf(sender.getServer().getMaxPlayers())));
    sender.sendMessage(online);
    return true;
}
 
Example #4
Source File: PardonIpCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String value = args[0];

    if (Pattern.matches("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", value)) {
        sender.getServer().getIPBans().remove(value);
        sender.getServer().getNetwork().unblockAddress(value);

        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.unbanip.success", value));
    } else {

        sender.sendMessage(new TranslationContainer("commands.unbanip.invalid"));
    }

    return true;
}
 
Example #5
Source File: Command.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) {
    Set<Permissible> users = source.getServer().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);

    TranslationContainer result = new TranslationContainer("chat.type.admin", source.getName(), message);

    TranslationContainer colored = new TranslationContainer(TextFormat.GRAY + "" + TextFormat.ITALIC + "%chat.type.admin", source.getName(), message);

    if (sendToSource && !(source instanceof ConsoleCommandSender)) {
        source.sendMessage(message);
    }

    for (Permissible user : users) {
        if (user instanceof CommandSender) {
            if (user instanceof ConsoleCommandSender) {
                ((ConsoleCommandSender) user).sendMessage(result);
            } else if (!user.equals(source)) {
                ((CommandSender) user).sendMessage(colored);
            }
        }
    }
}
 
Example #6
Source File: TimingsExport.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
private String getResponse(HttpURLConnection con) throws IOException {
    InputStream is = null;
    try {
        is = con.getInputStream();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        byte[] b = new byte[1024];
        int bytesRead;
        while ((bytesRead = is.read(b)) != -1) {
            bos.write(b, 0, bytesRead);
        }
        return bos.toString();

    } catch (IOException exception) {
        this.sender.sendMessage(TextFormat.RED + "" + new TranslationContainer("nukkit.command.timings.reportError"));
        Server.getInstance().getLogger().warning(con.getResponseMessage(), exception);
        return null;
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
 
Example #7
Source File: SaveCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.start"));

    for (Player player : sender.getServer().getOnlinePlayers().values()) {
        player.save();
    }

    for (Level level : sender.getServer().getLevels().values()) {
        level.save(true);
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.success"));
    return true;
}
 
Example #8
Source File: DeopCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String playerName = args[0];
    IPlayer player = sender.getServer().getOfflinePlayer(playerName);
    player.setOp(false);

    if (player instanceof Player) {
        ((Player) player).sendMessage(TextFormat.GRAY + "You are no longer op!");
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.deop.success", new String[]{player.getName()}));

    return true;
}
 
Example #9
Source File: PluginCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.owningPlugin.isEnabled()) {
        return false;
    }

    if (!this.testPermission(sender)) {
        return false;
    }

    boolean success = this.executor.onCommand(sender, this, commandLabel, args);

    if (!success && !this.usageMessage.equals("")) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
    }

    return success;
}
 
Example #10
Source File: SaveCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.start"));

    for (Player player : sender.getServer().getOnlinePlayers().values()) {
        player.save();
    }

    for (Level level : sender.getServer().getLevels().values()) {
        level.save(true);
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.success"));
    return true;
}
 
Example #11
Source File: OpCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.op.usage", this.usageMessage));
        return false;
    }

    String name = args[0];
    IPlayer player = sender.getServer().getOfflinePlayer(name);

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.op.success", player.getName()));
    if (player instanceof Player) {
        ((Player) player).sendMessage(new TranslationContainer(TextFormat.GRAY + "%commands.op.message"));
    }

    player.setOp(true);

    return true;
}
 
Example #12
Source File: PardonCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    sender.getServer().getNameBans().remove(args[0]);

    Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.unban.success", args[0]));

    return true;
}
 
Example #13
Source File: ListCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    String online = "";
    StringBuffer onlineBuffer = new StringBuffer();
    int onlineCount = 0;
    for (Player player : sender.getServer().getOnlinePlayers().values()) {
        if (player.isOnline() && (!(sender instanceof Player) || ((Player) sender).canSee(player))) {
            onlineBuffer.append(player.getDisplayName() + ", ");
            ++onlineCount;
        }
    }

    if (onlineBuffer.length() > 0) {
        online = onlineBuffer.substring(0, onlineBuffer.length() - 2);
    }

    sender.sendMessage(new TranslationContainer("commands.players.list",
            new String[]{String.valueOf(onlineCount), String.valueOf(sender.getServer().getMaxPlayers())}));
    sender.sendMessage(online);
    return true;
}
 
Example #14
Source File: SeedCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    long seed;
    if (sender instanceof Player) {
        seed = ((Player) sender).getLevel().getSeed();
    } else {
        seed = sender.getServer().getDefaultLevel().getSeed();
    }

    sender.sendMessage(new TranslationContainer("commands.seed.success", String.valueOf(seed)));

    return true;
}
 
Example #15
Source File: Server.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public boolean dispatchCommand(CommandSender sender, String commandLine) throws ServerException {
    // First we need to check if this command is on the main thread or not, if not, warn the user
    if (!this.isPrimaryThread()) {
        getLogger().warning("Command Dispatched Async: " + commandLine);
        getLogger().warning("Please notify author of plugin causing this execution to fix this bug!", new Throwable());
        // TODO: We should sync the command to the main thread too!
    }
    if (sender == null) {
        throw new ServerException("CommandSender is not valid");
    }

    if (this.commandMap.dispatch(sender, commandLine)) {
        return true;
    }

    sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.unknown", commandLine));

    return false;
}
 
Example #16
Source File: TimingsExport.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private String getResponse(HttpURLConnection con) throws IOException {
    try (InputStream is = con.getInputStream()) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        byte[] b = new byte[1024];
        int bytesRead;
        while ((bytesRead = is.read(b)) != -1) {
            bos.write(b, 0, bytesRead);
        }
        return bos.toString();

    } catch (IOException exception) {
        this.sender.sendMessage(TextFormat.RED + "" + new TranslationContainer("nukkit.command.timings.reportError"));
        Server.getInstance().getLogger().warning(con.getResponseMessage(), exception);
        return null;
    }
}
 
Example #17
Source File: DefaultGamemodeCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", new String[]{this.usageMessage}));
        return false;
    }
    int gameMode = Server.getGamemodeFromString(args[0]);
    if (gameMode != -1) {
        sender.getServer().setPropertyInt("gamemode", gameMode);
        sender.sendMessage(new TranslationContainer("commands.defaultgamemode.success", new String[]{Server.getGamemodeString(gameMode)}));
    } else {
        sender.sendMessage("Unknown game mode"); //
    }
    return true;
}
 
Example #18
Source File: SeedCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    long seed;
    if (sender instanceof Player) {
        seed = ((Player) sender).getLevel().getSeed();
    } else {
        seed = sender.getServer().getDefaultLevel().getSeed();
    }

    sender.sendMessage(new TranslationContainer("commands.seed.success", String.valueOf(seed)));

    return true;
}
 
Example #19
Source File: Command.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) {
    Set<Permissible> users = source.getServer().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);

    TranslationContainer result = new TranslationContainer("chat.type.admin", new String[]{source.getName(), message});

    TranslationContainer colored = new TranslationContainer(TextFormat.GRAY + "" + TextFormat.ITALIC + "%chat.type.admin", new String[]{source.getName(), message});

    if (sendToSource && !(source instanceof ConsoleCommandSender)) {
        source.sendMessage(message);
    }

    for (Permissible user : users) {
        if (user instanceof CommandSender) {
            if (user instanceof ConsoleCommandSender) {
                ((ConsoleCommandSender) user).sendMessage(result);
            } else if (!user.equals(source)) {
                ((CommandSender) user).sendMessage(colored);
            }
        }
    }
}
 
Example #20
Source File: PardonCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    sender.getServer().getNameBans().remove(args[0]);

    Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.unban.success", args[0]));

    return true;
}
 
Example #21
Source File: DefaultGamemodeCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", new String[]{this.usageMessage}));
        return false;
    }
    int gameMode = Server.getGamemodeFromString(args[0]);
    if (gameMode != -1) {
        sender.getServer().setPropertyInt("gamemode", gameMode);
        sender.sendMessage(new TranslationContainer("commands.defaultgamemode.success", new String[]{Server.getGamemodeString(gameMode)}));
    } else {
        sender.sendMessage("Unknown game mode"); //
    }
    return true;
}
 
Example #22
Source File: PardonIpCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String value = args[0];

    if (Pattern.matches("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", value)) {
        sender.getServer().getIPBans().remove(value);

        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.unbanip.success", value));
    } else {

        sender.sendMessage(new TranslationContainer("commands.unbanip.invalid"));
    }

    return true;
}
 
Example #23
Source File: PluginCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.owningPlugin.isEnabled()) {
        return false;
    }

    if (!this.testPermission(sender)) {
        return false;
    }

    boolean success = this.executor.onCommand(sender, this, commandLabel, args);

    if (!success && !this.usageMessage.equals("")) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
    }

    return success;
}
 
Example #24
Source File: TellCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length < 2) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    String name = args[0].toLowerCase();

    Player player = sender.getServer().getPlayer(name);
    if (player == null) {
        sender.sendMessage(new TranslationContainer("commands.generic.player.notFound"));
        return true;
    }

    if (Objects.equals(player, sender)) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.message.sameTarget"));
        return true;
    }

    String msg = "";
    for (int i = 1; i < args.length; i++) {
        msg += args[i] + " ";
    }
    if (msg.length() > 0) {
        msg = msg.substring(0, msg.length() - 1);
    }

    String displayName = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName());

    sender.sendMessage("[" + sender.getName() + " -> " + player.getDisplayName() + "] " + msg);
    player.sendMessage("[" + displayName + " -> " + player.getName() + "] " + msg);

    return true;
}
 
Example #25
Source File: Player.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void sendMessage(TextContainer message) {
    if (message instanceof TranslationContainer) {
        this.sendTranslation(message.getText(), ((TranslationContainer) message).getParameters());
        return;
    }
    this.sendMessage(message.getText());
}
 
Example #26
Source File: Command.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public boolean testPermission(CommandSender target) {
    if (this.testPermissionSilent(target)) {
        return true;
    }

    if (this.permissionMessage == null) {
        target.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
    } else if (!this.permissionMessage.equals("")) {
        target.sendMessage(this.permissionMessage.replace("<permission>", this.permission));
    }

    return false;
}
 
Example #27
Source File: WhitelistCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private boolean badPerm(CommandSender sender, String perm) {
    if (!sender.hasPermission("nukkit.command.whitelist" + perm)) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));

        return true;
    }

    return false;
}
 
Example #28
Source File: TimingsExport.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized void start() {
    if (this.sender instanceof RemoteConsoleCommandSender) {
        this.sender.sendMessage(new TranslationContainer("nukkit.command.timings.rcon"));
        run();
    } else {
        super.start();
    }
}
 
Example #29
Source File: DifficultyCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }

    int difficulty = Server.getDifficultyFromString(args[0]);

    if (sender.getServer().isHardcore()) {
        difficulty = 3;
    }

    if (difficulty != -1) {
        sender.getServer().setPropertyInt("difficulty", difficulty);

        SetDifficultyPacket pk = new SetDifficultyPacket();
        pk.difficulty = sender.getServer().getDifficulty();
        Server.broadcastPacket(new ArrayList<>(sender.getServer().getOnlinePlayers().values()), pk);

        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.difficulty.success", String.valueOf(difficulty)));
    } else {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));

        return false;
    }

    return true;
}
 
Example #30
Source File: SimpleCommandMap.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean dispatch(CommandSender sender, String cmdLine) {
    ArrayList<String> parsed = parseArguments(cmdLine);
    if (parsed.size() == 0) {
        return false;
    }

    String sentCommandLabel = parsed.remove(0).toLowerCase();
    String[] args = parsed.toArray(new String[parsed.size()]);
    Command target = this.getCommand(sentCommandLabel);

    if (target == null) {
        return false;
    }

    target.timing.startTiming();
    try {
        target.execute(sender, sentCommandLabel, args);
    } catch (Exception e) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.exception"));
        this.server.getLogger().critical(this.server.getLanguage().translateString("nukkit.command.exception", cmdLine, target.toString(), Utils.getExceptionMessage(e)));
        MainLogger logger = sender.getServer().getLogger();
        if (logger != null) {
            logger.logException(e);
        }
    }
    target.timing.stopTiming();

    return true;
}