Skip to content

Commit

Permalink
Avoid recalculating entire permission set after every portal removal in
Browse files Browse the repository at this point in the history
a batch.
  • Loading branch information
Joshua Rogers committed Apr 14, 2014
1 parent 229ebf2 commit 00ef9fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Expand Up @@ -167,10 +167,6 @@ private void addToUpperLists() {
allPortalFill.getChildren().put(this.fillPermission.getName(), true); allPortalFill.getChildren().put(this.fillPermission.getName(), true);


this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(all); this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(all);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allPortals);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allPortalAccess);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allPortalExempt);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allPortalFill);
for(Player player : this.plugin.getServer().getOnlinePlayers()){ for(Player player : this.plugin.getServer().getOnlinePlayers()){
player.recalculatePermissions(); player.recalculatePermissions();
} }
Expand Down
Expand Up @@ -136,6 +136,10 @@ private void addUniquePortal(MultiverseWorld world, String name, MVPortal portal
} }


public MVPortal removePortal(String portalName, boolean removeFromConfigs) { public MVPortal removePortal(String portalName, boolean removeFromConfigs) {
return removePortal(portalName, removeFromConfigs, false);
}

private MVPortal removePortal(String portalName, boolean removeFromConfigs, boolean delayRecalculation) {
if (!isPortal(portalName)) { if (!isPortal(portalName)) {
return null; return null;
} }
Expand All @@ -155,16 +159,18 @@ public MVPortal removePortal(String portalName, boolean removeFromConfigs) {
Permission portalFill = this.plugin.getServer().getPluginManager().getPermission("multiverse.portal.fill.*"); Permission portalFill = this.plugin.getServer().getPluginManager().getPermission("multiverse.portal.fill.*");
if (exemptAccess != null) { if (exemptAccess != null) {
exemptAccess.getChildren().remove(removed.getExempt().getName()); exemptAccess.getChildren().remove(removed.getExempt().getName());
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(exemptAccess);
} }
if (portalAccess != null) { if (portalAccess != null) {
portalAccess.getChildren().remove(removed.getPermission().getName()); portalAccess.getChildren().remove(removed.getPermission().getName());
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(portalAccess);
} }
if (portalFill != null) { if (portalFill != null) {
portalFill.getChildren().remove(removed.getFillPermission().getName()); portalFill.getChildren().remove(removed.getFillPermission().getName());
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(portalFill);
} }

if (!delayRecalculation) {
recalculatePermissions();
}

if (MultiversePortals.ClearOnRemove) { if (MultiversePortals.ClearOnRemove) {
// Replace portal blocks in the portal with air. This keeps us from // Replace portal blocks in the portal with air. This keeps us from
// leaving behind portal blocks (which would take an unsuspecting // leaving behind portal blocks (which would take an unsuspecting
Expand All @@ -179,6 +185,14 @@ public MVPortal removePortal(String portalName, boolean removeFromConfigs) {
return removed; return removed;
} }


private void recalculatePermissions() {
String[] permissionsNames = new String[] { "multiverse.portal.access.*", "multiverse.portal.exempt.*", "multiverse.portal.fill.*" };
for (String permissionName : permissionsNames) {
Permission permission = this.plugin.getServer().getPluginManager().getPermission(permissionName);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(permission);
}
}

public List<MVPortal> getAllPortals() { public List<MVPortal> getAllPortals() {
return new ArrayList<MVPortal>(this.portals.values()); return new ArrayList<MVPortal>(this.portals.values());
} }
Expand Down Expand Up @@ -259,8 +273,9 @@ public boolean isPortal(String portalName) {
public void removeAll(boolean removeFromConfigs) { public void removeAll(boolean removeFromConfigs) {
List<String> iterList = new ArrayList<String>(this.portals.keySet()); List<String> iterList = new ArrayList<String>(this.portals.keySet());
for (String s : iterList) { for (String s : iterList) {
this.removePortal(s, removeFromConfigs); this.removePortal(s, removeFromConfigs, true);
} }
recalculatePermissions();
} }


private void replaceInRegion(World world, MultiverseRegion removedRegion, Material oldMaterial, Material newMaterial) { private void replaceInRegion(World world, MultiverseRegion removedRegion, Material oldMaterial, Material newMaterial) {
Expand Down

0 comments on commit 00ef9fc

Please sign in to comment.