From 6abd48ab081cfb6da4059739ac022d70116e04df Mon Sep 17 00:00:00 2001 From: Wizjany Date: Sat, 19 Jan 2013 19:06:55 -0500 Subject: [PATCH] Add a config setting to allow creative mode players to override inventory setting. --- .../com/sk89q/worldedit/LocalConfiguration.java | 1 + src/main/java/com/sk89q/worldedit/LocalPlayer.java | 5 +++++ src/main/java/com/sk89q/worldedit/WorldEdit.java | 3 ++- .../com/sk89q/worldedit/bukkit/BukkitPlayer.java | 13 ++++++++++++- .../com/sk89q/worldedit/util/YAMLConfiguration.java | 2 ++ src/main/resources/config.yml | 1 + 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java index 216ded223..2540ab792 100644 --- a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java @@ -98,6 +98,7 @@ public abstract class LocalConfiguration { public boolean noDoubleSlash = false; public boolean useInventory = false; public boolean useInventoryOverride = false; + public boolean useInventoryCreativeOverride = false; public int navigationWand = ItemID.COMPASS; public int navigationWandMaxDistance = 50; public int scriptTimeout = 3000; diff --git a/src/main/java/com/sk89q/worldedit/LocalPlayer.java b/src/main/java/com/sk89q/worldedit/LocalPlayer.java index ccacee4aa..050cccb34 100644 --- a/src/main/java/com/sk89q/worldedit/LocalPlayer.java +++ b/src/main/java/com/sk89q/worldedit/LocalPlayer.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit; import java.io.File; + import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.BlockType; @@ -669,4 +670,8 @@ public abstract class LocalPlayer { public boolean isPlayer() { return true; } + + public boolean hasCreativeMode() { + return false; + } } diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index 6338fa6d9..34653a44c 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -345,7 +345,8 @@ public class WorldEdit { // Have the session use inventory if it's enabled and the player // doesn't have an override session.setUseInventory(config.useInventory - && !(config.useInventoryOverride + && !((config.useInventoryOverride || + (config.useInventoryCreativeOverride && player.hasCreativeMode())) && player.hasPermission("worldedit.inventory.unrestricted"))); } diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 0e129410f..82f2effd6 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -19,11 +19,17 @@ package com.sk89q.worldedit.bukkit; +import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; + import com.sk89q.util.StringUtil; -import com.sk89q.worldedit.*; +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalWorld; +import com.sk89q.worldedit.ServerInterface; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.cui.CUIEvent; @@ -139,4 +145,9 @@ public class BukkitPlayer extends LocalPlayer { public Player getPlayer() { return player; } + + @Override + public boolean hasCreativeMode() { + return player.getGameMode() == GameMode.CREATIVE; + } } diff --git a/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java b/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java index df71d6819..d640fc644 100644 --- a/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java @@ -93,6 +93,8 @@ public class YAMLConfiguration extends LocalConfiguration { useInventory = config.getBoolean("use-inventory.enable", useInventory); useInventoryOverride = config.getBoolean("use-inventory.allow-override", useInventoryOverride); + useInventoryCreativeOverride = config.getBoolean("use-inventory.creative-mode-overrides", + useInventoryCreativeOverride); navigationWand = config.getInt("navigation-wand.item", navigationWand); navigationWandMaxDistance = config.getInt("navigation-wand.max-distance", navigationWandMaxDistance); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 482937fd2..f4c7c2981 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -34,6 +34,7 @@ limits: use-inventory: enable: false allow-override: true + creative-mode-overrides: false logging: log-commands: false