Use CraftEventFactory for BlockFormEvent

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2016-12-09 12:45:21 +11:00
parent cd5305a554
commit 9e8988306c
4 changed files with 45 additions and 65 deletions

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();
}
}