diff --git a/calio/src/main/java/me/dueris/calio/CraftCalio.java b/calio/src/main/java/me/dueris/calio/CraftCalio.java index 5f7150e58..9edc09042 100644 --- a/calio/src/main/java/me/dueris/calio/CraftCalio.java +++ b/calio/src/main/java/me/dueris/calio/CraftCalio.java @@ -144,6 +144,8 @@ public void register(Class holder) { RequiresPlugin aN = holder.getAnnotation(RequiresPlugin.class); if (!org.bukkit.Bukkit.getPluginManager().isPluginEnabled(aN.pluginName())) return; } + ClassLoader classLoader = CraftCalio.class.getClassLoader(); + classLoader.loadClass(holder.getName()); // Preload class Method rC = holder.getDeclaredMethod("registerComponents", FactoryData.class); if (rC == null) throw new IllegalArgumentException("FactoryHolder doesn't have registerComponents method in it or its superclasses!"); @@ -152,22 +154,27 @@ public void register(Class holder) { if (identifier == null) throw new IllegalArgumentException("Type identifier was not provided! FactoryHolder will not be loaded : " + holder.getSimpleName()); this.types.put(identifier, new Pair<>(data, holder)); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ea) { + } catch (ClassNotFoundException ea) { + throw new RuntimeException("Unable to resolve class during registration!", ea); + } catch (Throwable ea) { if (ea instanceof NoSuchMethodException) return; + if (ea instanceof IllegalArgumentException) { + getLogger().severe("Type provider was not provided! FactoryHolder will not be loaded. : " + holder.getSimpleName()); + } ea.printStackTrace(); throw new RuntimeException("An exception occured when registering FactoryHolder", ea); } } public void registerAccessor(String directory, int priority, boolean useTypeDefiner, Class typeOf, RegistryKey registryKey, String defaultType) { - keys.add(new AccessorKey(directory, priority, useTypeDefiner, registryKey, typeOf, defaultType)); + keys.add(new AccessorKey(directory, priority, useTypeDefiner, registryKey, typeOf, defaultType)); } public void registerAccessor(String directory, int priority, boolean useTypeDefiner, Class typeOf, RegistryKey registryKey) { - keys.add(new AccessorKey(directory, priority, useTypeDefiner, registryKey, typeOf, null)); + keys.add(new AccessorKey(directory, priority, useTypeDefiner, registryKey, typeOf, null)); } public void registerAccessor(String directory, int priority, boolean useTypeDefiner, RegistryKey registryKey) { - keys.add(new AccessorKey(directory, priority, useTypeDefiner, registryKey, null, null)); + keys.add(new AccessorKey(directory, priority, useTypeDefiner, registryKey, null, null)); } } diff --git a/calio/src/main/java/me/dueris/calio/data/FactoryDataDefiner.java b/calio/src/main/java/me/dueris/calio/data/FactoryDataDefiner.java index 701bac40d..30cf4417c 100644 --- a/calio/src/main/java/me/dueris/calio/data/FactoryDataDefiner.java +++ b/calio/src/main/java/me/dueris/calio/data/FactoryDataDefiner.java @@ -2,30 +2,40 @@ import me.dueris.calio.data.types.OptionalInstance; import me.dueris.calio.data.types.RequiredInstance; -import me.dueris.calio.util.holders.TriPair; -public class FactoryDataDefiner extends TriPair { - public FactoryDataDefiner(String objName, Class type, T defaultVal) { - super(objName, type, defaultVal); +/** + * Implementation of a TriPair object + */ +public class FactoryDataDefiner { + private String key; + private Class type; + private Object defaultVal; + + public FactoryDataDefiner(String objName, Class type, T defaultVal) { + this.key = objName; + this.type = type; + this.defaultVal = defaultVal; } - public FactoryDataDefiner(String objName, Class type, RequiredInstance defaultVal) { - super(objName, type, defaultVal); + public FactoryDataDefiner(String objName, Class type, RequiredInstance defaultVal) { + this(objName, type, (T) null); + this.defaultVal = defaultVal; } - public FactoryDataDefiner(String objName, Class type, OptionalInstance defaultVal) { - super(objName, type, defaultVal); + public FactoryDataDefiner(String objName, Class type, OptionalInstance defaultVal) { + this(objName, type, (T) null); + this.defaultVal = defaultVal; } - public Class getType() { - return (Class) this.second; + public Class getType() { + return (Class) this.type; } public String getObjName() { - return (String) this.first; + return this.key; } public Object getDefaultValue() { - return this.third; + return this.defaultVal; } } diff --git a/calio/src/main/java/me/dueris/calio/util/holders/QuadPair.java b/calio/src/main/java/me/dueris/calio/util/holders/QuadPair.java index 1b15f89fc..34e1e9e70 100644 --- a/calio/src/main/java/me/dueris/calio/util/holders/QuadPair.java +++ b/calio/src/main/java/me/dueris/calio/util/holders/QuadPair.java @@ -1,15 +1,3 @@ package me.dueris.calio.util.holders; -public class QuadPair { - public Object first; - public Object second; - public Object third; - public Object fourth; - - public QuadPair(Object first, Object second, Object third, Object fourth) { - this.first = first; - this.second = second; - this.third = third; - this.fourth = fourth; - } -} +public record QuadPair(A a, B b, C c, D d) { } diff --git a/calio/src/main/java/me/dueris/calio/util/holders/TriBoolean.java b/calio/src/main/java/me/dueris/calio/util/holders/StateableBoolean.java similarity index 89% rename from calio/src/main/java/me/dueris/calio/util/holders/TriBoolean.java rename to calio/src/main/java/me/dueris/calio/util/holders/StateableBoolean.java index c07036348..b9c1bba8a 100644 --- a/calio/src/main/java/me/dueris/calio/util/holders/TriBoolean.java +++ b/calio/src/main/java/me/dueris/calio/util/holders/StateableBoolean.java @@ -2,10 +2,10 @@ import java.util.Optional; -public class TriBoolean { +public class StateableBoolean { private Boolean bool; - public TriBoolean(State state) { + public StateableBoolean(State state) { switch (state) { case TRUE -> { bool = Boolean.TRUE; diff --git a/calio/src/main/java/me/dueris/calio/util/holders/TriPair.java b/calio/src/main/java/me/dueris/calio/util/holders/TriPair.java index 4b5bddf97..6ab629245 100644 --- a/calio/src/main/java/me/dueris/calio/util/holders/TriPair.java +++ b/calio/src/main/java/me/dueris/calio/util/holders/TriPair.java @@ -1,14 +1,16 @@ package me.dueris.calio.util.holders; -public class TriPair { - public T first; - public S second; - public B third; - - public TriPair(T first, S second, B third) { - this.first = first; - this.second = second; - this.third = third; +public record TriPair(A a, B b, C c) { + + public A first() { + return a(); + } + + public B second() { + return b(); } + public C third() { + return c(); + } } diff --git a/origins/src/main/java/me/dueris/genesismc/factory/conditions/ConditionExecutor.java b/origins/src/main/java/me/dueris/genesismc/factory/conditions/ConditionExecutor.java index ed0addfa1..0e8a49464 100644 --- a/origins/src/main/java/me/dueris/genesismc/factory/conditions/ConditionExecutor.java +++ b/origins/src/main/java/me/dueris/genesismc/factory/conditions/ConditionExecutor.java @@ -8,6 +8,7 @@ import me.dueris.genesismc.factory.conditions.types.*; import me.dueris.genesismc.registry.Registries; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.biome.Biome; import org.bukkit.Location; import org.bukkit.NamespacedKey; @@ -141,7 +142,7 @@ public CraftEntity right() { return false; } - public static boolean testBiome(FactoryJsonObject condition, org.bukkit.block.Biome biome, Location blockPos) { + public static boolean testBiome(FactoryJsonObject condition, org.bukkit.block.Biome biome, Location blockPos, ServerLevel level) { if (condition == null || condition.isEmpty()) return true; // Empty condition, do nothing if (isMetaCondition(condition)) { String type = condition.getString("type"); @@ -155,7 +156,7 @@ public static boolean testBiome(FactoryJsonObject condition, org.bukkit.block.Bi Registrar factory = GenesisMC.getPlugin().registry.retrieve(Registries.BIOME_CONDITION); BiomeConditions.ConditionFactory con = factory.get(NamespacedKey.fromString(obj.getString("type"))); if (con != null) { - cons.add(getPossibleInvert(condition.getBooleanOrDefault("inverted", false), testBiome(obj, biome, blockPos))); + cons.add(getPossibleInvert(condition.getBooleanOrDefault("inverted", false), testBiome(obj, biome, blockPos, level))); } else { cons.add(getPossibleInvert(condition.getBooleanOrDefault("inverted", false), true)); // Condition null or not found. } @@ -175,7 +176,7 @@ public static boolean testBiome(FactoryJsonObject condition, org.bukkit.block.Bi Registrar factory = GenesisMC.getPlugin().registry.retrieve(Registries.BIOME_CONDITION); BiomeConditions.ConditionFactory con = factory.get(NamespacedKey.fromString(obj.getString("type"))); if (con != null) { - cons.add(getPossibleInvert(condition.getBooleanOrDefault("inverted", false), testBiome(obj, biome, blockPos))); + cons.add(getPossibleInvert(condition.getBooleanOrDefault("inverted", false), testBiome(obj, biome, blockPos, level))); } else { cons.add(getPossibleInvert(condition.getBooleanOrDefault("inverted", false), true)); // Condition null or not found. } @@ -195,11 +196,19 @@ public static boolean testBiome(FactoryJsonObject condition, org.bukkit.block.Bi } } else { // return the condition + Biome nmsBiome = CraftBiome.bukkitToMinecraft(biome); + if (nmsBiome == null) { + BlockPos nmsPos = CraftLocation.toBlockPosition(blockPos); + nmsBiome = level.getBiome(nmsPos).value(); + if (nmsBiome == null) { + throw new RuntimeException("Unable to convert biome to NMS equivalent!"); + } + } Registrar factory = GenesisMC.getPlugin().registry.retrieve(Registries.BIOME_CONDITION); BiomeConditions.ConditionFactory con = factory.get(NamespacedKey.fromString(condition.getString("type"))); boolean invert = condition.getBooleanOrDefault("inverted", false); if (con != null) { - return getPossibleInvert(invert, con.test(condition, new oshi.util.tuples.Pair(CraftBiome.bukkitToMinecraft(biome), CraftLocation.toBlockPosition(blockPos)))); + return getPossibleInvert(invert, con.test(condition, new oshi.util.tuples.Pair(nmsBiome, CraftLocation.toBlockPosition(blockPos)))); } else { return getPossibleInvert(invert, true); // Condition null or not found. } diff --git a/origins/src/main/java/me/dueris/genesismc/factory/conditions/types/EntityConditions.java b/origins/src/main/java/me/dueris/genesismc/factory/conditions/types/EntityConditions.java index a42c18699..54d55021f 100644 --- a/origins/src/main/java/me/dueris/genesismc/factory/conditions/types/EntityConditions.java +++ b/origins/src/main/java/me/dueris/genesismc/factory/conditions/types/EntityConditions.java @@ -544,7 +544,7 @@ public void registerConditions() { })); register(new ConditionFactory(GenesisMC.apoliIdentifier("biome"), (condition, entity) -> { if (condition.isPresent("condition")) { - return ConditionExecutor.testBiome(condition.getJsonObject("condition"), entity.getLocation().getBlock().getBiome(), entity.getLocation()); + return ConditionExecutor.testBiome(condition.getJsonObject("condition"), entity.getLocation().getBlock().getBiome(), entity.getLocation(), ((CraftWorld)entity.getWorld()).getHandle()); } else { // Assumed to be trying to get biome type String key = condition.getString("biome"); if (key.contains(":")) { diff --git a/origins/src/main/java/me/dueris/genesismc/util/AsyncUpgradeTracker.java b/origins/src/main/java/me/dueris/genesismc/util/AsyncUpgradeTracker.java index 7e257518a..af00f37ac 100644 --- a/origins/src/main/java/me/dueris/genesismc/util/AsyncUpgradeTracker.java +++ b/origins/src/main/java/me/dueris/genesismc/util/AsyncUpgradeTracker.java @@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap; public class AsyncUpgradeTracker implements Listener { - public static ConcurrentHashMap upgrades = new ConcurrentHashMap<>(); + public static ConcurrentHashMap/*String advancement, NamespacedKey identifier, String announcement*/> upgrades = new ConcurrentHashMap<>(); public static String NO_ANNOUNCEMENT = "no_announcement_found"; @EventHandler @@ -33,13 +33,13 @@ public void startEvent(ServerLoadEvent e) { @Override public void run() { MinecraftServer server = GenesisMC.server; - for (Map.Entry entry : upgrades.entrySet()) { + for (Map.Entry> entry : upgrades.entrySet()) { for (CraftPlayer player : ((CraftServer) Bukkit.getServer()).getOnlinePlayers()) { for (Layer layer : CraftApoli.getLayersFromRegistry()) { if (PowerHolderComponent.getOrigin(player, layer).equals(entry.getKey())) { - String advancement = (String) entry.getValue().first; - NamespacedKey originToSet = (NamespacedKey) entry.getValue().second; - String announcement = (String) entry.getValue().third; + String advancement = entry.getValue().a(); + NamespacedKey originToSet = entry.getValue().b(); + String announcement = entry.getValue().c(); AdvancementHolder advancementHolder = server.getAdvancements().get(CraftNamespacedKey.toMinecraft(NamespacedKey.fromString(advancement))); if (advancementHolder == null) {