mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-08-16 16:26:12 +00:00
make the mythic mobs link a data provider and make adding custom mob plugins easier
This commit is contained in:
parent
a9891e819a
commit
9ade90d9ca
@ -25,7 +25,6 @@ import com.volmit.iris.core.IrisSettings;
|
|||||||
import com.volmit.iris.core.ServerConfigurator;
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.link.IrisPapiExpansion;
|
import com.volmit.iris.core.link.IrisPapiExpansion;
|
||||||
import com.volmit.iris.core.link.MultiverseCoreLink;
|
import com.volmit.iris.core.link.MultiverseCoreLink;
|
||||||
import com.volmit.iris.core.link.MythicMobsLink;
|
|
||||||
import com.volmit.iris.core.loader.IrisData;
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
import com.volmit.iris.core.nms.v1X.NMSBinding1X;
|
import com.volmit.iris.core.nms.v1X.NMSBinding1X;
|
||||||
@ -95,7 +94,6 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
public static Iris instance;
|
public static Iris instance;
|
||||||
public static Bindings.Adventure audiences;
|
public static Bindings.Adventure audiences;
|
||||||
public static MultiverseCoreLink linkMultiverseCore;
|
public static MultiverseCoreLink linkMultiverseCore;
|
||||||
public static MythicMobsLink linkMythicMobs;
|
|
||||||
public static IrisCompat compat;
|
public static IrisCompat compat;
|
||||||
public static FileWatcher configWatcher;
|
public static FileWatcher configWatcher;
|
||||||
private static VolmitSender sender;
|
private static VolmitSender sender;
|
||||||
@ -454,7 +452,6 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
getSender().setTag(getTag());
|
getSender().setTag(getTag());
|
||||||
IrisSafeguard.splash(true);
|
IrisSafeguard.splash(true);
|
||||||
linkMultiverseCore = new MultiverseCoreLink();
|
linkMultiverseCore = new MultiverseCoreLink();
|
||||||
linkMythicMobs = new MythicMobsLink();
|
|
||||||
configWatcher = new FileWatcher(getDataFile("settings.json"));
|
configWatcher = new FileWatcher(getDataFile("settings.json"));
|
||||||
services.values().forEach(IrisService::onEnable);
|
services.values().forEach(IrisService::onEnable);
|
||||||
services.values().forEach(this::registerListener);
|
services.values().forEach(this::registerListener);
|
||||||
|
@ -1,24 +1,33 @@
|
|||||||
package com.volmit.iris.core.link;
|
package com.volmit.iris.core.link;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.link.data.DataType;
|
||||||
|
import com.volmit.iris.core.nms.container.Pair;
|
||||||
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.data.IrisCustomData;
|
import com.volmit.iris.util.data.IrisCustomData;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public abstract class ExternalDataProvider {
|
public abstract class ExternalDataProvider implements Listener {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final String pluginId;
|
private final String pluginId;
|
||||||
@ -53,7 +62,9 @@ public abstract class ExternalDataProvider {
|
|||||||
* @throws MissingResourceException when the blockId is invalid
|
* @throws MissingResourceException when the blockId is invalid
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public abstract BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException;
|
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
||||||
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ExternalDataProvider#getItemStack(Identifier)
|
* @see ExternalDataProvider#getItemStack(Identifier)
|
||||||
@ -73,7 +84,9 @@ public abstract class ExternalDataProvider {
|
|||||||
* @throws MissingResourceException when the itemId is invalid
|
* @throws MissingResourceException when the itemId is invalid
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public abstract ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException;
|
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
|
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is used for placing blocks that need to use the plugins api
|
* This method is used for placing blocks that need to use the plugins api
|
||||||
@ -85,9 +98,43 @@ public abstract class ExternalDataProvider {
|
|||||||
*/
|
*/
|
||||||
public void processUpdate(@NotNull Engine engine, @NotNull Block block, @NotNull Identifier blockId) {}
|
public void processUpdate(@NotNull Engine engine, @NotNull Block block, @NotNull Identifier blockId) {}
|
||||||
|
|
||||||
public abstract @NotNull Identifier[] getBlockTypes();
|
/**
|
||||||
|
* Spawns a mob in the specified location using the given engine and entity identifier.
|
||||||
|
*
|
||||||
|
* @param location The location in the world where the mob should spawn. Must not be null.
|
||||||
|
* @param entityId The identifier of the mob entity to spawn. Must not be null.
|
||||||
|
* @return The spawned {@link Entity} if successful, or null if the mob could not be spawned.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Entity spawnMob(@NotNull Location location, @NotNull Identifier entityId) throws MissingResourceException {
|
||||||
|
throw new MissingResourceException("Failed to find Entity!", entityId.namespace(), entityId.key());
|
||||||
|
}
|
||||||
|
|
||||||
public abstract @NotNull Identifier[] getItemTypes();
|
public abstract @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType);
|
||||||
|
|
||||||
public abstract boolean isValidProvider(@NotNull Identifier id, boolean isItem);
|
public abstract boolean isValidProvider(@NotNull Identifier id, DataType dataType);
|
||||||
|
|
||||||
|
protected static Pair<Float, BlockFace> parseYawAndFace(@NotNull Engine engine, @NotNull Block block, @NotNull KMap<@NotNull String, @NotNull String> state) {
|
||||||
|
float yaw = 0;
|
||||||
|
BlockFace face = BlockFace.NORTH;
|
||||||
|
|
||||||
|
long seed = engine.getSeedManager().getSeed() + Cache.key(block.getX(), block.getZ()) + block.getY();
|
||||||
|
RNG rng = new RNG(seed);
|
||||||
|
if ("true".equals(state.get("randomYaw"))) {
|
||||||
|
yaw = rng.f(0, 360);
|
||||||
|
} else if (state.containsKey("yaw")) {
|
||||||
|
yaw = Float.parseFloat(state.get("yaw"));
|
||||||
|
}
|
||||||
|
if ("true".equals(state.get("randomFace"))) {
|
||||||
|
BlockFace[] faces = BlockFace.values();
|
||||||
|
face = faces[rng.i(0, faces.length - 1)];
|
||||||
|
} else if (state.containsKey("face")) {
|
||||||
|
face = BlockFace.valueOf(state.get("face").toUpperCase());
|
||||||
|
}
|
||||||
|
if (face == BlockFace.SELF) {
|
||||||
|
face = BlockFace.NORTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Pair<>(yaw, face);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.volmit.iris.core.link.data;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.link.ExternalDataProvider;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
|
|
||||||
|
import java.util.MissingResourceException;
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public enum DataType implements BiPredicate<ExternalDataProvider, Identifier> {
|
||||||
|
ITEM,
|
||||||
|
BLOCK,
|
||||||
|
ENTITY;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean test(ExternalDataProvider dataProvider, Identifier identifier) {
|
||||||
|
if (!dataProvider.isValidProvider(identifier, this)) return false;
|
||||||
|
try {
|
||||||
|
switch (this) {
|
||||||
|
case ITEM -> dataProvider.getItemStack(identifier);
|
||||||
|
case BLOCK -> dataProvider.getBlockData(identifier);
|
||||||
|
case ENTITY -> {}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (MissingResourceException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Predicate<Identifier> asPredicate(ExternalDataProvider dataProvider) {
|
||||||
|
return i -> test(dataProvider, i);
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,18 @@
|
|||||||
package com.volmit.iris.core.link;
|
package com.volmit.iris.core.link.data;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.core.link.ExternalDataProvider;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.reflect.WrappedField;
|
import com.volmit.iris.util.reflect.WrappedField;
|
||||||
import com.willfp.ecoitems.items.EcoItem;
|
import com.willfp.ecoitems.items.EcoItem;
|
||||||
import com.willfp.ecoitems.items.EcoItems;
|
import com.willfp.ecoitems.items.EcoItems;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
|
|
||||||
public class EcoItemsDataProvider extends ExternalDataProvider {
|
public class EcoItemsDataProvider extends ExternalDataProvider {
|
||||||
@ -34,12 +36,6 @@ public class EcoItemsDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
|
||||||
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
@ -48,30 +44,18 @@ public class EcoItemsDataProvider extends ExternalDataProvider {
|
|||||||
return itemStack.get(item).clone();
|
return itemStack.get(item).clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) {
|
||||||
return new Identifier[0];
|
if (dataType != DataType.ITEM) return List.of();
|
||||||
}
|
return EcoItems.INSTANCE.values()
|
||||||
|
.stream()
|
||||||
@NotNull
|
.map(x -> Identifier.fromNamespacedKey(id.get(x)))
|
||||||
@Override
|
.filter(dataType.asPredicate(this))
|
||||||
public Identifier[] getItemTypes() {
|
.toList();
|
||||||
KList<Identifier> names = new KList<>();
|
|
||||||
for (EcoItem item : EcoItems.INSTANCE.values()) {
|
|
||||||
try {
|
|
||||||
Identifier key = Identifier.fromNamespacedKey(id.get(item));
|
|
||||||
if (getItemStack(key) != null)
|
|
||||||
names.add(key);
|
|
||||||
} catch (MissingResourceException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return names.toArray(new Identifier[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidProvider(@NotNull Identifier id, boolean isItem) {
|
public boolean isValidProvider(@NotNull Identifier id, DataType dataType) {
|
||||||
return id.namespace().equalsIgnoreCase("ecoitems") && isItem;
|
return id.namespace().equalsIgnoreCase("ecoitems") && dataType == DataType.ITEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,13 +1,15 @@
|
|||||||
package com.volmit.iris.core.link;
|
package com.volmit.iris.core.link.data;
|
||||||
|
|
||||||
import com.ssomar.score.api.executableitems.ExecutableItemsAPI;
|
import com.ssomar.score.api.executableitems.ExecutableItemsAPI;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.core.link.ExternalDataProvider;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -21,12 +23,6 @@ public class ExecutableItemsDataProvider extends ExternalDataProvider {
|
|||||||
Iris.info("Setting up ExecutableItems Link...");
|
Iris.info("Setting up ExecutableItems Link...");
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
|
||||||
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
@ -35,30 +31,19 @@ public class ExecutableItemsDataProvider extends ExternalDataProvider {
|
|||||||
.orElseThrow(() -> new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key()));
|
.orElseThrow(() -> new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) {
|
||||||
return new Identifier[0];
|
if (dataType != DataType.ITEM) return List.of();
|
||||||
}
|
return ExecutableItemsAPI.getExecutableItemsManager()
|
||||||
|
.getExecutableItemIdsList()
|
||||||
@NotNull
|
.stream()
|
||||||
@Override
|
.map(name -> new Identifier("executable_items", name))
|
||||||
public Identifier[] getItemTypes() {
|
.filter(dataType.asPredicate(this))
|
||||||
KList<Identifier> names = new KList<>();
|
.toList();
|
||||||
for (String name : ExecutableItemsAPI.getExecutableItemsManager().getExecutableItemIdsList()) {
|
|
||||||
try {
|
|
||||||
Identifier key = new Identifier("executable_items", name);
|
|
||||||
if (getItemStack(key) != null)
|
|
||||||
names.add(key);
|
|
||||||
} catch (MissingResourceException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return names.toArray(new Identifier[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidProvider(@NotNull Identifier key, boolean isItem) {
|
public boolean isValidProvider(@NotNull Identifier key, DataType dataType) {
|
||||||
return key.namespace().equalsIgnoreCase("executable_items") && isItem;
|
return key.namespace().equalsIgnoreCase("executable_items") && dataType == DataType.ITEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,11 @@
|
|||||||
package com.volmit.iris.core.link;
|
package com.volmit.iris.core.link.data;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.IrisSettings;
|
import com.volmit.iris.core.IrisSettings;
|
||||||
|
import com.volmit.iris.core.link.ExternalDataProvider;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
import com.volmit.iris.core.service.ExternalDataSVC;
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.util.collection.KList;
|
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.data.IrisCustomData;
|
import com.volmit.iris.util.data.IrisCustomData;
|
||||||
import com.volmit.iris.util.reflect.WrappedField;
|
import com.volmit.iris.util.reflect.WrappedField;
|
||||||
@ -18,6 +19,8 @@ import org.bukkit.block.data.type.Leaves;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@ -89,41 +92,20 @@ public class HMCLeavesDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) {
|
||||||
KList<Identifier> names = new KList<>();
|
if (dataType == DataType.ENTITY) return List.of();
|
||||||
for (String name : blockDataMap.keySet()) {
|
return (dataType == DataType.BLOCK ? blockDataMap.keySet() : itemDataField.keySet())
|
||||||
try {
|
.stream()
|
||||||
Identifier key = new Identifier("hmcleaves", name);
|
.map(x -> new Identifier("hmcleaves", x))
|
||||||
if (getBlockData(key) != null)
|
.filter(dataType.asPredicate(this))
|
||||||
names.add(key);
|
.toList();
|
||||||
} catch (MissingResourceException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return names.toArray(new Identifier[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Identifier[] getItemTypes() {
|
|
||||||
KList<Identifier> names = new KList<>();
|
|
||||||
for (String name : itemDataField.keySet()) {
|
|
||||||
try {
|
|
||||||
Identifier key = new Identifier("hmcleaves", name);
|
|
||||||
if (getItemStack(key) != null)
|
|
||||||
names.add(key);
|
|
||||||
} catch (MissingResourceException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return names.toArray(new Identifier[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidProvider(@NotNull Identifier id, boolean isItem) {
|
public boolean isValidProvider(@NotNull Identifier id, DataType dataType) {
|
||||||
return (isItem ? itemDataField.keySet() : blockDataMap.keySet()).contains(id.key());
|
if (dataType == DataType.ENTITY) return false;
|
||||||
|
return (dataType == DataType.ITEM ? itemDataField.keySet() : blockDataMap.keySet()).contains(id.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
private <C, T> Map<String, T> getMap(C config, String name) {
|
private <C, T> Map<String, T> getMap(C config, String name) {
|
@ -1,76 +1,76 @@
|
|||||||
package com.volmit.iris.core.link;
|
package com.volmit.iris.core.link.data;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.core.link.ExternalDataProvider;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.core.link.Identifier;
|
||||||
import dev.lone.itemsadder.api.CustomBlock;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import dev.lone.itemsadder.api.CustomStack;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import org.bukkit.block.data.BlockData;
|
import dev.lone.itemsadder.api.CustomBlock;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import dev.lone.itemsadder.api.CustomStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import java.util.MissingResourceException;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ItemAdderDataProvider extends ExternalDataProvider {
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
private KList<String> itemNamespaces, blockNamespaces;
|
import java.util.MissingResourceException;
|
||||||
|
|
||||||
public ItemAdderDataProvider() {
|
public class ItemAdderDataProvider extends ExternalDataProvider {
|
||||||
super("ItemsAdder");
|
|
||||||
}
|
private KList<String> itemNamespaces, blockNamespaces;
|
||||||
|
|
||||||
@Override
|
public ItemAdderDataProvider() {
|
||||||
public void init() {
|
super("ItemsAdder");
|
||||||
this.itemNamespaces = new KList<>();
|
}
|
||||||
this.blockNamespaces = new KList<>();
|
|
||||||
|
@Override
|
||||||
for (Identifier i : getItemTypes()) {
|
public void init() {
|
||||||
itemNamespaces.addIfMissing(i.namespace());
|
this.itemNamespaces = new KList<>();
|
||||||
}
|
this.blockNamespaces = new KList<>();
|
||||||
for (Identifier i : getBlockTypes()) {
|
|
||||||
blockNamespaces.addIfMissing(i.namespace());
|
for (Identifier i : getTypes(DataType.ITEM)) {
|
||||||
Iris.info("Found ItemAdder Block: " + i);
|
itemNamespaces.addIfMissing(i.namespace());
|
||||||
}
|
}
|
||||||
}
|
for (Identifier i : getTypes(DataType.BLOCK)) {
|
||||||
|
blockNamespaces.addIfMissing(i.namespace());
|
||||||
@NotNull
|
Iris.info("Found ItemAdder Block: " + i);
|
||||||
@Override
|
}
|
||||||
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
}
|
||||||
return CustomBlock.getBaseBlockData(blockId.toString());
|
|
||||||
}
|
@NotNull
|
||||||
|
@Override
|
||||||
@NotNull
|
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
||||||
@Override
|
return CustomBlock.getBaseBlockData(blockId.toString());
|
||||||
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
}
|
||||||
CustomStack stack = CustomStack.getInstance(itemId.toString());
|
|
||||||
if (stack == null) {
|
@NotNull
|
||||||
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
@Override
|
||||||
}
|
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
return stack.getItemStack();
|
CustomStack stack = CustomStack.getInstance(itemId.toString());
|
||||||
}
|
if (stack == null) {
|
||||||
|
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
||||||
@NotNull
|
}
|
||||||
@Override
|
return stack.getItemStack();
|
||||||
public Identifier[] getBlockTypes() {
|
}
|
||||||
KList<Identifier> keys = new KList<>();
|
|
||||||
for (String s : CustomBlock.getNamespacedIdsInRegistry()) {
|
@Override
|
||||||
keys.add(Identifier.fromString(s));
|
public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) {
|
||||||
}
|
return switch (dataType) {
|
||||||
return keys.toArray(new Identifier[0]);
|
case ENTITY -> List.of();
|
||||||
}
|
case ITEM -> CustomStack.getNamespacedIdsInRegistry()
|
||||||
|
.stream()
|
||||||
@NotNull
|
.map(Identifier::fromString)
|
||||||
@Override
|
.toList();
|
||||||
public Identifier[] getItemTypes() {
|
case BLOCK -> CustomBlock.getNamespacedIdsInRegistry()
|
||||||
KList<Identifier> keys = new KList<>();
|
.stream()
|
||||||
for (String s : CustomStack.getNamespacedIdsInRegistry()) {
|
.map(Identifier::fromString)
|
||||||
keys.add(Identifier.fromString(s));
|
.toList();
|
||||||
}
|
};
|
||||||
return keys.toArray(new Identifier[0]);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public boolean isValidProvider(@NotNull Identifier id, DataType dataType) {
|
||||||
public boolean isValidProvider(@NotNull Identifier id, boolean isItem) {
|
if (dataType == DataType.ENTITY) return false;
|
||||||
return isItem ? this.itemNamespaces.contains(id.namespace()) : this.blockNamespaces.contains(id.namespace());
|
return dataType == DataType.ITEM ? this.itemNamespaces.contains(id.namespace()) : this.blockNamespaces.contains(id.namespace());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package com.volmit.iris.core.link;
|
package com.volmit.iris.core.link.data;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.link.ExternalDataProvider;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
import com.volmit.iris.core.service.ExternalDataSVC;
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
@ -14,6 +16,8 @@ import org.bukkit.block.data.BlockData;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
|
|
||||||
public class KGeneratorsDataProvider extends ExternalDataProvider {
|
public class KGeneratorsDataProvider extends ExternalDataProvider {
|
||||||
@ -54,35 +58,17 @@ public class KGeneratorsDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Identifier[] getBlockTypes() {
|
public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) {
|
||||||
|
if (dataType == DataType.ENTITY) return List.of();
|
||||||
return Main.getGenerators().getAll().stream()
|
return Main.getGenerators().getAll().stream()
|
||||||
.map(gen -> new Identifier("kgenerators", gen.getId()))
|
.map(gen -> new Identifier("kgenerators", gen.getId()))
|
||||||
.filter(i -> {
|
.filter(dataType.asPredicate(this))
|
||||||
try {
|
.toList();
|
||||||
return getBlockData(i) != null;
|
|
||||||
} catch (MissingResourceException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.toArray(Identifier[]::new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Identifier[] getItemTypes() {
|
public boolean isValidProvider(@NotNull Identifier id, DataType dataType) {
|
||||||
return Main.getGenerators().getAll().stream()
|
if (dataType == DataType.ENTITY) return false;
|
||||||
.map(gen -> new Identifier("kgenerators", gen.getId()))
|
|
||||||
.filter(i -> {
|
|
||||||
try {
|
|
||||||
return getItemStack(i) != null;
|
|
||||||
} catch (MissingResourceException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.toArray(Identifier[]::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValidProvider(@NotNull Identifier id, boolean isItem) {
|
|
||||||
return "kgenerators".equalsIgnoreCase(id.namespace());
|
return "kgenerators".equalsIgnoreCase(id.namespace());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,21 +1,24 @@
|
|||||||
package com.volmit.iris.core.link;
|
package com.volmit.iris.core.link.data;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.core.link.ExternalDataProvider;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import net.Indyuce.mmoitems.api.ItemTier;
|
import net.Indyuce.mmoitems.api.ItemTier;
|
||||||
import net.Indyuce.mmoitems.api.Type;
|
|
||||||
import net.Indyuce.mmoitems.api.block.CustomBlock;
|
import net.Indyuce.mmoitems.api.block.CustomBlock;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class MMOItemsDataProvider extends ExternalDataProvider {
|
public class MMOItemsDataProvider extends ExternalDataProvider {
|
||||||
|
|
||||||
@ -85,52 +88,35 @@ public class MMOItemsDataProvider extends ExternalDataProvider {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) {
|
||||||
KList<Identifier> names = new KList<>();
|
return switch (dataType) {
|
||||||
for (Integer id : api().getCustomBlocks().getBlockIds()) {
|
case ENTITY -> List.of();
|
||||||
try {
|
case BLOCK -> api().getCustomBlocks().getBlockIds().stream().map(id -> new Identifier("mmoitems", String.valueOf(id)))
|
||||||
Identifier key = new Identifier("mmoitems", String.valueOf(id));
|
.filter(dataType.asPredicate(this))
|
||||||
if (getBlockData(key) != null)
|
.toList();
|
||||||
names.add(key);
|
case ITEM -> {
|
||||||
} catch (MissingResourceException ignored) {
|
Supplier<Collection<Identifier>> supplier = () -> api().getTypes()
|
||||||
}
|
.getAll()
|
||||||
}
|
.stream()
|
||||||
return names.toArray(new Identifier[0]);
|
.flatMap(type -> api()
|
||||||
}
|
.getTemplates()
|
||||||
|
.getTemplateNames(type)
|
||||||
|
.stream()
|
||||||
|
.map(name -> new Identifier("mmoitems_" + type.getId(), name)))
|
||||||
|
.filter(dataType.asPredicate(this))
|
||||||
|
.toList();
|
||||||
|
|
||||||
@NotNull
|
if (Bukkit.isPrimaryThread()) yield supplier.get();
|
||||||
@Override
|
else yield J.sfut(supplier).join();
|
||||||
public Identifier[] getItemTypes() {
|
|
||||||
KList<Identifier> names = new KList<>();
|
|
||||||
Runnable run = () -> {
|
|
||||||
for (Type type : api().getTypes().getAll()) {
|
|
||||||
for (String name : api().getTemplates().getTemplateNames(type)) {
|
|
||||||
try {
|
|
||||||
Identifier key = new Identifier("mmoitems_" + type.getId(), name);
|
|
||||||
if (getItemStack(key) != null)
|
|
||||||
names.add(key);
|
|
||||||
} catch (MissingResourceException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (Bukkit.isPrimaryThread()) run.run();
|
|
||||||
else {
|
|
||||||
try {
|
|
||||||
J.sfut(run).get();
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
Iris.error("Failed getting MMOItems item types!");
|
|
||||||
Iris.reportError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return names.toArray(new Identifier[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidProvider(@NotNull Identifier id, boolean isItem) {
|
public boolean isValidProvider(@NotNull Identifier id, DataType dataType) {
|
||||||
return isItem ? id.namespace().split("_", 2).length == 2 : id.namespace().equals("mmoitems");
|
if (dataType == DataType.ENTITY) return false;
|
||||||
|
return dataType == DataType.ITEM ? id.namespace().split("_", 2).length == 2 : id.namespace().equals("mmoitems");
|
||||||
}
|
}
|
||||||
|
|
||||||
private MMOItems api() {
|
private MMOItems api() {
|
@ -16,19 +16,18 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.volmit.iris.core.link;
|
package com.volmit.iris.core.link.data;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.link.ExternalDataProvider;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
import com.volmit.iris.core.service.ExternalDataSVC;
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.util.collection.KList;
|
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.data.B;
|
import com.volmit.iris.util.data.B;
|
||||||
import com.volmit.iris.util.data.IrisCustomData;
|
import com.volmit.iris.util.data.IrisCustomData;
|
||||||
import com.volmit.iris.util.math.RNG;
|
|
||||||
import io.lumine.mythic.bukkit.BukkitAdapter;
|
import io.lumine.mythic.bukkit.BukkitAdapter;
|
||||||
import io.lumine.mythic.bukkit.utils.serialize.Chroma;
|
import io.lumine.mythic.bukkit.utils.serialize.Chroma;
|
||||||
import io.lumine.mythiccrucible.MythicCrucible;
|
import io.lumine.mythiccrucible.MythicCrucible;
|
||||||
@ -37,11 +36,11 @@ import io.lumine.mythiccrucible.items.ItemManager;
|
|||||||
import io.lumine.mythiccrucible.items.blocks.CustomBlockItemContext;
|
import io.lumine.mythiccrucible.items.blocks.CustomBlockItemContext;
|
||||||
import io.lumine.mythiccrucible.items.furniture.FurnitureItemContext;
|
import io.lumine.mythiccrucible.items.furniture.FurnitureItemContext;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -88,69 +87,27 @@ public class MythicCrucibleDataProvider extends ExternalDataProvider {
|
|||||||
.generateItemStack(1));
|
.generateItemStack(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) {
|
||||||
KList<Identifier> names = new KList<>();
|
return itemManager.getItems()
|
||||||
for (CrucibleItem item : this.itemManager.getItems()) {
|
.stream()
|
||||||
if (item.getBlockData() == null) continue;
|
.map(i -> new Identifier("crucible", i.getInternalName()))
|
||||||
try {
|
.filter(dataType.asPredicate(this))
|
||||||
Identifier key = new Identifier("crucible", item.getInternalName());
|
.toList();
|
||||||
if (getBlockData(key) != null) {
|
|
||||||
Iris.info("getBlockTypes: Block loaded '" + item.getInternalName() + "'");
|
|
||||||
names.add(key);
|
|
||||||
}
|
|
||||||
} catch (MissingResourceException ignored) {}
|
|
||||||
}
|
|
||||||
return names.toArray(new Identifier[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Identifier[] getItemTypes() {
|
|
||||||
KList<Identifier> names = new KList<>();
|
|
||||||
for (CrucibleItem item : this.itemManager.getItems()) {
|
|
||||||
try {
|
|
||||||
Identifier key = new Identifier("crucible", item.getInternalName());
|
|
||||||
if (getItemStack(key) != null) {
|
|
||||||
Iris.info("getItemTypes: Item loaded '" + item.getInternalName() + "'");
|
|
||||||
names.add(key);
|
|
||||||
}
|
|
||||||
} catch (MissingResourceException ignored) {}
|
|
||||||
}
|
|
||||||
return names.toArray(new Identifier[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processUpdate(@NotNull Engine engine, @NotNull Block block, @NotNull Identifier blockId) {
|
public void processUpdate(@NotNull Engine engine, @NotNull Block block, @NotNull Identifier blockId) {
|
||||||
var pair = ExternalDataSVC.parseState(blockId);
|
var parsedState = ExternalDataSVC.parseState(blockId);
|
||||||
var state = pair.getB();
|
var state = parsedState.getB();
|
||||||
blockId = pair.getA();
|
blockId = parsedState.getA();
|
||||||
|
|
||||||
Optional<CrucibleItem> item = itemManager.getItem(blockId.key());
|
Optional<CrucibleItem> item = itemManager.getItem(blockId.key());
|
||||||
if (item.isEmpty()) return;
|
if (item.isEmpty()) return;
|
||||||
FurnitureItemContext furniture = item.get().getFurnitureData();
|
FurnitureItemContext furniture = item.get().getFurnitureData();
|
||||||
if (furniture == null) return;
|
if (furniture == null) return;
|
||||||
|
|
||||||
float yaw = 0;
|
var pair = parseYawAndFace(engine, block, state);
|
||||||
BlockFace face = BlockFace.NORTH;
|
|
||||||
long seed = engine.getSeedManager().getSeed() + Cache.key(block.getX(), block.getZ()) + block.getY();
|
|
||||||
RNG rng = new RNG(seed);
|
|
||||||
if ("true".equals(state.get("randomYaw"))) {
|
|
||||||
yaw = rng.f(0, 360);
|
|
||||||
} else if (state.containsKey("yaw")) {
|
|
||||||
yaw = Float.parseFloat(state.get("yaw"));
|
|
||||||
}
|
|
||||||
if ("true".equals(state.get("randomFace"))) {
|
|
||||||
BlockFace[] faces = BlockFace.values();
|
|
||||||
face = faces[rng.i(0, faces.length - 1)];
|
|
||||||
} else if (state.containsKey("face")) {
|
|
||||||
face = BlockFace.valueOf(state.get("face").toUpperCase());
|
|
||||||
}
|
|
||||||
if (face == BlockFace.SELF) {
|
|
||||||
face = BlockFace.NORTH;
|
|
||||||
}
|
|
||||||
|
|
||||||
BiomeColor type = null;
|
BiomeColor type = null;
|
||||||
Chroma color = null;
|
Chroma color = null;
|
||||||
try {
|
try {
|
||||||
@ -161,11 +118,12 @@ public class MythicCrucibleDataProvider extends ExternalDataProvider {
|
|||||||
if (biomeColor == null) return;
|
if (biomeColor == null) return;
|
||||||
color = Chroma.of(biomeColor.getRGB());
|
color = Chroma.of(biomeColor.getRGB());
|
||||||
}
|
}
|
||||||
furniture.place(block, face, yaw, color);
|
furniture.place(block, pair.getB(), pair.getA(), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidProvider(@NotNull Identifier key, boolean isItem) {
|
public boolean isValidProvider(@NotNull Identifier key, DataType dataType) {
|
||||||
|
if (dataType == DataType.ENTITY) return false;
|
||||||
return key.namespace().equalsIgnoreCase("crucible");
|
return key.namespace().equalsIgnoreCase("crucible");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,25 +1,7 @@
|
|||||||
/*
|
package com.volmit.iris.core.link.data;
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.volmit.iris.core.link;
|
import com.volmit.iris.core.link.ExternalDataProvider;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.volmit.iris.Iris;
|
|
||||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
import io.lumine.mythic.api.adapters.AbstractLocation;
|
import io.lumine.mythic.api.adapters.AbstractLocation;
|
||||||
import io.lumine.mythic.api.config.MythicLineConfig;
|
import io.lumine.mythic.api.config.MythicLineConfig;
|
||||||
@ -30,60 +12,59 @@ import io.lumine.mythic.bukkit.events.MythicConditionLoadEvent;
|
|||||||
import io.lumine.mythic.core.skills.SkillCondition;
|
import io.lumine.mythic.core.skills.SkillCondition;
|
||||||
import io.lumine.mythic.core.utils.annotations.MythicCondition;
|
import io.lumine.mythic.core.utils.annotations.MythicCondition;
|
||||||
import io.lumine.mythic.core.utils.annotations.MythicField;
|
import io.lumine.mythic.core.utils.annotations.MythicField;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class MythicMobsLink {
|
public class MythicMobsDataProvider extends ExternalDataProvider {
|
||||||
|
public MythicMobsDataProvider() {
|
||||||
public MythicMobsLink() {
|
super("MythicMobs");
|
||||||
if (getPlugin() == null) return;
|
|
||||||
Iris.instance.registerListener(new ConditionListener());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
@Override
|
||||||
return getPlugin() != null;
|
public void init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin getPlugin() {
|
@Override
|
||||||
return Bukkit.getPluginManager().getPlugin("MythicMobs");
|
public @Nullable Entity spawnMob(@NotNull Location location, @NotNull Identifier entityId) throws MissingResourceException {
|
||||||
|
var mm = MythicBukkit.inst().getMobManager().spawnMob(entityId.key(), location);
|
||||||
|
if (mm == null) throw new MissingResourceException("Failed to find mob!", entityId.namespace(), entityId.key());
|
||||||
|
return mm.getEntity().getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Spawn a mythic mob at this location
|
public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) {
|
||||||
*
|
if (dataType != DataType.ENTITY) return List.of();
|
||||||
* @param mob The mob
|
return MythicBukkit.inst()
|
||||||
* @param location The location
|
.getMobManager()
|
||||||
* @return The mob, or null if it can't be spawned
|
.getMobNames()
|
||||||
*/
|
.stream()
|
||||||
public @Nullable Entity spawnMob(String mob, Location location) {
|
.map(name -> new Identifier("mythicmobs", name))
|
||||||
return isEnabled() ? MythicBukkit.inst().getMobManager().spawnMob(mob, location).getEntity().getBukkitEntity() : null;
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> getMythicMobTypes() {
|
@Override
|
||||||
return isEnabled() ? MythicBukkit.inst().getMobManager().getMobNames() : List.of();
|
public boolean isValidProvider(@NotNull Identifier id, DataType dataType) {
|
||||||
|
return id.namespace().equalsIgnoreCase("mythicmobs") && dataType == DataType.ENTITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ConditionListener implements Listener {
|
@EventHandler
|
||||||
@EventHandler
|
public void on(MythicConditionLoadEvent event) {
|
||||||
public void on(MythicConditionLoadEvent event) {
|
switch (event.getConditionName()) {
|
||||||
switch (event.getConditionName()) {
|
case "irisbiome" -> event.register(new IrisBiomeCondition(event.getConditionName(), event.getConfig()));
|
||||||
case "irisbiome" -> event.register(new IrisBiomeCondition(event.getConditionName(), event.getConfig()));
|
case "irisregion" -> event.register(new IrisRegionCondition(event.getConditionName(), event.getConfig()));
|
||||||
case "irisregion" -> event.register(new IrisRegionCondition(event.getConditionName(), event.getConfig()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@MythicCondition(author = "CrazyDev22", name = "irisbiome", description = "Tests if the target is within the given list of biomes")
|
@MythicCondition(author = "CrazyDev22", name = "irisbiome", description = "Tests if the target is within the given list of biomes")
|
||||||
public static class IrisBiomeCondition extends SkillCondition implements ILocationCondition {
|
public static class IrisBiomeCondition extends SkillCondition implements ILocationCondition {
|
||||||
@MythicField(name = "biome", aliases = {"b"}, description = "A list of biomes to check")
|
@MythicField(name = "biome", aliases = {"b"}, description = "A list of biomes to check")
|
||||||
private Set<String> biomes = Sets.newConcurrentHashSet();
|
private Set<String> biomes = ConcurrentHashMap.newKeySet();
|
||||||
@MythicField(name = "surface", aliases = {"s"}, description = "If the biome check should only be performed on the surface")
|
@MythicField(name = "surface", aliases = {"s"}, description = "If the biome check should only be performed on the surface")
|
||||||
private boolean surface;
|
private boolean surface;
|
||||||
|
|
||||||
@ -107,10 +88,10 @@ public class MythicMobsLink {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@MythicCondition(author = "CrazyDev22", name = "irisbiome", description = "Tests if the target is within the given list of biomes")
|
@MythicCondition(author = "CrazyDev22", name = "irisregion", description = "Tests if the target is within the given list of biomes")
|
||||||
public static class IrisRegionCondition extends SkillCondition implements ILocationCondition {
|
public static class IrisRegionCondition extends SkillCondition implements ILocationCondition {
|
||||||
@MythicField(name = "region", aliases = {"r"}, description = "A list of regions to check")
|
@MythicField(name = "region", aliases = {"r"}, description = "A list of regions to check")
|
||||||
private Set<String> regions = Sets.newConcurrentHashSet();
|
private Set<String> regions = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
public IrisRegionCondition(String line, MythicLineConfig mlc) {
|
public IrisRegionCondition(String line, MythicLineConfig mlc) {
|
||||||
super(line);
|
super(line);
|
@ -1,28 +1,30 @@
|
|||||||
package com.volmit.iris.core.link;
|
package com.volmit.iris.core.link.data;
|
||||||
|
|
||||||
import com.nexomc.nexo.api.NexoBlocks;
|
import com.nexomc.nexo.api.NexoBlocks;
|
||||||
import com.nexomc.nexo.api.NexoFurniture;
|
import com.nexomc.nexo.api.NexoFurniture;
|
||||||
import com.nexomc.nexo.api.NexoItems;
|
import com.nexomc.nexo.api.NexoItems;
|
||||||
import com.nexomc.nexo.items.ItemBuilder;
|
import com.nexomc.nexo.items.ItemBuilder;
|
||||||
|
import com.volmit.iris.core.link.ExternalDataProvider;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
import com.volmit.iris.core.service.ExternalDataSVC;
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.data.B;
|
import com.volmit.iris.util.data.B;
|
||||||
import com.volmit.iris.util.data.IrisCustomData;
|
import com.volmit.iris.util.data.IrisCustomData;
|
||||||
import com.volmit.iris.util.math.RNG;
|
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.entity.ItemDisplay;
|
import org.bukkit.entity.ItemDisplay;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
|
import org.bukkit.inventory.meta.MapMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@ -69,9 +71,9 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processUpdate(@NotNull Engine engine, @NotNull Block block, @NotNull Identifier blockId) {
|
public void processUpdate(@NotNull Engine engine, @NotNull Block block, @NotNull Identifier blockId) {
|
||||||
var pair = ExternalDataSVC.parseState(blockId);
|
var statePair = ExternalDataSVC.parseState(blockId);
|
||||||
var state = pair.getB();
|
var state = statePair.getB();
|
||||||
blockId = pair.getA();
|
blockId = statePair.getA();
|
||||||
|
|
||||||
if (NexoBlocks.isCustomBlock(blockId.key())) {
|
if (NexoBlocks.isCustomBlock(blockId.key())) {
|
||||||
NexoBlocks.place(blockId.key(), block.getLocation());
|
NexoBlocks.place(blockId.key(), block.getLocation());
|
||||||
@ -81,26 +83,8 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
if (!NexoFurniture.isFurniture(blockId.key()))
|
if (!NexoFurniture.isFurniture(blockId.key()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float yaw = 0;
|
var pair = parseYawAndFace(engine, block, state);
|
||||||
BlockFace face = BlockFace.NORTH;
|
ItemDisplay display = NexoFurniture.place(blockId.key(), block.getLocation(), pair.getA(), pair.getB());
|
||||||
|
|
||||||
long seed = engine.getSeedManager().getSeed() + Cache.key(block.getX(), block.getZ()) + block.getY();
|
|
||||||
RNG rng = new RNG(seed);
|
|
||||||
if ("true".equals(state.get("randomYaw"))) {
|
|
||||||
yaw = rng.f(0, 360);
|
|
||||||
} else if (state.containsKey("yaw")) {
|
|
||||||
yaw = Float.parseFloat(state.get("yaw"));
|
|
||||||
}
|
|
||||||
if ("true".equals(state.get("randomFace"))) {
|
|
||||||
BlockFace[] faces = BlockFace.values();
|
|
||||||
face = faces[rng.i(0, faces.length - 1)];
|
|
||||||
} else if (state.containsKey("face")) {
|
|
||||||
face = BlockFace.valueOf(state.get("face").toUpperCase());
|
|
||||||
}
|
|
||||||
if (face == BlockFace.SELF) {
|
|
||||||
face = BlockFace.NORTH;
|
|
||||||
}
|
|
||||||
ItemDisplay display = NexoFurniture.place(blockId.key(), block.getLocation(), yaw, face);
|
|
||||||
if (display == null) return;
|
if (display == null) return;
|
||||||
ItemStack itemStack = display.getItemStack();
|
ItemStack itemStack = display.getItemStack();
|
||||||
if (itemStack == null) return;
|
if (itemStack == null) return;
|
||||||
@ -114,46 +98,31 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
var biomeColor = INMS.get().getBiomeColor(block.getLocation(), type);
|
var biomeColor = INMS.get().getBiomeColor(block.getLocation(), type);
|
||||||
if (biomeColor == null) return;
|
if (biomeColor == null) return;
|
||||||
var potionColor = Color.fromARGB(biomeColor.getAlpha(), biomeColor.getRed(), biomeColor.getGreen(), biomeColor.getBlue());
|
var potionColor = Color.fromARGB(biomeColor.getAlpha(), biomeColor.getRed(), biomeColor.getGreen(), biomeColor.getBlue());
|
||||||
if (itemStack.getItemMeta() instanceof PotionMeta meta) {
|
var meta = itemStack.getItemMeta();
|
||||||
meta.setColor(potionColor);
|
switch (meta) {
|
||||||
itemStack.setItemMeta(meta);
|
case LeatherArmorMeta armor -> armor.setColor(potionColor);
|
||||||
|
case PotionMeta potion -> potion.setColor(potionColor);
|
||||||
|
case MapMeta map -> map.setColor(potionColor);
|
||||||
|
case null, default -> {}
|
||||||
}
|
}
|
||||||
|
itemStack.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
display.setItemStack(itemStack);
|
display.setItemStack(itemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public @NotNull Collection<@NotNull Identifier> getTypes(@NotNull DataType dataType) {
|
||||||
return NexoItems.itemNames().stream()
|
if (dataType == DataType.ENTITY) return List.of();
|
||||||
|
return NexoItems.itemNames()
|
||||||
|
.stream()
|
||||||
.map(i -> new Identifier("nexo", i))
|
.map(i -> new Identifier("nexo", i))
|
||||||
.filter(i -> {
|
.filter(dataType.asPredicate(this))
|
||||||
try {
|
.toList();
|
||||||
return getBlockData(i) != null;
|
|
||||||
} catch (MissingResourceException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.toArray(Identifier[]::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Identifier[] getItemTypes() {
|
|
||||||
return NexoItems.itemNames().stream()
|
|
||||||
.map(i -> new Identifier("nexo", i))
|
|
||||||
.filter(i -> {
|
|
||||||
try {
|
|
||||||
return getItemStack(i) != null;
|
|
||||||
} catch (MissingResourceException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.toArray(Identifier[]::new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidProvider(@NotNull Identifier id, boolean isItem) {
|
public boolean isValidProvider(@NotNull Identifier id, DataType dataType) {
|
||||||
|
if (dataType == DataType.ENTITY) return false;
|
||||||
return "nexo".equalsIgnoreCase(id.namespace());
|
return "nexo".equalsIgnoreCase(id.namespace());
|
||||||
}
|
}
|
||||||
|
|
@ -19,9 +19,12 @@
|
|||||||
package com.volmit.iris.core.project;
|
package com.volmit.iris.core.project;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
|
import com.volmit.iris.core.link.data.DataType;
|
||||||
import com.volmit.iris.core.loader.IrisData;
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||||
import com.volmit.iris.core.loader.ResourceLoader;
|
import com.volmit.iris.core.loader.ResourceLoader;
|
||||||
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
import com.volmit.iris.engine.object.annotations.*;
|
import com.volmit.iris.engine.object.annotations.*;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
@ -39,7 +42,6 @@ import java.lang.reflect.Modifier;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class SchemaBuilder {
|
public class SchemaBuilder {
|
||||||
private static final String SYMBOL_LIMIT__N = "*";
|
private static final String SYMBOL_LIMIT__N = "*";
|
||||||
@ -266,16 +268,18 @@ public class SchemaBuilder {
|
|||||||
|
|
||||||
if (!definitions.containsKey(key)) {
|
if (!definitions.containsKey(key)) {
|
||||||
JSONObject j = new JSONObject();
|
JSONObject j = new JSONObject();
|
||||||
KList<String> list = new KList<>();
|
KList<String> list = Iris.service(ExternalDataSVC.class)
|
||||||
list.addAll(Iris.linkMythicMobs.getMythicMobTypes().stream().map(s -> "MythicMobs:" + s).collect(Collectors.toList()));
|
.getAllIdentifiers(DataType.ENTITY)
|
||||||
//TODO add Citizens stuff here too
|
.stream()
|
||||||
|
.map(Identifier::toString)
|
||||||
|
.collect(KList.collector());
|
||||||
j.put("enum", list.toJSONStringArray());
|
j.put("enum", list.toJSONStringArray());
|
||||||
definitions.put(key, j);
|
definitions.put(key, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
fancyType = "Mythic Mob Type";
|
fancyType = "Custom Mob Type";
|
||||||
prop.put("$ref", "#/definitions/" + key);
|
prop.put("$ref", "#/definitions/" + key);
|
||||||
description.add(SYMBOL_TYPE__N + " Must be a valid Mythic Mob Type (use ctrl+space for auto complete!) Define mythic mobs with the mythic mobs plugin configuration files.");
|
description.add(SYMBOL_TYPE__N + " Must be a valid Custom Mob Type (use ctrl+space for auto complete!)");
|
||||||
} else if (k.isAnnotationPresent(RegistryListFont.class)) {
|
} else if (k.isAnnotationPresent(RegistryListFont.class)) {
|
||||||
String key = "enum-font";
|
String key = "enum-font";
|
||||||
|
|
||||||
|
@ -20,16 +20,21 @@ package com.volmit.iris.core.service;
|
|||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.link.*;
|
import com.volmit.iris.core.link.*;
|
||||||
|
import com.volmit.iris.core.link.data.DataType;
|
||||||
import com.volmit.iris.core.nms.container.Pair;
|
import com.volmit.iris.core.nms.container.Pair;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import com.volmit.iris.util.io.JarScanner;
|
||||||
import com.volmit.iris.util.plugin.IrisService;
|
import com.volmit.iris.util.plugin.IrisService;
|
||||||
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -47,43 +52,12 @@ public class ExternalDataSVC implements IrisService {
|
|||||||
Iris.info("Loading ExternalDataProvider...");
|
Iris.info("Loading ExternalDataProvider...");
|
||||||
Bukkit.getPluginManager().registerEvents(this, Iris.instance);
|
Bukkit.getPluginManager().registerEvents(this, Iris.instance);
|
||||||
|
|
||||||
providers.add(new NexoDataProvider());
|
providers.addAll(createProviders());
|
||||||
if (Bukkit.getPluginManager().getPlugin("Nexo") != null) {
|
|
||||||
Iris.info("Nexo found, loading NexoDataProvider...");
|
|
||||||
}
|
|
||||||
providers.add(new MythicCrucibleDataProvider());
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("MythicCrucible") != null) {
|
|
||||||
Iris.info("MythicCrucible found, loading MythicCrucibleDataProvider...");
|
|
||||||
}
|
|
||||||
providers.add(new ItemAdderDataProvider());
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("ItemAdder") != null) {
|
|
||||||
Iris.info("ItemAdder found, loading ItemAdderDataProvider...");
|
|
||||||
}
|
|
||||||
providers.add(new ExecutableItemsDataProvider());
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("ExecutableItems") != null) {
|
|
||||||
Iris.info("ExecutableItems found, loading ExecutableItemsDataProvider...");
|
|
||||||
}
|
|
||||||
providers.add(new HMCLeavesDataProvider());
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("HMCLeaves") != null) {
|
|
||||||
Iris.info("BlockAdder found, loading HMCLeavesDataProvider...");
|
|
||||||
}
|
|
||||||
providers.add(new MMOItemsDataProvider());
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("MMOItems") != null) {
|
|
||||||
Iris.info("MMOItems found, loading MMOItemsDataProvider...");
|
|
||||||
}
|
|
||||||
providers.add(new EcoItemsDataProvider());
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("EcoItems") != null) {
|
|
||||||
Iris.info("EcoItems found, loading EcoItemsDataProvider...");
|
|
||||||
}
|
|
||||||
providers.add(new KGeneratorsDataProvider());
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("KGenerators") != null) {
|
|
||||||
Iris.info("KGenerators found, loading KGeneratorsDataProvider...");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ExternalDataProvider p : providers) {
|
for (ExternalDataProvider p : providers) {
|
||||||
if (p.isReady()) {
|
if (p.isReady()) {
|
||||||
activeProviders.add(p);
|
activeProviders.add(p);
|
||||||
p.init();
|
p.init();
|
||||||
|
Iris.instance.registerListener(p);
|
||||||
Iris.info("Enabled ExternalDataProvider for %s.", p.getPluginId());
|
Iris.info("Enabled ExternalDataProvider for %s.", p.getPluginId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,6 +73,7 @@ public class ExternalDataSVC implements IrisService {
|
|||||||
providers.stream().filter(p -> p.isReady() && p.getPlugin().equals(e.getPlugin())).findFirst().ifPresent(edp -> {
|
providers.stream().filter(p -> p.isReady() && p.getPlugin().equals(e.getPlugin())).findFirst().ifPresent(edp -> {
|
||||||
activeProviders.add(edp);
|
activeProviders.add(edp);
|
||||||
edp.init();
|
edp.init();
|
||||||
|
Iris.instance.registerListener(edp);
|
||||||
Iris.info("Enabled ExternalDataProvider for %s.", edp.getPluginId());
|
Iris.info("Enabled ExternalDataProvider for %s.", edp.getPluginId());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -113,6 +88,7 @@ public class ExternalDataSVC implements IrisService {
|
|||||||
if (provider.isReady()) {
|
if (provider.isReady()) {
|
||||||
activeProviders.add(provider);
|
activeProviders.add(provider);
|
||||||
provider.init();
|
provider.init();
|
||||||
|
Iris.instance.registerListener(provider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +96,7 @@ public class ExternalDataSVC implements IrisService {
|
|||||||
var pair = parseState(key);
|
var pair = parseState(key);
|
||||||
Identifier mod = pair.getA();
|
Identifier mod = pair.getA();
|
||||||
|
|
||||||
Optional<ExternalDataProvider> provider = activeProviders.stream().filter(p -> p.isValidProvider(mod, false)).findFirst();
|
Optional<ExternalDataProvider> provider = activeProviders.stream().filter(p -> p.isValidProvider(mod, DataType.BLOCK)).findFirst();
|
||||||
if (provider.isEmpty())
|
if (provider.isEmpty())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
try {
|
try {
|
||||||
@ -132,7 +108,7 @@ public class ExternalDataSVC implements IrisService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Optional<ItemStack> getItemStack(Identifier key, KMap<String, Object> customNbt) {
|
public Optional<ItemStack> getItemStack(Identifier key, KMap<String, Object> customNbt) {
|
||||||
Optional<ExternalDataProvider> provider = activeProviders.stream().filter(p -> p.isValidProvider(key, true)).findFirst();
|
Optional<ExternalDataProvider> provider = activeProviders.stream().filter(p -> p.isValidProvider(key, DataType.ITEM)).findFirst();
|
||||||
if (provider.isEmpty()) {
|
if (provider.isEmpty()) {
|
||||||
Iris.warn("No matching Provider found for modded material \"%s\"!", key);
|
Iris.warn("No matching Provider found for modded material \"%s\"!", key);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
@ -146,7 +122,7 @@ public class ExternalDataSVC implements IrisService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void processUpdate(Engine engine, Block block, Identifier blockId) {
|
public void processUpdate(Engine engine, Block block, Identifier blockId) {
|
||||||
Optional<ExternalDataProvider> provider = activeProviders.stream().filter(p -> p.isValidProvider(blockId, false)).findFirst();
|
Optional<ExternalDataProvider> provider = activeProviders.stream().filter(p -> p.isValidProvider(blockId, DataType.BLOCK)).findFirst();
|
||||||
if (provider.isEmpty()) {
|
if (provider.isEmpty()) {
|
||||||
Iris.warn("No matching Provider found for modded material \"%s\"!", blockId);
|
Iris.warn("No matching Provider found for modded material \"%s\"!", blockId);
|
||||||
return;
|
return;
|
||||||
@ -154,16 +130,24 @@ public class ExternalDataSVC implements IrisService {
|
|||||||
provider.get().processUpdate(engine, block, blockId);
|
provider.get().processUpdate(engine, block, blockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier[] getAllBlockIdentifiers() {
|
public Entity spawnMob(Location location, Identifier mobId) {
|
||||||
KList<Identifier> names = new KList<>();
|
Optional<ExternalDataProvider> provider = activeProviders.stream().filter(p -> p.isValidProvider(mobId, DataType.ENTITY)).findFirst();
|
||||||
activeProviders.forEach(p -> names.add(p.getBlockTypes()));
|
if (provider.isEmpty()) {
|
||||||
return names.toArray(new Identifier[0]);
|
Iris.warn("No matching Provider found for modded mob \"%s\"!", mobId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return provider.get().spawnMob(location, mobId);
|
||||||
|
} catch (MissingResourceException e) {
|
||||||
|
Iris.error(e.getMessage() + " - [" + e.getClassName() + ":" + e.getKey() + "]");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier[] getAllItemIdentifiers() {
|
public Collection<Identifier> getAllIdentifiers(DataType dataType) {
|
||||||
KList<Identifier> names = new KList<>();
|
return activeProviders.stream()
|
||||||
activeProviders.forEach(p -> names.add(p.getItemTypes()));
|
.flatMap(p -> p.getTypes(dataType).stream())
|
||||||
return names.toArray(new Identifier[0]);
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Pair<Identifier, KMap<String, String>> parseState(Identifier key) {
|
public static Pair<Identifier, KMap<String, String>> parseState(Identifier key) {
|
||||||
@ -188,4 +172,21 @@ public class ExternalDataSVC implements IrisService {
|
|||||||
.collect(Collectors.joining(",", key.key() + "[", "]"));
|
.collect(Collectors.joining(",", key.key() + "[", "]"));
|
||||||
return new Identifier(key.namespace(), path);
|
return new Identifier(key.namespace(), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static KList<ExternalDataProvider> createProviders() {
|
||||||
|
JarScanner jar = new JarScanner(Iris.instance.getJarFile(), "com.volmit.iris.core.link.data");
|
||||||
|
J.attempt(jar::scan);
|
||||||
|
KList<ExternalDataProvider> providers = new KList<>();
|
||||||
|
|
||||||
|
for (Class<?> c : jar.getClasses()) {
|
||||||
|
if (ExternalDataProvider.class.isAssignableFrom(c)) {
|
||||||
|
try {
|
||||||
|
ExternalDataProvider p = (ExternalDataProvider) c.getDeclaredConstructor().newInstance();
|
||||||
|
if (p.getPlugin() != null) Iris.info(p.getPluginId() + " found, loading " + c.getSimpleName() + "...");
|
||||||
|
providers.add(p);
|
||||||
|
} catch (Throwable ignored) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return providers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,10 @@ package com.volmit.iris.engine.object;
|
|||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.IrisSettings;
|
import com.volmit.iris.core.IrisSettings;
|
||||||
|
import com.volmit.iris.core.link.Identifier;
|
||||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.object.annotations.*;
|
import com.volmit.iris.engine.object.annotations.*;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
@ -455,24 +457,13 @@ public class IrisEntity extends IrisRegistrant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isSpecialType()) {
|
if (isSpecialType()) {
|
||||||
if (specialType.toLowerCase().startsWith("mythicmobs:")) {
|
return Iris.service(ExternalDataSVC.class).spawnMob(at, Identifier.fromString(specialType));
|
||||||
return Iris.linkMythicMobs.spawnMob(specialType.substring(11), at);
|
|
||||||
} else {
|
|
||||||
Iris.warn("Invalid mob type to spawn: '" + specialType + "'!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return INMS.get().spawnEntity(at, getType(), getReason());
|
return INMS.get().spawnEntity(at, getType(), getReason());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCitizens() {
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// TODO: return Iris.linkCitizens.supported() && someType is not empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSpecialType() {
|
public boolean isSpecialType() {
|
||||||
return specialType != null && !specialType.equals("");
|
return specialType != null && !specialType.equals("");
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ package com.volmit.iris.util.data;
|
|||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.IrisSettings;
|
import com.volmit.iris.core.IrisSettings;
|
||||||
import com.volmit.iris.core.link.Identifier;
|
import com.volmit.iris.core.link.Identifier;
|
||||||
|
import com.volmit.iris.core.link.data.DataType;
|
||||||
import com.volmit.iris.core.service.ExternalDataSVC;
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
@ -673,7 +674,7 @@ public class B {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Identifier id : Iris.service(ExternalDataSVC.class).getAllBlockIdentifiers())
|
for (Identifier id : Iris.service(ExternalDataSVC.class).getAllIdentifiers(DataType.BLOCK))
|
||||||
bt.add(id.toString());
|
bt.add(id.toString());
|
||||||
bt.addAll(custom.k());
|
bt.addAll(custom.k());
|
||||||
|
|
||||||
@ -688,7 +689,7 @@ public class B {
|
|||||||
bt.add(v);
|
bt.add(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Identifier id : Iris.service(ExternalDataSVC.class).getAllItemIdentifiers())
|
for (Identifier id : Iris.service(ExternalDataSVC.class).getAllIdentifiers(DataType.ITEM))
|
||||||
bt.add(id.toString());
|
bt.add(id.toString());
|
||||||
|
|
||||||
return bt.toArray(new String[0]);
|
return bt.toArray(new String[0]);
|
||||||
|
@ -240,6 +240,21 @@ public class J {
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> CompletableFuture<T> sfut(Supplier<T> r) {
|
||||||
|
CompletableFuture<T> f = new CompletableFuture<>();
|
||||||
|
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> {
|
||||||
|
try {
|
||||||
|
f.complete(r.get());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
f.completeExceptionally(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
public static CompletableFuture sfut(Runnable r, int delay) {
|
public static CompletableFuture sfut(Runnable r, int delay) {
|
||||||
CompletableFuture f = new CompletableFuture();
|
CompletableFuture f = new CompletableFuture();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user