Skip to content

Commit

Permalink
cleanup, deduplicate, drop old versions from runServer task
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreSchwang committed Nov 3, 2024
1 parent eb1845c commit e9447f0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 257 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ allprojects {
}

applyCommonConfiguration()
val supportedVersions = listOf("1.19.4", "1.20", "1.20.4", "1.20.5", "1.20.6", "1.21", "1.21.1", "1.21.3")
val supportedVersions = listOf("1.20.4", "1.20.5", "1.20.6", "1.21", "1.21.1", "1.21.3")

tasks {
supportedVersions.forEach {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ rootProject.name = "FastAsyncWorldEdit"

include("worldedit-libs")

listOf("1_20_2", "1_20_4", "1_20_5", "1_21").forEach {
listOf("1_20_2", "1_20_4", "1_20_5", "1_21", "1_21_3").forEach {
include("worldedit-bukkit:adapters:adapter-$it")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_21_3.PaperweightFaweAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.Watchdog;
import com.sk89q.worldedit.extent.Extent;
Expand All @@ -42,10 +43,6 @@
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.state.BooleanProperty;
import com.sk89q.worldedit.registry.state.DirectionalProperty;
import com.sk89q.worldedit.registry.state.EnumProperty;
import com.sk89q.worldedit.registry.state.IntegerProperty;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.SideEffect;
Expand Down Expand Up @@ -85,8 +82,6 @@
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.progress.ChunkProgressListener;
import net.minecraft.util.RandomSource;
import net.minecraft.util.StringRepresentable;
import net.minecraft.util.thread.BlockableEventLoop;
import net.minecraft.world.Clearable;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -144,7 +139,6 @@
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.LinTagType;
import org.jetbrains.annotations.NotNull;
import org.spigotmc.SpigotConfig;
import org.spigotmc.WatchdogThread;

Expand All @@ -159,7 +153,6 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.OptionalInt;
Expand Down Expand Up @@ -561,32 +554,7 @@ public Component getRichItemName(BaseItemStack itemStack) {
}

private static final LoadingCache<net.minecraft.world.level.block.state.properties.Property<?>, Property<?>> PROPERTY_CACHE =
CacheBuilder
.newBuilder()
.build(new CacheLoader<>() {
@Override
public @NotNull Property<?> load(net.minecraft.world.level.block.state.properties.@NotNull Property<?> state) {
return switch (state) {
case net.minecraft.world.level.block.state.properties.BooleanProperty booleanProperty ->
new BooleanProperty(booleanProperty.getName(), booleanProperty.getPossibleValues());
case net.minecraft.world.level.block.state.properties.IntegerProperty integerProperty ->
new IntegerProperty(integerProperty.getName(), integerProperty.getPossibleValues());
case net.minecraft.world.level.block.state.properties.EnumProperty<?> enumProperty -> {
if (enumProperty.getValueClass() == net.minecraft.core.Direction.class) {
yield new DirectionalProperty(enumProperty.getName(), enumProperty.getPossibleValues().stream()
.map(StringRepresentable::getSerializedName)
.map(s -> s.toUpperCase(Locale.ROOT))
.map(Direction::valueOf)
.toList()
);
}
yield new EnumProperty(enumProperty.getName(), enumProperty.getPossibleValues().stream()
.map(StringRepresentable::getSerializedName).collect(Collectors.toCollection(ArrayList::new)));
}
default -> throw new IllegalArgumentException("WorldEdit needs an update to support " + state.getClass().getSimpleName());
};
}
});
CacheBuilder.newBuilder().build(CacheLoader.from(PaperweightFaweAdapter::adaptProperty));

@SuppressWarnings({ "rawtypes" })
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_21_3.PaperweightAdapter;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_21_3.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_21_3.regen.PaperweightRegen;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extent.Extent;
Expand Down Expand Up @@ -90,8 +89,8 @@
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -147,10 +146,30 @@ public Function<BlockEntity, FaweCompoundTag> blockEntityToCompoundTag() {
);
}

@Nullable
private static String getEntityId(Entity entity) {
ResourceLocation resourceLocation = net.minecraft.world.entity.EntityType.getKey(entity.getType());
return resourceLocation == null ? null : resourceLocation.toString();
public static Property<?> adaptProperty(net.minecraft.world.level.block.state.properties.Property<?> property) {
return switch (property) {
case net.minecraft.world.level.block.state.properties.BooleanProperty booleanProperty ->
new BooleanProperty(booleanProperty.getName(), ImmutableList.copyOf(booleanProperty.getPossibleValues()));
case net.minecraft.world.level.block.state.properties.IntegerProperty integerProperty ->
new IntegerProperty(integerProperty.getName(), ImmutableList.copyOf(integerProperty.getPossibleValues()));
case net.minecraft.world.level.block.state.properties.EnumProperty<?> enumProperty -> {
if (enumProperty.getValueClass() == net.minecraft.core.Direction.class) {
yield new DirectionalProperty(enumProperty.getName(), enumProperty.getPossibleValues().stream()
.map(StringRepresentable::getSerializedName)
.map(s -> s.toUpperCase(Locale.ROOT))
.map(Direction::valueOf)
.toList()
);
}
yield new EnumProperty(enumProperty.getName(), enumProperty.getPossibleValues().stream()
.map(StringRepresentable::getSerializedName).collect(Collectors.toCollection(ArrayList::new)));
}
default -> throw new IllegalArgumentException("FastAsyncWorldEdit needs an update to support " + property.getClass().getSimpleName());
};
}

private static @NotNull String getEntityId(Entity entity) {
return net.minecraft.world.entity.EntityType.getKey(entity.getType()).toString();
}

private static void readEntityIntoTag(Entity entity, net.minecraft.nbt.CompoundTag compoundTag) {
Expand Down Expand Up @@ -183,40 +202,7 @@ private synchronized boolean init() {
if (!(obj instanceof net.minecraft.world.level.block.state.properties.Property<?> state)) {
continue;
}
Property<?> property;
if (state instanceof net.minecraft.world.level.block.state.properties.BooleanProperty) {
property = new BooleanProperty(
state.getName(),
(List<Boolean>) ImmutableList.copyOf(state.getPossibleValues())
);
} else if (state instanceof net.minecraft.world.level.block.state.properties.EnumProperty<?> enumProperty) {
if (enumProperty.getValueClass() == net.minecraft.core.Direction.class) {
property = new DirectionalProperty(enumProperty.getName(), enumProperty.getPossibleValues().stream()
.map(StringRepresentable::getSerializedName)
.map(s -> s.toUpperCase(Locale.ROOT))
.map(Direction::valueOf)
.toList()
);
} else {
property = new EnumProperty(
state.getName(),
state
.getPossibleValues()
.stream()
.map(e -> ((StringRepresentable) e).getSerializedName())
.collect(Collectors.toCollection(ArrayList::new))
);
}
} else if (state instanceof net.minecraft.world.level.block.state.properties.IntegerProperty) {
property = new IntegerProperty(
state.getName(),
(List<Integer>) ImmutableList.copyOf(state.getPossibleValues())
);
} else {
throw new IllegalArgumentException("FastAsyncWorldEdit needs an update to support " + state
.getClass()
.getSimpleName());
}
Property<?> property = adaptProperty(state);
properties.compute(property.getName().toLowerCase(Locale.ROOT), (k, v) -> {
if (v == null) {
v = new ArrayList<>(Collections.singletonList(property));
Expand All @@ -227,7 +213,7 @@ private synchronized boolean init() {
});
}
} catch (IllegalAccessException e) {
e.printStackTrace();
LOGGER.error("failed to initialize block states", e);
} finally {
allBlockProperties = ImmutableMap.copyOf(properties);
}
Expand Down Expand Up @@ -320,22 +306,18 @@ public BaseEntity getEntity(org.bukkit.entity.Entity entity) {
Entity mcEntity = craftEntity.getHandle();

String id = getEntityId(mcEntity);
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
Supplier<LinCompoundTag> saveTag = () -> {
final net.minecraft.nbt.CompoundTag minecraftTag = new net.minecraft.nbt.CompoundTag();
readEntityIntoTag(mcEntity, minecraftTag);
//add Id for AbstractChangeSet to work
final LinCompoundTag tag = (LinCompoundTag) toNativeLin(minecraftTag);
final Map<String, LinTag<?>> tags = NbtUtils.getLinCompoundTagValues(tag);
tags.put("Id", LinStringTag.of(id));
return LinCompoundTag.of(tags);
};
return new LazyBaseEntity(type, saveTag);

if (id != null) {
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
Supplier<LinCompoundTag> saveTag = () -> {
final net.minecraft.nbt.CompoundTag minecraftTag = new net.minecraft.nbt.CompoundTag();
readEntityIntoTag(mcEntity, minecraftTag);
//add Id for AbstractChangeSet to work
final LinCompoundTag tag = (LinCompoundTag) toNativeLin(minecraftTag);
final Map<String, LinTag<?>> tags = NbtUtils.getLinCompoundTagValues(tag);
tags.put("Id", LinStringTag.of(id));
return LinCompoundTag.of(tags);
};
return new LazyBaseEntity(type, saveTag);
} else {
return null;
}
}

@Override
Expand Down Expand Up @@ -506,7 +488,7 @@ public org.bukkit.inventory.ItemStack adapt(BaseItemStack baseItemStack) {
)),
baseItemStack.getAmount()
);
final CompoundTag nbt = (net.minecraft.nbt.CompoundTag) fromNative(baseItemStack.getNbtData());
final CompoundTag nbt = (net.minecraft.nbt.CompoundTag) fromNativeLin(baseItemStack.getNbt());
if (nbt != null) {
final DataComponentPatch patch = COMPONENTS_CODEC
.parse(registryAccess.createSerializationContext(NbtOps.INSTANCE), nbt)
Expand Down Expand Up @@ -561,9 +543,6 @@ public Tag toNative(net.minecraft.nbt.Tag foreign) {

@Override
public net.minecraft.nbt.Tag fromNative(Tag foreign) {
if (foreign instanceof PaperweightLazyCompoundTag) {
return ((PaperweightLazyCompoundTag) foreign).get();
}
return parent.fromNative(foreign);
}

Expand Down
Loading

0 comments on commit e9447f0

Please sign in to comment.