Package org.bukkit

Examples of org.bukkit.GameMode


   */
 
  public static Boolean run(CommandSender sender, String alias, String[] args) {
   
    Player target = null;
    GameMode toGM = null;
   
    if (args.length == 0){
      if (!(sender instanceof Player)){
        Commands.showCommandHelpAndUsage(sender, "cex_gm", alias);
        return true;
      }
     
      target = (Player) sender;
    }
   
    if (args.length > 3){
      Commands.showCommandHelpAndUsage(sender, "cex_gm", alias);
      return true;
    }
   
    if (args.length == 1){
      toGM = matchGM(args[0]);
      if (toGM == null){
        if (!sender.hasPermission("cex.gamemode.others")){
          LogHelper.showInfo("gamemodeOthersNoPerm", sender, ChatColor.RED);
          return true;
        }
       
        target = Bukkit.getPlayer(args[0]);
       
        if (target == null){
          LogHelper.showInfo("invalidPlayer", sender, ChatColor.RED);
          return true;
        }
      } else {
        if (!(sender instanceof Player)){
          Commands.showCommandHelpAndUsage(sender, "cex_gm", alias);
          return true;
        }
       
        target = (Player) sender;
      }
    }
   
    if (args.length == 2){
      if (!sender.hasPermission("cex.gamemode.others")){
        LogHelper.showInfo("gamemodeOthersNoPerm", sender, ChatColor.RED);
        return true;
      }
     
      target = Bukkit.getPlayer(args[0]);
      if (target == null){
        LogHelper.showInfo("invalidPlayer", sender, ChatColor.RED);
        return true;
      }
     
      toGM = matchGM(args[1]);
      if (toGM == null){
        LogHelper.showInfo("gamemodeInvalid", sender, ChatColor.RED);
        return true;
      }
    }
   
    if (toGM == null){
      if (target.getGameMode() == GameMode.SURVIVAL){
        toGM = GameMode.CREATIVE;
      } else {
        toGM = GameMode.SURVIVAL;
      }
    }
   
   
    target.setGameMode(toGM);
    if (sender != target){
      LogHelper.showInfo("gamemodeToSender#####[" + Nicknames.getNick(target.getName()) + " #####to#####[" + Utils.userFriendlyNames(toGM.name()), sender, ChatColor.AQUA);
      LogHelper.showInfo("gamemodeNotify#####[" + Nicknames.getNick(sender.getName()) + " #####to#####[" + Utils.userFriendlyNames(toGM.name()), target, ChatColor.AQUA);
    } else {
      LogHelper.showInfo("gamemodeSelf#####[" + Utils.userFriendlyNames(toGM.name()), sender, ChatColor.AQUA);
    }
   
    return true;
  }
View Full Code Here


   
    return true;
  }
 
  public static GameMode matchGM(String input){
    GameMode gamemode = null;
   
    if (input.matches(CommandsEX.intRegex)){
      int intValue = Integer.valueOf(input);
      for (GameMode gm : GameMode.values()){
        if (gm.getValue() == intValue){
View Full Code Here

       
        final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
        final BlockBreakData data = BlockBreakData.getData(player);
        final long now = System.currentTimeMillis();
       
        final GameMode gameMode = player.getGameMode();
       
        // Has the player broken a block that was not damaged before?
        if (wrongBlock.isEnabled(player) && wrongBlock.check(player, block, cc, data, isInstaBreak)) {
          cancelled = true;
        }
View Full Code Here

        try {
            value = Integer.parseInt(modeArg);
        } catch (NumberFormatException ex) {}

        GameMode mode = GameMode.getByValue(value);

        if (mode == null) {
            if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
                mode = GameMode.CREATIVE;
            } else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
                mode = GameMode.ADVENTURE;
            } else {
                mode = GameMode.SURVIVAL;
            }
        }

        Bukkit.getServer().setDefaultGameMode(mode);
        Command.broadcastCommandMessage(sender, "Default game mode set to " + mode.toString().toLowerCase());

        return true;
    }
View Full Code Here

            try {
                value = Integer.parseInt(modeArg);
            } catch (NumberFormatException ex) {}

            GameMode mode = GameMode.getByValue(value);

            if (mode == null) {
                if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
                    mode = GameMode.CREATIVE;
                } else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
                    mode = GameMode.ADVENTURE;
                } else {
                    mode = GameMode.SURVIVAL;
                }
            }

            if (mode != player.getGameMode()) {
                player.setGameMode(mode);

                if (mode != player.getGameMode()) {
                    sender.sendMessage("Game mode change for " + player.getName() + " failed!");
                } else {
                    if (player == sender) {
                        Command.broadcastCommandMessage(sender, "Set own game mode to " + mode.toString() + " mode");
                    } else {
                        Command.broadcastCommandMessage(sender, "Set " + player.getName() + "'s game mode to " + mode.toString() + " mode");
                    }
                }
            } else {
                sender.sendMessage(player.getName() + " already has game mode " + mode.getValue());
            }
        } else {
            sender.sendMessage("Can't find player " + playerArg);
        }
View Full Code Here

  }

  @Override
  public GameMode select(String arg, CommandSender sender)
  {
    GameMode ret = null;
   
    arg = arg.toLowerCase();
   
    if (arg.startsWith("s"))
    {
View Full Code Here

                usage = "[player] [gamemode]", desc = "Change a player's gamemode",
                flags = "c", min = 0, max = 2)
        public void gamemode(CommandContext args, CommandSender sender) throws CommandException {

            Player player;
            GameMode mode = null;
            boolean change = false;

            if (args.argsLength() == 0) { // check self
                // check current player
                player = PlayerUtil.checkPlayer(sender);
                mode = player.getGameMode();
            } else {
                if (args.hasFlag('c')) { //check other player
                    player = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0));
                    mode = player.getGameMode();
                } else {
                    change = true;

                    // we're going to assume that the first arg of one is mode, but the first of two is player
                    // if they want to check another player, they should use -c instead, since we can't guess
                    // reliably whether (with a single arg) they meant a player or a mode
                    String modeString;
                    if (args.argsLength() == 1) { // self mode
                        modeString = args.getString(0);
                        player = PlayerUtil.checkPlayer(sender);
                    } else { // 2 - first is player, second mode
                        // HERP DERP VANILLA COMMAND BLOCKS
                        try {
                            modeString = String.valueOf(args.getInteger(0));
                            player = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(1));
                        } catch (NumberFormatException e) {
                            // NOPE NOT VANILLA COMMAND BLOCKS
                            player = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0));
                            modeString = args.getString(1);
                        }
                    }

                    CommandBook.inst().checkPermission(sender, "commandbook.gamemode."
                            + (change ? "change" : "check")
                            + (player != sender ? ".other" : ""));

                    try {
                        mode = GameMode.valueOf(modeString.toUpperCase());
                    } catch (IllegalArgumentException e) {
                        try {
                            mode = GameMode.getByValue(Integer.parseInt(modeString));
                        } catch (NumberFormatException ignored) {}
                    }
                    if (mode == null) {
                        throw new CommandException("Unrecognized gamemode: " + modeString + ".");
                    }
                }
            }

            if (player == null || mode == null) {
                throw new CommandException("Something went wrong, please try again.");
            }

            String message;
            if (change) {
                if (player.getGameMode() == mode) {
                    message = " already had gamemode " + mode.toString();
                    change = false;
                } else {
                    message = " changed to gamemode " + mode.toString();
                }
            } else {
                message = " currently has gamemode " + mode.toString();
            }
            if (change) {
                player.setGameMode(mode);
            }
            sender.sendMessage(ChatColor.YELLOW + "Player " + (CommandBook.inst().useDisplayNames ? player.getDisplayName() : player.getName())
View Full Code Here

    @Override
    public void load(T entity, CompoundTag tag) {
        super.load(entity, tag);

        if (tag.isInt("playerGameType")) {
            GameMode mode = GameMode.getByValue(tag.getInt("playerGameType"));
            if (mode != null) {
                entity.setGameMode(mode);
            }
        }
        if (tag.isInt("SelectedItemSlot")) {
View Full Code Here

          message(ChatColor.WHITE + "Remember last pos.: " + ChatColor.GREEN + "No, teleport to spawn point");
        }
        //Difficulty
        message(ChatColor.WHITE + "Difficulty: " + ChatColor.YELLOW + wc.difficulty.toString().toLowerCase());
        //Game mode
        GameMode mode = wc.gameMode;
        if (mode == null) {
          message(ChatColor.WHITE + "Game mode: " + ChatColor.YELLOW + "Not set");
        } else {
          message(ChatColor.WHITE + "Game mode: " + ChatColor.YELLOW + mode.name().toLowerCase());
        }
        //Time
        String timestr = wc.timeControl.getTime(info.time);
        message(ChatColor.WHITE + "Time: " + ChatColor.YELLOW + timestr);
        //Weather
View Full Code Here

  public void execute() {
    this.genWorldname(1);
    if (this.handleWorld()) {
      if (args.length == 0) {
        //display
        GameMode mode = WorldConfig.get(worldname).gameMode;
        String msg = ChatColor.YELLOW + "Current game mode of world '" + worldname + "': ";
        if (mode == null) {
          message(msg + ChatColor.YELLOW + "Not set");
        } else {
          message(msg + ChatColor.YELLOW + mode.name().toLowerCase());
        }
      } else {
        //Parse the gamemode
        GameMode mode = ParseUtil.parseEnum(GameMode.class, args[0], null);
        WorldConfig wc = WorldConfig.get(worldname);
        wc.setGameMode(mode);
        if (mode == null) {
          message(ChatColor.YELLOW + "Game mode of World '" + worldname + "' cleared!");
        } else {
          message(ChatColor.YELLOW + "Game mode of World '" + worldname + "' set to " + mode.name().toLowerCase() + "!");
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.bukkit.GameMode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.