Skip to content

Commit afcea37

Browse files
committed
fix: don't throw exception in LinOps#getList + cleanup
1 parent 64c049d commit afcea37

File tree

3 files changed

+33
-37
lines changed

3 files changed

+33
-37
lines changed

worldedit-bukkit/adapters/adapter-1_21_11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_11/LinOps.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ public LinTag<?> empty() {
6363
return LinEndTag.instance();
6464
}
6565

66+
@Override
67+
public LinTag<?> emptyList() {
68+
return LinListTag.empty(LinTagType.endTag());
69+
}
70+
71+
@Override
72+
public LinTag<?> emptyMap() {
73+
return LinCompoundTag.builder().build();
74+
}
75+
6676
@Override
6777
public <U> U convertTo(final DynamicOps<U> outOps, final LinTag<?> input) {
6878
return switch (input) {
@@ -180,7 +190,7 @@ public DataResult<Stream<Pair<LinTag<?>, LinTag<?>>>> getMapValues(final LinTag<
180190
.stream()
181191
.map(entry -> Pair.of(this.createString(entry.getKey()), entry.getValue())));
182192
}
183-
return DataResult.error(() -> "Not a map");
193+
return DataResult.error(() -> "Not a map: " + input);
184194
}
185195

186196
@Override
@@ -189,7 +199,7 @@ public DataResult<Consumer<BiConsumer<LinTag<?>, LinTag<?>>>> getMapEntries(fina
189199
return DataResult.success(consumer ->
190200
tag.value().forEach((s, linTag) -> consumer.accept(this.createString(s), linTag)));
191201
}
192-
return DataResult.error(() -> "Not a map");
202+
return DataResult.error(() -> "Not a map: " + input);
193203
}
194204

195205
@Override
@@ -321,7 +331,7 @@ public DataResult<Consumer<Consumer<LinTag<?>>>> getList(final LinTag<?> input)
321331
}
322332
});
323333
}
324-
throw new UnsupportedOperationException("Not a list: " + input);
334+
return DataResult.error(() -> "Not a list: " + input);
325335
}
326336

327337
@Override

worldedit-bukkit/adapters/adapter-1_21_11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_11/LinValueInput.java

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -307,21 +307,23 @@ public boolean isEmpty() {
307307
return new AbstractIterator<>() {
308308
@Override
309309
protected @Nullable T computeNext() {
310-
while (iterator.hasNext()) {
311-
int index = iterator.nextIndex();
312-
LinTag<?> tag = iterator.next();
313-
switch (codec.parse(context.ops(), tag)) {
314-
case DataResult.Success<T> success:
315-
return success.value();
316-
case DataResult.Error<T> error:
317-
problemReporter.report(() -> "Failed to decode value '" + tag + "' from field '" + name + "' at index " + index + ":" + " " + error);
318-
if (error.partialValue().isEmpty()) {
319-
continue;
320-
}
321-
return error.partialValue().get();
310+
while (true) {
311+
if (iterator.hasNext()) {
312+
int index = iterator.nextIndex();
313+
LinTag<?> tag = iterator.next();
314+
switch (codec.parse(context.ops(), tag)) {
315+
case DataResult.Success<T> success:
316+
return success.value();
317+
case DataResult.Error<T> error:
318+
problemReporter.report(() -> "Failed to decode value '" + tag + "' from field '" + name + "' at index " + index + ":" + " " + error);
319+
if (error.partialValue().isEmpty()) {
320+
continue;
321+
}
322+
return error.partialValue().get();
323+
}
322324
}
325+
return this.endOfData();
323326
}
324-
return this.endOfData();
325327
}
326328
};
327329
}
@@ -366,21 +368,8 @@ public boolean isEmpty() {
366368

367369
}
368370

369-
private static final class EmptyValueInput implements ValueInput {
370-
371-
private final HolderLookup.Provider lookup;
372-
private final ValueInputList emptyChildList;
373-
private final TypedInputList<Object> emptyTypedList;
374-
375-
private EmptyValueInput(
376-
final HolderLookup.Provider lookup,
377-
final ValueInputList list,
378-
final TypedInputList<Object> typedList
379-
) {
380-
this.lookup = lookup;
381-
this.emptyChildList = list;
382-
this.emptyTypedList = typedList;
383-
}
371+
private record EmptyValueInput(HolderLookup.Provider lookup, ValueInputList emptyChildList,
372+
TypedInputList<Object> emptyTypedList) implements ValueInput {
384373

385374
@Override
386375
public <T> @NonNull Optional<T> read(final @NonNull String key, final @NonNull Codec<T> codec) {
@@ -483,11 +472,6 @@ public double getDoubleOr(final @NonNull String s, final double defaultValue) {
483472
return Optional.empty();
484473
}
485474

486-
@Override
487-
public HolderLookup.@NonNull Provider lookup() {
488-
return this.lookup;
489-
}
490-
491475
}
492476

493477
}

worldedit-bukkit/adapters/adapter-1_21_11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_11/LinValueOutput.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ public boolean isEmpty() {
198198
}
199199

200200
public LinCompoundTag buildResult() {
201-
return this.toBuilder().build();
201+
return LinCompoundTag.of(this.collector.entrySet().stream()
202+
.collect(Collectors.toMap(Map.Entry::getKey, entry -> unwrapPendingEntry(entry.getValue())))
203+
);
202204
}
203205

204206
public LinCompoundTag.Builder toBuilder() {

0 commit comments

Comments
 (0)