testserver/patches/server/0677-Add-PlayerSetSpawnEven...

147 lines
9.7 KiB
Diff
Raw Normal View History

2021-08-06 20:37:38 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 19 May 2021 18:59:10 -0700
Subject: [PATCH] Add PlayerSetSpawnEvent
diff --git a/src/main/java/net/minecraft/server/commands/SetSpawnCommand.java b/src/main/java/net/minecraft/server/commands/SetSpawnCommand.java
2022-06-08 09:31:06 +00:00
index ce1c7512cc368e196ae94ee22c6a228c975b4980..1e41de9523c5fa3b9cfced798a5c35a24ec9d349 100644
2021-08-06 20:37:38 +00:00
--- a/src/main/java/net/minecraft/server/commands/SetSpawnCommand.java
+++ b/src/main/java/net/minecraft/server/commands/SetSpawnCommand.java
@@ -32,9 +32,21 @@ public class SetSpawnCommand {
private static int setSpawn(CommandSourceStack source, Collection<ServerPlayer> targets, BlockPos pos, float angle) {
2021-08-06 20:37:38 +00:00
ResourceKey<Level> resourceKey = source.getLevel().dimension();
+ final Collection<ServerPlayer> actualTargets = new java.util.ArrayList<>(); // Paper
2021-08-06 20:37:38 +00:00
for(ServerPlayer serverPlayer : targets) {
- serverPlayer.setRespawnPosition(resourceKey, pos, angle, true, false);
+ // Paper start - PlayerSetSpawnEvent
+ if (serverPlayer.setRespawnPosition(resourceKey, pos, angle, true, false, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.COMMAND)) {
+ actualTargets.add(serverPlayer);
+ }
+ // Paper end
2021-08-06 20:37:38 +00:00
}
+ // Paper start
+ if (actualTargets.isEmpty()) {
+ return 0;
+ } else {
+ targets = actualTargets;
+ }
+ // Paper end
2021-08-06 20:37:38 +00:00
String string = resourceKey.location().toString();
if (targets.size() == 1) {
2021-08-06 20:37:38 +00:00
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 95e2cbe6f80e64c00e8e261a3e1731c73845fc83..218a71cbd62795fdf3b9b3ad224e201b1e97a5b6 100644
2021-08-06 20:37:38 +00:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 08:02:51 +00:00
@@ -1272,7 +1272,7 @@ public class ServerPlayer extends Player {
2021-08-06 20:37:38 +00:00
} else if (this.bedBlocked(blockposition, enumdirection)) {
return Either.left(Player.BedSleepingProblem.OBSTRUCTED);
} else {
- this.setRespawnPosition(this.level.dimension(), blockposition, this.getYRot(), false, true);
+ this.setRespawnPosition(this.level.dimension(), blockposition, this.getYRot(), false, true, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.BED); // Paper - PlayerSetSpawnEvent
if (this.level.isDay()) {
return Either.left(Player.BedSleepingProblem.NOT_POSSIBLE_NOW);
} else {
@@ -2127,12 +2127,33 @@ public class ServerPlayer extends Player {
2021-08-06 20:37:38 +00:00
return this.respawnForced;
}
+ @Deprecated // Paper
2021-11-24 23:46:26 +00:00
public void setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) {
2021-08-06 20:37:38 +00:00
+ // Paper start
2021-11-24 23:46:26 +00:00
+ this.setRespawnPosition(dimension, pos, angle, forced, sendMessage, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.UNKNOWN);
2021-08-06 20:37:38 +00:00
+ }
+ public boolean setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause cause) {
2021-08-06 20:37:38 +00:00
+ Location spawnLoc = null;
+ boolean willNotify = false;
if (pos != null) {
boolean flag2 = pos.equals(this.respawnPosition) && dimension.equals(this.respawnDimension);
+ spawnLoc = io.papermc.paper.util.MCUtil.toLocation(this.getServer().getLevel(dimension), pos);
2021-08-06 20:37:38 +00:00
+ spawnLoc.setYaw(angle);
+ willNotify = sendMessage && !flag2;
+ }
2021-11-24 23:46:26 +00:00
+ com.destroystokyo.paper.event.player.PlayerSetSpawnEvent event = new com.destroystokyo.paper.event.player.PlayerSetSpawnEvent(this.getBukkitEntity(), cause, spawnLoc, forced, willNotify, willNotify ? net.kyori.adventure.text.Component.translatable("block.minecraft.set_spawn") : null);
2021-08-06 20:37:38 +00:00
+ if (!event.callEvent()) {
+ return false;
2021-08-06 20:37:38 +00:00
+ }
+ if (event.getLocation() != null) {
+ dimension = event.getLocation().getWorld() != null ? ((CraftWorld) event.getLocation().getWorld()).getHandle().dimension() : dimension;
+ pos = io.papermc.paper.util.MCUtil.toBlockPosition(event.getLocation());
2021-08-16 21:46:25 +00:00
+ angle = (float) event.getLocation().getYaw();
2021-11-24 23:46:26 +00:00
+ forced = event.isForced();
2021-08-06 20:37:38 +00:00
+ // Paper end
- if (sendMessage && !flag2) {
2022-06-08 09:31:06 +00:00
- this.sendSystemMessage(Component.translatable("block.minecraft.set_spawn"));
2021-08-06 20:37:38 +00:00
+ if (event.willNotifyPlayer() && event.getNotification() != null) { // Paper
2022-06-08 09:31:06 +00:00
+ this.sendSystemMessage(PaperAdventure.asVanilla(event.getNotification())); // Paper
2021-08-06 20:37:38 +00:00
}
this.respawnPosition = pos;
@@ -2146,6 +2167,7 @@ public class ServerPlayer extends Player {
this.respawnForced = false;
}
+ return true; // Paper
}
public void trackChunk(ChunkPos chunkPos, Packet<?> chunkDataPacket) {
2021-08-06 20:37:38 +00:00
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 157c263649d56ee47a4ccf91d76ba6cfa783f87f..e756066c9ed33cfd5ff3c5911421ff8433b0d2d7 100644
2021-08-06 20:37:38 +00:00
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -902,13 +902,13 @@ public abstract class PlayerList {
2021-08-06 20:37:38 +00:00
f1 = (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
}
- entityplayer1.setRespawnPosition(worldserver1.dimension(), blockposition, f, flag1, false);
+ entityplayer1.setRespawnPosition(worldserver1.dimension(), blockposition, f, flag1, false, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.PLAYER_RESPAWN); // Paper - PlayerSetSpawnEvent
flag2 = !flag && flag3;
isBedSpawn = true;
location = new Location(worldserver1.getWorld(), vec3d.x, vec3d.y, vec3d.z, f1, 0.0F);
} else if (blockposition != null) {
entityplayer1.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F));
- entityplayer1.setRespawnPosition(null, null, 0f, false, false); // CraftBukkit - SPIGOT-5988: Clear respawn location when obstructed
+ entityplayer1.setRespawnPosition(null, null, 0f, false, false, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.PLAYER_RESPAWN); // CraftBukkit - SPIGOT-5988: Clear respawn location when obstructed // Paper - PlayerSetSpawnEvent
}
}
2021-08-06 20:37:38 +00:00
diff --git a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
2022-06-08 09:31:06 +00:00
index c3e49a781f838e6a46cb89744f3f1846de182275..c2f3d3a09327e7cb7d3167609eb3ce68eadf6443 100644
2021-08-06 20:37:38 +00:00
--- a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
2022-05-29 19:54:25 +00:00
@@ -72,9 +72,14 @@ public class RespawnAnchorBlock extends Block {
2021-08-06 20:37:38 +00:00
if (!world.isClientSide) {
ServerPlayer serverPlayer = (ServerPlayer)player;
if (serverPlayer.getRespawnDimension() != world.dimension() || !pos.equals(serverPlayer.getRespawnPosition())) {
- serverPlayer.setRespawnPosition(world.dimension(), pos, 0.0F, false, true);
+ if (serverPlayer.setRespawnPosition(world.dimension(), pos, 0.0F, false, true, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.RESPAWN_ANCHOR)) { // Paper - PlayerSetSpawnEvent
2021-08-06 20:37:38 +00:00
world.playSound((Player)null, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, SoundEvents.RESPAWN_ANCHOR_SET_SPAWN, SoundSource.BLOCKS, 1.0F, 1.0F);
return InteractionResult.SUCCESS;
+ // Paper start - handle failed set spawn
+ } else {
+ return InteractionResult.FAIL;
+ }
+ // Paper end
2021-08-06 20:37:38 +00:00
}
}
2021-08-06 20:37:38 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index ed51d20ebe72cd5f94882127968006fca2acec08..44d2473625420490e35e79f0388a9890bff18fa8 100644
2021-08-06 20:37:38 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1289,9 +1289,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-08-06 20:37:38 +00:00
@Override
public void setBedSpawnLocation(Location location, boolean override) {
if (location == null) {
- this.getHandle().setRespawnPosition(null, null, 0.0F, override, false);
+ this.getHandle().setRespawnPosition(null, null, 0.0F, override, false, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.PLUGIN); // Paper - PlayerSetSpawnEvent
} else {
- this.getHandle().setRespawnPosition(((CraftWorld) location.getWorld()).getHandle().dimension(), new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), location.getYaw(), override, false);
+ this.getHandle().setRespawnPosition(((CraftWorld) location.getWorld()).getHandle().dimension(), new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), location.getYaw(), override, false, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.PLUGIN); // Paper - PlayerSetSpawnEvent
2021-08-06 20:37:38 +00:00
}
}