Remove unsupported versions and display error messages

This commit is contained in:
filoghost 2021-08-14 12:26:53 +02:00
parent e1009b8cd8
commit 14541eb25d
11 changed files with 56 additions and 259 deletions

View File

@ -14,14 +14,11 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>v1_8_r2</module>
<module>v1_8_r3</module> <module>v1_8_r3</module>
<module>v1_9_r1</module>
<module>v1_9_r2</module> <module>v1_9_r2</module>
<module>v1_10_r1</module> <module>v1_10_r1</module>
<module>v1_11_r1</module> <module>v1_11_r1</module>
<module>v1_12_r1</module> <module>v1_12_r1</module>
<module>v1_13_r1</module>
<module>v1_13_r2</module> <module>v1_13_r2</module>
<module>v1_14_r1</module> <module>v1_14_r1</module>
<module>v1_15_r1</module> <module>v1_15_r1</module>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-nms</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>holographicdisplays-nms-v1_13_r1</artifactId>
<name>HolographicDisplays NMS v1_13_R1</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-common</artifactId>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.nms.v1_13_R1;
import me.filoghost.holographicdisplays.common.nms.EntityID;
import me.filoghost.holographicdisplays.common.nms.NMSManager;
import me.filoghost.holographicdisplays.common.nms.NMSPacketList;
import me.filoghost.holographicdisplays.common.nms.PacketListener;
import org.bukkit.entity.Player;
public class VersionNMSManager implements NMSManager {
@Override
public EntityID newEntityID() {
return null;
}
@Override
public NMSPacketList createPacketList() {
return null;
}
@Override
public void injectPacketListener(Player player, PacketListener packetListener) {
}
@Override
public void uninjectPacketListener(Player player) {
}
}

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-nms</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>holographicdisplays-nms-v1_8_r2</artifactId>
<name>HolographicDisplays NMS v1_8_R2</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-common</artifactId>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.8.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.nms.v1_8_R2;
import me.filoghost.holographicdisplays.common.nms.EntityID;
import me.filoghost.holographicdisplays.common.nms.NMSManager;
import me.filoghost.holographicdisplays.common.nms.NMSPacketList;
import me.filoghost.holographicdisplays.common.nms.PacketListener;
import org.bukkit.entity.Player;
public class VersionNMSManager implements NMSManager {
@Override
public EntityID newEntityID() {
return null;
}
@Override
public NMSPacketList createPacketList() {
return null;
}
@Override
public void injectPacketListener(Player player, PacketListener packetListener) {
}
@Override
public void uninjectPacketListener(Player player) {
}
}

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-nms</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>holographicdisplays-nms-v1_9_r1</artifactId>
<name>HolographicDisplays NMS v1_9_R1</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-common</artifactId>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.9-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.nms.v1_9_R1;
import me.filoghost.holographicdisplays.common.nms.EntityID;
import me.filoghost.holographicdisplays.common.nms.NMSManager;
import me.filoghost.holographicdisplays.common.nms.NMSPacketList;
import me.filoghost.holographicdisplays.common.nms.PacketListener;
import org.bukkit.entity.Player;
public class VersionNMSManager implements NMSManager {
@Override
public EntityID newEntityID() {
return null;
}
@Override
public NMSPacketList createPacketList() {
return null;
}
@Override
public void injectPacketListener(Player player, PacketListener packetListener) {
}
@Override
public void uninjectPacketListener(Player player) {
}
}

View File

@ -34,21 +34,11 @@
<artifactId>holographicdisplays-legacy-api-v2</artifactId> <artifactId>holographicdisplays-legacy-api-v2</artifactId>
</dependency> </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_8_r2</artifactId>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_8_r3</artifactId> <artifactId>holographicdisplays-nms-v1_8_r3</artifactId>
</dependency> </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_9_r1</artifactId>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_9_r2</artifactId> <artifactId>holographicdisplays-nms-v1_9_r2</artifactId>
@ -69,11 +59,6 @@
<artifactId>holographicdisplays-nms-v1_12_r1</artifactId> <artifactId>holographicdisplays-nms-v1_12_r1</artifactId>
</dependency> </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_13_r1</artifactId>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_13_r2</artifactId> <artifactId>holographicdisplays-nms-v1_13_r2</artifactId>

View File

@ -37,6 +37,7 @@ import me.filoghost.holographicdisplays.plugin.placeholder.internal.DefaultPlace
import me.filoghost.holographicdisplays.plugin.placeholder.registry.PlaceholderRegistry; import me.filoghost.holographicdisplays.plugin.placeholder.registry.PlaceholderRegistry;
import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderTracker; import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderTracker;
import me.filoghost.holographicdisplays.plugin.util.NMSVersion; import me.filoghost.holographicdisplays.plugin.util.NMSVersion;
import me.filoghost.holographicdisplays.plugin.util.NMSVersion.OutdatedVersionException;
import me.filoghost.holographicdisplays.plugin.util.NMSVersion.UnknownVersionException; import me.filoghost.holographicdisplays.plugin.util.NMSVersion.UnknownVersionException;
import org.bstats.bukkit.MetricsLite; import org.bstats.bukkit.MetricsLite;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -87,9 +88,9 @@ public class HolographicDisplays extends FCommonsPlugin {
try { try {
nmsManager = NMSVersion.getCurrent().createNMSManager(errorCollector); nmsManager = NMSVersion.getCurrent().createNMSManager(errorCollector);
} catch (UnknownVersionException e) { } catch (UnknownVersionException e) {
throw new PluginEnableException( throw new PluginEnableException("Holographic Displays only supports Spigot from 1.8 to 1.17.");
"Holographic Displays does not support this server version.", } catch (OutdatedVersionException e) {
"Supported Spigot versions: from 1.8.3 to 1.17."); throw new PluginEnableException("Holographic Displays only supports " + e.getMinimumSupportedVersion() + " and above.");
} catch (Throwable t) { } catch (Throwable t) {
throw new PluginEnableException(t, "Couldn't initialize the NMS manager."); throw new PluginEnableException(t, "Couldn't initialize the NMS manager.");
} }

View File

@ -19,23 +19,26 @@ import java.util.regex.Pattern;
public enum NMSVersion { public enum NMSVersion {
// Not using shorter method reference syntax here because it initializes the class, causing a ClassNotFoundException // Not using shorter method reference syntax here because it initializes the class, causing a ClassNotFoundException
v1_8_R2((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_8_R2.VersionNMSManager()),
v1_8_R3((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_8_R3.VersionNMSManager(errorCollector)),
v1_9_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_9_R1.VersionNMSManager()),
v1_9_R2((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_9_R2.VersionNMSManager(errorCollector)),
v1_10_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_10_R1.VersionNMSManager(errorCollector)),
v1_11_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_11_R1.VersionNMSManager(errorCollector)),
v1_12_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_12_R1.VersionNMSManager(errorCollector)),
v1_13_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_13_R1.VersionNMSManager()),
v1_13_R2((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_13_R2.VersionNMSManager(errorCollector)),
v1_14_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_14_R1.VersionNMSManager(errorCollector)),
v1_15_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_15_R1.VersionNMSManager(errorCollector)),
v1_16_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_16_R1.VersionNMSManager(errorCollector)),
v1_16_R2((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_16_R2.VersionNMSManager(errorCollector)),
v1_16_R3((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_16_R3.VersionNMSManager(errorCollector)),
v1_17_R1((errorCollector) -> new me.filoghost.holographicdisplays.nms.v1_17_R1.VersionNMSManager(errorCollector));
private static final NMSVersion CURRENT_VERSION = extractCurrentVersion(); /* 1.8 - 1.8.2 */ v1_8_R1(NMSManagerFactory.outdatedVersion("1.8.4")),
/* 1.8.3 */ v1_8_R2(NMSManagerFactory.outdatedVersion("1.8.4")),
/* 1.8.4 - 1.8.9 */ v1_8_R3(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_8_R3.VersionNMSManager(errorCollector)),
/* 1.9 - 1.9.3 */ v1_9_R1(NMSManagerFactory.outdatedVersion("1.9.4")),
/* 1.9.4 */ v1_9_R2(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_9_R2.VersionNMSManager(errorCollector)),
/* 1.10 - 1.10.2 */ v1_10_R1(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_10_R1.VersionNMSManager(errorCollector)),
/* 1.11 - 1.11.2 */ v1_11_R1(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_11_R1.VersionNMSManager(errorCollector)),
/* 1.12 - 1.12.2 */ v1_12_R1(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_12_R1.VersionNMSManager(errorCollector)),
/* 1.13 */ v1_13_R1(NMSManagerFactory.outdatedVersion("1.13.1")),
/* 1.13.1 - 1.13.2 */ v1_13_R2(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_13_R2.VersionNMSManager(errorCollector)),
/* 1.14 - 1.14.4 */ v1_14_R1(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_14_R1.VersionNMSManager(errorCollector)),
/* 1.15 - 1.15.2 */ v1_15_R1(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_15_R1.VersionNMSManager(errorCollector)),
/* 1.16 - 1.16.1 */ v1_16_R1(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_16_R1.VersionNMSManager(errorCollector)),
/* 1.16.2 - 1.16.3 */ v1_16_R2(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_16_R2.VersionNMSManager(errorCollector)),
/* 1.16.4 - 1.16.5 */ v1_16_R3(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_16_R3.VersionNMSManager(errorCollector)),
/* 1.17 - ? */ v1_17_R1(errorCollector -> new me.filoghost.holographicdisplays.nms.v1_17_R1.VersionNMSManager(errorCollector)),
/* Other versions */ UNKNOWN(NMSManagerFactory.unknownVersion());
private static final NMSVersion CURRENT_VERSION = detectCurrentVersion();
private final NMSManagerFactory nmsManagerFactory; private final NMSManagerFactory nmsManagerFactory;
@ -43,38 +46,62 @@ public enum NMSVersion {
this.nmsManagerFactory = nmsManagerFactory; this.nmsManagerFactory = nmsManagerFactory;
} }
public NMSManager createNMSManager(ErrorCollector errorCollector) { public NMSManager createNMSManager(ErrorCollector errorCollector) throws OutdatedVersionException, UnknownVersionException {
return nmsManagerFactory.create(errorCollector); return nmsManagerFactory.create(errorCollector);
} }
public static NMSVersion getCurrent() throws UnknownVersionException { public static NMSVersion getCurrent() {
if (CURRENT_VERSION == null) {
throw new UnknownVersionException();
}
return CURRENT_VERSION; return CURRENT_VERSION;
} }
private static NMSVersion extractCurrentVersion() { private static NMSVersion detectCurrentVersion() {
Matcher matcher = Pattern.compile("v\\d+_\\d+_R\\d+").matcher(Bukkit.getServer().getClass().getPackage().getName()); Matcher matcher = Pattern.compile("v\\d+_\\d+_R\\d+").matcher(Bukkit.getServer().getClass().getPackage().getName());
if (!matcher.find()) { if (!matcher.find()) {
return null; return UNKNOWN;
} }
String nmsVersionName = matcher.group(); String nmsVersionName = matcher.group();
try { try {
return valueOf(nmsVersionName); return valueOf(nmsVersionName);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return null; // Unknown version return UNKNOWN;
} }
} }
@FunctionalInterface
private interface NMSManagerFactory { private interface NMSManagerFactory {
NMSManager create(ErrorCollector errorCollector); NMSManager create(ErrorCollector errorCollector) throws UnknownVersionException, OutdatedVersionException;
static NMSManagerFactory unknownVersion() {
return errorCollector -> {
throw new UnknownVersionException();
};
}
static NMSManagerFactory outdatedVersion(String minimumSupportedVersion) {
return errorCollector -> {
throw new OutdatedVersionException(minimumSupportedVersion);
};
}
} }
public static class UnknownVersionException extends Exception {} public static class UnknownVersionException extends Exception {}
public static class OutdatedVersionException extends Exception {
private final String minimumSupportedVersion;
public OutdatedVersionException(String minimumSupportedVersion) {
this.minimumSupportedVersion = minimumSupportedVersion;
}
public String getMinimumSupportedVersion() {
return minimumSupportedVersion;
}
}
} }

18
pom.xml
View File

@ -96,24 +96,12 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_8_r2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_8_r3</artifactId> <artifactId>holographicdisplays-nms-v1_8_r3</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_9_r1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_9_r2</artifactId> <artifactId>holographicdisplays-nms-v1_9_r2</artifactId>
@ -138,12 +126,6 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_13_r1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>holographicdisplays-nms-v1_13_r2</artifactId> <artifactId>holographicdisplays-nms-v1_13_r2</artifactId>