ensure order

This commit is contained in:
sunmisc 2024-11-28 01:19:56 +03:00
parent 9b3c74237b
commit 368bd884f4
6 changed files with 36 additions and 28 deletions

View file

@ -2,6 +2,7 @@ package org.bukkit;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.List;
import java.util.Map;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
@ -384,7 +385,7 @@ public final class FireworkEffect implements ConfigurationSerializable {
@NotNull
@Override
public Map<String, Object> serialize() {
return Map.of(
return ImmutableMap.<String, Object>of(
FLICKER, flicker,
TRAIL, trail,
COLORS, colors,

View file

@ -2,11 +2,12 @@ package org.bukkit;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import java.util.*;
import java.util.function.Function;
import com.google.common.collect.ImmutableMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.bukkit.advancement.Advancement;
@ -404,12 +405,15 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
}
protected SimpleRegistry(@NotNull Class<T> type, @NotNull Predicate<T> predicate) {
this.map = Arrays.stream(type.getEnumConstants())
.filter(predicate)
.collect(Collectors.toUnmodifiableMap(
Keyed::getKey,
Function.identity())
);
ImmutableMap.Builder<NamespacedKey, T> builder = ImmutableMap.builder();
for (T entry : type.getEnumConstants()) {
if (predicate.test(entry)) {
builder.put(entry.getKey(), entry);
}
}
map = builder.build();
this.type = type;
}

View file

@ -1,6 +1,7 @@
package org.bukkit.block.banner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.NoSuchElementException;
import org.bukkit.Bukkit;
@ -63,7 +64,7 @@ public class Pattern implements ConfigurationSerializable {
@NotNull
@Override
public Map<String, Object> serialize() {
return Map.of(
return ImmutableMap.<String, Object>of(
COLOR, color.toString(),
PATTERN, pattern.getKey().toString()
);

View file

@ -1,11 +1,10 @@
package org.bukkit.event.inventory;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.bukkit.Location;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
@ -73,10 +72,11 @@ public class InventoryDragEvent extends InventoryInteractEvent {
this.newCursor = newCursor;
this.oldCursor = oldCursor;
this.addedItems = slots;
this.containerSlots = slots.keySet()
.stream()
.map(what::convertSlot)
.collect(Collectors.toUnmodifiableSet());
ImmutableSet.Builder<Integer> b = ImmutableSet.builder();
for (Integer slot : slots.keySet()) {
b.add(what.convertSlot(slot));
}
this.containerSlots = b.build();
}
/**

View file

@ -2,6 +2,7 @@ package org.bukkit.plugin;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.io.InputStream;
import java.io.Reader;
import java.io.Writer;
@ -1126,7 +1127,7 @@ public final class PluginDescriptionFile {
}
contributors = contributorsBuilder.build();
} else {
contributors = List.<String>of();
contributors = List.of();
}
if (map.get("default-permission") != null) {
@ -1148,7 +1149,7 @@ public final class PluginDescriptionFile {
} catch (ClassCastException ex) {
throw new InvalidDescriptionException(ex, "awareness has wrong type");
}
this.awareness = Set.copyOf(awareness);
this.awareness = ImmutableSet.copyOf(awareness);
}
if (map.get("api-version") != null) {

View file

@ -1,6 +1,7 @@
package org.bukkit.potion;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.NoSuchElementException;
import org.bukkit.Bukkit;
@ -142,14 +143,14 @@ public class PotionEffect implements ConfigurationSerializable {
@Override
@NotNull
public Map<String, Object> serialize() {
return Map.of(
TYPE, type.getKey().toString(),
DURATION, duration,
AMPLIFIER, amplifier,
AMBIENT, ambient,
PARTICLES, particles,
ICON, icon
);
return ImmutableMap.<String, Object>builder()
.put(TYPE, type.getKey().toString())
.put(DURATION, duration)
.put(AMPLIFIER, amplifier)
.put(AMBIENT, ambient)
.put(PARTICLES, particles)
.put(ICON, icon)
.build();
}