mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-02-16 02:20:44 +00:00
fixes to nexo support
This commit is contained in:
@@ -20,6 +20,8 @@ import org.bukkit.entity.ItemDisplay;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@@ -27,6 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
public class NexoDataProvider extends ExternalDataProvider {
|
public class NexoDataProvider extends ExternalDataProvider {
|
||||||
private final AtomicBoolean failed = new AtomicBoolean(false);
|
private final AtomicBoolean failed = new AtomicBoolean(false);
|
||||||
private WrappedReturningMethod<?, String[]> itemNames;
|
private WrappedReturningMethod<?, String[]> itemNames;
|
||||||
|
private WrappedReturningMethod<?, Object> itemFromId;
|
||||||
private WrappedReturningMethod<?, Boolean> exists;
|
private WrappedReturningMethod<?, Boolean> exists;
|
||||||
|
|
||||||
private WrappedReturningMethod<?, Boolean> isCustomBlock;
|
private WrappedReturningMethod<?, Boolean> isCustomBlock;
|
||||||
@@ -34,9 +37,7 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
|
|
||||||
private WrappedReturningMethod<?, BlockData> getBlockData;
|
private WrappedReturningMethod<?, BlockData> getBlockData;
|
||||||
private WrappedReturningMethod<?, ItemDisplay> placeFurniture;
|
private WrappedReturningMethod<?, ItemDisplay> placeFurniture;
|
||||||
|
private WrappedReturningMethod<?, ?> placeBlock;
|
||||||
private WrappedReturningMethod<?, Object> itemFromId;
|
|
||||||
private WrappedReturningMethod<?, ItemStack> buildItem;
|
|
||||||
|
|
||||||
public NexoDataProvider() {
|
public NexoDataProvider() {
|
||||||
super("Nexo");
|
super("Nexo");
|
||||||
@@ -48,19 +49,17 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
Class<?> nexoItems = Class.forName("com.nexomc.nexo.api.NexoItems");
|
Class<?> nexoItems = Class.forName("com.nexomc.nexo.api.NexoItems");
|
||||||
Class<?> nexoBlocks = Class.forName("com.nexomc.nexo.api.NexoBlocks");
|
Class<?> nexoBlocks = Class.forName("com.nexomc.nexo.api.NexoBlocks");
|
||||||
Class<?> nexoFurniture = Class.forName("com.nexomc.nexo.api.NexoFurniture");
|
Class<?> nexoFurniture = Class.forName("com.nexomc.nexo.api.NexoFurniture");
|
||||||
Class<?> itemBuilder = Class.forName("com.nexomc.nexo.items.ItemBuilder");
|
|
||||||
|
|
||||||
itemNames = new WrappedReturningMethod<>(nexoItems, "itemNames");
|
itemNames = new WrappedReturningMethod<>(nexoItems, "itemNames");
|
||||||
exists = new WrappedReturningMethod<>(nexoItems, "exists", String.class);
|
exists = new WrappedReturningMethod<>(nexoItems, "exists", String.class);
|
||||||
|
itemFromId = new WrappedReturningMethod<>(nexoItems, "itemFromId", String.class);
|
||||||
|
|
||||||
isCustomBlock = new WrappedReturningMethod<>(nexoBlocks, "isCustomBlock", String.class);
|
isCustomBlock = new WrappedReturningMethod<>(nexoBlocks, "isCustomBlock", String.class);
|
||||||
isFurniture = new WrappedReturningMethod<>(nexoFurniture, "isFurniture", String.class);
|
isFurniture = new WrappedReturningMethod<>(nexoFurniture, "isFurniture", String.class);
|
||||||
|
|
||||||
getBlockData = new WrappedReturningMethod<>(nexoBlocks, "blockData", String.class);
|
getBlockData = new WrappedReturningMethod<>(nexoBlocks, "blockData", String.class);
|
||||||
placeFurniture = new WrappedReturningMethod<>(nexoFurniture, "place", String.class, Location.class, float.class, BlockFace.class);
|
placeFurniture = new WrappedReturningMethod<>(nexoFurniture, "place", String.class, Location.class, float.class, BlockFace.class);
|
||||||
|
placeBlock = new WrappedReturningMethod<>(nexoBlocks, "place", String.class, Location.class);
|
||||||
itemFromId = new WrappedReturningMethod<>(nexoItems, "itemFromId", String.class);
|
|
||||||
buildItem = new WrappedReturningMethod<>(itemBuilder, "build");
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
failed.set(true);
|
failed.set(true);
|
||||||
Iris.error("Failed to initialize NexoDataProvider");
|
Iris.error("Failed to initialize NexoDataProvider");
|
||||||
@@ -74,10 +73,11 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Identifier blockState = ExternalDataSVC.buildState(blockId, state);
|
||||||
if (isCustomBlock.invoke(blockId.key())) {
|
if (isCustomBlock.invoke(blockId.key())) {
|
||||||
return getBlockData.invoke(blockId.key());
|
return new IrisBlockData(getBlockData.invoke(blockId.key()), blockState);
|
||||||
} else if (isFurniture.invoke(blockId.key())) {
|
} else if (isFurniture.invoke(blockId.key())) {
|
||||||
return new IrisBlockData(B.getAir(), ExternalDataSVC.buildState(blockId, state));
|
return new IrisBlockData(B.getAir(), blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
@@ -89,7 +89,8 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
if (o == null) {
|
if (o == null) {
|
||||||
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
||||||
}
|
}
|
||||||
ItemStack itemStack = buildItem.invoke(o, new Object[0]);
|
ItemBuilder builder = newProxy(o);
|
||||||
|
ItemStack itemStack = builder.build();
|
||||||
if (itemStack == null) {
|
if (itemStack == null) {
|
||||||
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
||||||
}
|
}
|
||||||
@@ -102,6 +103,11 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
var state = pair.getB();
|
var state = pair.getB();
|
||||||
blockId = pair.getA();
|
blockId = pair.getA();
|
||||||
|
|
||||||
|
if (isCustomBlock.invoke(blockId.key())) {
|
||||||
|
placeBlock.invoke(blockId.key(), block.getLocation());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isFurniture.invoke(blockId.key()))
|
if (!isFurniture.invoke(blockId.key()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -184,4 +190,15 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
public boolean isReady() {
|
public boolean isReady() {
|
||||||
return super.isReady() && !failed.get();
|
return super.isReady() && !failed.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ItemBuilder newProxy(Object instance) {
|
||||||
|
return (ItemBuilder) Proxy.newProxyInstance(
|
||||||
|
NexoDataProvider.class.getClassLoader(),
|
||||||
|
new Class[]{ItemBuilder.class},
|
||||||
|
(proxy, method, args) -> method.invoke(instance, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface ItemBuilder {
|
||||||
|
@Nullable ItemStack build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user