Added nms mappings check before loading the plugin

This commit is contained in:
OmerBenGera 2022-08-04 23:45:23 +03:00
parent 5eeb714145
commit 88f444de1a
10 changed files with 58 additions and 0 deletions

View File

@ -93,6 +93,10 @@ public final class WildLoadersPlugin extends JavaPlugin implements WildLoaders {
String version = getServer().getClass().getPackage().getName().split("\\.")[3];
try {
nmsAdapter = (NMSAdapter) Class.forName(String.format("com.bgsoftware.wildloaders.nms.%s.NMSAdapter", version)).newInstance();
if (!nmsAdapter.isMappingsSupported()) {
log("WildLoaders does not support your version mappings... Please contact @Ome_R");
shouldEnable = false;
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
shouldEnable = false;
log("Couldn't load up with an adapter " + version + ". Please contact @Ome_R");

View File

@ -10,6 +10,8 @@ import java.util.UUID;
public interface NMSAdapter {
boolean isMappingsSupported();
String getTag(ItemStack itemStack, String key, String def);
ItemStack setTag(ItemStack itemStack, String key, String value);

View File

@ -31,6 +31,11 @@ public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapt
private static final ReflectMethod<Void> TILE_ENTITY_LOAD = new ReflectMethod<>(TileEntity.class, "load", NBTTagCompound.class);
@Override
public boolean isMappingsSupported() {
return true;
}
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);

View File

@ -29,6 +29,11 @@ public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapt
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public boolean isMappingsSupported() {
return true;
}
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);

View File

@ -27,6 +27,7 @@ import org.bukkit.craftbukkit.v1_17_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers;
import java.util.UUID;
@ -38,6 +39,13 @@ public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapt
private static final ReflectMethod<TickingBlockEntity> CREATE_TICKING_BLOCK = new ReflectMethod<>(
Chunk.class, "a", TileEntity.class, BlockEntityTicker.class);
private static final String BUILT_AGAINST_MAPPING = "acd6e6c27e5a0a9440afba70a96c27c9";
@Override
public boolean isMappingsSupported() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals(BUILT_AGAINST_MAPPING);
}
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);

View File

@ -26,6 +26,7 @@ import org.bukkit.craftbukkit.v1_18_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_18_R1.CraftServer;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_18_R1.util.CraftMagicNumbers;
import java.util.UUID;
@ -39,6 +40,13 @@ public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapt
net.minecraft.world.level.chunk.Chunk.class, "a",
net.minecraft.world.level.block.entity.TileEntity.class, BlockEntityTicker.class);
private static final String BUILT_AGAINST_MAPPING = "20b026e774dbf715e40a0b2afe114792";
@Override
public boolean isMappingsSupported() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals(BUILT_AGAINST_MAPPING);
}
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack));

View File

@ -26,6 +26,7 @@ import org.bukkit.craftbukkit.v1_18_R2.CraftChunk;
import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_18_R2.util.CraftMagicNumbers;
import java.util.UUID;
@ -39,6 +40,13 @@ public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapt
net.minecraft.world.level.chunk.Chunk.class, "a",
net.minecraft.world.level.block.entity.TileEntity.class, BlockEntityTicker.class);
private static final String BUILT_AGAINST_MAPPING = "eaeedbff51b16ead3170906872fda334";
@Override
public boolean isMappingsSupported() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals(BUILT_AGAINST_MAPPING);
}
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack));

View File

@ -26,6 +26,7 @@ import org.bukkit.craftbukkit.v1_19_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_19_R1.util.CraftMagicNumbers;
import java.util.UUID;
@ -39,6 +40,13 @@ public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapt
net.minecraft.world.level.chunk.Chunk.class, "a",
net.minecraft.world.level.block.entity.TileEntity.class, BlockEntityTicker.class);
private static final String BUILT_AGAINST_MAPPING = "4cc0cc97cac491651bff3af8b124a214";
@Override
public boolean isMappingsSupported() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals(BUILT_AGAINST_MAPPING);
}
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = new ItemStack(CraftItemStack.asNMSCopy(itemStack));

View File

@ -27,6 +27,11 @@ public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapt
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public boolean isMappingsSupported() {
return true;
}
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);

View File

@ -27,6 +27,11 @@ public final class NMSAdapter implements com.bgsoftware.wildloaders.nms.NMSAdapt
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
@Override
public boolean isMappingsSupported() {
return true;
}
@Override
public String getTag(org.bukkit.inventory.ItemStack itemStack, String key, String def) {
ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);