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; 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 // CHILDREN > GET
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -45,7 +45,8 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
this.setAliases(this.getProperty().getNames()); this.setAliases(this.getProperty().getNames());
// Desc // Desc
this.setDesc("edit " + this.getProperty().getName()); String descAction = property.isEditable() ? "edit " : "show ";
this.setDesc(descAction + this.getProperty().getName());
// Requirements // Requirements
this.addRequirements(RequirementEditorUse.get()); this.addRequirements(RequirementEditorUse.get());
@ -66,7 +67,21 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
{ {
if (this.isParent()) if (this.isParent())
{ {
super.perform(); // 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 else
{ {

View File

@ -20,19 +20,22 @@ public class CommandEditContainer<O, V> extends CommandEditAbstract<O, V>
this.addChild(new CommandEditDelete<O, V>(settings, property)); this.addChild(new CommandEditDelete<O, V>(settings, property));
} }
this.addChild(new CommandEditContainerAdd<O, V>(settings, property)); if (property.isEditable())
this.addChild(new CommandEditContainerInsert<O, V>(settings, property));
this.addChild(new CommandEditContainerSet<O, V>(settings, property));
this.addChild(new CommandEditContainerRemove<O, V>(settings, property));
this.addChild(new CommandEditContainerRemoveIndex<O, V>(settings, property));
if ( ! property.getValueType().isContainerSorted() && property.getValueType().getContainerComparator() == null)
{ {
this.addChild(new CommandEditContainerMove<O, V>(settings, property)); this.addChild(new CommandEditContainerAdd<O, V>(settings, property));
this.addChild(new CommandEditContainerSwap<O, V>(settings, property)); this.addChild(new CommandEditContainerInsert<O, V>(settings, property));
} this.addChild(new CommandEditContainerSet<O, V>(settings, property));
this.addChild(new CommandEditContainerRemove<O, V>(settings, property));
this.addChild(new CommandEditContainerRemoveIndex<O, V>(settings, property));
this.addChild(new CommandEditContainerClear<O, V>(settings, property)); if ( ! property.getValueType().isContainerSorted() && property.getValueType().getContainerComparator() == null)
{
this.addChild(new CommandEditContainerMove<O, V>(settings, property));
this.addChild(new CommandEditContainerSwap<O, V>(settings, property));
}
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)); this.addChild(new CommandEditDelete<O, List<ItemStack>>(settings, property));
} }
this.addChild(new CommandEditItemStacksOpen<O>(settings, property)); if (property.isEditable())
{
this.addChild(new CommandEditItemStacksOpen<O>(settings, property));
}
} }
} }

View File

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