コード例 #1
0
ファイル: Commands.java プロジェクト: alexstanoev/IceProtect
  public void deleteRegion(Player player, String[] args) {
    if (args.length != 2) {
      player.sendMessage(ChatColor.RED + "Wrong usage. /pr help");
      return;
    }

    String id = "icp_" + player.getName() + "_" + args[1];

    World world = player.getWorld();
    LocalPlayer localPlayer = plugin.wrapPlayer(player);

    RegionManager mgr = plugin.getGlobalRegionManager().get(world);
    ProtectedRegion region = mgr.getRegion(id);

    if (region == null) {
      player.sendMessage(ChatColor.RED + "Could not find a region by that name.");
      return;
    }

    if (region.isOwner(localPlayer)) {
      mgr.removeRegion(id);

      player.sendMessage(ChatColor.YELLOW + "Region " + args[1] + " removed.");

      try {
        mgr.save();
      } catch (IOException e) {
        player.sendMessage(
            ChatColor.RED + "(shouldn't happen) Failed to write regions file: " + e.getMessage());
      }
    }
  }
コード例 #2
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length != 0) {
      plugin.sendMessageWarning(
          sender,
          ChatColor.translateAlternateColorCodes(
              '&', plugin.languageGetConfig().getString("buyland.general.parameters")));
      plugin.sendMessageInfo(sender, "Usage: /buyland list");
    } else {
      // See if the person requesting the information is a player
      if (sender instanceof Player) {
        Player player = (Player) sender;
        String playerName = player.getName();

        // See if the player has permission to this command
        if (player.hasPermission("buyland.list") || player.hasPermission("buyland.all")) {
          // State who the list is for
          plugin.sendMessageInfo(sender, "You own regions: ");

          // Loop through all the worlds
          for (World world : Bukkit.getWorlds()) {
            // get the list of regions for the selected world
            Map<String, ProtectedRegion> regionMap = WGBukkit.getRegionManager(world).getRegions();
            // Loop through all the regions
            for (ProtectedRegion region : regionMap.values()) {
              // see if the person is an owner of the region
              if (region.isOwner(playerName)) {
                // see if the region is buyable
                if (region.getFlag(DefaultFlag.BUYABLE) == null) {
                  // if it is null, it is not purchased by anyone.
                } else {
                  // See if the region was purchased.
                  if (region.getFlag(DefaultFlag.BUYABLE) == false) {
                    // list this as owned by the player in question
                    plugin.sendMessageInfo(
                        sender, " " + world.getName() + ": " + region.getId(), false);
                  }
                }
              }
            }
          }
        }
      } else {
        plugin.sendMessageInfo(sender, "Currently not available at console.");
      }
    }

    // command was utilized.
    return true;
  }
コード例 #3
0
ファイル: Commands.java プロジェクト: alexstanoev/IceProtect
  public void allowUser(Player player, String[] args) {
    if (args.length != 3) {
      player.sendMessage(ChatColor.RED + "Wrong usage. /pr help");
      return;
    }

    String id = "icp_" + player.getName() + "_" + args[2];

    World world = player.getWorld();
    LocalPlayer localPlayer = plugin.wrapPlayer(player);

    RegionManager mgr = plugin.getGlobalRegionManager().get(world);
    ProtectedRegion region = mgr.getRegion(id);

    if (region == null) {
      player.sendMessage(ChatColor.RED + "Could not find a region by that name.");
      return;
    }

    if (region.isOwner(localPlayer)) {
      region.getMembers().addPlayer(args[1]);
      player.sendMessage(
          ChatColor.GREEN
              + "Allowed "
              + ChatColor.RED
              + args[1]
              + ChatColor.GREEN
              + " to region "
              + ChatColor.RED
              + args[2]
              + ChatColor.GREEN
              + ".");

      Player targetPlayer = Bukkit.getServer().getPlayerExact(args[1]);
      if (targetPlayer != null) {
        targetPlayer.sendMessage(
            ChatColor.GREEN
                + player.getName()
                + " has added you as a member in the "
                + ChatColor.RED
                + args[2]
                + ChatColor.GREEN
                + " region.");
      }

    } else {
      player.sendMessage(ChatColor.RED + "(shouldn't happen) You don't own the region " + args[2]);
    }
  }
コード例 #4
0
ファイル: Commands.java プロジェクト: alexstanoev/IceProtect
  public void denyUser(Player player, String[] args) {
    if (args.length != 3) {
      player.sendMessage(ChatColor.RED + "Wrong usage. /pr help");
      return;
    }

    String id = "icp_" + player.getName() + "_" + args[2];

    World world = player.getWorld();
    LocalPlayer localPlayer = plugin.wrapPlayer(player);

    RegionManager mgr = plugin.getGlobalRegionManager().get(world);
    ProtectedRegion region = mgr.getRegion(id);

    if (region == null) {
      player.sendMessage(ChatColor.RED + "Could not find a region by that name.");
      return;
    }

    if (region.isOwner(localPlayer)) {
      region.getMembers().removePlayer(args[1]);
      player.sendMessage(
          ChatColor.GREEN
              + "Removed player "
              + ChatColor.RED
              + args[1]
              + ChatColor.GREEN
              + " from region "
              + ChatColor.RED
              + args[2]
              + ChatColor.GREEN
              + ".");
    } else {
      player.sendMessage(ChatColor.RED + "(shouldn't happen) You don't own the region " + args[2]);
    }
  }
コード例 #5
0
ファイル: Commands.java プロジェクト: alexstanoev/IceProtect
  public void setFlags(Player sender, String[] args) {
    Player player = null;
    try {
      player = plugin.checkPlayer(sender);
    } catch (CommandException e1) {
      e1.printStackTrace();
      return;
    }

    World world = player.getWorld();
    LocalPlayer localPlayer = plugin.wrapPlayer(player);

    String value = null;

    if (args.length == 4) {
      value = args[3];
    } else if (args.length == 3) {
      //
    } else {
      player.sendMessage(ChatColor.RED + "Wrong usage! /pr help");
      return;
    }

    String id = "icp_" + player.getName() + "_" + args[1];
    String flagName = args[2];

    if (!(flagName.equals("use")
        || flagName.equals("chest-access")
        || flagName.equals("snow-fall")
        || flagName.equals("snow-melt")
        || flagName.equals("ice-form")
        || flagName.equals("ice-melt"))) {
      player.sendMessage(ChatColor.RED + "Unsupported flag! /pr help flags");
      return;
    }

    RegionManager mgr = plugin.getGlobalRegionManager().get(world);
    ProtectedRegion region = mgr.getRegion(id);

    if (region == null) {
      player.sendMessage(ChatColor.RED + "Could not find a region by that name.");
      return;
    }

    Flag<?> foundFlag = null;

    for (Flag<?> flag : DefaultFlag.getFlags()) {
      if (flag.getName().replace("-", "").equalsIgnoreCase(flagName.replace("-", ""))) {
        foundFlag = flag;
        break;
      }
    }

    if (foundFlag == null) {
      StringBuilder list = new StringBuilder();

      for (Flag<?> flag : DefaultFlag.getFlags()) {
        if (list.length() > 0) {
          list.append(", ");
        }

        if (!region.isOwner(localPlayer)) {
          continue;
        }

        list.append(flag.getName());
      }

      player.sendMessage(ChatColor.RED + "Unknown flag specified: " + flagName);
      player.sendMessage(ChatColor.RED + "Available flags: " + list);
      return;
    }

    if (region.isOwner(localPlayer)) {

      if (value != null) {
        try {
          setFlag(region, foundFlag, sender, value);
        } catch (InvalidFlagFormat e) {
          player.sendMessage(ChatColor.RED + e.getMessage());
          return;
        }

        sender.sendMessage(
            ChatColor.YELLOW
                + "Region flag "
                + ChatColor.GREEN
                + foundFlag.getName()
                + ChatColor.YELLOW
                + " set.");
      } else {
        region.setFlag(foundFlag, null);

        sender.sendMessage(
            ChatColor.YELLOW
                + "Region flag "
                + ChatColor.GREEN
                + foundFlag.getName()
                + ChatColor.YELLOW
                + " cleared.");
      }

    } else {
      sender.sendMessage(ChatColor.RED + "(shouldn't happen) You don't own this region!");
      return;
    }

    try {
      mgr.save();
    } catch (IOException e) {
      player.sendMessage(ChatColor.RED + "Failed to write regions file: " + e.getMessage());
    }
  }