Skip to content

Commit 36e299e

Browse files
committed
1.21.4 backport
1 parent 4d7570a commit 36e299e

File tree

5 files changed

+42
-60
lines changed

5 files changed

+42
-60
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies {
3232
implementation(libs.bstats)
3333
implementation(libs.clickhouse.jdbc)
3434

35-
compileOnly(platform("com.intellectualsites.bom:bom-newest:1.55"))
35+
compileOnly(platform("com.intellectualsites.bom:bom-newest:1.45"))
3636
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Core")
3737
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit") {
3838
exclude(group = "*", module = "FastAsyncWorldEdit-Core")

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
minecraft = "1.21.8"
2+
minecraft = "1.21.4"
33
paper = "1.21.11"
44
hikaricp = "7.0.2"
55

src/main/java/net/coreprotect/thread/NetworkHandler.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
import java.util.TreeMap;
2424
import java.util.stream.Stream;
2525

26+
import com.google.gson.JsonElement;
27+
import com.google.gson.JsonObject;
28+
import net.coreprotect.utility.serialize.JsonSerialization;
2629
import org.bukkit.Bukkit;
27-
import org.json.simple.JSONObject;
28-
import org.json.simple.parser.JSONParser;
2930

3031
import net.coreprotect.CoreProtect;
3132
import net.coreprotect.config.Config;
@@ -190,7 +191,7 @@ else if (Files.isReadable(licensePath)) {
190191
phrases.put("DATA_VERSION", pluginVersion);
191192
phrases.put("DATA_LANGUAGE", languageCode);
192193

193-
String mapString = "data=" + JSONObject.toJSONString(phrases);
194+
String mapString = "data=" + JsonSerialization.DEFAULT_GSON.toJson(phrases);
194195
mapString = mapString.replaceAll("\\+", "{PLUS_SIGN}");
195196
byte[] postData = mapString.getBytes(StandardCharsets.UTF_8);
196197
int postDataLength = postData.length;
@@ -225,12 +226,11 @@ else if (Files.isReadable(licensePath)) {
225226
String response = responseBuilder.toString();
226227
if (response.length() > 0 && response.startsWith("{") && response.endsWith("}")) {
227228
TreeMap<Phrase, String> translatedPhrases = new TreeMap<>();
228-
JSONParser parser = new JSONParser();
229-
JSONObject json = (JSONObject) parser.parse(response);
230-
for (Object jsonKey : json.keySet()) {
231-
String key = (String) jsonKey;
232-
String value = ((String) json.get(jsonKey)).trim();
233-
if (phraseSet.contains(key) && value.length() > 0) {
229+
final JsonObject json = JsonSerialization.DEFAULT_GSON.fromJson(response, JsonObject.class);
230+
for (Map.Entry<String, JsonElement> entry : json.entrySet()) {
231+
String key = entry.getKey();
232+
String value = entry.getValue().getAsString();
233+
if (phraseSet.contains(key) && !value.isEmpty()) {
234234
Phrase phrase = Phrase.valueOf(key);
235235
translatedPhrases.put(phrase, value);
236236
Language.setTranslatedPhrase(phrase, value);

src/main/java/net/coreprotect/utility/serialize/JsonEntitySerializer.java

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@
33
import ca.spottedleaf.moonrise.common.PlatformHooks;
44
import com.google.common.base.Preconditions;
55
import com.google.gson.JsonObject;
6-
import com.mojang.logging.LogUtils;
76
import com.mojang.serialization.JsonOps;
87
import io.papermc.paper.entity.EntitySerializationFlag;
98
import net.minecraft.SharedConstants;
109
import net.minecraft.nbt.CompoundTag;
10+
import net.minecraft.nbt.ListTag;
1111
import net.minecraft.nbt.NbtOps;
1212
import net.minecraft.nbt.Tag;
1313
import net.minecraft.server.MinecraftServer;
1414
import net.minecraft.server.level.ServerLevel;
15-
import net.minecraft.util.ProblemReporter;
1615
import net.minecraft.util.datafix.fixes.References;
1716
import net.minecraft.world.entity.player.Player;
18-
import net.minecraft.world.level.storage.TagValueInput;
19-
import net.minecraft.world.level.storage.TagValueOutput;
2017
import org.bukkit.World;
2118
import org.bukkit.craftbukkit.CraftWorld;
2219
import org.bukkit.craftbukkit.entity.CraftEntity;
2320
import org.bukkit.entity.Entity;
2421
import org.jetbrains.annotations.NotNull;
25-
import org.slf4j.Logger;
2622

2723
import java.util.ArrayList;
2824
import java.util.List;
@@ -31,13 +27,11 @@
3127

3228
// Based on https://github.com/Warriorrrr/Paper/commit/acba85eac5a5c37577916d4561e593d38bb0573f
3329
public class JsonEntitySerializer {
34-
private static final Logger LOGGER = LogUtils.getLogger();
35-
3630
public static @NotNull JsonObject serializeEntityAsJson(@NotNull final Entity entity, final @NotNull EntitySerializationFlag... serializationFlags) {
3731
Preconditions.checkArgument(entity != null, "entity must not be null");
3832

3933
final CompoundTag nbt = serializeEntityToNbt(entity, serializationFlags);
40-
nbt.putInt("DataVersion", SharedConstants.getCurrentVersion().dataVersion().version());
34+
nbt.putInt("DataVersion", SharedConstants.getCurrentVersion().getDataVersion().getVersion());
4135

4236
return NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, nbt).getAsJsonObject();
4337
}
@@ -57,14 +51,14 @@ private static CompoundTag serializeEntityToNbt(org.bukkit.entity.Entity entity,
5751
Preconditions.checkArgument(entity instanceof CraftEntity, "Only CraftEntities can be serialized");
5852

5953
Set<EntitySerializationFlag> flags = Set.of(serializationFlags);
60-
final boolean serializePassengers = flags.contains(EntitySerializationFlag.PASSENGERS);
54+
final boolean serializePassangers = flags.contains(EntitySerializationFlag.PASSENGERS);
6155
final boolean forceSerialization = flags.contains(EntitySerializationFlag.FORCE);
6256
final boolean allowPlayerSerialization = flags.contains(EntitySerializationFlag.PLAYER);
6357
final boolean allowMiscSerialization = flags.contains(EntitySerializationFlag.MISC);
6458
final boolean includeNonSaveable = allowPlayerSerialization || allowMiscSerialization;
6559

6660
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
67-
(serializePassengers ? nmsEntity.getSelfAndPassengers() : Stream.of(nmsEntity)).forEach(e -> {
61+
(serializePassangers ? nmsEntity.getSelfAndPassengers() : Stream.of(nmsEntity)).forEach(e -> {
6862
// Ensure force flag is not needed
6963
Preconditions.checkArgument(
7064
(e.getBukkitEntity().isValid() && e.getBukkitEntity().isPersistent()) || forceSerialization,
@@ -91,30 +85,26 @@ private static CompoundTag serializeEntityToNbt(org.bukkit.entity.Entity entity,
9185
}
9286
});
9387

94-
try (final ProblemReporter.ScopedCollector problemReporter = new ProblemReporter.ScopedCollector(
95-
() -> "serialiseEntity@" + entity.getUniqueId(), LOGGER
96-
)) {
97-
final TagValueOutput output = TagValueOutput.createWithContext(problemReporter, nmsEntity.registryAccess());
98-
if (serializePassengers) {
99-
if (!nmsEntity.saveAsPassenger(output, true, includeNonSaveable, forceSerialization)) {
100-
throw new IllegalArgumentException("Couldn't serialize entity");
101-
}
102-
} else {
103-
List<net.minecraft.world.entity.Entity> pass = new ArrayList<>(nmsEntity.getPassengers());
104-
nmsEntity.passengers = com.google.common.collect.ImmutableList.of();
105-
boolean serialized = nmsEntity.saveAsPassenger(output, true, includeNonSaveable, forceSerialization);
106-
nmsEntity.passengers = com.google.common.collect.ImmutableList.copyOf(pass);
107-
if (!serialized) {
108-
throw new IllegalArgumentException("Couldn't serialize entity");
109-
}
88+
CompoundTag compound = new CompoundTag();
89+
if (serializePassangers) {
90+
if (!nmsEntity.saveAsPassenger(compound, true, includeNonSaveable, forceSerialization)) {
91+
throw new IllegalArgumentException("Couldn't serialize entity");
92+
}
93+
} else {
94+
List<net.minecraft.world.entity.Entity> pass = new ArrayList<>(nmsEntity.getPassengers());
95+
nmsEntity.passengers = com.google.common.collect.ImmutableList.of();
96+
boolean serialized = nmsEntity.saveAsPassenger(compound, true, includeNonSaveable, forceSerialization);
97+
nmsEntity.passengers = com.google.common.collect.ImmutableList.copyOf(pass);
98+
if (!serialized) {
99+
throw new IllegalArgumentException("Couldn't serialize entity");
110100
}
111-
return output.buildResult();
112101
}
102+
return compound;
113103
}
114104

115105
private static org.bukkit.entity.Entity deserializeEntityFromNbt(CompoundTag compound, World world, boolean preserveUUID, boolean preservePassengers) {
116-
int dataVersion = compound.getIntOr("DataVersion", 0);
117-
compound = PlatformHooks.get().convertNBT(References.ENTITY, MinecraftServer.getServer().fixerUpper, compound, dataVersion, SharedConstants.getCurrentVersion().dataVersion().version()); // Paper - possibly use dataconverter
106+
int dataVersion = compound.getInt("DataVersion");
107+
compound = PlatformHooks.get().convertNBT(References.ENTITY, MinecraftServer.getServer().fixerUpper, compound, dataVersion, SharedConstants.getCurrentVersion().getDataVersion().getVersion()); // Paper - possibly use dataconverter
118108
if (!preservePassengers) {
119109
compound.remove("Passengers");
120110
}
@@ -127,27 +117,19 @@ private static net.minecraft.world.entity.Entity deserializeEntity(CompoundTag c
127117
// Generate a new UUID, so we don't have to worry about deserializing the same entity twice
128118
compound.remove("UUID");
129119
}
120+
net.minecraft.world.entity.Entity nmsEntity = net.minecraft.world.entity.EntityType.create(compound, world, net.minecraft.world.entity.EntitySpawnReason.LOAD)
121+
.orElseThrow(() -> new IllegalArgumentException("An ID was not found for the data. Did you downgrade?"));
130122

131-
final net.minecraft.world.entity.Entity nmsEntity;
132-
try (final ProblemReporter.ScopedCollector problemReporter = new ProblemReporter.ScopedCollector(
133-
() -> "deserialiseEntity", LOGGER
134-
)) {
135-
nmsEntity = net.minecraft.world.entity.EntityType.create(
136-
TagValueInput.create(problemReporter, world.registryAccess(), compound),
137-
world,
138-
net.minecraft.world.entity.EntitySpawnReason.LOAD
139-
).orElseThrow(() -> new IllegalArgumentException("An ID was not found for the data. Did you downgrade?"));
140-
}
141-
142-
compound.getList("Passengers").ifPresent(passengers -> {
143-
for (final Tag tag : passengers) {
144-
if (!(tag instanceof final CompoundTag serializedPassenger)) {
123+
if (compound.contains("Passengers", Tag.TAG_LIST)) {
124+
ListTag passengersCompound = compound.getList("Passengers", Tag.TAG_COMPOUND);
125+
for (Tag tag : passengersCompound) {
126+
if (!(tag instanceof CompoundTag serializedPassenger)) {
145127
continue;
146128
}
147-
final net.minecraft.world.entity.Entity passengerEntity = deserializeEntity(serializedPassenger, world, preserveUUID);
129+
net.minecraft.world.entity.Entity passengerEntity = deserializeEntity(serializedPassenger, world, preserveUUID);
148130
passengerEntity.startRiding(nmsEntity, true);
149131
}
150-
});
132+
}
151133
return nmsEntity;
152134
}
153135
}

src/main/java/net/coreprotect/worldedit/WorldEditLogger.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.Locale;
44

5+
import com.google.gson.Gson;
6+
import com.google.gson.JsonObject;
57
import org.bukkit.DyeColor;
68
import org.bukkit.Location;
79
import org.bukkit.Material;
@@ -14,8 +16,6 @@
1416
import org.bukkit.entity.EntityType;
1517
import org.bukkit.inventory.ItemStack;
1618
import org.bukkit.plugin.Plugin;
17-
import org.json.simple.JSONObject;
18-
import org.json.simple.parser.JSONParser;
1919

2020
import com.sk89q.jnbt.CompoundTag;
2121
import com.sk89q.jnbt.NBTUtils;
@@ -182,8 +182,8 @@ private static String getSignText(String line) {
182182
}
183183

184184
try {
185-
JSONObject json = (JSONObject) new JSONParser().parse(line);
186-
return (String) json.get("text");
185+
final JsonObject object = new Gson().fromJson(line, JsonObject.class);
186+
return object.get("line").getAsString();
187187
}
188188
catch (Exception e) {
189189
e.printStackTrace();

0 commit comments

Comments
 (0)