Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to limit setting spawn points lower than a configurable Y level. #7393

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,16 @@ public enum ConfigNodes {
"",
"# Number of seconds that must pass before a player who is not a member or ally can use /n spawn."),

SPAWNING_Y_LIMITS_ROOT("spawning.y_limits","",""),
SPAWNING_Y_LIMITS_ENABLED("spawning.y_limits.enabled",
"false",
"",
"# Should towns, nations be limited in how low they can set a spawn point, or an outpost spawn point?"),
SPAWNING_Y_LIMITS_LOWEST_Y_ALLOWED("spawning.y_limits.lowest_y_allowed",
"0",
"",
"# When limiting is configured, what is the lowest y level allowed?"),

SPAWNING_RESPAWN_ROOT("spawning.respawning","",""),
SPAWNING_TOWN_RESPAWN(
"spawning.respawning.town_respawn",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3780,5 +3780,13 @@ public static String getDefaultResidentAbout() {
public static double maxBuyTownPrice() {
return getDouble(ConfigNodes.GTOWN_SETTINGS_MAX_BUYTOWN_PRICE);
}

public static boolean isSpawnYLevelLimitingEnabled() {
return getBoolean(ConfigNodes.SPAWNING_Y_LIMITS_ENABLED);
}

public static double getSpawningLowestYLevelAllowed() {
return getDouble(ConfigNodes.SPAWNING_Y_LIMITS_LOWEST_Y_ALLOWED);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
import com.palmergames.bukkit.towny.event.TownRemoveResidentEvent;
import com.palmergames.bukkit.towny.event.damage.TownyPlayerDamagePlayerEvent;
import com.palmergames.bukkit.towny.event.nation.NationPreTownLeaveEvent;
import com.palmergames.bukkit.towny.event.nation.NationSetSpawnEvent;
import com.palmergames.bukkit.towny.event.town.TownPreUnclaimCmdEvent;
import com.palmergames.bukkit.towny.event.town.TownSetOutpostSpawnEvent;
import com.palmergames.bukkit.towny.event.town.TownSetSpawnEvent;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.CellSurface;
import com.palmergames.bukkit.towny.object.PlayerCache;
Expand Down Expand Up @@ -322,4 +325,31 @@ private void attemptPlayerCacheReset(Player player, WorldCoord worldCoord) {
return;
Towny.getPlugin().resetCache(player);
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTownSetSpawn(TownSetSpawnEvent event) {
if (!TownySettings.isSpawnYLevelLimitingEnabled()
|| event.getNewSpawn().getY() >= TownySettings.getSpawningLowestYLevelAllowed())
return;
event.setCancelMessage(Translatable.of("msg_err_you_cannot_set_this_spawn_point_below", TownySettings.getSpawningLowestYLevelAllowed()).forLocale(event.getPlayer()));
event.setCancelled(true);
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTownSetOutpostSpawn(TownSetOutpostSpawnEvent event) {
if (!TownySettings.isSpawnYLevelLimitingEnabled()
|| event.getNewSpawn().getY() >= TownySettings.getSpawningLowestYLevelAllowed())
return;
event.setCancelMessage(Translatable.of("msg_err_you_cannot_set_this_spawn_point_below", TownySettings.getSpawningLowestYLevelAllowed()).forLocale(event.getPlayer()));
event.setCancelled(true);
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onNationSetSpawn(NationSetSpawnEvent event) {
if (!TownySettings.isSpawnYLevelLimitingEnabled()
|| event.getNewSpawn().getY() >= TownySettings.getSpawningLowestYLevelAllowed())
return;
event.setCancelMessage(Translatable.of("msg_err_you_cannot_set_this_spawn_point_below", TownySettings.getSpawningLowestYLevelAllowed()).forLocale(event.getPlayer()));
event.setCancelled(true);
}
}
4 changes: 3 additions & 1 deletion Towny/src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2524,4 +2524,6 @@ msg_recieved_refund_for_deleted_object: "You have received the bank balance of y

msg_err_you_already_own_this_plot: "You already own this plot."

msg_err_you_cannot_delete_this_nation: "You have been prevented from deleting this nation."
msg_err_you_cannot_delete_this_nation: "You have been prevented from deleting this nation."

msg_err_you_cannot_set_this_spawn_point_below: "You cannot set this spawn point below y level %s."
Loading