From c37feb469e6da8d73128b8ebfb0d85d85ef2a425 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 14 Jan 2016 22:36:25 +0100 Subject: [PATCH] Editor Nullable --- .../massivecore/command/editor/CommandEditAbstract.java | 6 ++++++ .../command/editor/CommandEditCollection.java | 8 ++++++-- .../command/editor/CommandEditItemStacks.java | 9 +++++++-- .../massivecore/command/editor/CommandEditMap.java | 8 ++++++-- .../massivecore/command/editor/CommandEditSimple.java | 3 +++ .../massivecore/command/editor/Property.java | 4 ++++ 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java b/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java index 9010e610..0af87bcf 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java @@ -249,4 +249,10 @@ public class CommandEditAbstract extends MassiveCommand msg("%s for %s: %s", descProperty, descObject, descValue); } + public void requireNullable() throws MassiveException + { + if (this.getProperty().isNullable()) return; + throw new MassiveException().addMsg("%s can not be null.", this.getPropertyName()); + } + } diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditCollection.java b/src/com/massivecraft/massivecore/command/editor/CommandEditCollection.java index 1fb905a9..e51e3b8d 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditCollection.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditCollection.java @@ -15,8 +15,12 @@ public class CommandEditCollection> extends CommandEd // Children this.addChild(new CommandEditShow(settings, property)); - this.addChild(new CommandEditCreate(settings, property)); - this.addChild(new CommandEditDelete(settings, property)); + + if (property.isNullable()) + { + this.addChild(new CommandEditCreate(settings, property)); + this.addChild(new CommandEditDelete(settings, property)); + } this.addChild(new CommandEditCollectionAdd(settings, property)); this.addChild(new CommandEditCollectionInsert(settings, property)); diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditItemStacks.java b/src/com/massivecraft/massivecore/command/editor/CommandEditItemStacks.java index dc5c05a6..ddc7f3c9 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditItemStacks.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditItemStacks.java @@ -17,8 +17,13 @@ public class CommandEditItemStacks extends CommandEditAbstract>(settings, property)); - this.addChild(new CommandEditCreate>(settings, property)); - this.addChild(new CommandEditDelete>(settings, property)); + + if (property.isNullable()) + { + this.addChild(new CommandEditCreate>(settings, property)); + this.addChild(new CommandEditDelete>(settings, property)); + } + this.addChild(new CommandEditItemStacksOpen(settings, property)); } diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditMap.java b/src/com/massivecraft/massivecore/command/editor/CommandEditMap.java index fd008756..1d76a6f1 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditMap.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditMap.java @@ -15,8 +15,12 @@ public class CommandEditMap> extends CommandEditAbstract< // Children this.addChild(new CommandEditShow(settings, property)); - this.addChild(new CommandEditCreate(settings, property)); - this.addChild(new CommandEditDelete(settings, property)); + + if (property.isNullable()) + { + this.addChild(new CommandEditCreate(settings, property)); + this.addChild(new CommandEditDelete(settings, property)); + } this.addChild(new CommandEditMapPut(settings, property)); this.addChild(new CommandEditMapRemove(settings, property)); diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditSimple.java b/src/com/massivecraft/massivecore/command/editor/CommandEditSimple.java index 2c4b90f3..a50db327 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditSimple.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditSimple.java @@ -39,6 +39,9 @@ public class CommandEditSimple extends CommandEditAbstract // Arguments V after = this.readArg(); + // Validate + if (after == null) this.requireNullable(); + // Apply this.attemptSet(after); } diff --git a/src/com/massivecraft/massivecore/command/editor/Property.java b/src/com/massivecraft/massivecore/command/editor/Property.java index 7e08a3d3..9ae90976 100644 --- a/src/com/massivecraft/massivecore/command/editor/Property.java +++ b/src/com/massivecraft/massivecore/command/editor/Property.java @@ -43,6 +43,10 @@ public abstract class Property implements Named public boolean isEditable() { return this.editable; } public void setEditable(boolean editable) { this.editable = editable; } + protected boolean nullable = true; + public boolean isNullable() { return this.nullable; } + public void setNullable(boolean nullable) { this.nullable = nullable; } + // -------------------------------------------- // // NAME // -------------------------------------------- //