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; }
@Override public boolean execute(CommandSender executor, String identifier, String[] args) { if (!(executor instanceof Player)) { Messaging.send(executor, "Can not create sub regions through console!"); return false; } String redefineRegion = args[0]; Player player = (Player) executor; Citizen citizen = getCitizen(player); // Get and validate the region ID String id = validateRegionId(redefineRegion, false); // Can't replace regions with this command RegionManager regionManager = wgp.getGlobalRegionManager().get(player.getWorld()); if (!regionManager.hasRegion(id)) { Messaging.send( executor, "That region doesn't exist, use " + "/town region create <childRegion> <parentRegion>" + id); return true; } ChildRegion foundRegion = null; if (manager.get(redefineRegion) != null && manager.get(redefineRegion).getName().equalsIgnoreCase(redefineRegion)) { Messaging.send(executor, "You can not redefine your Town region!"); return true; } else { ChildRegion temp = plugin.getWorldGuardManager().getChildRegion(regionManager.getRegion(redefineRegion)); if (temp != null && temp.getParent() instanceof Town) foundRegion = temp; } Town town = citizen.getTown(); if (foundRegion != null && foundRegion.getParent() instanceof Town) { // Means we found a child region belonging to a Town if (!foundRegion.getParent().equals(town)) { town = (Town) foundRegion.getParent(); } } else { Messaging.send(executor, "The region you want to redefine isn't part of a Town!"); return true; } if (!manager.getRegionManager().checkOwner(player, foundRegion)) { Messaging.send( executor, "You aren't a Region Owner! only Region Owners or Town Mayors can redefine regions!"); return true; } ChildRegion newRegion = manager.getRegionManager().redefineChildRegion(getSelection(player), foundRegion, town); // Delete old region manager.getRegionManager().addChildRegion(town, newRegion); plugin.getStorageManager().getStorage().saveCitizenGroup(town, false); plugin.getStorageManager().getStorage().saveManagerData(manager); Messaging.send(executor, "You have successfully redefined the region: " + id); return true; }
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()); } } }
protected static boolean existArea(String area, World w) { RegionManager rg = RegionTeleport.getWorldGuard().getRegionManager(w); if (rg.getRegion(area) != null) { return true; } else { return false; } }
public static void giveStall(Player player, String zone, String number) { WorldGuardPlugin worldGuard = getWorldGuard(); World world = player.getWorld(); RegionManager regionManager = worldGuard.getRegionManager(world); ProtectedRegion region = regionManager.getRegion("stall_" + zone.toLowerCase() + number); DefaultDomain owners = region.getOwners(); owners.addPlayer(player.getName()); region.setOwners(owners); editPlotSign(player, zone, number, region); }
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; }
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]); } }
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]); } }
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()); } }
protected static void claim(String regionname, CommandSender sender) throws CommandException { Player player = WGExtender.getInstance().getWorldGuard().checkPlayer(sender); LocalPlayer localPlayer = WGExtender.getInstance().getWorldGuard().wrapPlayer(player); RegionPermissionModel permModel = getPermissionModel(sender); if (!permModel.mayClaim()) { throw new CommandPermissionsException(); } String id = checkRegionId(regionname, false); RegionManager manager = checkRegionManager(WGExtender.getInstance().getWorldGuard(), player.getWorld()); checkRegionDoesNotExist(manager, id, false); ProtectedRegion region = checkRegionFromSelection(player, id); WorldConfiguration wcfg = WGExtender.getInstance().getWorldGuard().getGlobalStateManager().get(player.getWorld()); if (!permModel.mayClaimRegionsUnbounded()) { int maxRegionCount = wcfg.getMaxRegionCount(player); if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(localPlayer) >= maxRegionCount) { throw new CommandException( "У вас слишком много регионов, удалите один из них перед тем как заприватить новый."); } } ProtectedRegion existing = manager.getRegion(id); if (existing != null) { if (!existing.getOwners().contains(localPlayer)) { throw new CommandException("Регион уже существует, и вы им не владеете."); } } ApplicableRegionSet regions = manager.getApplicableRegions(region); if (regions.size() > 0) { if (!regions.isOwnerOfAll(localPlayer)) { throw new CommandException("Это регион перекрывает чужой регион."); } } else { if (wcfg.claimOnlyInsideExistingRegions) { throw new CommandException("Вы можете приватить только внутри своих регионов."); } } if (wcfg.maxClaimVolume >= Integer.MAX_VALUE) { throw new CommandException( "The maximum claim volume get in the configuration is higher than is supported. " + "Currently, it must be " + Integer.MAX_VALUE + " or smaller. Please contact a server administrator."); } if (!permModel.mayClaimRegionsUnbounded()) { if (region instanceof ProtectedPolygonalRegion) { throw new CommandException("Полигональные регионы не поддерживаются."); } if (region.volume() > wcfg.maxClaimVolume) { player.sendMessage(ChatColor.RED + "Размер региона слишком большой."); player.sendMessage( ChatColor.RED + "Максимальный размер: " + wcfg.maxClaimVolume + ", ваш размер: " + region.volume()); return; } } RegionAdder task = new RegionAdder(WGExtender.getInstance().getWorldGuard(), manager, region); task.setLocatorPolicy(UserLocatorPolicy.UUID_ONLY); task.setOwnersInput(new String[] {player.getName()}); try { task.call(); sender.sendMessage(ChatColor.YELLOW + "Вы заприватили регион " + id); } catch (Exception e) { sender.sendMessage(ChatColor.YELLOW + "Произошла ошибка при привате региона " + id); e.printStackTrace(); } }