From f165d4082d36e181d6b2df06d4937688716f6cdc Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Mon, 29 Aug 2011 16:09:13 +0100 Subject: [PATCH] Refactored some code from nms to ob for minimal diffs --- .../java/net/minecraft/server/BlockIce.java | 11 ++------ .../java/net/minecraft/server/BlockSnow.java | 11 ++------ .../craftbukkit/event/CraftEventFactory.java | 25 +++++++++++-------- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/main/java/net/minecraft/server/BlockIce.java b/src/main/java/net/minecraft/server/BlockIce.java index 1604495806..44f3573b0f 100644 --- a/src/main/java/net/minecraft/server/BlockIce.java +++ b/src/main/java/net/minecraft/server/BlockIce.java @@ -1,8 +1,7 @@ package net.minecraft.server; import java.util.Random; - -import org.bukkit.event.block.BlockFadeEvent; // CraftBukkit +import org.bukkit.craftbukkit.event.CraftEventFactory; public class BlockIce extends BlockBreakable { @@ -28,13 +27,7 @@ public class BlockIce extends BlockBreakable { public void a(World world, int i, int j, int k, Random random) { if (world.a(EnumSkyBlock.BLOCK, i, j, k) > 11 - Block.q[this.id]) { // CraftBukkit start - org.bukkit.block.BlockState blockState = world.getWorld().getBlockAt(i, j, k).getState(); - blockState.setTypeId(Block.STATIONARY_WATER.id); - - BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState); - world.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { + if (CraftEventFactory.callBlockFadeEvent(world.getWorld().getBlockAt(i, j, k), Block.STATIONARY_WATER.id).isCancelled()) { return; } // CraftBukkit end diff --git a/src/main/java/net/minecraft/server/BlockSnow.java b/src/main/java/net/minecraft/server/BlockSnow.java index 22fa603e23..bec1991925 100644 --- a/src/main/java/net/minecraft/server/BlockSnow.java +++ b/src/main/java/net/minecraft/server/BlockSnow.java @@ -1,8 +1,7 @@ package net.minecraft.server; import java.util.Random; - -import org.bukkit.event.block.BlockFadeEvent; // CraftBukkit +import org.bukkit.craftbukkit.event.CraftEventFactory; public class BlockSnow extends Block { @@ -78,13 +77,7 @@ public class BlockSnow extends Block { public void a(World world, int i, int j, int k, Random random) { if (world.a(EnumSkyBlock.BLOCK, i, j, k) > 11) { // CraftBukkit start - org.bukkit.block.BlockState blockState = world.getWorld().getBlockAt(i, j, k).getState(); - blockState.setTypeId(0); - - BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState); - world.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { + if (CraftEventFactory.callBlockFadeEvent(world.getWorld().getBlockAt(i, j, k), 0).isCancelled()) { return; } // CraftBukkit end diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index bb6baac87d..2539c28340 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -37,17 +37,10 @@ import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.CreatureType; import org.bukkit.entity.Player; import org.bukkit.event.Event.Type; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockDamageEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.block.*; +import org.bukkit.event.entity.*; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.event.entity.EntityTameEvent; -import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.bukkit.event.player.PlayerBucketFillEvent; -import org.bukkit.event.player.PlayerEvent; -import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.*; public class CraftEventFactory { private static boolean canBuild(CraftWorld world, Player player, int x, int z) { @@ -260,4 +253,16 @@ public class CraftEventFactory { craftServer.getPluginManager().callEvent(event); return event; } + + /** + * BlockFadeEvent + */ + public static BlockFadeEvent callBlockFadeEvent(Block block, int type) { + BlockState state = block.getState(); + state.setTypeId(type); + + BlockFadeEvent event = new BlockFadeEvent(block, state); + Bukkit.getPluginManager().callEvent(event); + return event; + } }