Fix adapter backwards compatiblity (and getHolder loading 🙈)

This commit is contained in:
Phoenix616 2021-01-28 17:33:40 +01:00
parent 65df4c40c6
commit 320d9ad9fb
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
1 changed files with 7 additions and 7 deletions

View File

@ -1,7 +1,5 @@
package com.Acrobot.Breeze.Utils;
import com.Acrobot.Breeze.Utils.ImplementationFeatures.PaperLatestHolder;
import com.Acrobot.Breeze.Utils.ImplementationFeatures.PaperLatestState;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.inventory.Inventory;
@ -16,15 +14,17 @@ public class ImplementationAdapter {
static {
try {
InventoryHolder.class.getMethod("getHolder", boolean.class);
HOLDER_PROVIDER = PaperLatestHolder.PROVIDER;
} catch (NoSuchMethodException e) {
Inventory.class.getMethod("getHolder", boolean.class);
Class c = Class.forName("com.Acrobot.Breeze.Utils.ImplementationFeatures.PaperLatestHolder");
HOLDER_PROVIDER = (BiFunction<Inventory, Boolean, InventoryHolder>) c.getDeclaredField("PROVIDER").get(null);
} catch (NoSuchMethodException | ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
HOLDER_PROVIDER = (inventory, useSnapshot) -> inventory.getHolder();
}
try {
Block.class.getMethod("getState", boolean.class);
STATE_PROVIDER = PaperLatestState.PROVIDER;
} catch (NoSuchMethodException e) {
Class c = Class.forName("com.Acrobot.Breeze.Utils.ImplementationFeatures.PaperLatestState");
STATE_PROVIDER = (BiFunction<Block, Boolean, BlockState>) c.getDeclaredField("PROVIDER").get(null);
} catch (NoSuchMethodException | ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
STATE_PROVIDER = (block, useSnapshot) -> block.getState();
}
}