13
0
geforkt von Mirrors/Paper

SPIGOT-7396: Add PlayerSignOpenEvent

By: Miles Holder <mwholder2005@gmail.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2023-08-05 09:33:42 +10:00
Ursprung 2a8121eac7
Commit 6d8757cb05
4 geänderte Dateien mit 59 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -242,7 +242,7 @@
+ try {
+ if (world.getBlockEntity(ItemSign.openSign) instanceof TileEntitySign tileentitysign) {
+ if (world.getBlockState(ItemSign.openSign).getBlock() instanceof BlockSign blocksign) {
+ blocksign.openTextEdit(entityhuman, tileentitysign, true);
+ blocksign.openTextEdit(entityhuman, tileentitysign, true, org.bukkit.event.player.PlayerSignOpenEvent.Cause.PLACE); // Craftbukkit
+ }
+ }
+ } finally {

Datei anzeigen

@ -0,0 +1,27 @@
--- a/net/minecraft/world/level/block/BlockSign.java
+++ b/net/minecraft/world/level/block/BlockSign.java
@@ -115,7 +115,7 @@
} else if (flag2) {
return EnumInteractionResult.SUCCESS;
} else if (!this.otherPlayerIsEditingSign(entityhuman, tileentitysign) && entityhuman.mayBuild() && this.hasEditableText(entityhuman, tileentitysign, flag1)) {
- this.openTextEdit(entityhuman, tileentitysign, flag1);
+ this.openTextEdit(entityhuman, tileentitysign, flag1, org.bukkit.event.player.PlayerSignOpenEvent.Cause.INTERACT); // CraftBukkit
return EnumInteractionResult.SUCCESS;
} else {
return EnumInteractionResult.PASS;
@@ -164,6 +164,15 @@
}
public void openTextEdit(EntityHuman entityhuman, TileEntitySign tileentitysign, boolean flag) {
+ // Craftbukkit start
+ openTextEdit(entityhuman, tileentitysign, flag, org.bukkit.event.player.PlayerSignOpenEvent.Cause.UNKNOWN);
+ }
+
+ public void openTextEdit(EntityHuman entityhuman, TileEntitySign tileentitysign, boolean flag, org.bukkit.event.player.PlayerSignOpenEvent.Cause cause) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerSignOpenEvent(entityhuman, tileentitysign, flag, cause)) {
+ return;
+ }
+ // Craftbukkit end
tileentitysign.setAllowedPlayerEditor(entityhuman.getUUID());
entityhuman.openTextEdit(tileentitysign, flag);
}

Datei anzeigen

@ -10,8 +10,10 @@ import org.bukkit.block.sign.Side;
import org.bukkit.block.sign.SignSide;
import org.bukkit.craftbukkit.block.sign.CraftSignSide;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerSignOpenEvent;
import org.jetbrains.annotations.NotNull;
public class CraftSign<T extends TileEntitySign> extends CraftBlockEntityState<T> implements Sign {
@ -111,6 +113,10 @@ public class CraftSign<T extends TileEntitySign> extends CraftBlockEntityState<T
TileEntitySign handle = ((CraftSign<?>) sign).getTileEntity();
if (!CraftEventFactory.callPlayerSignOpenEvent(player, sign, side, PlayerSignOpenEvent.Cause.PLUGIN)) {
return;
}
((CraftPlayer) player).getHandle().openTextEdit(handle, Side.FRONT == side);
}

Datei anzeigen

@ -63,6 +63,7 @@ import net.minecraft.world.level.ChunkCoordIntPair;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.GeneratorAccess;
import net.minecraft.world.level.World;
import net.minecraft.world.level.block.entity.TileEntitySign;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.block.state.properties.BlockPropertyInstrument;
import net.minecraft.world.level.storage.loot.LootTable;
@ -81,6 +82,8 @@ import org.bukkit.Statistic.Type;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.block.sign.Side;
import org.bukkit.craftbukkit.CraftChunk;
import org.bukkit.craftbukkit.CraftEquipmentSlot;
import org.bukkit.craftbukkit.CraftLootTable;
@ -231,6 +234,7 @@ import org.bukkit.event.player.PlayerLevelChangeEvent;
import org.bukkit.event.player.PlayerRecipeBookClickEvent;
import org.bukkit.event.player.PlayerRecipeDiscoverEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.player.PlayerSignOpenEvent;
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
import org.bukkit.event.player.PlayerUnleashEntityEvent;
import org.bukkit.event.raid.RaidFinishEvent;
@ -274,6 +278,25 @@ public class CraftEventFactory {
return event;
}
/**
* PlayerSignOpenEvent
*/
public static boolean callPlayerSignOpenEvent(EntityHuman player, TileEntitySign tileEntitySign, boolean front, PlayerSignOpenEvent.Cause cause) {
final Block block = CraftBlock.at(tileEntitySign.getLevel(), tileEntitySign.getBlockPos());
final Sign sign = (Sign) CraftBlockStates.getBlockState(block);
final Side side = (front) ? Side.FRONT : Side.BACK;
return callPlayerSignOpenEvent((Player) player.getBukkitEntity(), sign, side, cause);
}
/**
* PlayerSignOpenEvent
*/
public static boolean callPlayerSignOpenEvent(Player player, Sign sign, Side side, PlayerSignOpenEvent.Cause cause) {
final PlayerSignOpenEvent event = new PlayerSignOpenEvent(player, sign, side, cause);
Bukkit.getPluginManager().callEvent(event);
return !event.isCancelled();
}
/**
* PlayerBedEnterEvent
*/
@ -809,6 +832,7 @@ public class CraftEventFactory {
}
public static BlockPosition sourceBlockOverride = null; // SPIGOT-7068: Add source block override, not the most elegant way but better than passing down a BlockPosition up to five methods deep.
public static boolean handleBlockSpreadEvent(GeneratorAccess world, BlockPosition source, BlockPosition target, IBlockData block, int flag) {
// Suppress during worldgen
if (!(world instanceof World)) {
@ -1764,6 +1788,7 @@ public class CraftEventFactory {
EntitiesLoadEvent event = new EntitiesLoadEvent(new CraftChunk((WorldServer) world, coords.x, coords.z), bukkitEntities);
Bukkit.getPluginManager().callEvent(event);
}
public static void callEntitiesUnloadEvent(World world, ChunkCoordIntPair coords, List<Entity> entities) {
List<org.bukkit.entity.Entity> bukkitEntities = Collections.unmodifiableList(entities.stream().map(Entity::getBukkitEntity).collect(Collectors.toList()));
EntitiesUnloadEvent event = new EntitiesUnloadEvent(new CraftChunk((WorldServer) world, coords.x, coords.z), bukkitEntities);