diff --git a/all/pom.xml b/all/pom.xml index 7db043b3..0cee5e97 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -81,5 +81,11 @@ viabackwards-sponge ${project.parent.version} + + + nl.matsv + viabackwards-velocity + ${project.parent.version} + \ No newline at end of file diff --git a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java index baf9d722..c68094ca 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java @@ -12,15 +12,15 @@ package nl.matsv.viabackwards.api; import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; +import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1; import nl.matsv.viabackwards.protocol.protocol1_12_1to1_12_2.Protocol1_12_1To1_12_2; -import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_12to1_12_1.Protocol1_12To1_12_1; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolVersion; +import us.myles.ViaVersion.update.Version; -import java.lang.reflect.Field; import java.util.Collections; import java.util.logging.Logger; @@ -48,21 +48,22 @@ public interface ViaBackwardsPlatform { */ Logger getLogger(); - // TODO remove or better implement later default boolean isOutdated() { + String minimumVVVersion = "2.0.0"; boolean upToDate = false; try { - Class clazz = Class.forName("us.myles.ViaVersion.api.protocol.ProtocolVersion"); - Field v1_12_2 = clazz.getField("v1_12_2"); + Class vvVersionInfo = Class.forName("us.myles.ViaVersion.sponge.VersionInfo"); + String vvVersion = (String) vvVersionInfo.getField("VERSION").get(null); - upToDate = (v1_12_2 != null); - } catch (ClassNotFoundException | NoSuchFieldException ignored) { + upToDate = (vvVersion != null + && new Version(vvVersion).compareTo(new Version(minimumVVVersion + "--")) >= 0); + } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) { } if (!upToDate) { getLogger().severe("================================"); getLogger().severe("YOUR VIAVERSION IS OUTDATED"); - getLogger().severe("PLEASE USE THE LATEST VERSION"); + getLogger().severe("PLEASE USE VIAVERSION " + minimumVVVersion + " OR NEWER"); getLogger().severe("LINK: https://viaversion.com"); getLogger().severe("VIABACKWARDS WILL NOW DISABLE"); getLogger().severe("================================"); diff --git a/pom.xml b/pom.xml index 9a000266..e1d7713f 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ bukkit bungee sponge + velocity all diff --git a/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java b/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java index 39fb6b9b..090ea4df 100644 --- a/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java +++ b/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java @@ -11,14 +11,14 @@ package nl.matsv.viabackwards; import com.google.inject.Inject; +import lombok.Getter; import nl.matsv.viabackwards.api.ViaBackwardsPlatform; import nl.matsv.viabackwards.sponge.VersionInfo; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Order; -import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent; +import org.spongepowered.api.event.game.state.GameInitializationEvent; import org.spongepowered.api.plugin.Dependency; import org.spongepowered.api.plugin.Plugin; -import org.spongepowered.api.plugin.PluginContainer; import us.myles.ViaVersion.sponge.util.LoggerWrapper; import java.util.logging.Logger; @@ -31,26 +31,21 @@ import java.util.logging.Logger; dependencies = {@Dependency(id = "viaversion")} ) public class SpongePlugin implements ViaBackwardsPlatform { + @Getter private Logger logger; @Inject - private PluginContainer container; + private org.slf4j.Logger loggerSlf4j; @Listener(order = Order.LATE) - public void onServerStart(GameAboutToStartServerEvent e) { + public void onGameStart(GameInitializationEvent e) { // Setup Logger - this.logger = new LoggerWrapper(container.getLogger()); + this.logger = new LoggerWrapper(loggerSlf4j); // Init! this.init(); } - @Override - public Logger getLogger() { - return logger; - } - - // TODO check how to for sponge, site was offline @Override public void disable() { - + // Not possible } } diff --git a/velocity/pom.xml b/velocity/pom.xml new file mode 100644 index 00000000..ff974ef4 --- /dev/null +++ b/velocity/pom.xml @@ -0,0 +1,83 @@ + + + + + + viabackwards-parent + nl.matsv + 2.4.0-SNAPSHOT + + 4.0.0 + + viabackwards-velocity + + + + + . + true + src/main/resources/ + + * + + + + + + + org.codehaus.mojo + templating-maven-plugin + 1.0.0 + + + filter-src + + filter-sources + + + + + + + + + + velocity-maven-repo + Velocity maven repo + https://repo.velocitypowered.com/snapshots/ + + true + + + true + + + + + + + + nl.matsv + viabackwards-core + ${project.parent.version} + + + + + com.velocitypowered + velocity-api + 1.0-SNAPSHOT + provided + + + \ No newline at end of file diff --git a/velocity/src/main/java-templates/nl/matsv/viabackwards/velocity/VersionInfo.java b/velocity/src/main/java-templates/nl/matsv/viabackwards/velocity/VersionInfo.java new file mode 100644 index 00000000..f12f184f --- /dev/null +++ b/velocity/src/main/java-templates/nl/matsv/viabackwards/velocity/VersionInfo.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2016 Matsv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package nl.matsv.viabackwards.velocity; + +public class VersionInfo { + public static final String VERSION = "${project.version}"; +} diff --git a/velocity/src/main/java/nl/matsv/viabackwards/VelocityPlugin.java b/velocity/src/main/java/nl/matsv/viabackwards/VelocityPlugin.java new file mode 100644 index 00000000..f20d6f58 --- /dev/null +++ b/velocity/src/main/java/nl/matsv/viabackwards/VelocityPlugin.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Matsv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package nl.matsv.viabackwards; + +import com.google.inject.Inject; +import com.velocitypowered.api.event.PostOrder; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.plugin.Dependency; +import com.velocitypowered.api.plugin.Plugin; +import lombok.Getter; +import nl.matsv.viabackwards.api.ViaBackwardsPlatform; +import nl.matsv.viabackwards.velocity.VersionInfo; +import us.myles.ViaVersion.sponge.util.LoggerWrapper; + +import java.util.logging.Logger; + +@Plugin(id = "viabackwards", + name = "ViaBackwards", + version = VersionInfo.VERSION, + authors = {"Matsv"}, + description = "Allow older Minecraft versions to connect to an newer server version.", + dependencies = {@Dependency(id = "viaversion")} +) +public class VelocityPlugin implements ViaBackwardsPlatform { + @Getter + private Logger logger; + @Inject + private org.slf4j.Logger loggerSlf4j; + + @Subscribe(order = PostOrder.LATE) + public void onProxyStart(ProxyInitializeEvent e) { + // Setup Logger + this.logger = new LoggerWrapper(loggerSlf4j); + // Init! + this.init(); + } + + @Override + public void disable() { + // Not possible + } +}