Search in sources :

Example 1 with IslandPreTeleportEvent

use of com.wasteofplastic.acidisland.events.IslandPreTeleportEvent in project acidisland by tastybento.

the class GridManager method homeTeleport.

/**
 * 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);
    // 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);
}
Also used : Entity(org.bukkit.entity.Entity) SafeTeleportBuilder(com.wasteofplastic.acidisland.util.teleport.SafeTeleportBuilder) IslandPreTeleportEvent(com.wasteofplastic.acidisland.events.IslandPreTeleportEvent) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location) Boat(org.bukkit.entity.Boat)

Aggregations

IslandPreTeleportEvent (com.wasteofplastic.acidisland.events.IslandPreTeleportEvent)1 SafeTeleportBuilder (com.wasteofplastic.acidisland.util.teleport.SafeTeleportBuilder)1 Location (org.bukkit.Location)1 Boat (org.bukkit.entity.Boat)1 Entity (org.bukkit.entity.Entity)1 ItemStack (org.bukkit.inventory.ItemStack)1