2021-08-06 22:37:38 +02: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
|
2023-03-14 21:25:13 +01:00
|
|
|
index 7679d6b8b1eb8e849ce7e63cf293598db7eb4588..b0ed00b95b273f0916cbade0e3bac47aa464d3fd 100644
|
2021-08-06 22:37:38 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/commands/SetSpawnCommand.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/commands/SetSpawnCommand.java
|
2022-04-30 22:24:47 +02:00
|
|
|
@@ -32,9 +32,21 @@ public class SetSpawnCommand {
|
|
|
|
private static int setSpawn(CommandSourceStack source, Collection<ServerPlayer> targets, BlockPos pos, float angle) {
|
2021-08-06 22:37:38 +02:00
|
|
|
ResourceKey<Level> resourceKey = source.getLevel().dimension();
|
|
|
|
|
2022-04-30 22:24:47 +02:00
|
|
|
+ final Collection<ServerPlayer> actualTargets = new java.util.ArrayList<>(); // Paper
|
2021-08-06 22:37:38 +02:00
|
|
|
for(ServerPlayer serverPlayer : targets) {
|
|
|
|
- serverPlayer.setRespawnPosition(resourceKey, pos, angle, true, false);
|
2022-04-30 22:24:47 +02:00
|
|
|
+ // 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 22:37:38 +02:00
|
|
|
}
|
2022-04-30 22:24:47 +02:00
|
|
|
+ // Paper start
|
|
|
|
+ if (actualTargets.isEmpty()) {
|
|
|
|
+ return 0;
|
|
|
|
+ } else {
|
|
|
|
+ targets = actualTargets;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2021-08-06 22:37:38 +02:00
|
|
|
|
|
|
|
String string = resourceKey.location().toString();
|
2022-04-30 22:24:47 +02:00
|
|
|
if (targets.size() == 1) {
|
2021-08-06 22:37:38 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2023-03-26 22:29:41 +02:00
|
|
|
index af8af6bb44b84c74553068b6cd64f4e3941d4ae1..bc6ddf50bcd2f38be8c8fa064b49a7363643b9bd 100644
|
2021-08-06 22:37:38 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2023-03-26 22:29:41 +02:00
|
|
|
@@ -1307,7 +1307,7 @@ public class ServerPlayer extends Player {
|
2021-08-06 22:37:38 +02: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 {
|
2023-03-26 22:29:41 +02:00
|
|
|
@@ -2149,12 +2149,33 @@ public class ServerPlayer extends Player {
|
2021-08-06 22:37:38 +02:00
|
|
|
return this.respawnForced;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ @Deprecated // Paper
|
2021-11-25 00:46:26 +01:00
|
|
|
public void setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) {
|
2021-08-06 22:37:38 +02:00
|
|
|
+ // Paper start
|
2021-11-25 00:46:26 +01:00
|
|
|
+ this.setRespawnPosition(dimension, pos, angle, forced, sendMessage, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.UNKNOWN);
|
2021-08-06 22:37:38 +02:00
|
|
|
+ }
|
2022-04-30 22:24:47 +02: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 22:37:38 +02:00
|
|
|
+ Location spawnLoc = null;
|
|
|
|
+ boolean willNotify = false;
|
|
|
|
if (pos != null) {
|
|
|
|
boolean flag2 = pos.equals(this.respawnPosition) && dimension.equals(this.respawnDimension);
|
2022-10-24 21:43:46 +02:00
|
|
|
+ spawnLoc = io.papermc.paper.util.MCUtil.toLocation(this.getServer().getLevel(dimension), pos);
|
2021-08-06 22:37:38 +02:00
|
|
|
+ spawnLoc.setYaw(angle);
|
|
|
|
+ willNotify = sendMessage && !flag2;
|
|
|
|
+ }
|
2021-11-25 00:46:26 +01: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 22:37:38 +02:00
|
|
|
+ if (!event.callEvent()) {
|
2022-04-30 22:24:47 +02:00
|
|
|
+ return false;
|
2021-08-06 22:37:38 +02:00
|
|
|
+ }
|
|
|
|
+ if (event.getLocation() != null) {
|
|
|
|
+ dimension = event.getLocation().getWorld() != null ? ((CraftWorld) event.getLocation().getWorld()).getHandle().dimension() : dimension;
|
2022-10-24 21:43:46 +02:00
|
|
|
+ pos = io.papermc.paper.util.MCUtil.toBlockPosition(event.getLocation());
|
2021-08-16 23:46:25 +02:00
|
|
|
+ angle = (float) event.getLocation().getYaw();
|
2021-11-25 00:46:26 +01:00
|
|
|
+ forced = event.isForced();
|
2021-08-06 22:37:38 +02:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
- if (sendMessage && !flag2) {
|
2022-06-08 11:31:06 +02:00
|
|
|
- this.sendSystemMessage(Component.translatable("block.minecraft.set_spawn"));
|
2021-08-06 22:37:38 +02:00
|
|
|
+ if (event.willNotifyPlayer() && event.getNotification() != null) { // Paper
|
2022-06-08 11:31:06 +02:00
|
|
|
+ this.sendSystemMessage(PaperAdventure.asVanilla(event.getNotification())); // Paper
|
2021-08-06 22:37:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.respawnPosition = pos;
|
2023-03-26 22:29:41 +02:00
|
|
|
@@ -2168,6 +2189,7 @@ public class ServerPlayer extends Player {
|
2022-04-30 22:24:47 +02:00
|
|
|
this.respawnForced = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ return true; // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
public void trackChunk(ChunkPos chunkPos, Packet<?> chunkDataPacket) {
|
2021-08-06 22:37:38 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2023-04-02 20:37:53 +02:00
|
|
|
index 5f05e832a74a80f7a79b67ec18e269e4241089b9..d84b976364b0ffc4b7356c6791d70f0e34deff48 100644
|
2021-08-06 22:37:38 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2023-04-02 20:37:53 +02:00
|
|
|
@@ -844,13 +844,13 @@ public abstract class PlayerList {
|
2021-08-06 22:37:38 +02: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);
|
2022-04-30 22:24:47 +02:00
|
|
|
} 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 22:37:38 +02: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
|
2023-03-14 21:25:13 +01:00
|
|
|
index a64cd3b54840af9a9c946b3e4e4f91d1c5f4bc97..16f23ecffa52925904d585f3fed76aa61bac5f9d 100644
|
2021-08-06 22:37:38 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
|
2023-03-14 21:25:13 +01:00
|
|
|
@@ -73,9 +73,14 @@ public class RespawnAnchorBlock extends Block {
|
2021-08-06 22:37:38 +02: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);
|
2022-04-30 22:24:47 +02:00
|
|
|
+ if (serverPlayer.setRespawnPosition(world.dimension(), pos, 0.0F, false, true, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.RESPAWN_ANCHOR)) { // Paper - PlayerSetSpawnEvent
|
2021-08-06 22:37:38 +02: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;
|
2022-04-30 22:24:47 +02:00
|
|
|
+ // Paper start - handle failed set spawn
|
|
|
|
+ } else {
|
|
|
|
+ return InteractionResult.FAIL;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2021-08-06 22:37:38 +02:00
|
|
|
}
|
2022-04-30 22:24:47 +02:00
|
|
|
}
|
|
|
|
|
2021-08-06 22:37:38 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2023-03-26 22:29:41 +02:00
|
|
|
index d79c2ce6acc9a5b1239349ad5e1438cb035a9401..9833e8bce6cc45fa053b71f64d71a57c1630595f 100644
|
2021-08-06 22:37:38 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2023-03-14 21:25:13 +01:00
|
|
|
@@ -1338,9 +1338,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2021-08-06 22:37:38 +02: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);
|
2022-04-30 22:24:47 +02:00
|
|
|
+ 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 22:37:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|