From c7abaa7444c1ef91069dad8c82412fd3bbd621c3 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 28 Sep 2013 23:53:43 +0200 Subject: [PATCH] Armory load fix use "current" to set InventoryArmor from ingame command --- .../limitedcreative/ModInventories.java | 29 +++++++------ .../inventories/ArmoryConfig.java | 41 +++++++++++++++++-- .../inventories/InventoryConfig.java | 2 +- .../inventories/InventoryPermissions.java | 5 +++ .../inventories/PlayerListener.java | 14 ++++++- 5 files changed, 73 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java index f5a0538..2858e08 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java @@ -69,6 +69,9 @@ public class ModInventories extends CoreModule { public InventoryConfig getConfig() { return config; } + public ArmoryConfig getArmorConfig() { + return armor_config; + } public PlayerInventoryStorage getStorage() { return storage; @@ -119,18 +122,20 @@ public class ModInventories extends CoreModule { } public void setCreativeArmor(Player player) { - Map armor = armor_config.getCreativeArmor(); - if (armor != null) { - ItemStack[] is = new ItemStack[4]; - if (armor.containsKey("feet")) - is[0] = armor.get("feet"); - if (armor.containsKey("legs")) - is[1] = armor.get("legs"); - if (armor.containsKey("chest")) - is[2] = armor.get("chest"); - if (armor.containsKey("head")) - is[3] = armor.get("head"); - player.getInventory().setArmorContents(is); + if (!getPlugin().getPermManager().hasPermission(player, InventoryPermissions.BYPASS_CREATIVE_ARMOR)) { + Map armor = armor_config.getCreativeArmor(); + if (armor != null) { + ItemStack[] is = new ItemStack[4]; + if (armor.containsKey("feet")) + is[0] = armor.get("feet"); + if (armor.containsKey("legs")) + is[1] = armor.get("legs"); + if (armor.containsKey("chest")) + is[2] = armor.get("chest"); + if (armor.containsKey("head")) + is[3] = armor.get("head"); + player.getInventory().setArmorContents(is); + } } } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/ArmoryConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/ArmoryConfig.java index 4af6e2d..56b2afe 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/ArmoryConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/ArmoryConfig.java @@ -10,6 +10,7 @@ import org.bukkit.material.MaterialData; import de.jaschastarke.bukkit.lib.ModuleLogger; import de.jaschastarke.bukkit.lib.configuration.Configuration; import de.jaschastarke.bukkit.lib.configuration.ConfigurationContainer; +import de.jaschastarke.bukkit.lib.configuration.command.ICommandConfigCallback; import de.jaschastarke.bukkit.lib.items.MaterialDataNotRecognizedException; import de.jaschastarke.bukkit.lib.items.MaterialNotRecognizedException; import de.jaschastarke.bukkit.lib.items.ItemUtils; @@ -26,7 +27,7 @@ import de.jaschastarke.minecraft.limitedcreative.ModInventories; */ @ArchiveDocComments @PluginConfigurations(parent = InventoryConfig.class) -public class ArmoryConfig extends Configuration implements IConfigurationSubGroup { +public class ArmoryConfig extends Configuration implements IConfigurationSubGroup, ICommandConfigCallback { protected ModInventories mod; public ArmoryConfig(ConfigurationContainer container) { @@ -71,7 +72,7 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou if (getEnabled()) { Map armor = new HashMap(); for (Map.Entry entry : config.getValues(false).entrySet()) { - if (!entry.getKey().equals("enabled")) { + if (!entry.getKey().equals("enabled") && !entry.getKey().equals("fixed")) { if (entry.getValue() instanceof ItemStack) { armor.put(entry.getKey(), (ItemStack) entry.getValue()); } else { @@ -97,9 +98,11 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou /** * InventoryCreativeArmorItems * - * Allows changing of the "Creative-Armor" to be wear when in creative mode - * + * Allows changing of the "Creative-Armor" to be wear when in creative mode. * *see Blacklist for details on Item-Types + * + * When using commands to change this options, use "current" (without quotes) to set it to the currently wearing item. + * This way you can easily set it to dyed leather armor. */ @IsConfigurationNode(order = 500) public Object getHead() { @@ -117,6 +120,18 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou public Object getFeet() { return config.get("feet", "CHAINMAIL_BOOTS"); } + + /* -- Doesn't work, because of bugged bukkit... the event isn't fired if you try again --* + * InventoryCreativeArmorFixed + * + * Prevent players from changing armor while in creative. + * + * default: true + *//* + @IsConfigurationNode(order = 600, name = "fixed") + public boolean getFixedArmor() { + return config.getBoolean("fixed", true); + }*/ public String L(String msg, Object... objects) { return mod.getPlugin().getLocale().trans(msg, objects); @@ -124,4 +139,22 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou public ModuleLogger getLog() { return mod.getLog(); } + @Override + public void onConfigCommandChange(Callback cb) { + String n = cb.getNode().getName(); + if (n.equals("head") || n.equals("chest") || n.equals("legs") || n.equals("feet")) { + if (cb.getValue().equals("current") || cb.getValue().equals("this")) { + if (cb.getContext().isPlayer()) { + if (n.equals("head")) + cb.setValue(cb.getContext().getPlayer().getInventory().getHelmet()); + if (n.equals("chest")) + cb.setValue(cb.getContext().getPlayer().getInventory().getChestplate()); + if (n.equals("legs")) + cb.setValue(cb.getContext().getPlayer().getInventory().getLeggings()); + if (n.equals("feet")) + cb.setValue(cb.getContext().getPlayer().getInventory().getBoots()); + } + } + } + } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java index 6f05a80..ec6ab59 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java @@ -31,7 +31,7 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG super(container); } public InventoryConfig(ModInventories modInventories, ModuleEntry modEntry) { - super(modInventories.getPlugin()); + super(modInventories.getPlugin().getDocCommentStorage()); mod = modInventories; entry = modEntry; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryPermissions.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryPermissions.java index 1249c47..21e112d 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryPermissions.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryPermissions.java @@ -39,4 +39,9 @@ public class InventoryPermissions extends SimplePermissionContainer { * Allows bypassing the inventory separation */ public static final IPermission KEEP_INVENTORY = new BasicPermission(Permissions.CONTAINER, "keepinventory", PermissionDefault.FALSE); + + /** + * Allows bypassing creative armor settings. No armor is changed on going to creative. + */ + public static final IPermission BYPASS_CREATIVE_ARMOR = new BasicPermission(Permissions.CONTAINER, "bypass_creativearmor", PermissionDefault.FALSE); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/PlayerListener.java index bc0624d..1e466d3 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/PlayerListener.java @@ -49,10 +49,22 @@ public class PlayerListener implements Listener { mod.onSetGameMode(event.getPlayer(), event.getNewGameMode()); } - @EventHandler + @EventHandler(ignoreCancelled = true) public void onPlayerRespawn(PlayerRespawnEvent event) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { mod.setCreativeArmor(event.getPlayer()); } } + + /*@EventHandler(ignoreCancelled = true) + public void onCreativeInventory(InventoryCreativeEvent event) { + if (event.getWhoClicked() instanceof Player) { + Player player = (Player) event.getWhoClicked(); + if (event.getSlotType() == SlotType.ARMOR && mod.getArmorConfig().getFixedArmor()) { + if (!mod.getPlugin().getPermManager().hasPermission(player, InventoryPermissions.BYPASS_CREATIVE_ARMOR)) { + event.setCancelled(true); + } + } + } + }*/ }