org.bukkit.entity.Boat Java Examples

The following examples show how to use org.bukkit.entity.Boat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SafeBoat.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param e - event
 *            This function prevents boats from exploding when they hit
 *            something
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
public void onBoatHit(VehicleDestroyEvent e) {
    // plugin.getLogger().info("Vehicle destroyed event called");
    final Entity boat = e.getVehicle();
    if (!(boat instanceof Boat)) {
        return;
    }
    if (!boat.getWorld().getName().equalsIgnoreCase(Settings.worldName)) {
        // Not the right world
        return;
    }
    if (!(e.getAttacker() instanceof Player)) {
        // plugin.getLogger().info("Attacker is not a player so cancel event");
        e.setCancelled(true);
    }
}
 
Example #2
Source File: FlyOld.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
private boolean isOnBoat(Player p, Location loc) {
    Set<Entity> trackedEntities = hawk.getLagCompensator().getPositionTrackedEntities();
    int ping = ServerUtils.getPing(p);
    for(Entity entity : trackedEntities) {
        if (entity instanceof Boat) {
            AABB boatBB = WrappedEntity.getWrappedEntity(entity).getCollisionBox(hawk.getLagCompensator().getHistoryLocation(ping, entity).toVector());
            AABB feet = new AABB(
                    new Vector(-0.3, -0.4, -0.3).add(loc.toVector()),
                    new Vector(0.3, 0, 0.3).add(loc.toVector()));
            if (feet.isColliding(boatBB))
                return true;
        }
    }
    return false;
}
 
Example #3
Source File: Fly.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
private boolean isOnBoat(Player p, Location loc) {
    Set<Entity> trackedEntities = hawk.getLagCompensator().getPositionTrackedEntities();
    int ping = ServerUtils.getPing(p);
    for(Entity entity : trackedEntities) {
        if (entity instanceof Boat) {
            AABB boatBB = WrappedEntity.getWrappedEntity(entity).getCollisionBox(hawk.getLagCompensator().getHistoryLocation(ping, entity).toVector());
            AABB feet = new AABB(
                    new Vector(-0.3, -0.4, -0.3).add(loc.toVector()),
                    new Vector(0.3, 0, 0.3).add(loc.toVector()));
            if (feet.isColliding(boatBB))
                return true;
        }
    }
    return false;
}
 
Example #4
Source File: BoatData.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void set(Boat entity) {
	if (matchedPattern == 1) // If the type is 'any boat'.
		matchedPattern += new Random().nextInt(TreeSpecies.values().length); // It will spawn a random boat type in case is 'any boat'.
	if (matchedPattern > 1) // 0 and 1 are excluded
		entity.setWoodType(TreeSpecies.values()[matchedPattern - 2]); // Removes 2 to fix the index.
}
 
Example #5
Source File: SafeBoat.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param e - event
 *            This event check throws the boat at a player when they hit it
 *            unless someone is in it
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onClick(VehicleDamageEvent e) {
    // plugin.getLogger().info("Damage event " + e.getDamage());
    // Find out what block is being clicked
    Vehicle boat = e.getVehicle();
    if (!(boat instanceof Boat)) {
        return;
    }
    if (!boat.isEmpty()) {
        return;
    }
    final World playerWorld = boat.getWorld();
    if (!playerWorld.getName().equalsIgnoreCase(Settings.worldName)) {
        // Not the right world
        return;
    }
    // plugin.getLogger().info("Boat ");
    // Find out who is doing the clicking
    if (!(e.getAttacker() instanceof Player)) {
        // If a creeper blows up the boat, tough cookies!
        return;
    }
    Player p = (Player) e.getAttacker();
    if (p == null) {
        return;
    }
    // Try to remove the boat and throw it at the player
    Location boatSpot = new Location(boat.getWorld(), boat.getLocation().getX(), boat.getLocation().getY() + 2, boat.getLocation().getZ());
    Location throwTo = new Location(boat.getWorld(), p.getLocation().getX(), p.getLocation().getY() + 1, p.getLocation().getZ());
    ItemStack newBoat = new ItemStack(Material.BOAT, 1);
    // Find the direction the boat should move in
    Vector dir = throwTo.toVector().subtract(boatSpot.toVector()).normalize();
    dir = dir.multiply(0.5);
    Entity newB = boat.getWorld().dropItem(boatSpot, newBoat);
    newB.setVelocity(dir);
    boat.remove();
    e.setCancelled(true);
}
 
Example #6
Source File: BoatData.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean init(@Nullable Class<? extends Boat> c, @Nullable Boat e) {
	if (e != null)
		matchedPattern = 2 + e.getWoodType().ordinal();
	return true;
}
 
Example #7
Source File: BoatData.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean match(Boat entity) {
	return matchedPattern <= 1 || entity.getWoodType().ordinal() == matchedPattern - 2;
}
 
Example #8
Source File: BoatData.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class<? extends Boat> getType() {
	return Boat.class;
}
 
Example #9
Source File: GridManager.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Teleport player to a home location. If one cannot be found a search is done to
 * find a safe place.
 * @param player player object
 * @param number - home location to do to
 * @return true if successful, false if not
 */
@SuppressWarnings("deprecation")
public void homeTeleport(final Player player, int number) {
    Location home = null;
    //plugin.getLogger().info("home teleport called for #" + number);
    home = getSafeHomeLocation(player.getUniqueId(), number);
    //plugin.getLogger().info("home get safe loc = " + home);
    // Check if the player is a passenger in a boat
    if (player.isInsideVehicle()) {
        Entity boat = player.getVehicle();
        if (boat instanceof Boat) {
            player.leaveVehicle();
            // Remove the boat so they don't lie around everywhere
            boat.remove();
            player.getInventory().addItem(new ItemStack(Material.BOAT, 1));
            player.updateInventory();
        }
    }
    if (home == null) {
        //plugin.getLogger().info("Fixing home location using safe spot teleport");
        // Try to fix this teleport location and teleport the player if possible
        new SafeTeleportBuilder(plugin)
        .entity(player)
        .location(plugin.getPlayers().getHomeLocation(player.getUniqueId(), number))
        .homeNumber(number)
        .build();
        return;
    }
    //plugin.getLogger().info("DEBUG: home loc = " + home + " teleporting");
    //home.getChunk().load();
    IslandPreTeleportEvent event = new IslandPreTeleportEvent(player, IslandPreTeleportEvent.Type.HOME, home);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        player.teleport(event.getLocation());
        //player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
        if (number ==1 ) {
            Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandteleport);
        } else {
            Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandteleport + " #" + number);
        }
    }
    plugin.getPlayers().setInTeleport(player.getUniqueId(), false);
}