Skip to content

Commit ac88d95

Browse files
authored
Merge pull request #3159 from IntellectualSites/pr-3137
Upstream Updates
2 parents 4f114a6 + c6770c5 commit ac88d95

File tree

47 files changed

+998
-147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+998
-147
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ target
1616
forge-download
1717
out
1818
run
19+
.jqwik-database
1920

2021
/dependency-reduced-pom.xml
2122
*-private.sh

buildSrc/src/main/kotlin/CommonJavaConfig.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ fun Project.applyCommonJavaConfiguration(sourcesJar: Boolean, banSlf4j: Boolean
3636
}
3737

3838
tasks.withType<Test>().configureEach {
39-
useJUnitPlatform()
39+
useJUnitPlatform {
40+
includeEngines("junit-jupiter", "jqwik")
41+
}
4042
}
4143

4244
dependencies {
4345
"compileOnly"("com.google.code.findbugs:jsr305:3.0.2")
4446
"testImplementation"("org.junit.jupiter:junit-jupiter-api:5.11.1")
4547
"testImplementation"("org.junit.jupiter:junit-jupiter-params:5.11.1")
48+
"testImplementation"("net.jqwik:jqwik:1.9.0")
4649
"testImplementation"("org.mockito:mockito-core:5.14.0")
4750
"testImplementation"("org.mockito:mockito-junit-jupiter:5.14.0")
4851
"testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:5.11.1")

buildSrc/src/main/kotlin/PlatformConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fun Project.applyShadowConfiguration() {
151151

152152
val CLASSPATH = listOf("truezip", "truevfs", "js")
153153
.map { "$it.jar" }
154-
.flatMap { listOf(it, "FastAsyncWorldEdit/$it") }
154+
.flatMap { listOf(it, "FastAsyncWorldEdit/$it", "../$it", "../FastAsyncWorldEdit/$it") }
155155
.joinToString(separator = " ")
156156

157157
sealed class WorldEditKind(

worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext.fawe/v1_20_R4/PaperweightServerLevelDelegateProxy.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ private BlockEntity getBlockEntity(BlockPos blockPos) {
103103
if (tileEntity == null) {
104104
return null;
105105
}
106-
BlockEntity newEntity = tileEntity.getType().create(blockPos, getBlockState(blockPos));
107-
newEntity.loadWithComponents(
106+
tileEntity.loadWithComponents(
108107
(CompoundTag) adapter.fromNativeLin(this.editSession.getFullBlock(
109108
blockPos.getX(),
110109
blockPos.getY(),
@@ -113,7 +112,7 @@ private BlockEntity getBlockEntity(BlockPos blockPos) {
113112
this.serverLevel.registryAccess()
114113
);
115114

116-
return newEntity;
115+
return tileEntity;
117116
}
118117

119118
private BlockState getBlockState(BlockPos blockPos) {

worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext/fawe/v1_21_R1/PaperweightServerLevelDelegateProxy.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ private BlockEntity getBlockEntity(BlockPos blockPos) {
103103
if (tileEntity == null) {
104104
return null;
105105
}
106-
BlockEntity newEntity = tileEntity.getType().create(blockPos, getBlockState(blockPos));
107-
newEntity.loadWithComponents(
106+
tileEntity.loadWithComponents(
108107
(CompoundTag) adapter.fromNativeLin(this.editSession.getFullBlock(
109108
blockPos.getX(),
110109
blockPos.getY(),
@@ -113,7 +112,7 @@ private BlockEntity getBlockEntity(BlockPos blockPos) {
113112
this.serverLevel.registryAccess()
114113
);
115114

116-
return newEntity;
115+
return tileEntity;
117116
}
118117

119118
private BlockState getBlockState(BlockPos blockPos) {

worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext/fawe/v1_21_4/PaperweightServerLevelDelegateProxy.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ private BlockEntity getBlockEntity(BlockPos blockPos) {
103103
if (tileEntity == null) {
104104
return null;
105105
}
106-
BlockEntity newEntity = tileEntity.getType().create(blockPos, getBlockState(blockPos));
107-
newEntity.loadWithComponents(
106+
tileEntity.loadWithComponents(
108107
(CompoundTag) adapter.fromNativeLin(this.editSession.getFullBlock(
109108
blockPos.getX(),
110109
blockPos.getY(),
@@ -113,7 +112,7 @@ private BlockEntity getBlockEntity(BlockPos blockPos) {
113112
this.serverLevel.registryAccess()
114113
);
115114

116-
return newEntity;
115+
return tileEntity;
117116
}
118117

119118
private BlockState getBlockState(BlockPos blockPos) {

worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,8 @@ default Entity adapt(org.bukkit.entity.Entity entity) {
166166
*/
167167
default Material adapt(ItemType itemType) {
168168
checkNotNull(itemType);
169-
if (!itemType.id().startsWith("minecraft:")) {
170-
throw new IllegalArgumentException("Bukkit only supports Minecraft items");
171-
}
172-
return Material.getMaterial(itemType.id().substring(10).toUpperCase(Locale.ROOT));
169+
NamespacedKey key = checkNotNull(NamespacedKey.fromString(itemType.id()), "Item type key is invalid");
170+
return Registry.MATERIAL.get(key);
173171
}
174172

175173
/**
@@ -180,11 +178,8 @@ default Material adapt(ItemType itemType) {
180178
*/
181179
default Material adapt(BlockType blockType) {
182180
checkNotNull(blockType);
183-
if (!blockType.id().startsWith("minecraft:")) {
184-
throw new IllegalArgumentException("Bukkit only supports Minecraft blocks");
185-
}
186-
String id = blockType.id().substring(10).toUpperCase(Locale.ROOT);
187-
return Material.getMaterial(id);
181+
NamespacedKey key = checkNotNull(NamespacedKey.fromString(blockType.id()), "Block type key is invalid");
182+
return Registry.MATERIAL.get(key);
188183
}
189184

190185
default org.bukkit.entity.EntityType adapt(EntityType entityType) {

worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252

5353
import javax.annotation.Nonnull;
5454
import javax.annotation.Nullable;
55-
import java.util.EnumMap;
5655
import java.util.HashMap;
5756
import java.util.Map;
5857
import java.util.Objects;
58+
import java.util.concurrent.ConcurrentHashMap;
5959

6060
import static com.google.common.base.Preconditions.checkNotNull;
6161

@@ -83,6 +83,7 @@ private static IBukkitAdapter getAdapter() {
8383

8484
static {
8585
TO_BLOCK_CONTEXT.setRestricted(false);
86+
TO_BLOCK_CONTEXT.setTryLegacy(false);
8687
}
8788

8889
/**
@@ -366,6 +367,9 @@ public static GameMode adapt(org.bukkit.GameMode gameMode) {
366367
//FAWE end
367368
}
368369

370+
private static final Map<Biome, BiomeType> biomeBiomeTypeCache = new ConcurrentHashMap<>();
371+
private static final Map<BiomeType, Biome> biomeTypeBiomeCache = new ConcurrentHashMap<>();
372+
369373
/**
370374
* Create a WorldEdit BiomeType from a Bukkit one.
371375
*
@@ -402,8 +406,8 @@ public static org.bukkit.entity.EntityType adapt(EntityType entityType) {
402406
//FAWE end
403407
}
404408

405-
private static final EnumMap<Material, BlockType> materialBlockTypeCache = new EnumMap<>(Material.class);
406-
private static final EnumMap<Material, ItemType> materialItemTypeCache = new EnumMap<>(Material.class);
409+
private static final Map<Material, BlockType> materialBlockTypeCache = new ConcurrentHashMap<>();
410+
private static final Map<Material, ItemType> materialItemTypeCache = new ConcurrentHashMap<>();
407411

408412
/**
409413
* Converts a Material to a BlockType.

worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
2929
import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial;
3030
import org.bukkit.Material;
31-
import org.bukkit.block.data.BlockData;
32-
3331
import javax.annotation.Nullable;
34-
import java.util.ArrayList;
3532
import java.util.Collection;
3633
import java.util.List;
3734
import java.util.Map;

worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,10 @@ private void initializeRegistries() {
312312
/*
313313
314314
// Block & Item
315-
for (Material material : Material.values()) {
316-
if (material.isBlock() && !material.isLegacy()) {
317-
BlockType.REGISTRY.register(material.getKey().toString(), new BlockType(material.getKey().toString(), blockState -> {
315+
Registry.MATERIAL.forEach(material -> {
316+
String key = material.getKey().toString();
317+
if (material.isBlock()) {
318+
BlockType.REGISTRY.register(key, new BlockType(key, blockState -> {
318319
// TODO Use something way less hacky than this.
319320
ParserContext context = new ParserContext();
320321
context.setPreferringWildcard(true);
@@ -331,13 +332,13 @@ private void initializeRegistries() {
331332
}
332333
return defaultState;
333334
} catch (InputParseException e) {
334-
LOGGER.warn("Error loading block state for " + material.getKey(), e);
335+
LOGGER.warn("Error loading block state for " + key, e);
335336
return blockState;
336337
}
337338
}));
338339
}
339-
if (material.isItem() && !material.isLegacy()) {
340-
ItemType.REGISTRY.register(material.getKey().toString(), new ItemType(material.getKey().toString()));
340+
if (material.isItem()) {
341+
ItemType.REGISTRY.register(key, new ItemType(key));
341342
}
342343
}
343344
*/
@@ -359,10 +360,12 @@ private void setupTags() {
359360
// Tags
360361
try {
361362
for (Tag<Material> blockTag : Bukkit.getTags(Tag.REGISTRY_BLOCKS, Material.class)) {
362-
BlockCategory.REGISTRY.register(blockTag.getKey().toString(), new BlockCategory(blockTag.getKey().toString()));
363+
String key = blockTag.getKey().toString();
364+
BlockCategory.REGISTRY.register(key, new BlockCategory(blockTag.getKey().toString()));
363365
}
364366
for (Tag<Material> itemTag : Bukkit.getTags(Tag.REGISTRY_ITEMS, Material.class)) {
365-
ItemCategory.REGISTRY.register(itemTag.getKey().toString(), new ItemCategory(itemTag.getKey().toString()));
367+
String key = itemTag.getKey().toString();
368+
ItemCategory.REGISTRY.register(key, new ItemCategory(itemTag.getKey().toString()));
366369
}
367370
} catch (NoSuchMethodError ignored) {
368371
LOGGER.warn(

0 commit comments

Comments
 (0)