Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed May 25, 2024
1 parent 0c1b29b commit 3948746
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
8 changes: 6 additions & 2 deletions calio/src/main/java/me/dueris/calio/CraftCalio.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ public void register(Class<? extends FactoryHolder> holder) {
}
}

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));
}

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));
keys.add(new AccessorKey(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));
keys.add(new AccessorKey(directory, priority, useTypeDefiner, registryKey, null, null));
}
}
14 changes: 14 additions & 0 deletions calio/src/main/java/me/dueris/calio/data/AccessorKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
import me.dueris.calio.registry.Registrable;
import me.dueris.calio.registry.RegistryKey;

import javax.annotation.Nullable;

public class AccessorKey<T extends Registrable> {
private final String directory;
private final boolean usesTypeDefiner;
private final int priority;
private final RegistryKey<T> registryKey;
private Class<? extends FactoryHolder> ofType;
private String defaultType;

public AccessorKey(String directory, int priority, boolean usesTypeDefiner, RegistryKey<T> registryKey) {
this.directory = directory;
this.usesTypeDefiner = usesTypeDefiner;
this.ofType = null;
this.defaultType = null;
this.priority = priority;
this.registryKey = registryKey;
}
Expand All @@ -23,6 +27,11 @@ public AccessorKey(String directory, int priority, boolean usesTypeDefiner, Regi
this.ofType = ofType;
}

public AccessorKey(String directory, int priority, boolean usesTypeDefiner, RegistryKey<T> registryKey, Class<? extends FactoryHolder> ofType, @Nullable String defaultType) {
this(directory, priority, usesTypeDefiner, registryKey, ofType);
this.defaultType = defaultType;
}

public String getDirectory() {
return directory;
}
Expand All @@ -42,4 +51,9 @@ public int getPriority() {
public RegistryKey<T> getRegistryKey() {
return this.registryKey;
}

@Nullable
public String getDefaultType() {
return defaultType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ public static FactoryHolder initilize(Pair<JsonObject, NamespacedKey> pair, Acce
FactoryData data;
Class<? extends FactoryHolder> holder;
if (accessorKey.usesTypeDefiner()) {
if (!CraftCalio.INSTANCE.types.containsKey(NamespacedKey.fromString(pair.getFirst().get("type").getAsString()))) {
String type = pair.getFirst().has("type") ? pair.getFirst().get("type").getAsString() : accessorKey.getDefaultType();
if (!CraftCalio.INSTANCE.types.containsKey(NamespacedKey.fromString(type))) {
CraftCalio.INSTANCE.getLogger().severe("Unknown type was provided! : {a} | {b}"
.replace("{a}", NamespacedKey.fromString(pair.getFirst().get("type").getAsString()).asString())
.replace("{b}", key.asString())
);
return null;
} else {
data = CraftCalio.INSTANCE.types.get(NamespacedKey.fromString(pair.getFirst().get("type").getAsString())).getFirst();
holder = CraftCalio.INSTANCE.types.get(NamespacedKey.fromString(pair.getFirst().get("type").getAsString())).getSecond();
data = CraftCalio.INSTANCE.types.get(NamespacedKey.fromString(type)).getFirst();
holder = CraftCalio.INSTANCE.types.get(NamespacedKey.fromString(type)).getSecond();
}
} else {
// We gotta invoke the FactoryData manually
Expand Down
2 changes: 1 addition & 1 deletion origins/src/main/java/me/dueris/genesismc/GenesisMC.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public String right() {
calio.registerAccessor(
"powers", 0,
true, PowerType.class,
Registries.CRAFT_POWER
Registries.CRAFT_POWER, "apoli:simple"
);
calio.registerAccessor(
"origins", 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

public class OriginScheduler {
final Plugin plugin;
private final ConcurrentLinkedQueue<Runnable> mainThreadCalls = new ConcurrentLinkedQueue<>();

public void scheduleMainThreadCall(Runnable run){
mainThreadCalls.add(run);
}

public OriginScheduler(Plugin plugin) {
this.plugin = plugin;
Expand All @@ -34,6 +41,8 @@ public String toString() {

@Override
public void run() {
this.parent.mainThreadCalls.forEach(Runnable::run);
this.parent.mainThreadCalls.clear();
for (PowerType power : CraftApoli.getPowersFromRegistry()) {
power.tick(); // Allow powers to add their own BukkitRunnables
if (!power.hasPlayers()) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static void open(Player player, Layer layer, boolean inOrbChoosing) {
);

gui.setContents(layerPages.get(layer).get(currentDisplayingPage.getInt(player)).createDisplay(player, layer));
player.getBukkitEntity().openInventory(gui);
GenesisMC.scheduler.parent.scheduleMainThreadCall(() -> player.getBukkitEntity().openInventory(gui));
}

public static void open(org.bukkit.entity.Player player, Layer layer, boolean inOrbChoosing) {
Expand Down

0 comments on commit 3948746

Please sign in to comment.