summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArticdive <articdive@gmail.com>2018-07-23 17:20:52 +1000
committermd_5 <git@md-5.net>2018-07-23 17:21:07 +1000
commit30ab12cf4ceea49628d27e66fb06f00b9b29aa57 (patch)
tree860e3e55d376c91f2e53e4d5de9ca7420b767691
parentb50bb15f56ff4e6541b0c053ca4f725dfc815a19 (diff)
downloadcraftbukkit-30ab12cf4ceea49628d27e66fb06f00b9b29aa57.tar
craftbukkit-30ab12cf4ceea49628d27e66fb06f00b9b29aa57.tar.gz
craftbukkit-30ab12cf4ceea49628d27e66fb06f00b9b29aa57.tar.lz
craftbukkit-30ab12cf4ceea49628d27e66fb06f00b9b29aa57.tar.xz
craftbukkit-30ab12cf4ceea49628d27e66fb06f00b9b29aa57.zip
SPIGOT-824: SpongeAbsorbEvent
-rw-r--r--nms-patches/BlockSponge.patch80
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/BlockStateListPopulator.java25
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java2
3 files changed, 92 insertions, 15 deletions
diff --git a/nms-patches/BlockSponge.patch b/nms-patches/BlockSponge.patch
new file mode 100644
index 00000000..a73f8781
--- /dev/null
+++ b/nms-patches/BlockSponge.patch
@@ -0,0 +1,80 @@
+--- a/net/minecraft/server/BlockSponge.java
++++ b/net/minecraft/server/BlockSponge.java
+@@ -2,6 +2,12 @@
+
+ import com.google.common.collect.Lists;
+ import java.util.LinkedList;
++// CraftBukkit start
++import java.util.List;
++import org.bukkit.craftbukkit.block.CraftBlockState;
++import org.bukkit.craftbukkit.util.BlockStateListPopulator;
++import org.bukkit.event.block.SpongeAbsorbEvent;
++// CraftBukkit end
+
+ public class BlockSponge extends Block {
+
+@@ -33,6 +39,7 @@
+
+ linkedlist.add(new Tuple(blockposition, Integer.valueOf(0)));
+ int i = 0;
++ BlockStateListPopulator blockList = new BlockStateListPopulator(world); // CraftBukkit - Use BlockStateListPopulator
+
+ while (!linkedlist.isEmpty()) {
+ Tuple tuple = (Tuple) linkedlist.poll();
+@@ -49,20 +56,20 @@
+ Material material = iblockdata.getMaterial();
+
+ if (fluid.a(TagsFluid.a)) {
+- if (iblockdata.getBlock() instanceof IFluidSource && ((IFluidSource) iblockdata.getBlock()).a(world, blockposition2, iblockdata) != FluidTypes.a) {
++ if (iblockdata.getBlock() instanceof IFluidSource && ((IFluidSource) iblockdata.getBlock()).a(blockList, blockposition2, iblockdata) != FluidTypes.a) { // CraftBukkit
+ ++i;
+ if (j < 6) {
+ linkedlist.add(new Tuple(blockposition2, Integer.valueOf(j + 1)));
+ }
+ } else if (iblockdata.getBlock() instanceof BlockFluids) {
+- world.setTypeAndData(blockposition2, Blocks.AIR.getBlockData(), 3);
++ blockList.setTypeAndData(blockposition2, Blocks.AIR.getBlockData(), 3); // CraftBukkit
+ ++i;
+ if (j < 6) {
+ linkedlist.add(new Tuple(blockposition2, Integer.valueOf(j + 1)));
+ }
+ } else if (material == Material.WATER_PLANT || material == Material.REPLACEABLE_WATER_PLANT) {
+- iblockdata.a(world, blockposition2, 0);
+- world.setTypeAndData(blockposition2, Blocks.AIR.getBlockData(), 3);
++ // iblockdata.a(world, blockposition2, 0);
++ blockList.setTypeAndData(blockposition2, Blocks.AIR.getBlockData(), 3); // CraftBukkit
+ ++i;
+ if (j < 6) {
+ linkedlist.add(new Tuple(blockposition2, Integer.valueOf(j + 1)));
+@@ -75,6 +82,31 @@
+ break;
+ }
+ }
++ // CraftBukkit start
++ List<CraftBlockState> blocks = blockList.getList();
++ if (!blocks.isEmpty()) {
++ final org.bukkit.block.Block bblock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
++
++ SpongeAbsorbEvent event = new SpongeAbsorbEvent(bblock, (List<org.bukkit.block.BlockState>) (List) blocks);
++ world.getServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ return false;
++ }
++
++ for (CraftBlockState block : blocks) {
++ BlockPosition blockposition2 = new BlockPosition(block.getX(), block.getY(), block.getZ());
++ IBlockData iblockdata = world.getType(blockposition2);
++ Material material = iblockdata.getMaterial();
++
++ if (material == Material.WATER_PLANT || material == Material.REPLACEABLE_WATER_PLANT) {
++ iblockdata.a(world, blockposition2, 0);
++ }
++
++ world.setTypeAndData(blockposition2, block.getHandle(), block.getFlag());
++ }
++ }
++ // CraftBukkit end
+
+ return i > 0;
+ }
diff --git a/src/main/java/org/bukkit/craftbukkit/util/BlockStateListPopulator.java b/src/main/java/org/bukkit/craftbukkit/util/BlockStateListPopulator.java
index 3db85a3b..165843dd 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/BlockStateListPopulator.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/BlockStateListPopulator.java
@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.util;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
import net.minecraft.server.BlockPosition;
@@ -10,39 +11,35 @@ import net.minecraft.server.World;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.block.CraftBlockState;
-public class BlockStateListPopulator {
+public class BlockStateListPopulator extends DummyGeneratorAccess {
private final World world;
- private final List<CraftBlockState> list;
+ private final LinkedHashMap<BlockPosition, CraftBlockState> list;
public BlockStateListPopulator(World world) {
- this(world, new ArrayList<CraftBlockState>());
+ this(world, new LinkedHashMap<>());
}
- public BlockStateListPopulator(World world, List<CraftBlockState> list) {
+ public BlockStateListPopulator(World world, LinkedHashMap<BlockPosition, CraftBlockState> list) {
this.world = world;
this.list = list;
}
- public void setTypeUpdate(BlockPosition position, IBlockData data) {
- CraftBlockState state = CraftBlockState.getBlockState(world, position);
- state.setData(data);
- list.add(state);
- }
-
- public void setTypeAndData(BlockPosition position, IBlockData data, int flag) {
+ @Override
+ public boolean setTypeAndData(BlockPosition position, IBlockData data, int flag) {
CraftBlockState state = CraftBlockState.getBlockState(world, position, flag);
state.setData(data);
- list.add(state);
+ list.put(position, state);
+ return true;
}
public void updateList() {
- for (BlockState state : list) {
+ for (BlockState state : list.values()) {
state.update(true);
}
}
public List<CraftBlockState> getList() {
- return list;
+ return new ArrayList<>(list.values());
}
public World getWorld() {
diff --git a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
index 2d6e7089..897c8cc5 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
@@ -39,7 +39,7 @@ public class DummyGeneratorAccess implements GeneratorAccess {
public static final GeneratorAccess INSTANCE = new DummyGeneratorAccess();
- private DummyGeneratorAccess() {
+ protected DummyGeneratorAccess() {
}
@Override