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-06-08 21:00:58 +02:00
|
|
|
index a2d0699e8427b2262a2396495111125eccafbb66..d797637f61bdf8a424f56fbb48e28b7c9117d604 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
|
2023-06-08 21:00:58 +02:00
|
|
|
@@ -38,24 +38,34 @@ public class SetSpawnCommand {
|
2023-05-12 13:10:08 +02:00
|
|
|
ResourceKey<Level> resourcekey = source.getLevel().dimension();
|
|
|
|
Iterator iterator = targets.iterator();
|
2021-08-06 22:37:38 +02:00
|
|
|
|
2022-04-30 22:24:47 +02:00
|
|
|
+ final Collection<ServerPlayer> actualTargets = new java.util.ArrayList<>(); // Paper
|
2023-05-12 13:10:08 +02:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
|
|
|
|
|
|
|
- entityplayer.setRespawnPosition(resourcekey, pos, angle, true, false, org.bukkit.event.player.PlayerSpawnChangeEvent.Cause.COMMAND); // CraftBukkit
|
2022-04-30 22:24:47 +02:00
|
|
|
+ // Paper start - PlayerSetSpawnEvent
|
2023-05-12 13:10:08 +02:00
|
|
|
+ if (entityplayer.setRespawnPosition(resourcekey, pos, angle, true, false, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.COMMAND)) {
|
|
|
|
+ actualTargets.add(entityplayer);
|
2022-04-30 22:24:47 +02:00
|
|
|
+ }
|
|
|
|
+ // 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;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2021-08-06 22:37:38 +02:00
|
|
|
|
2023-05-12 13:10:08 +02:00
|
|
|
String s = resourcekey.location().toString();
|
|
|
|
|
2023-06-08 21:00:58 +02:00
|
|
|
- if (targets.size() == 1) {
|
|
|
|
+ if (actualTargets.size() == 1) { // Paper
|
|
|
|
source.sendSuccess(() -> {
|
|
|
|
- return Component.translatable("commands.spawnpoint.success.single", pos.getX(), pos.getY(), pos.getZ(), angle, s, ((ServerPlayer) targets.iterator().next()).getDisplayName());
|
|
|
|
+ return Component.translatable("commands.spawnpoint.success.single", pos.getX(), pos.getY(), pos.getZ(), angle, s, ((ServerPlayer) actualTargets.iterator().next()).getDisplayName()); // Paper
|
|
|
|
}, true);
|
|
|
|
} else {
|
|
|
|
source.sendSuccess(() -> {
|
|
|
|
- return Component.translatable("commands.spawnpoint.success.multiple", pos.getX(), pos.getY(), pos.getZ(), angle, s, targets.size());
|
|
|
|
+ return Component.translatable("commands.spawnpoint.success.multiple", pos.getX(), pos.getY(), pos.getZ(), angle, s, actualTargets.size()); // Paper
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
- return targets.size();
|
|
|
|
+ return actualTargets.size(); // Paper
|
|
|
|
}
|
|
|
|
}
|
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-10-29 02:45:07 +02:00
|
|
|
index 00adb106eea35b745e98e28e6b9e0affe2d00651..c358a078bdbb672b41f606cf83353fc35bcb4b15 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-10-08 12:07:48 +02:00
|
|
|
@@ -1351,7 +1351,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 {
|
2023-06-08 04:04:01 +02:00
|
|
|
- this.setRespawnPosition(this.level().dimension(), blockposition, this.getYRot(), false, true, PlayerSpawnChangeEvent.Cause.BED); // CraftBukkit
|
|
|
|
+ this.setRespawnPosition(this.level().dimension(), blockposition, this.getYRot(), false, true, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.BED); // Paper - PlayerSetSpawnEvent
|
|
|
|
if (this.level().isDay()) {
|
2021-08-06 22:37:38 +02:00
|
|
|
return Either.left(Player.BedSleepingProblem.NOT_POSSIBLE_NOW);
|
|
|
|
} else {
|
2023-10-29 02:45:07 +02:00
|
|
|
@@ -2209,44 +2209,50 @@ 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) {
|
2023-05-12 13:10:08 +02:00
|
|
|
- // CraftBukkit start
|
|
|
|
- this.setRespawnPosition(dimension, pos, angle, forced, sendMessage, PlayerSpawnChangeEvent.Cause.UNKNOWN);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setRespawnPosition(ResourceKey<Level> resourcekey, @Nullable BlockPos blockposition, float f, boolean flag, boolean flag1, PlayerSpawnChangeEvent.Cause cause) {
|
|
|
|
- ServerLevel newWorld = this.server.getLevel(resourcekey);
|
|
|
|
- Location newSpawn = (blockposition != null) ? CraftLocation.toBukkit(blockposition, newWorld.getWorld(), f, 0) : null;
|
|
|
|
-
|
|
|
|
- PlayerSpawnChangeEvent event = new PlayerSpawnChangeEvent(this.getBukkitEntity(), newSpawn, flag, cause);
|
|
|
|
- Bukkit.getServer().getPluginManager().callEvent(event);
|
|
|
|
- if (event.isCancelled()) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- newSpawn = event.getNewSpawn();
|
|
|
|
- flag = event.isForced();
|
|
|
|
-
|
|
|
|
- if (newSpawn != null) {
|
|
|
|
- resourcekey = ((CraftWorld) newSpawn.getWorld()).getHandle().dimension();
|
|
|
|
- blockposition = BlockPos.containing(newSpawn.getX(), newSpawn.getY(), newSpawn.getZ());
|
|
|
|
- f = newSpawn.getYaw();
|
|
|
|
- } else {
|
|
|
|
- resourcekey = Level.OVERWORLD;
|
|
|
|
- blockposition = null;
|
|
|
|
- f = 0.0F;
|
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
|
|
|
+ }
|
2023-05-12 13:10:08 +02:00
|
|
|
+ @Deprecated
|
|
|
|
+ public boolean setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage, PlayerSpawnChangeEvent.Cause cause) {
|
|
|
|
+ return this.setRespawnPosition(dimension, pos, angle, forced, sendMessage, cause == PlayerSpawnChangeEvent.Cause.RESET ?
|
|
|
|
+ com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.PLAYER_RESPAWN : com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.valueOf(cause.name()));
|
|
|
|
+ }
|
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;
|
2023-05-12 13:10:08 +02:00
|
|
|
+ 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;
|
|
|
|
+ }
|
2023-05-12 13:10:08 +02:00
|
|
|
+
|
|
|
|
+ PlayerSpawnChangeEvent dumbEvent = new PlayerSpawnChangeEvent(this.getBukkitEntity(), spawnLoc, forced,
|
|
|
|
+ cause == com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.PLAYER_RESPAWN ? PlayerSpawnChangeEvent.Cause.RESET : PlayerSpawnChangeEvent.Cause.valueOf(cause.name()));
|
|
|
|
+ dumbEvent.callEvent();
|
|
|
|
+
|
|
|
|
+ com.destroystokyo.paper.event.player.PlayerSetSpawnEvent event = new com.destroystokyo.paper.event.player.PlayerSetSpawnEvent(this.getBukkitEntity(), cause, dumbEvent.getNewSpawn(), dumbEvent.isForced(), willNotify, willNotify ? net.kyori.adventure.text.Component.translatable("block.minecraft.set_spawn") : null);
|
|
|
|
+ event.setCancelled(dumbEvent.isCancelled());
|
2021-08-06 22:37:38 +02:00
|
|
|
+ if (!event.callEvent()) {
|
2022-04-30 22:24:47 +02:00
|
|
|
+ return false;
|
2023-05-12 13:10:08 +02:00
|
|
|
}
|
|
|
|
- // CraftBukkit end
|
|
|
|
- if (blockposition != null) {
|
|
|
|
- boolean flag2 = blockposition.equals(this.respawnPosition) && resourcekey.equals(this.respawnDimension);
|
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());
|
2023-05-12 13:10:08 +02:00
|
|
|
+ angle = event.getLocation().getYaw();
|
2021-11-25 00:46:26 +01:00
|
|
|
+ forced = event.isForced();
|
2021-08-06 22:37:38 +02:00
|
|
|
+ // Paper end
|
|
|
|
|
2023-05-12 13:10:08 +02:00
|
|
|
- if (flag1 && !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
|
|
|
}
|
|
|
|
|
2023-05-12 13:10:08 +02:00
|
|
|
- this.respawnPosition = blockposition;
|
|
|
|
- this.respawnDimension = resourcekey;
|
|
|
|
- this.respawnAngle = f;
|
|
|
|
- this.respawnForced = flag;
|
|
|
|
+ this.respawnPosition = pos;
|
|
|
|
+ this.respawnDimension = dimension;
|
|
|
|
+ this.respawnAngle = angle;
|
|
|
|
+ this.respawnForced = forced;
|
|
|
|
} else {
|
|
|
|
this.respawnPosition = null;
|
|
|
|
this.respawnDimension = Level.OVERWORLD;
|
2023-10-29 02:45:07 +02:00
|
|
|
@@ -2254,6 +2260,7 @@ public class ServerPlayer extends Player {
|
2022-04-30 22:24:47 +02:00
|
|
|
this.respawnForced = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ return true; // Paper
|
|
|
|
}
|
|
|
|
|
2023-09-22 14:22:24 +02:00
|
|
|
public SectionPos getLastSectionPos() {
|
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-11-04 22:11:55 +01:00
|
|
|
index 3170c0f512ff315d40ad1d4e24794e51c1429a36..b06f36138bfda3f9802ee15e57e1895d8fe16c54 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-11-04 22:11:55 +01:00
|
|
|
@@ -876,7 +876,7 @@ public abstract class PlayerList {
|
2023-05-12 13:10:08 +02:00
|
|
|
location = CraftLocation.toBukkit(vec3d, worldserver1.getWorld(), 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));
|
2023-05-12 13:10:08 +02:00
|
|
|
- entityplayer1.setRespawnPosition(null, null, 0f, false, false, PlayerSpawnChangeEvent.Cause.RESET); // CraftBukkit - SPIGOT-5988: Clear respawn location when obstructed
|
2022-04-30 22:24:47 +02:00
|
|
|
+ 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-05-12 13:10:08 +02:00
|
|
|
index 1a27b7faa22e6b3dc5fce329ed06425de56c4315..b9903c29bdea8d1e3b6fce0e97be6bd9493cfdf4 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-05-12 13:10:08 +02:00
|
|
|
@@ -80,9 +80,14 @@ public class RespawnAnchorBlock extends Block {
|
|
|
|
ServerPlayer entityplayer = (ServerPlayer) player;
|
|
|
|
|
|
|
|
if (entityplayer.getRespawnDimension() != world.dimension() || !pos.equals(entityplayer.getRespawnPosition())) {
|
|
|
|
- entityplayer.setRespawnPosition(world.dimension(), pos, 0.0F, false, true, org.bukkit.event.player.PlayerSpawnChangeEvent.Cause.RESPAWN_ANCHOR); // CraftBukkit
|
|
|
|
+ if (entityplayer.setRespawnPosition(world.dimension(), pos, 0.0F, false, true, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.RESPAWN_ANCHOR)) { // Paper - PlayerSetSpawnEvent
|
|
|
|
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);
|
2021-08-06 22:37:38 +02:00
|
|
|
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-11-04 21:20:13 +01:00
|
|
|
index 34377bef2b359292d184ec89311f49dd234be53e..4b167b30275a4dd180c4b88f453e5d2ff935a857 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-11-04 21:20:13 +01:00
|
|
|
@@ -1311,9 +1311,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) {
|
2023-05-12 13:10:08 +02:00
|
|
|
- this.getHandle().setRespawnPosition(null, null, 0.0F, override, false, PlayerSpawnChangeEvent.Cause.PLUGIN);
|
2021-08-06 22:37:38 +02:00
|
|
|
+ this.getHandle().setRespawnPosition(null, null, 0.0F, override, false, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.PLUGIN); // Paper - PlayerSetSpawnEvent
|
|
|
|
} else {
|
2023-05-12 13:10:08 +02:00
|
|
|
- this.getHandle().setRespawnPosition(((CraftWorld) location.getWorld()).getHandle().dimension(), CraftLocation.toBlockPosition(location), location.getYaw(), override, false, PlayerSpawnChangeEvent.Cause.PLUGIN);
|
|
|
|
+ this.getHandle().setRespawnPosition(((CraftWorld) location.getWorld()).getHandle().dimension(), CraftLocation.toBlockPosition(location), location.getYaw(), override, false, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.PLUGIN); // Paper - PlayerSetSpawnEvent
|
2021-08-06 22:37:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|