mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 04:56:50 +01:00
efd47e3a68
* Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
189 lines
12 KiB
Diff
189 lines
12 KiB
Diff
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
|
|
index 3072f513c22904f8066e0c37f345df4fdb451f8a..aa701e68ed81562861eba559e61e522b934d5851 100644
|
|
--- a/src/main/java/net/minecraft/server/commands/SetSpawnCommand.java
|
|
+++ b/src/main/java/net/minecraft/server/commands/SetSpawnCommand.java
|
|
@@ -38,11 +38,23 @@ public class SetSpawnCommand {
|
|
ResourceKey<Level> resourcekey = source.getLevel().dimension();
|
|
Iterator iterator = targets.iterator();
|
|
|
|
+ final Collection<ServerPlayer> actualTargets = new java.util.ArrayList<>(); // Paper
|
|
while (iterator.hasNext()) {
|
|
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
|
|
|
- entityplayer.setRespawnPosition(resourcekey, pos, angle, true, false, org.bukkit.event.player.PlayerSpawnChangeEvent.Cause.COMMAND); // CraftBukkit
|
|
+ // Paper start - PlayerSetSpawnEvent
|
|
+ if (entityplayer.setRespawnPosition(resourcekey, pos, angle, true, false, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.COMMAND)) {
|
|
+ actualTargets.add(entityplayer);
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
+ // Paper start
|
|
+ if (actualTargets.isEmpty()) {
|
|
+ return 0;
|
|
+ } else {
|
|
+ targets = actualTargets;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
String s = resourcekey.location().toString();
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index a649d1baa727dd16cb8e786bdf510021e2d16d26..cdf85898d6ca9f1159b175dbc2760522abd8eb95 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1309,7 +1309,7 @@ public class ServerPlayer extends Player {
|
|
} else if (this.bedBlocked(blockposition, enumdirection)) {
|
|
return Either.left(Player.BedSleepingProblem.OBSTRUCTED);
|
|
} else {
|
|
- 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()) {
|
|
return Either.left(Player.BedSleepingProblem.NOT_POSSIBLE_NOW);
|
|
} else {
|
|
@@ -2151,44 +2151,50 @@ public class ServerPlayer extends Player {
|
|
return this.respawnForced;
|
|
}
|
|
|
|
+ @Deprecated // Paper
|
|
public void setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) {
|
|
- // 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;
|
|
+ // Paper start
|
|
+ this.setRespawnPosition(dimension, pos, angle, forced, sendMessage, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.UNKNOWN);
|
|
+ }
|
|
+ @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()));
|
|
+ }
|
|
+ public boolean setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause cause) {
|
|
+ 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);
|
|
+ spawnLoc.setYaw(angle);
|
|
+ willNotify = sendMessage && !flag2;
|
|
+ }
|
|
+
|
|
+ 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());
|
|
+ if (!event.callEvent()) {
|
|
+ return false;
|
|
}
|
|
- // CraftBukkit end
|
|
- if (blockposition != null) {
|
|
- boolean flag2 = blockposition.equals(this.respawnPosition) && resourcekey.equals(this.respawnDimension);
|
|
+ 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());
|
|
+ angle = event.getLocation().getYaw();
|
|
+ forced = event.isForced();
|
|
+ // Paper end
|
|
|
|
- if (flag1 && !flag2) {
|
|
- this.sendSystemMessage(Component.translatable("block.minecraft.set_spawn"));
|
|
+ if (event.willNotifyPlayer() && event.getNotification() != null) { // Paper
|
|
+ this.sendSystemMessage(PaperAdventure.asVanilla(event.getNotification())); // Paper
|
|
}
|
|
|
|
- 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;
|
|
@@ -2196,6 +2202,7 @@ public class ServerPlayer extends Player {
|
|
this.respawnForced = false;
|
|
}
|
|
|
|
+ return true; // Paper
|
|
}
|
|
|
|
public void trackChunk(ChunkPos chunkPos, Packet<?> chunkDataPacket) {
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 0e314e2b85ed17bef7b9cc75573b0dc6c13b46b1..9386d0836ed6dad232aa24219bdbbaeafffc49c0 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -853,7 +853,7 @@ public abstract class PlayerList {
|
|
location = CraftLocation.toBukkit(vec3d, worldserver1.getWorld(), 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, PlayerSpawnChangeEvent.Cause.RESET); // 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
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
|
|
index 1a27b7faa22e6b3dc5fce329ed06425de56c4315..b9903c29bdea8d1e3b6fce0e97be6bd9493cfdf4 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
|
|
@@ -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);
|
|
return InteractionResult.SUCCESS;
|
|
+ // Paper start - handle failed set spawn
|
|
+ } else {
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 6c8649749b3e66d6ab473321be6c48a0ddebc9f0..e826a9e405c0ea985f8a742f4bc81b38c9d98bba 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1370,9 +1370,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
@Override
|
|
public void setBedSpawnLocation(Location location, boolean override) {
|
|
if (location == null) {
|
|
- this.getHandle().setRespawnPosition(null, null, 0.0F, override, false, PlayerSpawnChangeEvent.Cause.PLUGIN);
|
|
+ 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(), 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
|
|
}
|
|
}
|
|
|