From d076e75b10ec36d09571ac529118c2492df833f4 Mon Sep 17 00:00:00 2001 From: luk Date: Tue, 17 Feb 2026 20:23:46 +0000 Subject: [PATCH] dev --- src/com/hypixel/hytale/component/Ref.java | 76 +++++++++++++++++++ .../universe/world/WorldConfigProvider.java | 38 ++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/com/hypixel/hytale/component/Ref.java create mode 100644 src/com/hypixel/hytale/server/core/universe/world/WorldConfigProvider.java diff --git a/src/com/hypixel/hytale/component/Ref.java b/src/com/hypixel/hytale/component/Ref.java new file mode 100644 index 00000000..8be6625d --- /dev/null +++ b/src/com/hypixel/hytale/component/Ref.java @@ -0,0 +1,76 @@ +package com.hypixel.hytale.component; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class Ref { + public static final Ref[] EMPTY_ARRAY = new Ref[0]; + @Nonnull + private final Store store; + private volatile int index; + private volatile Throwable invalidatedBy; + + public Ref(@Nonnull Store store) { + this(store, Integer.MIN_VALUE); + } + + public Ref(@Nonnull Store store, int index) { + this.store = store; + this.index = index; + } + + @Nonnull + public Store getStore() { + return this.store; + } + + public int getIndex() { + return this.index; + } + + void setIndex(int index) { + this.index = index; + } + + void invalidate() { + this.index = Integer.MIN_VALUE; + this.invalidatedBy = new Throwable(); + } + + void invalidate(@Nullable Throwable invalidatedBy) { + this.index = Integer.MIN_VALUE; + this.invalidatedBy = invalidatedBy != null ? invalidatedBy : new Throwable(); + } + + public void validate(@Nonnull Store store) { + if (this.store != store) { + throw new IllegalStateException("Incorrect store for entity reference"); + } else if (this.index == Integer.MIN_VALUE) { + throw new IllegalStateException("Invalid entity reference!", this.invalidatedBy); + } + } + + public void validate() { + if (this.index == Integer.MIN_VALUE) { + throw new IllegalStateException("Invalid entity reference!", this.invalidatedBy); + } + } + + public boolean isValid() { + return this.index != Integer.MIN_VALUE; + } + + @Nonnull + @Override + public String toString() { + return "Ref{store=" + this.store.getClass() + "@" + this.store.hashCode() + ", index=" + this.index + "}"; + } + + public boolean equals(Object other) { + if (other instanceof Ref) { + return ((Ref) other).index == index; + } else { + return false; + } + } +} diff --git a/src/com/hypixel/hytale/server/core/universe/world/WorldConfigProvider.java b/src/com/hypixel/hytale/server/core/universe/world/WorldConfigProvider.java new file mode 100644 index 00000000..0184898e --- /dev/null +++ b/src/com/hypixel/hytale/server/core/universe/world/WorldConfigProvider.java @@ -0,0 +1,38 @@ +package com.hypixel.hytale.server.core.universe.world; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.CompletableFuture; +import javax.annotation.Nonnull; + +public interface WorldConfigProvider { + @Nonnull + default CompletableFuture load(@Nonnull Path savePath, String name) { + Path oldPath = savePath.resolve("config.bson"); + Path path = savePath.resolve("config.json"); + if (Files.exists(oldPath) && !Files.exists(path)) { + try { + Files.move(oldPath, path); + } catch (IOException var6) { + } + } + + return WorldConfig.load(path); + } + + @Nonnull + default CompletableFuture save(@Nonnull Path savePath, WorldConfig config, World world) { + try { + return WorldConfig.save(savePath.resolve("config.json"), config); + } catch (Exception e) { + e.printStackTrace(); + return CompletableFuture.completedFuture(null); + } + } + + public static class Default implements WorldConfigProvider { + public Default() { + } + } +}