Armory load fix

use "current" to set InventoryArmor from ingame command
This commit is contained in:
Jascha Starke 2013-09-28 23:53:43 +02:00
parent fd3c9da9ff
commit c7abaa7444
5 changed files with 73 additions and 18 deletions

View file

@ -69,6 +69,9 @@ public class ModInventories extends CoreModule<LimitedCreative> {
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<LimitedCreative> {
}
public void setCreativeArmor(Player player) {
Map<String, ItemStack> 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<String, ItemStack> 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);
}
}
}
}

View file

@ -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<String, ItemStack> armor = new HashMap<String, ItemStack>();
for (Map.Entry<String, Object> 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() {
@ -118,10 +121,40 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
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);
}
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());
}
}
}
}
}

View file

@ -31,7 +31,7 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG
super(container);
}
public InventoryConfig(ModInventories modInventories, ModuleEntry<IModule> modEntry) {
super(modInventories.getPlugin());
super(modInventories.getPlugin().getDocCommentStorage());
mod = modInventories;
entry = modEntry;
}

View file

@ -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);
}

View file

@ -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);
}
}
}
}*/
}