Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import net.minecraft.server.EntityHuman;
- import net.minecraft.server.EntityPlayer;
- import net.minecraft.server.ItemInWorldManager;
- import net.minecraft.server.ItemStack;
- import net.minecraft.server.ModLoader;
- import net.minecraft.server.World;
- import org.bukkit.Server;
- import org.bukkit.block.Block;
- import org.bukkit.craftbukkit.block.CraftBlockState;
- import org.bukkit.craftbukkit.event.CraftEventFactory;
- import org.bukkit.entity.Player;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.block.BlockPlaceEvent;
- public class BukkitHandlers {
- public static boolean raiseBlockBreakEvent(Server server, World world, int i, int j, int k, String actorName) {
- Block bukkitBlock = world.getWorld().getBlockAt(i, j, k);
- Player actor = server.getPlayer(actorName);
- if (actor == null) {
- actor = getEntityByName(world, actorName).getBukkitEntity();
- }
- BlockBreakEvent event = new BlockBreakEvent(bukkitBlock, actor);
- server.getPluginManager().callEvent(event);
- if (event.isCancelled()) {
- return false;
- } else {
- return true;
- }
- }
- public static boolean raiseBlockPlaceEvent(Server server, World world, ItemStack stack, int i, int j, int k, int clickedX, int clickedY, int clickedZ, EntityHuman actor) {
- CraftBlockState replacedBlockState = CraftBlockState.getBlockState(world, i, j, k);
- world.suppressPhysics = true;
- world.setTypeIdAndData(i, j, k, stack.id, stack.getData());
- BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, actor, replacedBlockState, clickedX, clickedY, clickedZ);
- replacedBlockState.update(true);
- world.suppressPhysics = false;
- if (event.isCancelled() || !event.canBuild()) {
- world.setTypeIdAndData(i, j, k, replacedBlockState.getTypeId(), replacedBlockState.getRawData());
- return false;
- }
- return true;
- }
- public static EntityPlayer getEntityByName(World world, String actorName) {
- return new EntityPlayer(ModLoader.getMinecraftServerInstance(), world, actorName, new ItemInWorldManager(world));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement