Use Mson as visuals

This commit is contained in:
BuildTools 2016-02-22 15:31:58 +01:00 committed by Olof Larsson
parent 8668b9b744
commit ee907f1d6a
14 changed files with 390 additions and 151 deletions

View File

@ -2,10 +2,8 @@ package com.massivecraft.massivecore;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.util.Txt;
public class MassiveException extends Exception public class MassiveException extends Exception
@ -20,32 +18,31 @@ public class MassiveException extends Exception
// MESSAGES // MESSAGES
// -------------------------------------------- // // -------------------------------------------- //
protected List<String> messages = new MassiveList<String>(); protected Mson messages = Mson.mson();
public boolean hasMessages() { return ! this.messages.isEmpty(); } public boolean hasMessages() { return ! this.messages.isEmpty(); }
public List<String> getMessages() { return this.messages; } public Mson getMessages() { return this.messages; }
@Override @Override
public String getMessage() public String getMessage()
{ {
return Txt.implode(this.getMessages(), "\n"); return this.messages.toPlain(true);
} }
public MassiveException setMessage(String message) { this.messages = new MassiveList<String>(message); return this; } // Set single
public MassiveException setMsg(String msg) { return this.setMessage(Txt.parse(msg)); } public MassiveException setMessage(Object part) { this.messages = Mson.mson(part); return this; }
public MassiveException setMsg(String msg, Object... args) { return this.setMessage(Txt.parse(msg, args)); } public MassiveException setMsg(String msg) { this.messages = Mson.parse(msg); return this; }
public MassiveException setMsg(String msg, Object... objects) { this.messages = Mson.parse(msg, objects); return this; }
public MassiveException addMessage(String message) { this.getMessages().add(message); return this; } // Add single
public MassiveException addMsg(String msg) { return this.addMessage(Txt.parse(msg)); } public MassiveException addMessage(Object part) { this.messages = this.messages.add(Mson.mson("\n", part)); return this; }
public MassiveException addMsg(String msg, Object... args) { return this.addMessage(Txt.parse(msg, args)); } public MassiveException addMsg(String msg) { return this.addMessage(Mson.parse(msg)); }
public MassiveException addMsg(String msg, Object... args) { return this.addMessage(Mson.parse(msg, args)); }
public MassiveException setMessages(Collection<String> messages) { this.messages = new MassiveList<String>(messages); return this; } // Set several
public MassiveException setMessages(String... messages) { return this.setMessages(Arrays.asList(messages)); } public MassiveException setMsgs(Collection<String> msgs) { this.messages = Mson.parse(msgs); return this; }
public MassiveException setMsgs(Collection<String> msgs) { return this.setMessages(Txt.parse(msgs)); }
public MassiveException setMsgs(String... msgs) { return this.setMsgs(Arrays.asList(msgs)); } public MassiveException setMsgs(String... msgs) { return this.setMsgs(Arrays.asList(msgs)); }
public MassiveException addMessages(Collection<String> messages) { this.getMessages().addAll(messages); return this; } public MassiveException addMsgs(Collection<String> msgs) { return this.addMessage(Mson.parse(msgs)); }
public MassiveException addMessages(String... messages) { return this.addMessages(Arrays.asList(messages)); }
public MassiveException addMsgs(Collection<String> messages) { this.getMessages().addAll(messages); return this; }
public MassiveException addMsgs(String... msgs) { return this.addMsgs(Arrays.asList(msgs)); } public MassiveException addMsgs(String... msgs) { return this.addMsgs(Arrays.asList(msgs)); }
} }

View File

@ -1,9 +1,5 @@
package com.massivecraft.massivecore.command; package com.massivecraft.massivecore.command;
import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.command.Visibility;
public class DeprecatedCommand extends MassiveCommand public class DeprecatedCommand extends MassiveCommand
{ {
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -7,7 +7,6 @@ import java.util.List;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;

View File

@ -3,6 +3,7 @@ package com.massivecraft.massivecore.command.editor;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
@ -13,8 +14,8 @@ import com.massivecraft.massivecore.command.requirement.RequirementEditorUse;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.event.EventMassiveCoreEditorEdit; import com.massivecraft.massivecore.event.EventMassiveCoreEditorEdit;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.util.PermUtil; import com.massivecraft.massivecore.util.PermUtil;
import com.massivecraft.massivecore.util.Txt;
public class CommandEditAbstract<O, V> extends MassiveCommand public class CommandEditAbstract<O, V> extends MassiveCommand
{ {
@ -128,24 +129,32 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
this.attemptSetPerform(after); this.attemptSetPerform(after);
} }
protected String attemptSetNochangeMessage() protected Mson attemptSetNochangeMessage()
{ {
return mson(
return Txt.parse("%s<silver> for %s<silver> already: %s", this.getProperty().getDisplayName(), this.getObjectVisual(), this.getInheritedVisual()); this.getProperty().getDisplayNameMson(),
" for ",
this.getObjectVisual(),
" already: ",
this.getInheritedVisual()
).color(ChatColor.GRAY);
} }
protected void attemptSetPerform(V after) protected void attemptSetPerform(V after)
{ {
String descProperty = this.getProperty().getDisplayName(); String descProperty = this.getProperty().getDisplayName();
String descObject = this.getObjectVisual(); Mson descObject = this.getObjectVisual();
String descValue = this.getInheritedVisual(); Mson descValue = this.getInheritedVisual();
// Create messages // Create messages
List<String> messages = new MassiveList<>(); List<Mson> messages = new MassiveList<>();
// Before // Before
// We inform what the value was before. // We inform what the value was before.
messages.add(Txt.parse("<k>Before: %s", descValue)); messages.add(mson(
mson("Before: ").color(ChatColor.AQUA),
descValue
));
// Apply // Apply
// We set the new property value. // We set the new property value.
@ -154,13 +163,21 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
// After // After
// We inform what the value is after. // We inform what the value is after.
descValue = this.getInheritedVisual(); descValue = this.getInheritedVisual();
messages.add(Txt.parse("<k>After: %s", descValue)); messages.add(mson(
mson("After: ").color(ChatColor.AQUA),
descValue
));
// Startup // Startup
// We inform what property and object the edit is taking place on. // We inform what property and object the edit is taking place on.
// The visual might change after modification, so this should be added after we have made the change. // The visual might change after modification, so this should be added after we have made the change.
descObject = this.getObjectVisual(); descObject = this.getObjectVisual();
messages.add(0, Txt.parse("%s<silver> for %s<silver> edited:", descProperty, descObject)); messages.add(0, mson(
descProperty,
" for ",
descObject,
" edited:"
).color(ChatColor.GRAY));
message(messages); message(messages);
} }
@ -194,9 +211,9 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
return this.getSettings().getUsedPermission(); return this.getSettings().getUsedPermission();
} }
public String getObjectVisual() public Mson getObjectVisual()
{ {
return this.getObjectType().getVisual(this.getObject(), sender); return this.getObjectType().getVisualMson(this.getObject(), sender);
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -246,12 +263,12 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
return this.getProperty().getInheritedValue(this.getObject()); return this.getProperty().getInheritedValue(this.getObject());
} }
public String getInheritedVisual(O source, V value) public Mson getInheritedVisual(O source, V value)
{ {
return this.getProperty().getInheritedVisual(this.getObject(), source, value, sender); return this.getProperty().getInheritedVisual(this.getObject(), source, value, sender);
} }
public String getInheritedVisual() public Mson getInheritedVisual()
{ {
return this.getProperty().getInheritedVisual(this.getObject(), sender); return this.getProperty().getInheritedVisual(this.getObject(), sender);
} }
@ -282,10 +299,16 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
public void show(CommandSender sender) public void show(CommandSender sender)
{ {
String descProperty = this.getProperty().getDisplayName(); Mson descProperty = this.getProperty().getDisplayNameMson();
String descObject = this.getObjectVisual(); Mson descObject = this.getObjectVisual();
String descValue = this.getInheritedVisual(); Mson descValue = this.getInheritedVisual();
msg("%s<silver> for %s<silver>: %s", descProperty, descObject, descValue); message(mson(
descProperty,
" for ",
descObject,
": ",
descValue
).color(ChatColor.GRAY));
} }
public void requireNullable() throws MassiveException public void requireNullable() throws MassiveException

View File

@ -1,6 +1,9 @@
package com.massivecraft.massivecore.command.editor; package com.massivecraft.massivecore.command.editor;
import java.util.AbstractMap.SimpleImmutableEntry; import java.util.AbstractMap.SimpleImmutableEntry;
import org.bukkit.ChatColor;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -9,6 +12,7 @@ import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.requirement.RequirementEditorPropertyCreated; import com.massivecraft.massivecore.command.requirement.RequirementEditorPropertyCreated;
import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.command.type.TypeNullable; import com.massivecraft.massivecore.command.type.TypeNullable;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.util.ContainerUtil; import com.massivecraft.massivecore.util.ContainerUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
@ -85,9 +89,14 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String attemptSetNochangeMessage() public Mson attemptSetNochangeMessage()
{ {
return Txt.parse("%s<silver> for %s<silver> was not changed.", this.getProperty().getDisplayName(), this.getObjectVisual()); return mson(
this.getProperty().getDisplayNameMson(),
" for ",
this.getObjectVisual(),
" not changed."
).color(ChatColor.GRAY);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -1,18 +1,18 @@
package com.massivecraft.massivecore.command.editor; package com.massivecraft.massivecore.command.editor;
import java.util.AbstractMap.SimpleEntry;
import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.AbstractMap.SimpleEntry;
import java.util.Arrays;
import java.util.Collection;
import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.store.Entity; import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
@ -150,9 +150,9 @@ public abstract class Property<O, V> implements Named
return this.getValueType().createEditCommand(settings, this); return this.getValueType().createEditCommand(settings, this);
} }
public String getInheritedVisual(O object, O source, V value, CommandSender sender) public Mson getInheritedVisual(O object, O source, V value, CommandSender sender)
{ {
String string = this.getValueType().getVisual(value, sender); Mson mson = this.getValueType().getVisualMson(value, sender);
/*if (string == null) /*if (string == null)
{ {
System.out.println("value type " + this.getValueType()); System.out.println("value type " + this.getValueType());
@ -163,16 +163,16 @@ public abstract class Property<O, V> implements Named
System.out.println("sender " + sender); System.out.println("sender " + sender);
}*/ }*/
String suffix = null; Mson suffix = null;
if (source != null && ! source.equals(object)) if (source != null && ! source.equals(object))
{ {
suffix = Txt.parse("<silver>[%s<silver>]", this.getObjectType().getVisual(source)); suffix = Mson.parse("<silver>[%s<silver>]").replaceAll("%s", this.getObjectType().getVisualMson(source));
} }
return Txt.prepondfix(null, string, suffix); return Mson.prepondfix(null, mson, suffix);
} }
public String getInheritedVisual(O object, CommandSender sender) public Mson getInheritedVisual(O object, CommandSender sender)
{ {
Entry<O, V> inherited = this.getInheritedEntry(object); Entry<O, V> inherited = this.getInheritedEntry(object);
O source = inherited.getKey(); O source = inherited.getKey();
@ -184,6 +184,11 @@ public abstract class Property<O, V> implements Named
// VISUAL // VISUAL
// -------------------------------------------- // // -------------------------------------------- //
public Mson getDisplayNameMson()
{
return Mson.mson(this.getName()).color(ChatColor.AQUA);
}
public String getDisplayName() public String getDisplayName()
{ {
return ChatColor.AQUA.toString() + this.getName(); return ChatColor.AQUA.toString() + this.getName();

View File

@ -4,6 +4,7 @@ import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -11,6 +12,7 @@ import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.editor.CommandEditAbstract; import com.massivecraft.massivecore.command.editor.CommandEditAbstract;
import com.massivecraft.massivecore.command.editor.EditSettings; import com.massivecraft.massivecore.command.editor.EditSettings;
import com.massivecraft.massivecore.command.editor.Property; import com.massivecraft.massivecore.command.editor.Property;
import com.massivecraft.massivecore.mson.Mson;
public interface Type<T> public interface Type<T>
{ {
@ -41,6 +43,16 @@ public interface Type<T>
public ChatColor getVisualColor(T value); public ChatColor getVisualColor(T value);
public void setVisualColor(ChatColor color); public void setVisualColor(ChatColor color);
// -------------------------------------------- //
// WRITE VISUAL MSON
// -------------------------------------------- //
// A visual mson.
public Mson getVisualMsonInner(T value, CommandSender sender);
public Mson getVisualMsonInner(T value);
public Mson getVisualMson(T value, CommandSender sender);
public Mson getVisualMson(T value);
// -------------------------------------------- // // -------------------------------------------- //
// WRITE VISUAL // WRITE VISUAL
// -------------------------------------------- // // -------------------------------------------- //
@ -51,11 +63,6 @@ public interface Type<T>
public String getVisual(T value, CommandSender sender); public String getVisual(T value, CommandSender sender);
public String getVisual(T value); public String getVisual(T value);
public Set<String> getVisualsInner(T value, CommandSender sender);
public Set<String> getVisualsInner(T value);
public Set<String> getVisuals(T value, CommandSender sender);
public Set<String> getVisuals(T value);
// -------------------------------------------- // // -------------------------------------------- //
// WRITE NAME // WRITE NAME
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -9,6 +9,7 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Set; import java.util.Set;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -20,6 +21,7 @@ import com.massivecraft.massivecore.command.editor.CommandEditSimple;
import com.massivecraft.massivecore.command.editor.EditSettings; import com.massivecraft.massivecore.command.editor.EditSettings;
import com.massivecraft.massivecore.command.editor.Property; import com.massivecraft.massivecore.command.editor.Property;
import com.massivecraft.massivecore.comparator.ComparatorHashCode; import com.massivecraft.massivecore.comparator.ComparatorHashCode;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.store.Entity; import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.store.SenderEntity; import com.massivecraft.massivecore.store.SenderEntity;
import com.massivecraft.massivecore.util.ContainerUtil; import com.massivecraft.massivecore.util.ContainerUtil;
@ -35,6 +37,10 @@ public abstract class TypeAbstract<T> implements Type<T>
public static final String EMPTY = Txt.parse("<silver><em>EMPTY"); public static final String EMPTY = Txt.parse("<silver><em>EMPTY");
public static final String UNKNOWN = Txt.parse("<b>???"); public static final String UNKNOWN = Txt.parse("<b>???");
public static final Mson MSON_NULL = Mson.fromParsedMessage(NULL);
public static final Mson MSON_EMPTY = Mson.fromParsedMessage(EMPTY);
public static final Mson MSON_UNKNOWN = Mson.fromParsedMessage(UNKNOWN);
public static final ChatColor COLOR_DEFAULT = ChatColor.YELLOW; public static final ChatColor COLOR_DEFAULT = ChatColor.YELLOW;
public static final ChatColor COLOR_NUMBER = ChatColor.LIGHT_PURPLE; public static final ChatColor COLOR_NUMBER = ChatColor.LIGHT_PURPLE;
@ -93,6 +99,32 @@ public abstract class TypeAbstract<T> implements Type<T>
return this.getVisualColor(value, null); return this.getVisualColor(value, null);
} }
// -------------------------------------------- //
// WRITE VISUAL MSON
// -------------------------------------------- //
// A visual mson.
public Mson getVisualMsonInner(T value, CommandSender sender)
{
return Mson.fromParsedMessage(this.getVisualInner(value, sender)).tooltip("LUL, TEST");
}
public Mson getVisualMsonInner(T value)
{
return this.getVisualMson(value, null);
}
public Mson getVisualMson(T value, CommandSender sender)
{
if (value == null) return MSON_NULL;
return this.getVisualMsonInner(value, sender);
}
public Mson getVisualMson(T value)
{
if (value == null) return MSON_NULL;
return this.getVisualMsonInner(value);
}
// -------------------------------------------- // // -------------------------------------------- //
// WRITE VISUAL // WRITE VISUAL
// -------------------------------------------- // // -------------------------------------------- //
@ -123,25 +155,6 @@ public abstract class TypeAbstract<T> implements Type<T>
return this.getVisual(value, null); return this.getVisual(value, null);
} }
public Set<String> getVisualsInner(T value, CommandSender sender)
{
return Collections.singleton(this.getVisualInner(value, sender));
}
public Set<String> getVisualsInner(T value)
{
return this.getVisualsInner(value, null);
}
public Set<String> getVisuals(T value, CommandSender sender)
{
if (value == null) return Collections.singleton(NULL);
return this.getVisualsInner(value, sender);
}
public Set<String> getVisuals(T value)
{
return this.getVisuals(value, null);
}
// -------------------------------------------- // // -------------------------------------------- //
// WRITE NAME // WRITE NAME
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -6,8 +6,8 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -19,6 +19,7 @@ import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.collections.MassiveTreeSet; import com.massivecraft.massivecore.collections.MassiveTreeSet;
import com.massivecraft.massivecore.command.type.container.AllAble; import com.massivecraft.massivecore.command.type.container.AllAble;
import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.util.ReflectionUtil; import com.massivecraft.massivecore.util.ReflectionUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
@ -28,10 +29,10 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
// CONSTANTS // CONSTANTS
// -------------------------------------------- // // -------------------------------------------- //
public final static String SUGGEST_FORMAT = Txt.parse("<h>%s"); public final static Mson SUGGEST_FORMAT = Mson.parse("<h>%s");
public final static String SUGGEST_COMMMA = Txt.parse(" <silver>| "); public final static Mson SUGGEST_COMMMA = Mson.parse(" <silver>| ");
public final static String SUGGEST_AND = Txt.parse(" <silver>| "); public final static Mson SUGGEST_AND = Mson.parse(" <silver>| ");
public final static String SUGGEST_DOT = Txt.parse(""); public final static Mson SUGGEST_DOT = Mson.parse("");
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
@ -174,10 +175,10 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
else else
{ {
Collection<T> suggestions = null; Collection<T> suggestions = null;
String format = SUGGEST_FORMAT; Mson format = SUGGEST_FORMAT;
String comma = SUGGEST_COMMMA; Mson comma = SUGGEST_COMMMA;
String and = SUGGEST_AND; Mson and = SUGGEST_AND;
String dot = SUGGEST_DOT; Mson dot = SUGGEST_DOT;
if (suggestAmbiguous) if (suggestAmbiguous)
{ {
@ -206,12 +207,12 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
} }
else else
{ {
List<String> visuals = new MassiveList<String>(); List<Mson> visuals = new MassiveList<>();
for (T value : suggestions) for (T value : suggestions)
{ {
visuals.add(this.getVisual(value, sender)); visuals.add(this.getVisualMson(value, sender));
} }
exception.addMessage(message + Txt.implodeCommaAndDot(visuals, format, comma, and, dot)); exception.addMessage(Mson.mson(message, Mson.implodeCommaAndDot(visuals, format, comma, and, dot)));
} }
} }

View File

@ -12,6 +12,7 @@ import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.command.editor.CommandEditAbstract; import com.massivecraft.massivecore.command.editor.CommandEditAbstract;
import com.massivecraft.massivecore.command.editor.EditSettings; import com.massivecraft.massivecore.command.editor.EditSettings;
import com.massivecraft.massivecore.command.editor.Property; import com.massivecraft.massivecore.command.editor.Property;
import com.massivecraft.massivecore.mson.Mson;
// The "inner" controls all ways the type behaves and "seems". // The "inner" controls all ways the type behaves and "seems".
// The "outer" type is how the type interfaces in source code. For example what is read. // The "outer" type is how the type interfaces in source code. For example what is read.
@ -22,11 +23,16 @@ public abstract class TypeTransformer<I, O> extends TypeAbstract<O>
// -------------------------------------------- // // -------------------------------------------- //
public static final String PREFIX = UNKNOWN + " "; public static final String PREFIX = UNKNOWN + " ";
public static final String MSON_PREFIX = UNKNOWN + " ";
public static String prefix(String string) public static String prefix(String string)
{ {
return PREFIX + string; return PREFIX + string;
} }
public static Mson prefix(Mson mson)
{
return Mson.mson(MSON_PREFIX, mson);
}
public static Set<String> prefix(Set<String> strings) public static Set<String> prefix(Set<String> strings)
{ {
@ -105,6 +111,42 @@ public abstract class TypeTransformer<I, O> extends TypeAbstract<O>
INNER.setVisualColor(color); INNER.setVisualColor(color);
} }
// -------------------------------------------- //
// WRITE VISUAL MSON
// -------------------------------------------- //
@Override
public Mson getVisualMsonInner(O outer, CommandSender sender)
{
I inner = outerToInner(outer);
if (outer != null && inner == null) return prefix(OUTER.getVisualMsonInner(outer, sender));
return INNER.getVisualMsonInner(inner, sender);
}
@Override
public Mson getVisualMsonInner(O outer)
{
I inner = outerToInner(outer);
if (outer != null && inner == null) return prefix(OUTER.getVisualMsonInner(outer));
return INNER.getVisualMsonInner(inner);
}
@Override
public Mson getVisualMson(O outer, CommandSender sender)
{
I inner = outerToInner(outer);
if (outer != null && inner == null) return prefix(OUTER.getVisualMson(outer, sender));
return INNER.getVisualMson(inner, sender);
}
@Override
public Mson getVisualMson(O outer)
{
I inner = outerToInner(outer);
if (outer != null && inner == null) return prefix(OUTER.getVisualMson(outer));
return INNER.getVisualMson(inner);
}
// -------------------------------------------- // // -------------------------------------------- //
// WRITE VISUAL // WRITE VISUAL
// -------------------------------------------- // // -------------------------------------------- //
@ -141,38 +183,6 @@ public abstract class TypeTransformer<I, O> extends TypeAbstract<O>
return INNER.getVisual(inner); return INNER.getVisual(inner);
} }
@Override
public Set<String> getVisualsInner(O outer, CommandSender sender)
{
I inner = outerToInner(outer);
if (outer != null && inner == null) return prefix(OUTER.getVisualsInner(outer, sender));
return INNER.getVisualsInner(inner, sender);
}
@Override
public Set<String> getVisualsInner(O outer)
{
I inner = outerToInner(outer);
if (outer != null && inner == null) return prefix(OUTER.getVisualsInner(outer));
return INNER.getVisualsInner(inner);
}
@Override
public Set<String> getVisuals(O outer, CommandSender sender)
{
I inner = outerToInner(outer);
if (outer != null && inner == null) return prefix(OUTER.getVisuals(outer, sender));
return INNER.getVisuals(inner, sender);
}
@Override
public Set<String> getVisuals(O outer)
{
I inner = outerToInner(outer);
if (outer != null && inner == null) return prefix(OUTER.getVisuals(outer));
return INNER.getVisuals(inner);
}
// -------------------------------------------- // // -------------------------------------------- //
// WRITE NAME // WRITE NAME
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
@ -14,6 +15,7 @@ import com.massivecraft.massivecore.command.editor.EditSettings;
import com.massivecraft.massivecore.command.editor.Property; import com.massivecraft.massivecore.command.editor.Property;
import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.command.type.TypeAbstract; import com.massivecraft.massivecore.command.type.TypeAbstract;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.util.ContainerUtil; import com.massivecraft.massivecore.util.ContainerUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
@ -47,6 +49,38 @@ public abstract class TypeContainer<C extends Object, E> extends TypeAbstract<C>
// WRITE VISUAL // WRITE VISUAL
// -------------------------------------------- // // -------------------------------------------- //
@Override
public Mson getVisualMsonInner(C container, CommandSender sender)
{
// Empty
if (ContainerUtil.isEmpty(container)) return MSON_EMPTY;
// Create
List<Mson> parts = new MassiveList<>();
// Fill
List<E> elements = this.getContainerElementsOrdered(container);
Type<E> innerType = this.getInnerType();
int index = -1;
for (E element : elements)
{
index++;
Mson part = Mson.mson(
Mson.mson(String.valueOf(index)).color(ChatColor.WHITE),
" ",
innerType.getVisualMsonInner(element, sender)
);
parts.add(part);
}
// Return
return Mson.implode(parts, Mson.mson("\n"));
}
// -------------------------------------------- //
// WRITE VISUAL
// -------------------------------------------- //
@Override @Override
public String getVisualInner(C container, CommandSender sender) public String getVisualInner(C container, CommandSender sender)
{ {
@ -54,7 +88,7 @@ public abstract class TypeContainer<C extends Object, E> extends TypeAbstract<C>
if (ContainerUtil.isEmpty(container)) return EMPTY; if (ContainerUtil.isEmpty(container)) return EMPTY;
// Create // Create
List<String> parts = new MassiveList<String>(); List<String> parts = new MassiveList<>();
// Fill // Fill
List<E> elements = this.getContainerElementsOrdered(container); List<E> elements = this.getContainerElementsOrdered(container);
@ -82,7 +116,7 @@ public abstract class TypeContainer<C extends Object, E> extends TypeAbstract<C>
if (ContainerUtil.isEmpty(container)) return ""; if (ContainerUtil.isEmpty(container)) return "";
// Create // Create
List<String> parts = new MassiveList<String>(); List<String> parts = new MassiveList<>();
// Fill // Fill
List<E> elements = this.getContainerElementsOrdered(container); List<E> elements = this.getContainerElementsOrdered(container);
@ -108,7 +142,7 @@ public abstract class TypeContainer<C extends Object, E> extends TypeAbstract<C>
if (ContainerUtil.isEmpty(container)) return ""; if (ContainerUtil.isEmpty(container)) return "";
// Create // Create
List<String> parts = new MassiveList<String>(); List<String> parts = new MassiveList<>();
// Fill // Fill
Type<E> innerType = this.getInnerType(); Type<E> innerType = this.getInnerType();

View File

@ -1,9 +1,10 @@
package com.massivecraft.massivecore.mixin; package com.massivecraft.massivecore.mixin;
import org.bukkit.entity.Player;
import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.nms.NmsPacket; import com.massivecraft.massivecore.nms.NmsPacket;
import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.IdUtil;
import org.bukkit.entity.Player;
public class ActionbarMixinDefault extends ActionbarMixinAbstract public class ActionbarMixinDefault extends ActionbarMixinAbstract
{ {

View File

@ -4,12 +4,14 @@ import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Objects; import java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.lang.mutable.MutableInt;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -521,7 +523,7 @@ public class Mson implements Serializable
{ {
if (parts == null) throw new NullPointerException("parts"); if (parts == null) throw new NullPointerException("parts");
List<Mson> msons = new MassiveList<Mson>(); List<Mson> msons = new MassiveList<>();
for (Object part : parts) for (Object part : parts)
{ {
@ -535,6 +537,16 @@ public class Mson implements Serializable
// PARSE & FORMAT // PARSE & FORMAT
// -------------------------------------------- // // -------------------------------------------- //
public static Mson fromParsedMessages(Collection<String> messages)
{
List<Mson> extra = new MassiveList<>(messages.size());
for (String message : messages)
{
extra.add(fromParsedMessage(message));
}
return mson(extra);
}
public static Mson fromParsedMessage(String message) public static Mson fromParsedMessage(String message)
{ {
if (message == null) throw new NullPointerException("message"); if (message == null) throw new NullPointerException("message");
@ -551,7 +563,7 @@ public class Mson implements Serializable
// We don't want that empty element. // We don't want that empty element.
parts = Arrays.copyOfRange(parts, 1, parts.length); parts = Arrays.copyOfRange(parts, 1, parts.length);
List<Mson> msons = new ArrayList<Mson>(); List<Mson> msons = new MassiveList<>();
ChatColor latestColor = null; ChatColor latestColor = null;
Boolean bold = null; Boolean bold = null;
@ -603,6 +615,7 @@ public class Mson implements Serializable
// Parse redirects, convert to Mson directly // Parse redirects, convert to Mson directly
public static Mson parse(String string) { return Mson.fromParsedMessage(Txt.parse(string)); } public static Mson parse(String string) { return Mson.fromParsedMessage(Txt.parse(string)); }
public static Mson parse(Collection<String> strings) { return Mson.fromParsedMessages(Txt.parse(strings)); }
public static Mson parse(String format, Object... args) { return Mson.fromParsedMessage(Txt.parse(format, args)); } public static Mson parse(String format, Object... args) { return Mson.fromParsedMessage(Txt.parse(format, args)); }
public static Mson format(String format, Object... args) public static Mson format(String format, Object... args)
@ -754,7 +767,7 @@ public class Mson implements Serializable
if (regex == null) throw new NullPointerException("regex"); if (regex == null) throw new NullPointerException("regex");
if (replacement == null) throw new NullPointerException("replacement"); if (replacement == null) throw new NullPointerException("replacement");
return replaceAll(Pattern.compile(regex), replacement); return replaceAll(regex, mson(replacement));
} }
public Mson replaceAll(Pattern pattern, String replacement) public Mson replaceAll(Pattern pattern, String replacement)
@ -762,21 +775,7 @@ public class Mson implements Serializable
if (pattern == null) throw new NullPointerException("pattern"); if (pattern == null) throw new NullPointerException("pattern");
if (replacement == null) throw new NullPointerException("replacement"); if (replacement == null) throw new NullPointerException("replacement");
Mson ret = this.text(pattern.matcher(this.getText()).replaceAll(replacement)); return replaceAll(pattern, mson(replacement));
if (this.hasExtra())
{
Mson[] extra = new Mson[this.getExtra().size()];
int i = 0;
for (Mson part : this.getExtra())
{
extra[i] = part.replaceAll(pattern, replacement);
i++;
}
ret = ret.extra(extra);
}
return ret;
} }
// Special replace all // Special replace all
@ -785,21 +784,39 @@ public class Mson implements Serializable
{ {
if (regex == null) throw new NullPointerException("regex"); if (regex == null) throw new NullPointerException("regex");
if (replacement == null) throw new NullPointerException("replacement"); if (replacement == null) throw new NullPointerException("replacement");
return this.replaceAll(Pattern.compile(regex), replacement); return this.replaceAll(regex, new Mson[]{replacement});
} }
public Mson replaceAll(Pattern pattern, final Mson replacement) public Mson replaceAll(Pattern pattern, final Mson replacement)
{ {
if (pattern == null) throw new NullPointerException("pattern"); if (pattern == null) throw new NullPointerException("pattern");
if (replacement == null) throw new NullPointerException("replacement"); if (replacement == null) throw new NullPointerException("replacement");
return this.replaceAll(pattern, new Mson[]{replacement});
}
public Mson replaceAll(String regex, Mson... replacements)
{
if (regex == null) throw new NullPointerException("regex");
if (replacements == null) throw new NullPointerException("replacements");
return this.replaceAll(Pattern.compile(regex), replacements);
}
public Mson replaceAll(Pattern pattern, final Mson... replacements)
{
if (pattern == null) throw new NullPointerException("pattern");
if (replacements == null) throw new NullPointerException("replacements");
final MutableInt i = new MutableInt(0);
MsonReplacement replacer = new MsonReplacement() MsonReplacement replacer = new MsonReplacement()
{ {
@Override @Override
public Mson getReplacement(String match, Mson parent) public Mson getReplacement(String match, Mson parent)
{ {
return replacement; int idx = i.intValue();
i.setValue(idx+1);
return replacements[idx % replacements.length];
} }
}; };
return this.replaceAll(pattern, replacer); return this.replaceAll(pattern, replacer);
} }
@ -893,6 +910,135 @@ public class Mson implements Serializable
return ret; return ret;
} }
// -------------------------------------------- //
// IMPLODE
// -------------------------------------------- //
// Implode simple
public static Mson implode(final Object[] list, final Mson glue, final Mson format)
{
List<Mson> parts = new MassiveList<>();
for (int i = 0; i < list.length; i++)
{
Object item = list[i];
Mson part = (item == null ? mson("NULL") : Mson.mson(item));
if (i != 0)
{
parts.add(glue);
}
if (format != null)
{
part = format.replaceAll("%s", part);
}
parts.add(part);
}
return Mson.mson(parts);
}
public static Mson implode(final Object[] list, final Mson glue)
{
return implode(list, glue, null);
}
public static Mson implode(final Collection<? extends Object> coll, final Mson glue, final Mson format)
{
return implode(coll.toArray(new Object[0]), glue, format);
}
public static Mson implode(final Collection<? extends Object> coll, final Mson glue)
{
return implode(coll, glue, null);
}
// Implode comma and dot
public static Mson implodeCommaAndDot(Collection<? extends Object> objects, Mson format, Mson comma, Mson and, Mson dot)
{
if (objects.size() == 0) return mson();
if (objects.size() == 1)
{
return implode(objects, comma, format);
}
List<Object> ourObjects = new MassiveList<>(objects);
Mson ultimateItem = mson(ourObjects.remove(ourObjects.size()-1));
Mson penultimateItem = mson(ourObjects.remove(ourObjects.size()-1));
if (format != null)
{
ultimateItem = format.replaceAll("%s", ultimateItem);
penultimateItem = format.replaceAll("%s", penultimateItem);
}
Mson merge = mson(penultimateItem, and, ultimateItem);
ourObjects.add(merge);
return implode(ourObjects, comma, format).add(mson(dot));
}
public static Mson implodeCommaAndDot(final Collection<? extends Object> objects, Mson comma, Mson and, Mson dot)
{
return implodeCommaAndDot(objects, null, comma, and, dot);
}
public static Mson implodeCommaAnd(final Collection<? extends Object> objects, Mson comma, Mson and)
{
return implodeCommaAndDot(objects, comma, and, mson());
}
public static Mson implodeCommaAndDot(final Collection<? extends Object> objects, ChatColor color)
{
return implodeCommaAndDot(objects, mson(", ").color(color), mson(" and ").color(color), mson(".").color(color));
}
public static Mson implodeCommaAnd(final Collection<? extends Object> objects, ChatColor color)
{
return implodeCommaAndDot(objects, mson(", ").color(color), mson(" and ").color(color), mson());
}
public static Mson implodeCommaAndDot(final Collection<? extends Object> objects)
{
return implodeCommaAndDot(objects, null);
}
public static Mson implodeCommaAnd(final Collection<? extends Object> objects)
{
return implodeCommaAnd(objects, null);
}
// -------------------------------------------- //
// PREPONDFIX
// -------------------------------------------- //
// This weird algorithm takes:
// - A prefix
// - A centerpiece single string or a list of strings.
// - A suffix
// If the centerpiece is a single String it just concatenates prefix + centerpiece + suffix.
// 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 List<Mson> prepondfix(Mson prefix, List<Mson> msons, Mson suffix)
{
// Create
List<Mson> ret = new MassiveList<>();
// Fill
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);
ret.add(implode(parts, SPACE));
if (msons.size() != 1)
{
ret.addAll(msons);
}
// Return
return ret;
}
public static Mson prepondfix(Mson prefix, Mson mson, Mson suffix)
{
// HELP! How do I do this?
//List<Mson> strings = Arrays.asList(PATTERN_NEWLINE.split(string));
List<Mson> ret = prepondfix(prefix, Collections.singletonList(mson), suffix);
return implode(ret, mson("\n"));
}
// -------------------------------------------- // // -------------------------------------------- //
// MESSAGE // MESSAGE
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -11,8 +11,6 @@ import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListMap;
import org.bukkit.plugin.Plugin;
import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.MassiveCoreMConf; import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.MassivePlugin; import com.massivecraft.massivecore.MassivePlugin;