Editor - Only add edit parameter if editable

This commit is contained in:
BuildTools 2016-02-03 20:30:03 +01:00 committed by Olof Larsson
parent 03d224e953
commit f6815d4c45
5 changed files with 49 additions and 15 deletions

View File

@ -162,6 +162,16 @@ public class MassiveCommand
return this.getChildren().size() > 0;
}
public List<MassiveCommand> getVisibleChildren(CommandSender watcher)
{
List<MassiveCommand> ret = new MassiveList<>();
for (MassiveCommand child : this.getChildren())
{
if (child.isVisibleTo(watcher)) ret.add(child);
}
return ret;
}
// -------------------------------------------- //
// CHILDREN > GET
// -------------------------------------------- //

View File

@ -45,7 +45,8 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
this.setAliases(this.getProperty().getNames());
// Desc
this.setDesc("edit " + this.getProperty().getName());
String descAction = property.isEditable() ? "edit " : "show ";
this.setDesc(descAction + this.getProperty().getName());
// Requirements
this.addRequirements(RequirementEditorUse.get());
@ -65,9 +66,23 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
public void perform() throws MassiveException
{
if (this.isParent())
{
// If there is only one visible child, and it is a show command ....
// Note: We use the visible children because HelpCommand is always present, but often invisible.
List<MassiveCommand> children = this.getVisibleChildren(this.sender);
if (children.size() == 1 && children.get(0) instanceof CommandEditShow)
{
// ... skip directly to it.
CommandEditShow<?, ?> cmd = (CommandEditShow<?, ?>) children.get(0);
List<MassiveCommand> chain = this.getChain();
chain.add(this);
cmd.execute(this.sender, this.args, chain);
}
else
{
super.perform();
}
}
else
{
msg("<b>Not yet implemented.");

View File

@ -20,6 +20,8 @@ public class CommandEditContainer<O, V> extends CommandEditAbstract<O, V>
this.addChild(new CommandEditDelete<O, V>(settings, property));
}
if (property.isEditable())
{
this.addChild(new CommandEditContainerAdd<O, V>(settings, property));
this.addChild(new CommandEditContainerInsert<O, V>(settings, property));
this.addChild(new CommandEditContainerSet<O, V>(settings, property));
@ -34,5 +36,6 @@ public class CommandEditContainer<O, V> extends CommandEditAbstract<O, V>
this.addChild(new CommandEditContainerClear<O, V>(settings, property));
}
}
}

View File

@ -24,7 +24,10 @@ public class CommandEditItemStacks<O> extends CommandEditAbstract<O, List<ItemSt
this.addChild(new CommandEditDelete<O, List<ItemStack>>(settings, property));
}
if (property.isEditable())
{
this.addChild(new CommandEditItemStacksOpen<O>(settings, property));
}
}
}

View File

@ -16,8 +16,11 @@ public class CommandEditSimple<O, V> extends CommandEditAbstract<O, V>
super(settings, property, null);
// Parameters
if (property.isEditable())
{
this.addParameter(TypeNullable.get(this.getProperty().getValueType()), "set", "show", true);
}
}
// -------------------------------------------- //
// OVERRIDE