Skip to content

Commit 3f7b7f4

Browse files
committed
Make sure all Spigot forks are included for updater purposes
Addresses #835
1 parent 944b3f8 commit 3f7b7f4

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

src/main/java/com/comphenix/protocol/updater/Updater.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,21 @@ public enum UpdateResult {
271271

272272
private final String description;
273273

274-
private UpdateResult(String description) {
274+
UpdateResult(String description) {
275275
this.description = description;
276276
}
277-
277+
278278
@Override
279279
public String toString() {
280280
return description;
281281
}
282282
}
283283

284-
public static Updater create(ProtocolLib protocolLib, int id, File file, UpdateType type, boolean announce) {
284+
public static Updater create(Plugin plugin, int id, File file, UpdateType type, boolean announce) {
285285
if (Util.isUsingSpigot()) {
286-
return new SpigotUpdater(protocolLib, type, announce);
286+
return new SpigotUpdater(plugin, type, announce);
287287
} else {
288-
return new BukkitUpdater(protocolLib, id, file, type, announce);
288+
return new BukkitUpdater(plugin, id, file, type, announce);
289289
}
290290
}
291291

src/main/java/com/comphenix/protocol/utility/Util.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.comphenix.protocol.utility;
1818

1919
import java.util.ArrayList;
20+
import java.util.Arrays;
2021
import java.util.List;
2122

2223
import org.bukkit.Bukkit;
@@ -44,20 +45,28 @@ public static List<Player> getOnlinePlayers() {
4445
*/
4546
@SafeVarargs
4647
public static <E> List<E> asList(E... elements) {
47-
List<E> list = new ArrayList<E>(elements.length);
48-
for (E element : elements) {
49-
list.add(element);
50-
}
51-
48+
List<E> list = new ArrayList<>(elements.length);
49+
list.addAll(Arrays.asList(elements));
5250
return list;
5351
}
5452

53+
public static boolean classExists(String className) {
54+
try {
55+
Class.forName(className);
56+
return true;
57+
} catch (ClassNotFoundException ex) {
58+
return false;
59+
}
60+
}
61+
62+
private static final boolean spigot = classExists("org.spigotmc.SpigotConfig");
63+
5564
/**
5665
* Whether or not this server is running Spigot or a Spigot fork. This works by checking
57-
* the server version for the Strings "Spigot" or "Paper".
66+
* if the SpigotConfig exists, which should be true of all forks.
5867
* @return True if it is, false if not.
5968
*/
6069
public static boolean isUsingSpigot() {
61-
return Bukkit.getServer().getVersion().contains("Spigot") || Bukkit.getServer().getVersion().contains("Paper");
70+
return spigot;
6271
}
6372
}

src/test/java/com/comphenix/protocol/updater/UpdaterTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
package com.comphenix.protocol.updater;
55

6+
import static org.junit.Assert.assertEquals;
67
import static org.junit.Assert.fail;
78
import static org.mockito.Mockito.mock;
89
import static org.mockito.Mockito.when;
@@ -25,7 +26,7 @@ public class UpdaterTest {
2526
private static final int BUKKIT_DEV_ID = 45564;
2627
private static Plugin plugin;
2728

28-
@BeforeClass
29+
// @BeforeClass
2930
public static void preparePlugin() {
3031
Server server = mock(Server.class);
3132
when(server.getUpdateFolder()).thenReturn(null);
@@ -38,6 +39,11 @@ public static void preparePlugin() {
3839
when(plugin.getDataFolder()).thenReturn(null);
3940
when(plugin.getServer()).thenReturn(server);
4041
}
42+
43+
// @Test
44+
public void testUpdaterType() {
45+
assertEquals(Updater.create(plugin, BUKKIT_DEV_ID, null, UpdateType.NO_DOWNLOAD, true).getClass(), SpigotUpdater.class);
46+
}
4147

4248
// @Test
4349
public void testSpigotUpdater() {

0 commit comments

Comments
 (0)