From 2aefc902df941e02b6b8a4915c19783e891c47f4 Mon Sep 17 00:00:00 2001 From: Warrior <50800980+Warriorrrr@users.noreply.github.com> Date: Sat, 14 Sep 2024 21:33:32 +0200 Subject: [PATCH] Re-assign permissions for previous mayor after switch --- .../com/palmergames/bukkit/towny/object/Nation.java | 10 +++++----- .../java/com/palmergames/bukkit/towny/object/Town.java | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/Nation.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/Nation.java index bf3d0c32e66..8be339e5ba3 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/Nation.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/Nation.java @@ -203,18 +203,18 @@ public void forceSetCapital(Town capital) throws EmptyNationException { } public void setCapital(Town capital) { + final Town oldCapital = this.capital; TownyMessaging.sendDebugMsg("Nation " + this.getName() + " has set a capital city of " + capital.getName()); this.capital = capital; if (this.spawn != null && TownySettings.isNationSpawnOnlyAllowedInCapital() && !capital.isInsideTown(this.spawn)) this.spawn = capital.spawnPosition(); + + if (oldCapital != null && oldCapital.getMayor() != null) + TownyPerms.assignPermissions(oldCapital.getMayor(), null); - try { - TownyPerms.assignPermissions(capital.getMayor(), null); - } catch (Exception e) { - // Dummy catch to prevent errors on startup when setting nation. - } + TownyPerms.assignPermissions(capital.getMayor(), null); // Save the capital city. A town that becomes a capital might have its // peaceful/neutral status overridden and require saving. diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/Town.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/Town.java index 026501ec8e2..6a197484128 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/Town.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/Town.java @@ -239,12 +239,17 @@ public void setMayor(Resident mayor) { public void setMayor(Resident mayor, boolean callEvent) { if (!hasResident(mayor)) return; + + final Resident oldMayor = this.mayor; if (callEvent) BukkitTools.fireEvent(new TownMayorChangedEvent(this.mayor, mayor)); this.mayor = mayor; + if (oldMayor != null) + TownyPerms.assignPermissions(oldMayor, null); + TownyPerms.assignPermissions(mayor, null); }