Fix prepondFix for msons
This commit is contained in:
parent
29dde43d47
commit
54ab6bbfb2
@ -129,20 +129,14 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
|
||||
Collection<Object> additions = ContainerUtil.getAdditions(before, after);
|
||||
if ( ! additions.isEmpty())
|
||||
{
|
||||
messages.add(mson(
|
||||
mson("Additions: ").color(ChatColor.AQUA),
|
||||
this.getValueType().getVisualMson((V) additions)
|
||||
));
|
||||
messages.add(Mson.prepondfix(mson("Additions: ").color(ChatColor.AQUA), this.getValueType().getVisualMson((V) additions), null));
|
||||
}
|
||||
|
||||
// Note: The result of getDeletions is not actually V, but the implementation doesn't care.
|
||||
Collection<Object> deletions = ContainerUtil.getDeletions(before, after);
|
||||
if ( ! deletions.isEmpty())
|
||||
{
|
||||
messages.add(mson(
|
||||
mson("Deletions: ").color(ChatColor.AQUA),
|
||||
this.getValueType().getVisualMson((V) deletions)
|
||||
));
|
||||
messages.add(Mson.prepondfix(mson("Deletions: ").color(ChatColor.AQUA), this.getValueType().getVisualMson((V) deletions), null));
|
||||
}
|
||||
|
||||
message(messages);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.massivecraft.massivecore.command.editor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@ -32,7 +32,7 @@ public class CommandEditContainerRemove<O, V> extends CommandEditContainerAbstra
|
||||
{
|
||||
if (this.isCollection())
|
||||
{
|
||||
this.alterCollection((List<?>) container);
|
||||
this.alterCollection((Collection<?>) container);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -44,7 +44,7 @@ public class CommandEditContainerRemove<O, V> extends CommandEditContainerAbstra
|
||||
// OVERRIDE > COLLECTION
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void alterCollection(List<?> elements) throws MassiveException
|
||||
public void alterCollection(Collection<?> elements) throws MassiveException
|
||||
{
|
||||
// Args
|
||||
Object element = this.readElement();
|
||||
|
@ -47,6 +47,7 @@ public class Mson implements Serializable
|
||||
|
||||
public static final Mson SPACE = mson(" ");
|
||||
public static final Mson EMPTY = mson("");
|
||||
public static final Mson NEWLINE = mson("\n");
|
||||
|
||||
// -------------------------------------------- //
|
||||
// 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.
|
||||
// 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
|
||||
if (mson.contains("\n"))
|
||||
{
|
||||
List<Mson> parts = new MassiveList<>();
|
||||
if (prefix != null) parts.add(prefix);
|
||||
if (msons.size() == 1) parts.add(msons.get(0));
|
||||
if (suffix != null) parts.add(suffix);
|
||||
|
||||
return mson(
|
||||
implode(parts, SPACE),
|
||||
"\n",
|
||||
mson
|
||||
);
|
||||
}
|
||||
else
|
||||
ret.add(implode(parts, SPACE));
|
||||
|
||||
if (msons.size() != 1)
|
||||
{
|
||||
List<Mson> parts = new MassiveList<>();
|
||||
if (prefix != null) parts.add(prefix);
|
||||
parts.add(mson);
|
||||
if (suffix != null) parts.add(suffix);
|
||||
return implode(parts, SPACE);
|
||||
ret.addAll(msons);
|
||||
}
|
||||
|
||||
// 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
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user