mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2024-11-25 12:06:09 +01:00
Changed NMS Method.
Calls to newer NMS not possible from Core now.
This commit is contained in:
parent
6897c7321d
commit
9fc4ebdd13
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,13 +15,13 @@ public abstract class MaterialChecker {
|
||||
* @return
|
||||
* List of Materials.
|
||||
*/
|
||||
protected abstract List<Material> graphically2DList();
|
||||
public abstract List<Material> graphically2DList();
|
||||
|
||||
/**
|
||||
* List of @{@link Material} that gets ignored (Beds are a pain).
|
||||
* @return
|
||||
*/
|
||||
protected abstract List<Material> ignoredMaterials();
|
||||
public abstract List<Material> ignoredMaterials();
|
||||
|
||||
/**
|
||||
* This returns true if an item is held like a pickaxe/sword etc.
|
||||
|
@ -0,0 +1,6 @@
|
||||
package com.jamesdpeters.minecraft.chests;
|
||||
|
||||
public interface NMSProvider {
|
||||
ChestOpener getChestOpener();
|
||||
MaterialChecker getMaterialChecker();
|
||||
}
|
@ -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;
|
@ -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;
|
@ -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<Material> graphically2DList() {
|
||||
public List<Material> graphically2DList() {
|
||||
return version_1_14_Items;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Material> ignoredMaterials() {
|
||||
public List<Material> ignoredMaterials() {
|
||||
return version_1_14_Ignored_Items;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
@ -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;
|
@ -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<Material> graphically2DList() {
|
||||
public List<Material> graphically2DList() {
|
||||
return materials;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Material> ignoredMaterials() {
|
||||
public List<Material> ignoredMaterials() {
|
||||
return ignoredMaterials;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
@ -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;
|
@ -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<Material> graphically2DList() {
|
||||
public List<Material> graphically2DList() {
|
||||
return materials;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Material> ignoredMaterials() {
|
||||
public List<Material> ignoredMaterials() {
|
||||
return ignoredMaterials;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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]; }
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user