Fix prepondFix for msons

This commit is contained in:
BuildTools 2016-02-28 18:23:54 +01:00 committed by Olof Larsson
parent 29dde43d47
commit 54ab6bbfb2
3 changed files with 32 additions and 32 deletions

View File

@ -129,20 +129,14 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
Collection<Object> additions = ContainerUtil.getAdditions(before, after); Collection<Object> additions = ContainerUtil.getAdditions(before, after);
if ( ! additions.isEmpty()) if ( ! additions.isEmpty())
{ {
messages.add(mson( messages.add(Mson.prepondfix(mson("Additions: ").color(ChatColor.AQUA), this.getValueType().getVisualMson((V) additions), null));
mson("Additions: ").color(ChatColor.AQUA),
this.getValueType().getVisualMson((V) additions)
));
} }
// Note: The result of getDeletions is not actually V, but the implementation doesn't care. // Note: The result of getDeletions is not actually V, but the implementation doesn't care.
Collection<Object> deletions = ContainerUtil.getDeletions(before, after); Collection<Object> deletions = ContainerUtil.getDeletions(before, after);
if ( ! deletions.isEmpty()) if ( ! deletions.isEmpty())
{ {
messages.add(mson( messages.add(Mson.prepondfix(mson("Deletions: ").color(ChatColor.AQUA), this.getValueType().getVisualMson((V) deletions), null));
mson("Deletions: ").color(ChatColor.AQUA),
this.getValueType().getVisualMson((V) deletions)
));
} }
message(messages); message(messages);

View File

@ -1,7 +1,7 @@
package com.massivecraft.massivecore.command.editor; package com.massivecraft.massivecore.command.editor;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -32,7 +32,7 @@ public class CommandEditContainerRemove<O, V> extends CommandEditContainerAbstra
{ {
if (this.isCollection()) if (this.isCollection())
{ {
this.alterCollection((List<?>) container); this.alterCollection((Collection<?>) container);
} }
else else
{ {
@ -44,7 +44,7 @@ public class CommandEditContainerRemove<O, V> extends CommandEditContainerAbstra
// OVERRIDE > COLLECTION // OVERRIDE > COLLECTION
// -------------------------------------------- // // -------------------------------------------- //
public void alterCollection(List<?> elements) throws MassiveException public void alterCollection(Collection<?> elements) throws MassiveException
{ {
// Args // Args
Object element = this.readElement(); Object element = this.readElement();

View File

@ -47,6 +47,7 @@ public class Mson implements Serializable
public static final Mson SPACE = mson(" "); public static final Mson SPACE = mson(" ");
public static final Mson EMPTY = mson(""); public static final Mson EMPTY = mson("");
public static final Mson NEWLINE = mson("\n");
// -------------------------------------------- // // -------------------------------------------- //
// GSON // GSON
@ -1117,31 +1118,36 @@ public class Mson implements Serializable
// If the centerpiece is multiple Strings it concatenates prefix + suffix and then appends the centerpice at the end. // If the centerpiece is multiple Strings it concatenates prefix + suffix and then appends the centerpice at the end.
// This algorithm is used in the editor system. // This algorithm is used in the editor system.
public static Mson prepondfix(Mson prefix, Mson mson, Mson suffix) public static List<Mson> prepondfix(Mson prefix, List<Mson> msons, Mson suffix)
{ {
// Create
List<Mson> ret = new MassiveList<>();
// Fill // Fill
if (mson.contains("\n"))
{
List<Mson> parts = new MassiveList<>(); List<Mson> parts = new MassiveList<>();
if (prefix != null) parts.add(prefix); if (prefix != null) parts.add(prefix);
if (msons.size() == 1) parts.add(msons.get(0));
if (suffix != null) parts.add(suffix); if (suffix != null) parts.add(suffix);
return mson( ret.add(implode(parts, SPACE));
implode(parts, SPACE),
"\n", if (msons.size() != 1)
mson
);
}
else
{ {
List<Mson> parts = new MassiveList<>(); ret.addAll(msons);
if (prefix != null) parts.add(prefix);
parts.add(mson);
if (suffix != null) parts.add(suffix);
return implode(parts, SPACE);
} }
// Return
return ret;
} }
public static Mson prepondfix(Mson prefix, Mson mson, Mson suffix)
{
List<Mson> msons = mson.split(Txt.PATTERN_NEWLINE);
List<Mson> ret = prepondfix(prefix, msons, suffix);
return implode(ret, NEWLINE);
}
// -------------------------------------------- // // -------------------------------------------- //
// MESSAGE // MESSAGE
// -------------------------------------------- // // -------------------------------------------- //