diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index 9ab04b4cb..95d1404c0 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -327,5 +327,7 @@ public interface ISettings extends IConf { boolean allowOldIdSigns(); + boolean isWaterSafe(); + boolean isSafeUsermap(); } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 325fbb662..edc834f66 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -8,8 +8,8 @@ import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.SimpleTextInput; import com.earth2me.essentials.utils.EnumUtil; import com.earth2me.essentials.utils.FormatUtil; +import com.earth2me.essentials.utils.LocationUtil; import com.earth2me.essentials.utils.NumberUtil; - import net.ess3.api.IEssentials; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -24,15 +24,24 @@ import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; - -import static com.earth2me.essentials.I18n.tl; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import static com.earth2me.essentials.I18n.tl; + public class Settings implements net.ess3.api.ISettings { private final transient EssentialsConf config; @@ -543,6 +552,7 @@ public class Settings implements net.ess3.api.ISettings { itemDbType = _getItemDbType(); forceEnableRecipe = _isForceEnableRecipe(); allowOldIdSigns = _allowOldIdSigns(); + isWaterSafe = _isWaterSafe(); isSafeUsermap = _isSafeUsermap(); } @@ -1542,6 +1552,20 @@ public class Settings implements net.ess3.api.ISettings { return allowOldIdSigns; } + private boolean isWaterSafe; + + private boolean _isWaterSafe() { + boolean _isWaterSafe = config.getBoolean("is-water-safe", false); + LocationUtil.setIsWaterSafe(_isWaterSafe); + + return _isWaterSafe; + } + + @Override + public boolean isWaterSafe() { + return isWaterSafe; + } + private boolean isSafeUsermap; private boolean _isSafeUsermap() { diff --git a/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java b/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java index d8a54781c..2683e1e7d 100644 --- a/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java +++ b/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java @@ -16,6 +16,10 @@ import static com.earth2me.essentials.I18n.tl; public class LocationUtil { + // Water types used for TRANSPARENT_MATERIALS and is-water-safe config option + private static final Set WATER_TYPES = + EnumUtil.getAllMatching(Material.class, "WATER", "FLOWING_WATER"); + // The player can stand inside these materials private static final Set HOLLOW_MATERIALS = new HashSet<>(); private static final Set TRANSPARENT_MATERIALS = new HashSet<>(); @@ -29,10 +33,15 @@ public class LocationUtil { } TRANSPARENT_MATERIALS.addAll(HOLLOW_MATERIALS); - TRANSPARENT_MATERIALS.add(Material.WATER); - try { - TRANSPARENT_MATERIALS.add(Material.valueOf("FLOWING_WATER")); - } catch (Exception ignored) {} // 1.13 WATER uses Levelled + TRANSPARENT_MATERIALS.addAll(WATER_TYPES); + } + + public static void setIsWaterSafe(boolean isWaterSafe) { + if (isWaterSafe) { + HOLLOW_MATERIALS.addAll(WATER_TYPES); + } else { + HOLLOW_MATERIALS.removeAll(WATER_TYPES); + } } public static final int RADIUS = 3; diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 678375225..2ce72d16f 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -559,6 +559,11 @@ allow-direct-hat: true # This doesn't affect running the command from the console, where a world is always required. allow-world-in-broadcastworld: true +# Consider water blocks as "safe," therefore allowing players to teleport +# using commands such as /home or /spawn to a location that is occupied +# by water blocks +is-water-safe: false + # Should the usermap try to sanitise usernames before saving them? # You should only change this to false if you use Minecraft China. safe-usermap-names: true