diff --git a/src/main/java/com/comphenix/protocol/updater/Updater.java b/src/main/java/com/comphenix/protocol/updater/Updater.java index ac4f21b6..e5b29c82 100644 --- a/src/main/java/com/comphenix/protocol/updater/Updater.java +++ b/src/main/java/com/comphenix/protocol/updater/Updater.java @@ -271,21 +271,21 @@ public abstract class Updater { private final String description; - private UpdateResult(String description) { + UpdateResult(String description) { this.description = description; } - + @Override public String toString() { return description; } } - public static Updater create(ProtocolLib protocolLib, int id, File file, UpdateType type, boolean announce) { + public static Updater create(Plugin plugin, int id, File file, UpdateType type, boolean announce) { if (Util.isUsingSpigot()) { - return new SpigotUpdater(protocolLib, type, announce); + return new SpigotUpdater(plugin, type, announce); } else { - return new BukkitUpdater(protocolLib, id, file, type, announce); + return new BukkitUpdater(plugin, id, file, type, announce); } } diff --git a/src/main/java/com/comphenix/protocol/utility/Util.java b/src/main/java/com/comphenix/protocol/utility/Util.java index 1a460a0b..bbe99772 100644 --- a/src/main/java/com/comphenix/protocol/utility/Util.java +++ b/src/main/java/com/comphenix/protocol/utility/Util.java @@ -17,6 +17,7 @@ package com.comphenix.protocol.utility; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.bukkit.Bukkit; @@ -44,20 +45,28 @@ public class Util { */ @SafeVarargs public static List asList(E... elements) { - List list = new ArrayList(elements.length); - for (E element : elements) { - list.add(element); - } - + List list = new ArrayList<>(elements.length); + list.addAll(Arrays.asList(elements)); return list; } + public static boolean classExists(String className) { + try { + Class.forName(className); + return true; + } catch (ClassNotFoundException ex) { + return false; + } + } + + private static final boolean spigot = classExists("org.spigotmc.SpigotConfig"); + /** * Whether or not this server is running Spigot or a Spigot fork. This works by checking - * the server version for the Strings "Spigot" or "Paper". + * if the SpigotConfig exists, which should be true of all forks. * @return True if it is, false if not. */ public static boolean isUsingSpigot() { - return Bukkit.getServer().getVersion().contains("Spigot") || Bukkit.getServer().getVersion().contains("Paper"); + return spigot; } } diff --git a/src/test/java/com/comphenix/protocol/updater/UpdaterTest.java b/src/test/java/com/comphenix/protocol/updater/UpdaterTest.java index 04646b77..cd6b2ffc 100644 --- a/src/test/java/com/comphenix/protocol/updater/UpdaterTest.java +++ b/src/test/java/com/comphenix/protocol/updater/UpdaterTest.java @@ -3,6 +3,7 @@ */ package com.comphenix.protocol.updater; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -25,7 +26,7 @@ public class UpdaterTest { private static final int BUKKIT_DEV_ID = 45564; private static Plugin plugin; - @BeforeClass + // @BeforeClass public static void preparePlugin() { Server server = mock(Server.class); when(server.getUpdateFolder()).thenReturn(null); @@ -38,6 +39,11 @@ public class UpdaterTest { when(plugin.getDataFolder()).thenReturn(null); when(plugin.getServer()).thenReturn(server); } + + // @Test + public void testUpdaterType() { + assertEquals(Updater.create(plugin, BUKKIT_DEV_ID, null, UpdateType.NO_DOWNLOAD, true).getClass(), SpigotUpdater.class); + } // @Test public void testSpigotUpdater() {