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");
  }
 public void setLobbySignsFromSelection(Player pl, int a) {
   FileConfiguration c = SettingsManager.getInstance().getSystemConfig();
   SettingsManager s = SettingsManager.getInstance();
   if (!c.getBoolean("walls-system.lobby.sign.set", false)) {
     c.set("walls-system.lobby.sign.set", true);
     s.saveSystemConfig();
   }
   WorldEditPlugin we = GameManager.getInstance().getWorldEdit();
   Selection sel = we.getSelection(pl);
   if (sel == null) {
     pl.sendMessage(ChatColor.RED + "You must make a WorldEdit Selection first");
     return;
   }
   if ((sel.getNativeMaximumPoint().getBlockX() - sel.getNativeMinimumPoint().getBlockX()) != 0
       && (sel.getNativeMinimumPoint().getBlockZ() - sel.getNativeMaximumPoint().getBlockZ()
           != 0)) {
     pl.sendMessage(ChatColor.RED + " Must be in a straight line!");
     return;
   }
   Vector max = sel.getNativeMaximumPoint();
   Vector min = sel.getNativeMinimumPoint();
   int i = c.getInt("walls-system.lobby.signno", 0) + 1;
   c.set("walls-system.lobby.signno", i);
   c.set("walls-system.lobby.signs." + i + ".id", a);
   c.set("walls-system.lobby.signs." + i + ".world", pl.getWorld().getName());
   c.set("walls-system.lobby.signs." + i + ".x1", max.getBlockX());
   c.set("walls-system.lobby.signs." + i + ".y1", max.getBlockY());
   c.set("walls-system.lobby.signs." + i + ".z1", max.getBlockZ());
   c.set("walls-system.lobby.signs." + i + ".x2", min.getBlockX());
   c.set("walls-system.lobby.signs." + i + ".y2", min.getBlockY());
   c.set("walls-system.lobby.signs." + i + ".z2", min.getBlockZ());
   pl.sendMessage(ChatColor.GREEN + "Added Lobby Wall"); // TODO
   s.saveSystemConfig();
   loadSign(i);
 }
 @Override
 public void onPluginMessageReceived(String channel, Player player, byte[] message) {
   LocalSession session = plugin.getSession(player);
   String text = new String(message, UTF_8_CHARSET);
   session.handleCUIInitializationMessage(text);
   session.describeCUI(plugin.wrapPlayer(player));
 }
  private static boolean addWorldGuardRegion(
      CommandSender sender, Arena arena, BattleArenaController ac, String value) {
    if (!checkWorldGuard(sender)) {
      return false;
    }
    Player p = (Player) sender;
    WorldEditPlugin wep = WorldEditUtil.getWorldEditPlugin();
    Selection sel = wep.getSelection(p);
    if (sel == null) {
      sendMessage(sender, "&cYou need to select a region to use this command.");
      return false;
    }

    String region = arena.getRegion();
    World w = sel.getWorld();
    try {
      String id = makeRegionName(arena);
      if (region != null) {
        WorldGuardInterface.updateProtectedRegion(p, id);
        sendMessage(sender, "&2Region updated! ");
      } else {
        WorldGuardInterface.createProtectedRegion(p, id);
        sendMessage(sender, "&2Region added! ");
      }
      arena.addRegion(w.getName(), id);
      WorldGuardInterface.saveSchematic(p, id);
    } catch (Exception e) {
      sendMessage(sender, "&cAdding WorldGuard region failed!");
      sendMessage(sender, "&c" + e.getMessage());
      e.printStackTrace();
    }
    return true;
  }
  private static Selection checkSelection(Player player) throws CommandException {
    WorldEditPlugin worldEdit = WorldGuardPlugin.inst().getWorldEdit();
    Selection selection = worldEdit.getSelection(player);

    if (selection == null) {
      throw new CommandException(
          "Сначала выделите территорию. "
              + "Используйте WorldEdit для выделения "
              + "(wiki: http://wiki.sk89q.com/wiki/WorldEdit).");
    }

    return selection;
  }
  // VERY Loosely based on work contributed by drew-bahrue
  // (https://github.com/echurchill/CityWorld/pull/2)
  public static PasteProvider loadWorldEdit(CityWorldGenerator generator) {
    //		return null;
    WorldEditPlugin worldEditPlugin = null;

    try {
      PluginManager pm = Bukkit.getServer().getPluginManager();
      if (pm != null) {
        Plugin plugin = pm.getPlugin(pluginName);
        if (plugin != null) worldEditPlugin = (WorldEditPlugin) plugin;
      }

      if (worldEditPlugin == null) {
        generator.reportMessage("[PasteProvider] Problem loading WorldEdit, could not find it");
        return null;
      }

      // got the right version?
      if (!isPlugInVersionOrBetter(generator, worldEditPlugin, pluginMinVersion))

        // Use it anyway?
        if (generator.settings.forceLoadWorldEdit) {
          generator.reportMessage(
              "'" + CityWorldSettings.tagForceLoadWorldEdit + "' setting enabled!");

          // Well that didn't work... let's tell the user about a potential workaround
        } else {
          generator.reportMessage(
              "[PasteProvider] Cannot use the installed WorldEdit. ",
              "See the '"
                  + CityWorldSettings.tagForceLoadWorldEdit
                  + "' setting for possible workaround.");
          return null;
        }

      // make sure it is enabled
      if (!pm.isPluginEnabled(worldEditPlugin)) pm.enablePlugin(worldEditPlugin);

      // woot!
      generator.reportMessage(
          "[PasteProvider] Found WorldEdit v"
              + worldEditPlugin.getDescription().getVersion()
              + ", enabling its schematics");

      return new PasteProvider_WorldEdit(generator);
    } catch (Exception e) {
      generator.reportMessage("[PasteProvider] Problem loading WorldEdit (" + e.getMessage() + ")");
      return null;
    }
  }
Exemple #7
0
  public void regionPrice(Player player, String[] args) {
    Selection sel = worldEdit.getSelection(player);

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

    ProtectedRegion region = null;
    String id = "icp__tempregion";

    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 {
      player.sendMessage(
          ChatColor.RED
              + "(shouldn't happen) Something went wrong. The type of region selected is unsupported!");
      return;
    }

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

    player.sendMessage(ChatColor.AQUA + "That region will cost you $" + cost + ".");
  }
  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");
  }
Exemple #9
0
  public CuboidSelection getSelection(Player player) {

    PluginManager pm = getServer().getPluginManager();

    if (!pm.isPluginEnabled("WorldEdit")) {
      player.sendMessage("This plugin requres the WorldEdit plugin");
      return null;
    }

    WorldEditPlugin worldEdit = (WorldEditPlugin) pm.getPlugin("WorldEdit");

    Selection selection = worldEdit.getSelection(player);

    // We only work with Cuboid selections
    if (!(selection instanceof CuboidSelection)) {
      return null;
    }

    return (CuboidSelection) selection;
  }
Exemple #10
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!
    }
  }
  /**
   * Called when a player attempts to use a command
   *
   * @param event Relevant event details
   */
  @EventHandler(priority = EventPriority.LOW, event = PlayerCommandPreprocessEvent.class)
  public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    if (event.isCancelled()) {
      return;
    }

    String[] split = event.getMessage().split(" ");

    if (split.length > 0) {
      split = plugin.getWorldEdit().commandDetection(split);
      split[0] = "/" + split[0];
    }

    event.setMessage(StringUtil.joinString(split, " "));
  }
  @EventHandler(event = PlayerChatEvent.class)
  public void onPlayerChat(PlayerChatEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Matcher matcher = cuipattern.matcher(event.getMessage());
    if (matcher.find()) {
      String type = matcher.group(1);
      String args = matcher.group(2);

      if (type.equals("v")) {
        try {
          plugin.getSession(event.getPlayer()).setCUIVersion(Integer.parseInt(args));
          event.setCancelled(true);
        } catch (NumberFormatException e) {
        }
      }
    }
  }
 @EventHandler(priority = EventPriority.LOWEST, event = PlayerJoinEvent.class)
 public void onPlayerJoin(PlayerJoinEvent event) {
   plugin.wrapPlayer(event.getPlayer()).dispatchCUIHandshake();
 }
 /**
  * Called when a player leaves a server
  *
  * @param event Relevant event details
  */
 @EventHandler(event = PlayerQuitEvent.class)
 public void onPlayerQuit(PlayerQuitEvent event) {
   plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer()));
 }
Exemple #15
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;
    }
  }
  @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)");
    }
  }
  /**
   * Called when a player interacts
   *
   * @param event Relevant event details
   */
  @EventHandler(event = PlayerInteractEvent.class)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.useItemInHand() == Result.DENY) {
      return;
    }

    final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
    final LocalWorld world = player.getWorld();
    final WorldEdit we = plugin.getWorldEdit();

    Action action = event.getAction();
    if (action == Action.LEFT_CLICK_BLOCK) {
      final Block clickedBlock = event.getClickedBlock();
      final WorldVector pos =
          new WorldVector(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());

      if (we.handleBlockLeftClick(player, pos)) {
        event.setCancelled(true);
      }

      if (we.handleArmSwing(player)) {
        event.setCancelled(true);
      }

      if (!ignoreLeftClickAir) {
        final int taskId =
            Bukkit.getScheduler()
                .scheduleSyncDelayedTask(
                    plugin,
                    new Runnable() {
                      public void run() {
                        ignoreLeftClickAir = false;
                      }
                    },
                    2);

        if (taskId != -1) {
          ignoreLeftClickAir = true;
        }
      }
    } else if (action == Action.LEFT_CLICK_AIR) {
      if (ignoreLeftClickAir) {
        return;
      }

      if (we.handleArmSwing(player)) {
        event.setCancelled(true);
      }

    } else if (action == Action.RIGHT_CLICK_BLOCK) {
      final Block clickedBlock = event.getClickedBlock();
      final WorldVector pos =
          new WorldVector(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());

      if (we.handleBlockRightClick(player, pos)) {
        event.setCancelled(true);
      }

      if (we.handleRightClick(player)) {
        event.setCancelled(true);
      }
    } else if (action == Action.RIGHT_CLICK_AIR) {
      if (we.handleRightClick(player)) {
        event.setCancelled(true);
      }
    }
  }