Armory load fix
use "current" to set InventoryArmor from ingame command
This commit is contained in:
parent
fd3c9da9ff
commit
c7abaa7444
5 changed files with 73 additions and 18 deletions
|
@ -69,6 +69,9 @@ public class ModInventories extends CoreModule<LimitedCreative> {
|
||||||
public InventoryConfig getConfig() {
|
public InventoryConfig getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
public ArmoryConfig getArmorConfig() {
|
||||||
|
return armor_config;
|
||||||
|
}
|
||||||
|
|
||||||
public PlayerInventoryStorage getStorage() {
|
public PlayerInventoryStorage getStorage() {
|
||||||
return storage;
|
return storage;
|
||||||
|
@ -119,6 +122,7 @@ public class ModInventories extends CoreModule<LimitedCreative> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreativeArmor(Player player) {
|
public void setCreativeArmor(Player player) {
|
||||||
|
if (!getPlugin().getPermManager().hasPermission(player, InventoryPermissions.BYPASS_CREATIVE_ARMOR)) {
|
||||||
Map<String, ItemStack> armor = armor_config.getCreativeArmor();
|
Map<String, ItemStack> armor = armor_config.getCreativeArmor();
|
||||||
if (armor != null) {
|
if (armor != null) {
|
||||||
ItemStack[] is = new ItemStack[4];
|
ItemStack[] is = new ItemStack[4];
|
||||||
|
@ -134,3 +138,4 @@ public class ModInventories extends CoreModule<LimitedCreative> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.bukkit.material.MaterialData;
|
||||||
import de.jaschastarke.bukkit.lib.ModuleLogger;
|
import de.jaschastarke.bukkit.lib.ModuleLogger;
|
||||||
import de.jaschastarke.bukkit.lib.configuration.Configuration;
|
import de.jaschastarke.bukkit.lib.configuration.Configuration;
|
||||||
import de.jaschastarke.bukkit.lib.configuration.ConfigurationContainer;
|
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.MaterialDataNotRecognizedException;
|
||||||
import de.jaschastarke.bukkit.lib.items.MaterialNotRecognizedException;
|
import de.jaschastarke.bukkit.lib.items.MaterialNotRecognizedException;
|
||||||
import de.jaschastarke.bukkit.lib.items.ItemUtils;
|
import de.jaschastarke.bukkit.lib.items.ItemUtils;
|
||||||
|
@ -26,7 +27,7 @@ import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
||||||
*/
|
*/
|
||||||
@ArchiveDocComments
|
@ArchiveDocComments
|
||||||
@PluginConfigurations(parent = InventoryConfig.class)
|
@PluginConfigurations(parent = InventoryConfig.class)
|
||||||
public class ArmoryConfig extends Configuration implements IConfigurationSubGroup {
|
public class ArmoryConfig extends Configuration implements IConfigurationSubGroup, ICommandConfigCallback {
|
||||||
protected ModInventories mod;
|
protected ModInventories mod;
|
||||||
|
|
||||||
public ArmoryConfig(ConfigurationContainer container) {
|
public ArmoryConfig(ConfigurationContainer container) {
|
||||||
|
@ -71,7 +72,7 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
|
||||||
if (getEnabled()) {
|
if (getEnabled()) {
|
||||||
Map<String, ItemStack> armor = new HashMap<String, ItemStack>();
|
Map<String, ItemStack> armor = new HashMap<String, ItemStack>();
|
||||||
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
|
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) {
|
if (entry.getValue() instanceof ItemStack) {
|
||||||
armor.put(entry.getKey(), (ItemStack) entry.getValue());
|
armor.put(entry.getKey(), (ItemStack) entry.getValue());
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,9 +98,11 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
|
||||||
/**
|
/**
|
||||||
* InventoryCreativeArmorItems
|
* 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
|
* *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)
|
@IsConfigurationNode(order = 500)
|
||||||
public Object getHead() {
|
public Object getHead() {
|
||||||
|
@ -118,10 +121,40 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
|
||||||
return config.get("feet", "CHAINMAIL_BOOTS");
|
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) {
|
public String L(String msg, Object... objects) {
|
||||||
return mod.getPlugin().getLocale().trans(msg, objects);
|
return mod.getPlugin().getLocale().trans(msg, objects);
|
||||||
}
|
}
|
||||||
public ModuleLogger getLog() {
|
public ModuleLogger getLog() {
|
||||||
return mod.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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG
|
||||||
super(container);
|
super(container);
|
||||||
}
|
}
|
||||||
public InventoryConfig(ModInventories modInventories, ModuleEntry<IModule> modEntry) {
|
public InventoryConfig(ModInventories modInventories, ModuleEntry<IModule> modEntry) {
|
||||||
super(modInventories.getPlugin());
|
super(modInventories.getPlugin().getDocCommentStorage());
|
||||||
mod = modInventories;
|
mod = modInventories;
|
||||||
entry = modEntry;
|
entry = modEntry;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,4 +39,9 @@ public class InventoryPermissions extends SimplePermissionContainer {
|
||||||
* Allows bypassing the inventory separation
|
* Allows bypassing the inventory separation
|
||||||
*/
|
*/
|
||||||
public static final IPermission KEEP_INVENTORY = new BasicPermission(Permissions.CONTAINER, "keepinventory", PermissionDefault.FALSE);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,10 +49,22 @@ public class PlayerListener implements Listener {
|
||||||
mod.onSetGameMode(event.getPlayer(), event.getNewGameMode());
|
mod.onSetGameMode(event.getPlayer(), event.getNewGameMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
mod.setCreativeArmor(event.getPlayer());
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue