From 9fc4ebdd13187af7efa1cfa85477930158f0b4f3 Mon Sep 17 00:00:00 2001 From: jameslfc19 Date: Tue, 7 Jul 2020 17:26:53 +0100 Subject: [PATCH] Changed NMS Method. Calls to newer NMS not possible from Core now. --- .../jamesdpeters/minecraft/chests/API.java | 15 ++++ .../minecraft/chests/MaterialChecker.java | 4 +- .../minecraft/chests/NMSProvider.java | 6 ++ .../{ => v1_14_R1}/ChestOpener_1_14.java | 3 +- .../{ => v1_14_R1}/CustomTileEntityChest.java | 2 +- .../{ => v1_14_R1}/MaterialChecker_1_14.java | 7 +- .../chests/v1_14_R1/NMSProviderImpl.java | 17 +++++ .../{ => v1_15_R1}/ChestOpener_1_15.java | 3 +- .../{ => v1_15_R1}/CustomTileEntityChest.java | 2 +- .../{ => v1_15_R1}/MaterialChecker_1_15.java | 8 +- .../chests/v1_15_R1/NMSProviderImpl.java | 17 +++++ .../{ => v1_16_R1}/ChestOpener_1_16.java | 7 +- .../{ => v1_16_R1}/CustomTileEntityChest.java | 2 +- .../{ => v1_16_R1}/MaterialChecker_1_16.java | 8 +- .../chests/v1_16_R1/NMSProviderImpl.java | 18 +++++ .../minecraft/chests/ChestsPlusPlus.java | 2 +- .../minecraft/chests/api/ApiSpecific.java | 29 ++++++++ .../chests/api/NMSProviderDefault.java | 21 ++++++ .../chests/api_interfaces/ApiSpecific.java | 74 ------------------- .../commands/ChestsPlusPlusCommand.java | 2 +- .../storage/abstracts/AbstractStorage.java | 2 +- 21 files changed, 155 insertions(+), 94 deletions(-) create mode 100644 ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/NMSProvider.java rename ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/{ => v1_14_R1}/ChestOpener_1_14.java (92%) rename ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/{ => v1_14_R1}/CustomTileEntityChest.java (93%) rename ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/{ => v1_14_R1}/MaterialChecker_1_14.java (96%) create mode 100644 ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/NMSProviderImpl.java rename ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/{ => v1_15_R1}/ChestOpener_1_15.java (92%) rename ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/{ => v1_15_R1}/CustomTileEntityChest.java (93%) rename ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/{ => v1_15_R1}/MaterialChecker_1_15.java (78%) create mode 100644 ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/NMSProviderImpl.java rename ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/{ => v1_16_R1}/ChestOpener_1_16.java (87%) rename ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/{ => v1_16_R1}/CustomTileEntityChest.java (93%) rename ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/{ => v1_16_R1}/MaterialChecker_1_16.java (84%) create mode 100644 ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/NMSProviderImpl.java create mode 100644 ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/ApiSpecific.java create mode 100644 ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/NMSProviderDefault.java delete mode 100644 ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api_interfaces/ApiSpecific.java diff --git a/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/API.java b/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/API.java index 6a70d80..63e190b 100644 --- a/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/API.java +++ b/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/API.java @@ -1,5 +1,6 @@ package com.jamesdpeters.minecraft.chests; +import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; public class API { @@ -13,4 +14,18 @@ public class API { public static Plugin getPlugin(){ return plugin; } + + public static NMSProvider getNMSProvider(){ + String packageName = NMSProvider.class.getPackage().getName(); + String nmsVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + String nmsProvider = packageName+"."+nmsVersion+".NMSProviderImpl"; + plugin.getLogger().info("Found API version: "+nmsVersion); + try { + return (NMSProvider) Class.forName(nmsProvider).newInstance(); + } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { + plugin.getLogger().warning("A valid server implementation wasn't found for: "+nmsVersion); + plugin.getLogger().warning("You may be running an outdated version of the plugin or it needs to be updated to the latest version!"); + return null; + } + } } diff --git a/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker.java b/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker.java index 8dddcd5..01db80d 100644 --- a/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker.java +++ b/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker.java @@ -15,13 +15,13 @@ public abstract class MaterialChecker { * @return * List of Materials. */ - protected abstract List graphically2DList(); + public abstract List graphically2DList(); /** * List of @{@link Material} that gets ignored (Beds are a pain). * @return */ - protected abstract List ignoredMaterials(); + public abstract List ignoredMaterials(); /** * This returns true if an item is held like a pickaxe/sword etc. diff --git a/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/NMSProvider.java b/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/NMSProvider.java new file mode 100644 index 0000000..b0c6435 --- /dev/null +++ b/ChestsPlusPlusAPI/src/main/java/com/jamesdpeters/minecraft/chests/NMSProvider.java @@ -0,0 +1,6 @@ +package com.jamesdpeters.minecraft.chests; + +public interface NMSProvider { + ChestOpener getChestOpener(); + MaterialChecker getMaterialChecker(); +} diff --git a/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/ChestOpener_1_14.java b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/ChestOpener_1_14.java similarity index 92% rename from ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/ChestOpener_1_14.java rename to ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/ChestOpener_1_14.java index c1007b2..6d2a143 100644 --- a/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/ChestOpener_1_14.java +++ b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/ChestOpener_1_14.java @@ -1,5 +1,6 @@ -package com.jamesdpeters.minecraft.chests; +package com.jamesdpeters.minecraft.chests.v1_14_R1; +import com.jamesdpeters.minecraft.chests.ChestOpener; import net.minecraft.server.v1_14_R1.BlockPosition; import net.minecraft.server.v1_14_R1.TileEntity; import net.minecraft.server.v1_14_R1.TileEntityChest; diff --git a/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/CustomTileEntityChest.java b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/CustomTileEntityChest.java similarity index 93% rename from ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/CustomTileEntityChest.java rename to ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/CustomTileEntityChest.java index f3239e1..aec0764 100644 --- a/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/CustomTileEntityChest.java +++ b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/CustomTileEntityChest.java @@ -1,4 +1,4 @@ -package com.jamesdpeters.minecraft.chests; +package com.jamesdpeters.minecraft.chests.v1_14_R1; import net.minecraft.server.v1_14_R1.Block; import net.minecraft.server.v1_14_R1.BlockChest; diff --git a/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_14.java b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/MaterialChecker_1_14.java similarity index 96% rename from ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_14.java rename to ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/MaterialChecker_1_14.java index 4241d11..66cdc3c 100644 --- a/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_14.java +++ b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/MaterialChecker_1_14.java @@ -1,5 +1,6 @@ -package com.jamesdpeters.minecraft.chests; +package com.jamesdpeters.minecraft.chests.v1_14_R1; +import com.jamesdpeters.minecraft.chests.MaterialChecker; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.inventory.ItemStack; @@ -106,12 +107,12 @@ public class MaterialChecker_1_14 extends MaterialChecker { } @Override - protected List graphically2DList() { + public List graphically2DList() { return version_1_14_Items; } @Override - protected List ignoredMaterials() { + public List ignoredMaterials() { return version_1_14_Ignored_Items; } diff --git a/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/NMSProviderImpl.java b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/NMSProviderImpl.java new file mode 100644 index 0000000..756b8c5 --- /dev/null +++ b/ChestsPlusPlus_1_14/src/main/java/com/jamesdpeters/minecraft/chests/v1_14_R1/NMSProviderImpl.java @@ -0,0 +1,17 @@ +package com.jamesdpeters.minecraft.chests.v1_14_R1; + +import com.jamesdpeters.minecraft.chests.ChestOpener; +import com.jamesdpeters.minecraft.chests.MaterialChecker; +import com.jamesdpeters.minecraft.chests.NMSProvider; + +public class NMSProviderImpl implements NMSProvider { + @Override + public ChestOpener getChestOpener() { + return new ChestOpener_1_14(); + } + + @Override + public MaterialChecker getMaterialChecker() { + return new MaterialChecker_1_14(); + } +} diff --git a/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/ChestOpener_1_15.java b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/ChestOpener_1_15.java similarity index 92% rename from ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/ChestOpener_1_15.java rename to ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/ChestOpener_1_15.java index 790bda9..29da8f4 100644 --- a/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/ChestOpener_1_15.java +++ b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/ChestOpener_1_15.java @@ -1,5 +1,6 @@ -package com.jamesdpeters.minecraft.chests; +package com.jamesdpeters.minecraft.chests.v1_15_R1; +import com.jamesdpeters.minecraft.chests.ChestOpener; import net.minecraft.server.v1_15_R1.BlockPosition; import net.minecraft.server.v1_15_R1.TileEntity; import net.minecraft.server.v1_15_R1.TileEntityChest; diff --git a/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/CustomTileEntityChest.java b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/CustomTileEntityChest.java similarity index 93% rename from ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/CustomTileEntityChest.java rename to ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/CustomTileEntityChest.java index cc16a03..206fd37 100644 --- a/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/CustomTileEntityChest.java +++ b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/CustomTileEntityChest.java @@ -1,4 +1,4 @@ -package com.jamesdpeters.minecraft.chests; +package com.jamesdpeters.minecraft.chests.v1_15_R1; import net.minecraft.server.v1_15_R1.Block; import net.minecraft.server.v1_15_R1.BlockChest; diff --git a/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_15.java b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/MaterialChecker_1_15.java similarity index 78% rename from ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_15.java rename to ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/MaterialChecker_1_15.java index 5f5bb72..e3d4902 100644 --- a/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_15.java +++ b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/MaterialChecker_1_15.java @@ -1,6 +1,8 @@ -package com.jamesdpeters.minecraft.chests; +package com.jamesdpeters.minecraft.chests.v1_15_R1; +import com.jamesdpeters.minecraft.chests.MaterialChecker; +import com.jamesdpeters.minecraft.chests.v1_14_R1.MaterialChecker_1_14; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -24,12 +26,12 @@ public class MaterialChecker_1_15 extends MaterialChecker { } @Override - protected List graphically2DList() { + public List graphically2DList() { return materials; } @Override - protected List ignoredMaterials() { + public List ignoredMaterials() { return ignoredMaterials; } diff --git a/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/NMSProviderImpl.java b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/NMSProviderImpl.java new file mode 100644 index 0000000..7bd4144 --- /dev/null +++ b/ChestsPlusPlus_1_15/src/main/java/com/jamesdpeters/minecraft/chests/v1_15_R1/NMSProviderImpl.java @@ -0,0 +1,17 @@ +package com.jamesdpeters.minecraft.chests.v1_15_R1; + +import com.jamesdpeters.minecraft.chests.ChestOpener; +import com.jamesdpeters.minecraft.chests.MaterialChecker; +import com.jamesdpeters.minecraft.chests.NMSProvider; + +public class NMSProviderImpl implements NMSProvider { + @Override + public ChestOpener getChestOpener() { + return new ChestOpener_1_15(); + } + + @Override + public MaterialChecker getMaterialChecker() { + return new MaterialChecker_1_15(); + } +} diff --git a/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/ChestOpener_1_16.java b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/ChestOpener_1_16.java similarity index 87% rename from ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/ChestOpener_1_16.java rename to ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/ChestOpener_1_16.java index 37d3406..6f9cd71 100644 --- a/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/ChestOpener_1_16.java +++ b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/ChestOpener_1_16.java @@ -1,5 +1,6 @@ -package com.jamesdpeters.minecraft.chests; +package com.jamesdpeters.minecraft.chests.v1_16_R1; +import com.jamesdpeters.minecraft.chests.ChestOpener; import net.minecraft.server.v1_16_R1.BlockPosition; import net.minecraft.server.v1_16_R1.TileEntity; import net.minecraft.server.v1_16_R1.TileEntityChest; @@ -11,6 +12,10 @@ import org.bukkit.craftbukkit.v1_16_R1.block.CraftChest; public class ChestOpener_1_16 implements ChestOpener { + public ChestOpener_1_16(){ + System.out.println("Created ChestOpener v1.16!!"); + } + @Override public void setLidOpen(Chest chest, boolean open) { CraftChest craftChest = (CraftChest) chest; diff --git a/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/CustomTileEntityChest.java b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/CustomTileEntityChest.java similarity index 93% rename from ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/CustomTileEntityChest.java rename to ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/CustomTileEntityChest.java index 4fcddc8..58252ed 100644 --- a/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/CustomTileEntityChest.java +++ b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/CustomTileEntityChest.java @@ -1,4 +1,4 @@ -package com.jamesdpeters.minecraft.chests; +package com.jamesdpeters.minecraft.chests.v1_16_R1; import net.minecraft.server.v1_16_R1.Block; import net.minecraft.server.v1_16_R1.BlockChest; diff --git a/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_16.java b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/MaterialChecker_1_16.java similarity index 84% rename from ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_16.java rename to ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/MaterialChecker_1_16.java index cab7659..0c079dc 100644 --- a/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/MaterialChecker_1_16.java +++ b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/MaterialChecker_1_16.java @@ -1,5 +1,7 @@ -package com.jamesdpeters.minecraft.chests; +package com.jamesdpeters.minecraft.chests.v1_16_R1; +import com.jamesdpeters.minecraft.chests.MaterialChecker; +import com.jamesdpeters.minecraft.chests.v1_15_R1.MaterialChecker_1_15; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.inventory.ItemStack; @@ -37,12 +39,12 @@ public class MaterialChecker_1_16 extends MaterialChecker { } @Override - protected List graphically2DList() { + public List graphically2DList() { return materials; } @Override - protected List ignoredMaterials() { + public List ignoredMaterials() { return ignoredMaterials; } diff --git a/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/NMSProviderImpl.java b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/NMSProviderImpl.java new file mode 100644 index 0000000..88e5060 --- /dev/null +++ b/ChestsPlusPlus_1_16/src/main/java/com/jamesdpeters/minecraft/chests/v1_16_R1/NMSProviderImpl.java @@ -0,0 +1,18 @@ +package com.jamesdpeters.minecraft.chests.v1_16_R1; + +import com.jamesdpeters.minecraft.chests.ChestOpener; +import com.jamesdpeters.minecraft.chests.MaterialChecker; +import com.jamesdpeters.minecraft.chests.NMSProvider; + +public class NMSProviderImpl implements NMSProvider { + + @Override + public ChestOpener getChestOpener() { + return new ChestOpener_1_16(); + } + + @Override + public MaterialChecker getMaterialChecker() { + return new MaterialChecker_1_16(); + } +} diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java index 02efc3f..61b08f2 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/ChestsPlusPlus.java @@ -1,6 +1,6 @@ package com.jamesdpeters.minecraft.chests; -import com.jamesdpeters.minecraft.chests.api_interfaces.ApiSpecific; +import com.jamesdpeters.minecraft.chests.api.ApiSpecific; import com.jamesdpeters.minecraft.chests.commands.AutoCraftCommand; import com.jamesdpeters.minecraft.chests.commands.ChestLinkCommand; import com.jamesdpeters.minecraft.chests.commands.ChestsPlusPlusCommand; diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/ApiSpecific.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/ApiSpecific.java new file mode 100644 index 0000000..1359b5a --- /dev/null +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/ApiSpecific.java @@ -0,0 +1,29 @@ +package com.jamesdpeters.minecraft.chests.api; + +import com.jamesdpeters.minecraft.chests.API; +import com.jamesdpeters.minecraft.chests.ChestOpener; +import com.jamesdpeters.minecraft.chests.NMSProvider; +import com.jamesdpeters.minecraft.chests.MaterialChecker; +import org.bukkit.Bukkit; + + +public class ApiSpecific { + + private static MaterialChecker materialChecker; + private static ChestOpener chestOpener; + + public static void init(){ + NMSProvider nmsProvider = API.getNMSProvider(); + if(nmsProvider == null) nmsProvider = new NMSProviderDefault(); + materialChecker = nmsProvider.getMaterialChecker(); + chestOpener = nmsProvider.getChestOpener(); + } + + public static MaterialChecker getMaterialChecker() { + return materialChecker; + } + public static ChestOpener getChestOpener() { + return chestOpener; + } + public static String getApiVersion(){ return Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; } +} diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/NMSProviderDefault.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/NMSProviderDefault.java new file mode 100644 index 0000000..3911783 --- /dev/null +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/NMSProviderDefault.java @@ -0,0 +1,21 @@ +package com.jamesdpeters.minecraft.chests.api; + +import com.jamesdpeters.minecraft.chests.ChestOpener; +import com.jamesdpeters.minecraft.chests.MaterialChecker; +import com.jamesdpeters.minecraft.chests.NMSProvider; +import com.jamesdpeters.minecraft.chests.v1_16_R1.MaterialChecker_1_16; + +public class NMSProviderDefault implements NMSProvider { + @Override + public ChestOpener getChestOpener() { + return (chest, open) -> { + //Default to doing nothing. + }; + } + + @Override + public MaterialChecker getMaterialChecker() { + //Return the current latest MaterialChecker when an newer server implementation is found. + return new MaterialChecker_1_16(); + } +} diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api_interfaces/ApiSpecific.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api_interfaces/ApiSpecific.java deleted file mode 100644 index aacf27a..0000000 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api_interfaces/ApiSpecific.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.jamesdpeters.minecraft.chests.api_interfaces; - -import com.jamesdpeters.minecraft.chests.ChestOpener; -import com.jamesdpeters.minecraft.chests.ChestOpener_1_14; -import com.jamesdpeters.minecraft.chests.ChestOpener_1_15; -import com.jamesdpeters.minecraft.chests.ChestOpener_1_16; -import com.jamesdpeters.minecraft.chests.ChestsPlusPlus; -import com.jamesdpeters.minecraft.chests.MaterialChecker; -import com.jamesdpeters.minecraft.chests.MaterialChecker_1_14; -import com.jamesdpeters.minecraft.chests.MaterialChecker_1_15; -import com.jamesdpeters.minecraft.chests.MaterialChecker_1_16; -import org.bukkit.Bukkit; - -public class ApiSpecific { - - private static MaterialChecker materialChecker; - private static ChestOpener chestOpener; - private static Version version; - - public static void init(){ - version = getVersion(); - ChestsPlusPlus.PLUGIN.getLogger().info("Found API version: "+version); - materialChecker = getMaterialChecker(version); - chestOpener = getChestOpener(version); - } - - enum Version { - API_1_16, - API_1_15, - API_1_14 - } - - private static Version getVersion(){ - String version = Bukkit.getBukkitVersion().split("-")[0]; - String[] versionRevisions = version.split("\\."); - String minorVersion = versionRevisions[1]; - - //Switch minor revision number e.g 1.xx - switch (minorVersion){ - //Assume default API is latest. - default: return Version.API_1_16; - case "15": return Version.API_1_15; - case "14": return Version.API_1_14; - } - } - - private static MaterialChecker getMaterialChecker(Version version){ - switch (version){ - //Return latest version as default since only builds newer won't be present here. - default: return new MaterialChecker_1_16(); - case API_1_15: return new MaterialChecker_1_15(); - case API_1_14: return new MaterialChecker_1_14(); - } - } - - private static ChestOpener getChestOpener(Version version){ - switch (version){ - case API_1_16: return new ChestOpener_1_16(); - case API_1_15: return new ChestOpener_1_15(); - case API_1_14: return new ChestOpener_1_14(); - default: return (chest, open) -> { - //Do nothing - }; - } - } - - public static MaterialChecker getMaterialChecker() { - return materialChecker; - } - public static ChestOpener getChestOpener() { - return chestOpener; - } - public static Version getApiVersion(){ return version; } -} diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestsPlusPlusCommand.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestsPlusPlusCommand.java index d47cadd..51759f5 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestsPlusPlusCommand.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/commands/ChestsPlusPlusCommand.java @@ -1,7 +1,7 @@ package com.jamesdpeters.minecraft.chests.commands; import com.jamesdpeters.minecraft.chests.ChestsPlusPlus; -import com.jamesdpeters.minecraft.chests.api_interfaces.ApiSpecific; +import com.jamesdpeters.minecraft.chests.api.ApiSpecific; import com.jamesdpeters.minecraft.chests.maventemplates.BuildConstants; import org.bukkit.Bukkit; import org.bukkit.ChatColor; diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java index d9eb4b3..8298251 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/abstracts/AbstractStorage.java @@ -1,7 +1,7 @@ package com.jamesdpeters.minecraft.chests.storage.abstracts; import com.jamesdpeters.minecraft.chests.ChestsPlusPlus; -import com.jamesdpeters.minecraft.chests.api_interfaces.ApiSpecific; +import com.jamesdpeters.minecraft.chests.api.ApiSpecific; import com.jamesdpeters.minecraft.chests.misc.Permissions; import com.jamesdpeters.minecraft.chests.misc.Values; import com.jamesdpeters.minecraft.chests.serialize.LocationInfo;