Search in sources :

Example 6 with Message

use of com.flowpowered.networking.Message 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 7 with Message

use of com.flowpowered.networking.Message in project Dragonet-Legacy by DragonetMC.

the class UseItemPacketTranslator method handleSpecific.

@Override
public Message[] handleSpecific(UseItemPacket packet) {
    UseItemPacket pkUseItem = (UseItemPacket) packet;
    System.out.println("FACE=" + (pkUseItem.face & 0xFF) + ", ITEM=" + packet.item);
    if (pkUseItem.face == 0xFF) {
        //Air touch
        //Left click air
        PlayerSwingArmMessage msg = new PlayerSwingArmMessage();
        return new Message[] { msg };
    }
    if (!(pkUseItem.face >= 0 && pkUseItem.face < 6)) {
        return null;
    }
    //Check the slot
    ItemStack test_holding = this.getSession().getPlayer().getInventory().getItemInHand();
    if (packet.item.id != this.getTranslator().getItemTranslator().translateToPE(test_holding.getTypeId()) || packet.item.meta != test_holding.getDurability()) {
        //Not same, resend slot
        PlayerEquipmentPacket pkRet = new PlayerEquipmentPacket();
        pkRet.eid = this.getSession().getPlayer().getEntityId();
        pkRet.item = new PEInventorySlot((short) 0, (byte) 0, (short) 0);
        pkRet.item.id = (short) (this.getTranslator().getItemTranslator().translateToPE(test_holding.getTypeId()) & 0xFFFF);
        pkRet.item.count = (byte) (test_holding.getAmount() & 0xFF);
        pkRet.item.meta = test_holding.getDurability();
        pkRet.selectedSlot = this.getSession().getPlayer().getInventory().getHeldItemSlot();
        //Resend block
        UpdateBlockPacket pkUpdateBlock = new UpdateBlockPacket();
        UpdateBlockPacket.UpdateBlockRecord blockRec = new UpdateBlockPacket.UpdateBlockRecord();
        blockRec.x = packet.x;
        blockRec.z = packet.z;
        blockRec.y = (byte) (packet.y & 0xFF);
        blockRec.block = (byte) (this.getSession().getPlayer().getWorld().getBlockAt(pkUseItem.x, pkUseItem.y, pkUseItem.z).getTypeId() & 0xFF);
        blockRec.meta = (byte) (this.getSession().getPlayer().getWorld().getBlockAt(pkUseItem.x, pkUseItem.y, pkUseItem.z).getData() & 0xFF);
        pkUpdateBlock.records = new UpdateBlockPacket.UpdateBlockRecord[] { blockRec };
        getSession().send(pkRet);
        getSession().send(pkUpdateBlock);
        return null;
    }
    //Copied from Glowstone class BlockPlacementHandler
    new BlockPlacementHandler().handle(getSession(), new BlockPlacementMessage(packet.x, packet.y, packet.z, packet.face, test_holding, 0, 0, 0));
    return null;
}
Also used : BlockPlacementMessage(net.glowstone.net.message.play.player.BlockPlacementMessage) UseItemPacket(org.dragonet.net.packet.minecraft.UseItemPacket) Message(com.flowpowered.networking.Message) PlayerSwingArmMessage(net.glowstone.net.message.play.player.PlayerSwingArmMessage) BlockPlacementMessage(net.glowstone.net.message.play.player.BlockPlacementMessage) ItemStack(org.bukkit.inventory.ItemStack) PlayerSwingArmMessage(net.glowstone.net.message.play.player.PlayerSwingArmMessage) PlayerEquipmentPacket(org.dragonet.net.packet.minecraft.PlayerEquipmentPacket) BlockPlacementHandler(net.glowstone.net.handler.play.player.BlockPlacementHandler) PEInventorySlot(org.dragonet.inventory.PEInventorySlot) UpdateBlockPacket(org.dragonet.net.packet.minecraft.UpdateBlockPacket)

Aggregations

Message (com.flowpowered.networking.Message)7 GlowPlayer (net.glowstone.entity.GlowPlayer)2 HeldItemMessage (net.glowstone.net.message.play.inv.HeldItemMessage)2 DiggingMessage (net.glowstone.net.message.play.player.DiggingMessage)2 DragonetPlayer (org.dragonet.entity.DragonetPlayer)2 Codec (com.flowpowered.networking.Codec)1 ByteBuf (io.netty.buffer.ByteBuf)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 GlowWorld (net.glowstone.GlowWorld)1 GlowBlock (net.glowstone.block.GlowBlock)1 PlayerDataService (net.glowstone.io.PlayerDataService)1 BlockPlacementHandler (net.glowstone.net.handler.play.player.BlockPlacementHandler)1 UserListItemMessage (net.glowstone.net.message.play.game.UserListItemMessage)1 BlockPlacementMessage (net.glowstone.net.message.play.player.BlockPlacementMessage)1 PlayerPositionLookMessage (net.glowstone.net.message.play.player.PlayerPositionLookMessage)1 PlayerSwingArmMessage (net.glowstone.net.message.play.player.PlayerSwingArmMessage)1 PlayProtocol (net.glowstone.net.protocol.PlayProtocol)1 Location (org.bukkit.Location)1