convert a bunch of stuff to new APIs

This commit is contained in:
dfsek
2025-12-29 21:11:11 -07:00
parent 16705057e0
commit 9a16336f53
29 changed files with 167 additions and 87 deletions

View File

@@ -42,7 +42,7 @@ public class AllayPlatform extends AbstractPlatform {
boolean succeed = loadConfigPacks();
GENERATOR_WRAPPERS.forEach(wrapper -> {
getConfigRegistry().get(wrapper.getConfigPack().getRegistryKey()).ifPresent(pack -> {
getConfigRegistry().get(wrapper.getConfigPack().getRegistryKey()).consume(pack -> {
wrapper.setConfigPack(pack);
var dimension = wrapper.getAllayWorldGenerator().getDimension();
TerraAllayPlugin.instance.getPluginLogger().info(

View File

@@ -1,5 +1,7 @@
package com.dfsek.terra.allay.generator;
import com.dfsek.terra.api.util.function.FunctionUtils;
import com.google.common.base.Preconditions;
import org.allaymc.api.utils.AllayStringUtils;
import org.allaymc.api.world.biome.BiomeType;
@@ -24,6 +26,8 @@ import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
import com.dfsek.terra.api.world.info.WorldProperties;
import java.util.function.Function;
/**
* @author daoge_cmd
@@ -91,14 +95,16 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
return TerraAllayPlugin.platform
.getConfigRegistry()
.getByID(packId)
.orElseThrow(() -> new IllegalArgumentException("Cant find terra config pack named " + packId));
.collectThrow(
left -> new IllegalArgumentException("Cant find terra config pack named " + packId + ": " + left));
}
protected static ConfigPack getConfigPackByMeta(String metaPackId, DimensionInfo dimensionInfo) {
return TerraAllayPlugin.platform
.getMetaConfigRegistry()
.getByID(metaPackId)
.orElseThrow(() -> new IllegalArgumentException("Cant find terra meta pack named " + metaPackId))
.collectThrow(
left -> new IllegalArgumentException("Cant find terra meta pack named " + metaPackId + ": " + left))
.packs()
.get(Mapping.dimensionIdBeToJe(dimensionInfo.toString()));
}

View File

@@ -1,5 +1,7 @@
package com.dfsek.terra.bukkit;
import com.dfsek.terra.api.util.generic.data.types.Maybe;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.ChatColor;
@@ -24,19 +26,19 @@ public class CloudCommandSender implements CommandSender {
}
@Override
public Optional<Entity> getEntity() {
public Maybe<Entity> getEntity() {
if(delegate instanceof org.bukkit.entity.Entity entity) {
return Optional.of(BukkitAdapter.adapt(entity));
return Maybe.just(BukkitAdapter.adapt(entity));
}
return Optional.empty();
return Maybe.nothing();
}
@Override
public Optional<Player> getPlayer() {
public Maybe<Player> getPlayer() {
if(delegate instanceof org.bukkit.entity.Player player) {
return Optional.of(BukkitAdapter.adapt(player));
return Maybe.just(BukkitAdapter.adapt(player));
}
return Optional.empty();
return Maybe.nothing();
}
@Override

View File

@@ -73,7 +73,7 @@ public class PlatformImpl extends AbstractPlatform {
Bukkit.getWorlds().forEach(world -> {
if(world.getGenerator() instanceof BukkitChunkGeneratorWrapper wrapper) {
getConfigRegistry().get(wrapper.getPack().getRegistryKey()).ifPresent(pack -> {
getConfigRegistry().get(wrapper.getPack().getRegistryKey()).consume(pack -> {
wrapper.setPack(pack);
LOGGER.info("Replaced pack in chunk generator for world {}", world);
});

View File

@@ -182,10 +182,10 @@ public class TerraBukkitPlugin extends JavaPlugin {
ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String id) {
if(id == null || id.trim().isEmpty()) { return null; }
return new BukkitChunkGeneratorWrapper(generatorMap.computeIfAbsent(worldName, name -> {
ConfigPack pack = platform.getConfigRegistry().getByID(id).orElseThrow(
() -> new IllegalArgumentException("No such config pack \"" + id + "\""));
ConfigPack pack = platform.getConfigRegistry().getByID(id).collectThrow(
left -> new IllegalArgumentException("No such config pack \"" + id + "\": " + left));
return pack.getGeneratorProvider().newInstance(pack);
}), platform.getRawConfigRegistry().getByID(id).orElseThrow(), platform.getWorldHandle().air());
}), platform.getRawConfigRegistry().getByID(id).collectThrow(RuntimeException::new), platform.getWorldHandle().air());
}
public AsyncScheduler getAsyncScheduler() {

View File

@@ -80,7 +80,7 @@ public class CommonListener implements Listener {
return;
}
ConfigPack pack = platform.getConfigRegistry().get(wrapper.getPack().getRegistryKey()).orElse(null);
ConfigPack pack = platform.getConfigRegistry().get(wrapper.getPack().getRegistryKey()).get((ConfigPack) null);
if(pack == null) {
return;
}

View File

@@ -51,7 +51,7 @@ public final class TerraCLI implements Callable<Integer> {
CLIPlatform platform = new CLIPlatform();
platform.getEventManager().callEvent(new PlatformInitializationEvent());
ConfigPack generate = platform.getConfigRegistry().getByID(pack).orElseThrow();
ConfigPack generate = platform.getConfigRegistry().getByID(pack).collectThrow(RuntimeException::new);
CLIWorld world = new CLIWorld(size, seed, maxHeight, minHeight, generate, noSave);

View File

@@ -95,7 +95,7 @@ public final class TerraMinestomPlatform extends AbstractPlatform {
MinecraftServer.getInstanceManager().getInstances().forEach(world -> {
if(world.generator() instanceof MinestomChunkGeneratorWrapper wrapper) {
getConfigRegistry().get(wrapper.getPack().getRegistryKey()).ifPresent(pack -> {
getConfigRegistry().get(wrapper.getPack().getRegistryKey()).consume(pack -> {
wrapper.setPack(pack);
LOGGER.info("Replaced pack in chunk generator for instance {}", world.getUuid());
});

View File

@@ -39,14 +39,14 @@ public class TerraMinestomWorldBuilder {
}
public TerraMinestomWorldBuilder packById(String id) {
this.pack = platform.getConfigRegistry().getByID(id).orElseThrow();
this.pack = platform.getConfigRegistry().getByID(id).collectThrow(RuntimeException::new);
return this;
}
public TerraMinestomWorldBuilder packByMeta(String metaPack, RegistryKey<@NonNull DimensionType> dimensionType) {
this.pack = platform.getMetaConfigRegistry()
.getByID(metaPack)
.orElseThrow(() -> new RuntimeException("MetaPack " + metaPack + " could not be found"))
.collectThrow(left -> new RuntimeException("MetaPack " + metaPack + " could not be found: " + left))
.packs()
.get(dimensionType.key().asString());
return this;

View File

@@ -31,7 +31,7 @@ public final class Codecs {
.apply(config, config.stable(id -> CommonPlatform.get()
.getConfigRegistry()
.get(id)
.orElseThrow(() -> new IllegalArgumentException(
.orThrow(() -> new IllegalArgumentException(
"No such config pack " +
id)))));

View File

@@ -92,7 +92,7 @@ public abstract class LifecyclePlatform extends ModPlatform {
}).join();
server.getWorlds().forEach(world -> {
if(world.getChunkManager().getChunkGenerator() instanceof MinecraftChunkGeneratorWrapper chunkGeneratorWrapper) {
getConfigRegistry().get(chunkGeneratorWrapper.getPack().getRegistryKey()).ifPresent(pack -> {
getConfigRegistry().get(chunkGeneratorWrapper.getPack().getRegistryKey()).consume(pack -> {
chunkGeneratorWrapper.setPack(pack);
LOGGER.info("Replaced pack in chunk generator for world {}", world);
});