WorldGuard

WorldGuard

8M Downloads

Ability to rename a region

LadyCailinBot opened this issue · 9 comments

commented

WORLDGUARD-2862 - Reported by Tofwap

would allow operation

/region rename

Suggested as an alternative to the following method:
/region select
/region remove
/region define
<all flags/owners/members variables that need to be re-added>

commented

Comment by wizjany

I believe this has been discussed in the past, not sure what the conclusion was though.

commented

Comment by Tofwap

I used the search using tag "Rename" and did not find anything, So I submitted this. Only 27 results, so it was nothing too much to look through.

commented

Comment by wizjany

Oh if it was a duplicate I would have marked it as invalid. I just said there was a discussion about it already, not that we have a ticket for it.

commented

Comment by Богдан.Шкляренко

/region rename herobrine notch

commented

Comment by Tofwap

Set as a duplicate to another, then that one a duplicate of this one, so now it is invalid? I have to ask which one stayed around to keep this as an Idea. They both are marked as invalid now, because they are duplicates of each other or is there a 3rd older one that is not linked to these.

commented

Comment by Dark_Arc

What...?

commented

Comment by Dark_Arc

btw, if someone wants to tackle this

public static boolean renameRegion(RegionManager manager, String oldName, String newName, boolean cleanPersonal)
            throws ProtectionDatabaseException, ProtectedRegion.CircularInheritanceException {

        // Check for old conflicting regions
        ProtectedRegion oldRegion = manager.getRegion(oldName);
        ProtectedRegion newRegion = manager.getRegion(newName);

        if (oldRegion == null || newRegion != null) {
            return false;
        }

        // Recreate the region based on it's old values
        if (oldRegion instanceof ProtectedPolygonalRegion) {
            int minY = oldRegion.getMinimumPoint().getBlockY();
            int maxY = oldRegion.getMaximumPoint().getBlockY();
            newRegion = new ProtectedPolygonalRegion(newName, oldRegion.getPoints(), minY, maxY);
        } else if (oldRegion instanceof ProtectedCuboidRegion) {
            BlockVector min = oldRegion.getMinimumPoint();
            BlockVector max = oldRegion.getMaximumPoint();
            newRegion = new ProtectedCuboidRegion(newName, min, max);
        } else {
            return false;
        }

        // Assign the old values to the new region
        if (!cleanPersonal) {
            newRegion.setMembers(oldRegion.getMembers());
            newRegion.setOwners(oldRegion.getOwners());
            newRegion.setFlags(oldRegion.getFlags());
        }
        newRegion.setPriority(oldRegion.getPriority());
        newRegion.setParent(oldRegion.getParent());

        // Remove the old region and add the new region then proceed to attempt to save the regions
        // Save twice because databases can be funky
        manager.removeRegion(oldRegion.getId());
        manager.save();
        manager.addRegion(newRegion);
        manager.save();
        return true;
    }
commented

If this issue wasn't here, I would create it myself! Feature request which I also adore to see in WorldGuard! I hope someone will pick it up otherwise if someone can guide me how to implement this feature, I'm into this!

commented

The main reasons for not including this so far are:

  • There isn't a super good reason to include it
  • A rename function isn't trivial, it has to update all other references to the name, eg in child regions etc.
  • Many many many other plugins rely on the region name as an identifier. Unless those plugins somehow listened for renames, they would break.

Similar to how Mojang migrated to UUIDs for players before allowing renames to happen, something similar would have to happen for region identifiers to allow this. In saying that, I don't see it as likely to happen as it creates a significantly large amount of migratory work for very little benefit.