Skip to content

Commit

Permalink
- Add new resident mode: bedspawn
Browse files Browse the repository at this point in the history
    - This mode will make a player spawn at their bed instead of their
town spawn.
    - Mode is added and removed using /res toggle bedspawn.
    - When no bed is owned by a player they will spawn at their town, if
they have one.
    - Closes #7616.
  - New Command: /res toggle bedspawn
    - Turns on and off the respawn-to-bed option.
  • Loading branch information
LlmDl committed Sep 30, 2024
1 parent 15b5891 commit 7af103f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class ResidentCommand extends BaseCommand implements CommandExecutor {
"mobs",
"explosion",
"adminbypass",
"bedspawn",
"plotborder",
"constantplotborder",
"townborder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,22 @@ public void onPlayerQuit(PlayerQuitEvent event) {

@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerRespawn(PlayerRespawnEvent event) {
if (plugin.isError() || isEndPortalRespawn(event)) {
if (plugin.isError() || isEndPortalRespawn(event) || !TownySettings.isTownRespawning()) {
return;
}

Player player = event.getPlayer();

if (!TownySettings.isTownRespawning()) {
return;
}


// If respawn anchors have higher precedence than town spawns, use them instead.
if (event.isAnchorSpawn() && TownySettings.isRespawnAnchorHigherPrecedence()) {
return;
}

Location respawn;
respawn = TownyAPI.getInstance().getTownSpawnLocation(player);
Player player = event.getPlayer();
Location respawn = TownyAPI.getInstance().getTownSpawnLocation(player);
Resident resident = TownyAPI.getInstance().getResident(player);

// Towny might be prioritizing bed spawns over town spawns.
if (TownySettings.getBedUse()) {
// Towny or the Resident might be prioritizing bed spawns over town spawns.
if (TownySettings.getBedUse() ||
(resident != null && resident.hasMode("bedspawn"))) {
Location bed = BukkitTools.getBedOrRespawnLocation(player);
if (bed != null)
respawn = bed;
Expand All @@ -238,13 +234,8 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {

// Handle Spawn protection
long protectionTime = TownySettings.getSpawnProtectionDuration();
if (protectionTime > 0L) {
Resident res = TownyAPI.getInstance().getResident(player);
if (res == null)
return;

res.addRespawnProtection(protectionTime);
}
if (protectionTime > 0L && resident != null)
resident.addRespawnProtection(protectionTime);
}

private boolean isEndPortalRespawn(PlayerRespawnEvent event) {
Expand Down
9 changes: 8 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10026,4 +10026,11 @@ v0.92.0.11:
- Fix /plot group tab completion.
0.100.4.4:
- Add a message notifying a player of their pending town and nation invites.
- Closes #7607.
- Closes #7607.
- Add new resident mode: bedspawn
- This mode will make a player spawn at their bed instead of their town spawn.
- Mode is added and removed using /res toggle bedspawn.
- When no bed is owned by a player they will spawn at their town, if they have one.
- Closes #7616.
- New Command: /res toggle bedspawn
- Turns on and off the respawn-to-bed option.

0 comments on commit 7af103f

Please sign in to comment.