Working Inventory-Feature with some basic configuration
This commit is contained in:
parent
f80a88174c
commit
672befc658
18 changed files with 882 additions and 49 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -8,3 +8,6 @@
|
||||||
|
|
||||||
# maven
|
# maven
|
||||||
/target
|
/target
|
||||||
|
|
||||||
|
# Mac stuff
|
||||||
|
.DS_Store
|
49
pom.xml
49
pom.xml
|
@ -3,7 +3,7 @@
|
||||||
<groupId>de.jaschastarke</groupId>
|
<groupId>de.jaschastarke</groupId>
|
||||||
<artifactId>LimitedCreative</artifactId>
|
<artifactId>LimitedCreative</artifactId>
|
||||||
<name>LimitedCreative</name>
|
<name>LimitedCreative</name>
|
||||||
<version>1.4.1a-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
<url>https://github.com/possi/LimitedCreative</url>
|
<url>https://github.com/possi/LimitedCreative</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -17,11 +17,14 @@
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<!-- Required dependencies for optional integrations, that aren't hosted yet -->
|
<!-- Possible public Maven Repository, containing LimitedCreative builds and other dependencies without own rep.
|
||||||
|
like AuthMe, etc.
|
||||||
|
Supports http & https -->
|
||||||
<repository>
|
<repository>
|
||||||
<id>opt-dep</id>
|
<id>de-jas-mvn</id>
|
||||||
<url>http://dl.dropbox.com/u/5023975/mvn-repo</url>
|
<url>https://repository-possi.forge.cloudbees.com/release</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<!-- Official (Craft-)Bukkit repository -->
|
<!-- Official (Craft-)Bukkit repository -->
|
||||||
<repository>
|
<repository>
|
||||||
<id>bukkit-repo</id>
|
<id>bukkit-repo</id>
|
||||||
|
@ -37,27 +40,44 @@
|
||||||
<id>onarandombox</id>
|
<id>onarandombox</id>
|
||||||
<url>http://repo.onarandombox.com/content/groups/public</url>
|
<url>http://repo.onarandombox.com/content/groups/public</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<!-- Official Vault repository -->
|
||||||
<repository>
|
<repository>
|
||||||
<id>vault-repo</id>
|
<id>vault-repo</id>
|
||||||
<url>http://ci.herocraftonline.com/plugin/repository/everything</url>
|
<url>http://ci.herocraftonline.com/plugin/repository/everything</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<!-- Official xAuth repository; it is no good! we keep our own dep-files of it - ->
|
||||||
|
<repository>
|
||||||
|
<id>luricos.de-repo</id>
|
||||||
|
<url>http://repo.luricos.de/bukkit-plugins/</url>
|
||||||
|
</repository><!- - -->
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>1.4.2-R0.2</version>
|
<version>1.4.6-R0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.4.6-R0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sk89q</groupId>
|
||||||
|
<artifactId>worldedit</artifactId>
|
||||||
|
<version>5.4.5</version>
|
||||||
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sk89q</groupId>
|
<groupId>com.sk89q</groupId>
|
||||||
<artifactId>worldguard</artifactId>
|
<artifactId>worldguard</artifactId>
|
||||||
<version>5.6.3</version>
|
<version>5.6.6-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>uk.org.whoami</groupId>
|
<groupId>uk.org.whoami</groupId>
|
||||||
<artifactId>authme</artifactId>
|
<artifactId>authme</artifactId>
|
||||||
<version>2.6.7b5</version>
|
<version>2.7.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.onarandombox.multiversecore</groupId>
|
<groupId>com.onarandombox.multiversecore</groupId>
|
||||||
|
@ -67,7 +87,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.cypherx</groupId>
|
<groupId>com.cypherx</groupId>
|
||||||
<artifactId>xauth</artifactId>
|
<artifactId>xauth</artifactId>
|
||||||
<version>2.0.20</version>
|
<version>2.0.26</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.jaschastarke</groupId>
|
<groupId>de.jaschastarke</groupId>
|
||||||
|
@ -89,12 +109,21 @@
|
||||||
<includes>
|
<includes>
|
||||||
<include>plugin.yml</include>
|
<include>plugin.yml</include>
|
||||||
<include>config.yml</include>
|
<include>config.yml</include>
|
||||||
|
<include>META-INF/descriptions.jos</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
<resource>
|
<resource>
|
||||||
<targetPath>lang/</targetPath>
|
<targetPath>lang/</targetPath>
|
||||||
<directory>${basedir}/lang/</directory>
|
<directory>${basedir}/lang/</directory>
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<targetPath>META-INF/</targetPath>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<directory>${project.build.directory}/generated-sources/annotations/META-INF/</directory>
|
||||||
|
<includes>
|
||||||
|
<include>descriptions.jos</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
31
src/de/jaschastarke/minecraft/limitedcreative/Config.java
Normal file
31
src/de/jaschastarke/minecraft/limitedcreative/Config.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package de.jaschastarke.minecraft.limitedcreative;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import de.jaschastarke.bukkit.lib.Core;
|
||||||
|
import de.jaschastarke.bukkit.lib.configuration.PluginConfiguration;
|
||||||
|
import de.jaschastarke.maven.ArchiveDocComments;
|
||||||
|
import de.jaschastarke.utils.ClassDescriptorStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limited Creative - Configuration
|
||||||
|
*
|
||||||
|
* (YAML-Syntax: http://en.wikipedia.org/wiki/YAML)
|
||||||
|
*/
|
||||||
|
@ArchiveDocComments
|
||||||
|
public class Config extends PluginConfiguration {
|
||||||
|
public Config(Core plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
try {
|
||||||
|
ClassDescriptorStorage.load(plugin.getResource("META-INF/descriptions.jos"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
plugin.getLog().severe("Failed to load ConfigNode-Descriptions");
|
||||||
|
}
|
||||||
|
super.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -15,11 +15,10 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import de.jaschastarke.bukkit.lib.Core;
|
|
||||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||||
|
|
||||||
public class FeatureBlockItemSpawn extends CoreModule implements Listener {
|
public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implements Listener {
|
||||||
public FeatureBlockItemSpawn(Core plugin) {
|
public FeatureBlockItemSpawn(LimitedCreative plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
}
|
}
|
||||||
public final static long TIME_OFFSET = 250;
|
public final static long TIME_OFFSET = 250;
|
||||||
|
|
|
@ -5,13 +5,23 @@ import de.jaschastarke.bukkit.lib.Core;
|
||||||
|
|
||||||
public class LimitedCreative extends Core {
|
public class LimitedCreative extends Core {
|
||||||
private i18n lang;
|
private i18n lang;
|
||||||
|
protected Config config = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void OnInitialize() {
|
public void OnInitialize() {
|
||||||
|
config = new Config(this);
|
||||||
lang = new i18n("lang/messages");
|
lang = new i18n("lang/messages");
|
||||||
addModule(new ModInventories(this));
|
addModule(new ModInventories(this));
|
||||||
addModule(new ModCreativeLimits(this));
|
addModule(new ModCreativeLimits(this));
|
||||||
addModule(new ModRegions(this));
|
addModule(new ModRegions(this));
|
||||||
addModule(new ModCmdBlocker(this));
|
addModule(new ModCmdBlocker(this));
|
||||||
|
Hooks.inizializeHooks(this);
|
||||||
|
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Config getPluginConfig() {
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative;
|
package de.jaschastarke.minecraft.limitedcreative;
|
||||||
|
|
||||||
import de.jaschastarke.bukkit.lib.Core;
|
|
||||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||||
|
|
||||||
public class ModCmdBlocker extends CoreModule {
|
public class ModCmdBlocker extends CoreModule<LimitedCreative> {
|
||||||
|
|
||||||
public ModCmdBlocker(Core plugin) {
|
public ModCmdBlocker(LimitedCreative plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative;
|
package de.jaschastarke.minecraft.limitedcreative;
|
||||||
|
|
||||||
import de.jaschastarke.bukkit.lib.Core;
|
|
||||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||||
import de.jaschastarke.modularize.IModule;
|
import de.jaschastarke.modularize.IModule;
|
||||||
import de.jaschastarke.modularize.ModuleEntry;
|
import de.jaschastarke.modularize.ModuleEntry;
|
||||||
|
|
||||||
public class ModCreativeLimits extends CoreModule {
|
public class ModCreativeLimits extends CoreModule<LimitedCreative> {
|
||||||
public ModCreativeLimits(Core plugin) {
|
public ModCreativeLimits(LimitedCreative plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,58 +1,114 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative;
|
package de.jaschastarke.minecraft.limitedcreative;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
import de.jaschastarke.bukkit.lib.Core;
|
|
||||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||||
|
import de.jaschastarke.bukkit.lib.permissions.PermissionManager;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.ArmoryConfig;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryConfig;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryPermissions;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.inventories.PlayerListener;
|
import de.jaschastarke.minecraft.limitedcreative.inventories.PlayerListener;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.store.InvYamlStorage;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.store.PlayerInventoryStorage;
|
||||||
import de.jaschastarke.modularize.IModule;
|
import de.jaschastarke.modularize.IModule;
|
||||||
import de.jaschastarke.modularize.ModuleEntry;
|
import de.jaschastarke.modularize.ModuleEntry;
|
||||||
|
|
||||||
public class ModInventories extends CoreModule {
|
public class ModInventories extends CoreModule<LimitedCreative> {
|
||||||
public ModInventories(Core plugin) {
|
protected PlayerInventoryStorage storage;
|
||||||
|
protected Map<Player, Inventory> inventories;
|
||||||
|
protected InventoryConfig config;
|
||||||
|
protected ArmoryConfig armor_config;
|
||||||
|
|
||||||
|
public ModInventories(LimitedCreative plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void Initialize(ModuleEntry<IModule> entry) {
|
public void Initialize(ModuleEntry<IModule> entry) {
|
||||||
super.Initialize(entry);
|
super.Initialize(entry);
|
||||||
listeners.registerEvents(new PlayerListener(this));
|
listeners.addListener(new PlayerListener(this));
|
||||||
|
config = plugin.getPluginConfig().registerSection(new InventoryConfig(this));
|
||||||
|
armor_config = config.registerSection(new ArmoryConfig(this));
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void OnEnable() {
|
||||||
|
super.OnEnable();
|
||||||
|
storage = new InvYamlStorage(this, new File(plugin.getDataFolder(), config.getFolder()));
|
||||||
|
inventories = new WeakHashMap<Player, Inventory>();
|
||||||
|
}
|
||||||
|
public InventoryConfig getConfig() {
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlayerInventoryStorage getStorage() {
|
||||||
|
return storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Inventory getInventory(Player player) {
|
||||||
|
if (inventories.containsKey(player)) {
|
||||||
|
return inventories.get(player);
|
||||||
|
} else {
|
||||||
|
Inventory inv = new Inventory(storage, player);
|
||||||
|
inventories.put(player, inv);
|
||||||
|
return inv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void onSetGameMode(Player player, GameMode gm) {
|
public void onSetGameMode(Player player, GameMode gm) {
|
||||||
//if (hasPermission(Perms.KEEPINVENTORY))
|
if (PermissionManager.hasPermission(player, InventoryPermissions.KEEP_INVENTORY))
|
||||||
// return true;
|
return;
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
GameMode cgm = player.getGameMode();
|
GameMode cgm = player.getGameMode();
|
||||||
if (gm == GameMode.ADVENTURE && !plugin.config.getAdventureInv())
|
if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
||||||
gm = GameMode.SURVIVAL;
|
gm = GameMode.SURVIVAL;
|
||||||
if (cgm == GameMode.ADVENTURE && !plugin.config.getAdventureInv())
|
if (cgm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
||||||
cgm = GameMode.SURVIVAL;
|
cgm = GameMode.SURVIVAL;
|
||||||
|
|
||||||
if (gm != cgm) {
|
if (gm != cgm) {
|
||||||
if (gm != GameMode.CREATIVE || plugin.config.getStoreCreative()) {
|
if (gm != GameMode.CREATIVE || config.getStoreCreative()) {
|
||||||
getInv().save(cgm);
|
getInventory(player).save(cgm);
|
||||||
}
|
}
|
||||||
if (gm == GameMode.CREATIVE) {
|
if (gm == GameMode.CREATIVE) {
|
||||||
if (plugin.config.getStoreCreative() && getInv().isStored(GameMode.CREATIVE)) {
|
if (config.getStoreCreative() && getInventory(player).isStored(GameMode.CREATIVE)) {
|
||||||
getInv().load(GameMode.CREATIVE);
|
getInventory(player).load(GameMode.CREATIVE);
|
||||||
} else {
|
} else {
|
||||||
getInv().clear();
|
getInventory(player).clear();
|
||||||
}
|
}
|
||||||
setCreativeArmor();
|
setCreativeArmor(player);
|
||||||
} else if (gm == GameMode.SURVIVAL) {
|
} else if (gm == GameMode.SURVIVAL) {
|
||||||
if (getInv().isStored(GameMode.SURVIVAL))
|
if (getInventory(player).isStored(GameMode.SURVIVAL))
|
||||||
getInv().load(GameMode.SURVIVAL);
|
getInventory(player).load(GameMode.SURVIVAL);
|
||||||
} else if (gm == GameMode.ADVENTURE) {
|
} else if (gm == GameMode.ADVENTURE) {
|
||||||
if (getInv().isStored(GameMode.ADVENTURE))
|
if (getInventory(player).isStored(GameMode.ADVENTURE))
|
||||||
getInv().load(GameMode.ADVENTURE);
|
getInventory(player).load(GameMode.ADVENTURE);
|
||||||
else
|
else
|
||||||
getInv().clear();
|
getInventory(player).clear();
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreativeArmor(Player player) {
|
||||||
|
Map<String, MaterialData> armor = armor_config.getCreativeArmor();
|
||||||
|
if (armor != null) {
|
||||||
|
ItemStack[] is = new ItemStack[4];
|
||||||
|
if (armor.containsKey("feet"))
|
||||||
|
is[0] = armor.get("feet").toItemStack(1);
|
||||||
|
if (armor.containsKey("legs"))
|
||||||
|
is[1] = armor.get("legs").toItemStack(1);
|
||||||
|
if (armor.containsKey("chest"))
|
||||||
|
is[2] = armor.get("chest").toItemStack(1);
|
||||||
|
if (armor.containsKey("head"))
|
||||||
|
is[3] = armor.get("head").toItemStack(1);
|
||||||
|
player.getInventory().setArmorContents(is);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative;
|
package de.jaschastarke.minecraft.limitedcreative;
|
||||||
|
|
||||||
import de.jaschastarke.bukkit.lib.Core;
|
|
||||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||||
|
|
||||||
public class ModRegions extends CoreModule {
|
public class ModRegions extends CoreModule<LimitedCreative> {
|
||||||
|
public ModRegions(LimitedCreative plugin) {
|
||||||
public ModRegions(Core plugin) {
|
|
||||||
super(plugin);
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
package de.jaschastarke.minecraft.limitedcreative.inventories;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
|
import de.jaschastarke.bukkit.lib.ModuleLogger;
|
||||||
|
import de.jaschastarke.bukkit.lib.configuration.Configuration;
|
||||||
|
import de.jaschastarke.bukkit.lib.items.MaterialDataNotRecognizedException;
|
||||||
|
import de.jaschastarke.bukkit.lib.items.MaterilNotRecognizedException;
|
||||||
|
import de.jaschastarke.bukkit.lib.items.Utils;
|
||||||
|
import de.jaschastarke.configuration.annotations.IConfigurationSubGroup;
|
||||||
|
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
|
||||||
|
import de.jaschastarke.maven.ArchiveDocComments;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CreativeArmor
|
||||||
|
*
|
||||||
|
* When set, all creative Player automatically wears the given items as Armor. So they are better seen by other Players.
|
||||||
|
*/
|
||||||
|
@ArchiveDocComments
|
||||||
|
public class ArmoryConfig extends Configuration implements IConfigurationSubGroup {
|
||||||
|
protected ModInventories mod;
|
||||||
|
public ArmoryConfig(ModInventories modInventories) {
|
||||||
|
mod = modInventories;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getNodeName() {
|
||||||
|
return "armor";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CreativeArmorEnabled
|
||||||
|
*
|
||||||
|
* When disabled, the players Armor isn't swapped
|
||||||
|
*
|
||||||
|
* default: true
|
||||||
|
*/
|
||||||
|
@IsConfigurationNode
|
||||||
|
public boolean getEnabled() {
|
||||||
|
return config.getBoolean("enabled", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CreativeArmor-Items
|
||||||
|
*
|
||||||
|
* Allows changing of the "Creative-Armor" to be wear when in creative mode
|
||||||
|
*
|
||||||
|
* *see Blacklist for details on Item-Types
|
||||||
|
*/
|
||||||
|
public Map<String, MaterialData> getCreativeArmor() {
|
||||||
|
if (getEnabled()) {
|
||||||
|
Map<String, MaterialData> armor = new HashMap<String, MaterialData>();
|
||||||
|
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
|
||||||
|
if (!entry.getKey().equals("enabled")) {
|
||||||
|
MaterialData md = null;
|
||||||
|
try {
|
||||||
|
md = Utils.parseMaterial((String) entry.getValue());
|
||||||
|
} catch (MaterilNotRecognizedException e) {
|
||||||
|
getLog().warn(L("exception.config.material_not_found", entry.getValue()));
|
||||||
|
} catch (MaterialDataNotRecognizedException e) {
|
||||||
|
getLog().warn(L("exception.config.materiak_data_not_found", entry.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (md != null)
|
||||||
|
armor.put(entry.getKey(), md);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return armor.size() > 0 ? armor : null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public String L(String msg, Object... objects) {
|
||||||
|
return ((LimitedCreative) Bukkit.getPluginManager().getPlugin("LimitedCreative")).getLocale().trans(msg, objects);
|
||||||
|
}
|
||||||
|
@Deprecated
|
||||||
|
public ModuleLogger getLog() {
|
||||||
|
return ((LimitedCreative) Bukkit.getPluginManager().getPlugin("LimitedCreative")).getModule(ModInventories.class).getLog();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package de.jaschastarke.minecraft.limitedcreative.inventories;
|
||||||
|
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import uk.org.whoami.authme.events.RestoreInventoryEvent;
|
||||||
|
import uk.org.whoami.authme.events.StoreInventoryEvent;
|
||||||
|
import de.jaschastarke.bukkit.lib.SimpleModule;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
||||||
|
|
||||||
|
public class AuthMeInventories extends SimpleModule<LimitedCreative> implements Listener {
|
||||||
|
ModInventories invmod;
|
||||||
|
public AuthMeInventories(LimitedCreative plugin, ModInventories modInventories) {
|
||||||
|
super(plugin);
|
||||||
|
invmod = modInventories;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onStoreInventory(StoreInventoryEvent event) {
|
||||||
|
if (isDebug())
|
||||||
|
getLog().debug("AuthMe Store Event: "+event.getPlayer().getName());
|
||||||
|
|
||||||
|
event.getPlayer().closeInventory();
|
||||||
|
GameMode cgm = event.getPlayer().getGameMode();
|
||||||
|
|
||||||
|
if (cgm == GameMode.ADVENTURE && !invmod.getConfig().getSeparateAdventure())
|
||||||
|
cgm = GameMode.SURVIVAL;
|
||||||
|
|
||||||
|
if (cgm != GameMode.CREATIVE || invmod.getConfig().getStoreCreative()) {
|
||||||
|
invmod.getInventory(event.getPlayer()).save(cgm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@EventHandler
|
||||||
|
public void onRestoreInventory(RestoreInventoryEvent event) {
|
||||||
|
if (isDebug())
|
||||||
|
getLog().debug("AuthMe Restore Event: "+event.getPlayer().getName());
|
||||||
|
|
||||||
|
event.getPlayer().closeInventory();
|
||||||
|
GameMode cgm = event.getPlayer().getGameMode();
|
||||||
|
|
||||||
|
if (cgm == GameMode.ADVENTURE && !invmod.getConfig().getSeparateAdventure())
|
||||||
|
cgm = GameMode.SURVIVAL;
|
||||||
|
|
||||||
|
Inventory inv = invmod.getInventory(event.getPlayer());
|
||||||
|
if (inv.isStored(cgm)) {
|
||||||
|
inv.load(cgm);
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* Limited Creative - (Bukkit Plugin)
|
||||||
|
* Copyright (C) 2012 jascha@ja-s.de
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.jaschastarke.minecraft.limitedcreative.inventories;
|
||||||
|
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.store.PlayerInventoryStorage;
|
||||||
|
|
||||||
|
public class Inventory {
|
||||||
|
private PlayerInventoryStorage storage;
|
||||||
|
protected Player player;
|
||||||
|
|
||||||
|
public enum Target {
|
||||||
|
SURVIVAL,
|
||||||
|
CREATIVE,
|
||||||
|
ADVENTURE;
|
||||||
|
|
||||||
|
public static Target getTarget(GameMode gm) {
|
||||||
|
return Target.valueOf(gm.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Inventory(PlayerInventoryStorage storage, Player player) {
|
||||||
|
this.storage= storage;
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player.getPlayer();
|
||||||
|
}
|
||||||
|
private PlayerInventory inv() {
|
||||||
|
return player.getInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
save(getPlayer().getGameMode());
|
||||||
|
}
|
||||||
|
public void save(GameMode gm) {
|
||||||
|
storage.getLog().debug(getPlayer().getName()+": store inventory: "+gm);
|
||||||
|
storage.store(this, Target.getTarget(gm));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
load(getPlayer().getGameMode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStored(GameMode gm) {
|
||||||
|
return storage.contains(this, Target.getTarget(gm));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(GameMode gm) {
|
||||||
|
storage.getLog().debug(getPlayer().getName()+": load inventory: "+gm);
|
||||||
|
storage.load(this, Target.getTarget(gm));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
inv().setArmorContents(new ItemStack[0]);
|
||||||
|
inv().clear();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package de.jaschastarke.minecraft.limitedcreative.inventories;
|
||||||
|
|
||||||
|
import de.jaschastarke.bukkit.lib.configuration.Configuration;
|
||||||
|
import de.jaschastarke.configuration.annotations.IConfigurationSubGroup;
|
||||||
|
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
|
||||||
|
import de.jaschastarke.maven.ArchiveDocComments;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
||||||
|
|
||||||
|
@ArchiveDocComments
|
||||||
|
public class InventoryConfig extends Configuration implements IConfigurationSubGroup {
|
||||||
|
protected ModInventories mod;
|
||||||
|
public InventoryConfig(ModInventories modInventories) {
|
||||||
|
mod = modInventories;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getNodeName() {
|
||||||
|
return "store";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SeparatedInventoryEnabled
|
||||||
|
*
|
||||||
|
* Use this option to disable the separated inventories feature, for the case you only need the other features.
|
||||||
|
*
|
||||||
|
* default: true
|
||||||
|
*/
|
||||||
|
@IsConfigurationNode
|
||||||
|
public boolean getEnabled() {
|
||||||
|
return config.getBoolean("enabled", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StoreCreative
|
||||||
|
*
|
||||||
|
* Should the creative-inventory also be stored on disk, when switching to survival?
|
||||||
|
* If disabled, the inventory gets cleared every time on switching to creative.
|
||||||
|
*
|
||||||
|
* default: true
|
||||||
|
*/
|
||||||
|
@IsConfigurationNode
|
||||||
|
public boolean getStoreCreative() {
|
||||||
|
return config.getBoolean("storeCreative", config.getBoolean("creative", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* default: false
|
||||||
|
*/
|
||||||
|
@IsConfigurationNode
|
||||||
|
public boolean getSeparateAdventure() {
|
||||||
|
return config.getBoolean("separateAdventure", config.getBoolean("adventure", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InventoryFolder
|
||||||
|
*
|
||||||
|
* The folder inside the datadir-folder (plugin/LimitedCreative) where the inventories are saved to.
|
||||||
|
* By default the inventories are saved to "plugin/LimitedCreative/inventories".
|
||||||
|
*
|
||||||
|
* default: "inventories"
|
||||||
|
*/
|
||||||
|
@IsConfigurationNode
|
||||||
|
public String getFolder() {
|
||||||
|
return config.getString("folder", "inventories");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,12 +17,13 @@
|
||||||
*/
|
*/
|
||||||
package de.jaschastarke.minecraft.limitedcreative.inventories;
|
package de.jaschastarke.minecraft.limitedcreative.inventories;
|
||||||
|
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.Hooks;
|
import de.jaschastarke.minecraft.limitedcreative.Hooks;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
||||||
|
@ -60,9 +61,9 @@ public class PlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLogout(PlayerQuitEvent event) {
|
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||||
if (event.getPlayer() != null) {
|
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
//mod.getInventories().remove(event.getPlayer());
|
mod.setCreativeArmor(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,170 @@
|
||||||
|
/*
|
||||||
|
* Limited Creative - (Bukkit Plugin)
|
||||||
|
* Copyright (C) 2012 jascha@ja-s.de
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.jaschastarke.minecraft.limitedcreative.inventories.store;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
public class Fallback {
|
||||||
|
|
||||||
|
public static void loadVersion1(PlayerInventory inv, ConfigurationSection sect) {
|
||||||
|
new Armor(inv).restore(sect.getConfigurationSection("armor"));
|
||||||
|
new Items(inv).restore(sect.getConfigurationSection("inv"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface Storeable {
|
||||||
|
public void store(ConfigurationSection section);
|
||||||
|
public void restore(ConfigurationSection section);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Items implements Storeable {
|
||||||
|
private PlayerInventory inv;
|
||||||
|
public Items(PlayerInventory pi) {
|
||||||
|
inv = pi;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void store(ConfigurationSection section) {
|
||||||
|
for (int i = 0; i < inv.getSize(); i++) {
|
||||||
|
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0)
|
||||||
|
sectionSetItem(section, String.valueOf(i), inv.getItem(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void restore(ConfigurationSection section) {
|
||||||
|
inv.clear();
|
||||||
|
for (int i = 0; i < inv.getSize(); i++) {
|
||||||
|
if (section.contains(String.valueOf(i)))
|
||||||
|
inv.setItem(i, sectionGetItem(section, String.valueOf(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sectionSetItem(ConfigurationSection section, String path, ItemStack item) {
|
||||||
|
//if (!Core.plugin.config.getUnsafeStorage()) {
|
||||||
|
section.set(path, item);
|
||||||
|
/*} else { // unsafe enchants fallback
|
||||||
|
Map<String, Object> serialize = item.serialize();
|
||||||
|
if (serialize.containsKey("type") && serialize.get("type") instanceof Material)
|
||||||
|
serialize.put("type", serialize.get("type").toString());
|
||||||
|
section.createSection(path, serialize);
|
||||||
|
};*/
|
||||||
|
}
|
||||||
|
public static ItemStack sectionGetItem(ConfigurationSection section, String path) {
|
||||||
|
if (section.isItemStack(path)) {
|
||||||
|
return section.getItemStack(path);
|
||||||
|
} else {
|
||||||
|
ConfigurationSection s = section.getConfigurationSection(path);
|
||||||
|
Material type = Material.getMaterial(s.getString("type"));
|
||||||
|
short damage = new Integer(s.getInt("damage", 0)).shortValue();
|
||||||
|
int amount = s.getInt("amaount", 1);
|
||||||
|
|
||||||
|
ItemStack result = new ItemStack(type, amount, damage);
|
||||||
|
Map<String, Object> item = section.getConfigurationSection(path).getValues(false);
|
||||||
|
item.remove("enchantments");
|
||||||
|
if (s.contains("enchantments")) {
|
||||||
|
for (Map.Entry<String, Object> entry : s.getConfigurationSection("enchantments").getValues(false).entrySet()) {
|
||||||
|
Enchantment enchantment = Enchantment.getByName(entry.getKey().toString());
|
||||||
|
if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
|
||||||
|
result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static Map<Integer, ItemStack> storeInventory(PlayerInventory inv) {
|
||||||
|
Map<Integer, ItemStack> map = new HashMap<Integer, ItemStack>();
|
||||||
|
for (int i = 0; i < inv.getSize(); i++) {
|
||||||
|
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) {
|
||||||
|
map.put(i, inv.getItem(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < inv.getArmorContents().length; i++) {
|
||||||
|
map.put((i * -1) - 1, inv.getArmorContents()[i]);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
public static void restoreInventory(PlayerInventory inv, Map<Integer, ItemStack> map) {
|
||||||
|
for (int i = 0; i < inv.getSize(); i++) {
|
||||||
|
if (map.containsKey(i)) {
|
||||||
|
inv.setItem(i, map.get(i));
|
||||||
|
} else {
|
||||||
|
inv.setItem(i, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < inv.getArmorContents().length; i++) {
|
||||||
|
int _i = (i * -1) - 1;
|
||||||
|
if (map.containsKey(_i)) {
|
||||||
|
inv.getArmorContents()[i] = map.get(_i);
|
||||||
|
} else {
|
||||||
|
inv.getArmorContents()[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Armor implements Storeable {
|
||||||
|
private PlayerInventory inv;
|
||||||
|
public Armor(PlayerInventory pi) {
|
||||||
|
inv = pi;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void store(ConfigurationSection section) {
|
||||||
|
if (inv.getHelmet() != null && inv.getHelmet().getTypeId() != 0)
|
||||||
|
Items.sectionSetItem(section, "helmet", inv.getHelmet());
|
||||||
|
if (inv.getChestplate() != null && inv.getChestplate().getTypeId() != 0)
|
||||||
|
Items.sectionSetItem(section, "chestplate", inv.getChestplate());
|
||||||
|
if (inv.getLeggings() != null && inv.getLeggings().getTypeId() != 0)
|
||||||
|
Items.sectionSetItem(section, "leggins", inv.getLeggings());
|
||||||
|
if (inv.getBoots() != null && inv.getBoots().getTypeId() != 0)
|
||||||
|
Items.sectionSetItem(section, "boots", inv.getBoots());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void restore(ConfigurationSection section) {
|
||||||
|
if (section.contains("helmet"))
|
||||||
|
inv.setHelmet(Items.sectionGetItem(section, "helmet"));
|
||||||
|
else
|
||||||
|
inv.setHelmet(null);
|
||||||
|
|
||||||
|
if (section.contains("chestplate"))
|
||||||
|
inv.setChestplate(Items.sectionGetItem(section, "chestplate"));
|
||||||
|
else
|
||||||
|
inv.setChestplate(null);
|
||||||
|
|
||||||
|
if (section.contains("leggins"))
|
||||||
|
inv.setLeggings(Items.sectionGetItem(section, "leggins"));
|
||||||
|
else
|
||||||
|
inv.setLeggings(null);
|
||||||
|
|
||||||
|
if (section.contains("boots"))
|
||||||
|
inv.setBoots(Items.sectionGetItem(section, "boots"));
|
||||||
|
else
|
||||||
|
inv.setBoots(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
* Limited Creative - (Bukkit Plugin)
|
||||||
|
* Copyright (C) 2012 jascha@ja-s.de
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.jaschastarke.minecraft.limitedcreative.inventories.store;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory;
|
||||||
|
|
||||||
|
abstract public class InvConfStorage extends PlayerInventoryStorage {
|
||||||
|
private static final int ARMOR_SIZE = 4;
|
||||||
|
|
||||||
|
public void store(Inventory pinv, ConfigurationSection sect) {
|
||||||
|
PlayerInventory inv = pinv.getPlayer().getInventory();
|
||||||
|
sect.set("version", 4);
|
||||||
|
/*if (Core.plugin.config.getUnsafeStorage())
|
||||||
|
sect.set("unsafe", true);*/
|
||||||
|
storeItems(sect.createSection("armor"), inv.getArmorContents());
|
||||||
|
storeItems(sect.createSection("inv"), inv.getContents());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(Inventory pinv, ConfigurationSection sect) {
|
||||||
|
PlayerInventory inv = pinv.getPlayer().getInventory();
|
||||||
|
|
||||||
|
if (!sect.contains("version")) {
|
||||||
|
Fallback.loadVersion1(inv, sect);
|
||||||
|
} else {
|
||||||
|
inv.setArmorContents(restoreItems(sect.getConfigurationSection("armor"), ARMOR_SIZE));
|
||||||
|
inv.setContents(restoreItems(sect.getConfigurationSection("inv"), inv.getSize()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void storeItems(ConfigurationSection sect, ItemStack[] items) {
|
||||||
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
ItemStack is = items[i];
|
||||||
|
if (is != null && is.getType() != Material.AIR) {
|
||||||
|
sect.set(String.valueOf(i), serialize(is));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected ItemStack[] restoreItems(ConfigurationSection sect, int size) {
|
||||||
|
ItemStack[] items = new ItemStack[size];
|
||||||
|
if (sect != null) {
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
if (sect.contains(String.valueOf(i))) {
|
||||||
|
if (sect.isItemStack(String.valueOf(i))) {
|
||||||
|
items[i] = sect.getItemStack(String.valueOf(i));
|
||||||
|
} else {
|
||||||
|
items[i] = deserializeItemStack(sect.get(String.valueOf(i)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
items[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Object serialize(ItemStack is) {/*
|
||||||
|
if (Core.plugin.config.getUnsafeStorage()) {
|
||||||
|
return getRecursiveSerialized(is);
|
||||||
|
}*/
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected ItemStack deserializeItemStack(Object is) {
|
||||||
|
if (is instanceof ConfigurationSection) {
|
||||||
|
ConfigurationSection sect = (ConfigurationSection) is;
|
||||||
|
Material type = Material.getMaterial(sect.getString("type"));
|
||||||
|
short damage = new Integer(sect.getInt("damage", 0)).shortValue();
|
||||||
|
int amount = sect.getInt("amount", 1);
|
||||||
|
|
||||||
|
ItemStack result = new ItemStack(type, amount, damage);
|
||||||
|
if (sect.contains("enchantments")) { // conf-version 2
|
||||||
|
for (Map.Entry<String, Object> entry : sect.getConfigurationSection("enchantments").getValues(false).entrySet()) {
|
||||||
|
Enchantment enchantment = Enchantment.getByName(entry.getKey().toString());
|
||||||
|
if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
|
||||||
|
result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sect.contains("tag")) { // Backward compatibility for 1.4.5-R0.2; Was Conf-Version 2, but should be 3 ;)
|
||||||
|
ConfigurationSection tag = sect.getConfigurationSection("tag");
|
||||||
|
ItemMeta meta = result.getItemMeta();
|
||||||
|
meta.setDisplayName(tag.getString("name"));
|
||||||
|
result.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else if (is instanceof Map) {
|
||||||
|
return ItemStack.deserialize((Map<String, Object>) is);
|
||||||
|
} else {
|
||||||
|
getLog().warn("Failed to restore Item: "+is.toString());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*protected static Map<String, Object> getRecursiveSerialized(ConfigurationSerializable conf) {
|
||||||
|
Map<String, Object> serialized = new HashMap<String, Object>(conf.serialize()); // de-immutable
|
||||||
|
for (Map.Entry<String, Object> entry : serialized.entrySet()) {
|
||||||
|
if (entry.getValue() instanceof ConfigurationSerializable) {
|
||||||
|
entry.setValue(getRecursiveSerialized((ConfigurationSerializable) entry.getValue())); // immutable
|
||||||
|
//serialized.put(entry.getKey(), getRecursiveSerialized((ConfigurationSerializable) entry.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return serialized;
|
||||||
|
}*/
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* Limited Creative - (Bukkit Plugin)
|
||||||
|
* Copyright (C) 2012 jascha@ja-s.de
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.jaschastarke.minecraft.limitedcreative.inventories.store;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||||
|
import de.jaschastarke.bukkit.lib.ModuleLogger;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory.Target;
|
||||||
|
|
||||||
|
public class InvYamlStorage extends InvConfStorage {
|
||||||
|
private static final String SUFFIX = ".yml";
|
||||||
|
|
||||||
|
private CoreModule<?> mod;
|
||||||
|
private File dir;
|
||||||
|
public InvYamlStorage(CoreModule<?> mod, File file) {
|
||||||
|
this.mod = mod;
|
||||||
|
dir = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModuleLogger getLog() {
|
||||||
|
return mod.getLog();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(Inventory pinv, Target target) {
|
||||||
|
load(pinv, YamlConfiguration.loadConfiguration(getFile(pinv, target)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void store(Inventory pinv, Target target) {
|
||||||
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
|
yml.options().header("DO NOT MODIFY THIS FILE");
|
||||||
|
store(pinv, yml);
|
||||||
|
try {
|
||||||
|
yml.save(getFile(pinv, target));
|
||||||
|
} catch (IOException e) {
|
||||||
|
mod.getLog().warn("Failed to save Inventory for Player " + pinv.getPlayer().getName());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(Inventory pinv, Target target) {
|
||||||
|
getFile(pinv, target).delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Inventory pinv, Target target) {
|
||||||
|
return getFile(pinv, target).exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected File getFile(Inventory pinv, Target target) {
|
||||||
|
if (target != default_target) {
|
||||||
|
return new File(dir, pinv.getPlayer().getName() + "_" + target.toString().toLowerCase() + SUFFIX);
|
||||||
|
} else {
|
||||||
|
return new File(dir, pinv.getPlayer().getName() + SUFFIX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Limited Creative - (Bukkit Plugin)
|
||||||
|
* Copyright (C) 2012 jascha@ja-s.de
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.jaschastarke.minecraft.limitedcreative.inventories.store;
|
||||||
|
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory.Target;
|
||||||
|
import de.jaschastarke.utils.ISimpleLogger;
|
||||||
|
|
||||||
|
public abstract class PlayerInventoryStorage {
|
||||||
|
protected Target default_target = Target.SURVIVAL;
|
||||||
|
abstract public ISimpleLogger getLog();
|
||||||
|
|
||||||
|
final public void store(Inventory pinv) {
|
||||||
|
store(pinv, default_target);
|
||||||
|
}
|
||||||
|
final public void load(Inventory pinv) {
|
||||||
|
load(pinv, default_target);
|
||||||
|
}
|
||||||
|
final public void remove(Inventory pinv) {
|
||||||
|
remove(pinv, default_target);
|
||||||
|
}
|
||||||
|
final public boolean contains(Inventory pinv) {
|
||||||
|
return contains(pinv, default_target);
|
||||||
|
}
|
||||||
|
abstract public void store(Inventory pinv, Target target);
|
||||||
|
abstract public void load(Inventory pinv, Target target);
|
||||||
|
abstract public void remove(Inventory pinv, Target target);
|
||||||
|
abstract public boolean contains(Inventory pinv, Target target);
|
||||||
|
}
|
Loading…
Reference in a new issue