Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/origin' into origin
Browse files Browse the repository at this point in the history
  • Loading branch information
tye-exe committed Jun 7, 2024
2 parents 960f94c + e48b75b commit 9d0f943
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 50 deletions.
15 changes: 11 additions & 4 deletions calio/src/main/java/me/dueris/calio/CraftCalio.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public void register(Class<? extends FactoryHolder> 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!");
Expand All @@ -152,22 +154,27 @@ public void register(Class<? extends FactoryHolder> 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 <T extends Registrable> void registerAccessor(String directory, int priority, boolean useTypeDefiner, Class<? extends FactoryHolder> typeOf, RegistryKey<T> registryKey, String defaultType) {
keys.add(new AccessorKey(directory, priority, useTypeDefiner, registryKey, typeOf, defaultType));
keys.add(new AccessorKey<T>(directory, priority, useTypeDefiner, registryKey, typeOf, defaultType));
}

public <T extends Registrable> void registerAccessor(String directory, int priority, boolean useTypeDefiner, Class<? extends FactoryHolder> typeOf, RegistryKey<T> registryKey) {
keys.add(new AccessorKey(directory, priority, useTypeDefiner, registryKey, typeOf, null));
keys.add(new AccessorKey<T>(directory, priority, useTypeDefiner, registryKey, typeOf, null));
}

public <T extends Registrable> void registerAccessor(String directory, int priority, boolean useTypeDefiner, RegistryKey<T> registryKey) {
keys.add(new AccessorKey(directory, priority, useTypeDefiner, registryKey, null, null));
keys.add(new AccessorKey<T>(directory, priority, useTypeDefiner, registryKey, null, null));
}
}
34 changes: 22 additions & 12 deletions calio/src/main/java/me/dueris/calio/data/FactoryDataDefiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> FactoryDataDefiner(String objName, Class<T> type, T defaultVal) {
super(objName, type, defaultVal);
/**
* Implementation of a TriPair object
*/
public class FactoryDataDefiner<T> {
private String key;
private Class<T> type;
private Object defaultVal;

public FactoryDataDefiner(String objName, Class<T> type, T defaultVal) {
this.key = objName;
this.type = type;
this.defaultVal = defaultVal;
}

public <T> FactoryDataDefiner(String objName, Class<T> type, RequiredInstance defaultVal) {
super(objName, type, defaultVal);
public FactoryDataDefiner(String objName, Class<T> type, RequiredInstance defaultVal) {
this(objName, type, (T) null);
this.defaultVal = defaultVal;
}

public <T> FactoryDataDefiner(String objName, Class<T> type, OptionalInstance defaultVal) {
super(objName, type, defaultVal);
public FactoryDataDefiner(String objName, Class<T> type, OptionalInstance defaultVal) {
this(objName, type, (T) null);
this.defaultVal = defaultVal;
}

public Class<?> getType() {
return (Class<?>) this.second;
public Class<T> getType() {
return (Class<T>) this.type;
}

public String getObjName() {
return (String) this.first;
return this.key;
}

public Object getDefaultValue() {
return this.third;
return this.defaultVal;
}
}
14 changes: 1 addition & 13 deletions calio/src/main/java/me/dueris/calio/util/holders/QuadPair.java
Original file line number Diff line number Diff line change
@@ -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, B, C, D>(A a, B b, C c, D d) { }
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 11 additions & 9 deletions calio/src/main/java/me/dueris/calio/util/holders/TriPair.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package me.dueris.calio.util.holders;

public class TriPair<T, S, B> {
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, B, C>(A a, B b, C c) {

public A first() {
return a();
}

public B second() {
return b();
}

public C third() {
return c();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -155,7 +156,7 @@ public static boolean testBiome(FactoryJsonObject condition, org.bukkit.block.Bi
Registrar<BiomeConditions.ConditionFactory> 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.
}
Expand All @@ -175,7 +176,7 @@ public static boolean testBiome(FactoryJsonObject condition, org.bukkit.block.Bi
Registrar<BiomeConditions.ConditionFactory> 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.
}
Expand All @@ -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<BiomeConditions.ConditionFactory> 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<Biome, BlockPos>(CraftBiome.bukkitToMinecraft(biome), CraftLocation.toBlockPosition(blockPos))));
return getPossibleInvert(invert, con.test(condition, new oshi.util.tuples.Pair<Biome, BlockPos>(nmsBiome, CraftLocation.toBlockPosition(blockPos))));
} else {
return getPossibleInvert(invert, true); // Condition null or not found.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(":")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.concurrent.ConcurrentHashMap;

public class AsyncUpgradeTracker implements Listener {
public static ConcurrentHashMap<Origin, TriPair/*String advancement, NamespacedKey identifier, String announcement*/> upgrades = new ConcurrentHashMap<>();
public static ConcurrentHashMap<Origin, TriPair<String, NamespacedKey, String>/*String advancement, NamespacedKey identifier, String announcement*/> upgrades = new ConcurrentHashMap<>();
public static String NO_ANNOUNCEMENT = "no_announcement_found";

@EventHandler
Expand All @@ -33,13 +33,13 @@ public void startEvent(ServerLoadEvent e) {
@Override
public void run() {
MinecraftServer server = GenesisMC.server;
for (Map.Entry<Origin, TriPair> entry : upgrades.entrySet()) {
for (Map.Entry<Origin, TriPair<String, NamespacedKey, String>> 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) {
Expand Down

0 comments on commit 9d0f943

Please sign in to comment.