Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
fix version check + spigot api 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
Puyodead1 committed Jul 1, 2022
1 parent b26688d commit e4efd71
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.puyodead1</groupId>
<artifactId>EnchantCrystals</artifactId>
<version>2.1.6</version>
<version>2.1.7</version>
<packaging>jar</packaging>

<name>EnchantCrystals</name>
Expand Down Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>-->
Expand Down Expand Up @@ -112,7 +112,7 @@
<configuration>
<target>
<copy file="target/${project.name}-${project.version}.jar"
toFile="C:\Users\23562\Desktop\TestServer\1.18.2\plugins\${project.name}-${project.version}.jar"/>
toFile="C:\Users\23562\Desktop\TestServer\1.19\plugins\${project.name}-${project.version}.jar"/>
</target>
</configuration>
<goals>
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/me/puyodead1/enchantcrystals/EnchantCrystals.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,24 @@ public void onEnable() {
plugin = this;
metrics = new Metrics(this, 15180);

EnchantCrystalsUtils.sendConsole(PREFIX + "&d=============================================================");
EnchantCrystalsUtils.sendConsole(PREFIX + "&bAuthor: &ePuyodead1");
EnchantCrystalsUtils.sendConsole(PREFIX + "&b" + this.getName() + " Version: &e" + Objects.requireNonNull(getServer().getPluginManager().getPlugin(this.getDescription().getName())).getDescription().getVersion());
EnchantCrystalsUtils.sendConsole(PREFIX + "&bMinecraft Version: &e" + getServer().getVersion());
EnchantCrystalsUtils.sendConsole(PREFIX + "&bBukkit Version: &e" + getServer().getBukkitVersion());
EnchantCrystalsUtils.sendConsole(PREFIX + "&bNMS Version: &e" + Version.getNMSVersionString() + " (" + Version.getNMSVersionInt() + ")");
EnchantCrystalsUtils.sendConsole(PREFIX + "&d=============================================================");

// disable plugin if the server is running anything older than 1.8.3
if (Version.isOlder(Version.v1_8_R3)) {
EnchantCrystalsUtils.sendConsole(PREFIX + "&cThis server is running 1.8.3 or older which is not supported, plugin will be disabled.");
// disable plugin if the server is running a newer version
if (Version.getCurrentVersion() == Version.TOO_NEW) {
EnchantCrystalsUtils.sendConsole(PREFIX + "&cThis server is running a newer version of Minecraft, the latest supported version is " + Version.getLatestVersion() + ", plugin will be disabled. Please file an issue on GitHub.");
getServer().getPluginManager().disablePlugin(this);
return;
}

// disable plugin if the server is running a newer version
if(Version.getCurrentVersion() == Version.TOO_NEW) {
EnchantCrystalsUtils.sendConsole(PREFIX + "&cThis server is running a newer version of Minecraft, the latest supported version is " + Version.getLatestVersion() + ", plugin will be disabled. Please file an issue on GitHub.");
// disable plugin if the server is running anything older than 1.8.3
if (Version.isOlder(Version.v1_8_R3)) {
EnchantCrystalsUtils.sendConsole(PREFIX + "&cThis server is running 1.8.3 or older which is not supported, plugin will be disabled.");
getServer().getPluginManager().disablePlugin(this);
return;
}
Expand Down Expand Up @@ -67,14 +73,6 @@ public void onEnable() {
initConfig();
initEvents();
initCommands();

EnchantCrystalsUtils.sendConsole(PREFIX + "&d========================");
EnchantCrystalsUtils.sendConsole(PREFIX + "&bAuthor: &ePuyodead1");
EnchantCrystalsUtils.sendConsole(PREFIX + "&b" + this.getName() + " Version: &e" + Objects.requireNonNull(getServer().getPluginManager().getPlugin(this.getDescription().getName())).getDescription().getVersion());
EnchantCrystalsUtils.sendConsole(PREFIX + "&bMinecraft Version: &e" + getServer().getVersion());
EnchantCrystalsUtils.sendConsole(PREFIX + "&bBukkit Version: &e" + getServer().getBukkitVersion());
EnchantCrystalsUtils.sendConsole(PREFIX + "&bNMS Version: &e" + Version.getCurrentVersion().toString() + " (" + Version.getCurrentVersion().getVersionInteger() + ")");
EnchantCrystalsUtils.sendConsole(PREFIX + "&d=============================================================");
}

@Override
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/me/puyodead1/enchantcrystals/nms/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ public enum Version {
this.versionInteger = versionInteger;
}

public static String getNMSVersionString() {
String v = Bukkit.getServer().getClass().getPackage().getName();
return v.substring(v.lastIndexOf('.') + 1);
}

public static int getNMSVersionInt() {
String ver = getNMSVersionString();
return Integer.parseInt(ver.replace("_", "").replace("R", "").replace("v", ""));
}

/**
* @return Get the server's Minecraft version.
*/
public static Version getCurrentVersion() {
if (currentVersion == null) {
String ver = Bukkit.getServer().getClass().getPackage().getName();
int v = Integer.parseInt(ver.substring(ver.lastIndexOf('.') + 1).replace("_", "").replace("R", "").replace("v", ""));
int v = getNMSVersionInt();
for (Version version : values()) {
if (version.getVersionInteger() == v) {
currentVersion = version;
Expand Down

0 comments on commit e4efd71

Please sign in to comment.