diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditProperties.java b/src/com/massivecraft/massivecore/command/editor/CommandEditProperties.java index de5bb7f9..7ff7d2e0 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditProperties.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditProperties.java @@ -8,21 +8,21 @@ public class CommandEditProperties extends CommandEditAbstract // CONSTRUCT // -------------------------------------------- // - public CommandEditProperties(EditSettings settings, Property property) + public CommandEditProperties(EditSettings parentSettings, Property childProperty) { // Super - super(settings, property, null); + super(parentSettings, childProperty, null); - this.addChild(new CommandEditShow<>(settings, property)); + this.addChild(new CommandEditShow<>(parentSettings, childProperty)); // Parameters - if (property.isEditable()) + if (childProperty.isEditable()) { Type type = this.getValueType(); - EditSettings fieldSettings = new EditSettingsDelegate<>(settings, property); + EditSettings childSettings = new EditSettings<>(parentSettings, childProperty); for (Property prop : type.getInnerProperties()) { - this.addChild(prop.createEditCommand(fieldSettings)); + this.addChild(prop.createEditCommand(childSettings)); } } } diff --git a/src/com/massivecraft/massivecore/command/editor/EditSettings.java b/src/com/massivecraft/massivecore/command/editor/EditSettings.java index c784ee8a..6f8a829d 100644 --- a/src/com/massivecraft/massivecore/command/editor/EditSettings.java +++ b/src/com/massivecraft/massivecore/command/editor/EditSettings.java @@ -17,6 +17,43 @@ import com.massivecraft.massivecore.util.Txt; public class EditSettings { + // -------------------------------------------- // + // PARENTS + // -------------------------------------------- // + + private EditSettings parent = null; + public EditSettings getParent() { return this.parent; } + public void setParent(EditSettings parent) { this.parent = parent; } + public boolean hasParent() { return this.getParent() != null; } + + public List> getParents() + { + // Create + List> ret = new MassiveList<>(); + + // Fill + EditSettings parent = this; + while (parent.hasParent()) + { + parent = parent.getParent(); + ret.add(parent); + } + + // Return + return ret; + } + + public boolean isRoot() { return ! this.hasParent(); } + public EditSettings getRoot() + { + EditSettings ret = this; + while (ret.hasParent()) + { + ret = ret.getParent(); + } + return ret; + } + // -------------------------------------------- // // FIELDS // -------------------------------------------- // @@ -60,13 +97,13 @@ public class EditSettings public void addPropertyRequirements(Requirement... requirements) { this.addPropertyRequirements(Arrays.asList(requirements)); } // -------------------------------------------- // - // INSTANCE & CONSTRUCT + // CONSTRUCT > NORMAL // -------------------------------------------- // - public EditSettings(Type objectType, Property objectProperty) + public EditSettings(Type objectType, Property usedProperty) { this.objectType = objectType; - this.usedProperty = objectProperty; + this.usedProperty = usedProperty; } public EditSettings(Type objectType) @@ -74,6 +111,40 @@ public class EditSettings this(objectType, null); } + // -------------------------------------------- // + // CONSTRUCT > DELEGATE + // -------------------------------------------- // + + public

EditSettings(final EditSettings

parentSettings, final Property childProperty) + { + this(childProperty.getValueType()); + + this.setParent(parentSettings); + + PropertyUsed usedProperty = new PropertyUsed(this) { + + @Override + public O getRaw(CommandSender sender) + { + P parentUsed = parentSettings.getUsed(sender); + return childProperty.getRaw(parentUsed); + } + + @Override + public CommandSender setRaw(CommandSender sender, O used) + { + P parentUsed = parentSettings.getUsed(sender); + childProperty.setRaw(parentUsed, used); + return sender; + } + + }; + this.setUsedProperty(usedProperty); + + this.addUsedRequirements(parentSettings.getPropertyRequirements()); + this.addUsedRequirements(childProperty.getRequirements()); + } + // -------------------------------------------- // // OBJECT // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/command/editor/EditSettingsDelegate.java b/src/com/massivecraft/massivecore/command/editor/EditSettingsDelegate.java deleted file mode 100644 index 7ee4830e..00000000 --- a/src/com/massivecraft/massivecore/command/editor/EditSettingsDelegate.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.massivecraft.massivecore.command.editor; - -import org.bukkit.command.CommandSender; - -public class EditSettingsDelegate extends EditSettings -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - public EditSettingsDelegate(final EditSettings outerSettings, final Property property) - { - super(property.getValueType()); - - PropertyUsed usedProperty = new PropertyUsed(this) { - - @Override - public V getRaw(CommandSender sender) - { - return property.getRaw(outerSettings.getUsed(sender)); - } - - @Override - public CommandSender setRaw(CommandSender sender, V used) - { - property.setRaw(outerSettings.getUsed(sender), used); - return sender; - } - - }; - this.setUsedProperty(usedProperty); - - this.addUsedRequirements(outerSettings.getPropertyRequirements()); - this.addUsedRequirements(property.getRequirements()); - } - -}