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 a new permission flag to toggle snowfall, like you would for firespread #7690

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
14 changes: 14 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 @@ -331,6 +331,19 @@ public enum ConfigNodes {
"# Do new worlds have force_fire_on enabled by default?",
"# This setting overrides a towns' setting.",
"# You can adjust this setting for an existing world using /townyworld toggle forcefire"),
NWS_WORLD_SNOW_HEADER("new_world_settings.snow", "", ""),
NWS_WORLD_SNOW(
"new_world_settings.snow.world_snowfall_enabled",
"true",
"# Do new worlds allow snow to fall in towns by default?",
"# You can adjust this setting for an existing world using /townyworld toggle snow"),
NWS_FORCE_SNOW_ON(
"new_world_settings.snow.force_snow_on",
"false",
"",
"# Do new worlds have force_snow_on enabled by default?",
"# This setting overrides a towns' setting.",
"# You can adjust this setting for an existing world using /townyworld toggle forcesnow"),
NWS_WORLD_ENDERMAN(
"new_world_settings.enderman_protect",
"true",
Expand Down Expand Up @@ -2240,6 +2253,7 @@ public enum ConfigNodes {
"default_perm_flags.town.default.explosion",
"false"),
FLAGS_TOWN_DEF_MOBS("default_perm_flags.town.default.mobs", "false"),
FLAGS_TOWN_DEF_SNOW("default_perm_flags.town.default.snow", "true"), // TODO: fruit add node to config
LlmDl marked this conversation as resolved.
Show resolved Hide resolved

FLAGS_TOWN_RES_BUILD("default_perm_flags.town.resident.build", "true"),
FLAGS_TOWN_RES_DESTROY("default_perm_flags.town.resident.destroy", "true"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static StatusScreen getStatus(TownBlock townBlock, Player player) {
screen.addComponentOf("explosion", colourKeyValue(translator.of("explosions"), ((world.isForceExpl() || townBlock.getPermissions().explosion) ? translator.of("status_on"): translator.of("status_off"))));
screen.addComponentOf("firespread", colourKeyValue(translator.of("firespread"), ((world.isForceFire() || townBlock.getPermissions().fire) ? translator.of("status_on"):translator.of("status_off"))));
screen.addComponentOf("mobspawns", colourKeyValue(translator.of("mobspawns"), ((world.isForceTownMobs() || townBlock.getPermissions().mobs || town.isAdminEnabledMobs()) ? translator.of("status_on"): translator.of("status_off"))));
screen.addComponentOf("snowfall", colourKeyValue(translator.of("snowfall"), ((world.isForceSnow() || townBlock.getPermissions().snow) ? translator.of("status_on") : translator.of("status_off"))));

if (townBlock.hasDistrict())
screen.addComponentOf("district", colourKey(translator.of("status_district_name_and_size", townBlock.getDistrict().getName(), townBlock.getDistrict().getTownBlocks().size())));
Expand Down Expand Up @@ -223,7 +224,8 @@ public static StatusScreen getStatus(Resident resident, CommandSender sender) {
screen.addComponentOf("explosions", colourKeyValue(translator.of("explosions"), (resident.getPermissions().explosion) ? translator.of("status_on"): translator.of("status_off")));
screen.addComponentOf("firespread", colourKeyValue(translator.of("firespread"), (resident.getPermissions().fire) ? translator.of("status_on"): translator.of("status_off")));
screen.addComponentOf("mobspawns", colourKeyValue(translator.of("mobspawns"), (resident.getPermissions().mobs) ? translator.of("status_on"): translator.of("status_off")));

screen.addComponentOf("snowfall", colourKeyValue(translator.of("snowfall"), (resident.getPermissions().snow) ? translator.of("status_on"): translator.of("status_off")));

if (resident.isNPC()) {
screen.addComponentOf("npcstatus", translator.of("msg_status_npc", resident.getName()));
// Add any metadata which opt to be visible.
Expand Down Expand Up @@ -333,6 +335,7 @@ public static StatusScreen getStatus(Town town, CommandSender sender) {
screen.addComponentOf("explosion", colourKeyValue(translator.of("explosions"), (town.isExplosion() || world.isForceExpl()) ? translator.of("status_on"): translator.of("status_off")));
screen.addComponentOf("firespread", colourKeyValue(translator.of("firespread"), (town.isFire() || world.isForceFire()) ? translator.of("status_on"): translator.of("status_off")));
screen.addComponentOf("mobspawns", colourKeyValue(translator.of("mobspawns"), (town.hasMobs() || town.isAdminEnabledMobs() || world.isForceTownMobs()) ? translator.of("status_on"): translator.of("status_off")));
screen.addComponentOf("snowfall", colourKeyValue(translator.of("snowfall"), (town.isSnow() || world.isForceSnow()) ? translator.of("status_on"): translator.of("status_off")));

if (TownySettings.getTownRuinsEnabled() && town.isRuined()) {
TownRuinUtil.addRuinedComponents(town, screen, translator);
Expand Down Expand Up @@ -576,6 +579,9 @@ public static StatusScreen getStatus(TownyWorld world, CommandSender sender) {
// WorldMobs: ON | Wilderness Mobs: ON
screen.addComponentOf("mobs", colourKeyValue(translator.of("status_world_worldmobs"), (world.hasWorldMobs() ? translator.of("status_on") : translator.of("status_off"))) + translator.of("status_splitter") +
colourKeyValue(translator.of("status_world_wildernessmobs"), (world.hasWildernessMobs() ? translator.of("status_on") : translator.of("status_off"))));
// Snow: ON | ForceSnow: ON
screen.addComponentOf("snow", colourKeyValue(translator.of("status_world_snow"), (world.isSnow() ? translator.of("status_on") : translator.of("status_off"))) + translator.of("status_splitter") +
colourKeyValue(translator.of("status_world_forcesnow"), (world.isForceSnow() ? translator.of("status_forced") : translator.of("status_adjustable"))));
// ForceTownMobs: ON
screen.addComponentOf("townmobs", colourKeyValue(translator.of("status_world_forcetownmobs"), (world.isForceTownMobs() ? translator.of("status_forced") : translator.of("status_adjustable"))));
// Unclaim Revert: ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2447,6 +2447,14 @@ public static boolean isForcingFire() {

return getBoolean(ConfigNodes.NWS_FORCE_FIRE_ON);
}

public static boolean isSnow() {
return getBoolean(ConfigNodes.NWS_WORLD_SNOW);
}

public static boolean isForcingSnow() {
return getBoolean(ConfigNodes.NWS_FORCE_SNOW_ON);
}

public static boolean isDeletingEntitiesOnUnclaim() {
return getBoolean(ConfigNodes.NWS_PLOT_MANAGEMENT_ENTITY_DELETE_ENABLE);
Expand Down Expand Up @@ -2748,6 +2756,11 @@ public static boolean getPermFlag_Town_Default_Mobs() {

return getBoolean(ConfigNodes.FLAGS_TOWN_DEF_MOBS);
}

public static boolean getPermFlag_Town_Default_Snow() {

return getBoolean(ConfigNodes.FLAGS_TOWN_DEF_SNOW);
}

public static boolean getPermFlag_Town_Resident_Build() {

Expand Down
LlmDl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ protected MenuBuilder load() {
.add("friendlyfire", Translatable.of("world_toggle_help_4"))
.add("explosion/forceexplosion", Translatable.of("world_toggle_help_5"))
.add("fire/forcefire", Translatable.of("world_toggle_help_6"))
.add("snow/forcesnow", Translatable.of("world_toggle_help_12"))
.add("townmobs/wildernessmobs/worldmobs", Translatable.of("world_toggle_help_7"))
.add("revertunclaim", Translatable.of("world_toggle_help_8"))
.add("revertentityexpl/revertblockexpl", Translatable.of("world_toggle_help_9"))
Expand All @@ -521,6 +522,7 @@ protected MenuBuilder load() {
.add("friendlyfire", Translatable.of("world_toggle_help_4"))
.add("explosion/forceexplosion", Translatable.of("world_toggle_help_5"))
.add("fire/forcefire", Translatable.of("world_toggle_help_6"))
.add("snow/forcesnow", Translatable.of("world_toggle_help_12"))
.add("townmobs/wildernessmobs/worldmobs", Translatable.of("world_toggle_help_7"))
.add("revertunclaim", Translatable.of("world_toggle_help_8"))
.add("revertentityexpl/revertblockexpl", Translatable.of("world_toggle_help_9"))
Expand Down Expand Up @@ -758,6 +760,7 @@ protected MenuBuilder load() {
.add("fire", Translatable.of("res_toggle_help_1"))
.add("mobs", Translatable.of("res_toggle_help_2"))
.add("explosion", Translatable.of("res_toggle_help_3"))
.add("snow", Translatable.of("res_toggle_help_17"))
.add("plotborder", Translatable.of("res_toggle_help_4"))
.add("constantplotborder", Translatable.of("res_toggle_help_5"))
.add("townborder", Translatable.of("res_toggle_help_6"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.palmergames.bukkit.towny.event.plot.toggle.PlotToggleFireEvent;
import com.palmergames.bukkit.towny.event.plot.toggle.PlotToggleMobsEvent;
import com.palmergames.bukkit.towny.event.plot.toggle.PlotTogglePvpEvent;
import com.palmergames.bukkit.towny.event.plot.toggle.PlotToggleSnowEvent;
import com.palmergames.bukkit.towny.event.plot.toggle.PlotToggleTaxedEvent;
import com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException;
import com.palmergames.bukkit.towny.exceptions.CancelledEventException;
Expand Down Expand Up @@ -164,7 +165,8 @@ public class PlotCommand extends BaseCommand implements CommandExecutor {
"fire",
"pvp",
"explosion",
"mobs"
"mobs",
"snow"
);

private static final List<String> plotPermTabCompletes = Arrays.asList(
Expand Down Expand Up @@ -1053,7 +1055,8 @@ else if (split[0].equalsIgnoreCase("town"))
TownyMessaging.sendMessage(player, Colors.Green + Translatable.of("status_pvp").forLocale(player) + " " + ((perm.pvp) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") +
Colors.Green + Translatable.of("explosions").forLocale(player) + " " + ((perm.explosion) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") +
Colors.Green + Translatable.of("firespread").forLocale(player) + " " + ((perm.fire) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") +
Colors.Green + Translatable.of("mobspawns").forLocale(player) + " " + ((perm.mobs) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));
Colors.Green + Translatable.of("mobspawns").forLocale(player) + " " + ((perm.mobs) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") +
Colors.Green + Translatable.of("snowfall").forLocale(player) + " " + ((perm.snow) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));
}


Expand Down Expand Up @@ -1153,7 +1156,11 @@ public void plotToggle(Player player, Resident resident, TownBlock townBlock, St
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_PLOT_TOGGLE_MOBS.getNode());
tryToggleTownBlockMobs(player, townBlock, split, choice);
TownyMessaging.sendMsg(player, Translatable.of("msg_changed_mobs", "the Plot", townBlock.getPermissions().mobs ? Translatable.of("enabled") : Translatable.of("disabled")));
break;
break;
case "snow":
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_PLOT_TOGGLE_SNOW.getNode());
tryToggleTownBlockSnow(player, townBlock, split, choice);
TownyMessaging.sendMsg(player, Translatable.of("msg_changed_snow", "the Plot", townBlock.getPermissions().snow ? Translatable.of("enabled") : Translatable.of("disabled")));
LlmDl marked this conversation as resolved.
Show resolved Hide resolved
case "taxed":
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_PLOT_ASMAYOR.getNode());
tryToggleTownBlockTaxed(player, townBlock, split, choice);
Expand Down Expand Up @@ -1240,6 +1247,15 @@ private void tryToggleTownBlockMobs(Player player, TownBlock townBlock, String[]
townBlock.getPermissions().mobs = choice.orElse(!townBlock.getPermissions().mobs);
}

private void tryToggleTownBlockSnow(Player player, TownBlock townBlock, String[] split, Optional<Boolean> choice) throws TownyException {
// Make sure we are allowed to set these permissions.
toggleTest(player, townBlock, StringMgmt.join(split, " "));
// Fire cancellable event directly before setting the toggle.
BukkitTools.ifCancelledThenThrow(new PlotToggleSnowEvent(townBlock, player, choice.orElse(!townBlock.getPermissions().snow)));

townBlock.getPermissions().snow = choice.orElse(!townBlock.getPermissions().snow);
}

private void tryToggleTownBlockTaxed(Player player, TownBlock townBlock, String[] split, Optional<Boolean> choice) throws TownyException {
// Fire cancellable event directly before setting the toggle.
BukkitTools.ifCancelledThenThrow(new PlotToggleTaxedEvent(townBlock, player, choice.orElse(!townBlock.isTaxed())));
Expand Down Expand Up @@ -1278,6 +1294,11 @@ private void toggleTest(Player player, TownBlock townBlock, String split) throws
if (townBlock.getWorld().isForceExpl())
throw new TownyException(Translatable.of("msg_world_expl"));
}

if (split.contains("snow")) {
if (townBlock.getWorld().isForceSnow())
throw new TownyException(Translatable.of("msg_world_snow"));
}

if (split.contains("pvp")) {
if (townBlock.getWorld().isForcePVP())
Expand Down Expand Up @@ -1820,7 +1841,8 @@ public void parsePlotGroupSetPerm(String[] args, TownBlock townBlock, Player pla
TownyMessaging.sendMessage(player, Colors.Green + translator.of("status_pvp") + " " + (perm.pvp ? translator.of("status_on") : translator.of("status_off")) +
Colors.Green + translator.of("explosions") + " " + (perm.explosion ? translator.of("status_on") : translator.of("status_off")) +
Colors.Green + translator.of("firespread") + " " + (perm.fire ? translator.of("status_on") : translator.of("status_off")) +
Colors.Green + translator.of("mobspawns") + " " + (perm.mobs ? translator.of("status_on") : translator.of("status_off")));
Colors.Green + translator.of("mobspawns") + " " + (perm.mobs ? translator.of("status_on") : translator.of("status_off")) +
Colors.Green + translator.of("snowfall") + " " + (perm.snow ? translator.of("status_on") : translator.of("status_off")));
}
};

Expand Down Expand Up @@ -2012,6 +2034,9 @@ public void plotGroupToggle(Player player, Resident resident, PlotGroup plotGrou
case "mobs":
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_PLOT_TOGGLE_MOBS.getNode());
break;
case "snow":
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_PLOT_TOGGLE_SNOW.getNode());
break;
case "taxed":
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_PLOT_ASMAYOR.getNode());
break;
Expand Down Expand Up @@ -2039,6 +2064,9 @@ public void plotGroupToggle(Player player, Resident resident, PlotGroup plotGrou
tryToggleTownBlockMobs(player, groupBlock, split, choice);
endingMessage = Translatable.of("msg_changed_mobs", Translatable.of("msg_the_plot_group"), groupBlock.getPermissions().mobs ? Translatable.of("enabled") : Translatable.of("disabled"));
break;
case "snow":
tryToggleTownBlockSnow(player, groupBlock, split, choice);
endingMessage = Translatable.of("msg_changed_snow", Translatable.of("msg_the_plot_group"), groupBlock.getPermissions().snow ? Translatable.of("enabled") : Translatable.of("disabled"));
LlmDl marked this conversation as resolved.
Show resolved Hide resolved
case "taxed":
tryToggleTownBlockTaxed(player, groupBlock, split, choice);
endingMessage = Translatable.of("msg_changed_plotgroup_taxed", groupBlock.isTaxed() ? Translatable.of("enabled") : Translatable.of("disabled"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public class ResidentCommand extends BaseCommand implements CommandExecutor {
"pvp",
"fire",
"mobs",
"explosion"
"explosion",
"snow"
);

private static final List<String> residentToggleModeTabCompletes = ResidentModeHandler.getValidModeNames();
Expand Down Expand Up @@ -434,6 +435,9 @@ private void residentToggle(Player player, String[] newSplit) throws TownyExcept
} else if (newSplit[0].equalsIgnoreCase("mobs")) {
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_TOGGLE_MOBS.getNode());
perm.mobs = choice.orElse(!perm.mobs);
} else if (newSplit[0].equalsIgnoreCase("snow")) {
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_TOGGLE_SNOW.getNode());
perm.snow = choice.orElse(!perm.snow);
} else if (newSplit[0].equalsIgnoreCase("bordertitles")) {
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_TOGGLE_BORDERTITLES.getNode());
ResidentUtil.toggleResidentBorderTitles(resident, choice);
Expand Down Expand Up @@ -461,8 +465,12 @@ private void residentToggle(Player player, String[] newSplit) throws TownyExcept
private void notifyPerms(Player player, TownyPermission perm) {

TownyMessaging.sendMsg(player, Translatable.of("msg_set_perms"));
TownyMessaging.sendMessage(player, Colors.Green + "PvP: " + ((perm.pvp) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + " Explosions: " + ((perm.explosion) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + " Firespread: " + ((perm.fire) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + " Mob Spawns: " + ((perm.mobs) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));

TownyMessaging.sendMessage(player,
Colors.Green + "PvP: " + ((perm.pvp) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") +
Colors.Green + " Explosions: " + ((perm.explosion) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") +
Colors.Green + " Firespread: " + ((perm.fire) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") +
Colors.Green + " Mob Spawns: " + ((perm.mobs) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") +
Colors.Green + " Snowfall: " + ((perm.snow) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));
}

public void listResidents(CommandSender sender) throws TownyException {
Expand Down
Loading