Ejemplo n.º 1
0
  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());
      }
    }
  }
Ejemplo n.º 2
0
  public Boolean addPlayer(String name) {
    Player p = Bukkit.getServer().getPlayer(name);
    if (p == null) {
      return false;
    }
    if (p.getName().equals(leader)) {
      return false;
    }
    members.add(name);

    /* Dodanie gracza do cuboidu i configu */
    RegionManager regionManager = getRegionManager(world);
    String prefix = Config.getPrefix();
    DefaultDomain dd = regionManager.getRegion(prefix + akronim).getMembers();
    dd.addPlayer(name);
    regionManager.getRegion(prefix + akronim).setMembers(dd);
    try {
      regionManager.save();
    } catch (ProtectionDatabaseException ex) {
      Logger.getLogger(Wioska.class.getName()).log(Level.SEVERE, null, ex);
    }

    saveWioska();
    return true;
  }
Ejemplo n.º 3
0
  public Boolean removePlayer(String name) {
    if (!members.contains(name)) {
      return false;
    }
    members.remove(name);

    /* Usunięcie gracza z cuboidu i configu */
    RegionManager regionManager = getRegionManager(world);
    String prefix = Config.getPrefix();
    DefaultDomain dd = regionManager.getRegion(prefix + akronim).getMembers();
    dd.removePlayer(name);
    regionManager.getRegion(prefix + akronim).setMembers(dd);
    try {
      regionManager.save();
    } catch (ProtectionDatabaseException ex) {
      Logger.getLogger(Wioska.class.getName()).log(Level.SEVERE, null, ex);
    }

    saveWioska();
    return true;
  }
Ejemplo n.º 4
0
  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());
    }
  }
Ejemplo n.º 5
0
  public void setRegion(Player sender, String[] args) {
    if (args.length != 2) {
      sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help");
      return;
    }

    LocalPlayer wgPlayer = plugin.wrapPlayer(sender);

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

    if (!ProtectedRegion.isValidId(id)) {
      sender.sendMessage(ChatColor.RED + "Invalid region name specified!");
      return;
    }

    Selection sel = worldEdit.getSelection(sender);

    if (sel == null) {
      sender.sendMessage(ChatColor.RED + "Select a region with a wooden axe first.");
      return;
    }

    RegionManager mgr = plugin.getGlobalRegionManager().get(sel.getWorld());

    if (mgr.hasRegion(id)) {
      sender.sendMessage(
          ChatColor.RED + "That region name is already taken. Please choose a new name.");
      return;
    }

    int regionCount = mgr.getRegionCountOfPlayer(wgPlayer);

    if (regionCount > Economy.maxDonatorAllowedRegions
        && !sender.isOp()
        && sender.hasPermission("iceprotect.freeprotect")) {
      sender.sendMessage(
          ChatColor.RED
              + "You have reached the maximum allowed regions per user ("
              + Economy.maxDonatorAllowedRegions
              + ").");
      sender.sendMessage(ChatColor.RED + "Please contact an admin.");
      return;
    }

    ProtectedRegion region = null;

    if (sel instanceof Polygonal2DSelection) {
      Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
      int minY = polySel.getNativeMinimumPoint().getBlockY();
      int maxY = polySel.getNativeMaximumPoint().getBlockY();
      region = new ProtectedPolygonalRegion(id, polySel.getNativePoints(), minY, maxY);
    } else if (sel instanceof CuboidSelection) {
      BlockVector min = sel.getNativeMinimumPoint().toBlockVector();
      BlockVector max = sel.getNativeMaximumPoint().toBlockVector();
      region = new ProtectedCuboidRegion(id, min, max);
    } else {
      sender.sendMessage(
          ChatColor.RED
              + "(shouldn't happen) Something went wrong. The type of region selected is unsupported!");
      return;
    }

    String[] names = new String[1];
    names[0] = sender.getName();
    region.setOwners(RegionUtil.parseDomainString(names, 0));

    ApplicableRegionSet regions = mgr.getApplicableRegions(region);

    if (!regions.isOwnerOfAll(wgPlayer)) {
      sender.sendMessage(ChatColor.RED + "That region overlaps with another one not owned by you!");
      return;
    }

    double cost = (int) Math.ceil(econ.getCost(region.volume()));

    if (cost > Economy.maxDonatorAllowedCost && sender.hasPermission("iceprotect.freeprotect")) {
      sender.sendMessage(
          ChatColor.RED + "You have exceeded the maximum allowed price for this region!");
      sender.sendMessage(
          ChatColor.RED
              + "Cost: "
              + ChatColor.GRAY
              + "$"
              + cost
              + ChatColor.RED
              + ", "
              + ChatColor.GRAY
              + "$"
              + Economy.maxDonatorAllowedCost
              + " allowed.");
      return;
    }

    if (!sender.hasPermission("iceprotect.freeprotect") && !econ.chargePlayer(sender, cost)) {
      sender.sendMessage(ChatColor.RED + "You don't have enough money! $" + cost + " needed.");
      return;
    }

    mgr.addRegion(region);

    try {
      mgr.save();
      sender.sendMessage(
          ChatColor.YELLOW
              + "Region saved as "
              + args[1]
              + ". "
              + (sender.hasPermission("iceprotect.freeprotect") ? "" : "Cost: $" + cost + "."));
    } catch (IOException e) {
      sender.sendMessage(
          ChatColor.RED + "(shouldn't happen) Failed to write regions file: " + e.getMessage());
      e.printStackTrace();
      return;
    }
  }