Fix maven so it compiles

This commit is contained in:
Myles 2016-09-25 20:05:58 +01:00
parent 471076cbe1
commit 669cbcd142
11 changed files with 64 additions and 42 deletions

View File

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>viaversion</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>1.0.0-ALPHA-16w38a</version> <version>1.0.0-ALPHA-16w38a</version>
</parent> </parent>

View File

@ -37,8 +37,8 @@ public abstract class ViaListener implements Listener {
* @return The UserConnection * @return The UserConnection
*/ */
protected UserConnection getUserConnection(@NonNull UUID uuid) { protected UserConnection getUserConnection(@NonNull UUID uuid) {
if (!plugin.isPorted(uuid)) return null; if (!Via.getAPI().isPorted(uuid)) return null;
return plugin.getConnection(uuid); return Via.getManager().getConnection(uuid);
} }
/** /**

View File

@ -13,7 +13,7 @@ public class ViaVersion {
public static void setInstance(ViaVersionPlugin plugin) { public static void setInstance(ViaVersionPlugin plugin) {
Validate.isTrue(instance == null, "Instance is already set"); Validate.isTrue(instance == null, "Instance is already set");
ViaVersion.instance = plugin; ViaVersion.instance = (ViaVersionAPI) plugin.getApi();
ViaVersion.config = plugin.getConf(); ViaVersion.config = plugin.getConf();
} }
} }

View File

@ -6,6 +6,7 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.platform.ViaInjector; import us.myles.ViaVersion.api.platform.ViaInjector;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.handlers.ViaVersionInitializer; import us.myles.ViaVersion.handlers.ViaVersionInitializer;
@ -23,12 +24,11 @@ public class BukkitViaInjector implements ViaInjector {
private List<Pair<Field, Object>> injectedLists = new ArrayList<>(); private List<Pair<Field, Object>> injectedLists = new ArrayList<>();
@Override @Override
public void inject() { public void inject() throws Exception {
try { try {
Object connection = getServerConnection(); Object connection = getServerConnection();
if (connection == null) { if (connection == null) {
getLogger().warning("We failed to find the core component 'ServerConnection', please file an issue on our GitHub."); throw new Exception("We failed to find the core component 'ServerConnection', please file an issue on our GitHub.");
return;
} }
for (Field field : connection.getClass().getDeclaredFields()) { for (Field field : connection.getClass().getDeclaredFields()) {
field.setAccessible(true); field.setAccessible(true);
@ -40,7 +40,11 @@ public class BukkitViaInjector implements ViaInjector {
public synchronized void handleAdd(Object o) { public synchronized void handleAdd(Object o) {
synchronized (this) { synchronized (this) {
if (o instanceof ChannelFuture) { if (o instanceof ChannelFuture) {
injectChannelFuture((ChannelFuture) o); try {
injectChannelFuture((ChannelFuture) o);
} catch (Exception e) {
e.printStackTrace();
}
} }
} }
} }
@ -61,12 +65,12 @@ public class BukkitViaInjector implements ViaInjector {
} }
} catch (Exception e) { } catch (Exception e) {
getLogger().severe("Unable to inject ViaVersion, please post these details on our GitHub and ensure you're using a compatible server version."); Via.getPlatform().getLogger().severe("Unable to inject ViaVersion, please post these details on our GitHub and ensure you're using a compatible server version.");
e.printStackTrace(); throw e;
} }
} }
private void injectChannelFuture(ChannelFuture future) { private void injectChannelFuture(ChannelFuture future) throws Exception {
try { try {
ChannelHandler bootstrapAcceptor = future.channel().pipeline().first(); ChannelHandler bootstrapAcceptor = future.channel().pipeline().first();
try { try {
@ -87,8 +91,8 @@ public class BukkitViaInjector implements ViaInjector {
} }
} catch (Exception e) { } catch (Exception e) {
getLogger().severe("We failed to inject ViaVersion, have you got late-bind enabled with something else?"); Via.getPlatform().getLogger().severe("We failed to inject ViaVersion, have you got late-bind enabled with something else?");
e.printStackTrace(); throw e;
} }
} }
@ -123,7 +127,7 @@ public class BukkitViaInjector implements ViaInjector {
} }
@Override @Override
public int getServerProtocolVersion() { public int getServerProtocolVersion() throws Exception {
try { try {
Class<?> serverClazz = ReflectionUtil.nms("MinecraftServer"); Class<?> serverClazz = ReflectionUtil.nms("MinecraftServer");
Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer"); Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer");
@ -164,9 +168,9 @@ public class BukkitViaInjector implements ViaInjector {
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); throw new Exception("Failed to get server", e);
// We couldn't work it out... We'll just use ping and hope for the best...
} }
throw new Exception("Failed to get server");
} }
public static Object getServerConnection() throws Exception { public static Object getServerConnection() throws Exception {
@ -188,7 +192,7 @@ public class BukkitViaInjector implements ViaInjector {
public static void patchLists() throws Exception { public static void patchLists() throws Exception {
Object connection = getServerConnection(); Object connection = getServerConnection();
if (connection == null) { if (connection == null) {
getLogger().warning("We failed to find the core component 'ServerConnection', please file an issue on our GitHub."); Via.getPlatform().getLogger().warning("We failed to find the core component 'ServerConnection', please file an issue on our GitHub.");
return; return;
} }
for (Field field : connection.getClass().getDeclaredFields()) { for (Field field : connection.getClass().getDeclaredFields()) {

View File

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>viaversion</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>1.0.0-ALPHA-16w38a</version> <version>1.0.0-ALPHA-16w38a</version>
</parent> </parent>

View File

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>viaversion</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>1.0.0-ALPHA-16w38a</version> <version>1.0.0-ALPHA-16w38a</version>
</parent> </parent>
@ -11,5 +11,4 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>viaversion-common</artifactId> <artifactId>viaversion-common</artifactId>
</project> </project>

View File

@ -44,8 +44,13 @@ public class ViaManager {
if (platform.getConf().isCheckForUpdates()) if (platform.getConf().isCheckForUpdates())
UpdateUtil.sendUpdateMessage(); UpdateUtil.sendUpdateMessage();
// Inject // Inject
// TODO: Get errors try {
injector.inject(); injector.inject();
} catch (Exception e) {
getPlatform().getLogger().severe("ViaVersion failed to inject:");
e.printStackTrace();
return;
}
// Mark as injected // Mark as injected
System.setProperty("ViaVersion", getPlatform().getPluginVersion()); System.setProperty("ViaVersion", getPlatform().getPluginVersion());
// If successful // If successful
@ -58,9 +63,15 @@ public class ViaManager {
}); });
} }
public void onServerLoaded() { public void onServerLoaded() {
// Load Server Protocol // Load Server Protocol
ProtocolRegistry.SERVER_PROTOCOL = injector.getServerProtocolVersion(); try {
ProtocolRegistry.SERVER_PROTOCOL = injector.getServerProtocolVersion();
} catch (Exception e) {
getPlatform().getLogger().severe("ViaVersion failed to get the server protocol!");
e.printStackTrace();
}
// Check if there are any pipes to this version // Check if there are any pipes to this version
if (ProtocolRegistry.SERVER_PROTOCOL != -1) { if (ProtocolRegistry.SERVER_PROTOCOL != -1) {
getPlatform().getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(ProtocolRegistry.SERVER_PROTOCOL)); getPlatform().getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(ProtocolRegistry.SERVER_PROTOCOL));
@ -81,7 +92,12 @@ public class ViaManager {
public void destroy() { public void destroy() {
// Uninject // Uninject
getPlatform().getLogger().info("ViaVersion is disabling, if this is a reload and you experience issues consider rebooting."); getPlatform().getLogger().info("ViaVersion is disabling, if this is a reload and you experience issues consider rebooting.");
injector.uninject(); try {
injector.uninject();
} catch (Exception e) {
getPlatform().getLogger().severe("ViaVersion failed to uninject:");
e.printStackTrace();
}
} }
public void addPortedClient(UserConnection info) { public void addPortedClient(UserConnection info) {

View File

@ -1,9 +1,9 @@
package us.myles.ViaVersion.api.platform; package us.myles.ViaVersion.api.platform;
public interface ViaInjector { public interface ViaInjector {
public void inject(); public void inject() throws Exception;
public void uninject(); public void uninject() throws Exception;
public int getServerProtocolVersion(); public int getServerProtocolVersion() throws Exception;
} }

View File

@ -63,7 +63,7 @@ public class ProtocolRegistry {
if (Via.getPlatform().isPluginEnabled()) { if (Via.getPlatform().isPluginEnabled()) {
protocol.registerListeners(); protocol.registerListeners();
protocol.registerProviders(Via.getManager().getProviders()); protocol.register(Via.getManager().getProviders());
refreshVersions(); refreshVersions();
} else { } else {
registerList.add(protocol); registerList.add(protocol);
@ -110,7 +110,7 @@ public class ProtocolRegistry {
public static void onServerLoaded() { public static void onServerLoaded() {
for (Protocol protocol : registerList) { for (Protocol protocol : registerList) {
protocol.registerListeners(); protocol.registerListeners();
protocol.registerProviders(Via.getManager().getProviders()); protocol.register(Via.getManager().getProviders());
} }
registerList.clear(); registerList.clear();
} }

View File

@ -35,17 +35,6 @@
</resources> </resources>
<plugins> <plugins>
<!-- Maven Java Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${jdkVersion}</source>
<target>${jdkVersion}</target>
</configuration>
</plugin>
<!-- Libs Shading and Relocation --> <!-- Libs Shading and Relocation -->
<plugin> <plugin>
<!--Relocate all lib we use in order to fix class loading errors if we use different versions <!--Relocate all lib we use in order to fix class loading errors if we use different versions

18
pom.xml
View File

@ -30,7 +30,8 @@
<projectEncoding>UTF-8</projectEncoding> <projectEncoding>UTF-8</projectEncoding>
<project.build.sourceEncoding>${projectEncoding}</project.build.sourceEncoding> <project.build.sourceEncoding>${projectEncoding}</project.build.sourceEncoding>
<project.build.outputEncoding>${projectEncoding}</project.build.outputEncoding> <project.build.outputEncoding>${projectEncoding}</project.build.outputEncoding>
<jdkVersion>1.7</jdkVersion> <maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties> </properties>
<repositories> <repositories>
@ -61,7 +62,6 @@
<version>1.16.6</version> <version>1.16.6</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Javassist (Bytecode Library) --> <!-- Javassist (Bytecode Library) -->
<dependency> <dependency>
<groupId>org.javassist</groupId> <groupId>org.javassist</groupId>
@ -114,4 +114,18 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<!-- Maven Java Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>