Search in sources :

Example 1 with DiggingMessage

use of net.glowstone.net.message.play.player.DiggingMessage in project Dragonet-Legacy by DragonetMC.

the class PlayerActionPacketTranslator method handleSpecific.

@Override
public Message[] handleSpecific(PlayerActionPacket packet) {
    System.out.println("ACTION = " + packet.action + " @ (" + packet.x + ", " + packet.y + ", " + packet.z + ") face=" + packet.face);
    Message ret = null;
    switch(packet.action) {
        case PlayerActionPacket.ACTION_START_BREAK:
            ret = new DiggingMessage(DiggingMessage.START_DIGGING, packet.x, packet.y, packet.z, packet.face);
            break;
    }
    return new Message[] { ret };
}
Also used : DiggingMessage(net.glowstone.net.message.play.player.DiggingMessage) DiggingMessage(net.glowstone.net.message.play.player.DiggingMessage) Message(com.flowpowered.networking.Message)

Example 2 with DiggingMessage

use of net.glowstone.net.message.play.player.DiggingMessage in project Dragonet-Legacy by DragonetMC.

the class RemoveBlockPacketTranslator method handleSpecific.

@Override
public Message[] handleSpecific(RemoveBlockPacket packet) {
    if (!(this.getSession().getPlayer() instanceof Player)) {
        return null;
    }
    if (getSession().getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
        final GlowPlayer player = getSession().getPlayer();
        GlowWorld world = player.getWorld();
        GlowBlock block = world.getBlockAt(packet.x, packet.y, packet.z);
        PlayerInteractEvent interactEvent = EventFactory.onPlayerInteract(player, Action.LEFT_CLICK_BLOCK, block, BlockFace.UP);
        if (interactEvent.isCancelled()) {
            player.sendBlockChange(block.getLocation(), block.getType(), block.getData());
            return null;
        }
        block.setType(Material.AIR);
    } else {
        //Not Creative
        DiggingMessage msgFinishBreak = new DiggingMessage(DiggingMessage.FINISH_DIGGING, packet.x, packet.y, packet.z, 1);
        return new Message[] { msgFinishBreak };
    }
    return null;
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) GlowBlock(net.glowstone.block.GlowBlock) DiggingMessage(net.glowstone.net.message.play.player.DiggingMessage) Message(com.flowpowered.networking.Message) DiggingMessage(net.glowstone.net.message.play.player.DiggingMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) GlowWorld(net.glowstone.GlowWorld)

Example 3 with DiggingMessage

use of net.glowstone.net.message.play.player.DiggingMessage in project Glowstone by GlowstoneMC.

the class DiggingCodec method decode.

@Override
public DiggingMessage decode(ByteBuf buf) throws IOException {
    int state = buf.readByte();
    BlockVector pos = GlowBufUtils.readBlockPosition(buf);
    int face = buf.readByte();
    return new DiggingMessage(state, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), face);
}
Also used : DiggingMessage(net.glowstone.net.message.play.player.DiggingMessage) BlockVector(org.bukkit.util.BlockVector)

Aggregations

DiggingMessage (net.glowstone.net.message.play.player.DiggingMessage)3 Message (com.flowpowered.networking.Message)2 GlowWorld (net.glowstone.GlowWorld)1 GlowBlock (net.glowstone.block.GlowBlock)1 GlowPlayer (net.glowstone.entity.GlowPlayer)1 Player (org.bukkit.entity.Player)1 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)1 BlockVector (org.bukkit.util.BlockVector)1