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 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); }
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"); }
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; }
/** * 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! } }
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"); }
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; }
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)"); } }