コード例 #1
0
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    Player p = (Player) sender;
    if (commandLabel.equalsIgnoreCase("createarena")) {
      if (args.length > 0) { // > means greater than
        if (p.hasPermission("paintball.createarena")) {
          if (c.get("leftx") != null
              && c.get("lefty") != null
              && c.get("leftz") != null
              && c.get("rightx") != null
              && c.get("righty") != null
              && c.get("rightz") != null) {
            Location spawn = p.getLocation();
            World world = p.getWorld();

            double lx = (float) c.get("leftx");
            double ly = (float) c.get("lefty");
            double lz = (float) c.get("leftz");
            double rx = (float) c.get("rightx");
            double ry = (float) c.get("righty");
            double rz = (float) c.get("rightz");

            Location corner1 = new Location(world, lx, ly, lz);
            Location corner2 = new Location(world, rx, ry, rz);
            try {
              mg.createArena(args[1], spawn, corner1, corner2);
            } catch (InvalidLocationException e) {
              p.sendMessage(ChatColor.RED + "That is an invalid location!");
              e.printStackTrace();
            } catch (ArenaExistsException e) {
              p.sendMessage(ChatColor.RED + "That arena already exists!");
              e.printStackTrace();
            }
          } else {
            p.sendMessage(ChatColor.RED + "You have to set pos1 and pos2 first!");
          }
        } else {
          p.sendMessage(ChatColor.RED + "You do not have the permission to do that.");
        }
      } else {
        p.sendMessage(
            ChatColor.RED
                + "Wrong arguments. Try "
                + ChatColor.YELLOW
                + "/createarena <name>"
                + ChatColor.RED
                + ".");
      }

      if (commandLabel.equalsIgnoreCase("paintball")) {
        if (p.hasPermission("paintball.paintball")) {
          p.sendMessage(ChatColor.YELLOW + "MiniWorldPaintball Help:");
          p.sendMessage("");
          p.sendMessage(
              ChatColor.AQUA + "/paintball" + ChatColor.GOLD + " - Gives you the paintball help");
          p.sendMessage(
              ChatColor.AQUA + "/createarena" + ChatColor.GOLD + " - Creates a paintball arena");
          p.sendMessage(
              ChatColor.AQUA + "/deletearena" + ChatColor.GOLD + " - Deletes a paintball arena");
          p.sendMessage(
              ChatColor.AQUA
                  + "/paintballwand"
                  + ChatColor.GOLD
                  + " - Gives you the paintball wand");
          p.sendMessage(ChatColor.AQUA + "/createround" + ChatColor.GOLD + " - Creates a round");
          p.sendMessage(ChatColor.AQUA + "/join" + ChatColor.GOLD + " - Joins a round");
          p.sendMessage(ChatColor.AQUA + "/leave" + ChatColor.GOLD + " - Leaves a round");
        } else {
          p.sendMessage(ChatColor.RED + "You do not have the permission to do that.");
        }
      }

      if (commandLabel.equalsIgnoreCase("paintballwand")) {
        if (p.hasPermission("paintball.createarena")) {
          PaintballWand = new PaintballWand("paintballwand", Material.STICK);
          CustomItemStack is = new CustomItemStack(PaintballWand);
          p.getInventory().addItem(is.getItem());
          p.sendMessage(
              ChatColor.AQUA
                  + "Use the "
                  + ChatColor.BLACK
                  + "[Paintball Wand]"
                  + ChatColor.AQUA
                  + " to set pos1 and pos2.");
        } else {
          p.sendMessage(ChatColor.RED + "You do not have the permission to do that.");
        }
      }

      if (commandLabel.equalsIgnoreCase("deletearena")) {
        if (p.hasPermission("paintball.deletearena")) {
          if (args.length > 0) {
            try {
              mg.deleteArena(args[1]);
            } catch (ArenaNotExistsException e) {
              p.sendMessage(ChatColor.RED + "That arena doesn't exist.");
              e.printStackTrace();
            }
          } else {
            p.sendMessage(
                ChatColor.RED
                    + "Wrong arguments. Try "
                    + ChatColor.YELLOW
                    + "/deletearena <name>"
                    + ChatColor.RED
                    + ".");
          }
        } else {
          p.sendMessage(ChatColor.RED + "You do not have the permission to do that.");
        }
      }

      if (commandLabel.equalsIgnoreCase("createround")) {
        if (p.hasPermission("paintball.createround")) {
          if (args.length > 0) {
            try {
              mg.createRound(args[1]);
            } catch (ArenaNotExistsException e) {
              p.sendMessage(ChatColor.RED + "That arena doesn't exist.");
              e.printStackTrace();
            }
          } else {
            p.sendMessage(
                ChatColor.RED
                    + "Wrong arguments. Try "
                    + ChatColor.YELLOW
                    + "/createround <arenaname>"
                    + ChatColor.RED
                    + ".");
          }
        } else {
          p.sendMessage(ChatColor.RED + "You do not have the permission to do that.");
        }
      }

      if (commandLabel.equalsIgnoreCase("forcestart")) {
        if (p.hasPermission("paintball.forcestart")) {
          if (args.length > 0) {
            Round round = mg.getRound(args[1]);
            round.start();
          } else {
            p.sendMessage(
                ChatColor.RED
                    + "Wrong arguments. Try "
                    + ChatColor.YELLOW
                    + "/forcestart <arenaname>"
                    + ChatColor.RED
                    + ".");
          }
        } else {
          p.sendMessage(ChatColor.RED + "You do not have the permission to do that.");
        }
      }

      if (commandLabel.equalsIgnoreCase("forcestop")) {
        if (p.hasPermission("paintball.forcestop")) {
          if (args.length > 0) {
            Round round = mg.getRound(args[1]);
            round.end();
          } else {
            p.sendMessage(
                ChatColor.RED
                    + "Wrong arguments. Try "
                    + ChatColor.YELLOW
                    + "/forcestop <arenaname>"
                    + ChatColor.RED
                    + ".");
          }
        } else {
          p.sendMessage(ChatColor.RED + "You do not have the permission to do that.");
        }
      }

      if (commandLabel.equalsIgnoreCase("join")) {
        if (p.hasPermission("paintball.join")) {
          if (args.length > 0) {
            Round round = mg.getRound(args[1]);
            MGPlayer mgplayer;
            String player = "" + p + "";
            try {
              round.addPlayer(player);
            } catch (PlayerOfflineException e) {
              p.sendMessage(ChatColor.RED + "That player is offline.");
              e.printStackTrace();
            } catch (PlayerPresentException e) {
              // Don't know what this means... :P
              e.printStackTrace();
            } catch (RoundFullException e) {
              p.sendMessage(ChatColor.RED + "That round is full.");
              e.printStackTrace();
            }
          } else {
            p.sendMessage(
                ChatColor.RED
                    + "Wrong arguments. Try "
                    + ChatColor.YELLOW
                    + "/join <arenaname>"
                    + ChatColor.RED
                    + ".");
          }
        } else {
          p.sendMessage(ChatColor.RED + "You do not have the permission to do that.");
        }
      }

      if (commandLabel.equalsIgnoreCase("leave")) {
        if (p.hasPermission("paintball.leave")) {
          MGPlayer player = (MGPlayer) p;
          String playerstring = "" + p + "";
          String arena = player.getArena();
          Round round = mg.getRound(arena);
          try {
            round.removePlayer(playerstring);
          } catch (PlayerOfflineException e) {
            p.sendMessage(ChatColor.RED + "That player is offline.");
            e.printStackTrace();
          } catch (PlayerNotPresentException e) {
            p.sendMessage(ChatColor.RED + "You are not in a round.");
            e.printStackTrace();
          }
        } else {
          p.sendMessage(ChatColor.RED + "You do not have the permission to do that.");
        }
      }
    }
    return false;
  }
コード例 #2
0
 public void onEnable() {
   mg = Minigame.registerPlugin(this);
   c.options().copyDefaults(true);
   saveConfig();
   l.info("MiniWorldPaintball is now enabled.");
 }