3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 20:40:07 +01:00

SPIGOT-4570: Add FluidLevelChangeEvent

Dieser Commit ist enthalten in:
md_5 2019-01-08 21:23:11 +11:00
Ursprung b15abb12cb
Commit 9dc56581e6
3 geänderte Dateien mit 40 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -1,18 +1,21 @@
--- a/net/minecraft/server/FluidTypeFlowing.java
+++ b/net/minecraft/server/FluidTypeFlowing.java
@@ -10,6 +10,11 @@
@@ -10,6 +10,14 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
+// CraftBukkit start
+import org.bukkit.block.BlockFace;
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.BlockFromToEvent;
+import org.bukkit.event.block.FluidLevelChangeEvent;
+// CraftBukkit end
public abstract class FluidTypeFlowing extends FluidType {
@@ -141,6 +146,15 @@
@@ -141,6 +149,15 @@
Fluid fluid1 = this.a((IWorldReader) generatoraccess, blockposition1, iblockdata1);
if (this.a(generatoraccess, blockposition, iblockdata, EnumDirection.DOWN, blockposition1, iblockdata1, generatoraccess.getFluid(blockposition1), fluid1.c())) {
@ -28,7 +31,7 @@
this.a(generatoraccess, blockposition1, iblockdata1, EnumDirection.DOWN, fluid1);
if (this.a((IWorldReader) generatoraccess, blockposition) >= 3) {
this.a(generatoraccess, blockposition, fluid, iblockdata);
@@ -171,6 +185,15 @@
@@ -171,6 +188,15 @@
IBlockData iblockdata1 = generatoraccess.getType(blockposition1);
if (this.a(generatoraccess, blockposition, iblockdata, enumdirection, blockposition1, iblockdata1, generatoraccess.getFluid(blockposition1), fluid1.c())) {
@ -44,3 +47,30 @@
this.a(generatoraccess, blockposition1, iblockdata1, enumdirection, fluid1);
}
}
@@ -448,12 +474,23 @@
if (fluid1.e()) {
fluid = fluid1;
- world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 3);
+ // CraftBukkit start
+ FluidLevelChangeEvent event = CraftEventFactory.callFluidLevelChangeEvent(world, blockposition, Blocks.AIR.getBlockData());
+ if (event.isCancelled()) {
+ return;
+ }
+ world.setTypeAndData(blockposition, ((CraftBlockData) event.getNewData()).getState(), 3);
+ // CraftBukkit end
} else if (!fluid1.equals(fluid)) {
fluid = fluid1;
IBlockData iblockdata = fluid1.i();
-
- world.setTypeAndData(blockposition, iblockdata, 2);
+ // CraftBukkit start
+ FluidLevelChangeEvent event = CraftEventFactory.callFluidLevelChangeEvent(world, blockposition, iblockdata);
+ if (event.isCancelled()) {
+ return;
+ }
+ world.setTypeAndData(blockposition, ((CraftBlockData) event.getNewData()).getState(), 2);
+ // CraftBukkit end
world.getFluidTickList().a(blockposition, fluid1.c(), i);
world.applyPhysics(blockposition, iblockdata.getBlock());
}

Datei anzeigen

@ -232,7 +232,7 @@ public class CraftBlock implements Block {
@Override
public String toString() {
return "CraftBlock{pos=" + position + ",type=" + getType() + ",data=" + getNMS() + '}';
return "CraftBlock{pos=" + position + ",type=" + getType() + ",data=" + getNMS() + ",fluid=" + world.getFluid(position) + '}';
}
public static BlockFace notchToBlockFace(EnumDirection notch) {

Datei anzeigen

@ -835,6 +835,12 @@ public class CraftEventFactory {
return !event.isCancelled();
}
public static FluidLevelChangeEvent callFluidLevelChangeEvent(World world, BlockPosition block, IBlockData newData) {
FluidLevelChangeEvent event = new FluidLevelChangeEvent(CraftBlock.at(world, block), CraftBlockData.fromData(newData));
world.getServer().getPluginManager().callEvent(event);
return event;
}
public static FoodLevelChangeEvent callFoodLevelChangeEvent(EntityHuman entity, int level) {
FoodLevelChangeEvent event = new FoodLevelChangeEvent(entity.getBukkitEntity(), level);
entity.getBukkitEntity().getServer().getPluginManager().callEvent(event);