MassiveCore - Editor Improvements. Only single singletons. Shared annotation for inner types.
This commit is contained in:
parent
2d8f10eb00
commit
bec8286fb6
@ -214,12 +214,10 @@
|
|||||||
"HIDE_UNBREAKABLE"
|
"HIDE_UNBREAKABLE"
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
banner-base: byte (dye color) // It seems this one never is used
|
banner-base: byte (dye color)
|
||||||
banner:
|
banner:
|
||||||
[
|
[
|
||||||
str (pattern id), byte (dye color),
|
*banner-pattern*
|
||||||
str (pattern id), byte (dye color),
|
|
||||||
str (pattern id), byte (dye color),
|
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.BlockMultiPlaceEvent;
|
import org.bukkit.event.block.BlockMultiPlaceEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.permissions.Permissible;
|
|||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorName;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorName;
|
||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
||||||
import com.massivecraft.massivecore.command.type.TypeMillisDiff;
|
import com.massivecraft.massivecore.command.type.TypeMillisDiff;
|
||||||
|
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanOn;
|
||||||
import com.massivecraft.massivecore.store.Entity;
|
import com.massivecraft.massivecore.store.Entity;
|
||||||
import com.massivecraft.massivecore.util.MUtil;
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
import com.massivecraft.massivecore.util.PermissionUtil;
|
import com.massivecraft.massivecore.util.PermissionUtil;
|
||||||
@ -122,7 +123,7 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
|
|||||||
@EditorType(TypeMillisDiff.class)
|
@EditorType(TypeMillisDiff.class)
|
||||||
public volatile long millisBetweenRemotePollWithPusher = TimeUnit.MILLIS_PER_MINUTE * 1;
|
public volatile long millisBetweenRemotePollWithPusher = TimeUnit.MILLIS_PER_MINUTE * 1;
|
||||||
|
|
||||||
@EditorType(fieldName = "iOn")
|
@EditorType(TypeBooleanOn.class)
|
||||||
public boolean warnOnLocalAlter = false;
|
public boolean warnOnLocalAlter = false;
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -11,8 +11,8 @@ import org.bukkit.entity.Player;
|
|||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorName;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorName;
|
||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorNullable;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorNullable;
|
||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
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.command.type.enumeration.TypeSound;
|
||||||
|
import com.massivecraft.massivecore.command.type.enumeration.TypeSoundId;
|
||||||
import com.massivecraft.massivecore.util.MUtil;
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
|
|
||||||
public final class SoundEffect implements Serializable
|
public final class SoundEffect implements Serializable
|
||||||
@ -25,7 +25,7 @@ public final class SoundEffect implements Serializable
|
|||||||
|
|
||||||
@EditorNullable(false)
|
@EditorNullable(false)
|
||||||
@EditorName("sound")
|
@EditorName("sound")
|
||||||
@EditorType(value = TypeId.class, fieldName = "iSound")
|
@EditorType(TypeSoundId.class)
|
||||||
private final String soundId;
|
private final String soundId;
|
||||||
public String getSoundId() { return this.soundId; }
|
public String getSoundId() { return this.soundId; }
|
||||||
public Sound getSound()
|
public Sound getSound()
|
||||||
|
@ -3,7 +3,7 @@ package com.massivecraft.massivecore.command;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.MassiveException;
|
import com.massivecraft.massivecore.MassiveException;
|
||||||
import com.massivecraft.massivecore.command.type.primitive.TypeBoolean;
|
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanOn;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
|
|
||||||
public abstract class MassiveCommandToggle extends MassiveCommand
|
public abstract class MassiveCommandToggle extends MassiveCommand
|
||||||
@ -29,7 +29,7 @@ public abstract class MassiveCommandToggle extends MassiveCommand
|
|||||||
public MassiveCommandToggle()
|
public MassiveCommandToggle()
|
||||||
{
|
{
|
||||||
// Parameters
|
// Parameters
|
||||||
this.addParameter(TypeBoolean.getOn(), "on|off", "toggle");
|
this.addParameter(TypeBooleanOn.get(), "on|off", "toggle");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -60,7 +60,7 @@ public abstract class MassiveCommandToggle extends MassiveCommand
|
|||||||
// Args
|
// Args
|
||||||
boolean before = this.getValue();
|
boolean before = this.getValue();
|
||||||
boolean after = this.readArg( ! before);
|
boolean after = this.readArg( ! before);
|
||||||
String afterDesc = TypeBoolean.getOn().getVisual(after, sender);
|
String afterDesc = TypeBooleanOn.get().getVisual(after, sender);
|
||||||
|
|
||||||
// NoChange
|
// NoChange
|
||||||
if (after == before)
|
if (after == before)
|
||||||
|
@ -9,9 +9,5 @@ import java.lang.annotation.Target;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface EditorType
|
public @interface EditorType
|
||||||
{
|
{
|
||||||
// This is the type class.
|
Class<?> value();
|
||||||
Class<?> value() default void.class;
|
|
||||||
|
|
||||||
// The name of the singleton instance field to use.
|
|
||||||
String fieldName() default "i";
|
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,7 @@ import java.lang.annotation.Target;
|
|||||||
|
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface EditorTypeSet
|
public @interface EditorTypeInner
|
||||||
{
|
{
|
||||||
// This is the type class.
|
Class<?>[] value();
|
||||||
Class<?> value();
|
|
||||||
|
|
||||||
// The name of the singleton instance field to use.
|
|
||||||
String fieldName() default "i";
|
|
||||||
}
|
}
|
@ -1,17 +0,0 @@
|
|||||||
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";
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
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";
|
|
||||||
}
|
|
@ -14,7 +14,7 @@ import com.massivecraft.massivecore.command.Visibility;
|
|||||||
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
||||||
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
|
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
|
||||||
import com.massivecraft.massivecore.command.type.TypeItemStack;
|
import com.massivecraft.massivecore.command.type.TypeItemStack;
|
||||||
import com.massivecraft.massivecore.command.type.primitive.TypeBoolean;
|
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes;
|
||||||
import com.massivecraft.massivecore.mson.Mson;
|
import com.massivecraft.massivecore.mson.Mson;
|
||||||
import com.massivecraft.massivecore.util.InventoryUtil;
|
import com.massivecraft.massivecore.util.InventoryUtil;
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ public class CmdMassiveCoreTest extends MassiveCommand
|
|||||||
this.addAliases("test");
|
this.addAliases("test");
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
this.addParameter(false, TypeBoolean.getYes(), "set", "no");
|
this.addParameter(false, TypeBooleanYes.get(), "set", "no");
|
||||||
|
|
||||||
// Requirements
|
// Requirements
|
||||||
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.TEST));
|
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.TEST));
|
||||||
|
@ -8,12 +8,11 @@ import java.util.Map.Entry;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.collections.ExceptionSet;
|
import com.massivecraft.massivecore.collections.ExceptionSet;
|
||||||
|
import com.massivecraft.massivecore.collections.MassiveList;
|
||||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||||
import com.massivecraft.massivecore.collections.WorldExceptionSet;
|
import com.massivecraft.massivecore.collections.WorldExceptionSet;
|
||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeList;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner;
|
||||||
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.TypeDataBannerPattern;
|
||||||
import com.massivecraft.massivecore.command.type.combined.TypeDataPotionEffect;
|
import com.massivecraft.massivecore.command.type.combined.TypeDataPotionEffect;
|
||||||
import com.massivecraft.massivecore.command.type.combined.TypeEntry;
|
import com.massivecraft.massivecore.command.type.combined.TypeEntry;
|
||||||
@ -44,7 +43,7 @@ import com.massivecraft.massivecore.command.type.enumeration.TypeSkeletonType;
|
|||||||
import com.massivecraft.massivecore.command.type.enumeration.TypeSound;
|
import com.massivecraft.massivecore.command.type.enumeration.TypeSound;
|
||||||
import com.massivecraft.massivecore.command.type.enumeration.TypeVillagerProfession;
|
import com.massivecraft.massivecore.command.type.enumeration.TypeVillagerProfession;
|
||||||
import com.massivecraft.massivecore.command.type.enumeration.TypeWorldType;
|
import com.massivecraft.massivecore.command.type.enumeration.TypeWorldType;
|
||||||
import com.massivecraft.massivecore.command.type.primitive.TypeBoolean;
|
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanTrue;
|
||||||
import com.massivecraft.massivecore.command.type.primitive.TypeByte;
|
import com.massivecraft.massivecore.command.type.primitive.TypeByte;
|
||||||
import com.massivecraft.massivecore.command.type.primitive.TypeDouble;
|
import com.massivecraft.massivecore.command.type.primitive.TypeDouble;
|
||||||
import com.massivecraft.massivecore.command.type.primitive.TypeFloat;
|
import com.massivecraft.massivecore.command.type.primitive.TypeFloat;
|
||||||
@ -64,111 +63,171 @@ public class RegistryType
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private static final Map<Class<?>, Type<?>> registry = new MassiveMap<>();
|
private static final Map<Class<?>, Type<?>> registry = new MassiveMap<>();
|
||||||
|
|
||||||
public static <T> void register(Class<T> clazz, Type<? super T> type)
|
public static <T> void register(Class<T> clazz, Type<? super T> type)
|
||||||
{
|
{
|
||||||
if (clazz == null) throw new NullPointerException("clazz");
|
if (clazz == null) throw new NullPointerException("clazz");
|
||||||
if (type == null) throw new NullPointerException("type");
|
if (type == null) throw new NullPointerException("type");
|
||||||
registry.put(clazz, type);
|
registry.put(clazz, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void register(Type<T> type)
|
public static <T> void register(Type<T> type)
|
||||||
{
|
{
|
||||||
if (type == null) throw new NullPointerException("type");
|
if (type == null) throw new NullPointerException("type");
|
||||||
register(type.getClazz(), type);
|
register(type.getClazz(), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> Type<? super T> unregister(Class<T> clazz)
|
public static <T> Type<? super T> unregister(Class<T> clazz)
|
||||||
{
|
{
|
||||||
if (clazz == null) throw new NullPointerException("clazz");
|
if (clazz == null) throw new NullPointerException("clazz");
|
||||||
return (Type<T>) registry.remove(clazz);
|
return (Type<T>) registry.remove(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRegistered(Class<?> clazz)
|
public static boolean isRegistered(Class<?> clazz)
|
||||||
{
|
{
|
||||||
if (clazz == null) throw new NullPointerException("clazz");
|
if (clazz == null) throw new NullPointerException("clazz");
|
||||||
return registry.containsKey(clazz);
|
return registry.containsKey(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// GET TYPE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static Type<?> getType(Field field, java.lang.reflect.Type fieldType, boolean strictThrow)
|
||||||
|
{
|
||||||
|
if (field != null)
|
||||||
|
{
|
||||||
|
EditorType annotationType = ReflectionUtil.getAnnotation(field, EditorType.class);
|
||||||
|
if (annotationType != null)
|
||||||
|
{
|
||||||
|
Class<?> typeClass = annotationType.value();
|
||||||
|
Type<?> type = ReflectionUtil.getSingletonInstance(typeClass);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldType == null)
|
||||||
|
{
|
||||||
|
fieldType = field.getGenericType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldType != null)
|
||||||
|
{
|
||||||
|
if (fieldType instanceof ParameterizedType)
|
||||||
|
{
|
||||||
|
Class<?> fieldClass = field.getType();
|
||||||
|
List<Type<?>> innerTypes;
|
||||||
|
|
||||||
|
if (List.class.isAssignableFrom(fieldClass))
|
||||||
|
{
|
||||||
|
innerTypes = getInnerTypes(field, fieldType, 1);
|
||||||
|
return TypeList.get(innerTypes.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Set.class.isAssignableFrom(fieldClass))
|
||||||
|
{
|
||||||
|
innerTypes = getInnerTypes(field, fieldType, 1);
|
||||||
|
return TypeSet.get(innerTypes.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Entry.class.isAssignableFrom(fieldClass))
|
||||||
|
{
|
||||||
|
innerTypes = getInnerTypes(field, fieldType, 2);
|
||||||
|
return TypeEntry.get(innerTypes.get(0), innerTypes.get(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Map.class.isAssignableFrom(fieldClass))
|
||||||
|
{
|
||||||
|
innerTypes = getInnerTypes(field, fieldType, 2);
|
||||||
|
return TypeMap.get(innerTypes.get(0), innerTypes.get(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strictThrow) throw new IllegalArgumentException("Unhandled ParameterizedType: " + fieldType);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldType instanceof Class)
|
||||||
|
{
|
||||||
|
Type<?> type = registry.get(fieldType);
|
||||||
|
if (strictThrow && type == null) throw new IllegalStateException(fieldType + " is not registered.");
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Neither ParameterizedType nor Class: " + fieldType);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("No Information Supplied");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type<?> getType(Field field, boolean strictThrow)
|
||||||
|
{
|
||||||
|
return getType(field, null, strictThrow);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type<?> getType(java.lang.reflect.Type fieldType, boolean strictThrow)
|
||||||
|
{
|
||||||
|
return getType(null, fieldType, strictThrow);
|
||||||
|
}
|
||||||
|
|
||||||
public static Type<?> getType(Field field)
|
public static Type<?> getType(Field field)
|
||||||
{
|
{
|
||||||
try
|
return getType(field, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type<?> getType(java.lang.reflect.Type fieldType)
|
||||||
|
{
|
||||||
|
return getType(fieldType, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// GET INNER TYPES
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static List<Type<?>> getInnerTypes(Field field, java.lang.reflect.Type fieldType, int amountRequired)
|
||||||
|
{
|
||||||
|
// Create
|
||||||
|
List<Type<?>> ret = new MassiveList<>();
|
||||||
|
|
||||||
|
// Fill > Annotation
|
||||||
|
if (field != null)
|
||||||
{
|
{
|
||||||
EditorType annotation = field.getAnnotation(EditorType.class);
|
EditorTypeInner annotation = ReflectionUtil.getAnnotation(field, EditorTypeInner.class);
|
||||||
if (annotation != null)
|
if (annotation != null)
|
||||||
{
|
{
|
||||||
Class<?> clazz = annotation.value();
|
Class<?>[] innerTypeClasses = annotation.value();
|
||||||
if (clazz == void.class) clazz = getType(field.getGenericType()).getClass();
|
for (Class<?> innerTypeClass : innerTypeClasses)
|
||||||
return getType(clazz, annotation.fieldName());
|
{
|
||||||
|
Type<?> innerType = ReflectionUtil.getSingletonInstance(innerTypeClass);
|
||||||
|
ret.add(innerType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorTypeList annList = field.getAnnotation(EditorTypeList.class);
|
if (fieldType == null)
|
||||||
if (annList != null)
|
|
||||||
{
|
{
|
||||||
return TypeList.get(getType(annList.value(), annList.fieldName()));
|
fieldType = field.getGenericType();
|
||||||
}
|
|
||||||
|
|
||||||
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()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable t)
|
|
||||||
|
// Fill > Reflection
|
||||||
|
if (fieldType != null)
|
||||||
{
|
{
|
||||||
// This has to do with backwards compatibility (Usually 1.7).
|
if (fieldType instanceof ParameterizedType)
|
||||||
// The EditorType annotations may trigger creation of type class instances.
|
|
||||||
// Those type classes may refer to Bukkit classes not present.
|
|
||||||
// This issue was first encountered for TypeDataItemStack.
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
if (reflectType instanceof Class)
|
|
||||||
{
|
|
||||||
Type<?> type = registry.get(reflectType);
|
|
||||||
if (type == null) throw new IllegalStateException(reflectType + " is not registered.");
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reflectType instanceof ParameterizedType)
|
|
||||||
{
|
|
||||||
ParameterizedType paramType = (ParameterizedType) reflectType;
|
|
||||||
Class<?> parent = (Class<?>) paramType.getRawType();
|
|
||||||
|
|
||||||
if (Map.class.isAssignableFrom(parent))
|
|
||||||
{
|
{
|
||||||
TypeEntry<?, ?> typeEntry = TypeEntry.get(getType(paramType.getActualTypeArguments()[0]), getType(paramType.getActualTypeArguments()[1]));
|
ParameterizedType parameterizedType = (ParameterizedType)fieldType;
|
||||||
return TypeMap.get(typeEntry);
|
int count = 0;
|
||||||
}
|
for (java.lang.reflect.Type actualTypeArgument : parameterizedType.getActualTypeArguments())
|
||||||
|
{
|
||||||
if (List.class.isAssignableFrom(parent))
|
boolean strictThrow = (amountRequired < 0 || count < amountRequired);
|
||||||
{
|
Type<?> innerType = getType(actualTypeArgument, strictThrow);
|
||||||
return TypeList.get(getType(paramType.getActualTypeArguments()[0]));
|
ret.add(innerType);
|
||||||
}
|
count++;
|
||||||
|
}
|
||||||
if (Set.class.isAssignableFrom(parent))
|
|
||||||
{
|
|
||||||
return TypeSet.get(getType(paramType.getActualTypeArguments()[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Entry.class.isAssignableFrom(parent))
|
|
||||||
{
|
|
||||||
return TypeEntry.get(getType(paramType.getActualTypeArguments()[0]), getType(paramType.getActualTypeArguments()[1]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException("Unknown type: " + reflectType);
|
// Return
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -181,8 +240,8 @@ public class RegistryType
|
|||||||
public static void registerAll()
|
public static void registerAll()
|
||||||
{
|
{
|
||||||
// Primitive
|
// Primitive
|
||||||
register(Boolean.TYPE, TypeBoolean.getTrue());
|
register(Boolean.TYPE, TypeBooleanTrue.get());
|
||||||
register(Boolean.class, TypeBoolean.getTrue());
|
register(Boolean.class, TypeBooleanTrue.get());
|
||||||
|
|
||||||
register(Byte.TYPE, TypeByte.get());
|
register(Byte.TYPE, TypeByte.get());
|
||||||
register(Byte.class, TypeByte.get());
|
register(Byte.class, TypeByte.get());
|
||||||
@ -222,6 +281,14 @@ public class RegistryType
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
register(TypeRabbitType.get());
|
register(TypeRabbitType.get());
|
||||||
|
}
|
||||||
|
catch (Throwable t)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
register(TypeDamageModifier.get());
|
register(TypeDamageModifier.get());
|
||||||
}
|
}
|
||||||
catch (Throwable t)
|
catch (Throwable t)
|
||||||
|
@ -1,24 +1,30 @@
|
|||||||
package com.massivecraft.massivecore.command.type.convert;
|
package com.massivecraft.massivecore.command.type.convert;
|
||||||
|
|
||||||
import org.bukkit.block.banner.PatternType;
|
import com.massivecraft.massivecore.command.type.Type;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.command.type.enumeration.TypePatternType;
|
import com.massivecraft.massivecore.command.type.enumeration.TypePatternType;
|
||||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||||
|
import com.massivecraft.massivecore.item.Converter;
|
||||||
import com.massivecraft.massivecore.item.ConverterFromBannerPatternType;
|
import com.massivecraft.massivecore.item.ConverterFromBannerPatternType;
|
||||||
import com.massivecraft.massivecore.item.ConverterToBannerPatternType;
|
import com.massivecraft.massivecore.item.ConverterToBannerPatternType;
|
||||||
|
|
||||||
public class TypeConverterBannerPatternType extends TypeConverter<PatternType, String>
|
// Minecraft 1.7 Compatibility
|
||||||
|
public class TypeConverterBannerPatternType<A> extends TypeConverter<A, String>
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private static TypeConverterBannerPatternType i = new TypeConverterBannerPatternType();
|
private static TypeConverterBannerPatternType<?> i = null;
|
||||||
public static TypeConverterBannerPatternType get() { return i; }
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> TypeConverterBannerPatternType<T> get()
|
||||||
public TypeConverterBannerPatternType()
|
|
||||||
{
|
{
|
||||||
super(TypePatternType.get(), TypeString.get(), ConverterFromBannerPatternType.get(), ConverterToBannerPatternType.get());
|
if (i == null) i = new TypeConverterBannerPatternType<>(TypePatternType.get(), ConverterFromBannerPatternType.get(), ConverterToBannerPatternType.get());
|
||||||
|
return (TypeConverterBannerPatternType<T>) i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypeConverterBannerPatternType(Type<A> typeA, Converter<A, String> a2b, Converter<String, A> b2a)
|
||||||
|
{
|
||||||
|
super(typeA, TypeString.get(), a2b, b2a);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.massivecraft.massivecore.command.type.enumeration;
|
||||||
|
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
|
||||||
|
import com.massivecraft.massivecore.command.type.TypeId;
|
||||||
|
|
||||||
|
public class TypeSoundId extends TypeId<Sound>
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static TypeSoundId i = new TypeSoundId();
|
||||||
|
public static TypeSoundId get() { return i; }
|
||||||
|
public TypeSoundId()
|
||||||
|
{
|
||||||
|
super(TypeSound.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,36 +8,32 @@ import org.bukkit.command.CommandSender;
|
|||||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||||
import com.massivecraft.massivecore.command.type.TypeAbstractChoice;
|
import com.massivecraft.massivecore.command.type.TypeAbstractChoice;
|
||||||
|
|
||||||
public class TypeBoolean extends TypeAbstractChoice<Boolean>
|
public abstract class TypeBooleanAbstract extends TypeAbstractChoice<Boolean>
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static final String NAME_YES = "Yes";
|
||||||
|
public static final String NAME_TRUE = "True";
|
||||||
|
public static final String NAME_ON = "On";
|
||||||
|
|
||||||
|
public static final String NAME_NO = "No";
|
||||||
|
public static final String NAME_FALSE = "False";
|
||||||
|
public static final String NAME_OFF = "Off";
|
||||||
|
|
||||||
public static final Set<String> NAMES_TRUE = new MassiveSet<String>(
|
public static final Set<String> NAMES_TRUE = new MassiveSet<String>(
|
||||||
"Yes",
|
NAME_YES,
|
||||||
"True",
|
NAME_TRUE,
|
||||||
"On"
|
NAME_ON
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final Set<String> NAMES_FALSE = new MassiveSet<String>(
|
public static final Set<String> NAMES_FALSE = new MassiveSet<String>(
|
||||||
"No",
|
NAME_NO,
|
||||||
"False",
|
NAME_FALSE,
|
||||||
"Off"
|
NAME_OFF
|
||||||
);
|
);
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// INSTANCE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private static TypeBoolean iYes = new TypeBoolean("Yes", "No");
|
|
||||||
private static TypeBoolean iTrue = new TypeBoolean("True", "False");
|
|
||||||
private static TypeBoolean iOn = new TypeBoolean("On", "Off");
|
|
||||||
|
|
||||||
public static TypeBoolean getYes() { return iYes; }
|
|
||||||
public static TypeBoolean getTrue() { return iTrue; }
|
|
||||||
public static TypeBoolean getOn() { return iOn; }
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// FIELDS
|
// FIELDS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -52,7 +48,7 @@ public class TypeBoolean extends TypeAbstractChoice<Boolean>
|
|||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public TypeBoolean(String t, String f)
|
public TypeBooleanAbstract(String t, String f)
|
||||||
{
|
{
|
||||||
super(Boolean.class);
|
super(Boolean.class);
|
||||||
this.stringTrue = t;
|
this.stringTrue = t;
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.massivecraft.massivecore.command.type.primitive;
|
||||||
|
|
||||||
|
public class TypeBooleanOn extends TypeBooleanAbstract
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static TypeBooleanOn i = new TypeBooleanOn();
|
||||||
|
public static TypeBooleanOn get() { return i; }
|
||||||
|
public TypeBooleanOn()
|
||||||
|
{
|
||||||
|
super(NAME_ON, NAME_OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.massivecraft.massivecore.command.type.primitive;
|
||||||
|
|
||||||
|
public class TypeBooleanTrue extends TypeBooleanAbstract
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static TypeBooleanTrue i = new TypeBooleanTrue();
|
||||||
|
public static TypeBooleanTrue get() { return i; }
|
||||||
|
public TypeBooleanTrue()
|
||||||
|
{
|
||||||
|
super(NAME_TRUE, NAME_FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.massivecraft.massivecore.command.type.primitive;
|
||||||
|
|
||||||
|
public class TypeBooleanYes extends TypeBooleanAbstract
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static TypeBooleanYes i = new TypeBooleanYes();
|
||||||
|
public static TypeBooleanYes get() { return i; }
|
||||||
|
public TypeBooleanYes()
|
||||||
|
{
|
||||||
|
super(NAME_YES, NAME_NO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,7 +12,7 @@ import org.bukkit.FireworkEffect;
|
|||||||
import com.massivecraft.massivecore.collections.MassiveListDef;
|
import com.massivecraft.massivecore.collections.MassiveListDef;
|
||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
|
||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeList;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner;
|
||||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterColor;
|
import com.massivecraft.massivecore.command.type.convert.TypeConverterColor;
|
||||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterFireworkEffectType;
|
import com.massivecraft.massivecore.command.type.convert.TypeConverterFireworkEffectType;
|
||||||
import com.massivecraft.massivecore.comparator.ComparatorSmart;
|
import com.massivecraft.massivecore.comparator.ComparatorSmart;
|
||||||
@ -46,12 +46,12 @@ public class DataFireworkEffect implements Comparable<DataFireworkEffect>
|
|||||||
public boolean hasTrail() { return get(this.trail, DEFAULT_TRAIL); }
|
public boolean hasTrail() { return get(this.trail, DEFAULT_TRAIL); }
|
||||||
public DataFireworkEffect setTrail(boolean trail) { this.trail = set(trail, DEFAULT_TRAIL); return this; }
|
public DataFireworkEffect setTrail(boolean trail) { this.trail = set(trail, DEFAULT_TRAIL); return this; }
|
||||||
|
|
||||||
@EditorTypeList(TypeConverterColor.class)
|
@EditorTypeInner(TypeConverterColor.class)
|
||||||
private MassiveListDef<Integer> colors = null;
|
private MassiveListDef<Integer> colors = null;
|
||||||
public List<Integer> getColors() { return get(this.colors, DEFAULT_COLORS); }
|
public List<Integer> getColors() { return get(this.colors, DEFAULT_COLORS); }
|
||||||
public DataFireworkEffect setColors(List<Integer> colors) { this.colors = set(colors, DEFAULT_COLORS); return this; }
|
public DataFireworkEffect setColors(List<Integer> colors) { this.colors = set(colors, DEFAULT_COLORS); return this; }
|
||||||
|
|
||||||
@EditorTypeList(TypeConverterColor.class)
|
@EditorTypeInner(TypeConverterColor.class)
|
||||||
@SerializedName("fade-colors")
|
@SerializedName("fade-colors")
|
||||||
private MassiveListDef<Integer> fadeColors = null;
|
private MassiveListDef<Integer> fadeColors = null;
|
||||||
public List<Integer> getFadeColors() { return get(this.fadeColors, DEFAULT_FADE_COLORS); }
|
public List<Integer> getFadeColors() { return get(this.fadeColors, DEFAULT_FADE_COLORS); }
|
||||||
|
@ -18,9 +18,7 @@ import com.massivecraft.massivecore.collections.MassiveTreeMapDef;
|
|||||||
import com.massivecraft.massivecore.collections.MassiveTreeSetDef;
|
import com.massivecraft.massivecore.collections.MassiveTreeSetDef;
|
||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorMethods;
|
||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorType;
|
||||||
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeList;
|
import com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner;
|
||||||
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.TypeMaterialId;
|
||||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterColor;
|
import com.massivecraft.massivecore.command.type.convert.TypeConverterColor;
|
||||||
import com.massivecraft.massivecore.command.type.convert.TypeConverterDyeColor;
|
import com.massivecraft.massivecore.command.type.convert.TypeConverterDyeColor;
|
||||||
@ -107,7 +105,7 @@ public class DataItemStack implements Comparable<DataItemStack>
|
|||||||
public String getName() { return get(this.name, DEFAULT_NAME); }
|
public String getName() { return get(this.name, DEFAULT_NAME); }
|
||||||
public DataItemStack setName(String name) { this.name = set(name, DEFAULT_NAME); return this; }
|
public DataItemStack setName(String name) { this.name = set(name, DEFAULT_NAME); return this; }
|
||||||
|
|
||||||
@EditorTypeList(TypeStringParsed.class)
|
@EditorTypeInner(TypeStringParsed.class)
|
||||||
private MassiveListDef<String> lore = null;
|
private MassiveListDef<String> lore = null;
|
||||||
public List<String> getLore() { return get(this.lore, DEFAULT_LORE); }
|
public List<String> getLore() { return get(this.lore, DEFAULT_LORE); }
|
||||||
public DataItemStack setLore(List<String> lore) { this.lore = set(lore, DEFAULT_LORE); return this; }
|
public DataItemStack setLore(List<String> lore) { this.lore = set(lore, DEFAULT_LORE); return this; }
|
||||||
@ -115,7 +113,7 @@ public class DataItemStack implements Comparable<DataItemStack>
|
|||||||
// The Bukkit ItemMeta#getEnchants() is not sorted by the enchant id.
|
// The Bukkit ItemMeta#getEnchants() is not sorted by the enchant id.
|
||||||
// There may be some sort of custom sorting order, I'm not sure.
|
// 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.
|
// We are however enforcing sorting by the enchant id ourselves to be sure.
|
||||||
@EditorTypeMap(typeKey = TypeConverterEnchant.class, typeValue = TypeInteger.class)
|
@EditorTypeInner({TypeConverterEnchant.class, TypeInteger.class})
|
||||||
private MassiveTreeMapDef<Integer, Integer, ComparatorSmart> enchants = null;
|
private MassiveTreeMapDef<Integer, Integer, ComparatorSmart> enchants = null;
|
||||||
public Map<Integer, Integer> getEnchants() { return get(this.enchants, DEFAULT_ENCHANTS); }
|
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; }
|
public DataItemStack setEnchants(Map<Integer, Integer> enchants) { this.enchants = set(enchants, DEFAULT_ENCHANTS); return this; }
|
||||||
@ -137,7 +135,7 @@ public class DataItemStack implements Comparable<DataItemStack>
|
|||||||
public String getAuthor() { return get(this.author, DEFAULT_AUTHOR); }
|
public String getAuthor() { return get(this.author, DEFAULT_AUTHOR); }
|
||||||
public DataItemStack setAuthor(String author) { this.author = set(author, DEFAULT_AUTHOR); return this; }
|
public DataItemStack setAuthor(String author) { this.author = set(author, DEFAULT_AUTHOR); return this; }
|
||||||
|
|
||||||
@EditorTypeList(TypeStringParsed.class)
|
@EditorTypeInner(TypeStringParsed.class)
|
||||||
private MassiveListDef<String> pages = null;
|
private MassiveListDef<String> pages = null;
|
||||||
public List<String> getPages() { return get(this.pages, DEFAULT_PAGES); }
|
public List<String> getPages() { return get(this.pages, DEFAULT_PAGES); }
|
||||||
public DataItemStack setPages(Collection<String> pages) { this.pages = set(pages, DEFAULT_PAGES); return this; }
|
public DataItemStack setPages(Collection<String> pages) { this.pages = set(pages, DEFAULT_PAGES); return this; }
|
||||||
@ -206,7 +204,7 @@ public class DataItemStack implements Comparable<DataItemStack>
|
|||||||
// FIELDS > STORED ENCHANTS
|
// FIELDS > STORED ENCHANTS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@EditorTypeMap(typeKey = TypeConverterEnchant.class, typeValue = TypeInteger.class)
|
@EditorTypeInner({TypeConverterEnchant.class, TypeInteger.class})
|
||||||
@SerializedName("stored-enchants")
|
@SerializedName("stored-enchants")
|
||||||
private MassiveTreeMapDef<Integer, Integer, ComparatorSmart> storedEnchants = null;
|
private MassiveTreeMapDef<Integer, Integer, ComparatorSmart> storedEnchants = null;
|
||||||
public Map<Integer, Integer> getStoredEnchants() { return get(this.storedEnchants, DEFAULT_STORED_ENCHANTS); }
|
public Map<Integer, Integer> getStoredEnchants() { return get(this.storedEnchants, DEFAULT_STORED_ENCHANTS); }
|
||||||
@ -226,7 +224,7 @@ public class DataItemStack implements Comparable<DataItemStack>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// SINCE: 1.8
|
// SINCE: 1.8
|
||||||
|
|
||||||
@EditorTypeSet(TypeConverterItemFlag.class)
|
@EditorTypeInner(TypeConverterItemFlag.class)
|
||||||
private MassiveTreeSetDef<String, ComparatorSmart> flags = null;
|
private MassiveTreeSetDef<String, ComparatorSmart> flags = null;
|
||||||
public Set<String> getFlags() { return get(this.flags, DEFAULT_FLAGS); }
|
public Set<String> getFlags() { return get(this.flags, DEFAULT_FLAGS); }
|
||||||
public DataItemStack setFlags(Set<String> flags) { this.flags = set(flags, DEFAULT_FLAGS); return this; }
|
public DataItemStack setFlags(Set<String> flags) { this.flags = set(flags, DEFAULT_FLAGS); return this; }
|
||||||
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||||||
import com.massivecraft.massivecore.Engine;
|
import com.massivecraft.massivecore.Engine;
|
||||||
import com.massivecraft.massivecore.MassiveCoreMConf;
|
import com.massivecraft.massivecore.MassiveCoreMConf;
|
||||||
import com.massivecraft.massivecore.collections.MassiveList;
|
import com.massivecraft.massivecore.collections.MassiveList;
|
||||||
import com.massivecraft.massivecore.command.type.primitive.TypeBoolean;
|
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanOn;
|
||||||
import com.massivecraft.massivecore.util.MUtil;
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
import com.massivecraft.massivecore.util.ReflectionUtil;
|
import com.massivecraft.massivecore.util.ReflectionUtil;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
@ -114,7 +114,7 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB, D> extends Engine
|
|||||||
String message;
|
String message;
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
message = Txt.parse("<h>%s %s", name, TypeBoolean.getOn().getVisual(success));
|
message = Txt.parse("<h>%s %s", name, TypeBooleanOn.get().getVisual(success));
|
||||||
messages.add(message);
|
messages.add(message);
|
||||||
|
|
||||||
// Throwable
|
// Throwable
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.massivecraft.massivecore.util;
|
package com.massivecraft.massivecore.util;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -240,6 +241,27 @@ public class ReflectionUtil
|
|||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// ANNOTATION
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static <T extends Annotation> T getAnnotation(Field field, Class<T> annotationClass)
|
||||||
|
{
|
||||||
|
// Fail Fast
|
||||||
|
if (field == null) throw new NullPointerException("field");
|
||||||
|
if (annotationClass == null) throw new NullPointerException("annotationClass");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return field.getAnnotation(annotationClass);
|
||||||
|
}
|
||||||
|
catch (Throwable t)
|
||||||
|
{
|
||||||
|
t.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// FIELD > GET
|
// FIELD > GET
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
Loading…
Reference in New Issue
Block a user