-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6608 from TownyAdvanced/api/mayoral_succession_event
API: Add town-changing mayor events.
- Loading branch information
Showing
5 changed files
with
176 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/com/palmergames/bukkit/towny/event/town/TownMayorChangedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.palmergames.bukkit.towny.event.town; | ||
|
||
import com.palmergames.bukkit.towny.TownyAPI; | ||
import com.palmergames.bukkit.towny.object.Resident; | ||
import com.palmergames.bukkit.towny.object.Town; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Event that gets fired when a town's mayor has changed. | ||
*/ | ||
public class TownMayorChangedEvent extends Event { | ||
private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
||
private final Resident oldMayor; | ||
private final Resident newMayor; | ||
|
||
public TownMayorChangedEvent(Resident oldMayor, Resident newMayor) { | ||
super(!Bukkit.getServer().isPrimaryThread()); | ||
this.oldMayor = oldMayor; | ||
this.newMayor = newMayor; | ||
} | ||
|
||
public Resident getOldMayor() { | ||
return oldMayor; | ||
} | ||
|
||
public Resident getNewMayor() { | ||
return newMayor; | ||
} | ||
|
||
public Town getTown() { | ||
return TownyAPI.getInstance().getResidentTownOrNull(newMayor); | ||
} | ||
|
||
public boolean isNationCapital() { | ||
return getTown().isCapital(); | ||
} | ||
|
||
public boolean isKingChange() { | ||
return oldMayor.isKing(); | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return HANDLER_LIST; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public HandlerList getHandlers() { | ||
return HANDLER_LIST; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/com/palmergames/bukkit/towny/event/town/TownMayorChosenBySuccessionEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.palmergames.bukkit.towny.event.town; | ||
|
||
import com.palmergames.bukkit.towny.TownyAPI; | ||
import com.palmergames.bukkit.towny.object.Resident; | ||
import com.palmergames.bukkit.towny.object.Town; | ||
|
||
import java.util.List; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Event that gets fired when a town has had their mayor removed by Towny, | ||
* resulting in Towny choosing a Town resident to become mayor. | ||
* | ||
* Towny has chosen the newMayor out of the potentialResidents, but you can | ||
* override who will become the new mayor using this event. | ||
*/ | ||
public class TownMayorChosenBySuccessionEvent extends Event { | ||
private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
||
private final Resident oldMayor; | ||
private Resident newMayor; | ||
private List<Resident> potentialResidents; | ||
|
||
public TownMayorChosenBySuccessionEvent(Resident oldMayor, Resident newMayor, List<Resident> potentialResidents) { | ||
super(!Bukkit.getServer().isPrimaryThread()); | ||
this.oldMayor = oldMayor; | ||
this.newMayor = newMayor; | ||
for (Resident resident : potentialResidents) { | ||
if (resident != oldMayor) | ||
this.potentialResidents.add(resident); | ||
} | ||
|
||
} | ||
|
||
public Resident getOldMayor() { | ||
return oldMayor; | ||
} | ||
|
||
public Resident getNewMayor() { | ||
return newMayor; | ||
} | ||
|
||
public void setNewMayor(Resident replacementMayor) { | ||
newMayor = replacementMayor; | ||
} | ||
|
||
public Town getTown() { | ||
return TownyAPI.getInstance().getResidentTownOrNull(newMayor); | ||
} | ||
|
||
@Nullable | ||
public List<Resident> getPotentialMayors() { | ||
return potentialResidents; | ||
} | ||
|
||
public boolean isNationCapital() { | ||
return getTown().isCapital(); | ||
} | ||
|
||
public boolean isKingChange() { | ||
return oldMayor.isKing(); | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return HANDLER_LIST; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public HandlerList getHandlers() { | ||
return HANDLER_LIST; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters