PaperMC/nms-patches/BlockPressurePlateWeighted.patch
2020-06-25 10:00:00 +10:00

43 lines
1.9 KiB
Diff

--- a/net/minecraft/server/BlockPressurePlateWeighted.java
+++ b/net/minecraft/server/BlockPressurePlateWeighted.java
@@ -1,5 +1,7 @@
package net.minecraft.server;
+import org.bukkit.event.entity.EntityInteractEvent; // CraftBukkit
+
public class BlockPressurePlateWeighted extends BlockPressurePlateAbstract {
public static final BlockStateInteger POWER = BlockProperties.az;
@@ -13,7 +15,31 @@
@Override
protected int b(World world, BlockPosition blockposition) {
- int i = Math.min(world.a(Entity.class, BlockPressurePlateWeighted.c.a(blockposition)).size(), this.weight);
+ // CraftBukkit start
+ // int i = Math.min(world.a(Entity.class, BlockPressurePlateWeighted.c.a(blockposition)).size(), this.weight);
+ int i = 0;
+ java.util.Iterator iterator = world.a(Entity.class, BlockPressurePlateWeighted.c.a(blockposition)).iterator();
+
+ while (iterator.hasNext()) {
+ Entity entity = (Entity) iterator.next();
+
+ org.bukkit.event.Cancellable cancellable;
+
+ if (entity instanceof EntityHuman) {
+ cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+ } else {
+ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ world.getServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
+ }
+
+ // We only want to block turning the plate on if all events are cancelled
+ if (!cancellable.isCancelled()) {
+ i++;
+ }
+ }
+
+ i = Math.min(i, this.weight);
+ // CraftBukkit end
if (i > 0) {
float f = (float) Math.min(this.weight, i) / (float) this.weight;