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
|
|
|
|
index e95f2222814e104bf9194a96385737dffe2cb2b5..249ab7357aa19d87179fa4c3ae89d9d37f32fbfb 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/commands/SetSpawnCommand.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/commands/SetSpawnCommand.java
|
|
|
|
@@ -33,7 +33,7 @@ public class SetSpawnCommand {
|
|
|
|
ResourceKey<Level> resourceKey = source.getLevel().dimension();
|
|
|
|
|
|
|
|
for(ServerPlayer serverPlayer : targets) {
|
|
|
|
- serverPlayer.setRespawnPosition(resourceKey, pos, angle, true, false);
|
|
|
|
+ serverPlayer.setRespawnPosition(resourceKey, pos, angle, true, false, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.COMMAND); // Paper - PlayerSetSpawnEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
String string = 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
|
2021-11-25 12:20:13 +01:00
|
|
|
index 2607dc36e0bd7a915afb0cc9e0f453a2b301c0bd..ea724b1781ea256c991fe47aa044183e20ae4d82 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
|
2021-11-25 12:20:13 +01:00
|
|
|
@@ -1276,7 +1276,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 {
|
2021-11-25 12:20:13 +01:00
|
|
|
@@ -2104,12 +2104,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
|
|
|
+ }
|
2021-11-25 00:46:26 +01:00
|
|
|
+ public void 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);
|
|
|
|
+ spawnLoc = net.minecraft.server.MCUtil.toLocation(this.getServer().getLevel(dimension), pos);
|
|
|
|
+ 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()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (event.getLocation() != null) {
|
|
|
|
+ dimension = event.getLocation().getWorld() != null ? ((CraftWorld) event.getLocation().getWorld()).getHandle().dimension() : dimension;
|
|
|
|
+ pos = net.minecraft.server.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) {
|
|
|
|
- this.sendMessage(new TranslatableComponent("block.minecraft.set_spawn"), Util.NIL_UUID);
|
|
|
|
+ if (event.willNotifyPlayer() && event.getNotification() != null) { // Paper
|
|
|
|
+ this.sendMessage(PaperAdventure.asVanilla(event.getNotification()), Util.NIL_UUID); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
this.respawnPosition = pos;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2021-11-29 12:55:13 +01:00
|
|
|
index 2c3249359bf8f7e5e625ef4769c7e884cddd473c..8a74c1aa2add393f4706a7f943f0fd5d9f5175e1 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
|
2021-11-25 12:20:13 +01:00
|
|
|
@@ -891,7 +891,7 @@ 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);
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
|
2021-11-25 00:46:26 +01:00
|
|
|
index d620f559cdd1bd0e161a99123ef6c6f64e3302df..07e893f1859abe3c2a765694c21309d60346ca82 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
|
|
|
|
@@ -73,7 +73,7 @@ public class RespawnAnchorBlock extends Block {
|
|
|
|
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);
|
|
|
|
+ serverPlayer.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;
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2021-11-29 12:55:13 +01:00
|
|
|
index 9d8e48b859933a2b9412df78daf158129b430e8c..ad15c4c20ae9e1858a2b914b0a1aa91ec1d7a012 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
|
2021-11-26 23:58:39 +01:00
|
|
|
@@ -1088,9 +1088,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);
|
|
|
|
+ this.getHandle().setRespawnPosition(((CraftWorld) location.getWorld()).getHandle().dimension(), new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), location.getYaw(), override, false); // Paper - PlayerSetSpawnEvent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|