Skip to content

Commit

Permalink
Fix problems on load in versions >1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Nov 13, 2023
1 parent 8faf22a commit 3f94ab4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.tonimatasdev.perworldplugins.manager.ListenerManager;
import net.tonimatasdev.perworldplugins.metrics.Metrics;
import net.tonimatasdev.perworldplugins.util.UpdateChecker;
import net.tonimatasdev.perworldplugins.util.Version;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -22,6 +23,8 @@ public static PerWorldPlugins getInstance() {

@Override
public void onLoad() {
// Detect the server version
if (Version.getVersion() <= 1192) return;
// Enable PerWorldPlugins
this.getPluginLoader().enablePlugin(this);
}
Expand All @@ -38,8 +41,8 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new Listeners(), this);

// Register command and tab completer.
Objects.requireNonNull(Bukkit.getPluginCommand("perworldplugins")).setExecutor(new PrimaryCommand());
Objects.requireNonNull(Bukkit.getPluginCommand("perworldplugins")).setTabCompleter(new PrimaryCommand());
Objects.requireNonNull(getCommand("perworldplugins")).setExecutor(new PrimaryCommand());
Objects.requireNonNull(getCommand("perworldplugins")).setTabCompleter(new PrimaryCommand());

// Register metrics.
if (getConfig().getBoolean("metrics")) new Metrics(this, 15794);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.Executors;
Expand All @@ -25,6 +24,7 @@

// bStats metrics, this class is not programmed for me.

@SuppressWarnings("deprecation")
public class Metrics {
private final Plugin plugin;

Expand All @@ -41,11 +41,11 @@ public Metrics(JavaPlugin plugin, int serviceId) {
config.addDefault("logFailedRequests", false);
config.addDefault("logSentData", false);
config.addDefault("logResponseStatusText", false);
config.options().setHeader(Arrays.asList("bStats (https://bStats.org) collects some basic information for plugin authors, like how",
"many people use their plugin and their total player count. It's recommended to keep bStats",
"enabled, but if you're not comfortable with this, you can turn this setting off. There is no",
"performance penalty associated with having metrics enabled, and data sent to bStats is fully",
"anonymous.")).copyDefaults(true);
config.options().header("bStats (https://bStats.org) collects some basic information for plugin authors, like how\n" +
"many people use their plugin and their total player count. It's recommended to keep bStats\n" +
"enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n" +
"performance penalty associated with having metrics enabled, and data sent to bStats is fully\n" +
"anonymous.").copyDefaults(true);

try {
config.save(configFile);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/net/tonimatasdev/perworldplugins/util/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.tonimatasdev.perworldplugins.util;

import org.bukkit.Bukkit;

public class Version {
private static final String[] versionString = Bukkit.getBukkitVersion().split("-")[0].split("\\.");

public static int getVersion() {
// Create new StringBuilder.
StringBuilder version = new StringBuilder();

// Append all versions.
for (String number : versionString) {
version.append(number);
}

if (versionString.length == 2) version.append(0);

// Return version int (Example: 188 - 1.8.8)
return Integer.parseInt(version.toString());
}
}

0 comments on commit 3f94ab4

Please sign in to comment.