From c25b9a53f21e8616cf03f18483600d333feb993d Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Tue, 31 Dec 2013 18:55:33 +0100 Subject: [PATCH] Added config option to set the default for the /up and /ceil commands. The config option defaults to glass as that is consistent across gamemodes. Use -f to force flight (if available). Use -g to force glass. --- .../sk89q/worldedit/LocalConfiguration.java | 1 + .../commands/NavigationCommands.java | 32 ++++++++++++++----- .../util/PropertiesConfiguration.java | 1 + .../worldedit/util/YAMLConfiguration.java | 1 + 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java index ae885d5bb..5a3cd72a3 100644 --- a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java @@ -101,6 +101,7 @@ public abstract class LocalConfiguration { public boolean useInventory = false; public boolean useInventoryOverride = false; public boolean useInventoryCreativeOverride = false; + public boolean navigationUseGlass = true; public int navigationWand = ItemID.COMPASS; public int navigationWandMaxDistance = 50; public int scriptTimeout = 3000; diff --git a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java index aa48ca700..17b1df07a 100644 --- a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java @@ -26,6 +26,7 @@ import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalPlayer; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; @@ -118,7 +119,7 @@ public class NavigationCommands { aliases = { "ceil" }, usage = "[clearance]", desc = "Go to the celing", - flags = "f", + flags = "fg", min = 0, max = 1 ) @@ -127,11 +128,11 @@ public class NavigationCommands { public void ceiling(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - int clearence = args.argsLength() > 0 ? + final int clearance = args.argsLength() > 0 ? Math.max(0, args.getInteger(0)) : 0; - final boolean useFlight = args.hasFlag('f'); - if (player.ascendToCeiling(clearence, !useFlight)) { + final boolean alwaysGlass = getAlwaysGlass(args); + if (player.ascendToCeiling(clearance, alwaysGlass)) { player.print("Whoosh!"); } else { player.printError("No free spot above you found."); @@ -179,7 +180,7 @@ public class NavigationCommands { aliases = { "up" }, usage = "", desc = "Go upwards some distance", - flags = "f", + flags = "fg", min = 1, max = 1 ) @@ -188,13 +189,28 @@ public class NavigationCommands { public void up(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - int distance = args.getInteger(0); + final int distance = args.getInteger(0); - final boolean useFlight = args.hasFlag('f'); - if (player.ascendUpwards(distance, !useFlight)) { + final boolean alwaysGlass = getAlwaysGlass(args); + if (player.ascendUpwards(distance, alwaysGlass)) { player.print("Whoosh!"); } else { player.printError("You would hit something above you."); } } + + /** + * Helper function for /up and /ceil. + * + * @param args The {@link CommandContext} to extract the flags from. + * @return true, if glass should always be put under the player + */ + private boolean getAlwaysGlass(CommandContext args) { + final LocalConfiguration config = we.getConfiguration(); + + final boolean forceFlight = args.hasFlag('f'); + final boolean forceGlass = args.hasFlag('g'); + + return forceGlass || (config.navigationUseGlass && !forceFlight); + } } diff --git a/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java b/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java index e7b7bbcbe..9edd1ec3d 100644 --- a/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java @@ -101,6 +101,7 @@ public class PropertiesConfiguration extends LocalConfiguration { useInventoryCreativeOverride = getBool("use-inventory-creative-override", useInventoryCreativeOverride); navigationWand = getInt("nav-wand-item", navigationWand); navigationWandMaxDistance = getInt("nav-wand-distance", navigationWandMaxDistance); + navigationUseGlass = getBool("nav-use-glass", navigationUseGlass); scriptTimeout = getInt("scripting-timeout", scriptTimeout); saveDir = getString("schematic-save-dir", saveDir); scriptsDir = getString("craftscript-dir", scriptsDir); diff --git a/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java b/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java index bf0431c94..b15ec4d10 100644 --- a/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java @@ -98,6 +98,7 @@ public class YAMLConfiguration extends LocalConfiguration { navigationWand = config.getInt("navigation-wand.item", navigationWand); navigationWandMaxDistance = config.getInt("navigation-wand.max-distance", navigationWandMaxDistance); + navigationUseGlass = config.getBoolean("navigation.use-glass", navigationUseGlass); scriptTimeout = config.getInt("scripting.timeout", scriptTimeout); scriptsDir = config.getString("scripting.dir", scriptsDir);