Skip to content

Commit bf417ba

Browse files
committed
tag renames
needs a doc update for the new config default
1 parent 907f193 commit bf417ba

File tree

2 files changed

+31
-43
lines changed

2 files changed

+31
-43
lines changed

paper-server/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public class Spawning extends ConfigurationPart {
169169
public ArrowDespawnRate nonPlayerArrowDespawnRate = ArrowDespawnRate.def(WorldConfiguration.this.spigotConfig);
170170
public ArrowDespawnRate creativeArrowDespawnRate = ArrowDespawnRate.def(WorldConfiguration.this.spigotConfig);
171171
public boolean filterBadTileEntityNbtFromFallingBlocks = true;
172-
public List<NbtPathArgument.NbtPath> filteredEntityTagNbtPaths = NbtPathSerializer.fromString(List.of("Pos", "Motion", "SleepingX", "SleepingY", "SleepingZ"));
172+
public List<NbtPathArgument.NbtPath> filteredEntityTagNbtPaths = NbtPathSerializer.fromString(List.of("Pos", "Motion", "sleeping_pos"));
173173
public boolean disableMobSpawnerSpawnEggTransformation = false;
174174
public boolean perPlayerMobSpawns = true;
175175
public boolean scanForLegacyEnderDragon = true;

paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java

+30-42
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import net.minecraft.server.players.UserWhiteListEntry;
1919
import net.minecraft.stats.ServerStatsCounter;
2020
import net.minecraft.world.level.storage.PlayerDataStorage;
21+
import net.minecraft.world.phys.Vec2;
22+
import net.minecraft.world.phys.Vec3;
2123
import org.bukkit.BanEntry;
2224
import org.bukkit.BanList;
2325
import org.bukkit.Bukkit;
@@ -26,6 +28,7 @@
2628
import org.bukkit.OfflinePlayer;
2729
import org.bukkit.Server;
2830
import org.bukkit.Statistic;
31+
import org.bukkit.World;
2932
import org.bukkit.ban.ProfileBanList;
3033
import org.bukkit.configuration.serialization.ConfigurationSerializable;
3134
import org.bukkit.configuration.serialization.SerializableAs;
@@ -79,9 +82,7 @@ public String getName() {
7982
CompoundTag data = this.getBukkitData();
8083

8184
if (data != null) {
82-
if (data.contains("lastKnownName")) {
83-
return data.getString("lastKnownName");
84-
}
85+
return data.getString("lastKnownName").orElse(null);
8586
}
8687

8788
return null;
@@ -217,10 +218,7 @@ private CompoundTag getBukkitData() {
217218
CompoundTag result = this.getData();
218219

219220
if (result != null) {
220-
if (!result.contains("bukkit")) {
221-
result.put("bukkit", new CompoundTag());
222-
}
223-
result = result.getCompound("bukkit");
221+
result = result.getCompound("bukkit").orElse(null);
224222
}
225223

226224
return result;
@@ -238,12 +236,10 @@ public long getFirstPlayed() {
238236
CompoundTag data = this.getBukkitData();
239237

240238
if (data != null) {
241-
if (data.contains("firstPlayed")) {
242-
return data.getLong("firstPlayed");
243-
} else {
239+
return data.getLong("firstPlayed").orElseGet(() -> {
244240
File file = this.getDataFile();
245241
return file.lastModified();
246-
}
242+
});
247243
} else {
248244
return 0;
249245
}
@@ -257,12 +253,10 @@ public long getLastPlayed() {
257253
CompoundTag data = this.getBukkitData();
258254

259255
if (data != null) {
260-
if (data.contains("lastPlayed")) {
261-
return data.getLong("lastPlayed");
262-
} else {
256+
return data.getLong("lastPlayed").orElseGet(() -> {
263257
File file = this.getDataFile();
264258
return file.lastModified();
265-
}
259+
});
266260
} else {
267261
return 0;
268262
}
@@ -282,13 +276,11 @@ public long getLastLogin() {
282276
CompoundTag data = getPaperData();
283277

284278
if (data != null) {
285-
if (data.contains("LastLogin")) {
286-
return data.getLong("LastLogin");
287-
} else {
279+
return data.getLong("LastLogin").orElseGet(() -> {
288280
// if the player file cannot provide accurate data, this is probably the closest we can approximate
289281
File file = getDataFile();
290282
return file.lastModified();
291-
}
283+
});
292284
} else {
293285
return 0;
294286
}
@@ -302,13 +294,11 @@ public long getLastSeen() {
302294
CompoundTag data = getPaperData();
303295

304296
if (data != null) {
305-
if (data.contains("LastSeen")) {
306-
return data.getLong("LastSeen");
307-
} else {
297+
return data.getLong("LastSeen").orElseGet(() -> {
308298
// if the player file cannot provide accurate data, this is probably the closest we can approximate
309299
File file = getDataFile();
310300
return file.lastModified();
311-
}
301+
});
312302
} else {
313303
return 0;
314304
}
@@ -318,10 +308,7 @@ private CompoundTag getPaperData() {
318308
CompoundTag result = getData();
319309

320310
if (result != null) {
321-
if (!result.contains("Paper")) {
322-
result.put("Paper", new CompoundTag());
323-
}
324-
result = result.getCompound("Paper");
311+
result = result.getCompound("Paper").orElse(null);
325312
}
326313

327314
return result;
@@ -338,7 +325,7 @@ public io.papermc.paper.persistence.PersistentDataContainerView getPersistentDat
338325
this.persistentDataContainerView = new io.papermc.paper.persistence.PaperPersistentDataContainerView(DATA_TYPE_REGISTRY) {
339326

340327
private CompoundTag getPersistentTag() {
341-
return net.minecraft.Optionull.map(CraftOfflinePlayer.this.getData(), data -> data.getCompound("BukkitValues"));
328+
return net.minecraft.Optionull.map(CraftOfflinePlayer.this.getData(), data -> data.getCompound("BukkitValues").orElse(null));
342329
}
343330

344331
@Override
@@ -358,10 +345,12 @@ public net.minecraft.nbt.Tag getTag(String key) {
358345

359346
@Override
360347
public Location getLastDeathLocation() {
361-
if (this.getData().contains("LastDeathLocation", 10)) {
362-
return GlobalPos.CODEC.parse(NbtOps.INSTANCE, this.getData().get("LastDeathLocation")).result().map(CraftLocation::fromGlobalPos).orElse(null);
348+
CompoundTag data = this.getData();
349+
if (data == null) {
350+
return null;
363351
}
364-
return null;
352+
353+
return data.read("LastDeathLocation", GlobalPos.CODEC).map(CraftLocation::fromGlobalPos).orElse(null);
365354
}
366355

367356
@Override
@@ -371,18 +360,17 @@ public Location getLocation() {
371360
return null;
372361
}
373362

374-
if (data.contains("Pos") && data.contains("Rotation")) {
375-
ListTag position = (ListTag) data.get("Pos");
376-
ListTag rotation = (ListTag) data.get("Rotation");
377-
378-
UUID uuid = new UUID(data.getLong("WorldUUIDMost"), data.getLong("WorldUUIDLeast"));
363+
Vec3 pos = data.read("Pos", Vec3.CODEC).orElse(null);
364+
Vec2 rot = data.read("Rotation", Vec2.CODEC).orElse(null);
365+
if (pos != null && rot != null) {
366+
Long msb = data.getLong("WorldUUIDMost").orElse(null);
367+
Long lsb = data.getLong("WorldUUIDLeast").orElse(null);
368+
World world = msb != null && lsb != null ? this.server.getWorld(new UUID(msb, lsb)) : null;
379369

380-
return new Location(this.server.getWorld(uuid),
381-
position.getDouble(0),
382-
position.getDouble(1),
383-
position.getDouble(2),
384-
rotation.getFloat(0),
385-
rotation.getFloat(1)
370+
return new Location(
371+
world,
372+
pos.x(), pos.y(), pos.z(),
373+
rot.x, rot.y
386374
);
387375
}
388376

0 commit comments

Comments
 (0)