diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java b/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java index 93e73ee5..740a1871 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java @@ -118,18 +118,27 @@ public class CommandEditAbstract extends MassiveCommand if (event.isCancelled()) return; after = event.getAfter(); - // Setup - String descProperty = this.getProperty().getDisplayName(); - String descObject = this.getObjectVisual(); - String descValue = this.getInheritedVisual(source, before); - // NoChange // We check, inform and cancel on equality. if (this.getValueType().equals(before, after)) { - msg("%s for %s already: %s", descProperty, descObject, descValue); + message(this.attemptSetNochangeMessage()); return; } + this.attemptSetPerform(after); + } + + protected String attemptSetNochangeMessage() + { + + return Txt.parse("%s for %s already: %s", this.getProperty().getDisplayName(), this.getObjectVisual(), this.getInheritedVisual()); + } + + protected void attemptSetPerform(V after) + { + String descProperty = this.getProperty().getDisplayName(); + String descObject = this.getObjectVisual(); + String descValue = this.getInheritedVisual(); // Create messages List messages = new MassiveList<>(); diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditContainerAbstract.java b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerAbstract.java index 4808968d..c0a23ba7 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditContainerAbstract.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerAbstract.java @@ -1,9 +1,11 @@ package com.massivecraft.massivecore.command.editor; import java.util.AbstractMap.SimpleImmutableEntry; +import java.util.Collection; import java.util.List; import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.command.requirement.RequirementEditorPropertyCreated; import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.command.type.TypeNullable; @@ -78,6 +80,49 @@ public abstract class CommandEditContainerAbstract extends CommandEditAbst return alias; } + // -------------------------------------------- // + // ATTEMPT SET + // -------------------------------------------- // + + @Override + public String attemptSetNochangeMessage() + { + return Txt.parse("%s for %s was not changed.", this.getProperty().getDisplayName(), this.getObjectVisual()); + } + + @SuppressWarnings("unchecked") + @Override + public void attemptSetPerform(V after) + { + V before = this.getInheritedValue(); + String descProperty = this.getProperty().getDisplayName(); + + // Apply + // We set the new property value. + this.getProperty().setValue(this.getObject(), after); + + // Create messages + List messages = new MassiveList<>(); + + messages.add(Txt.parse("%s for %s edited:", descProperty, this.getObjectVisual())); + + // Note: The result of getAdditions is not actually V, but the implementation doesn't care. + Collection additions = ContainerUtil.getAdditions(before, after); + if ( ! additions.isEmpty()) + { + messages.add(Txt.parse("Additions: %s", this.getValueType().getVisual((V) additions))); + } + + // Note: The result of getDeletions is not actually V, but the implementation doesn't care. + Collection deletions = ContainerUtil.getDeletions(before, after); + if ( ! deletions.isEmpty()) + { + messages.add(Txt.parse("Deletions: %s", this.getValueType().getVisual((V) deletions))); + } + + message(messages); + } + // -------------------------------------------- // // ABSTRACT // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/util/ContainerUtil.java b/src/com/massivecraft/massivecore/util/ContainerUtil.java index 44bac52a..8528a0a1 100644 --- a/src/com/massivecraft/massivecore/util/ContainerUtil.java +++ b/src/com/massivecraft/massivecore/util/ContainerUtil.java @@ -5,7 +5,11 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Map.Entry; + +import com.massivecraft.massivecore.collections.MassiveSet; + import java.util.SortedMap; import java.util.SortedSet; @@ -210,4 +214,24 @@ public class ContainerUtil } } + // -------------------------------------------- // + // ADDITIONS & DELETIONS + // -------------------------------------------- // + + public static Collection getAdditions(Object before, Object after) + { + Collection elements = ContainerUtil.getElements(after); + Set ret = new MassiveSet(elements); + ret.removeAll(ContainerUtil.getElements(before)); + return ret; + } + + public static Collection getDeletions(Object before, Object after) + { + Collection elements = ContainerUtil.getElements(before); + Set ret = new MassiveSet(elements); + ret.removeAll(ContainerUtil.getElements(after)); + return ret; + } + }