Package org.bukkit.entity

Examples of org.bukkit.entity.Minecart


    }

    public static void teleport(final Minecart cart, Location destination) {

        EntityType type = cart.getType();
        final Minecart toCart;

        if(type == EntityType.MINECART_CHEST) {
            toCart = cart.getWorld().spawn(destination, StorageMinecart.class);
            ((StorageMinecart)toCart).getInventory().setContents(((StorageMinecart) cart).getInventory().getContents());
        } else if(type == EntityType.MINECART_FURNACE) {
            toCart = cart.getWorld().spawn(destination, PoweredMinecart.class);
        } else if(type == EntityType.MINECART_HOPPER) {
            toCart = cart.getWorld().spawn(destination, HopperMinecart.class);
            ((HopperMinecart)toCart).getInventory().setContents(((HopperMinecart) cart).getInventory().getContents());
        } else if(type == EntityType.MINECART_MOB_SPAWNER) {
            toCart = cart.getWorld().spawn(destination, SpawnerMinecart.class);
        } else if(type == EntityType.MINECART_TNT)
            toCart = cart.getWorld().spawn(destination, ExplosiveMinecart.class);
        else if(type == EntityType.MINECART_COMMAND) {
            toCart = cart.getWorld().spawn(destination, CommandMinecart.class);
            ((CommandMinecart)toCart).setCommand(((CommandMinecart)toCart).getCommand());
            ((CommandMinecart)toCart).setName(((CommandMinecart)toCart).getName());
        } else
            toCart = cart.getWorld().spawn(destination, RideableMinecart.class);

        final Entity passenger = cart.getPassenger();
        if (passenger != null) {
            cart.eject();
            passenger.teleport(destination);
            Bukkit.getScheduler().runTask(CraftBookPlugin.inst(), new Runnable() {

                @Override
                public void run() {

                    toCart.setPassenger(passenger);
                    passenger.setVelocity(cart.getVelocity());
                }
            });
        }
        toCart.getLocation().setYaw(cart.getLocation().getYaw());
        toCart.getLocation().setPitch(cart.getLocation().getPitch());
        toCart.setVelocity(cart.getVelocity()); // speedy thing goes in, speedy thing comes out
        cart.remove();
    }
View Full Code Here


        if (!EventUtil.passesFilter(event))
            return;

        if(event.getVehicle() instanceof Minecart) {
            try {
                Minecart cart = (Minecart) event.getVehicle();
                CartMechanismBlocks cmb = CartMechanismBlocks.findByRail(event.getTo().getBlock());
                cmb.setFromBlock(event.getFrom().getBlock());
                Location from = event.getFrom();
                Location to = event.getTo();
                if(LocationUtil.getDistanceSquared(from, to) > 2*2) //Further than max distance
View Full Code Here

        if(!event.getVehicle().getWorld().isChunkLoaded(event.getVehicle().getLocation().getBlockX() >> 4, event.getVehicle().getLocation().getBlockZ() >> 4))
            return;

        if(event.getVehicle() instanceof Minecart) {
            try {
                Minecart cart = (Minecart) event.getVehicle();
                Block block = event.getVehicle().getLocation().getBlock();
                CartMechanismBlocks cmb = CartMechanismBlocks.findByRail(block);
                cmb.setFromBlock(block); // WAI
                CartBlockEnterEvent ev = new CartBlockEnterEvent(cart, event.getEntered(), cmb);
                CraftBookPlugin.inst().getServer().getPluginManager().callEvent(ev);
View Full Code Here

        if (!event.getBlocks().matches(getMaterial())) return;
        if (!event.getBlocks().hasSign()) return;
        if (event.isMinor()) return;
        if (!(event.getBlocks().matches("cartlift up") || event.getBlocks().matches("cartlift down"))) return;

        Minecart cart = (Minecart) event.getVehicle();

        // go
        boolean up = event.getBlocks().matches("cartlift up");
        Block destination = event.getBlocks().sign;

        BlockFace face;
        if (up) face = BlockFace.UP;
        else face = BlockFace.DOWN;

        while (true) {

            if(destination.getLocation().getBlockY() <= 0 && !up)
                return;
            if(destination.getLocation().getBlockY() >= destination.getWorld().getMaxHeight()-1 && up)
                return;

            destination = destination.getRelative(face);

            if (SignUtil.isSign(destination) && event.getBlocks().base.getType() == destination.getRelative(BlockFace.UP, 1).getType()) {

                ChangedSign state = BukkitUtil.toChangedSign(destination);
                String testLine = state.getLine(1);

                if (testLine.equalsIgnoreCase("[CartLift Up]") || testLine.equalsIgnoreCase("[CartLift Down]") || testLine.equalsIgnoreCase("[CartLift]")) {
                    destination = destination.getRelative(BlockFace.UP, 2);
                    break;
                }
            }
        }

        CartUtil.teleport(cart, new Location(destination.getWorld(), destination.getX(), destination.getY(), destination.getZ(), cart.getLocation().getYaw(), cart.getLocation().getPitch()));
    }
View Full Code Here

            } else if (type.equals(CartType.HopperMinecart)) {
                if (!inv.contains(Material.HOPPER_MINECART)) return;
                inv.removeItem(new ItemStack(Material.HOPPER_MINECART, 1));
            }
        }
        Minecart cart = blocks.rail.getWorld().spawn(location, type.toClass());
        if(minecartDispenserPropel) {
            BlockFace dir = SignUtil.getBack(blocks.sign);
            Vector vel = new Vector(dir.getModX(), dir.getModY(), dir.getModZ());
            cart.setVelocity(vel.normalize());
        }
    }
View Full Code Here

public class CartUtilsTest {

    @Test
    public void testReverse() {

        Minecart cart = mock(Minecart.class);
        when(cart.getVelocity()).thenReturn(new Vector(0,1,0));
        CartUtil.reverse(cart);
        verify(cart).setVelocity(new Vector(0,-1,0));
    }
View Full Code Here

    }

    @Test
    public void testStop() {

        Minecart cart = mock(Minecart.class);
        CartUtil.stop(cart);
        verify(cart).setVelocity(new Vector(0,0,0));
    }
View Full Code Here

        if (plugin.getBlockSafety().playerCanSpawnHereSafely(l)) {
            plugin.log(Level.FINE, "The first location you gave me was safe.");
            return l;
        }
        if (e instanceof Minecart) {
            Minecart m = (Minecart) e;
            if (!plugin.getBlockSafety().canSpawnCartSafely(m)) {
                return null;
            }
        } else if (e instanceof Vehicle) {
            Vehicle v = (Vehicle) e;
View Full Code Here

        if (this.bs.playerCanSpawnHereSafely(l)) {
            plugin.log(Level.FINE, "The first location you gave me was safe.");
            return l;
        }
        if (e instanceof Minecart) {
            Minecart m = (Minecart) e;
            if (!this.bs.canSpawnCartSafely(m)) {
                return null;
            }
        } else if (e instanceof Vehicle) {
            Vehicle v = (Vehicle) e;
View Full Code Here

TOP

Related Classes of org.bukkit.entity.Minecart

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.