mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
Add PlayerFlowerPotManipulateEvent
This commit is contained in:
parent
20b298c421
commit
428affde24
2 changed files with 141 additions and 0 deletions
94
Spigot-API-Patches/Add-PlayerFlowerPotManipulateEvent.patch
Normal file
94
Spigot-API-Patches/Add-PlayerFlowerPotManipulateEvent.patch
Normal file
|
@ -0,0 +1,94 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MisterVector <whizkid3000@hotmail.com>
|
||||
Date: Tue, 13 Aug 2019 19:44:19 -0700
|
||||
Subject: [PATCH] Add PlayerFlowerPotManipulateEvent
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/event/player/PlayerFlowerPotManipulateEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerFlowerPotManipulateEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/event/player/PlayerFlowerPotManipulateEvent.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.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.bukkit.inventory.ItemStack;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+/**
|
||||
+ * Called when a player places an item in or takes an item out of a flowerpot.
|
||||
+ */
|
||||
+public class PlayerFlowerPotManipulateEvent extends PlayerEvent implements Cancellable {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+
|
||||
+ @NotNull
|
||||
+ private final Block flowerpot;
|
||||
+ @NotNull
|
||||
+ private final ItemStack item;
|
||||
+ private final boolean placing;
|
||||
+
|
||||
+ private boolean cancel = false;
|
||||
+
|
||||
+ public PlayerFlowerPotManipulateEvent(@NotNull final Player player, @NotNull final Block flowerpot, @NotNull final ItemStack item, final boolean placing) {
|
||||
+ super(player);
|
||||
+ this.flowerpot = flowerpot;
|
||||
+ this.item = item;
|
||||
+ this.placing = placing;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCancelled() {
|
||||
+ return cancel;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setCancelled(boolean cancel) {
|
||||
+ this.cancel = cancel;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the flowerpot that is involved in this event.
|
||||
+ *
|
||||
+ * @return the flowerpot that is involved with this event
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public Block getFlowerpot() {
|
||||
+ return flowerpot;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the item being placed, or taken from, the flower pot.
|
||||
+ * Check if placing with {@link #isPlacing()}.
|
||||
+ *
|
||||
+ * @return the item placed, or taken from, the flowerpot
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public ItemStack getItem() {
|
||||
+ return item;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets if the item is being placed into the flowerpot.
|
||||
+ *
|
||||
+ * @return if the item is being placed into the flowerpot
|
||||
+ */
|
||||
+ public boolean isPlacing() {
|
||||
+ return placing;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ @Override
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+}
|
|
@ -0,0 +1,47 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MisterVector <whizkid3000@hotmail.com>
|
||||
Date: Tue, 13 Aug 2019 19:45:06 -0700
|
||||
Subject: [PATCH] Implement PlayerFlowerPotManipulateEvent
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/BlockFlowerPot.java b/src/main/java/net/minecraft/server/BlockFlowerPot.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/BlockFlowerPot.java
|
||||
+++ b/src/main/java/net/minecraft/server/BlockFlowerPot.java
|
||||
@@ -0,0 +0,0 @@ package net.minecraft.server;
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Map;
|
||||
|
||||
+import io.papermc.paper.event.player.PlayerFlowerPotManipulateEvent; // Paper
|
||||
+
|
||||
public class BlockFlowerPot extends Block {
|
||||
|
||||
private static final Map<Block, Block> b = Maps.newHashMap();
|
||||
@@ -0,0 +0,0 @@ public class BlockFlowerPot extends Block {
|
||||
boolean flag1 = this.c == Blocks.AIR;
|
||||
|
||||
if (flag != flag1) {
|
||||
+ // Paper start
|
||||
+ org.bukkit.entity.Player player = (org.bukkit.entity.Player) entityhuman.getBukkitEntity();
|
||||
+ boolean placing = flag1;
|
||||
+ org.bukkit.block.Block bukkitblock = org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition);
|
||||
+ org.bukkit.inventory.ItemStack bukkititemstack = org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack);
|
||||
+ org.bukkit.Material mat = org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(c);
|
||||
+ org.bukkit.inventory.ItemStack bukkititemstack1 = new org.bukkit.inventory.ItemStack(mat, 1);
|
||||
+ org.bukkit.inventory.ItemStack whichitem = placing ? bukkititemstack : bukkititemstack1;
|
||||
+
|
||||
+ PlayerFlowerPotManipulateEvent event = new PlayerFlowerPotManipulateEvent(player, bukkitblock, whichitem, placing);
|
||||
+ player.getServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ if (event.isCancelled()) {
|
||||
+ // Update client
|
||||
+ player.sendBlockChange(bukkitblock.getLocation(), bukkitblock.getBlockData());
|
||||
+ player.updateInventory();
|
||||
+
|
||||
+ return EnumInteractionResult.PASS;
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
if (flag1) {
|
||||
world.setTypeAndData(blockposition, block.getBlockData(), 3);
|
||||
entityhuman.a(StatisticList.POT_FLOWER);
|
Loading…
Reference in a new issue