-
-
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 #5432 from TownyAdvanced/feature/spawn-set-events
Add events for when a town/nation spawn is set.
- Loading branch information
Showing
4 changed files
with
227 additions
and
10 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
99 changes: 99 additions & 0 deletions
99
src/com/palmergames/bukkit/towny/event/nation/NationSetSpawnEvent.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,99 @@ | ||
package com.palmergames.bukkit.towny.event.nation; | ||
|
||
import com.palmergames.bukkit.towny.object.Nation; | ||
import com.palmergames.bukkit.towny.object.Translation; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Fired when a player uses /nation set spawn | ||
*/ | ||
public class NationSetSpawnEvent extends Event implements Cancellable { | ||
private static final HandlerList handlers = new HandlerList(); | ||
|
||
private final Nation nation; | ||
private final Player player; | ||
private final Location oldSpawn; | ||
private Location newSpawn; | ||
|
||
private boolean cancelled = false; | ||
private String cancelMessage = Translation.of("msg_err_command_disable"); | ||
|
||
public NationSetSpawnEvent(Nation nation, Player player, Location newSpawn) { | ||
this.nation = nation; | ||
this.player = player; | ||
this.oldSpawn = nation.getSpawnOrNull(); | ||
this.newSpawn = newSpawn; | ||
} | ||
|
||
/** | ||
* @return The nation for which this spawn is being set. | ||
*/ | ||
@NotNull | ||
public Nation getNation() { | ||
return nation; | ||
} | ||
|
||
/** | ||
* @return The player that is changing the spawn. | ||
*/ | ||
@NotNull | ||
public Player getPlayer() { | ||
return player; | ||
} | ||
|
||
/** | ||
* @return The old spawn, or {@code null} if none has been set. | ||
*/ | ||
@Nullable | ||
public Location getOldSpawn() { | ||
return oldSpawn; | ||
} | ||
|
||
/** | ||
* @return The location where the spawn is being set to. | ||
*/ | ||
@NotNull | ||
public Location getNewSpawn() { | ||
return newSpawn; | ||
} | ||
|
||
/** | ||
* @param newSpawn Sets the location where the new spawn will be set to. | ||
*/ | ||
public void setNewSpawn(@NotNull Location newSpawn) { | ||
this.newSpawn = newSpawn; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancelled) { | ||
this.cancelled = cancelled; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return cancelled; | ||
} | ||
|
||
public void setCancelMessage(String cancelMessage) { | ||
this.cancelMessage = cancelMessage; | ||
} | ||
|
||
public String getCancelMessage() { | ||
return cancelMessage; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
} | ||
|
||
@Override | ||
public @NotNull HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/com/palmergames/bukkit/towny/event/town/TownSetSpawnEvent.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,96 @@ | ||
package com.palmergames.bukkit.towny.event.town; | ||
|
||
import com.palmergames.bukkit.towny.object.Town; | ||
import com.palmergames.bukkit.towny.object.Translation; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Fired when a player uses /town set spawn | ||
*/ | ||
public class TownSetSpawnEvent extends Event implements Cancellable { | ||
private static final HandlerList handlers = new HandlerList(); | ||
|
||
private final Town town; | ||
private final Player player; | ||
private final Location oldSpawn; | ||
private Location newSpawn; | ||
|
||
private boolean cancelled = false; | ||
private String cancelMessage = Translation.of("msg_err_command_disable"); | ||
|
||
public TownSetSpawnEvent(Town town, Player player, Location newSpawn) { | ||
this.town = town; | ||
this.player = player; | ||
this.oldSpawn = town.getSpawnOrNull(); | ||
this.newSpawn = newSpawn; | ||
} | ||
|
||
/** | ||
* @return The town for which this spawn is being set. | ||
*/ | ||
@NotNull | ||
public Town getTown() { | ||
return town; | ||
} | ||
|
||
/** | ||
* @return The player that ran the command | ||
*/ | ||
@NotNull | ||
public Player getPlayer() { | ||
return player; | ||
} | ||
|
||
/** | ||
* @return The town's old spawnpoint location. | ||
*/ | ||
@Nullable | ||
public Location getOldSpawn() { | ||
return oldSpawn; | ||
} | ||
|
||
/** | ||
* @return The new spawn location. | ||
*/ | ||
@NotNull | ||
public Location getNewSpawn() { | ||
return newSpawn; | ||
} | ||
|
||
public void setNewSpawn(@NotNull Location newSpawn) { | ||
this.newSpawn = newSpawn; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return cancelled; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancelled) { | ||
this.cancelled = cancelled; | ||
} | ||
|
||
public String getCancelMessage() { | ||
return cancelMessage; | ||
} | ||
|
||
public void setCancelMessage(String cancelMessage) { | ||
this.cancelMessage = cancelMessage; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
} | ||
|
||
@Override | ||
public @NotNull HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
} |