Compatibility 1.7, fallbacks etc.

This commit is contained in:
Olof Larsson 2016-05-18 09:27:26 +02:00
parent 5daebc8e33
commit b78417b48b
No known key found for this signature in database
GPG Key ID: BBEF14F97DA52474
14 changed files with 192 additions and 106 deletions

View File

@ -22,7 +22,6 @@ public abstract class Engine implements Active, Listener, Runnable
private static final transient Set<Engine> allInstances = new MassiveSet<>();
public static Set<Engine> getAllInstances() { return allInstances; }
// -------------------------------------------- //
// PLUGIN
// -------------------------------------------- //
@ -116,9 +115,14 @@ public abstract class Engine implements Active, Listener, Runnable
public void setActiveListener(boolean active)
{
if (active)
{
// Support without at load
MassivePlugin plugin = this.getPlugin();
if (plugin.isEnabled())
{
Bukkit.getPluginManager().registerEvents(this, this.getPlugin());
}
}
else
{
HandlerList.unregisterAll(this);
@ -134,6 +138,10 @@ public abstract class Engine implements Active, Listener, Runnable
if (active)
{
if (this.getPeriod() != null)
{
// Support without at load
MassivePlugin plugin = this.getPlugin();
if (plugin.isEnabled())
{
if (this.isSync())
{
@ -145,6 +153,7 @@ public abstract class Engine implements Active, Listener, Runnable
}
}
}
}
else
{
if (this.task != null)

View File

@ -217,17 +217,20 @@ public class MassiveCore extends MassivePlugin
}
// -------------------------------------------- //
// OVERRIDE
// LOAD
// -------------------------------------------- //
@Override
public void onLoad()
public void onLoadInner()
{
super.onLoad();
// Attempting to fix a race condition within the class asynchronous class loader.
System.out.println("TimeUnit.MILLIS_PER_MINUTE: " + TimeUnit.MILLIS_PER_MINUTE);
}
// -------------------------------------------- //
// ENABLE
// -------------------------------------------- //
@Override
public void onEnableInner()
{
@ -328,6 +331,10 @@ public class MassiveCore extends MassivePlugin
Bukkit.getScheduler().scheduleSyncDelayedTask(this, MassiveCoreTaskDeleteFiles.get());
}
// -------------------------------------------- //
// DISABLE
// -------------------------------------------- //
@Override
public void onDisable()
{

View File

@ -36,19 +36,52 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
public boolean isVersionSynchronized() { return this.versionSynchronized; }
public void setVersionSynchronized(boolean versionSynchronized) { this.versionSynchronized = versionSynchronized; }
// -------------------------------------------- //
// LOAD
// -------------------------------------------- //
@Override
public void onLoad()
{
this.onLoadPre();
this.onLoadInner();
this.onLoadPost();
}
public void onLoadPre()
{
this.logPrefixColored = Txt.parse("<teal>[<aqua>%s %s<teal>] <i>", this.getDescription().getName(), this.getDescription().getVersion());
this.logPrefixPlain = ChatColor.stripColor(this.logPrefixColored);
}
public void onLoadInner()
{
}
public void onLoadPost()
{
}
// -------------------------------------------- //
// ENABLE
// -------------------------------------------- //
@Override
public void onEnable()
{
if ( ! this.onEnablePre()) return;
this.onEnableInner();
this.onEnablePost();
}
private long enableTime;
public long getEnableTime() { return this.enableTime; }
public boolean preEnable()
public boolean onEnablePre()
{
enableTime = System.currentTimeMillis();
this.logPrefixColored = Txt.parse("<teal>[<aqua>%s %s<teal>] <i>", this.getDescription().getName(), this.getDescription().getVersion());
this.logPrefixPlain = ChatColor.stripColor(this.logPrefixColored);
this.enableTime = System.currentTimeMillis();
log("=== ENABLE START ===");
@ -65,27 +98,6 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
return true;
}
public void postEnable()
{
// Metrics
if (MassiveCoreMConf.get().mcstatsEnabled)
{
try
{
MetricsLite metrics = new MetricsLite(this);
metrics.start();
}
catch (IOException e)
{
String message = Txt.parse("<b>Metrics Initialization Failed :'(");
log(message);
}
}
long ms = System.currentTimeMillis() - enableTime;
log(Txt.parse("=== ENABLE <g>COMPLETE <i>(Took <h>" + ms + "ms<i>) ==="));
}
public void checkVersionSynchronization()
{
// If this plugin is version synchronized ...
@ -121,21 +133,32 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
}
}
@Override
public void onEnable()
{
if ( ! this.preEnable()) return;
this.onEnableInner();
this.postEnable();
}
public void onEnableInner()
{
}
public void onEnablePost()
{
// Metrics
if (MassiveCoreMConf.get().mcstatsEnabled)
{
try
{
MetricsLite metrics = new MetricsLite(this);
metrics.start();
}
catch (IOException e)
{
String message = Txt.parse("<b>Metrics Initialization Failed :'(");
log(message);
}
}
long ms = System.currentTimeMillis() - this.enableTime;
log(Txt.parse("=== ENABLE <g>COMPLETE <i>(Took <h>" + ms + "ms<i>) ==="));
}
// -------------------------------------------- //
// DISABLE
// -------------------------------------------- //

View File

@ -87,6 +87,8 @@ public class RegistryType
}
public static Type<?> getType(Field field)
{
try
{
EditorType annotation = field.getAnnotation(EditorType.class);
if (annotation != null)
@ -113,6 +115,15 @@ public class RegistryType
{
return TypeMap.get(getType(annMap.typeKey(), annMap.fieldNameKey()), getType(annMap.typeValue(), annMap.fieldNameValue()));
}
}
catch (Throwable t)
{
// This has to do with backwards compatibility (Usually 1.7).
// 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)
@ -225,30 +236,10 @@ public class RegistryType
register(TypeDestination.get());
register(TypeItemStack.get());
// 1.7 Compat
try
{
register(TypeDataBannerPattern.get());
}
catch (Throwable t)
{
}
register(TypeDataPotionEffect.get());
register(TypeDataFireworkEffect.get());
// 1.? Compat
// TODO: The annotations breaks with 1.7.
// TODO: Find a solution to dodge the converter annotation class inits.
try
{
register(TypeDataItemStack.get());
}
catch (Throwable t)
{
}
register(TypePermission.get());
register(TypePotionEffectType.get());

View File

@ -47,25 +47,31 @@ public class DataBannerPattern implements Comparable<DataBannerPattern>
}
public DataBannerPattern(Pattern pattern)
// Minecraft 1.7 Compatibility
public DataBannerPattern(Object pattern)
{
this.write(pattern, false);
if ( ! (pattern instanceof Pattern)) throw new IllegalArgumentException("pattern");
this.write((Pattern)pattern, false);
}
// -------------------------------------------- //
// WRITE
// -------------------------------------------- //
public void write(Pattern pattern, boolean a2b)
// Minecraft 1.7 Compatibility
public void write(Object pattern, boolean a2b)
{
WriterBannerPattern.get().write(this, pattern, a2b);
if ( ! (pattern instanceof Pattern)) throw new IllegalArgumentException("pattern");
WriterBannerPattern.get().write(this, (Pattern)pattern, a2b);
}
// -------------------------------------------- //
// TO BUKKIT
// -------------------------------------------- //
public Pattern toBukkit()
// Minecraft 1.7 Compatibility
@SuppressWarnings("unchecked")
public <T> T toBukkit()
{
// Create
Pattern ret = WriterBannerPattern.get().createOB();
@ -74,7 +80,7 @@ public class DataBannerPattern implements Comparable<DataBannerPattern>
this.write(ret, true);
// Return
return ret;
return (T) ret;
}
// -------------------------------------------- //

View File

@ -65,7 +65,7 @@ public class Mixin extends Engine
// NOTE: This field must be set in the default constructor!
private Boolean availableDefault = null;
public boolean isAvailableDefault() { return (this.availableDefault != null ? this.availableDefault : this.getDefault().getAlternatives().isEmpty()); }
public void setAvailableDefault(boolean availableDefault) { this.setAvailableDefault(availableDefault); }
public void setAvailableDefault(boolean availableDefault) { this.availableDefault = availableDefault; }
public boolean isAvailable() { return this.isAvailableDefault() || this.getInstance() != this.getDefault(); }
public void require() { if (this.isAvailable()) return; throw new IllegalStateException(this.getBaseName() + " is Required"); }

View File

@ -127,10 +127,8 @@ public final class MsonEvent implements Serializable
public static MsonEvent item(ItemStack item)
{
if (item == null) throw new NullPointerException("item");
String nbtStringTooltip = null;
NmsItemStackTooltip nms = NmsItemStackTooltip.get();
if (nms.isAvailable()) nbtStringTooltip = nms.getNbtStringTooltip(item);
return MsonEvent.valueOf(MsonEventAction.SHOW_ITEM, nbtStringTooltip);
String value = NmsItemStackTooltip.get().getNbtStringTooltip(item);
return MsonEvent.valueOf(MsonEventAction.SHOW_ITEM, value);
}
// -------------------------------------------- //

View File

@ -84,4 +84,13 @@ public class NmsBasics extends Mixin
throw this.notImplemented();
}
// -------------------------------------------- //
// PING
// -------------------------------------------- //
public int getPing(Player player)
{
throw this.notImplemented();
}
}

View File

@ -72,6 +72,10 @@ public class NmsBasics17R4P extends NmsBasics
// net.minecraft.server.PlayerConnection#sendPacket(Packet)
private Method methodPlayerConnectionsendPacket;
// PING
// net.minecraft.server.EntityPlayer#ping
private Field fieldNmsPlayerPing;
// -------------------------------------------- //
// SETUP
// -------------------------------------------- //
@ -107,6 +111,9 @@ public class NmsBasics17R4P extends NmsBasics
this.classNmsPacket = PackageType.MINECRAFT_SERVER.getClass("Packet");
this.classNmsPlayerConnection = PackageType.MINECRAFT_SERVER.getClass("PlayerConnection");
this.methodPlayerConnectionsendPacket = ReflectionUtil.getMethod(this.classNmsPlayerConnection, "sendPacket", this.classNmsPacket);
// PING
this.fieldNmsPlayerPing = ReflectionUtil.getField(this.classNmsPlayer, "ping");
}
// -------------------------------------------- //
@ -170,4 +177,14 @@ public class NmsBasics17R4P extends NmsBasics
ReflectionUtil.invokeMethod(this.methodPlayerConnectionsendPacket, connection, packet);
}
// -------------------------------------------- //
// PING
// -------------------------------------------- //
public int getPing(Player player)
{
Object handle = this.getHandle(player);
return ReflectionUtil.getField(this.fieldNmsPlayerPing, handle);
}
}

View File

@ -16,7 +16,8 @@ public class NmsChat extends Mixin
private static NmsChat d = new NmsChat().setAlternatives(
NmsChat18R2P.class,
NmsChat18R1.class
NmsChat18R1.class,
NmsChatFallback.class
);
// -------------------------------------------- //

View File

@ -0,0 +1,12 @@
package com.massivecraft.massivecore.nms;
public class NmsChatFallback extends NmsChat
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static NmsChatFallback i = new NmsChatFallback();
public static NmsChatFallback get() { return i; }
}

View File

@ -11,7 +11,8 @@ public class NmsItemStackTooltip extends Mixin
// -------------------------------------------- //
private static NmsItemStackTooltip d = new NmsItemStackTooltip().setAlternatives(
NmsItemStackTooltip18R1P.class
NmsItemStackTooltip18R1P.class,
NmsItemStackTooltipFallback.class
);
// -------------------------------------------- //
@ -27,7 +28,7 @@ public class NmsItemStackTooltip extends Mixin
public String getNbtStringTooltip(ItemStack item)
{
throw notImplemented();
return null;
}
}

View File

@ -0,0 +1,12 @@
package com.massivecraft.massivecore.nms;
public class NmsItemStackTooltipFallback extends NmsItemStackTooltip
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static NmsItemStackTooltipFallback i = new NmsItemStackTooltipFallback();
public static NmsItemStackTooltipFallback get () { return i; }
}