Skip to content

Commit 53c9cbe

Browse files
committed
More configuration option for respawning
1 parent b68e8a2 commit 53c9cbe

File tree

4 files changed

+64
-22
lines changed

4 files changed

+64
-22
lines changed

src/main/java/org/mvplugins/multiverse/core/api/MVConfig.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,17 @@ public interface MVConfig {
166166
* Sets defaultRespawnToWorldSpawn.
167167
* @param defaultRespawnToWorldSpawn The new value
168168
*/
169-
void setDefaultRespawnToWorldSpawn(boolean defaultRespawnToWorldSpawn);
169+
void setDefaultRespawnWithinSameWorld(boolean defaultRespawnToWorldSpawn);
170170

171171
/**
172172
* Gets defaultRespawnToWorldSpawn
173173
* @return defaultRespawnToWorldSpawn
174174
*/
175-
boolean getDefaultRespawnToWorldSpawn();
175+
boolean getDefaultRespawnWithinSameWorld();
176+
177+
void setEnforceRespawnAtWorldSpawn(boolean enforceRespawnAtWorldSpawn);
178+
179+
boolean getEnforceRespawnAtWorldSpawn();
176180

177181
/**
178182
* Sets whether or not to let Bukkit determine portal search radius on its own or if Multiverse should give input.

src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfig.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public class MVCoreConfig implements MVConfig {
7878
.addAction(MoveMigratorAction.of("world.teleport-intercept", "teleport.teleport-intercept"))
7979
.addAction(MoveMigratorAction.of("world.resolve-alias-name", "command.resolve-alias-name"))
8080
.build())
81+
.addVersionMigrator(VersionMigrator.builder(5.2)
82+
.addAction(MoveMigratorAction.of("spawn.default-respawn-to-world-spawn", "world.enforce-respawn-at-world-spawn"))
83+
.build())
8184
.build())
8285
.build();
8386
this.stringPropertyHandle = new StringPropertyHandle(configHandle);
@@ -245,13 +248,23 @@ public String getJoinDestination() {
245248
}
246249

247250
@Override
248-
public void setDefaultRespawnToWorldSpawn(boolean defaultRespawnToWorldSpawn) {
249-
configHandle.set(configNodes.DEFAULT_RESPAWN_TO_WORLD_SPAWN, defaultRespawnToWorldSpawn);
251+
public void setDefaultRespawnWithinSameWorld(boolean defaultRespawnToWorldSpawn) {
252+
configHandle.set(configNodes.DEFAULT_RESPAWN_WITHIN_SAME_WORLD, defaultRespawnToWorldSpawn);
253+
}
254+
255+
@Override
256+
public boolean getDefaultRespawnWithinSameWorld() {
257+
return configHandle.get(configNodes.DEFAULT_RESPAWN_WITHIN_SAME_WORLD);
258+
}
259+
260+
@Override
261+
public void setEnforceRespawnAtWorldSpawn(boolean enforceRespawnAtWorldSpawn) {
262+
configHandle.set(configNodes.ENFORCE_RESPAWN_AT_WORLD_SPAWN, enforceRespawnAtWorldSpawn);
250263
}
251264

252265
@Override
253-
public boolean getDefaultRespawnToWorldSpawn() {
254-
return configHandle.get(configNodes.DEFAULT_RESPAWN_TO_WORLD_SPAWN);
266+
public boolean getEnforceRespawnAtWorldSpawn() {
267+
return configHandle.get(configNodes.ENFORCE_RESPAWN_AT_WORLD_SPAWN);
255268
}
256269

257270
@Override

src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfigNodes.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,34 @@ private <N extends Node> N node(N node) {
185185
.name("join-destination")
186186
.build());
187187

188-
final ConfigNode<Boolean> DEFAULT_RESPAWN_TO_WORLD_SPAWN = node(ConfigNode.builder("spawn.default-respawn-to-world-spawn", Boolean.class)
188+
final ConfigNode<Boolean> DEFAULT_RESPAWN_WITHIN_SAME_WORLD = node(ConfigNode.builder("spawn.default-respawn-within-same-world", Boolean.class)
189+
.comment("")
190+
.comment("This only applies if the `respawn-world` property is not set for the world that the player died in,")
191+
.comment("and the player does not have bed or anchor set.")
192+
.comment("----")
193+
.comment("When this option is enabled, players will respawn in the same world's that they died in.")
194+
.comment("If the /spawnpoint is already within that world and `enforce-respawn-at-world-spawn` is disabled,")
195+
.comment("Multiverse will use that spawn location, else it will use the world's spawn where the player died in.")
196+
.comment("----")
197+
.comment("You can set `respawn-world` property with the command: `/mv modify <worldname> set respawn-world <worldname>`")
198+
.comment("You can reset `respawn-world` property with the command: `/mv modify <worldname> reset respawn-world`")
199+
.comment("----")
200+
.comment("Set this to false if you want another plugin to handle respawning.")
201+
.defaultValue(true)
202+
.name("default-respawn-within-same-world")
203+
.build());
204+
205+
final ConfigNode<Boolean> ENFORCE_RESPAWN_AT_WORLD_SPAWN = node(ConfigNode.builder("spawn.enforce-respawn-at-world-spawn", Boolean.class)
189206
.comment("")
190-
.comment("By default when `respawn-world` is not set, players will respawn at the world's spawn location that they died in.")
191-
.comment("If you want another plugin to handle respawn, or use vanilla /spawnpoint, set this to false.")
192-
.comment("This only applies if the `respawn-world` property is not set for the world that the player died in.")
193-
.comment("You can set `respawn-world` property by running the command: `/mv modify <worldname> set respawn-world <worldname>`")
207+
.comment("This config will only apply if `respawn-world` is set, or `default-respawn-within-same-world` is enabled.")
208+
.comment("----")
209+
.comment("When this option is enabled, players will always respawn at the world's spawn location of `respawn-world`,")
210+
.comment("unless bed or anchor is set and `bed-respawn` or `anchor-spawn` is enabled respectively.")
211+
.comment("If respawn-world is set, Multiverse will use that world's spawn location, else it will use the world's spawn where the player died in.")
212+
.comment("----")
213+
.comment("Set this to false if you want to use the /spawnpoint instead of the world's spawn location.")
194214
.defaultValue(true)
195-
.name("default-respawn-to-world-spawn")
215+
.name("enforce-respawn-at-world-spawn")
196216
.build());
197217

198218
private final ConfigHeaderNode PORTAL_HEADER = node(ConfigHeaderNode.builder("portal")

src/main/java/org/mvplugins/multiverse/core/listeners/MVPlayerListener.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import io.vavr.control.Option;
1515
import jakarta.inject.Inject;
1616
import jakarta.inject.Provider;
17-
import org.bukkit.Bukkit;
1817
import org.bukkit.Location;
1918
import org.bukkit.Material;
2019
import org.bukkit.Server;
@@ -132,31 +131,37 @@ public void playerRespawn(PlayerRespawnEvent event) {
132131
Logging.fine("Spawning %s at their anchor.", player.getName());
133132
return false;
134133
}
135-
if (!config.getDefaultRespawnToWorldSpawn() && mvWorld.getRespawnWorldName().isBlank()) {
134+
if (!config.getDefaultRespawnWithinSameWorld() && mvWorld.getRespawnWorldName().isEmpty()) {
136135
Logging.fine("Not overriding respawn location for player '%s' as " +
137-
"default-respawn-to-world-spawn is disabled and no respawn-world is set.", player.getName());
136+
"default-respawn-within-same-world is disabled and no respawn-world is set.", player.getName());
138137
return false;
139138
}
140139
return true;
141140
})
142-
.flatMap(mvWorld -> getMostAccurateRespawnLocation (player, mvWorld))
141+
.flatMap(mvWorld -> getMostAccurateRespawnLocation(player, mvWorld, event.getRespawnLocation()))
143142
.peek(newRespawnLocation -> {
144143
MVRespawnEvent respawnEvent = new MVRespawnEvent(newRespawnLocation, event.getPlayer(), "compatability");
145144
this.server.getPluginManager().callEvent(respawnEvent);
146145
event.setRespawnLocation(respawnEvent.getPlayersRespawnLocation());
147146
});
148147
}
149148

150-
private Option<Location> getMostAccurateRespawnLocation(Player player, LoadedMultiverseWorld mvWorld) {
151-
return Option.of(mvWorld.getRespawnWorldName().isBlank()
149+
private Option<Location> getMostAccurateRespawnLocation(Player player, LoadedMultiverseWorld mvWorld, Location defaultRespawnLocation) {
150+
return Option.of(mvWorld.getRespawnWorldName().isEmpty()
152151
? player.getWorld()
153152
: server.getWorld(mvWorld.getRespawnWorldName()))
154153
.onEmpty(() -> Logging.warning("World '%s' has respawn-world property of '%s' that does not exist!",
155154
player.getWorld().getName(), mvWorld.getRespawnWorldName()))
156-
.map(newRespawnWorld -> getWorldManager()
157-
.getLoadedWorld(newRespawnWorld)
158-
.map(newMVRespawnWorld -> (Location) newMVRespawnWorld.getSpawnLocation())
159-
.getOrElse(newRespawnWorld::getSpawnLocation));
155+
.map(newRespawnWorld -> {
156+
if (!config.getEnforceRespawnAtWorldSpawn() && newRespawnWorld.equals(defaultRespawnLocation.getWorld())) {
157+
Logging.fine("Respawn location is within same world as respawn-world, not overriding.");
158+
return defaultRespawnLocation;
159+
}
160+
return getWorldManager()
161+
.getLoadedWorld(newRespawnWorld)
162+
.map(newMVRespawnWorld -> (Location) newMVRespawnWorld.getSpawnLocation())
163+
.getOrElse(newRespawnWorld::getSpawnLocation);
164+
});
160165
}
161166

162167
@EventHandler

0 commit comments

Comments
 (0)