mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
Add BlockFailedDispenseEvent
Co-authored-by: MiniDigger | Martin <admin@minidigger.dev>
This commit is contained in:
parent
3ca5850362
commit
5e08466cc1
2 changed files with 176 additions and 0 deletions
69
Spigot-API-Patches/Add-BlockFailedDispenseEvent.patch
Normal file
69
Spigot-API-Patches/Add-BlockFailedDispenseEvent.patch
Normal file
|
@ -0,0 +1,69 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: TheViperShow <29604693+TheViperShow@users.noreply.github.com>
|
||||
Date: Wed, 22 Apr 2020 09:40:23 +0200
|
||||
Subject: [PATCH] Add BlockFailedDispenseEvent
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/event/block/BlockFailedDispenseEvent.java b/src/main/java/io/papermc/paper/event/block/BlockFailedDispenseEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/event/block/BlockFailedDispenseEvent.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.event.block;
|
||||
+
|
||||
+import org.bukkit.block.Block;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.block.BlockEvent;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+/**
|
||||
+ * Called when a block tries to dispense an item, but its inventory is empty.
|
||||
+ */
|
||||
+public class BlockFailedDispenseEvent extends BlockEvent {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+
|
||||
+ private boolean shouldPlayEffect = true;
|
||||
+
|
||||
+ public BlockFailedDispenseEvent(@NotNull Block theBlock) {
|
||||
+ super(theBlock);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @return if the effect should be played
|
||||
+ */
|
||||
+ public boolean shouldPlayEffect() {
|
||||
+ return this.shouldPlayEffect;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Sets if the effect for empty dispensers should be played
|
||||
+ *
|
||||
+ * @param playEffect if the effect should be played
|
||||
+ */
|
||||
+ public void shouldPlayEffect(boolean playEffect) {
|
||||
+ this.shouldPlayEffect = playEffect;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * {@inheritDoc}
|
||||
+ *
|
||||
+ * @return {@link #shouldPlayEffect()}
|
||||
+ */
|
||||
+ @Override
|
||||
+ public boolean callEvent() {
|
||||
+ super.callEvent();
|
||||
+ return this.shouldPlayEffect();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull
|
||||
+ HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ public static @NotNull
|
||||
+ HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+}
|
107
Spigot-Server-Patches/Implemented-BlockFailedDispenseEvent.patch
Normal file
107
Spigot-Server-Patches/Implemented-BlockFailedDispenseEvent.patch
Normal file
|
@ -0,0 +1,107 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: TheViperShow <29604693+TheViperShow@users.noreply.github.com>
|
||||
Date: Wed, 22 Apr 2020 09:40:38 +0200
|
||||
Subject: [PATCH] Implemented BlockFailedDispenseEvent
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/BlockDispenser.java b/src/main/java/net/minecraft/server/BlockDispenser.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/BlockDispenser.java
|
||||
+++ b/src/main/java/net/minecraft/server/BlockDispenser.java
|
||||
@@ -0,0 +0,0 @@ public class BlockDispenser extends BlockTileEntity {
|
||||
int i = tileentitydispenser.h();
|
||||
|
||||
if (i < 0) {
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFailedDispenseEvent(worldserver, blockposition)) // Paper - BlockFailedDispenseEvent is called here
|
||||
worldserver.triggerEffect(1001, blockposition, 0);
|
||||
} else {
|
||||
ItemStack itemstack = tileentitydispenser.getItem(i);
|
||||
diff --git a/src/main/java/net/minecraft/server/BlockDropper.java b/src/main/java/net/minecraft/server/BlockDropper.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/BlockDropper.java
|
||||
+++ b/src/main/java/net/minecraft/server/BlockDropper.java
|
||||
@@ -0,0 +0,0 @@ public class BlockDropper extends BlockDispenser {
|
||||
int i = tileentitydispenser.h();
|
||||
|
||||
if (i < 0) {
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFailedDispenseEvent(worldserver, blockposition)) // Paper - BlockFailedDispenseEvent is called here
|
||||
worldserver.triggerEffect(1001, blockposition, 0);
|
||||
} else {
|
||||
ItemStack itemstack = tileentitydispenser.getItem(i);
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
@@ -0,0 +0,0 @@ import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
+import io.papermc.paper.event.block.BlockFailedDispenseEvent;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -0,0 +0,0 @@ import net.minecraft.server.EntityAnimal;
|
||||
import net.minecraft.server.EntityAreaEffectCloud;
|
||||
import net.minecraft.server.EntityDamageSource;
|
||||
import net.minecraft.server.EntityDamageSourceIndirect;
|
||||
-import net.minecraft.server.EntityEnderCrystal;
|
||||
import net.minecraft.server.EntityEnderDragon;
|
||||
import net.minecraft.server.EntityExperienceOrb;
|
||||
import net.minecraft.server.EntityFireworks;
|
||||
@@ -0,0 +0,0 @@ import net.minecraft.server.EntityVillager;
|
||||
import net.minecraft.server.EntityWaterAnimal;
|
||||
import net.minecraft.server.EnumDirection;
|
||||
import net.minecraft.server.EnumHand;
|
||||
-import net.minecraft.server.EnumItemSlot;
|
||||
import net.minecraft.server.Explosion;
|
||||
import net.minecraft.server.GeneratorAccess;
|
||||
import net.minecraft.server.IBlockData;
|
||||
-import net.minecraft.server.IChatBaseComponent;
|
||||
import net.minecraft.server.IInventory;
|
||||
import net.minecraft.server.IProjectile;
|
||||
import net.minecraft.server.ItemActionContext;
|
||||
@@ -0,0 +0,0 @@ import net.minecraft.server.Unit;
|
||||
import net.minecraft.server.World;
|
||||
import net.minecraft.server.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
-import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Server;
|
||||
@@ -0,0 +0,0 @@ import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
-import org.bukkit.entity.ExperienceOrb; // Paper
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Result;
|
||||
@@ -0,0 +0,0 @@ import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityEnterLoveModeEvent;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.entity.EntityPlaceEvent;
|
||||
-import org.bukkit.event.entity.EntityPortalEvent;
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
@@ -0,0 +0,0 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
-import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import org.bukkit.event.entity.SpawnerSpawnEvent; // Spigot
|
||||
|
||||
@@ -0,0 +0,0 @@ public class CraftEventFactory {
|
||||
|
||||
return event;
|
||||
}
|
||||
+
|
||||
+ // Paper start
|
||||
+ public static boolean handleBlockFailedDispenseEvent(WorldServer worldserver, BlockPosition blockposition) {
|
||||
+ org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
|
||||
+ BlockFailedDispenseEvent event = new BlockFailedDispenseEvent(block);
|
||||
+ return event.callEvent();
|
||||
+ }
|
||||
+ // Paper end
|
||||
}
|
Loading…
Reference in a new issue