This commit is contained in:
luk
2026-02-17 20:23:46 +00:00
parent f4e38945fc
commit d076e75b10
2 changed files with 114 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
package com.hypixel.hytale.component;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class Ref<ECS_TYPE> {
public static final Ref<?>[] EMPTY_ARRAY = new Ref[0];
@Nonnull
private final Store<ECS_TYPE> store;
private volatile int index;
private volatile Throwable invalidatedBy;
public Ref(@Nonnull Store<ECS_TYPE> store) {
this(store, Integer.MIN_VALUE);
}
public Ref(@Nonnull Store<ECS_TYPE> store, int index) {
this.store = store;
this.index = index;
}
@Nonnull
public Store<ECS_TYPE> 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<ECS_TYPE> 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<ECS_TYPE>) other).index == index;
} else {
return false;
}
}
}

View File

@@ -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<WorldConfig> 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<Void> 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() {
}
}
}