Package net.glowstone.entity

Examples of net.glowstone.entity.GlowPlayer


            for (int i = 1; i < args.length; i++) {
                if (i > 1) message.append(" ");
                message.append(args[i]);
            }

            GlowPlayer glowPlayer = (GlowPlayer) player;

            Object obj = JSONValue.parse(message.toString());
            if (!(obj instanceof JSONObject)) {
                sender.sendMessage(ChatColor.RED + "Failed to parse JSON");
            } else {
                glowPlayer.getSession().send(new ChatMessage((JSONObject) obj));
            }
        }

        return true;
    }
View Full Code Here


            return;
        }

        // initialize the player
        PlayerDataService.PlayerReader reader = server.getPlayerDataService().beginReadingData(profile.getUniqueId());
        player = new GlowPlayer(this, profile, reader);

        // isActive check here in case player disconnected after authentication,
        // but before the GlowPlayer initialization was completed
        if (!isActive()) {
            onDisconnect();
View Full Code Here

import net.glowstone.net.message.play.player.PlayerActionMessage;

public final class PlayerActionHandler implements MessageHandler<GlowSession, PlayerActionMessage> {
    @Override
    public void handle(GlowSession session, PlayerActionMessage message) {
        final GlowPlayer player = session.getPlayer();

        switch (message.getAction()) {
            case 0: // crouch
                player.setSneaking(true);
                break;
            case 1: // uncrouch
                player.setSneaking(false);
                break;
            case 2: // leave bed
                // todo
                break;
            case 3: // start sprinting
                player.setSprinting(true);
                break;
            case 4: // stop sprinting
                player.setSprinting(false);
                break;
            default:
                GlowServer.logger.info("Player " + player + " sent unknown PlayerAction: " + message.getAction());
        }
    }
View Full Code Here

    @Override
    public void handle(GlowSession session, PlayerAbilitiesMessage message) {
        // player sends this when changing whether or not they are currently flying
        // other values should match what we've sent in the past but are ignored here

        final GlowPlayer player = session.getPlayer();
        boolean flying = (message.getFlags() & 0x02) != 0;

        player.setFlying(player.getAllowFlight() && flying);
    }
View Full Code Here

import org.bukkit.Achievement;

public final class ClientStatusHandler implements MessageHandler<GlowSession, ClientStatusMessage> {
    @Override
    public void handle(GlowSession session, ClientStatusMessage message) {
        final GlowPlayer player = session.getPlayer();

        switch (message.getAction()) {
            case ClientStatusMessage.RESPAWN:
                player.respawn();
                break;

            case ClientStatusMessage.REQUEST_STATS:
                player.sendStats();
                break;

            case ClientStatusMessage.OPEN_INVENTORY:
                player.awardAchievement(Achievement.OPEN_INVENTORY);
                break;

            default:
                GlowServer.logger.info(session + " sent unknown ClientStatus action: " + message.getAction());
        }
View Full Code Here

import org.bukkit.event.player.PlayerAnimationEvent;

public final class PlayerSwingArmHandler implements MessageHandler<GlowSession, PlayerSwingArmMessage> {
    @Override
    public void handle(GlowSession session, PlayerSwingArmMessage message) {
        final GlowPlayer player = session.getPlayer();

        Block block;
        try {
            block = player.getTargetBlock(null, 6);
        } catch (IllegalStateException ex) {
            // getTargetBlock failed to find any block at all
            block = null;
        }

        if (block == null || block.isEmpty()) {
            if (EventFactory.onPlayerInteract(player, Action.LEFT_CLICK_AIR).useItemInHand() == Event.Result.DENY)
                return;
            // todo: item interactions with air
        }

        if (!EventFactory.callEvent(new PlayerAnimationEvent(player)).isCancelled()) {
            // play the animation to others
            AnimateEntityMessage toSend = new AnimateEntityMessage(player.getEntityId(), AnimateEntityMessage.OUT_SWING_ARM);
            for (GlowPlayer observer : player.getWorld().getRawPlayers()) {
                if (observer != player && observer.canSeeEntity(player)) {
                    observer.getSession().send(toSend);
                }
            }
        }
View Full Code Here

import org.bukkit.inventory.ItemStack;

public final class DiggingHandler implements MessageHandler<GlowSession, DiggingMessage> {
    @Override
    public void handle(GlowSession session, DiggingMessage message) {
        final GlowPlayer player = session.getPlayer();
        GlowWorld world = player.getWorld();
        GlowBlock block = world.getBlockAt(message.getX(), message.getY(), message.getZ());
        BlockFace face = BlockPlacementHandler.convertFace(message.getFace());
        ItemStack holding = player.getItemInHand();

        boolean blockBroken = false;
        boolean revert = false;
        if (message.getState() == DiggingMessage.START_DIGGING) {
            // call interact event
            Action action = Action.LEFT_CLICK_BLOCK;
            Block eventBlock = block;
            if (player.getLocation().distanceSquared(block.getLocation()) > 36 || block.getTypeId() == 0) {
                action = Action.LEFT_CLICK_AIR;
                eventBlock = null;
            }
            PlayerInteractEvent interactEvent = EventFactory.onPlayerInteract(player, action, eventBlock, face);

            // blocks don't get interacted with on left click, so ignore that
            // attempt to use item in hand, that is, dig up the block
            if (!BlockPlacementHandler.selectResult(interactEvent.useItemInHand(), true)) {
                // the event was cancelled, get out of here
                revert = true;
            } else {
                // emit damage event - cancel by default if holding a sword
                boolean instaBreak = player.getGameMode() == GameMode.CREATIVE;
                BlockDamageEvent damageEvent = new BlockDamageEvent(player, block, player.getItemInHand(), instaBreak);
                if (player.getGameMode() == GameMode.CREATIVE && holding != null && EnchantmentTarget.WEAPON.includes(holding.getType())) {
                    damageEvent.setCancelled(true);
                }
                EventFactory.callEvent(damageEvent);

                // follow orders
                if (damageEvent.isCancelled()) {
                    revert = true;
                } else {
                    // in creative, break even if denied in the event, or the block
                    // can never be broken (client does not send DONE_DIGGING).
                    blockBroken = damageEvent.getInstaBreak() || instaBreak;
                }
            }
        } else if (message.getState() == DiggingMessage.FINISH_DIGGING) {
            // shouldn't happen in creative mode

            // todo: verification against malicious clients
            // also, if the block dig was denied, this break might still happen
            // because a player's digging status isn't yet tracked. this is bad.
            blockBroken = true;
        } else {
            return;
        }

        if (blockBroken) {
            // fire the block break event
            BlockBreakEvent breakEvent = EventFactory.callEvent(new BlockBreakEvent(block, player));
            if (breakEvent.isCancelled()) {
                BlockPlacementHandler.revert(player, block);
                return;
            }

            BlockType blockType = ItemTable.instance().getBlock(block.getType());
            if (blockType != null) {
                blockType.blockDestroy(player, block, face);
            }

            // destroy the block
            if (!block.isEmpty() && !block.isLiquid() && player.getGameMode() != GameMode.CREATIVE) {
                for (ItemStack drop : block.getDrops(holding)) {
                    player.getInventory().addItem(drop);
                }
            }
            // STEP_SOUND actually is the block break particles
            world.playEffectExceptTo(block.getLocation(), Effect.STEP_SOUND, block.getTypeId(), 64, player);
            block.setType(Material.AIR);
View Full Code Here

import org.bukkit.block.Sign;

public final class UpdateSignHandler implements MessageHandler<GlowSession, UpdateSignMessage> {
    @Override
    public void handle(GlowSession session, UpdateSignMessage message) {
        final GlowPlayer player = session.getPlayer();

        // filter out json messages that aren't plaintext
        String[] lines = new String[4];
        for (int i = 0; i < lines.length; ++i) {
            lines[i] = message.getMessage()[i].asPlaintext();
        }

        Location location = new Location(player.getWorld(), message.getX(), message.getY(), message.getZ());
        if (player.checkSignLocation(location)) {
            // update the sign if it's actually still there
            BlockState state = location.getBlock().getState();
            if (state instanceof Sign) {
                Sign sign = (Sign) state;
                for (int i = 0; i < lines.length; ++i) {
View Full Code Here

import java.util.Objects;

public final class BlockPlacementHandler implements MessageHandler<GlowSession, BlockPlacementMessage> {
    @Override
    public void handle(GlowSession session, BlockPlacementMessage message) {
        final GlowPlayer player = session.getPlayer();
        if (player == null)
            return;

        //GlowServer.logger.info(session + ": " + message);

        /**
         * The client sends this packet for the following cases:
         * Right click air:
         * - Send direction=-1 packet for any non-null item
         * Right click block:
         * - Send packet with all values filled
         * - If client DOES NOT expect a block placement to result:
         *   - Send direction=-1 packet (unless item is null)
         *
         * Client will expect a block placement to result from blocks and from
         * certain items (e.g. sugarcane, sign). We *could* opt to trust the
         * client on this, but the server's view of events (particularly under
         * the Bukkit API, or custom ItemTypes) may differ from the client's.
         *
         * In order to avoid firing two events for one interact, the two
         * packet case must be handled here. Care must also be taken that a
         * right-click air of an expected-place item immediately after is
         * not considered part of the same action.
         */

        Action action = Action.RIGHT_CLICK_BLOCK;
        GlowBlock clicked = player.getWorld().getBlockAt(message.getX(), message.getY(), message.getZ());

        /**
         * Check if the message is a -1. If we *just* got a message with the
         * values filled, discard it, otherwise perform right-click-air.
         */
        if (message.getDirection() == -1) {
            BlockPlacementMessage previous = session.getPreviousPlacement();
            if (previous == null || !previous.getHeldItem().equals(message.getHeldItem())) {
                // perform normal right-click-air actions
                action = Action.RIGHT_CLICK_AIR;
                clicked = null;
            } else {
                // terminate processing of this event
                session.setPreviousPlacement(null);
                return;
            }
        }

        // Set previous placement message
        session.setPreviousPlacement(message);

        // Get values from the message
        Vector clickedLoc = new Vector(message.getCursorX(), message.getCursorY(), message.getCursorZ());
        BlockFace face = convertFace(message.getDirection());
        ItemStack holding = player.getItemInHand();

        // check that held item matches
        if (!Objects.equals(holding, message.getHeldItem())) {
            // above handles cases where holding and/or message's item are null
            // todo: inform player their item is wrong
            return;
        }

        // check that a block-click wasn't against air
        if (clicked != null && clicked.getType() == Material.AIR) {
            // inform the player their perception of reality is wrong
            player.sendBlockChange(clicked.getLocation(), Material.AIR, (byte) 0);
            return;
        }

        // call interact event
        PlayerInteractEvent event = EventFactory.onPlayerInteract(player, action, clicked, face);
        //GlowServer.logger.info("Interact: " + action + " " + clicked + " " + face);

        // attempt to use interacted block
        // DEFAULT is treated as ALLOW, and sneaking is always considered
        boolean useInteractedBlock = event.useInteractedBlock() != Event.Result.DENY;
        if (useInteractedBlock && clicked != null && (!player.isSneaking() || holding == null)) {
            BlockType blockType = ItemTable.instance().getBlock(clicked.getType());
            useInteractedBlock = blockType.blockInteract(player, clicked, face, clickedLoc);
        } else {
            useInteractedBlock = false;
        }

        // attempt to use item in hand
        // follows ALLOW/DENY: default to if no block was interacted with
        if (selectResult(event.useItemInHand(), !useInteractedBlock) && holding != null) {
            // call out to the item type to determine the appropriate right-click action
            ItemType type = ItemTable.instance().getItem(holding.getType());
            if (clicked == null) {
                type.rightClickAir(player, holding);
            } else {
                type.rightClickBlock(player, clicked, face, holding, clickedLoc);
            }
        }

        // if anything was actually clicked, make sure the player's up to date
        // in case something is unimplemented or otherwise screwy on our side
        if (clicked != null) {
            revert(player, clicked);
            revert(player, clicked.getRelative(face));
        }

        // if there's been a change in the held item, make it valid again
        if (holding != null) {
            if (holding.getType().getMaxDurability() > 0 && holding.getDurability() > holding.getType().getMaxDurability()) {
                holding.setAmount(holding.getAmount() - 1);
                holding.setDurability((short) 0);
            }
            if (holding.getAmount() <= 0) {
                holding = null;
            }
        }
        player.setItemInHand(holding);
    }
View Full Code Here

import org.bukkit.GameMode;

public final class CloseWindowHandler implements MessageHandler<GlowSession, CloseWindowMessage> {
    @Override
    public void handle(GlowSession session, CloseWindowMessage message) {
        final GlowPlayer player = session.getPlayer();

        // todo: drop items from workbench, enchant inventory, own crafting grid if needed

        player.closeInventory();

        if (player.getItemOnCursor() != null) {
            // player.getWorld().dropItem(player.getEyeLocation(), player.getItemInHand());
            if (player.getGameMode() != GameMode.CREATIVE) {
                player.getInventory().addItem(player.getItemOnCursor());
            }
            player.setItemOnCursor(null);
        }
    }
View Full Code Here

TOP

Related Classes of net.glowstone.entity.GlowPlayer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.