mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-23 19:16:14 +01:00
Make sure all Spigot forks are included for updater purposes
Addresses #835
This commit is contained in:
parent
944b3f8280
commit
3f7b7f4bb3
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 <E> List<E> asList(E... elements) {
|
||||
List<E> list = new ArrayList<E>(elements.length);
|
||||
for (E element : elements) {
|
||||
list.add(element);
|
||||
}
|
||||
|
||||
List<E> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user