Create PlayerUseRespawnAnchorEvent

This commit is contained in:
lexikiq
2021-05-14 00:04:26 -04:00
parent 2ebfc40672
commit 0aa5ef25d1
5 changed files with 199 additions and 4 deletions

View File

@@ -911,7 +911,7 @@ index 9013d043503d175004ad276799e5935b7fa59dc4..9a6e1ebd46d580addf532786842ea64f
private boolean cancelled;
diff --git a/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java b/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
index c9af02b0f62b3d18da1e91d1ea02ce0864fc60b9..35e8c680309f0a67e941b749240f902be07c22e6 100644
index 77aefda5aac4602bf5bf71c29600e7450defdd4e..e1275a902986ea82187f491503032d60b8c2c784 100644
--- a/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
+++ b/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
@@ -4,6 +4,7 @@ import java.net.InetAddress;

View File

@@ -0,0 +1,114 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: lexikiq <noellekiq@gmail.com>
Date: Thu, 13 May 2021 23:55:02 -0400
Subject: [PATCH] Create PlayerUseRespawnAnchorEvent
diff --git a/src/main/java/me/lexikiq/event/player/PlayerUseRespawnAnchorEvent.java b/src/main/java/me/lexikiq/event/player/PlayerUseRespawnAnchorEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..96b552fe0bd6e6507c1c4f9380cab32e725cb129
--- /dev/null
+++ b/src/main/java/me/lexikiq/event/player/PlayerUseRespawnAnchorEvent.java
@@ -0,0 +1,102 @@
+package me.lexikiq.event.player;
+
+import org.bukkit.block.Block;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * This event is fired immediately before the result of using a respawn anchor is executed
+ */
+public class PlayerUseRespawnAnchorEvent extends PlayerEvent implements Cancellable {
+
+ /**
+ * Represents the default possible outcomes of this event.
+ */
+ public enum RespawnAnchorResult {
+ /**
+ * The player's spawn point will be set
+ */
+ SET_SPAWN,
+ /**
+ * The respawn anchor will explode due to being used outside the nether
+ */
+ EXPLODE,
+ /**
+ * The player will charge the respawn anchor
+ */
+ CHARGE
+ }
+
+ private static final HandlerList handlers = new HandlerList();
+ private final Block respawnAnchor;
+ private final RespawnAnchorResult respawnAnchorResult;
+ private boolean cancelled = false;
+
+ public PlayerUseRespawnAnchorEvent(@NotNull Player who, @NotNull Block respawnAnchor, @NotNull RespawnAnchorResult respawnAnchorResult) {
+ super(who);
+ this.respawnAnchor = respawnAnchor;
+ this.respawnAnchorResult = respawnAnchorResult;
+ }
+
+ /**
+ * Returns the respawn anchor block involved in this event.
+ *
+ * @return the respawn anchor block involved in this event
+ */
+ @NotNull
+ public Block getRespawnAnchor() {
+ return this.respawnAnchor;
+ }
+
+ /**
+ * Describes the outcome of the event.
+ *
+ * @return the respawn anchor result for the outcome of the event
+ */
+ @NotNull
+ public RespawnAnchorResult getRespawnAnchorResult() {
+ return this.respawnAnchorResult;
+ }
+
+ /**
+ * Gets the cancellation state of this event. A cancelled event will not
+ * be executed in the server, but will still pass to other plugins.
+ * <p>
+ * A positive value means the respawn anchor will not take any action, as
+ * if it had not been clicked at all.
+ *
+ * @return true if this event is cancelled
+ */
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ /**
+ * Sets the cancellation state of this event. A canceled event will not be
+ * executed in the server, but will still pass to other plugins.
+ * <p>
+ * Canceling this event will prevent use of the respawn anchor, leaving it
+ * as thought it hadn't been clicked at all.
+ *
+ * @param cancel true if you wish to cancel this event
+ */
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @Override
+ public @NotNull HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+}

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Parchment brand changes
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 61712ae515b329a6b85dbe2e5960e4e864dc7731..051ba2c4ae14c5da58177e52f5c55241f97caab8 100644
index 35bb4d0b9ed131e6570cce0b43ae78c5557a0bff..8d651788bce04f4d6d3e8bcbd3f97a8e0bbacf02 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1579,7 +1579,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
@@ -1580,7 +1580,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
}
public String getServerModName() {
@@ -18,7 +18,7 @@ index 61712ae515b329a6b85dbe2e5960e4e864dc7731..051ba2c4ae14c5da58177e52f5c55241
public CrashReport b(CrashReport crashreport) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 1a0b3e2313b87c6a5eb049838ec72304dcc8f543..e91e5c3ee22a6bb646956b06ae3949ee7e5bea0b 100644
index 6cc8eb04f42592aa12f76bb4a0a863ea509741b2..ae3af6c152aefad32616c9debd4f1172c49f68fd 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -232,7 +232,7 @@ import javax.annotation.Nullable; // Paper

View File

@@ -0,0 +1,80 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: lexikiq <noellekiq@gmail.com>
Date: Thu, 13 May 2021 23:52:14 -0400
Subject: [PATCH] Create PlayerUseRespawnAnchorEvent
diff --git a/src/main/java/net/minecraft/world/level/block/BlockRespawnAnchor.java b/src/main/java/net/minecraft/world/level/block/BlockRespawnAnchor.java
index 028e98decf8b0496b4ebcd1aad3aa474e5c4e7c1..1a3c66464947e16cc085a20ee1172cc51a3fc2f5 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockRespawnAnchor.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockRespawnAnchor.java
@@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.UnmodifiableIterator;
import java.util.Optional;
import java.util.stream.Stream;
+import me.lexikiq.event.player.PlayerUseRespawnAnchorEvent;
import net.minecraft.core.BaseBlockPosition;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.EnumDirection;
@@ -37,6 +38,8 @@ import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.pathfinder.PathMode;
import net.minecraft.world.phys.MovingObjectPositionBlock;
import net.minecraft.world.phys.Vec3D;
+import org.bukkit.craftbukkit.block.CraftBlock; // Parchment
+import org.bukkit.entity.Player; // Parchment
public class BlockRespawnAnchor extends Block {
@@ -53,6 +56,11 @@ public class BlockRespawnAnchor extends Block {
public EnumInteractionResult interact(IBlockData iblockdata, World world, BlockPosition blockposition, EntityHuman entityhuman, EnumHand enumhand, MovingObjectPositionBlock movingobjectpositionblock) {
ItemStack itemstack = entityhuman.b(enumhand);
+ // Parchment start -- PlayerUseRespawnAnchorEvent
+ Player player = entityhuman.getBukkitEntity() instanceof Player ? (Player) entityhuman.getBukkitEntity() : null;
+ org.bukkit.block.Block block = CraftBlock.at(world, blockposition);
+ // Parchment end
+
if (enumhand == EnumHand.MAIN_HAND && !a(itemstack) && a(entityhuman.b(EnumHand.OFF_HAND))) {
return EnumInteractionResult.PASS;
} else if (a(itemstack) && h(iblockdata)) {
@@ -61,16 +69,31 @@ public class BlockRespawnAnchor extends Block {
itemstack.subtract(1);
}
+ // Parchment start
+ if (player != null && !(new PlayerUseRespawnAnchorEvent(player, block, PlayerUseRespawnAnchorEvent.RespawnAnchorResult.CHARGE).callEvent()))
+ return EnumInteractionResult.PASS;
+ // Parchment end
+
return EnumInteractionResult.a(world.isClientSide);
} else if ((Integer) iblockdata.get(BlockRespawnAnchor.a) == 0) {
return EnumInteractionResult.PASS;
} else if (!a(world)) {
+ // Parchment start
+ if (player != null && !(new PlayerUseRespawnAnchorEvent(player, block, PlayerUseRespawnAnchorEvent.RespawnAnchorResult.EXPLODE).callEvent()))
+ return EnumInteractionResult.PASS;
+ // Parchment end
+
if (!world.isClientSide) {
this.d(iblockdata, world, blockposition);
}
return EnumInteractionResult.a(world.isClientSide);
} else {
+ // Parchment start
+ if (player != null && !(new PlayerUseRespawnAnchorEvent(player, block, PlayerUseRespawnAnchorEvent.RespawnAnchorResult.SET_SPAWN).callEvent()))
+ return EnumInteractionResult.PASS;
+ // Parchment end
+
if (!world.isClientSide) {
EntityPlayer entityplayer = (EntityPlayer) entityhuman;
@@ -115,7 +138,7 @@ public class BlockRespawnAnchor extends Block {
private void d(IBlockData iblockdata, World world, final BlockPosition blockposition) {
world.a(blockposition, false);
- Stream stream = EnumDirection.EnumDirectionLimit.HORIZONTAL.a();
+ Stream<EnumDirection> stream = EnumDirection.EnumDirectionLimit.HORIZONTAL.a(); // Parchment - Fix deobfuscation error
blockposition.getClass();
boolean flag = stream.map(blockposition::shift).anyMatch((blockposition1) -> {

View File

@@ -104,6 +104,7 @@ fi
# import Foo
import world/item/context/BlockActionContext
import world/level/block/BlockRespawnAnchor
########################################################
########################################################