Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/nms-patches/BlockButtonAbstract.patch

111 Zeilen
5.1 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/BlockButtonAbstract.java
+++ b/net/minecraft/server/BlockButtonAbstract.java
2016-05-10 13:47:39 +02:00
@@ -4,6 +4,11 @@
import java.util.Random;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.event.block.BlockRedstoneEvent;
+import org.bukkit.event.entity.EntityInteractEvent;
+// CraftBukkit end
+
2016-02-29 22:32:46 +01:00
public abstract class BlockButtonAbstract extends BlockDirectional {
2016-02-29 22:32:46 +01:00
public static final BlockStateBoolean POWERED = BlockStateBoolean.of("powered");
2017-05-14 04:00:00 +02:00
@@ -126,6 +131,19 @@
if (((Boolean) iblockdata.get(BlockButtonAbstract.POWERED)).booleanValue()) {
return true;
} else {
+ // CraftBukkit start
+ boolean powered = ((Boolean) iblockdata.get(POWERED));
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ int old = (powered) ? 15 : 0;
+ int current = (!powered) ? 15 : 0;
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current);
+ world.getServer().getPluginManager().callEvent(eventRedstone);
+
+ if ((eventRedstone.getNewCurrent() > 0) != (!powered)) {
+ return true;
+ }
+ // CraftBukkit end
world.setTypeAndData(blockposition, iblockdata.set(BlockButtonAbstract.POWERED, Boolean.valueOf(true)), 3);
world.b(blockposition, blockposition);
2016-02-29 22:32:46 +01:00
this.a(entityhuman, world, blockposition);
2017-05-14 04:00:00 +02:00
@@ -167,6 +185,16 @@
2016-02-29 22:32:46 +01:00
if (this.I) {
2016-11-17 02:41:03 +01:00
this.d(iblockdata, world, blockposition);
} else {
+ // CraftBukkit start
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 15, 0);
+ world.getServer().getPluginManager().callEvent(eventRedstone);
+
+ if (eventRedstone.getNewCurrent() > 0) {
+ return;
+ }
+ // CraftBukkit end
world.setTypeUpdate(blockposition, iblockdata.set(BlockButtonAbstract.POWERED, Boolean.valueOf(false)));
2015-02-26 23:41:06 +01:00
this.c(world, blockposition, (EnumDirection) iblockdata.get(BlockButtonAbstract.FACING));
2016-02-29 22:32:46 +01:00
this.b(world, blockposition);
2017-05-14 04:00:00 +02:00
@@ -192,7 +220,41 @@
boolean flag = !list.isEmpty();
boolean flag1 = ((Boolean) iblockdata.get(BlockButtonAbstract.POWERED)).booleanValue();
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - Call interact event when arrows turn on wooden buttons
+ if (flag1 != flag && flag) {
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ boolean allowed = false;
+
+ // If all of the events are cancelled block the button press, else allow
+ for (Object object : list) {
+ if (object != null) {
+ EntityInteractEvent event = new EntityInteractEvent(((Entity) object).getBukkitEntity(), block);
+ world.getServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ allowed = true;
+ break;
+ }
+ }
+ }
+
+ if (!allowed) {
+ return;
+ }
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
if (flag && !flag1) {
+ // CraftBukkit start
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 0, 15);
+ world.getServer().getPluginManager().callEvent(eventRedstone);
+
+ if (eventRedstone.getNewCurrent() <= 0) {
+ return;
+ }
+ // CraftBukkit end
world.setTypeUpdate(blockposition, iblockdata.set(BlockButtonAbstract.POWERED, Boolean.valueOf(true)));
2015-02-26 23:41:06 +01:00
this.c(world, blockposition, (EnumDirection) iblockdata.get(BlockButtonAbstract.FACING));
world.b(blockposition, blockposition);
2017-05-14 04:00:00 +02:00
@@ -200,6 +262,16 @@
}
if (!flag && flag1) {
+ // CraftBukkit start
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 15, 0);
+ world.getServer().getPluginManager().callEvent(eventRedstone);
+
+ if (eventRedstone.getNewCurrent() > 0) {
+ return;
+ }
+ // CraftBukkit end
world.setTypeUpdate(blockposition, iblockdata.set(BlockButtonAbstract.POWERED, Boolean.valueOf(false)));
2015-02-26 23:41:06 +01:00
this.c(world, blockposition, (EnumDirection) iblockdata.get(BlockButtonAbstract.FACING));
world.b(blockposition, blockposition);