Java Code Examples for cn.nukkit.Server#getGamemodeFromString()

The following examples show how to use cn.nukkit.Server#getGamemodeFromString() . 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: 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 2
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 3
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 4
Source File: GamemodeCommand.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }

    int gameMode = Server.getGamemodeFromString(args[0]);
    if (gameMode == -1) {
        sender.sendMessage("Unknown game mode");
        return true;
    }

    CommandSender target = sender;
    if (args.length > 1) {
        if (sender.hasPermission("nukkit.command.gamemode.other")) {
            target = sender.getServer().getPlayer(args[1]);
            if (target == null) {
                sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
                return true;
            }
        } else {
            sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
            return true;
        }
    } else if (!(sender instanceof Player)) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }

    if ((gameMode == 0 && !sender.hasPermission("nukkit.command.gamemode.survival")) ||
            (gameMode == 1 && !sender.hasPermission("nukkit.command.gamemode.creative")) ||
            (gameMode == 2 && !sender.hasPermission("nukkit.command.gamemode.adventure")) ||
            (gameMode == 3 && !sender.hasPermission("nukkit.command.gamemode.spectator"))) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
        return true;
    }

    if (!((Player) target).setGamemode(gameMode)) {
        sender.sendMessage("" + target.getName() + "のゲームモード変更に失敗しました。");
    } else {
        if (target.equals(sender)) {
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.gamemode.success.self", Server.getGamemodeString(gameMode)));
        } else {
            target.sendMessage(new TranslationContainer("gameMode.changed"));
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.gamemode.success.other", new String[]{target.getName(), Server.getGamemodeString(gameMode)}));
        }
    }

    return true;
}
 
Example 5
Source File: GamemodeCommand.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }

    int gameMode = Server.getGamemodeFromString(args[0]);
    if (gameMode == -1) {
        sender.sendMessage("Unknown game mode");
        return true;
    }

    CommandSender target = sender;
    if (args.length > 1) {
        if (sender.hasPermission("nukkit.command.gamemode.other")) {
            target = sender.getServer().getPlayer(args[1]);
            if (target == null) {
                sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
                return true;
            }
        } else {
            sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
            return true;
        }
    } else if (!(sender instanceof Player)) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }

    if ((gameMode == 0 && !sender.hasPermission("nukkit.command.gamemode.survival")) ||
            (gameMode == 1 && !sender.hasPermission("nukkit.command.gamemode.creative")) ||
            (gameMode == 2 && !sender.hasPermission("nukkit.command.gamemode.adventure")) ||
            (gameMode == 3 && !sender.hasPermission("nukkit.command.gamemode.spectator"))) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
        return true;
    }

    if (!((Player) target).setGamemode(gameMode)) {
        sender.sendMessage("Game mode update for " + target.getName() + " failed");
    } else {
        if (target.equals(sender)) {
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.gamemode.success.self", Server.getGamemodeString(gameMode)));
        } else {
            target.sendMessage(new TranslationContainer("gameMode.changed"));
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.gamemode.success.other", target.getName(), Server.getGamemodeString(gameMode)));
        }
    }

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

    int gameMode = Server.getGamemodeFromString(args[0]);
    if (gameMode == -1) {
        sender.sendMessage("Unknown game mode");
        return true;
    }

    CommandSender target = sender;
    if (args.length > 1) {
        if (sender.hasPermission("nukkit.command.gamemode.other")) {
            target = sender.getServer().getPlayer(args[1]);
            if (target == null) {
                sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
                return true;
            }
        } else {
            sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
            return true;
        }
    } else if (!(sender instanceof Player)) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }

    if ((gameMode == 0 && !sender.hasPermission("nukkit.command.gamemode.survival")) ||
            (gameMode == 1 && !sender.hasPermission("nukkit.command.gamemode.creative")) ||
            (gameMode == 2 && !sender.hasPermission("nukkit.command.gamemode.adventure")) ||
            (gameMode == 3 && !sender.hasPermission("nukkit.command.gamemode.spectator"))) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
        return true;
    }

    if (!((Player) target).setGamemode(gameMode)) {
        sender.sendMessage("Game mode update for " + target.getName() + " failed");
    } else {
        if (target.equals(sender)) {
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.gamemode.success.self", Server.getGamemodeString(gameMode)));
        } else {
            target.sendMessage(new TranslationContainer("gameMode.changed"));
            Command.broadcastCommandMessage(sender, new TranslationContainer("commands.gamemode.success.other", new String[]{target.getName(), Server.getGamemodeString(gameMode)}));
        }
    }

    return true;
}