Allow properties for types

This commit is contained in:
BuildTools 2016-04-28 22:32:23 +02:00 committed by Olof Larsson
parent d73126c544
commit df4c031842
No known key found for this signature in database
GPG Key ID: BBEF14F97DA52474
102 changed files with 1476 additions and 545 deletions

View File

@ -47,6 +47,7 @@ import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreClick;
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreCmdurl;
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreStore;
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreUsys;
import com.massivecraft.massivecore.command.type.RegistryType;
import com.massivecraft.massivecore.engine.EngineMassiveCoreGank;
import com.massivecraft.massivecore.engine.EngineMassiveCoreChestGui;
import com.massivecraft.massivecore.engine.EngineMassiveCoreCollTick;
@ -234,6 +235,9 @@ public class MassiveCore extends MassivePlugin
// Setup IdUtil
IdUtil.setup();
// Setup RegistryType
RegistryType.registerAll();
// Activate
this.activate(
// Coll

View File

@ -6,6 +6,7 @@ import java.util.Map;
import org.bukkit.permissions.Permissible;
import com.massivecraft.massivecore.command.editor.annotation.EditorName;
import com.massivecraft.massivecore.command.editor.annotation.EditorNullable;
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
import com.massivecraft.massivecore.store.Entity;
@ -14,6 +15,7 @@ import com.massivecraft.massivecore.util.PermUtil;
import com.massivecraft.massivecore.util.TimeUnit;
import com.massivecraft.massivecore.xlib.mongodb.WriteConcern;
@EditorName("config")
public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
{
// -------------------------------------------- //

View File

@ -8,6 +8,8 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
import com.massivecraft.massivecore.command.type.convert.TypeConverterPotionEffectType;
/**
* This class wraps the Bukkit PotionEffect class by reimplementing storage of the data.
@ -21,6 +23,7 @@ public class PotionEffectWrap
// FIELDS
// -------------------------------------------- //
@EditorType(TypeConverterPotionEffectType.class)
protected int id;
public int getId() { return this.id; }
public void setId(int id) { this.id = id; }

View File

@ -8,6 +8,10 @@ import org.bukkit.Sound;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import com.massivecraft.massivecore.command.editor.annotation.EditorName;
import com.massivecraft.massivecore.command.editor.annotation.EditorNullable;
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
import com.massivecraft.massivecore.command.type.TypeId;
import com.massivecraft.massivecore.command.type.enumeration.TypeSound;
import com.massivecraft.massivecore.util.MUtil;
@ -19,6 +23,9 @@ public final class SoundEffect implements Serializable
// FIELDS: RAW
// -------------------------------------------- //
@EditorNullable(false)
@EditorName("sound")
@EditorType(value = TypeId.class, fieldName = "iSound")
private final String soundId;
public String getSoundId() { return this.soundId; }
public Sound getSound()

View File

@ -1,5 +1,7 @@
package com.massivecraft.massivecore.collections;
import java.util.Arrays;
import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive;
public class ExceptionSet<T>
@ -11,7 +13,7 @@ public class ExceptionSet<T>
public boolean standard = true;
public boolean isStandard() { return this.standard; }
public MassiveTreeSet<String, ComparatorCaseInsensitive> exceptions = new MassiveTreeSet<String, ComparatorCaseInsensitive>(ComparatorCaseInsensitive.get());
public MassiveTreeSet<String, ComparatorCaseInsensitive> exceptions = new MassiveTreeSet<>(ComparatorCaseInsensitive.get());
// -------------------------------------------- //
// CONSTRUCT
@ -32,11 +34,7 @@ public class ExceptionSet<T>
{
this.standard = standard;
if (exceptions.length == 0) return;
for (Object exception : exceptions)
{
String string = asString(exception);
this.exceptions.add(string);
}
this.exceptions.addAll(asStrings(exceptions));
}
// -------------------------------------------- //
@ -54,6 +52,25 @@ public class ExceptionSet<T>
return this.convert(t);
}
public MassiveTreeSet<String, ComparatorCaseInsensitive> asStrings(Object... exceptions)
{
return asStrings(Arrays.asList(exceptions));
}
public MassiveTreeSet<String, ComparatorCaseInsensitive> asStrings(Iterable<?> exceptions)
{
MassiveTreeSet<String, ComparatorCaseInsensitive> ret = new MassiveTreeSet<>(ComparatorCaseInsensitive.get());
for (Object exception : exceptions)
{
String string = asString(exception);
ret.add(string);
}
return ret;
}
// -------------------------------------------- //
// CONVERT
// -------------------------------------------- //

View File

@ -53,6 +53,8 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
// Requirements
this.addRequirements(RequirementEditorUse.get());
this.addRequirements(settings.getPropertyRequirements());
this.addRequirements(property.getRequirements());
}
// -------------------------------------------- //
@ -158,7 +160,7 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
// Apply
// We set the new property value.
this.getProperty().setValue(sender, this.getObject(), after);
this.setValue(after);
// After
// We inform what the value is after.
@ -195,11 +197,19 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
{
return this.getSettings().getUsed(sender);
}
public void setObject(CommandSender sender, O object)
{
this.getSettings().setUsed(sender, object);
}
public O getObject()
{
return this.getSettings().getUsed(sender);
}
public void setObject(O object)
{
this.setObject(sender, object);
}
public Mson getObjectVisual()
{
@ -233,9 +243,11 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
return this.getProperty().getValue(this.getObject());
}
public V setValue(V value)
public O setValue(V value)
{
return this.getProperty().setValue(sender, this.getObject(), value);
O object = this.getProperty().setValue(sender, this.getObject(), value);
this.setObject(object);
return object;
}
public Entry<O, V> getInheritedEntry()
@ -289,33 +301,41 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
public void show(int page)
{
Mson descValue = this.getInheritedVisual();
List<Mson> show = this.getValueType().getShow(this.getValue(), sender);
Property<O, V> property = this.getProperty();
Mson descProperty = property.getDisplayNameMson();
Mson descObject = this.getObjectVisual();
Mson title;
if (property instanceof PropertyThis)
{
title = descObject;
}
else
{
title = mson(
descProperty,
" for ",
descObject
);
}
// For things with line breaks.
if (descValue.contains("\n"))
if (show.size() > 1)
{
Mson title = mson(
this.getProperty().getDisplayNameMson(),
" for ",
this.getObjectVisual()
);
List<Mson> lines = descValue.split(Txt.PATTERN_NEWLINE);
message(Txt.getPage(lines, page, title, this));
message(Txt.getPage(show, page, title, this));
}
// Others
else
{
Mson descProperty = this.getProperty().getDisplayNameMson();
Mson descObject = this.getObjectVisual();
message(mson(
descProperty,
" for ",
descObject,
": ",
descValue
).color(ChatColor.GRAY));
message(Mson.prepondfix(
title.add(mson(":").color(ChatColor.GRAY)),
show,
null
));
}
}

View File

@ -114,7 +114,7 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
// Apply
// We set the new property value.
this.getProperty().setValue(sender, this.getObject(), after);
this.setValue(after);
// Create messages
List<Mson> messages = new MassiveList<>();

View File

@ -0,0 +1,33 @@
package com.massivecraft.massivecore.command.editor;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.type.Type;
public class CommandEditProperties<O, V> extends CommandEditAbstract<O, V>
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CommandEditProperties(EditSettings<O> settings, Property<O, V> property, String permission)
{
// Super
super(settings, property, null);
this.addChild(new CommandEditShow<>(settings, property));
// Parameters
if (property.isEditable())
{
Type<V> type = this.getValueType();
EditSettings<V> fieldSettings = new EditSettingsDelegate<>(settings, property);
for (Property<V, ?> prop : type.getInnerProperties())
{
this.addChild(prop.createEditCommand(fieldSettings));
}
}
if (permission != null) this.addRequirements(RequirementHasPerm.get(permission));
}
}

View File

@ -1,30 +0,0 @@
package com.massivecraft.massivecore.command.editor;
import java.lang.reflect.Field;
import com.massivecraft.massivecore.command.MassiveCommand;
public class CommandEditReflection<O, V> extends CommandEditAbstract<O, V>
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CommandEditReflection(EditSettings<O> settings, Property<O, V> property, Class<V> clazz)
{
super(settings, property, null);
// TODO: What about super classes?
// TODO: While we not often use super classes they could in theory also be meant to be editable.
// TODO: Something to consider coding in for the future.
for (Field field : clazz.getDeclaredFields())
{
if ( ! PropertyReflection.isVisible(field)) continue;
Property<O, ?> fieldProperty = PropertyReflection.get(field);
MassiveCommand fieldCommand = fieldProperty.createEditCommand(settings);
this.addChild(fieldCommand);
}
}
}

View File

@ -1,6 +1,7 @@
package com.massivecraft.massivecore.command.editor;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.command.type.TypeNullable;
public class CommandEditSimple<O, V> extends CommandEditAbstract<O, V>
@ -17,7 +18,9 @@ public class CommandEditSimple<O, V> extends CommandEditAbstract<O, V>
// Parameters
if (property.isEditable())
{
this.addParameter(TypeNullable.get(this.getProperty().getValueType()), "set", "show", true);
Type<V> type = this.getValueType();
if (property.isNullable()) type = TypeNullable.get(type);
this.addParameter(type, "set", "show", true);
}
}

View File

@ -1,11 +1,10 @@
package com.massivecraft.massivecore.command.editor;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.type.RegistryType;
import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.command.type.TypeSingleton;
public class CommandEditSingleton<O> extends CommandEditReflection<O, O>
public class CommandEditSingleton<O> extends CommandEditProperties<O, O>
{
// -------------------------------------------- //
// CONSTRUCT
@ -16,10 +15,9 @@ public class CommandEditSingleton<O> extends CommandEditReflection<O, O>
this(object, getType(object), permission);
}
@SuppressWarnings("unchecked")
public CommandEditSingleton(O object, Type<O> typeObject, String permission)
{
super(createEditSettings(object, typeObject, permission), new PropertyThis<>(typeObject), (Class<O>) object.getClass());
super(createEditSettings(object, typeObject), new PropertyThis<>(typeObject), permission);
String name = typeObject.getName(object);
this.setAliases(name);
this.setDesc("edit " + name);
@ -29,15 +27,13 @@ public class CommandEditSingleton<O> extends CommandEditReflection<O, O>
// UTIL
// -------------------------------------------- //
private static <O> EditSettings<O> createEditSettings(O object, Type<O> typeObject, String permission)
private static <O> EditSettings<O> createEditSettings(O object, Type<O> typeObject)
{
EditSettings<O> ret = new EditSettings<>(typeObject);
PropertyUsed<O> usedProperty = new PropertyUsed<O>(ret, object);
ret.setUsedProperty(usedProperty);
ret.addPropertyRequirements(RequirementHasPerm.get(permission));
return ret;
}

View File

@ -1,63 +0,0 @@
package com.massivecraft.massivecore.command.editor;
import java.util.Collection;
import java.util.List;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.type.RegistryType;
public abstract class CommandEditSingletons<O> extends MassiveCommand
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final String permission;
public String getPermission() { return this.permission; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CommandEditSingletons(Class<O> clazz, String permission)
{
// Aliases
String name = RegistryType.getType(clazz).getName() + "s";
this.setAliases(name);
this.setDesc("edit " + name);
// Requirements
this.permission = permission;
this.addRequirements(RequirementHasPerm.get(permission));
}
// -------------------------------------------- //
// ABSTRACT
// -------------------------------------------- //
public abstract Collection<O> getAll();
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
// This is evaluated every time, because it might change.
// In Factions we use this to edit configuration of flags and perms, and those can be added and removed at any time.
@Override
public List<MassiveCommand> getChildren()
{
List<MassiveCommand> ret = new MassiveList<>();
for (O singleton : this.getAll())
{
MassiveCommand cmd = new CommandEditSingleton<>(singleton, this.getPermission());
List<MassiveCommand> chain = this.getChain();
chain.add(this);
cmd.setChain(chain);
ret.add(cmd);
}
return ret;
}
}

View File

@ -1,6 +1,5 @@
package com.massivecraft.massivecore.command.editor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@ -9,6 +8,7 @@ import java.util.Set;
import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.requirement.Requirement;
import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.command.type.sender.TypeSender;
@ -46,14 +46,14 @@ public class EditSettings<O>
}
// Requirements to edit the used object.
private List<Requirement> usedRequirements = new ArrayList<Requirement>();
private List<Requirement> usedRequirements = new MassiveList<>();
public List<Requirement> getUsedRequirements() { return this.usedRequirements; }
public void setUsedRequirements(List<Requirement> requirements) { this.usedRequirements = requirements; }
public void addUsedRequirements(Collection<Requirement> requirements) { this.usedRequirements.addAll(requirements); }
public void addUsedRequirements(Requirement... requirements) { this.addUsedRequirements(Arrays.asList(requirements)); }
// Requirements to edit properties. Common stuff shared by all properties.
private List<Requirement> propertyRequirements = new ArrayList<Requirement>();
private List<Requirement> propertyRequirements = new MassiveList<>();
public List<Requirement> getPropertyRequirements() { return this.propertyRequirements; }
public void setPropertyRequirements(List<Requirement> requirements) { this.propertyRequirements = requirements; }
public void addPropertyRequirements(Collection<Requirement> requirements) { this.propertyRequirements.addAll(requirements); }

View File

@ -0,0 +1,37 @@
package com.massivecraft.massivecore.command.editor;
import org.bukkit.command.CommandSender;
public class EditSettingsDelegate<O, V> extends EditSettings<V>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
public EditSettingsDelegate(final EditSettings<O> outerSettings, final Property<O, V> property)
{
super(property.getValueType());
PropertyUsed<V> usedProperty = new PropertyUsed<V>(this) {
@Override
public V getRaw(CommandSender sender)
{
return property.getRaw(outerSettings.getUsed(sender));
}
@Override
public CommandSender setRaw(CommandSender sender, V used)
{
property.setRaw(outerSettings.getUsed(sender), used);
return sender;
}
};
this.setUsedProperty(usedProperty);
this.addUsedRequirements(outerSettings.getPropertyRequirements());
this.addUsedRequirements(property.getRequirements());
}
}

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
import java.util.Map.Entry;
import org.bukkit.ChatColor;
@ -17,10 +18,15 @@ import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
public abstract class Property<O, V> implements Named
{
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
public static final String SHOW_INDENT = " "; // Two spaces
// -------------------------------------------- //
// TYPE
// -------------------------------------------- //
@ -95,37 +101,34 @@ public abstract class Property<O, V> implements Named
// -------------------------------------------- //
public abstract V getRaw(O object);
public abstract void setRaw(O object, V value);
public abstract O setRaw(O object, V value);
public V getValue(O object)
{
return this.getRaw(object);
}
public V setValue(CommandSender sender, O object, V value)
public O setValue(CommandSender sender, O object, V value)
{
// Get Before
V before = this.getRaw(object);
// Get Live Entity
Entity<?> entity = null;
if (object instanceof Entity) entity = (Entity<?>)object;
if (entity != null && ! entity.isLive()) entity = null;
// NoChange
if (entity != null && MUtil.equals(before, value)) return before;
if (MUtil.equals(before, value)) return object;
// Apply
this.setRaw(object, value);
object = this.setRaw(object, value);
// Mark Change
if (entity != null) entity.changed();
// Mark Entity Changed
Entity<?> entity = null;
if (object instanceof Entity) entity = (Entity<?>)object;
if (entity != null && entity.isLive()) entity.changed();
// On Change
this.onChange(sender, object, before, value);
// Return Before
return before;
return object;
}
// -------------------------------------------- //
@ -164,15 +167,7 @@ public abstract class Property<O, V> implements Named
public CommandEditAbstract<O, V> createEditCommand(EditSettings<O> settings)
{
CommandEditAbstract<O, V> ret = this.getValueType().createEditCommand(settings, this);
// Add general requirements.
ret.addRequirements(settings.getPropertyRequirements());
// Add specific requirements.
ret.addRequirements(this.getRequirements());
return ret;
return this.getValueType().createEditCommand(settings, this);
}
public Mson getInheritedVisual(O object, O source, V value, CommandSender sender)
@ -221,12 +216,19 @@ public abstract class Property<O, V> implements Named
public List<Mson> getShowLines(O object, CommandSender sender)
{
Mson ret = Mson.mson(
Mson prefix = Mson.mson(
this.getDisplayNameMson(),
Mson.mson(": ").color(ChatColor.GRAY),
this.getInheritedVisual(object, sender)
);
return ret.split(Txt.PATTERN_NEWLINE);
Mson.mson(":").color(ChatColor.GRAY)
);
List<Mson> ret = Mson.prepondfix(prefix, this.getValueType().getShow(this.getInheritedValue(object), sender), null);
for (ListIterator<Mson> it = ret.listIterator(1); it.hasNext();)
{
Mson mson = it.next();
it.set(mson.text(SHOW_INDENT + mson.getText()));
}
return ret;
}
public static <O> List<Mson> getShowLines(O object, CommandSender sender, Collection<? extends Property<O, ?>> properties)

View File

@ -1,18 +1,40 @@
package com.massivecraft.massivecore.command.editor;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.editor.annotation.EditorEditable;
import com.massivecraft.massivecore.command.editor.annotation.EditorInheritable;
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
import com.massivecraft.massivecore.command.editor.annotation.EditorName;
import com.massivecraft.massivecore.command.editor.annotation.EditorNullable;
import com.massivecraft.massivecore.command.editor.annotation.EditorVisible;
import com.massivecraft.massivecore.command.type.RegistryType;
import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.command.type.TypeWrapper;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.particleeffect.ReflectionUtils;
import com.massivecraft.massivecore.util.ReflectionUtil;
import com.massivecraft.massivecore.util.Txt;
public class PropertyReflection<O, V> extends Property<O, V>
{
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
public static final boolean VISIBLE_DEFAULT = true;
public static final boolean INHERITABLE_DEFAULT = true;
public static final boolean EDITABLE_DEFAULT = true;
public static final boolean NULLABLE_DEFAULT = false;
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
@ -20,19 +42,106 @@ public class PropertyReflection<O, V> extends Property<O, V>
private final Field field;
public Field getField() { return this.field; }
private final Method getter;
public Method getGetter() { return this.getter; }
private final Method setter;
public Method getSetter() { return this.setter; }
public static Method calcGetter(Field field)
{
String name = Txt.upperCaseFirst(field.getName());
if ( ! getAnnotationValue(field, EditorMethods.class, false)) return null;
// Try with normal get
if (ReflectionUtil.hasMethod(field.getDeclaringClass(), "get" + name))
{
return ReflectionUtil.getMethod(field.getDeclaringClass(), "get" + name);
}
// For booleans try other options
if ( ! (boolean.class.equals(field.getType()) || Boolean.class.equals(field.getType()))) throw new RuntimeException(field.toString());
// Try is
if (ReflectionUtil.hasMethod(field.getDeclaringClass(), "is" + name))
{
return ReflectionUtil.getMethod(field.getDeclaringClass(), "is" + name);
}
// Try has
if (ReflectionUtil.hasMethod(field.getDeclaringClass(), "has" + name))
{
return ReflectionUtil.getMethod(field.getDeclaringClass(), "has" + name);
}
// Fail
throw new RuntimeException(field.toString());
}
public static Method calcSetter(Field field)
{
String name = Txt.upperCaseFirst(field.getName());
if ( ! getAnnotationValue(field, EditorMethods.class, false)) return null;
try
{
return ReflectionUtils.getMethod(field.getDeclaringClass(), "set" + name, field.getType());
}
catch (NoSuchMethodException e)
{
// Fail
throw new RuntimeException(field.toString());
}
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public static <O, V> PropertyReflection<O, V> get(Class<O> clazz, String fieldName)
public static <O> List<PropertyReflection<O, ?>> getAll(Class<O> clazz, Type<O> typeObject)
{
return get(ReflectionUtil.getField(clazz, fieldName));
List<PropertyReflection<O, ?>> ret = new MassiveList<>();
// TODO: What about super classes?
// TODO: While we not often use super classes they could in theory also be meant to be editable.
// TODO: Something to consider coding in for the future.
for (Field field : clazz.getDeclaredFields())
{
if ( ! isVisible(field)) continue;
PropertyReflection<O, ?> property = get(field, typeObject);
ret.add(property);
}
return ret;
}
@SuppressWarnings("unchecked")
public static <O, V> PropertyReflection<O, V> get(Field field)
public static <O, V> PropertyReflection<O, V> get(final Field field, Type<O> typeObject)
{
Type<O> typeObject = (Type<O>) RegistryType.getType(field.getDeclaringClass());
Type<V> typeValue = (Type<V>) RegistryType.getType(field);
// This makes sure it is called "volume for clickSound" instead of "volume for UiButtonClick 0.75 1.0"
// We also only do it for things with properties, so the edited message works and shows the actual visual.
if (typeValue.hasInnerProperties())
{
typeValue = new TypeWrapper<V>(typeValue)
{
@Override
public Mson getVisualMsonInner(V value, CommandSender sender)
{
return Mson.mson(PropertyReflection.getName(field)).color(ChatColor.AQUA);
}
@Override
public String getVisualInner(V value, CommandSender sender)
{
return ChatColor.AQUA + PropertyReflection.getName(field);
}
};
}
return new PropertyReflection<>(typeObject, typeValue, field);
}
@ -42,12 +151,14 @@ public class PropertyReflection<O, V> extends Property<O, V>
ReflectionUtil.makeAccessible(field);
this.field = field;
this.getter = calcGetter(field);
this.setter = calcSetter(field);
this.setVisible(isVisible(field));
this.setInheritable(isInheritable(field));
this.setEditable(isEditable(field));
this.setNullable(isNullable(field));
this.setName(field.getName());
this.setName(getName(field));
}
// -------------------------------------------- //
@ -57,13 +168,33 @@ public class PropertyReflection<O, V> extends Property<O, V>
@Override
public V getRaw(O object)
{
return ReflectionUtil.getField(this.getField(), object);
// Use method if possible.
if (this.getGetter() != null)
{
return ReflectionUtil.invokeMethod(this.getGetter(), object);
}
else
{
// Otherwise just get.
return ReflectionUtil.getField(this.getField(), object);
}
}
@Override
public void setRaw(O object, V value)
public O setRaw(O object, V value)
{
ReflectionUtil.setField(this.getField(), object, value);
// Use method if possible.
if (this.getSetter() != null)
{
ReflectionUtil.invokeMethod(this.getSetter(), object, value);
}
else
{
// Otherwise just set.
ReflectionUtil.setField(this.getField(), object, value);
}
return object;
}
// -------------------------------------------- //
@ -73,15 +204,14 @@ public class PropertyReflection<O, V> extends Property<O, V>
public static boolean isVisible(Field field)
{
// Create
boolean ret = true;
boolean ret = VISIBLE_DEFAULT;
// Fill > Standard
int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) ret = false;
// Fill > Annotation
EditorVisible annotation = field.getAnnotation(EditorVisible.class);
if (annotation != null) ret = annotation.value();
ret = getAnnotationValue(field, EditorVisible.class, ret);
// Return
return ret;
@ -89,29 +219,20 @@ public class PropertyReflection<O, V> extends Property<O, V>
public static boolean isInheritable(Field field)
{
// Create
boolean ret = true;
// Fill > Annotation
EditorInheritable annotation = field.getAnnotation(EditorInheritable.class);
if (annotation != null) ret = annotation.value();
// Return
return ret;
return getAnnotationValue(field, EditorInheritable.class, INHERITABLE_DEFAULT);
}
public static boolean isEditable(Field field)
{
// Create
boolean ret = true;
boolean ret = EDITABLE_DEFAULT;
// Fill > Standard
int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers) || Modifier.isFinal(modifiers)) ret = false;
// Fill > Annotation
EditorEditable annotation = field.getAnnotation(EditorEditable.class);
if (annotation != null) ret = annotation.value();
ret = getAnnotationValue(field, EditorEditable.class, ret);
// Return
return ret;
@ -122,15 +243,47 @@ public class PropertyReflection<O, V> extends Property<O, V>
// Primitive
if (field.getType().isPrimitive()) return false;
// Annotation
return getAnnotationValue(field, EditorNullable.class, NULLABLE_DEFAULT);
}
public static String getName(Field field)
{
// Create
boolean ret = true;
String ret;
// Fill > Standard
ret = field.getName();
// Fill > Annotation
EditorNullable annotation = field.getAnnotation(EditorNullable.class);
EditorName annotation = field.getAnnotation(EditorName.class);
if (annotation != null) ret = annotation.value();
// Return
return ret;
}
// -------------------------------------------- //
// ANNOTATION UTIL
// -------------------------------------------- //
public static <U> U getAnnotationValue(Field field, Class<? extends Annotation> clazz, U defaultValue)
{
// Try for field
Annotation annotation = field.getAnnotation(clazz);
if (annotation != null) return invokeAnnotationValue(annotation, clazz);
// Try class
annotation = field.getDeclaringClass().getAnnotation(clazz);
if (annotation != null) return invokeAnnotationValue(annotation, clazz);
return defaultValue;
}
private static <U> U invokeAnnotationValue(Annotation annotation, Class<?> clazz)
{
return ReflectionUtil.invokeMethod(ReflectionUtil.getMethod(clazz, "value"), annotation);
}
}

View File

@ -24,9 +24,9 @@ public class PropertyThis<O> extends Property<O, O>
}
@Override
public void setRaw(O object, O value)
public O setRaw(O object, O value)
{
return;
return object;
}
}

View File

@ -36,9 +36,9 @@ public class PropertyThisSenderEntity<O extends SenderEntity<O>> extends Propert
}
@Override
public void setRaw(CommandSender object, O value)
public CommandSender setRaw(CommandSender object, O value)
{
return;
return object;
}
}

View File

@ -39,9 +39,10 @@ public class PropertyUsed<V> extends Property<CommandSender, V>
}
@Override
public void setRaw(CommandSender sender, V used)
public CommandSender setRaw(CommandSender sender, V used)
{
this.used = used;
return sender;
}
}

View File

@ -0,0 +1,13 @@
package com.massivecraft.massivecore.command.editor.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface EditorMethods
{
boolean value();
}

View File

@ -0,0 +1,13 @@
package com.massivecraft.massivecore.command.editor.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface EditorName
{
String value();
}

View File

@ -0,0 +1,17 @@
package com.massivecraft.massivecore.command.editor.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EditorTypeList
{
// This is the type class.
Class<?> value();
// The name of the singleton instance field to use.
String fieldName() default "i";
}

View File

@ -0,0 +1,19 @@
package com.massivecraft.massivecore.command.editor.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EditorTypeMap
{
// This is the type class.
Class<?> typeKey();
Class<?> typeValue();
// The name of the singleton instance field to use.
String fieldNameKey() default "i";
String fieldNameValue() default "i";
}

View File

@ -0,0 +1,17 @@
package com.massivecraft.massivecore.command.editor.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EditorTypeSet
{
// This is the type class.
Class<?> value();
// The name of the singleton instance field to use.
String fieldName() default "i";
}

View File

@ -42,9 +42,6 @@ public class CmdMassiveCore extends MassiveCommand
public CmdMassiveCore()
{
// Tweak
this.cmdMassiveCoreConfig.setAliases("config");
// Children
this.addChild(this.cmdMassiveCoreUsys);
this.addChild(this.cmdMassiveCoreMStore);

View File

@ -7,36 +7,15 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.Difficulty;
import org.bukkit.DyeColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldType;
import org.bukkit.block.Biome;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.event.EventPriority;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.Permission;
import org.bukkit.potion.PotionEffectType;
import com.massivecraft.massivecore.Aspect;
import com.massivecraft.massivecore.Multiverse;
import com.massivecraft.massivecore.PotionEffectWrap;
import com.massivecraft.massivecore.SoundEffect;
import com.massivecraft.massivecore.collections.ExceptionSet;
import com.massivecraft.massivecore.collections.MassiveMap;
import com.massivecraft.massivecore.collections.WorldExceptionSet;
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeList;
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeMap;
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeSet;
import com.massivecraft.massivecore.command.type.combined.TypeDataBannerPattern;
import com.massivecraft.massivecore.command.type.combined.TypeDataPotionEffect;
import com.massivecraft.massivecore.command.type.combined.TypeEntry;
import com.massivecraft.massivecore.command.type.combined.TypePotionEffectWrap;
import com.massivecraft.massivecore.command.type.combined.TypeSoundEffect;
@ -51,6 +30,7 @@ import com.massivecraft.massivecore.command.type.enumeration.TypeDyeColor;
import com.massivecraft.massivecore.command.type.enumeration.TypeEntityType;
import com.massivecraft.massivecore.command.type.enumeration.TypeEnvironment;
import com.massivecraft.massivecore.command.type.enumeration.TypeEventPriority;
import com.massivecraft.massivecore.command.type.enumeration.TypeFireworkEffectType;
import com.massivecraft.massivecore.command.type.enumeration.TypeGameMode;
import com.massivecraft.massivecore.command.type.enumeration.TypeHorseColor;
import com.massivecraft.massivecore.command.type.enumeration.TypeHorseStyle;
@ -74,9 +54,6 @@ import com.massivecraft.massivecore.command.type.sender.TypePlayer;
import com.massivecraft.massivecore.command.type.sender.TypeSender;
import com.massivecraft.massivecore.command.type.store.TypeAspect;
import com.massivecraft.massivecore.command.type.store.TypeMultiverse;
import com.massivecraft.massivecore.particleeffect.ParticleEffect;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.teleport.Destination;
import com.massivecraft.massivecore.util.ReflectionUtil;
public class RegistryType
@ -86,9 +63,28 @@ public class RegistryType
// -------------------------------------------- //
private static final Map<Class<?>, Type<?>> registry = new MassiveMap<>();
public static <T> void register(Class<T> clazz, Type<? super T> type) { registry.put(clazz, type); }
@SuppressWarnings("unchecked") public static <T> Type<? super T> unregister(Class<T> clazz) { return (Type<T>) registry.remove(clazz); }
public static boolean isRegistered(Class<?> clazz) { return registry.containsKey(clazz); }
public static <T> void register(Class<T> clazz, Type<? super T> type)
{
if (clazz == null) throw new NullPointerException("clazz");
if (type == null) throw new NullPointerException("type");
registry.put(clazz, type);
}
public static <T> void register(Type<T> type)
{
if (type == null) throw new NullPointerException("type");
register(type.getClazz(), type);
}
@SuppressWarnings("unchecked")
public static <T> Type<? super T> unregister(Class<T> clazz)
{
if (clazz == null) throw new NullPointerException("clazz");
return (Type<T>) registry.remove(clazz);
}
public static boolean isRegistered(Class<?> clazz)
{
if (clazz == null) throw new NullPointerException("clazz");
return registry.containsKey(clazz);
}
public static Type<?> getType(Field field)
{
@ -97,11 +93,32 @@ public class RegistryType
{
Class<?> clazz = annotation.value();
if (clazz == void.class) clazz = getType(field.getGenericType()).getClass();
return ReflectionUtil.getField(clazz, annotation.fieldName(), null);
return getType(clazz, annotation.fieldName());
}
EditorTypeList annList = field.getAnnotation(EditorTypeList.class);
if (annList != null)
{
return TypeList.get(getType(annList.value(), annList.fieldName()));
}
EditorTypeSet annSet = field.getAnnotation(EditorTypeSet.class);
if (annSet != null)
{
return TypeSet.get(getType(annSet.value(), annSet.fieldName()));
}
EditorTypeMap annMap = field.getAnnotation(EditorTypeMap.class);
if (annMap != null)
{
return TypeMap.get(getType(annMap.typeKey(), annMap.fieldNameKey()), getType(annMap.typeValue(), annMap.fieldNameValue()));
}
return getType(field.getGenericType());
}
private static Type<?> getType(Class<?> clazz, String fieldName)
{
return ReflectionUtil.getField(clazz, fieldName, null);
}
public static Type<?> getType(java.lang.reflect.Type reflectType)
{
@ -151,11 +168,6 @@ public class RegistryType
// DEFAULTS
// -------------------------------------------- //
static
{
registerAll();
}
public static void registerAll()
{
// Primitive
@ -177,57 +189,62 @@ public class RegistryType
register(Long.TYPE, TypeLong.get());
register(Long.class, TypeLong.get());
register(String.class, TypeString.get());
// Bukkit
register(Destination.class, TypeDestination.get());
register(ItemStack.class, TypeItemStack.get());
register(Permission.class, TypePermission.get());
register(PotionEffectType.class, TypePotionEffectType.get());
register(PS.class, TypePS.get());
register(World.class, TypeWorld.get());
register(PotionEffectWrap.class, TypePotionEffectWrap.get());
register(SoundEffect.class, TypeSoundEffect.get());
register(TypeString.get());
// Enum
register(Biome.class, TypeBiome.get());
register(ChatColor.class, TypeChatColor.get());
register(Difficulty.class, TypeDifficulty.get());
register(DyeColor.class, TypeDyeColor.get());
register(EntityType.class, TypeEntityType.get());
register(Environment.class, TypeEnvironment.get());
register(EventPriority.class, TypeEventPriority.get());
register(GameMode.class, TypeGameMode.get());
register(Horse.Color.class, TypeHorseColor.get());
register(Horse.Style.class, TypeHorseStyle.get());
register(Horse.Variant.class, TypeHorseVariant.get());
register(Material.class, TypeMaterial.get());
register(Ocelot.Type.class, TypeOcelotType.get());
register(ParticleEffect.class, TypeParticleEffect.get());
register(TypeBiome.get());
register(TypeChatColor.get());
register(TypeDifficulty.get());
register(TypeDyeColor.get());
register(TypeEntityType.get());
register(TypeEnvironment.get());
register(TypeEventPriority.get());
register(TypeFireworkEffectType.get());
register(TypeGameMode.get());
register(TypeHorseColor.get());
register(TypeHorseStyle.get());
register(TypeHorseVariant.get());
register(TypeMaterial.get());
register(TypeOcelotType.get());
register(TypeParticleEffect.get());
// About 15% of all servers are still using 1.7.x.
// We catch NoClassDefFoundError and silently move along on those servers.
try
{
register(org.bukkit.entity.Rabbit.Type.class, TypeRabbitType.get());
register(TypeRabbitType.get());
}
catch (Throwable t)
{
}
register(SkeletonType.class, TypeSkeletonType.get());
register(Sound.class, TypeSound.get());
register(Profession.class, TypeVillagerProfession.get());
register(WorldType.class, TypeWorldType.get());
register(TypeSkeletonType.get());
register(TypeSound.get());
register(TypeVillagerProfession.get());
register(TypeWorldType.get());
// Bukkit
register(TypeDestination.get());
register(TypeItemStack.get());
register(TypeDataBannerPattern.get());
register(TypeDataPotionEffect.get());
register(TypeDataFireworkEffect.get());
register(TypeDataItemStack.get());
register(TypePermission.get());
register(TypePotionEffectType.get());
register(TypePS.get());
register(TypeWorld.get());
register(TypePotionEffectWrap.get());
register(TypeSoundEffect.get());
// Sender
register(Player.class, TypePlayer.get());
register(CommandSender.class, TypeSender.get());
register(TypePlayer.get());
register(TypeSender.get());
// Store
register(Aspect.class, TypeAspect.get());
register(Multiverse.class, TypeMultiverse.get());
register(TypeAspect.get());
register(TypeMultiverse.get());
// Collection
register(WorldExceptionSet.class, TypeExceptionSet.get(TypeWorld.get()));

View File

@ -24,8 +24,10 @@ public interface Type<T> extends Named
// Human friendly name
public String getName();
public Class<T> getClazz();
// -------------------------------------------- //
// INNER
// INNER TYPE
// -------------------------------------------- //
public <I extends Type<?>> List<I> getInnerTypes();
@ -42,6 +44,19 @@ public interface Type<T> extends Named
public Integer getIndexUser(int indexTechy);
public Integer getIndexTech(int indexUser);
// -------------------------------------------- //
// INNER PROPERTY
// -------------------------------------------- //
public boolean hasInnerProperties();
public <I extends Property<T, ?>> List<I> getInnerProperties();
public <I extends Property<T, ?>> I getInnerProperty(int index);
public <I extends Property<T, ?>> void setInnerProperties(Collection<I> innerTypes);
@SuppressWarnings("unchecked")
public <I extends Property<T, ?>> void setInnerProperties(I... innerTypes);
// -------------------------------------------- //
// WRITE VISUAL COLOR
// -------------------------------------------- //
@ -50,6 +65,15 @@ public interface Type<T> extends Named
public ChatColor getVisualColor(T value);
public void setVisualColor(ChatColor color);
// -------------------------------------------- //
// WRITE SHOW
// -------------------------------------------- //
// A list of property values.
public List<Mson> getShowInner(T value, CommandSender sender);
public List<Mson> getShow(T value, CommandSender sender);
public List<Mson> getShow(T value);
// -------------------------------------------- //
// WRITE VISUAL MSON
// -------------------------------------------- //

View File

@ -1,5 +1,6 @@
package com.massivecraft.massivecore.command.type;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -19,9 +20,11 @@ import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.editor.CommandEditAbstract;
import com.massivecraft.massivecore.command.editor.CommandEditProperties;
import com.massivecraft.massivecore.command.editor.CommandEditSimple;
import com.massivecraft.massivecore.command.editor.EditSettings;
import com.massivecraft.massivecore.command.editor.Property;
import com.massivecraft.massivecore.command.editor.PropertyReflection;
import com.massivecraft.massivecore.comparator.ComparatorSmart;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.store.SenderEntity;
@ -67,6 +70,29 @@ public abstract class TypeAbstract<T> implements Type<T>
return Txt.implode(words, " ").toLowerCase();
}
protected final Class<T> clazz;
public Class<T> getClazz() { return this.clazz; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
@SuppressWarnings("unchecked")
public TypeAbstract(Class<?> clazz)
{
this.clazz = (Class<T>) clazz;
try
{
constructor = ReflectionUtil.getConstructor(clazz);
}
catch(Exception e)
{
}
}
// -------------------------------------------- //
// INNER
// -------------------------------------------- //
@ -110,6 +136,47 @@ public abstract class TypeAbstract<T> implements Type<T>
return this.userOrder.get(indexUser);
}
// -------------------------------------------- //
// INNER PROPERTY
// -------------------------------------------- //
protected List<Property<T, ?>> innerProperties = new MassiveList<>();
public boolean hasInnerProperties() { return ! this.getInnerProperties().isEmpty(); }
@SuppressWarnings("unchecked")
public <I extends Property<T, ?>> List<I> getInnerProperties() { return (List<I>) this.innerProperties; }
@SuppressWarnings("unchecked")
public <I extends Property<T, ?>> I getInnerProperty(int index) { return (I) this.getInnerProperties().get(index); }
public <I extends Property<T, ?>> void setInnerProperties(Collection<I> innerProperties) { this.innerProperties = new MassiveList<Property<T, ?>>(innerProperties); }
@SuppressWarnings("unchecked")
public <I extends Property<T, ?>> void setInnerProperties(I... innerProperties) { this.setInnerProperties(Arrays.asList(innerProperties)); }
public void setInnerProperties(Class<T> clazz) { this.setInnerProperties(PropertyReflection.getAll(clazz, this)); }
// -------------------------------------------- //
// WRITE SHOW
// -------------------------------------------- //
// A list of property values.
public List<Mson> getShowInner(T value, CommandSender sender)
{
if (this.hasInnerProperties())
{
return Property.getShowLines(value, sender, this.getInnerProperties());
}
return this.getVisualMsonInner(value, sender).split(Txt.PATTERN_NEWLINE);
}
public List<Mson> getShow(T value, CommandSender sender)
{
if (value == null) return Collections.singletonList(MSON_NULL);
return this.getShowInner(value, sender);
}
public List<Mson> getShow(T value)
{
return this.getShow(value, null);
}
// -------------------------------------------- //
// WRITE VISUAL COLOR
// -------------------------------------------- //
@ -153,8 +220,10 @@ public abstract class TypeAbstract<T> implements Type<T>
public Mson getVisualMsonInner(T value, CommandSender sender)
{
String visualInner = this.getVisualInner(value, sender);
if (visualInner == null) MUtil.stackTraceDebug("visualInner null for + " + value);
return Mson.fromParsedMessage(visualInner);
Mson ret = Mson.fromParsedMessage(visualInner);
if (this.hasInnerProperties()) ret.tooltip(Mson.toPlain(this.getShow(value, sender), true));
return ret;
}
@Override
@ -581,13 +650,29 @@ public abstract class TypeAbstract<T> implements Type<T>
@Override
public <O> CommandEditAbstract<O, T> createEditCommand(EditSettings<O> settings, Property<O, T> property)
{
return new CommandEditSimple<O, T>(settings, property);
if (this.hasInnerProperties())
{
return new CommandEditProperties<O, T>(settings, property, null);
}
else
{
return new CommandEditSimple<O, T>(settings, property);
}
}
private Constructor<T> constructor;
@Override
public T createNewInstance()
{
return null;
try
{
return this.constructor.newInstance();
}
catch (Exception e)
{
return null;
}
}
}

View File

@ -95,6 +95,15 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
public Collection<String> getTabs() { return this.tabs; }
public void setTabs(Collection<String> tabs) { this.tabs = tabs; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public TypeAbstractChoice(Class<?> clazz)
{
super(clazz);
}
// -------------------------------------------- //
// OVERRIDE: TYPE
// -------------------------------------------- //

View File

@ -13,6 +13,15 @@ public abstract class TypeAbstractException<T> extends TypeAbstract<T>
public abstract T valueOf(String arg, CommandSender sender) throws Exception;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public TypeAbstractException(Class<?> clazz)
{
super(clazz);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //

View File

@ -28,6 +28,15 @@ public abstract class TypeAbstractSelect<T> extends TypeAbstract<T> implements A
public boolean canList(CommandSender sender) { return true; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public TypeAbstractSelect(Class<?> clazz)
{
super(clazz);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //

View File

@ -6,6 +6,15 @@ import com.massivecraft.massivecore.util.Txt;
public abstract class TypeAbstractSimple<T> extends TypeAbstractException<T>
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public TypeAbstractSimple(Class<?> clazz)
{
super(clazz);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //

View File

@ -21,6 +21,7 @@ public class TypeColor extends TypeAbstract<Color>
private static TypeColor i = new TypeColor();
public static TypeColor get() { return i; }
public TypeColor() { super(Color.class); }
// -------------------------------------------- //
// WRITE VISUAL

View File

@ -0,0 +1,19 @@
package com.massivecraft.massivecore.command.type;
import com.massivecraft.massivecore.command.type.primitive.TypeObject;
import com.massivecraft.massivecore.item.DataFireworkEffect;
public class TypeDataFireworkEffect extends TypeObject<DataFireworkEffect>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeDataFireworkEffect i = new TypeDataFireworkEffect();
public static TypeDataFireworkEffect get() { return i; }
public TypeDataFireworkEffect()
{
super(DataFireworkEffect.class);
}
}

View File

@ -22,6 +22,7 @@ public class TypeDate extends TypeAbstractSimple<Date>
private static TypeDate i = new TypeDate();
public static TypeDate get() { return i; }
public TypeDate() { super(Date.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -17,6 +17,7 @@ public class TypeDestination extends TypeAbstract<Destination>
private static TypeDestination i = new TypeDestination();
public static TypeDestination get() { return i; }
public TypeDestination() { super(Destination.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -19,6 +19,7 @@ public class TypeEnchantment extends TypeAbstractChoice<Enchantment>
public static TypeEnchantment get() { return i; }
public TypeEnchantment()
{
super(Enchantment.class);
this.setVisualColor(ChatColor.AQUA);
this.setAll(Enchantment.values());
}

View File

@ -0,0 +1,51 @@
package com.massivecraft.massivecore.command.type;
import org.bukkit.Sound;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.enumeration.TypeSound;
import com.massivecraft.massivecore.command.type.primitive.TypeStringId;
public class TypeId<T> extends TypeTransformer<T, String>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeId<Sound> iSound = TypeId.get(TypeSound.get());
public static TypeId<Sound> getSound() { return iSound; }
public static <T> TypeId<T> get(Type<T> inner) { return new TypeId<>(inner); }
public TypeId(Type<T> inner)
{
super(inner, TypeStringId.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String innerToOuter(T inner)
{
if (inner == null) return null;
return INNER.getId(inner);
}
@Override
public T outerToInner(String outer)
{
if (outer == null) return null;
try
{
return this.INNER.read(outer);
}
catch (MassiveException e)
{
e.printStackTrace();
return null;
}
}
}

View File

@ -36,6 +36,7 @@ public class TypeItemStack extends TypeAbstract<ItemStack>
public TypeItemStack(ExceptionSet<Material> materialsAllowed)
{
super(ItemStack.class);
this.materialsAllowed = materialsAllowed;
}

View File

@ -0,0 +1,42 @@
package com.massivecraft.massivecore.command.type;
import org.bukkit.Material;
import com.massivecraft.massivecore.command.type.enumeration.TypeMaterial;
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
@SuppressWarnings("deprecation")
public class TypeMaterialId extends TypeTransformer<Material, Integer>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeMaterialId i = new TypeMaterialId();
public static TypeMaterialId get() { return i; }
public TypeMaterialId()
{
super(TypeMaterial.get(), TypeInteger.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Integer innerToOuter(Material inner)
{
if (inner == null) return null;
return inner.getId();
}
@Override
public Material outerToInner(Integer outer)
{
if (outer == null) return null;
return Material.getMaterial(outer);
}
}

View File

@ -18,6 +18,7 @@ public class TypeMillisDiff extends TypeAbstractException<Long>
private static TypeMillisDiff i = new TypeMillisDiff();
public static TypeMillisDiff get() { return i; }
public TypeMillisDiff() { super(Long.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -6,7 +6,6 @@ import java.util.Collections;
import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.TypeAbstract;
public abstract class TypeNameAbstract extends TypeAbstract<String>
{
@ -24,6 +23,7 @@ public abstract class TypeNameAbstract extends TypeAbstract<String>
public TypeNameAbstract(boolean strict)
{
super(String.class);
this.strict = strict;
}

View File

@ -25,6 +25,7 @@ public class TypePS extends TypeAbstract<PS>
private static TypePS i = new TypePS();
public static TypePS get() { return i; }
public TypePS() { super(PS.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -12,6 +12,7 @@ public class TypePermission extends TypeAbstractChoice<Permission>
private static TypePermission i = new TypePermission();
public static TypePermission get() { return i; }
public TypePermission() { super(Permission.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -12,6 +12,7 @@ public class TypePotionEffectType extends TypeAbstractChoice<PotionEffectType>
public static TypePotionEffectType get() { return i; }
public TypePotionEffectType()
{
super(PotionEffectType.class);
this.setAll(PotionEffectType.values());
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.massivecore.command.type;
import com.massivecraft.massivecore.command.editor.annotation.EditorName;
public class TypeReflection<T> extends TypeAbstractChoice<T>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
public static <T> TypeReflection<T> get(Class<T> clazz){ return new TypeReflection<>(clazz); }
public TypeReflection(Class<T> clazz)
{
super(clazz);
this.setInnerProperties(clazz);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String getName()
{
return this.getClazz().getSimpleName();
}
@Override
public String getIdInner(T value)
{
return getId(value.getClass());
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public static String getId(Class<?> clazz)
{
EditorName ann = clazz.getAnnotation(EditorName.class);
if (ann != null) return ann.value();
return clazz.getSimpleName();
}
}

View File

@ -1,42 +1,17 @@
package com.massivecraft.massivecore.command.type;
import com.massivecraft.massivecore.command.editor.CommandEditAbstract;
import com.massivecraft.massivecore.command.editor.CommandEditReflection;
import com.massivecraft.massivecore.command.editor.EditSettings;
import com.massivecraft.massivecore.command.editor.Property;
public class TypeSingleton<T> extends TypeAbstractChoice<T>
public class TypeSingleton<T> extends TypeReflection<T>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
public static <T> TypeSingleton<T> get(T singleton){ return new TypeSingleton<>(singleton); }
@SuppressWarnings("unchecked")
public TypeSingleton(T singleton)
{
super((Class<T>) singleton.getClass());
super.setAll(singleton);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String getName()
{
return this.getAll().iterator().next().getClass().getSimpleName();
}
@Override
public String getIdInner(T value)
{
return value.getClass().getSimpleName();
}
@SuppressWarnings("unchecked")
public <O> CommandEditAbstract<O, T> createEditCommand(EditSettings<O> settings, Property<O, T> property)
{
return new CommandEditReflection<O, T>(settings, property, (Class<T>) this.getAll().iterator().next().getClass());
}
}

View File

@ -35,6 +35,7 @@ public class TypeStringCommand extends TypeAbstract<String>
public TypeStringCommand()
{
super(String.class);
this.setVisualColor(ChatColor.AQUA);
}

View File

@ -66,6 +66,7 @@ public abstract class TypeTransformer<I, O> extends TypeAbstract<O>
public TypeTransformer(Type<I> typeInner, Type<O> typeOuter)
{
super(typeOuter.getClazz());
this.setInnerTypes(typeInner, typeOuter);
INNER = typeInner;
OUTER = typeOuter;
@ -89,6 +90,22 @@ public abstract class TypeTransformer<I, O> extends TypeAbstract<O>
return INNER.getName();
}
// -------------------------------------------- //
// INNER PROPERTIES
// -------------------------------------------- //
@Override
public <U extends Property<O, ?>> List<U> getInnerProperties()
{
return OUTER.getInnerProperties();
}
@Override
public <U extends Property<O, ?>> void setInnerProperties(Collection<U> innerProperties)
{
OUTER.setInnerProperties(innerProperties);
}
// -------------------------------------------- //
// WRITE VISUAL COLOR
// -------------------------------------------- //

View File

@ -27,8 +27,8 @@ public class TypeUniverse extends TypeAbstractChoice<String>
public static TypeUniverse get(Aspect aspect) { return new TypeUniverse(aspect); }
public static TypeUniverse get(Multiverse multiverse) { return new TypeUniverse(multiverse); }
public TypeUniverse(Aspect aspect) { this.aspect = aspect; }
public TypeUniverse(Multiverse multiverse) { this.multiverse = multiverse; }
public TypeUniverse(Aspect aspect) { super(String.class); this.aspect = aspect; }
public TypeUniverse(Multiverse multiverse) { super(String.class); this.multiverse = multiverse; }
// -------------------------------------------- //
// OVERRIDE

View File

@ -16,6 +16,7 @@ public class TypeWorld extends TypeAbstractChoice<World>
private static TypeWorld i = new TypeWorld();
public static TypeWorld get() { return i; }
public TypeWorld() { super(World.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -14,6 +14,7 @@ public class TypeWorldId extends TypeAbstractChoice<String>
private static TypeWorldId i = new TypeWorldId();
public static TypeWorldId get() { return i; }
public TypeWorldId() { super(String.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -1,11 +1,16 @@
package com.massivecraft.massivecore.command.type;
import java.util.Collection;
import java.util.List;
import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.MassiveList;
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 class TypeWrapper<T> extends TypeAbstract<T>
{
@ -15,7 +20,7 @@ public class TypeWrapper<T> extends TypeAbstract<T>
public TypeWrapper(Type<T> innerType)
{
if (innerType == null) throw new NullPointerException("inner");
super(innerType.getClazz());
this.setInnerType(innerType);
}
@ -29,6 +34,20 @@ public class TypeWrapper<T> extends TypeAbstract<T>
return this.getInnerType().getName();
}
@Override
public List<Mson> getShowInner(T value, CommandSender sender)
{
Type<T> innerType = this.getInnerType();
return innerType.getShowInner(value, sender);
}
@Override
public Mson getVisualMsonInner(T value, CommandSender sender)
{
Type<T> innerType = this.getInnerType();
return innerType.getVisualMsonInner(value, sender);
}
@Override
public String getVisualInner(T value, CommandSender sender)
{
@ -69,4 +88,32 @@ public class TypeWrapper<T> extends TypeAbstract<T>
return this.getInnerType().allowSpaceAfterTab();
}
@Override
public <I extends Property<T, ?>> List<I> getInnerProperties()
{
Type<T> innerType = this.getInnerType();
return innerType.getInnerProperties();
}
@Override
public <I extends Property<T, ?>> void setInnerProperties(Collection<I> innerProperties)
{
Type<T> innerType = this.getInnerType();
innerType.setInnerProperties(innerProperties);
}
@Override
public <O> CommandEditAbstract<O, T> createEditCommand(EditSettings<O> settings, Property<O, T> property)
{
Type<T> innerType = this.getInnerType();
return innerType.createEditCommand(settings, property);
}
@Override
public T createNewInstance()
{
Type<T> innerType = this.getInnerType();
return innerType.createNewInstance();
}
}

View File

@ -12,6 +12,8 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.editor.Property;
import com.massivecraft.massivecore.command.editor.PropertyReflection;
import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.command.type.TypeAbstract;
import com.massivecraft.massivecore.mson.Mson;
@ -87,19 +89,64 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
// CONSTRUCT
// -------------------------------------------- //
public TypeCombined(Type<?>... innerTypes)
public TypeCombined(Class<?> clazz, Type<?>... innerTypes)
{
super(clazz);
this.setInnerTypes(innerTypes);
this.setSeparators(SEPARATORS_DEFAULT);
}
public TypeCombined(Class<T> clazz)
{
super(clazz);
this.setInnerProperties(PropertyReflection.getAll(clazz, this));
List<Type<?>> innerTypes = new MassiveList<>();
for (Property<T, ?> property : this.getInnerProperties())
{
innerTypes.add(property.getValueType());
}
this.setInnerTypes(innerTypes);
this.setSeparators(SEPARATORS_DEFAULT);
}
// -------------------------------------------- //
// ABSTRACT
// CORE
// -------------------------------------------- //
public abstract T combine(List<Object> parts);
public T combine(List<Object> parts)
{
if ( ! this.hasInnerProperties()) throw new IllegalStateException("TypeCombined#combine must be implemented.");
public abstract List<Object> split(T value);
T ret = this.createNewInstance();
if (ret == null) throw new IllegalStateException("Type#createNewInstance must be implemented.");
int i = 0;
for (Object part : parts)
{
Property<T, Object> property = this.getInnerProperty(i);
property.setRaw(ret, part);
i++;
}
return ret;
}
public List<Object> split(T value)
{
if ( ! this.hasInnerProperties()) throw new IllegalStateException("TypeCombined#split must be implemented.");
List<Object> parts = new MassiveList<>();
for (Property<T, ?> property : this.getInnerProperties())
{
parts.add(property.getValue(value));
}
return parts;
}
// -------------------------------------------- //
// SPLIT ENTRIES
@ -115,7 +162,7 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
if (parts.size() > this.getInnerTypes().size()) throw new RuntimeException("Too many parts!");
for (int i = 0; i < parts.size(); i++)
{
Type<?> type = this.getInnerTypes().get(i);
Type<?> type = this.getInnerType(i);
Object part = parts.get(i);
SimpleEntry<Type<?>, Object> entry = new SimpleEntry<Type<?>, Object>(type, part);
ret.add(entry);
@ -203,6 +250,33 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
return Txt.implode(parts, this.getTypeNameSeparator());
}
// -------------------------------------------- //
// WRITE SHOW
// -------------------------------------------- //
@SuppressWarnings("unchecked")
@Override
public List<Mson> getShowInner(T value, CommandSender sender)
{
if (this.hasInnerProperties())
{
return super.getShowInner(value, sender);
}
// Create
List<Mson> ret = new MassiveList<>();
// Fill
for (Entry<Type<?>, Object> entry : this.splitEntriesUser(value))
{
Type<Object> type = (Type<Object>) entry.getKey();
ret.addAll(type.getShow(entry.getValue()));
}
// Return
return ret;
}
// -------------------------------------------- //
// WRITE VISUAL MSON
// -------------------------------------------- //
@ -323,7 +397,7 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
for (int i = 0; i < innerArgs.size(); i++)
{
String innerArg = innerArgs.get(i);
Type<?> innerType = this.getInnerTypes().get(getIndexUser(i));
Type<?> innerType = this.getInnerType(getIndexUser(i));
Object part = innerType.read(innerArg, sender);
ret.add(part);
}

View File

@ -0,0 +1,19 @@
package com.massivecraft.massivecore.command.type.combined;
import com.massivecraft.massivecore.item.DataBannerPattern;
public class TypeDataBannerPattern extends TypeCombined<DataBannerPattern>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeDataBannerPattern i = new TypeDataBannerPattern();
public static TypeDataBannerPattern get() { return i; }
public TypeDataBannerPattern()
{
super(DataBannerPattern.class);
}
}

View File

@ -0,0 +1,18 @@
package com.massivecraft.massivecore.command.type.combined;
import com.massivecraft.massivecore.item.DataPotionEffect;
public class TypeDataPotionEffect extends TypeCombined<DataPotionEffect>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeDataPotionEffect i = new TypeDataPotionEffect();
public static TypeDataPotionEffect get() { return i; }
public TypeDataPotionEffect()
{
super(DataPotionEffect.class);
}
}

View File

@ -23,7 +23,7 @@ public class TypeEntry<K, V> extends TypeCombined<Entry<K, V>>
public static <K, V> TypeEntry<K, V> get(Type<K> keyType, Type<V> valueType) { return new TypeEntry<K, V>(keyType, valueType); }
public TypeEntry(Type<K> keyType, Type<V> valueType)
{
super(keyType, valueType);
super(Entry.class, keyType, valueType);
this.setTypeNameSeparator(" and ");
}

View File

@ -1,66 +0,0 @@
package com.massivecraft.massivecore.command.type.combined;
import java.util.List;
import org.bukkit.DyeColor;
import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.type.enumeration.TypeDyeColor;
import com.massivecraft.massivecore.command.type.enumeration.TypePatternType;
public class TypePattern extends TypeCombined<Pattern>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypePattern i = new TypePattern();
public static TypePattern get() { return i; }
public TypePattern()
{
super(
TypeDyeColor.get(),
TypePatternType.get()
);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public List<Object> split(Pattern value)
{
return new MassiveList<Object>(
value.getColor(),
value.getPattern()
);
}
@Override
public Pattern combine(List<Object> parts)
{
DyeColor color = null;
PatternType pattern = null;
for (int i = 0 ; i < parts.size() ; i++)
{
Object part = parts.get(i);
if (i == 0)
{
color = (DyeColor)part;
}
else if (i == 1)
{
pattern = (PatternType) part;
}
}
return new Pattern(color, pattern);
}
}

View File

@ -1,14 +1,6 @@
package com.massivecraft.massivecore.command.type.combined;
import java.util.List;
import org.bukkit.potion.PotionEffectType;
import com.massivecraft.massivecore.PotionEffectWrap;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.type.TypePotionEffectType;
import com.massivecraft.massivecore.command.type.primitive.TypeBoolean;
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
public class TypePotionEffectWrap extends TypeCombined<PotionEffectWrap>
{
@ -21,71 +13,7 @@ public class TypePotionEffectWrap extends TypeCombined<PotionEffectWrap>
public TypePotionEffectWrap()
{
super(
TypePotionEffectType.get(),
TypeInteger.get(),
TypeInteger.get(),
TypeBoolean.getYes(),
TypeBoolean.getYes()
);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public List<Object> split(PotionEffectWrap value)
{
return new MassiveList<Object>(
value.getPotionEffectType(),
value.getAmplifier(),
value.getDuration(),
value.isAmbient(),
value.isParticles()
);
}
@Override
public PotionEffectWrap combine(List<Object> parts)
{
// Create
PotionEffectWrap ret = new PotionEffectWrap();
// Fill
for (int i = 0 ; i < parts.size() ; i++)
{
Object part = parts.get(i);
if (i == 0)
{
PotionEffectType potionEffectType = (PotionEffectType)part;
ret.setPotionEffectType(potionEffectType);
}
else if (i == 1)
{
Integer amplifier = (Integer) part;
ret.setAmplifier(amplifier);
}
else if (i == 2)
{
Integer duration = (Integer) part;
ret.setDuration(duration);
}
else if (i == 3)
{
Boolean ambient = (Boolean) part;
ret.setAmbient(ambient);
}
else if (i == 4)
{
Boolean particles = (Boolean) part;
ret.setParticles(particles);
}
}
// Return
return ret;
super(PotionEffectWrap.class);
}
}

View File

@ -1,13 +1,6 @@
package com.massivecraft.massivecore.command.type.combined;
import java.util.List;
import org.bukkit.Sound;
import com.massivecraft.massivecore.SoundEffect;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.type.enumeration.TypeSound;
import com.massivecraft.massivecore.command.type.primitive.TypeFloat;
public class TypeSoundEffect extends TypeCombined<SoundEffect>
{
@ -15,58 +8,12 @@ public class TypeSoundEffect extends TypeCombined<SoundEffect>
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeSoundEffect i = new TypeSoundEffect();
private static final TypeSoundEffect i = new TypeSoundEffect();
public static TypeSoundEffect get() { return i; }
public TypeSoundEffect()
{
super(
TypeSound.get(),
TypeFloat.get(),
TypeFloat.get()
);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public List<Object> split(SoundEffect value)
{
return new MassiveList<Object>(
value.getSound(),
value.getVolume(),
value.getPitch()
);
}
@Override
public SoundEffect combine(List<Object> parts)
{
Sound sound = null;
float volume = 1.0f;
float pitch = 1.0f;
for (int i = 0 ; i < parts.size() ; i++)
{
Object part = parts.get(i);
if (i == 0)
{
sound = (Sound)part;
}
else if (i == 1)
{
volume = (Float) part;
}
else if (i == 2)
{
pitch = (Float) part;
}
}
return SoundEffect.valueOf(sound, volume, pitch);
super(SoundEffect.class);
}
}

View File

@ -25,8 +25,9 @@ public abstract class TypeContainer<C extends Object, E> extends TypeAbstract<C>
// CONSTRUCT
// -------------------------------------------- //
public TypeContainer(Type<E> innerType)
public TypeContainer(Class<?> clazz, Type<E> innerType)
{
super(clazz);
this.setInnerType(innerType);
}

View File

@ -7,9 +7,13 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.ExceptionSet;
import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.command.editor.Property;
import com.massivecraft.massivecore.command.editor.PropertyReflection;
import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.command.type.TypeAbstract;
import com.massivecraft.massivecore.command.type.primitive.TypeBoolean;
import com.massivecraft.massivecore.util.ReflectionUtil;
import com.massivecraft.massivecore.util.Txt;
public class TypeExceptionSet<E> extends TypeAbstract<ExceptionSet<E>>
@ -30,14 +34,55 @@ public class TypeExceptionSet<E> extends TypeAbstract<ExceptionSet<E>>
return new TypeExceptionSet<E>(innerType);
}
public TypeExceptionSet(Type<E> innerType)
@SuppressWarnings("unchecked")
public TypeExceptionSet(final Type<E> innerType)
{
super(ExceptionSet.class);
this.typeElements = TypeSet.get(innerType);
// PROPERTIES
Property<ExceptionSet<E>, Boolean> propertyStandard = PropertyReflection.get(ReflectionUtil.getField(ExceptionSet.class, "standard"), this);
Property<ExceptionSet<E>, Set<E>> propertyExceptions = new Property<ExceptionSet<E>, Set<E>>(this, typeElements, "exceptions")
{
@Override
public Set<E> getRaw(ExceptionSet<E> object)
{
Set<E> ret = new MassiveSet<>();
for (String exception : object.exceptions)
{
try
{
ret.add(innerType.read(exception));
}
catch (MassiveException e)
{
e.printStackTrace();
}
}
return ret;
}
@Override
public ExceptionSet<E> setRaw(ExceptionSet<E> object, Set<E> value)
{
object.exceptions = object.asStrings(value);
return object;
}
};
propertyExceptions.setNullable(false);
this.setInnerProperties(propertyStandard, propertyExceptions);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
// TODO: Do we even need this now?
@Override
public ExceptionSet<E> read(String arg, CommandSender sender) throws MassiveException

View File

@ -18,7 +18,7 @@ public class TypeList<E> extends TypeContainer<List<E>, E>
public TypeList(Type<E> innerType)
{
super(innerType);
super(List.class, innerType);
}
// -------------------------------------------- //

View File

@ -25,7 +25,7 @@ public class TypeMap<K, V> extends TypeContainer<Map<K, V>, Entry<K, V>>
public TypeMap(TypeEntry<K, V> entryType)
{
super(entryType);
super(Map.class, entryType);
}
// -------------------------------------------- //

View File

@ -18,7 +18,7 @@ public class TypeSet<E> extends TypeContainer<Set<E>, E>
public TypeSet(Type<E> innerType)
{
super(innerType);
super(Set.class, innerType);
}
// -------------------------------------------- //

View File

@ -0,0 +1,48 @@
package com.massivecraft.massivecore.command.type.convert;
import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.command.type.TypeTransformer;
import com.massivecraft.massivecore.item.Converter;
public class TypeConverter<A, B> extends TypeTransformer<A, B>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final Converter<A, B> a2b;
public Converter<A, B> getA2b() { return this.a2b; }
private final Converter<B, A> b2a;
public Converter<B, A> getB2a() { return this.b2a; }
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
public TypeConverter(Type<A> typeA, Type<B> typeB, Converter<A, B> a2b, Converter<B, A> b2a)
{
super(typeA, typeB);
this.a2b = a2b;
this.b2a = b2a;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public B innerToOuter(A inner)
{
return this.getA2b().convert(inner);
}
@Override
public A outerToInner(B outer)
{
return this.getB2a().convert(outer);
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.massivecore.command.type.convert;
import org.bukkit.block.banner.PatternType;
import com.massivecraft.massivecore.command.type.enumeration.TypePatternType;
import com.massivecraft.massivecore.command.type.primitive.TypeString;
import com.massivecraft.massivecore.item.ConverterFromBannerPatternType;
import com.massivecraft.massivecore.item.ConverterToBannerPatternType;
public class TypeConverterBannerPatternType extends TypeConverter<PatternType, String>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeConverterBannerPatternType i = new TypeConverterBannerPatternType();
public static TypeConverterBannerPatternType get() { return i; }
public TypeConverterBannerPatternType()
{
super(TypePatternType.get(), TypeString.get(), ConverterFromBannerPatternType.get(), ConverterToBannerPatternType.get());
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.massivecore.command.type.convert;
import org.bukkit.Color;
import com.massivecraft.massivecore.command.type.TypeColor;
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
import com.massivecraft.massivecore.item.ConverterFromColor;
import com.massivecraft.massivecore.item.ConverterToColor;
public class TypeConverterColor extends TypeConverter<Color, Integer>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeConverterColor i = new TypeConverterColor();
public static TypeConverterColor get() { return i; }
public TypeConverterColor()
{
super(TypeColor.get(), TypeInteger.get(), ConverterFromColor.get(), ConverterToColor.get());
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.massivecore.command.type.convert;
import org.bukkit.DyeColor;
import com.massivecraft.massivecore.command.type.enumeration.TypeDyeColor;
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
import com.massivecraft.massivecore.item.ConverterFromDyeColor;
import com.massivecraft.massivecore.item.ConverterToDyeColor;
public class TypeConverterDyeColor extends TypeConverter<DyeColor, Integer>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeConverterDyeColor i = new TypeConverterDyeColor();
public static TypeConverterDyeColor get() { return i; }
public TypeConverterDyeColor()
{
super(TypeDyeColor.get(), TypeInteger.get(), ConverterFromDyeColor.get(), ConverterToDyeColor.get());
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.massivecore.command.type.convert;
import org.bukkit.enchantments.Enchantment;
import com.massivecraft.massivecore.command.type.TypeEnchantment;
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
import com.massivecraft.massivecore.item.ConverterFromEnchant;
import com.massivecraft.massivecore.item.ConverterToEnchant;
public class TypeConverterEnchant extends TypeConverter<Enchantment, Integer>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeConverterEnchant i = new TypeConverterEnchant();
public static TypeConverterEnchant get() { return i; }
public TypeConverterEnchant()
{
super(TypeEnchantment.get(), TypeInteger.get(), ConverterFromEnchant.get(), ConverterToEnchant.get());
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.massivecore.command.type.convert;
import org.bukkit.FireworkEffect.Type;
import com.massivecraft.massivecore.command.type.enumeration.TypeFireworkEffectType;
import com.massivecraft.massivecore.command.type.primitive.TypeString;
import com.massivecraft.massivecore.item.ConverterFromFireworkEffectType;
import com.massivecraft.massivecore.item.ConverterToFireworkEffectType;
public class TypeConverterFireworkEffectType extends TypeConverter<Type, String>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeConverterFireworkEffectType i = new TypeConverterFireworkEffectType();
public static TypeConverterFireworkEffectType get() { return i; }
public TypeConverterFireworkEffectType()
{
super(TypeFireworkEffectType.get(), TypeString.get(), ConverterFromFireworkEffectType.get(), ConverterToFireworkEffectType.get());
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.massivecore.command.type.convert;
import org.bukkit.inventory.ItemFlag;
import com.massivecraft.massivecore.command.type.enumeration.TypeItemFlag;
import com.massivecraft.massivecore.command.type.primitive.TypeString;
import com.massivecraft.massivecore.item.ConverterFromItemFlag;
import com.massivecraft.massivecore.item.ConverterToItemFlag;
public class TypeConverterItemFlag extends TypeConverter<ItemFlag, String>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeConverterItemFlag i = new TypeConverterItemFlag();
public static TypeConverterItemFlag get() { return i; }
public TypeConverterItemFlag()
{
super(TypeItemFlag.get(), TypeString.get(), ConverterFromItemFlag.get(), ConverterToItemFlag.get());
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.massivecore.command.type.convert;
import org.bukkit.potion.PotionEffectType;
import com.massivecraft.massivecore.command.type.TypePotionEffectType;
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
import com.massivecraft.massivecore.item.ConverterFromPotionEffectType;
import com.massivecraft.massivecore.item.ConverterToPotionEffectType;
public class TypeConverterPotionEffectType extends TypeConverter<PotionEffectType, Integer>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeConverterPotionEffectType i = new TypeConverterPotionEffectType();
public static TypeConverterPotionEffectType get() { return i; }
public TypeConverterPotionEffectType()
{
super(TypePotionEffectType.get(), TypeInteger.get(), ConverterFromPotionEffectType.get(), ConverterToPotionEffectType.get());
}
}

View File

@ -18,6 +18,7 @@ public class TypeEnum<T extends Enum<T>> extends TypeAbstractChoice<T>
public TypeEnum(Class<T> clazz)
{
super(clazz);
if ( ! clazz.isEnum()) throw new IllegalArgumentException("clazz must be enum");
this.clazz = clazz;

View File

@ -0,0 +1,18 @@
package com.massivecraft.massivecore.command.type.enumeration;
import org.bukkit.FireworkEffect.Type;
public class TypeFireworkEffectType extends TypeEnum<Type>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeFireworkEffectType i = new TypeFireworkEffectType();
public static TypeFireworkEffectType get() { return i; }
public TypeFireworkEffectType()
{
super(Type.class);
}
}

View File

@ -20,8 +20,9 @@ public abstract class TypeAbstractNumber<T extends Number> extends TypeAbstractS
// OVERRIDE
// -------------------------------------------- //
public TypeAbstractNumber()
public TypeAbstractNumber(Class<T> clazz)
{
super(clazz);
this.setVisualColor(COLOR_NUMBER);
}

View File

@ -54,6 +54,7 @@ public class TypeBoolean extends TypeAbstractChoice<Boolean>
public TypeBoolean(String t, String f)
{
super(Boolean.class);
this.stringTrue = t;
this.stringFalse = f;
this.setAll(

View File

@ -10,6 +10,7 @@ public class TypeByte extends TypeAbstractNumber<Byte>
private static TypeByte i = new TypeByte();
public static TypeByte get() { return i; }
public TypeByte() { super(Byte.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -10,6 +10,7 @@ public class TypeDouble extends TypeAbstractNumber<Double>
private static TypeDouble i = new TypeDouble();
public static TypeDouble get() { return i; }
public TypeDouble() { super(Double.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -10,6 +10,7 @@ public class TypeFloat extends TypeAbstractNumber<Float>
private static TypeFloat i = new TypeFloat();
public static TypeFloat get() { return i; }
public TypeFloat() { super(Float.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -10,6 +10,7 @@ public class TypeInteger extends TypeAbstractNumber<Integer>
private static TypeInteger i = new TypeInteger();
public static TypeInteger get() { return i; }
public TypeInteger() { super(Integer.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -10,6 +10,7 @@ public class TypeLong extends TypeAbstractNumber<Long>
private static TypeLong i = new TypeLong();
public static TypeLong get() { return i; }
public TypeLong() { super(Long.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -17,13 +17,18 @@ public class TypeObject<T> extends TypeAbstract<T>
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeObject<Object> i = new TypeObject<Object>();
/*private static TypeObject<Object> i = new TypeObject<Object>();
@SuppressWarnings("unchecked")
public static <T> TypeObject<T> get() { return (TypeObject<T>) i; }
public static <T> TypeObject<T> get() { return (TypeObject<T>) i; }*/
@SuppressWarnings("unchecked")
public static <T> TypeObject<T> get(Class<T> classOfT) { return (TypeObject<T>) i; }
public static <T> TypeObject<T> get(Class<T> clazz) { return new TypeObject<T>(clazz); }
public TypeObject(Class<T> clazz)
{
super(clazz);
this.setInnerProperties(clazz);
}
// -------------------------------------------- //
// OVERRIDE

View File

@ -10,6 +10,7 @@ public class TypeShort extends TypeAbstractNumber<Short>
private static TypeShort i = new TypeShort();
public static TypeShort get() { return i; }
public TypeShort() { super(Short.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -15,6 +15,7 @@ public class TypeString extends TypeAbstract<String>
private static TypeString i = new TypeString();
public static TypeString get() { return i; }
public TypeString() { super(String.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -17,7 +17,7 @@ public class TypePlayer extends TypeSenderIdAbstract<Player>
public static TypePlayer get() { return i; }
private TypePlayer()
{
super(SenderIdSourceMixinAllSenderIds.get(), SenderPresence.LOCAL, SenderType.PLAYER);
super(Player.class, SenderIdSourceMixinAllSenderIds.get(), SenderPresence.LOCAL, SenderType.PLAYER);
}
// -------------------------------------------- //

View File

@ -17,7 +17,7 @@ public class TypeSender extends TypeSenderIdAbstract<CommandSender>
public static TypeSender get() { return i; }
private TypeSender()
{
super(SenderIdSourceMixinAllSenderIds.get(), SenderPresence.LOCAL, SenderType.ANY);
super(CommandSender.class, SenderIdSourceMixinAllSenderIds.get(), SenderPresence.LOCAL, SenderType.ANY);
}
// -------------------------------------------- //

View File

@ -20,25 +20,25 @@ public class TypeSenderEntity<T extends SenderEntity<T>> extends TypeSenderIdAbs
private TypeSenderEntity(SenderColl<T> coll, SenderPresence presence, SenderType type)
{
super(coll, presence, type);
super(SenderEntity.class, coll, presence, type);
this.coll = coll;
}
private TypeSenderEntity(SenderColl<T> coll, SenderPresence presence)
{
super(coll, presence);
super(SenderEntity.class, coll, presence);
this.coll = coll;
}
private TypeSenderEntity(SenderColl<T> coll, SenderType type)
{
super(coll, type);
super(SenderEntity.class, coll, type);
this.coll = coll;
}
private TypeSenderEntity(SenderColl<T> coll)
{
super(coll);
super(SenderEntity.class, coll);
this.coll = coll;
}

View File

@ -13,22 +13,22 @@ public class TypeSenderId extends TypeSenderIdAbstract<String>
private TypeSenderId(SenderIdSource source, SenderPresence presence, SenderType type)
{
super(source, presence, type);
super(String.class, source, presence, type);
}
private TypeSenderId(SenderIdSource source, SenderPresence presence)
{
super(source, presence);
super(String.class, source, presence);
}
private TypeSenderId(SenderIdSource source, SenderType type)
{
super(source, type);
super(String.class, source, type);
}
private TypeSenderId(SenderIdSource source)
{
super(source);
super(String.class, source);
}
// -------------------------------------------- //

View File

@ -31,8 +31,9 @@ public abstract class TypeSenderIdAbstract<T> extends TypeAbstract<T>
// CONSTRUCT
// -------------------------------------------- //
public TypeSenderIdAbstract(SenderIdSource source, SenderPresence presence, SenderType type)
public TypeSenderIdAbstract(Class<?> clazz, SenderIdSource source, SenderPresence presence, SenderType type)
{
super(clazz);
if (source == null) throw new NullPointerException("source");
if (presence == null) throw new NullPointerException("presence");
if (type == null) throw new NullPointerException("type");
@ -42,19 +43,19 @@ public abstract class TypeSenderIdAbstract<T> extends TypeAbstract<T>
this.type = type;
}
public TypeSenderIdAbstract(SenderIdSource source, SenderPresence presence)
public TypeSenderIdAbstract(Class<?> clazz, SenderIdSource source, SenderPresence presence)
{
this(source, presence, SenderType.ANY);
this(clazz, source, presence, SenderType.ANY);
}
public TypeSenderIdAbstract(SenderIdSource source, SenderType type)
public TypeSenderIdAbstract(Class<?> clazz, SenderIdSource source, SenderType type)
{
this(source, SenderPresence.ANY, type);
this(clazz, source, SenderPresence.ANY, type);
}
public TypeSenderIdAbstract(SenderIdSource source)
public TypeSenderIdAbstract(Class<?> clazz, SenderIdSource source)
{
this(source, SenderPresence.ANY);
this(clazz, source, SenderPresence.ANY);
}
// -------------------------------------------- //

View File

@ -14,22 +14,22 @@ public class TypeSenderName extends TypeSenderIdAbstract<String>
private TypeSenderName(SenderIdSource source, SenderPresence presence, SenderType type)
{
super(source, presence, type);
super(String.class, source, presence, type);
}
private TypeSenderName(SenderIdSource source, SenderPresence presence)
{
super(source, presence);
super(String.class, source, presence);
}
private TypeSenderName(SenderIdSource source, SenderType type)
{
super(source, type);
super(String.class, source, type);
}
private TypeSenderName(SenderIdSource source)
{
super(source);
super(String.class, source);
}
// -------------------------------------------- //

View File

@ -13,6 +13,7 @@ public class TypeColl extends TypeAbstractChoice<Coll<?>>
private static TypeColl i = new TypeColl();
public static TypeColl get() { return i; }
public TypeColl() { super(Coll.class); }
// -------------------------------------------- //
// OVERRIDE

View File

@ -19,6 +19,7 @@ public class TypeEntity<T extends Entity<T>> extends TypeAbstractChoice<T>
public TypeEntity(Coll<T> coll)
{
super(coll.getEntityClass());
this.coll = coll;
}
@ -53,4 +54,10 @@ public class TypeEntity<T extends Entity<T>> extends TypeAbstractChoice<T>
return this.getColl().getAll();
}
@Override
public T createNewInstance()
{
return this.getColl().createNewInstance();
}
}

View File

@ -6,9 +6,15 @@ import static com.massivecraft.massivecore.item.DataItemStack.set;
import java.util.Objects;
import org.bukkit.block.banner.Pattern;
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
import com.massivecraft.massivecore.command.type.convert.TypeConverterBannerPatternType;
import com.massivecraft.massivecore.command.type.convert.TypeConverterDyeColor;
import com.massivecraft.massivecore.comparator.ComparatorSmart;
import com.massivecraft.massivecore.util.MUtil;
@EditorMethods(true)
public class DataBannerPattern implements Comparable<DataBannerPattern>
{
// -------------------------------------------- //
@ -22,10 +28,12 @@ public class DataBannerPattern implements Comparable<DataBannerPattern>
// FIELDS
// -------------------------------------------- //
@EditorType(TypeConverterBannerPatternType.class)
private String id = null;
public String getId() { return get(this.id, DEFAULT_ID); }
public DataBannerPattern setId(String id) { this.id = set(id, DEFAULT_ID); return this; }
@EditorType(TypeConverterDyeColor.class)
private Integer color = null;
public Integer getColor() { return get(this.color, DEFAULT_COLOR); }
public DataBannerPattern setColor(Integer color) { this.color = set(color, DEFAULT_ID); return this; }

View File

@ -1,20 +1,25 @@
package com.massivecraft.massivecore.item;
import static com.massivecraft.massivecore.item.DataItemStack.get;
import static com.massivecraft.massivecore.item.DataItemStack.set;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.bukkit.FireworkEffect;
import static com.massivecraft.massivecore.item.DataItemStack.get;
import static com.massivecraft.massivecore.item.DataItemStack.set;
import com.massivecraft.massivecore.collections.MassiveListDef;
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeList;
import com.massivecraft.massivecore.command.type.convert.TypeConverterColor;
import com.massivecraft.massivecore.command.type.convert.TypeConverterFireworkEffectType;
import com.massivecraft.massivecore.comparator.ComparatorSmart;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.xlib.gson.annotations.SerializedName;
@EditorMethods(true)
public class DataFireworkEffect implements Comparable<DataFireworkEffect>
{
// -------------------------------------------- //
@ -41,15 +46,18 @@ public class DataFireworkEffect implements Comparable<DataFireworkEffect>
public boolean hasTrail() { return get(this.trail, DEFAULT_TRAIL); }
public DataFireworkEffect setTrail(boolean trail) { this.trail = set(trail, DEFAULT_TRAIL); return this; }
@EditorTypeList(TypeConverterColor.class)
private MassiveListDef<Integer> colors = null;
public List<Integer> getColors() { return get(this.colors, DEFAULT_COLORS); }
public DataFireworkEffect setColors(List<Integer> colors) { this.colors = set(colors, DEFAULT_COLORS); return this; }
@EditorTypeList(TypeConverterColor.class)
@SerializedName("fade-colors")
private MassiveListDef<Integer> fadeColors = null;
public List<Integer> getFadeColors() { return get(this.fadeColors, DEFAULT_FADE_COLORS); }
public DataFireworkEffect setFadeColors(List<Integer> fadeColors) { this.fadeColors = set(fadeColors, DEFAULT_FADE_COLORS); return this; }
@EditorType(TypeConverterFireworkEffectType.class)
private String type = null;
public String getType() { return get(this.type, DEFAULT_TYPE); }
public DataFireworkEffect setType(String type) { this.type = set(type, DEFAULT_TYPE); return this; }

View File

@ -16,6 +16,18 @@ import com.massivecraft.massivecore.collections.MassiveListDef;
import com.massivecraft.massivecore.collections.MassiveMap;
import com.massivecraft.massivecore.collections.MassiveTreeMapDef;
import com.massivecraft.massivecore.collections.MassiveTreeSetDef;
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeList;
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeMap;
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeSet;
import com.massivecraft.massivecore.command.type.TypeMaterialId;
import com.massivecraft.massivecore.command.type.convert.TypeConverterColor;
import com.massivecraft.massivecore.command.type.convert.TypeConverterDyeColor;
import com.massivecraft.massivecore.command.type.convert.TypeConverterEnchant;
import com.massivecraft.massivecore.command.type.convert.TypeConverterItemFlag;
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
import com.massivecraft.massivecore.command.type.primitive.TypeStringParsed;
import com.massivecraft.massivecore.comparator.ComparatorSmart;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.xlib.gson.annotations.SerializedName;
@ -32,6 +44,7 @@ import com.massivecraft.massivecore.xlib.gson.annotations.SerializedName;
* It is mainly used by the ItemStackAdapter and InventoryAdapter.
* It can also be used directly, for example in maps, since it provides a stable equals and hash code method (as opposed to Bukkit).
*/
@EditorMethods(true)
public class DataItemStack implements Comparable<DataItemStack>
{
// -------------------------------------------- //
@ -72,6 +85,7 @@ public class DataItemStack implements Comparable<DataItemStack>
// FIELDS > BASIC
// -------------------------------------------- //
@EditorType(value = TypeMaterialId.class)
private Integer id = null;
public int getId() { return get(this.id, DEFAULT_ID); }
public DataItemStack setId(int id) { this.id = set(id, DEFAULT_ID); return this; }
@ -88,10 +102,12 @@ public class DataItemStack implements Comparable<DataItemStack>
// FIELDS > UNSPECIFIC
// -------------------------------------------- //
@EditorType(TypeStringParsed.class)
private String name = null;
public String getName() { return get(this.name, DEFAULT_NAME); }
public DataItemStack setName(String name) { this.name = set(name, DEFAULT_NAME); return this; }
@EditorTypeList(TypeStringParsed.class)
private MassiveListDef<String> lore = null;
public List<String> getLore() { return get(this.lore, DEFAULT_LORE); }
public DataItemStack setLore(List<String> lore) { this.lore = set(lore, DEFAULT_LORE); return this; }
@ -99,6 +115,7 @@ public class DataItemStack implements Comparable<DataItemStack>
// The Bukkit ItemMeta#getEnchants() is not sorted by the enchant id.
// There may be some sort of custom sorting order, I'm not sure.
// We are however enforcing sorting by the enchant id ourselves to be sure.
@EditorTypeMap(typeKey = TypeConverterEnchant.class, typeValue = TypeInteger.class)
private MassiveTreeMapDef<Integer, Integer, ComparatorSmart> enchants = null;
public Map<Integer, Integer> getEnchants() { return get(this.enchants, DEFAULT_ENCHANTS); }
public DataItemStack setEnchants(Map<Integer, Integer> enchants) { this.enchants = set(enchants, DEFAULT_ENCHANTS); return this; }
@ -111,6 +128,7 @@ public class DataItemStack implements Comparable<DataItemStack>
// FIELDS > BOOK
// -------------------------------------------- //
@EditorType(TypeStringParsed.class)
private String title = null;
public String getTitle() { return get(this.title, DEFAULT_TITLE); }
public DataItemStack setTitle(String title) { this.title = set(title, DEFAULT_TITLE); return this; }
@ -119,6 +137,7 @@ public class DataItemStack implements Comparable<DataItemStack>
public String getAuthor() { return get(this.author, DEFAULT_AUTHOR); }
public DataItemStack setAuthor(String author) { this.author = set(author, DEFAULT_AUTHOR); return this; }
@EditorTypeList(TypeStringParsed.class)
private MassiveListDef<String> pages = null;
public List<String> getPages() { return get(this.pages, DEFAULT_PAGES); }
public DataItemStack setPages(Collection<String> pages) { this.pages = set(pages, DEFAULT_PAGES); return this; }
@ -127,6 +146,7 @@ public class DataItemStack implements Comparable<DataItemStack>
// FIELDS > LEATHER ARMOR
// -------------------------------------------- //
@EditorType(TypeConverterColor.class)
private Integer color = null;
public Integer getColor() { return get(this.color, DEFAULT_COLOR); }
public DataItemStack setColor(int color) { this.color = set(color, DEFAULT_COLOR); return this; }
@ -186,6 +206,7 @@ public class DataItemStack implements Comparable<DataItemStack>
// FIELDS > STORED ENCHANTS
// -------------------------------------------- //
@EditorTypeMap(typeKey = TypeConverterEnchant.class, typeValue = TypeInteger.class)
@SerializedName("stored-enchants")
private MassiveTreeMapDef<Integer, Integer, ComparatorSmart> storedEnchants = null;
public Map<Integer, Integer> getStoredEnchants() { return get(this.storedEnchants, DEFAULT_STORED_ENCHANTS); }
@ -205,6 +226,7 @@ public class DataItemStack implements Comparable<DataItemStack>
// -------------------------------------------- //
// SINCE: 1.8
@EditorTypeSet(TypeConverterItemFlag.class)
private MassiveTreeSetDef<String, ComparatorSmart> flags = null;
public Set<String> getFlags() { return get(this.flags, DEFAULT_FLAGS); }
public DataItemStack setFlags(Set<String> flags) { this.flags = set(flags, DEFAULT_FLAGS); return this; }
@ -216,6 +238,7 @@ public class DataItemStack implements Comparable<DataItemStack>
// The integer is the dye color byte representation.
// Is actually nullable in Bukkit.
@EditorType(TypeConverterDyeColor.class)
@SerializedName("banner-base")
private Integer bannerBase = null;
public Integer getBannerBase() { return get(this.bannerBase, DEFAULT_BANNER_BASE); }

View File

@ -7,9 +7,14 @@ import java.util.Objects;
import org.bukkit.potion.PotionEffect;
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
import com.massivecraft.massivecore.command.type.convert.TypeConverterColor;
import com.massivecraft.massivecore.command.type.convert.TypeConverterPotionEffectType;
import com.massivecraft.massivecore.comparator.ComparatorSmart;
import com.massivecraft.massivecore.util.MUtil;
@EditorMethods(true)
public class DataPotionEffect implements Comparable<DataPotionEffect>
{
// -------------------------------------------- //
@ -27,6 +32,7 @@ public class DataPotionEffect implements Comparable<DataPotionEffect>
// FIELDS
// -------------------------------------------- //
@EditorType(value = TypeConverterPotionEffectType.class)
private Integer id = null;
public Integer getId() { return get(this.id, DEFAULT_ID); }
public DataPotionEffect setId(Integer id) { this.id = set(id, DEFAULT_ID); return this; }
@ -49,6 +55,7 @@ public class DataPotionEffect implements Comparable<DataPotionEffect>
public DataPotionEffect setParticles(boolean particles) { this.particles = set(particles, DEFAULT_PARTICLES); return this; }
// SINCE: 1.9
@EditorType(TypeConverterColor.class)
private Integer color = null;
public Integer getColor() { return get(this.color, DEFAULT_COLOR); }
public DataPotionEffect setColor(Integer color) { this.color = set(color, DEFAULT_COLOR); return this; }

View File

@ -2,8 +2,6 @@ package com.massivecraft.massivecore.item;
import org.bukkit.inventory.ItemStack;
public abstract class WriterAbstractItemStackField<FA, FB> extends WriterAbstractItemStack<ItemStack, ItemStack, FA, FB>
{
// -------------------------------------------- //

View File

@ -1228,6 +1228,18 @@ public class Mson implements Serializable
return raw;
}
public static List<String> toPlain(Iterable<Mson> iterable, boolean styled)
{
List<String> ret = new MassiveList<>();
for (Mson mson : iterable)
{
ret.add(mson.toPlain(styled));
}
return ret;
}
public String toPlain(boolean styled)
{
final StringBuilder ret = new StringBuilder();

View File

@ -4,6 +4,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Some files were not shown because too many files have changed in this diff Show More