Fix API NPE

NMSProvider was giving a NPE
This commit is contained in:
James Peters 2021-12-20 16:23:29 +00:00
parent 9ad0e41c6b
commit 5bc7fbcd37
3 changed files with 9 additions and 7 deletions

View File

@ -10,16 +10,17 @@ public class Api {
private static Plugin plugin;
private static NMSProvider nmsProvider;
public static void register(Plugin plugin) {
public static void init(Plugin plugin) {
Api.plugin = plugin;
Values.init(plugin);
nmsProvider = setupNMSProvider();
}
public static Plugin getPlugin() {
return plugin;
}
public static NMSProvider setupNMSProvider() {
private static NMSProvider setupNMSProvider() {
String packageName = NMSProvider.class.getPackage().getName();
String nmsVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
String nmsProvider = packageName + "." + nmsVersion + ".NMSProviderImpl";
@ -33,7 +34,7 @@ public class Api {
}
}
protected static NMSProvider getNmsProvider() {
public static NMSProvider getNmsProvider() {
return nmsProvider;
}
}

View File

@ -94,8 +94,7 @@ public class ChestsPlusPlus extends JavaPlugin {
Stats.addCharts(metrics);
//API initialisation
Api.register(this);
ApiSpecific.init();
ApiSpecific.init(this);
//Register commands
new ChestLinkCommand().register(this);

View File

@ -5,6 +5,7 @@ import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
public class ApiSpecific {
@ -13,8 +14,9 @@ public class ApiSpecific {
private static ChestOpener chestOpener;
private static NMSProvider nmsProvider;
public static void init() {
nmsProvider = Api.setupNMSProvider();
public static void init(Plugin plugin) {
Api.init(plugin);
nmsProvider = Api.getNmsProvider();
if (nmsProvider == null) nmsProvider = new NMSProviderDefault();
materialChecker = nmsProvider.getMaterialChecker();
chestOpener = nmsProvider.getChestOpener();