Add world property toggle allow anchor spawn

This commit is contained in:
Ben Woo 2025-01-16 11:00:44 +08:00
parent 9be7c75dcc
commit c49653ebc8
4 changed files with 51 additions and 12 deletions

View File

@ -126,8 +126,13 @@ public class MVPlayerListener implements CoreListener {
return;
}
if (mvWorld.getBedRespawn() && (event.isBedSpawn() || event.isAnchorSpawn())) {
Logging.fine("Spawning %s at their %s.", event.getPlayer().getName(), event.isBedSpawn() ? "BED" : "ANCHOR");
if (mvWorld.getBedRespawn() && event.isBedSpawn()) {
Logging.fine("Spawning %s at their bed.", event.getPlayer().getName());
return;
}
if (mvWorld.getAnchorSpawn() && event.isAnchorSpawn()) {
Logging.fine("Spawning %s at their anchor.", event.getPlayer().getName());
return;
}

View File

@ -147,6 +147,29 @@ public class MultiverseWorld {
return worldConfig.setAllowWeather(allowWeather);
}
/**
* Gets whether or not a player who dies in this world will respawn in their
* anchor or follow the normal respawn pattern.
*
* @return True if players dying in this world should respawn at their anchor.
*/
public boolean getAnchorSpawn() {
return worldConfig.getAnchorSpawn();
}
/**
* Sets whether or not a player who dies in this world will respawn in their
* anchor or follow the normal respawn pattern.
* <br/>
* True is default.
*
* @param anchorSpawn True if players dying in this world respawn at their anchor.
* @return Result of setting property.
*/
public Try<Void> setAnchorSpawn(boolean anchorSpawn) {
return worldConfig.setAnchorSpawn(anchorSpawn);
}
/**
* Gets whether or not a world will auto-heal players if the difficulty is on peaceful.
*
@ -197,16 +220,6 @@ public class MultiverseWorld {
return worldConfig.getBedRespawn();
}
/**
* Gets the single biome used for this world. This may be null, in which case the biome from the generator will be used.
* If no generator is specified, the "natural" biome behaviour for this environment will be used.
*
* @return The biome used for this world
*/
public @Nullable Biome getBiome() {
return worldConfig.getBiome();
}
/**
* Sets whether or not a player who dies in this world will respawn in their
* bed or follow the normal respawn pattern.
@ -220,6 +233,16 @@ public class MultiverseWorld {
return worldConfig.setBedRespawn(bedRespawn);
}
/**
* Gets the single biome used for this world. This may be null, in which case the biome from the generator will be used.
* If no generator is specified, the "natural" biome behaviour for this environment will be used.
*
* @return The biome used for this world
*/
public @Nullable Biome getBiome() {
return worldConfig.getBiome();
}
/**
* Gets the type of currency that will be used when users enter this world. A value of null indicates a non-item
* based currency is used.

View File

@ -149,6 +149,13 @@ public final class WorldConfig {
public Try<Void> setAllowWeather(boolean allowWeather) {
return configHandle.set(configNodes.ALLOW_WEATHER, allowWeather);
}
public boolean getAnchorSpawn() {
return configHandle.get(configNodes.ANCHOR_RESPAWN);
}
public Try<Void> setAnchorSpawn(boolean anchorSpawn) {
return configHandle.set(configNodes.ANCHOR_RESPAWN, anchorSpawn);
}
public boolean getAutoHeal() {
return configHandle.get(configNodes.AUTO_HEAL);

View File

@ -90,6 +90,10 @@ public class WorldConfigNodes {
})
.build());
final ConfigNode<Boolean> ANCHOR_RESPAWN = node(ConfigNode.builder("anchor-respawn", Boolean.class)
.defaultValue(true)
.build());
final ConfigNode<Boolean> AUTO_HEAL = node(ConfigNode.builder("auto-heal", Boolean.class)
.defaultValue(true)
.build());