Search in sources :

Example 16 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class UseItemHandler method handle.

@Override
public void handle(GlowSession session, UseItemMessage message) {
    GlowPlayer player = session.getPlayer();
    ItemStack holding = player.getItemInHand();
    if (holding != null) {
        ItemType type = ItemTable.instance().getItem(holding.getType());
        if (type != null) {
            if (type.canOnlyUseSelf()) {
                type.rightClickAir(player, holding);
            } else {
                if (holding.getType() == Material.WATER_BUCKET || holding.getType() == Material.LAVA_BUCKET) {
                    holding.setType(Material.BUCKET);
                }
            }
        }
    }
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) ItemType(net.glowstone.block.itemtype.ItemType) ItemStack(org.bukkit.inventory.ItemStack)

Example 17 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class UpdateSignHandler method handle.

@Override
public void handle(GlowSession session, UpdateSignMessage message) {
    GlowPlayer player = session.getPlayer();
    Location location = new Location(player.getWorld(), message.getX(), message.getY(), message.getZ());
    if (!player.checkSignLocation(location)) {
        GlowServer.logger.warning(session + " tried to edit sign at " + location);
        return;
    }
    // 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();
    }
    SignChangeEvent event = new SignChangeEvent(location.getBlock(), player, lines);
    EventFactory.callEvent(event);
    if (event.isCancelled()) {
        GlowServer.logger.warning("Sign was cancelled");
        return;
    }
    // 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) {
            sign.setLine(i, lines[i]);
        }
        sign.update();
    }
}
Also used : BlockState(org.bukkit.block.BlockState) GlowPlayer(net.glowstone.entity.GlowPlayer) Sign(org.bukkit.block.Sign) SignChangeEvent(org.bukkit.event.block.SignChangeEvent) Location(org.bukkit.Location)

Example 18 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class HeldItemHandler method handle.

@Override
public void handle(GlowSession session, HeldItemMessage message) {
    int slot = message.getSlot();
    if (slot < 0 || slot > 8) {
        // sanity check
        return;
    }
    GlowPlayer player = session.getPlayer();
    int oldSlot = player.getInventory().getHeldItemSlot();
    if (slot == oldSlot) {
        // ignore
        return;
    }
    PlayerItemHeldEvent event = new PlayerItemHeldEvent(player, oldSlot, slot);
    EventFactory.callEvent(event);
    if (!event.isCancelled()) {
        player.getInventory().setRawHeldItemSlot(slot);
    } else {
        // sends a packet to switch back to the previous held slot
        player.getInventory().setHeldItemSlot(oldSlot);
    }
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) PlayerItemHeldEvent(org.bukkit.event.player.PlayerItemHeldEvent)

Example 19 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class PlayerActionHandler method handle.

@Override
public void handle(GlowSession session, PlayerActionMessage message) {
    GlowPlayer player = session.getPlayer();
    switch(message.getAction()) {
        case // crouch
        0:
            player.setSneaking(true);
            break;
        case // uncrouch
        1:
            player.setSneaking(false);
            break;
        case // leave bed
        2:
            if (player.isSleeping()) {
                player.leaveBed(true);
            }
            break;
        case // start sprinting
        3:
            player.setSprinting(true);
            break;
        case // stop sprinting
        4:
            player.setSprinting(false);
            break;
        case // start jump with horse
        5:
            break;
        case // stop jump with horse
        6:
            break;
        case // open horse inventory
        7:
            break;
        case // start gliding
        8:
            ItemStack chestplate = player.getInventory().getChestplate();
            boolean hasElytra = chestplate != null && chestplate.getType() == Material.ELYTRA && chestplate.getDurability() < chestplate.getType().getMaxDurability();
            if (!player.isOnGround() && !player.isGliding() && !player.isInWater() && hasElytra) {
                player.setGliding(true);
            }
    }
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) ItemStack(org.bukkit.inventory.ItemStack)

Example 20 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class GlowArmorStand method damage.

@Override
public void damage(double amount, Entity source, DamageCause cause) {
    if (getNoDamageTicks() > 0 || health <= 0 || !canTakeDamage(cause)) {
        return;
    }
    if (source instanceof Projectile && !(source instanceof Arrow)) {
        return;
    }
    EntityDamageEvent event;
    if (source == null) {
        event = new EntityDamageEvent(this, cause, amount);
    } else {
        event = new EntityDamageByEntityEvent(source, this, cause, amount);
    }
    EventFactory.callEvent(event);
    if (event.isCancelled()) {
        return;
    }
    boolean drop = false;
    if (source instanceof GlowPlayer || source instanceof Arrow && ((Projectile) source).getShooter() instanceof GlowPlayer) {
        GlowPlayer damager = (GlowPlayer) (source instanceof GlowPlayer ? source : ((Arrow) source).getShooter());
        if (damager.getGameMode() == GameMode.ADVENTURE)
            return;
        else if (damager.getGameMode() == GameMode.CREATIVE) {
            //Instantly kill the entity
            amount = 2;
        } else {
            //Needs two hits
            amount = 1;
            drop = true;
        }
    }
    setLastDamage(amount);
    setHealth(health - amount, drop);
}
Also used : EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) GlowPlayer(net.glowstone.entity.GlowPlayer) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Aggregations

GlowPlayer (net.glowstone.entity.GlowPlayer)39 ItemStack (org.bukkit.inventory.ItemStack)10 GlowBlock (net.glowstone.block.GlowBlock)5 Player (org.bukkit.entity.Player)5 Message (com.flowpowered.network.Message)4 Location (org.bukkit.Location)4 GlowWorld (net.glowstone.GlowWorld)3 ItemType (net.glowstone.block.itemtype.ItemType)3 UserListItemMessage (net.glowstone.net.message.play.game.UserListItemMessage)3 BlockPlacementMessage (net.glowstone.net.message.play.player.BlockPlacementMessage)3 Material (org.bukkit.Material)3 Block (org.bukkit.block.Block)3 BlockFace (org.bukkit.block.BlockFace)3 Vector (org.bukkit.util.Vector)3 ChunkLocation (org.dragonet.ChunkLocation)3 PEPacket (org.dragonet.net.packet.minecraft.PEPacket)3 AsyncableMessage (com.flowpowered.network.AsyncableMessage)2 Message (com.flowpowered.networking.Message)2 ArrayList (java.util.ArrayList)2 BlockType (net.glowstone.block.blocktype.BlockType)2