Solved WorldGuard API || Remove all player's regions

Discussion in 'Spigot Plugin Development' started by dexelOK, May 2, 2017.

Thread Status:
Not open for further replies.
  1. Hello, Spigot! I'm using Spigot 1.11.2, WorldEdit 6.1.5 and WorldGuard 6.2.

    I know player's name and I want to remove all player's regions (all regions he owns) in all worlds. I tried this code, but it doesn't work. I mean, plugin finds two worlds (world and world_the_end), finds regions in these worlds (e.g., sir in world), but it seems it can't get owners list and find there player's name.
    Code (Text):
    for (World w : Bukkit.getWorlds()) {
                    List<String> forRemove = new ArrayList<>();
                    for (String p : Main.wg.getRegionManager(w).getRegions().keySet()) {
                        if (Main.wg.getRegionManager(w).getRegion(p).getOwners().contains(s) || Main.wg.getRegionManager(w).getRegion(p).getOwners().contains(s.toLowerCase())) {
                            forRemove.add(p);
                        }
                    }
                    for (String p : forRemove) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "rg rem " + p + " -w " + w.getName());
                    }
                    forRemove.clear();
    }
    Help please :oops:
     
  2. Try using getRegionManager.deleteRegion(id)

    Or .removeRegion(id). Pretty sure it's deleteRegion


    Sent from my iPhone using Tapatalk
     
  3. I tried this, but it didn't work. I just can't find a player in region owner list.
     
  4. Code (Text):
    if (Main.wg.getRegionManager(w).getRegion(p).getOwners().getPlayers().contains(s)
                                || Main.wg.getRegionManager(w).getRegion(p).getOwners().getPlayers().contains(s.toLowerCase())
                                || Main.wg.getRegionManager(w).getRegion(p).getOwners().getPlayers().contains(s + "*")
                                || Main.wg.getRegionManager(w).getRegion(p).getOwners().getPlayers().contains(s.toLowerCase() + "*")) {
                            forRemove.add(p);
                        }
    This doesn't work. Plugin just can't find player.
     
  5. Theme is still unclosed.
     
  6. Why are you trying to remove an *? You should be passing just the player name / player object.

    Or add some debug code to this where you get the region then theowners and loop through that list printing out the player names found within


    Sent from my iPhone using Tapatalk
     
  7. The problem is solved. I just switched to player UniqueIDs. Thanks all, the theme is closed.
     
Thread Status:
Not open for further replies.