From 585aa06fae95aca9ce0662086397f6a835ae4b8d Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 4 Aug 2012 11:23:55 +0200 Subject: [PATCH] v1.3.01: MC 1.3.1: - Adventure GameMode Inventory (optional) - Region Flag for Adventure Inventory --- config.yml | 5 +++ plugin.yml | 2 +- pom.xml | 4 +- .../limitedcreative/Configuration.java | 4 ++ .../minecraft/limitedcreative/Inventory.java | 9 ++++- .../minecraft/limitedcreative/LCPlayer.java | 40 +++++++++++++------ .../limitedcreative/regions/GameModeFlag.java | 2 + 7 files changed, 48 insertions(+), 18 deletions(-) diff --git a/config.yml b/config.yml index 800d01a..2f501d5 100644 --- a/config.yml +++ b/config.yml @@ -47,6 +47,11 @@ store: # By default the inventories are saved to "plugin/LimitedCreative/inventories". # default: "inventories" folder: "inventories" + + # SeparateAdventureInventory + # When true, your players get a separate inventory when switching to adventure gamemode (2). Otherwise + # they have the default survival inventory while in adventure gamemode. + adventure: false limit: # LimitsEnabled diff --git a/plugin.yml b/plugin.yml index f358dba..1e0f0bd 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: LimitedCreative main: de.jaschastarke.minecraft.limitedcreative.Core -version: 1.2.5 +version: 1.3.0a softdepend: [WorldGuard, WorldEdit, MultiInv] dev-url: http://dev.bukkit.org/server-mods/limited-creative/ commands: diff --git a/pom.xml b/pom.xml index 1d69880..45334be 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.jaschastarke LimitedCreative LimitedCreative - 1.2.5 + 1.3.0a https://github.com/possi/LimitedCreative scm:git:git://github.com/possi/LimitedCreative.git @@ -68,7 +68,7 @@ org.bukkit bukkit - 1.2.5-R4.0 + 1.3.1-R0.1-SNAPSHOT com.sk89q diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java index 2c30456..b7fb4e6 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java @@ -43,6 +43,7 @@ public class Configuration { public enum Option { STORECREATIVE("store.creative", true), CREATIVEARMOR("store.armor.enabled", true), + ADVENTUREINV("store.adventure", false), REGION_OPTIONAL("region.optional", true), REGION_REMEMBER("region.remember", true), BLOCKPICKUP("limit.pickup", true), @@ -127,6 +128,9 @@ public class Configuration { public String getInventoryFolder() { return c.getString("store.folder", "inventories"); } + public boolean getAdventureInv() { + return this.getBoolean(Option.ADVENTUREINV); + } public boolean getBlockPickupInCreative() { return this.getBoolean(Option.BLOCKPICKUP); } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java b/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java index 8860039..cf881f9 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java @@ -35,10 +35,11 @@ public class Inventory { public enum Target { SURVIVAL, - CREATIVE; + CREATIVE, + ADVENTURE; public static Target getTarget(GameMode gm) { - return gm == GameMode.CREATIVE ? Target.CREATIVE : Target.SURVIVAL; + return Target.valueOf(gm.name()); } } @@ -60,6 +61,10 @@ public class Inventory { Core.debug(getPlayer().getName()+": store inventory: "+getPlayer().getGameMode()); storage.store(this, Target.getTarget(getPlayer().getGameMode())); } + public void save(GameMode gm) { + Core.debug(getPlayer().getName()+": store inventory: "+gm); + storage.store(this, Target.getTarget(gm)); + } public void load() { load(getPlayer().getGameMode()); diff --git a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java index cc31d8f..bcbbc12 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java @@ -195,20 +195,34 @@ public class LCPlayer { if (plugin.config.getPermissionToKeepInventory() && hasPermission(Perms.KEEPINVENTORY)) return true; getPlayer().closeInventory(); - if (gm != GameMode.CREATIVE || plugin.config.getStoreCreative()) - getInv().save(); - if (gm == GameMode.CREATIVE) { - if (plugin.config.getStoreCreative() && getInv().isStored(GameMode.CREATIVE)) { - getInv().load(GameMode.CREATIVE); - } else { - getInv().clear(); - } - setCreativeArmor(); - } else if (gm == GameMode.SURVIVAL) { - if (getInv().isStored(GameMode.SURVIVAL)) - getInv().load(GameMode.SURVIVAL); - } + GameMode cgm = getPlayer().getGameMode(); + if (gm == GameMode.ADVENTURE && !plugin.config.getAdventureInv()) + gm = GameMode.SURVIVAL; + if (cgm == GameMode.ADVENTURE && !plugin.config.getAdventureInv()) + cgm = GameMode.SURVIVAL; + + if (gm != cgm) { + if (gm != GameMode.CREATIVE || plugin.config.getStoreCreative()) { + getInv().save(cgm); + } + if (gm == GameMode.CREATIVE) { + if (plugin.config.getStoreCreative() && getInv().isStored(GameMode.CREATIVE)) { + getInv().load(GameMode.CREATIVE); + } else { + getInv().clear(); + } + setCreativeArmor(); + } else if (gm == GameMode.SURVIVAL) { + if (getInv().isStored(GameMode.SURVIVAL)) + getInv().load(GameMode.SURVIVAL); + } else if (gm == GameMode.ADVENTURE) { + if (getInv().isStored(GameMode.ADVENTURE)) + getInv().load(GameMode.ADVENTURE); + else + getInv().clear(); + } + } } return true; } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/GameModeFlag.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/GameModeFlag.java index 30a305f..e43686f 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/regions/GameModeFlag.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/GameModeFlag.java @@ -23,6 +23,8 @@ public class GameModeFlag extends Flag { return GameMode.CREATIVE; } else if (input.equalsIgnoreCase("survival")) { return GameMode.SURVIVAL; + } else if (input.equalsIgnoreCase("adventure")) { + return GameMode.ADVENTURE; } else if (input.equalsIgnoreCase("none")) { return null; } else {