Use CraftEventFactory for BlockFormEvent

This commit is contained in:
md_5 2016-12-09 12:45:21 +11:00
parent 521b64741e
commit caf86c88a9
4 changed files with 45 additions and 65 deletions

View File

@ -9,21 +9,14 @@
import java.util.Iterator;
public class EnchantmentFrostWalker extends Enchantment {
@@ -42,8 +45,18 @@
@@ -42,8 +45,11 @@
IBlockData iblockdata1 = world.getType(blockposition_mutableblockposition1);
if (iblockdata1.getMaterial() == Material.WATER && ((Integer) iblockdata1.get(BlockFluids.LEVEL)).intValue() == 0 && world.a(Blocks.FROSTED_ICE, blockposition_mutableblockposition1, false, EnumDirection.DOWN, (Entity) null)) {
- world.setTypeUpdate(blockposition_mutableblockposition1, Blocks.FROSTED_ICE.getBlockData());
- world.a(blockposition_mutableblockposition1.h(), Blocks.FROSTED_ICE, MathHelper.nextInt(entityliving.getRandom(), 60, 120));
+ // CraftBukkit Start - Call EntityBlockFormEvent for Frost Walker
+ org.bukkit.block.BlockState blockState = world.getWorld().getBlockAt(blockposition_mutableblockposition1.getX(), blockposition_mutableblockposition1.getY(), blockposition_mutableblockposition1.getZ()).getState();
+ blockState.setType(CraftMagicNumbers.getMaterial(Blocks.FROSTED_ICE));
+
+ EntityBlockFormEvent event = new EntityBlockFormEvent(entityliving.bukkitEntity, blockState.getBlock(), blockState);
+ world.getServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ blockState.update(true);
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(world, blockposition_mutableblockposition1, Blocks.FROSTED_ICE, entityliving)) {
+ world.a(blockposition_mutableblockposition1.h(), Blocks.FROSTED_ICE, MathHelper.nextInt(entityliving.getRandom(), 60, 120));
+ }
+ // CraftBukkit End

View File

@ -21,22 +21,12 @@
}
if (!this.world.getGameRules().getBoolean("mobGriefing")) {
@@ -73,7 +78,17 @@
@@ -73,7 +78,7 @@
BlockPosition blockposition = new BlockPosition(i, j, k);
if (this.world.getType(blockposition).getMaterial() == Material.AIR && this.world.getBiome(blockposition).a(blockposition) < 0.8F && Blocks.SNOW_LAYER.canPlace(this.world, blockposition)) {
- this.world.setTypeUpdate(blockposition, Blocks.SNOW_LAYER.getBlockData());
+ // CraftBukkit start
+ org.bukkit.block.BlockState blockState = this.world.getWorld().getBlockAt(i, j, k).getState();
+ blockState.setType(CraftMagicNumbers.getMaterial(Blocks.SNOW_LAYER));
+
+ EntityBlockFormEvent event = new EntityBlockFormEvent(this.getBukkitEntity(), blockState.getBlock(), blockState);
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if(!event.isCancelled()) {
+ blockState.update(true);
+ }
+ // CraftBukkit end
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this.world, blockposition, Blocks.SNOW_LAYER, this); // CraftBukkit
}
}
}

View File

@ -267,39 +267,21 @@
this.strikeLightning(new EntityLightning(this, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), true));
} else {
this.strikeLightning(new EntityLightning(this, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), false));
@@ -297,11 +437,29 @@
@@ -297,11 +437,11 @@
BlockPosition blockposition1 = blockposition.down();
if (this.v(blockposition1)) {
- this.setTypeUpdate(blockposition1, Blocks.ICE.getBlockData());
+ // CraftBukkit start
+ BlockState blockState = this.getWorld().getBlockAt(blockposition1.getX(), blockposition1.getY(), blockposition1.getZ()).getState();
+ blockState.setTypeId(Block.getId(Blocks.ICE));
+
+ BlockFormEvent iceBlockForm = new BlockFormEvent(blockState.getBlock(), blockState);
+ this.getServer().getPluginManager().callEvent(iceBlockForm);
+ if (!iceBlockForm.isCancelled()) {
+ blockState.update(true);
+ }
+ // CraftBukkit end
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition1, Blocks.ICE, null); // CraftBukkit
}
if (flag && this.f(blockposition, true)) {
- this.setTypeUpdate(blockposition, Blocks.SNOW_LAYER.getBlockData());
+ // CraftBukkit start
+ BlockState blockState = this.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()).getState();
+ blockState.setTypeId(Block.getId(Blocks.SNOW_LAYER));
+
+ BlockFormEvent snow = new BlockFormEvent(blockState.getBlock(), blockState);
+ this.getServer().getPluginManager().callEvent(snow);
+ if (!snow.isCancelled()) {
+ blockState.update(true);
+ }
+ // CraftBukkit end
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition, Blocks.SNOW_LAYER, null); // CraftBukkit
}
if (flag && this.getBiome(blockposition1).d()) {
@@ -376,7 +534,7 @@
@@ -376,7 +516,7 @@
public boolean b(BlockPosition blockposition, Block block) {
NextTickListEntry nextticklistentry = new NextTickListEntry(blockposition, block);
@ -308,7 +290,7 @@
}
public void a(BlockPosition blockposition, Block block, int i) {
@@ -415,8 +573,8 @@
@@ -415,8 +555,8 @@
nextticklistentry.a(j);
}
@ -319,7 +301,7 @@
this.nextTickList.add(nextticklistentry);
}
}
@@ -438,15 +596,15 @@
@@ -438,15 +578,15 @@
nextticklistentry.a((long) i + this.worldData.getTime());
}
@ -338,7 +320,7 @@
if (this.emptyTime++ >= 300) {
return;
}
@@ -516,11 +674,17 @@
@@ -516,11 +656,17 @@
} else {
int i = this.nextTickList.size();
@ -358,7 +340,7 @@
}
this.methodProfiler.a("cleaning");
@@ -533,8 +697,9 @@
@@ -533,8 +679,9 @@
break;
}
@ -369,7 +351,7 @@
this.U.add(nextticklistentry);
}
@@ -604,7 +769,7 @@
@@ -604,7 +751,7 @@
if (blockposition.getX() >= structureboundingbox.a && blockposition.getX() < structureboundingbox.d && blockposition.getZ() >= structureboundingbox.c && blockposition.getZ() < structureboundingbox.f) {
if (flag) {
if (i == 0) {
@ -378,7 +360,7 @@
}
iterator.remove();
@@ -622,6 +787,7 @@
@@ -622,6 +769,7 @@
return arraylist;
}
@ -386,7 +368,7 @@
public void entityJoinedWorld(Entity entity, boolean flag) {
if (!this.getSpawnAnimals() && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) {
entity.die();
@@ -633,6 +799,7 @@
@@ -633,6 +781,7 @@
super.entityJoinedWorld(entity, flag);
}
@ -394,7 +376,7 @@
private boolean getSpawnNPCs() {
return this.server.getSpawnNPCs();
@@ -645,7 +812,54 @@
@@ -645,7 +794,54 @@
protected IChunkProvider n() {
IChunkLoader ichunkloader = this.dataManager.createChunkLoader(this.worldProvider);
@ -450,7 +432,7 @@
}
public boolean a(EntityHuman entityhuman, BlockPosition blockposition) {
@@ -707,6 +921,23 @@
@@ -707,6 +903,23 @@
int j = this.worldProvider.getSeaLevel();
int k = 8;
@ -474,7 +456,7 @@
if (blockposition != null) {
i = blockposition.getX();
k = blockposition.getZ();
@@ -716,7 +947,7 @@
@@ -716,7 +929,7 @@
int l = 0;
@ -483,7 +465,7 @@
i += random.nextInt(64) - random.nextInt(64);
k += random.nextInt(64) - random.nextInt(64);
++l;
@@ -758,6 +989,7 @@
@@ -758,6 +971,7 @@
ChunkProviderServer chunkproviderserver = this.getChunkProviderServer();
if (chunkproviderserver.e()) {
@ -491,7 +473,7 @@
if (iprogressupdate != null) {
iprogressupdate.a("Saving level");
}
@@ -768,7 +1000,8 @@
@@ -768,7 +982,8 @@
}
chunkproviderserver.a(flag);
@ -501,7 +483,7 @@
Iterator iterator = arraylist.iterator();
while (iterator.hasNext()) {
@@ -803,6 +1036,12 @@
@@ -803,6 +1018,12 @@
}
}
@ -514,7 +496,7 @@
this.worldData.a(this.getWorldBorder().getSize());
this.worldData.d(this.getWorldBorder().getCenterX());
this.worldData.c(this.getWorldBorder().getCenterZ());
@@ -816,9 +1055,13 @@
@@ -816,9 +1037,13 @@
this.worldMaps.a();
}
@ -530,7 +512,7 @@
public void a(Collection<Entity> collection) {
ArrayList arraylist = Lists.newArrayList(collection);
@@ -837,7 +1080,7 @@
@@ -837,7 +1062,7 @@
private boolean i(Entity entity) {
if (entity.dead) {
@ -539,7 +521,7 @@
return false;
} else {
UUID uuid = entity.getUniqueID();
@@ -849,7 +1092,7 @@
@@ -849,7 +1074,7 @@
this.f.remove(entity1);
} else {
if (!(entity instanceof EntityHuman)) {
@ -548,7 +530,7 @@
return false;
}
@@ -902,8 +1145,16 @@
@@ -902,8 +1127,16 @@
}
public boolean strikeLightning(Entity entity) {
@ -566,7 +548,7 @@
return true;
} else {
return false;
@@ -919,10 +1170,20 @@
@@ -919,10 +1152,20 @@
}
public Explosion createExplosion(@Nullable Entity entity, double d0, double d1, double d2, float f, boolean flag, boolean flag1) {
@ -587,7 +569,7 @@
if (!flag1) {
explosion.clearBlocks();
}
@@ -968,7 +1229,8 @@
@@ -968,7 +1211,8 @@
BlockActionData blockactiondata = (BlockActionData) iterator.next();
if (this.a(blockactiondata)) {
@ -597,7 +579,7 @@
}
}
@@ -991,6 +1253,7 @@
@@ -991,6 +1235,7 @@
boolean flag = this.W();
super.t();
@ -605,7 +587,7 @@
if (this.n != this.o) {
this.server.getPlayerList().a((Packet) (new PacketPlayOutGameStateChange(7, this.o)), this.worldProvider.getDimensionManager().getDimensionID());
}
@@ -1009,6 +1272,21 @@
@@ -1009,6 +1254,21 @@
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(7, this.o));
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(8, this.q));
}
@ -627,7 +609,7 @@
}
@@ -1038,10 +1316,20 @@
@@ -1038,10 +1298,20 @@
}
public void a(EnumParticle enumparticle, boolean flag, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6, int... aint) {

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import com.google.common.base.Function;
import com.google.common.base.Functions;
@ -1028,4 +1029,18 @@ public class CraftEventFactory {
child.world.getServer().getPluginManager().callEvent(event);
return event;
}
public static boolean handleBlockFormEvent(World world, BlockPosition pos, net.minecraft.server.Block block, @Nullable Entity entity) {
BlockState blockState = world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()).getState();
blockState.setType(CraftMagicNumbers.getMaterial(block));
BlockFormEvent event = (entity == null) ? new BlockFormEvent(blockState.getBlock(), blockState) : new EntityBlockFormEvent(entity.getBukkitEntity(), blockState.getBlock(), blockState);
world.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
blockState.update(true);
}
return !event.isCancelled();
}
}