0.5h More Named, Identified and Colorized

This commit is contained in:
BuildTools 2016-03-08 23:07:59 +01:00 committed by Olof Larsson
parent f92b042cca
commit a2e390f2b3
37 changed files with 88 additions and 116 deletions

View File

@ -0,0 +1,8 @@
package com.massivecraft.massivecore;
import org.bukkit.ChatColor;
public interface Colorized
{
public ChatColor getColor();
}

View File

@ -16,7 +16,7 @@ import com.massivecraft.massivecore.util.Txt;
import com.massivecraft.massivecore.xlib.gson.Gson;
import com.massivecraft.massivecore.xlib.gson.GsonBuilder;
public abstract class MassivePlugin extends JavaPlugin implements Listener
public abstract class MassivePlugin extends JavaPlugin implements Listener, Named
{
// -------------------------------------------- //
// FIELDS

View File

@ -148,7 +148,7 @@ public class Parameter<T>
// Without defaultValue, name, reqFromConsole and defaultDesc.
public Parameter(Type<T> type)
{
this(type, REQUIRED_FROM_CONSOLE_DEFAULT, type.getTypeName(), DEFAULT_DESC_DEFAULT);
this(type, REQUIRED_FROM_CONSOLE_DEFAULT, type.getName(), DEFAULT_DESC_DEFAULT);
}
// -------------------------------------------- //

View File

@ -192,8 +192,8 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
}
else
{
this.addParameter(null, TypeNullable.get(keyType, "any", "all"), keyType.getTypeName(), "any");
this.addParameter(null, TypeNullable.get(valueType, "any", "all"), valueType.getTypeName(), "any", true);
this.addParameter(null, TypeNullable.get(keyType, "any", "all"), keyType.getName(), "any");
this.addParameter(null, TypeNullable.get(valueType, "any", "all"), valueType.getName(), "any", true);
}
}
}

View File

@ -17,7 +17,7 @@ public class CommandEditUsed<O> extends CommandEditSimple<CommandSender, O>
this.setAliases("used", "selected");
// Desc
this.setDesc("edit used " + this.getProperty().getValueType().getTypeName());
this.setDesc("edit used " + this.getProperty().getValueType().getName());
}
}

View File

@ -113,14 +113,14 @@ public class EditSettings<O>
{
O ret = this.getUsed(sender);
if (ret != null) return ret;
String noun = this.getObjectType().getTypeName();
String noun = this.getObjectType().getName();
String aan = Txt.aan(noun);
throw new MassiveException().addMsg("<b>You must select %s %s for use to skip the optional argument.", aan, noun);
}
if (ALIASES_USED.contains(arg))
{
O ret = this.getUsed(sender);
if (ret == null) throw new MassiveException().addMsg("<b>You have no selected %s.", this.getObjectType().getTypeName() );
if (ret == null) throw new MassiveException().addMsg("<b>You have no selected %s.", this.getObjectType().getName() );
return ret;
}

View File

@ -12,7 +12,7 @@ public abstract class PropertyUsed<V> extends Property<CommandSender, V>
public PropertyUsed(EditSettings<V> settings)
{
super(TypeSender.get(), settings.getObjectType(), "used " + settings.getObjectType().getTypeName());
super(TypeSender.get(), settings.getObjectType(), "used " + settings.getObjectType().getName());
}
}

View File

@ -34,7 +34,7 @@ public class RequirementEditorUse extends RequirementAbstract
if ( ! (command instanceof CommandEditAbstract)) return Txt.parse("<b>This is not an editor!");
CommandEditAbstract<?, ?> commandEditor = (CommandEditAbstract<?, ?>)command;
String noun = commandEditor.getSettings().getObjectType().getTypeName();
String noun = commandEditor.getSettings().getObjectType().getName();
String aan = Txt.aan(noun);
return Txt.parse("<b>You must use %s %s to edit it.", aan, noun);

View File

@ -9,19 +9,20 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.command.editor.CommandEditAbstract;
import com.massivecraft.massivecore.command.editor.EditSettings;
import com.massivecraft.massivecore.command.editor.Property;
import com.massivecraft.massivecore.mson.Mson;
public interface Type<T>
public interface Type<T> extends Named
{
// -------------------------------------------- //
// META
// -------------------------------------------- //
// Human friendly name
public String getTypeName();
public String getName();
// -------------------------------------------- //
// INNER

View File

@ -13,6 +13,8 @@ import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.Colorized;
import com.massivecraft.massivecore.Identified;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.collections.MassiveList;
@ -22,7 +24,6 @@ import com.massivecraft.massivecore.command.editor.EditSettings;
import com.massivecraft.massivecore.command.editor.Property;
import com.massivecraft.massivecore.comparator.ComparatorHashCode;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.store.SenderEntity;
import com.massivecraft.massivecore.util.ContainerUtil;
import com.massivecraft.massivecore.util.ReflectionUtil;
@ -52,7 +53,7 @@ public abstract class TypeAbstract<T> implements Type<T>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
int prefixLength = "Type".length();
String name = this.getClass().getSimpleName();
@ -111,6 +112,11 @@ public abstract class TypeAbstract<T> implements Type<T>
@Override
public ChatColor getVisualColor(T value, CommandSender sender)
{
if (value instanceof Colorized)
{
Colorized colorized = (Colorized) value;
return colorized.getColor();
}
return this.visualColor;
}
@Override
@ -228,10 +234,10 @@ public abstract class TypeAbstract<T> implements Type<T>
@Override
public String getIdInner(T value)
{
if (value instanceof Entity)
if (value instanceof Identified)
{
Entity<?> entity = (Entity<?>)value;
return entity.getId();
Identified identified = (Identified)value;
return identified.getId();
}
else if (value instanceof String || value instanceof Number || value instanceof Boolean)
{

View File

@ -147,14 +147,14 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
String message;
if (matches.isEmpty())
{
message = String.format(MESSAGE_MATCH_NOTHING, this.getTypeName(), arg);
message = String.format(MESSAGE_MATCH_NOTHING, this.getName(), arg);
exception.addMessage(message);
suggestLevenshtein = true;
}
// Ambiguous
else
{
message = String.format(MESSAGE_MATCH_AMBIGUOUS, matches.size(), this.getTypeName(), arg);
message = String.format(MESSAGE_MATCH_AMBIGUOUS, matches.size(), this.getName(), arg);
exception.addMessage(message);
suggestAmbiguous = true;
}
@ -169,7 +169,7 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
}
else if (suggestNone)
{
message = String.format(MESSAGE_AVAILABLE_EMPTY, this.getTypeName());
message = String.format(MESSAGE_AVAILABLE_EMPTY, this.getName());
exception.addMessage(message);
}
else

View File

@ -56,7 +56,7 @@ public abstract class TypeAbstractSelect<T> extends TypeAbstract<T> implements A
public MassiveException createExceptionForInvalidArg(String arg, CommandSender sender)
{
MassiveException ret = new MassiveException();
ret.addMsg("<b>No %s matches \"<h>%s<b>\".", this.getTypeName(), arg);
ret.addMsg("<b>No %s matches \"<h>%s<b>\".", this.getName(), arg);
if (this.canList(sender))
{
@ -67,7 +67,7 @@ public abstract class TypeAbstractSelect<T> extends TypeAbstract<T> implements A
if (names.isEmpty())
{
ret.addMsg("<i>Note: There is no %s available.", this.getTypeName());
ret.addMsg("<i>Note: There is no %s available.", this.getName());
}
else if ( ! matches.isEmpty() && matches.size() <= LIST_COUNT_MAX)
{

View File

@ -13,7 +13,7 @@ public abstract class TypeAbstractSimple<T> extends TypeAbstractException<T>
@Override
public String extractErrorMessage(String arg, CommandSender sender, Exception ex)
{
return Txt.parse("<b>\"<h>%s<b>\" is not a %s.", arg, this.getTypeName());
return Txt.parse("<b>\"<h>%s<b>\" is not a %s.", arg, this.getName());
}
}

View File

@ -28,7 +28,7 @@ public class TypeDate extends TypeAbstractSimple<Date>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return "YYYY-MM-DD date";
}

View File

@ -24,7 +24,7 @@ public class TypeMillisDiff extends TypeAbstractException<Long>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return "time amount";
}

View File

@ -39,7 +39,7 @@ public class TypeStringCommand extends TypeAbstract<String>
}
@Override
public String getTypeName()
public String getName()
{
return "command";
}

View File

@ -80,9 +80,9 @@ public abstract class TypeTransformer<I, O> extends TypeAbstract<O>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return INNER.getTypeName();
return INNER.getName();
}
// -------------------------------------------- //

View File

@ -20,7 +20,7 @@ public class TypeWorldId extends TypeAbstractChoice<String>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return "world";
}

View File

@ -24,9 +24,9 @@ public class TypeWrapper<T> extends TypeAbstract<T>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return this.getInnerType().getTypeName();
return this.getInnerType().getName();
}
@Override

View File

@ -130,7 +130,7 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
// Create
List<String> parts = new MassiveList<String>();
@ -138,7 +138,7 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
// Fill
for (Type<?> type : this.getInnerTypes())
{
parts.add(type.getTypeName());
parts.add(type.getName());
}
// Return

View File

@ -35,14 +35,14 @@ public abstract class TypeContainer<C extends Object, E> extends TypeAbstract<C>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return this.getCollectionTypeName() + " of " + this.getInnerType().getTypeName();
return this.getCollectionTypeName() + " of " + this.getInnerType().getName();
}
public String getCollectionTypeName()
{
return super.getTypeName();
return super.getName();
}
// -------------------------------------------- //

View File

@ -29,7 +29,7 @@ public class TypeEnum<T extends Enum<T>> extends TypeAbstractChoice<T>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return Txt.getNicedEnumString(this.getClazz().getSimpleName());
}

View File

@ -67,7 +67,7 @@ public class TypeBoolean extends TypeAbstractChoice<Boolean>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return "toggle";
}

View File

@ -16,7 +16,7 @@ public class TypeByte extends TypeAbstractNumber<Byte>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return "small number";
}

View File

@ -16,7 +16,7 @@ public class TypeDouble extends TypeAbstractNumber<Double>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return "number with decimals";
}

View File

@ -16,7 +16,7 @@ public class TypeFloat extends TypeAbstractNumber<Float>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return "number with decimals";
}

View File

@ -16,7 +16,7 @@ public class TypeInteger extends TypeAbstractNumber<Integer>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return "number";
}

View File

@ -16,7 +16,7 @@ public class TypeLong extends TypeAbstractNumber<Long>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return "number";
}

View File

@ -21,7 +21,7 @@ public class TypeString extends TypeAbstract<String>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return "text";
}

View File

@ -20,7 +20,7 @@ public class TypeStringId extends TypeString
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
return "text id";
}

View File

@ -68,7 +68,7 @@ public abstract class TypeSenderIdAbstract<T> extends TypeAbstract<T>
// -------------------------------------------- //
@Override
public String getTypeName()
public String getName()
{
switch (presence)
{
@ -178,7 +178,7 @@ public abstract class TypeSenderIdAbstract<T> extends TypeAbstract<T>
public String getErrorMessageForArg(String arg)
{
return Txt.parse("<b>No %s matches \"<h>%s<b>\".", this.getTypeName(), arg);
return Txt.parse("<b>No %s matches \"<h>%s<b>\".", this.getName(), arg);
}
public String getSenderIdFor(String arg)

View File

@ -59,8 +59,8 @@ public class Coll<E extends Entity<E>> extends CollAbstract<E>
// WHAT DO WE HANDLE?
// -------------------------------------------- //
protected final String name;
@Override public String getName() { return this.name; }
protected final String id;
@Override public String getId() { return this.id; }
protected final String basename;
@Override public String getBasename() { return this.basename; }
@ -930,15 +930,15 @@ public class Coll<E extends Entity<E>> extends CollAbstract<E>
// CONSTRUCT
// -------------------------------------------- //
public Coll(String name, Class<E> entityClass, Db db, MassivePlugin plugin)
public Coll(String id, Class<E> entityClass, Db db, MassivePlugin plugin)
{
// Setup the name and the parsed parts
this.name = name;
String[] nameParts = this.name.split("\\@");
this.basename = nameParts[0];
if (nameParts.length > 1)
this.id = id;
String[] idParts = this.id.split("\\@");
this.basename = idParts[0];
if (idParts.length > 1)
{
this.universe = nameParts[1];
this.universe = idParts[1];
}
else
{

View File

@ -15,7 +15,13 @@ public abstract class CollAbstract<E extends Entity<E>> implements CollInterface
// -------------------------------------------- //
// WHAT DO WE HANDLE?
// -------------------------------------------- //
// This is all placed in the implementation.
@Override
public String getName()
{
return this.getId();
}
// -------------------------------------------- //
// SUPPORTING SYSTEM

View File

@ -7,18 +7,19 @@ import java.util.Map;
import java.util.Map.Entry;
import com.massivecraft.massivecore.Active;
import com.massivecraft.massivecore.Identified;
import com.massivecraft.massivecore.MassivePlugin;
import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.xlib.gson.JsonObject;
public interface CollInterface<E extends Entity<E>> extends Named, Active
public interface CollInterface<E extends Entity<E>> extends Named, Active, Identified
{
// -------------------------------------------- //
// WHAT DO WE HANDLE?
// -------------------------------------------- //
public String getName();
public String getId();
public String getBasename();
public String getUniverse();
public Class<E> getEntityClass();

View File

@ -2,6 +2,7 @@ package com.massivecraft.massivecore.store;
import java.util.Objects;
import com.massivecraft.massivecore.Identified;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.store.accessor.Accessor;
import com.massivecraft.massivecore.xlib.gson.Gson;
@ -15,7 +16,7 @@ import com.massivecraft.massivecore.xlib.gson.JsonObject;
// Self referencing generic.
// http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ206
public class Entity<E extends Entity<E>>
public class Entity<E extends Entity<E>> implements Identified
{
// -------------------------------------------- //
// FIELDS
@ -27,7 +28,7 @@ public class Entity<E extends Entity<E>>
protected transient String id;
protected void setId(String id) { this.id = id; }
public String getId() { return this.id; }
@Override public String getId() { return this.id; }
public String getUniverse()
{

View File

@ -1,16 +1,19 @@
package com.massivecraft.massivecore.util;
public class IdData
import com.massivecraft.massivecore.Identified;
import com.massivecraft.massivecore.Named;
public class IdData implements Identified, Named
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected final String id;
public String getId() { return this.id; }
@Override public String getId() { return this.id; }
protected final String name;
public String getName() { return this.name; }
@Override public String getName() { return this.name; }
protected final long millis;
public long getMillis() { return this.millis; }

View File

@ -1,54 +0,0 @@
package com.massivecraft.massivecore.util;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.massivecraft.massivecore.SenderPresence;
import com.massivecraft.massivecore.SenderType;
class SenderMapTest
{
static SenderMap map = new SenderMap();
public static void main(String[] args)
{
map.addValue("Madus", SenderPresence.LOCAL); // Satisfying
//printMap();
map.removeValueCompletely("Madus"); // Satisfying
//printMap();
map.addValue("Madus", SenderPresence.LOCAL); // Satisfying
map.addValue("Cayorion", SenderPresence.ONLINE); // Satisfying
//printMap();
map.removeValueCompletely("madus"); // Satisfying (case insensitive)
//printMap();
map.addValue("@console", SenderPresence.OFFLINE); // Satisfying
//printMap();
System.out.println(map.getPresence("@console")); // Satisfying (OFFLINE)
System.out.println(map.getPresence("caYorioN")); // Satisfying (ONLINE)
System.out.println(map.getPresence("MaDus")); // Satisfying (null)
}
public static void printMap()
{
printMap(map);
}
public static void printMap(SenderMap map)
{
for (Entry<SenderPresence, Map<SenderType, Set<String>>> entry1 : map.getInnerMap().entrySet())
{
System.out.println(entry1.getKey());
for (Entry<SenderType, Set<String>> entry2 : entry1.getValue().entrySet())
{
System.out.println(" " + entry2.getKey() + ": " + entry2.getValue());
}
}
}
}