Ejemplo n.º 1
0
  public void createArenaFromSelection(Player pl, String name) {
    FileConfiguration c = SettingsManager.getInstance().getSystemConfig();
    // SettingsManager s = SettingsManager.getInstance();

    WorldEditPlugin we = p.getWorldEdit();
    Selection sel = we.getSelection(pl);
    if (sel == null) {
      Message.send(pl, ChatColor.RED + "You must make a WorldEdit Selection first!");
      return;
    }
    Location max = sel.getMaximumPoint();
    Location min = sel.getMinimumPoint();

    /* if(max.getWorld()!=SettingsManager.getGameWorld() || min.getWorld()!=SettingsManager.getGameWorld()){
    	Message.send(pl, ChatColor.RED+"Wrong World!");
    	return;
    }*/
    SettingsManager.getInstance().getSpawns().set(("spawns." + name), null);
    c.set("system.arenas." + name + ".world", max.getWorld().getName());
    c.set("system.arenas." + name + ".x1", max.getBlockX());
    c.set("system.arenas." + name + ".y1", max.getBlockY());
    c.set("system.arenas." + name + ".z1", max.getBlockZ());
    c.set("system.arenas." + name + ".x2", min.getBlockX());
    c.set("system.arenas." + name + ".y2", min.getBlockY());
    c.set("system.arenas." + name + ".z2", min.getBlockZ());
    c.set("system.arenas." + name + ".enabled", false);
    c.set("system.arenas." + name + ".min", 3);
    c.set("system.arenas." + name + ".max", 4);
    SettingsManager.getInstance().saveSystemConfig();
    hotAddArena(name);
    Message.send(pl, ChatColor.GREEN + "Arena " + name.toUpperCase() + " succesfully added");
  }
Ejemplo n.º 2
0
  /**
   * Returns the selection of the players.
   *
   * @param player the players
   * @return the selection of the passed players.
   */
  public Area getSelectedArea(Player player) {
    if (worldEditPlugin != null) {
      Selection weSelection = worldEditPlugin.getSelection(player);

      if (weSelection != null && weSelection.getArea() > 0) {
        return new CuboidArea(weSelection.getMinimumPoint(), weSelection.getMaximumPoint());
      } else {
        return null;
      }
    } else {
      return null; // ToDo: Implement own selection tool!
    }
  }
Ejemplo n.º 3
0
 @Override
 protected void execute() {
   Mine m = Mines.i.mm.getMine(args[1]);
   if (m == null) {
     sender.sendMessage(MessageUtil.get("mines.notFound"));
     return;
   }
   Selection s = Mines.i.getWE().getSelection(Prison.i().playerList.getPlayer(sender.getName()));
   if (s == null) {
     sender.sendMessage(MessageUtil.get("mines.makeWESel"));
     return;
   }
   m.minX = s.getMinimumPoint().getBlockX();
   m.minY = s.getMinimumPoint().getBlockY();
   m.minZ = s.getMinimumPoint().getBlockZ();
   m.maxX = s.getMaximumPoint().getBlockX();
   m.maxY = s.getMaximumPoint().getBlockY();
   m.maxZ = s.getMaximumPoint().getBlockZ();
   m.save();
   Mines.i.mm.mines.remove(args[1]);
   Mines.i.mm.addMine(m);
   sender.sendMessage(MessageUtil.get("mines.redefineSuccess", m.name));
 }
Ejemplo n.º 4
0
  public void createArenaFromSelection(Player pl) {
    FileConfiguration c = SettingsManager.getInstance().getSystemConfig();
    // SettingsManager s = SettingsManager.getInstance();

    WorldEditPlugin we = getWorldEdit();
    Selection sel = we.getSelection(pl);
    if (sel == null) {
      msgmgr.sendMessage(PrefixType.WARNING, "You must make a WorldEdit Selection first!", pl);
      return;
    }
    Location max = sel.getMaximumPoint();
    Location min = sel.getMinimumPoint();

    /* if(max.getWorld()!=SettingsManager.getGameWorld() || min.getWorld()!=SettingsManager.getGameWorld()){
        pl.sendMessage(ChatColor.RED+"Wrong World!");
        return;
    }*/

    /*
     *
     *
     *
     *     RE-IMPLEMENT THIS PART
     *     LEAVING AS A REFRENCE
     *
     *
     */

    int no = c.getInt("sg-system.arenano") + 1;
    c.set("sg-system.arenano", no);
    if (games.size() == 0) {
      no = 1;
    } else no = games.get(games.size() - 1).getID() + 1;
    SettingsManager.getInstance().getSpawns().set(("spawns." + no), null);
    c.set("sg-system.arenas." + no + ".world", max.getWorld().getName());
    c.set("sg-system.arenas." + no + ".x1", max.getBlockX());
    c.set("sg-system.arenas." + no + ".y1", max.getBlockY());
    c.set("sg-system.arenas." + no + ".z1", max.getBlockZ());
    c.set("sg-system.arenas." + no + ".x2", min.getBlockX());
    c.set("sg-system.arenas." + no + ".y2", min.getBlockY());
    c.set("sg-system.arenas." + no + ".z2", min.getBlockZ());
    c.set("sg-system.arenas." + no + ".enabled", true);

    SettingsManager.getInstance().saveSystemConfig();
    hotAddArena(no);
    pl.sendMessage(ChatColor.GREEN + "Arena ID " + no + " Succesfully added");
  }
Ejemplo n.º 5
0
  public SearchParser(CommandSender player, List<String> args) throws IllegalArgumentException {
    this.player = player;

    String lastParam = "";
    boolean paramSet = false;
    boolean worldedit = false;

    for (int i = 0; i < args.size(); i++) {
      String arg = args.get(i);
      if (arg.isEmpty()) continue;

      if (!paramSet) {
        if (arg.length() < 2)
          throw new IllegalArgumentException("Invalid argument format: &7" + arg);
        if (!arg.substring(1, 2).equals(":")) {
          if (arg.contains(":"))
            throw new IllegalArgumentException("Invalid argument format: &7" + arg);

          // No arg specified, treat as player
          players.add(arg);
          continue;
        }

        lastParam = arg.substring(0, 1).toLowerCase();
        paramSet = true;

        if (arg.length() == 2) {
          if (i == (args.size() - 1)) // No values specified
          throw new IllegalArgumentException("Invalid argument format: &7" + arg);
          else // User put a space between the colon and value
          continue;
        }

        // Get values out of argument
        arg = arg.substring(2);
      }

      if (paramSet) {
        if (arg.isEmpty()) {
          throw new IllegalArgumentException("Invalid argument format: &7" + lastParam + ":");
        }

        String[] values = arg.split(",");

        // Players
        if (lastParam.equals("p")) for (String p : values) players.add(p);
        // Worlds
        else if (lastParam.equals("w")) worlds = values;
        // Filters
        else if (lastParam.equals("f")) {
          if (filters != null) filters = Util.concat(filters, values);
          else filters = values;
        }
        // Blocks
        else if (lastParam.equals("b")) {
          for (int j = 0; j < values.length; j++) {
            if (Material.getMaterial(values[j]) != null)
              values[j] = Integer.toString(Material.getMaterial(values[j]).getId());
          }
        }
        // Actions
        else if (lastParam.equals("a")) {
          for (String value : values) {
            DataType type = DataType.fromName(value);
            if (type == null)
              throw new IllegalArgumentException("Invalid action supplied: &7" + value);
            if (!Util.hasPerm(player, "search." + type.getConfigName().toLowerCase()))
              throw new IllegalArgumentException(
                  "You do not have permission to search for: &7" + type.getConfigName());
            actions.add(type);
          }
        }
        // Location
        else if (lastParam.equals("l") && player instanceof Player) {
          if (values[0].equalsIgnoreCase("here")) loc = ((Player) player).getLocation().toVector();
          else {
            loc = new Vector();
            loc.setX(Integer.parseInt(values[0]));
            loc.setY(Integer.parseInt(values[1]));
            loc.setZ(Integer.parseInt(values[2]));
          }
        }
        // Radius
        else if (lastParam.equals("r") && player instanceof Player) {
          if (!Util.isInteger(values[0])) {
            if ((values[0].equalsIgnoreCase("we") || values[0].equalsIgnoreCase("worldedit"))
                && HawkEye.worldEdit != null) {
              Selection sel = HawkEye.worldEdit.getSelection((Player) player);
              double lRadius = Math.ceil(sel.getLength() / 2);
              double wRadius = Math.ceil(sel.getWidth() / 2);
              double hRadius = Math.ceil(sel.getHeight() / 2);

              if (Config.MaxRadius != 0
                  && (lRadius > Config.MaxRadius
                      || wRadius > Config.MaxRadius
                      || hRadius > Config.MaxRadius))
                throw new IllegalArgumentException(
                    "Selection too large, max radius: &7" + Config.MaxRadius);

              worldedit = true;
              minLoc =
                  new Vector(
                      sel.getMinimumPoint().getX(),
                      sel.getMinimumPoint().getY(),
                      sel.getMinimumPoint().getZ());
              maxLoc =
                  new Vector(
                      sel.getMaximumPoint().getX(),
                      sel.getMaximumPoint().getY(),
                      sel.getMaximumPoint().getZ());
            } else {
              throw new IllegalArgumentException("Invalid radius supplied: &7" + values[0]);
            }
          } else {
            radius = Integer.parseInt(values[0]);
            if (Config.MaxRadius != 0 && radius > Config.MaxRadius)
              throw new IllegalArgumentException(
                  "Radius too large, max allowed: &7" + Config.MaxRadius);
          }
        }
        // Time
        else if (lastParam.equals("t")) {

          int type = 2;
          boolean isTo = false;
          for (int j = 0; j < arg.length(); j++) {
            String c = arg.substring(j, j + 1);
            if (!Util.isInteger(c)) {
              if (c.equals("m")
                  || c.equals("s")
                  || c.equals("h")
                  || c.equals("d")
                  || c.equals("w")) {
                type = 0;
              }
              if (c.equals("-") || c.equals(":")) type = 1;
            }
          }

          // If the time is in the format '0w0d0h0m0s'
          if (type == 0) {

            int weeks = 0;
            int days = 0;
            int hours = 0;
            int mins = 0;
            int secs = 0;

            String nums = "";
            for (int j = 0; j < values[0].length(); j++) {
              String c = values[0].substring(j, j + 1);
              if (c.equals("!")) { // If the number has a ! infront of it the time inverts
                c = values[0].substring(j, j + 2).replace("!", "");
                isTo = true;
              } else {
                if (Util.isInteger(c)) {
                  nums += c;
                  continue;
                }

                int num = Integer.parseInt(nums);
                if (c.equals("w")) weeks = num;
                else if (c.equals("d")) days = num;
                else if (c.equals("h")) hours = num;
                else if (c.equals("m")) mins = num;
                else if (c.equals("s")) secs = num;
                else throw new IllegalArgumentException("Invalid time measurement: &7" + c);
                nums = "";
              }
            }

            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.WEEK_OF_YEAR, -1 * weeks);
            cal.add(Calendar.DAY_OF_MONTH, -1 * days);
            cal.add(Calendar.HOUR, -1 * hours);
            cal.add(Calendar.MINUTE, -1 * mins);
            cal.add(Calendar.SECOND, -1 * secs);
            SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (isTo) dateTo = form.format(cal.getTime());
            else dateFrom = form.format(cal.getTime());
          }

          // If the time is in the format 'yyyy-MM-dd HH:mm:ss'
          else if (type == 1) {
            if (values.length == 1) {
              SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd");
              dateFrom = form.format(Calendar.getInstance().getTime()) + " " + values[0];
            }
            if (values.length >= 2) dateFrom = values[0] + " " + values[1];
            if (values.length == 4) dateTo = values[2] + " " + values[3];
          }
          // Invalid time format
          else if (type == 2) throw new IllegalArgumentException("Invalid time format!");

        } else throw new IllegalArgumentException("Invalid parameter supplied: &7" + lastParam);

        paramSet = false;
      }
    }

    // Sort out locations
    if (!worldedit) parseLocations();
  }
Ejemplo n.º 6
0
 /**
  * Creates a new region from WorldEdit selection.
  *
  * @param selection worldedit selection
  */
 public Region(final Selection selection) {
   this.v1 = new SerializableVector(selection.getMinimumPoint().toVector());
   this.v2 = new SerializableVector(selection.getMaximumPoint().toVector());
   this.w = selection.getWorld();
   this.w_name = this.w.getName();
 }
  @Command(
      aliases = {"save"},
      desc = "Saves the selected area",
      usage = "[-n namespace ] <id>",
      flags = "n:",
      min = 1)
  public void saveArea(CommandContext context, CommandSender sender) throws CommandException {

    if (!(sender instanceof Player)) return;
    LocalPlayer player = plugin.wrapPlayer((Player) sender);

    String id;
    String namespace = player.getName();
    boolean personal = true;

    if (context.hasFlag('n')
        && player.hasPermission("craftbook.mech.area.save." + context.getFlag('n'))) {
      namespace = context.getFlag('n');
      personal = false;
    } else if (!player.hasPermission("craftbook.mech.area.save.self"))
      throw new CommandPermissionsException();

    if (plugin.getConfiguration().areaShortenNames && namespace.length() > 14)
      namespace = namespace.substring(0, 14);

    if (!CopyManager.isValidNamespace(namespace))
      throw new CommandException("Invalid namespace. Needs to be between 1 and 14 letters long.");

    if (personal) {
      namespace = "~" + namespace;
    }

    id = context.getString(0);

    if (!CopyManager.isValidName(id))
      throw new CommandException("Invalid area name. Needs to be between 1 and 13 letters long.");

    try {
      WorldEditPlugin worldEdit = CraftBookPlugin.plugins.getWorldEdit();

      World world = ((Player) sender).getWorld();
      Selection sel = worldEdit.getSelection((Player) sender);
      if (sel == null) {
        sender.sendMessage(ChatColor.RED + "You have not made a selection!");
        return;
      }
      Vector min = BukkitUtil.toVector(sel.getMinimumPoint());
      Vector max = BukkitUtil.toVector(sel.getMaximumPoint());
      Vector size = max.subtract(min).add(1, 1, 1);

      // Check maximum size
      if (config.areaMaxAreaSize != -1
          && size.getBlockX() * size.getBlockY() * size.getBlockZ() > config.areaMaxAreaSize) {
        throw new CommandException(
            "Area is larger than allowed " + config.areaMaxAreaSize + " blocks.");
      }

      // Check to make sure that a user doesn't have too many toggle
      // areas (to prevent flooding the server with files)
      if (config.areaMaxAreaPerUser >= 0 && !namespace.equals("global")) {
        int count = copyManager.meetsQuota(world, namespace, id, config.areaMaxAreaPerUser);

        if (count > -1) {
          throw new CommandException(
              "You are limited to "
                  + config.areaMaxAreaPerUser
                  + " toggle area(s). "
                  + "You have "
                  + count
                  + " areas.");
        }
      }

      // Copy
      CuboidCopy copy;

      if (config.areaUseSchematics) {
        copy = new MCEditCuboidCopy(min, size, world);
      } else {
        copy = new FlatCuboidCopy(min, size, world);
      }

      copy.copy();

      plugin
          .getServer()
          .getLogger()
          .info(
              player.getName()
                  + " saving toggle area with folder '"
                  + namespace
                  + "' and ID '"
                  + id
                  + "'.");

      // Save
      try {
        CopyManager.getInstance().save(world, namespace, id.toLowerCase(Locale.ENGLISH), copy);
        player.print("Area saved as '" + id + "' under the '" + namespace + "' namespace.");
      } catch (IOException e) {
        player.printError("Could not save area: " + e.getMessage());
      } catch (DataException e) {
        player.print(e.getMessage());
      }
    } catch (NoClassDefFoundError e) {
      throw new CommandException(
          "WorldEdit.jar does not exist in plugins/, or is outdated. (Or you are using an outdated version of CraftBook)");
    }
  }