Search in sources :

Example 1 with IslandEnterEvent

use of com.wasteofplastic.askyblock.events.IslandEnterEvent in project askyblock by tastybento.

the class NetherPortals method onPlayerPortal.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerPortal(PlayerPortalEvent event) {
    if (DEBUG)
        plugin.getLogger().info("Player portal event - reason =" + event.getCause());
    UUID playerUUID = event.getPlayer().getUniqueId();
    // If the nether is disabled then quit immediately
    if (!Settings.createNether || ASkyBlock.getNetherWorld() == null) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Disabled nether: Settings create nether = " + Settings.createNether + " " + (ASkyBlock.getNetherWorld() == null ? "Nether world is null" : "Nether world is not null"));
        return;
    }
    Location currentLocation = event.getFrom().clone();
    String currentWorld = currentLocation.getWorld().getName();
    if (!currentWorld.equalsIgnoreCase(Settings.worldName) && !currentWorld.equalsIgnoreCase(Settings.worldName + "_nether") && !currentWorld.equalsIgnoreCase(Settings.worldName + "_the_end")) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: not island world");
        return;
    }
    // Check if player has permission
    Island island = plugin.getGrid().getIslandAt(currentLocation);
    if ((island == null && !Settings.defaultWorldSettings.get(SettingsFlag.PORTAL)) || (island != null && !(island.getIgsFlag(SettingsFlag.PORTAL) || island.getMembers().contains(event.getPlayer().getUniqueId())))) {
        // Portals use is not allowed
        if (!event.getPlayer().isOp() && !VaultHelper.checkPerm(event.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
            Util.sendMessage(event.getPlayer(), ChatColor.RED + plugin.myLocale(event.getPlayer().getUniqueId()).islandProtected);
            event.setCancelled(true);
            return;
        }
    }
    // Determine what portal it is
    switch(event.getCause()) {
        case END_PORTAL:
            // Same action for all worlds except the end itself
            if (!event.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) {
                if (plugin.getServer().getWorld(Settings.worldName + "_the_end") != null) {
                    // The end exists
                    event.setCancelled(true);
                    Location end_place = plugin.getServer().getWorld(Settings.worldName + "_the_end").getSpawnLocation();
                    if (GridManager.isSafeLocation(end_place)) {
                        event.getPlayer().teleport(end_place);
                        // end_place.getBlock().getType(),end_place.getBlock().getData());
                        return;
                    } else {
                        Util.sendMessage(event.getPlayer(), ChatColor.RED + plugin.myLocale(event.getPlayer().getUniqueId()).warpserrorNotSafe);
                        plugin.getGrid().homeTeleport(event.getPlayer());
                        return;
                    }
                }
            } else {
                event.setCancelled(true);
                plugin.getGrid().homeTeleport(event.getPlayer());
            }
            break;
        case NETHER_PORTAL:
            // Get the home world of this player
            World homeWorld = ASkyBlock.getIslandWorld();
            Location home = plugin.getPlayers().getHomeLocation(event.getPlayer().getUniqueId());
            if (home != null) {
                homeWorld = home.getWorld();
            }
            if (!Settings.newNether) {
                // Legacy action
                if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) {
                    // Going to Nether
                    if (homeWorld.getEnvironment().equals(Environment.NORMAL)) {
                        // Home world is over world
                        event.setTo(ASkyBlock.getNetherWorld().getSpawnLocation());
                        event.useTravelAgent(true);
                    } else {
                        // Home world is nether - going home
                        event.useTravelAgent(false);
                        Location dest = plugin.getGrid().getSafeHomeLocation(playerUUID, 1);
                        if (dest != null) {
                            event.setTo(dest);
                        } else {
                            event.setCancelled(true);
                            new SafeTeleportBuilder(plugin).entity(event.getPlayer()).location(plugin.getPlayers().getIslandLocation(playerUUID)).portal().homeNumber(1).build();
                        }
                    }
                } else {
                    // Going to Over world
                    if (homeWorld.getEnvironment().equals(Environment.NORMAL)) {
                        // Home world is over world
                        event.useTravelAgent(false);
                        Location dest = plugin.getGrid().getSafeHomeLocation(playerUUID, 1);
                        if (dest != null) {
                            event.setTo(dest);
                            // Fire entry event
                            Island islandTo = plugin.getGrid().getIslandAt(dest);
                            final IslandEnterEvent event2 = new IslandEnterEvent(event.getPlayer().getUniqueId(), islandTo, dest);
                            plugin.getServer().getPluginManager().callEvent(event2);
                        } else {
                            event.setCancelled(true);
                            new SafeTeleportBuilder(plugin).entity(event.getPlayer()).location(plugin.getPlayers().getIslandLocation(playerUUID)).portal().homeNumber(1).build();
                            // Fire entry event
                            Island islandTo = plugin.getGrid().getIslandAt(plugin.getPlayers().getIslandLocation(playerUUID));
                            final IslandEnterEvent event2 = new IslandEnterEvent(event.getPlayer().getUniqueId(), islandTo, plugin.getPlayers().getIslandLocation(playerUUID));
                            plugin.getServer().getPluginManager().callEvent(event2);
                        }
                    } else {
                        // Home world is nether
                        event.setTo(ASkyBlock.getIslandWorld().getSpawnLocation());
                        event.useTravelAgent(true);
                    }
                }
            } else {
                // Get location of the island where the player is at
                if (island == null) {
                    event.setCancelled(true);
                    return;
                }
                // Can go both ways now
                Location overworldIsland = island.getCenter().toVector().toLocation(ASkyBlock.getIslandWorld());
                Location netherIsland = island.getCenter().toVector().toLocation(ASkyBlock.getNetherWorld());
                // Location dest = event.getFrom().toVector().toLocation(ASkyBlock.getIslandWorld());
                if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) {
                    // Check that there is a nether island there. Due to legacy reasons it may not exist
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: island center = " + island.getCenter());
                    if (netherIsland.getBlock().getType() != Material.BEDROCK) {
                        // Check to see if there is anything there
                        if (plugin.getGrid().bigScan(netherIsland, 20) == null) {
                            if (DEBUG)
                                plugin.getLogger().info("DEBUG: big scan is null");
                            plugin.getLogger().warning("Creating nether island for " + event.getPlayer().getName() + " using default nether schematic");
                            Schematic nether = IslandCmd.getSchematics().get("nether");
                            if (nether != null) {
                                if (DEBUG)
                                    plugin.getLogger().info("DEBUG: pasting at " + island.getCenter().toVector());
                                plugin.getIslandCmd().pasteSchematic(nether, netherIsland, event.getPlayer(), PasteReason.PARTNER);
                                if (nether.isPlayerSpawn()) {
                                    // Set partner home
                                    plugin.getPlayers().setHomeLocation(event.getPlayer().getUniqueId(), nether.getPlayerSpawn(netherIsland), -2);
                                }
                            } else {
                                plugin.getLogger().severe("Cannot teleport player to nether because there is no nether schematic");
                                event.setCancelled(true);
                                Util.sendMessage(event.getPlayer(), ChatColor.RED + plugin.myLocale(event.getPlayer().getUniqueId()).warpserrorNotSafe);
                                return;
                            }
                        }
                    }
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: Teleporting to " + event.getFrom().toVector().toLocation(ASkyBlock.getNetherWorld()));
                    event.setCancelled(true);
                    // Teleport using the new safeSpot teleport
                    new SafeTeleportBuilder(plugin).entity(event.getPlayer()).location(netherIsland).portal().build();
                    return;
                }
                // Going to the over world - if there isn't an island, do nothing
                event.setCancelled(true);
                // Teleport using the new safeSpot teleport
                new SafeTeleportBuilder(plugin).entity(event.getPlayer()).location(overworldIsland).portal().build();
            }
            break;
        default:
            break;
    }
}
Also used : IslandEnterEvent(com.wasteofplastic.askyblock.events.IslandEnterEvent) SafeTeleportBuilder(com.wasteofplastic.askyblock.util.teleport.SafeTeleportBuilder) UUID(java.util.UUID) World(org.bukkit.World) Island(com.wasteofplastic.askyblock.Island) Schematic(com.wasteofplastic.askyblock.schematics.Schematic) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 2 with IslandEnterEvent

use of com.wasteofplastic.askyblock.events.IslandEnterEvent in project askyblock by tastybento.

the class PlayerEvents method onPlayerJoin.

/**
 * Handle player joining
 * @param event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerJoin(final PlayerJoinEvent event) {
    final Island island = plugin.getGrid().getProtectedIslandAt(event.getPlayer().getLocation());
    if (island != null) {
        processPerms(event.getPlayer(), island);
        // Fire entry event
        final IslandEnterEvent e = new IslandEnterEvent(event.getPlayer().getUniqueId(), island, event.getPlayer().getLocation());
        plugin.getServer().getPluginManager().callEvent(e);
    }
}
Also used : IslandEnterEvent(com.wasteofplastic.askyblock.events.IslandEnterEvent) Island(com.wasteofplastic.askyblock.Island) EventHandler(org.bukkit.event.EventHandler)

Example 3 with IslandEnterEvent

use of com.wasteofplastic.askyblock.events.IslandEnterEvent in project askyblock by tastybento.

the class IslandGuard method onVehicleMove.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVehicleMove(final VehicleMoveEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: vehicle move = " + e.getVehicle());
    if (!inWorld(e.getVehicle())) {
        return;
    }
    Entity passenger = e.getVehicle().getPassenger();
    if (passenger == null || !(passenger instanceof Player)) {
        return;
    }
    Player player = (Player) passenger;
    if (plugin.getGrid() == null) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: grid = null");
        return;
    }
    Island islandTo = plugin.getGrid().getProtectedIslandAt(e.getTo());
    // Announcement entering
    Island islandFrom = plugin.getGrid().getProtectedIslandAt(e.getFrom());
    // plugin.getLogger().info("islandFrom = " + islandFrom);
    if (islandTo != null && (islandTo.getOwner() != null || islandTo.isSpawn())) {
        // Lock check
        if (islandTo.isLocked() || plugin.getPlayers().isBanned(islandTo.getOwner(), player.getUniqueId())) {
            if (!islandTo.getMembers().contains(player.getUniqueId()) && !player.isOp() && !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect") && !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypasslock")) {
                Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).lockIslandLocked);
                // Check if the player is within the border a lot
                int minX = Math.max(islandTo.getMinProtectedX() - e.getTo().getBlockX(), e.getTo().getBlockX() - (islandTo.getMinProtectedX() + islandTo.getProtectionSize()));
                int minZ = Math.max(islandTo.getMinProtectedZ() - e.getTo().getBlockZ(), e.getTo().getBlockZ() - (islandTo.getMinProtectedZ() + islandTo.getProtectionSize()));
                int minMin = Math.max(minX, minZ);
                // plugin.getLogger().info("DEBUG: " + minMin);
                if (minMin < 1) {
                    Vector v = e.getVehicle().getLocation().toVector().subtract(islandTo.getCenter().toVector()).normalize().multiply(new Vector(1.2, 0, 1.2));
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: direction vector = " + v);
                    e.getVehicle().setVelocity(v);
                }
                if (minMin < -1) {
                    // Teleport player
                    plugin.getGrid().homeTeleport(player);
                }
                return;
            }
        }
    }
    if (islandTo != null && islandFrom == null) {
        // Entering
        if (islandTo.getOwner() != null && (islandTo.isLocked() || plugin.getPlayers().isBanned(islandTo.getOwner(), player.getUniqueId()))) {
            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).lockIslandLocked);
        }
        if (islandTo.isSpawn()) {
            if (!plugin.myLocale(player.getUniqueId()).lockEnteringSpawn.isEmpty()) {
                if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).lockEnteringSpawn);
                }
            }
        } else {
            if (islandTo.getOwner() != null && !plugin.myLocale(player.getUniqueId()).lockNowEntering.isEmpty()) {
                if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendEnterExit(player, plugin.myLocale(player.getUniqueId()).lockNowEntering.replace("[name]", plugin.getGrid().getIslandName(islandTo.getOwner())));
                }
            }
        }
        // Fire entry event
        final IslandEnterEvent event = new IslandEnterEvent(player.getUniqueId(), islandTo, e.getTo());
        plugin.getServer().getPluginManager().callEvent(event);
    } else if (islandTo == null && islandFrom != null) {
        // Leaving
        if (islandFrom.isSpawn()) {
            // Leaving
            if (!plugin.myLocale(player.getUniqueId()).lockLeavingSpawn.isEmpty()) {
                if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).lockLeavingSpawn);
                }
            }
        } else {
            if (islandFrom.getOwner() != null && !plugin.myLocale(player.getUniqueId()).lockNowLeaving.isEmpty()) {
                if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendEnterExit(player, plugin.myLocale(player.getUniqueId()).lockNowLeaving.replace("[name]", plugin.getGrid().getIslandName(islandFrom.getOwner())));
                }
            }
        }
        // Fire exit event
        final IslandExitEvent event = new IslandExitEvent(player.getUniqueId(), islandFrom, e.getFrom());
        plugin.getServer().getPluginManager().callEvent(event);
    } else if (islandTo != null && islandFrom != null && !islandTo.equals(islandFrom)) {
        // Adjacent islands or overlapping protections
        if (islandFrom.isSpawn()) {
            // Leaving
            if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).lockLeavingSpawn);
            }
        } else if (islandFrom.getOwner() != null) {
            if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendEnterExit(player, plugin.myLocale(player.getUniqueId()).lockNowLeaving.replace("[name]", plugin.getGrid().getIslandName(islandFrom.getOwner())));
            }
        }
        if (islandTo.isSpawn()) {
            if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).lockEnteringSpawn);
            }
        } else if (islandTo.getOwner() != null) {
            if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendEnterExit(player, plugin.myLocale(player.getUniqueId()).lockNowEntering.replace("[name]", plugin.getGrid().getIslandName(islandTo.getOwner())));
            }
        }
        // Fire exit event
        final IslandExitEvent event = new IslandExitEvent(player.getUniqueId(), islandFrom, e.getFrom());
        plugin.getServer().getPluginManager().callEvent(event);
        // Fire entry event
        final IslandEnterEvent event2 = new IslandEnterEvent(player.getUniqueId(), islandTo, e.getTo());
        plugin.getServer().getPluginManager().callEvent(event2);
    }
}
Also used : IslandEnterEvent(com.wasteofplastic.askyblock.events.IslandEnterEvent) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) IslandExitEvent(com.wasteofplastic.askyblock.events.IslandExitEvent) Island(com.wasteofplastic.askyblock.Island) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 4 with IslandEnterEvent

use of com.wasteofplastic.askyblock.events.IslandEnterEvent in project askyblock by tastybento.

the class IslandGuard method onPlayerMove.

/**
 * Adds island lock function
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent e) {
    if (e.getPlayer().isDead()) {
        return;
    }
    if (!inWorld(e.getPlayer())) {
        return;
    }
    if (plugin.getGrid() == null) {
        return;
    }
    // Only do something if there is a definite x or z movement
    if (e.getTo().getBlockX() - e.getFrom().getBlockX() == 0 && e.getTo().getBlockZ() - e.getFrom().getBlockZ() == 0) {
        return;
    }
    final Island islandTo = plugin.getGrid().getProtectedIslandAt(e.getTo());
    // Announcement entering
    final Island islandFrom = plugin.getGrid().getProtectedIslandAt(e.getFrom());
    // plugin.getLogger().info("islandFrom = " + islandFrom);
    if (islandTo != null && (islandTo.getOwner() != null || islandTo.isSpawn())) {
        // Lock check
        if (islandTo.isLocked() || plugin.getPlayers().isBanned(islandTo.getOwner(), e.getPlayer().getUniqueId())) {
            if (!islandTo.getMembers().contains(e.getPlayer().getUniqueId()) && !e.getPlayer().isOp() && !VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect") && !VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypasslock")) {
                Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).lockIslandLocked);
                // Get the vector away from this island
                if (e.getPlayer().isInsideVehicle()) {
                    if (e.getPlayer().getVehicle() instanceof LivingEntity) {
                        // Dismount
                        e.getPlayer().leaveVehicle();
                        e.setCancelled(true);
                    }
                } else {
                    // Check if the player is within the border a lot
                    int minX = Math.max(islandTo.getMinProtectedX() - e.getTo().getBlockX(), e.getTo().getBlockX() - (islandTo.getMinProtectedX() + islandTo.getProtectionSize()));
                    int minZ = Math.max(islandTo.getMinProtectedZ() - e.getTo().getBlockZ(), e.getTo().getBlockZ() - (islandTo.getMinProtectedZ() + islandTo.getProtectionSize()));
                    int minMin = Math.max(minX, minZ);
                    // plugin.getLogger().info("DEBUG: " + minMin);
                    if (minMin < 1) {
                        Vector v = e.getPlayer().getLocation().toVector().subtract(islandTo.getCenter().toVector()).normalize().multiply(new Vector(1.2, 0, 1.2));
                        if (DEBUG)
                            plugin.getLogger().info("DEBUG: direction vector = " + v);
                        e.getPlayer().setVelocity(v);
                    }
                    if (minMin < -1) {
                        // Teleport player
                        plugin.getGrid().homeTeleport(e.getPlayer());
                    }
                }
                return;
            }
        }
    }
    if (islandTo != null && islandFrom == null) {
        // Entering
        if (islandTo.isLocked() || plugin.getPlayers().isBanned(islandTo.getOwner(), e.getPlayer().getUniqueId())) {
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).lockIslandLocked);
        }
        if (islandTo.isSpawn()) {
            if (!plugin.myLocale(e.getPlayer().getUniqueId()).lockEnteringSpawn.isEmpty()) {
                if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendMessage(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockEnteringSpawn);
                }
            }
        } else {
            if (islandTo.getOwner() != null && !plugin.myLocale(e.getPlayer().getUniqueId()).lockNowEntering.isEmpty()) {
                if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowEntering.replace("[name]", plugin.getGrid().getIslandName(islandTo.getOwner())));
                }
            }
        }
        // Fire entry event
        final IslandEnterEvent event = new IslandEnterEvent(e.getPlayer().getUniqueId(), islandTo, e.getTo());
        plugin.getServer().getPluginManager().callEvent(event);
    } else if (islandTo == null && islandFrom != null) {
        // Leaving
        if (islandFrom.isSpawn()) {
            // Leaving
            if (!plugin.myLocale(e.getPlayer().getUniqueId()).lockLeavingSpawn.isEmpty()) {
                if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendMessage(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockLeavingSpawn);
                }
            }
        } else {
            if (islandFrom.getOwner() != null && !plugin.myLocale(e.getPlayer().getUniqueId()).lockNowLeaving.isEmpty()) {
                if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowLeaving.replace("[name]", plugin.getGrid().getIslandName(islandFrom.getOwner())));
                }
            }
        }
        // Fire exit event
        final IslandExitEvent event = new IslandExitEvent(e.getPlayer().getUniqueId(), islandFrom, e.getFrom());
        plugin.getServer().getPluginManager().callEvent(event);
    } else if (islandTo != null && islandFrom != null && !islandTo.equals(islandFrom)) {
        // Adjacent islands or overlapping protections
        if (islandFrom.isSpawn()) {
            // Leaving
            if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendMessage(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockLeavingSpawn);
            }
        } else if (islandFrom.getOwner() != null) {
            if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowLeaving.replace("[name]", plugin.getGrid().getIslandName(islandFrom.getOwner())));
            }
        }
        if (islandTo.isSpawn()) {
            if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendMessage(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockEnteringSpawn);
            }
        } else if (islandTo.getOwner() != null) {
            if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowEntering.replace("[name]", plugin.getGrid().getIslandName(islandTo.getOwner())));
            }
        }
        // Fire exit event
        final IslandExitEvent event = new IslandExitEvent(e.getPlayer().getUniqueId(), islandFrom, e.getFrom());
        plugin.getServer().getPluginManager().callEvent(event);
        // Fire entry event
        final IslandEnterEvent event2 = new IslandEnterEvent(e.getPlayer().getUniqueId(), islandTo, e.getTo());
        plugin.getServer().getPluginManager().callEvent(event2);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) IslandEnterEvent(com.wasteofplastic.askyblock.events.IslandEnterEvent) IslandExitEvent(com.wasteofplastic.askyblock.events.IslandExitEvent) Island(com.wasteofplastic.askyblock.Island) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 5 with IslandEnterEvent

use of com.wasteofplastic.askyblock.events.IslandEnterEvent in project askyblock by tastybento.

the class PlayerEvents method onPlayerTeleport.

/**
 * Prevents teleporting when falling based on setting and teleporting to locked islands
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
        plugin.getLogger().info("DEBUG: to = " + e.getTo());
        plugin.getLogger().info("DEBUG: from = " + e.getFrom());
    }
    // Player is not in an island world and teleporting not in - skip
    if (e.getTo() == null || e.getFrom() == null) {
        return;
    }
    if (!IslandGuard.inWorld(e.getTo()) && !IslandGuard.inWorld(e.getFrom())) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: to or from are not in this world - returning ");
        return;
    }
    // Check if ready
    if (plugin.getGrid() == null) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: grid is not ready");
        return;
    }
    // Teleporting while falling check
    if (!Settings.allowTeleportWhenFalling && e.getPlayer().getGameMode().equals(GameMode.SURVIVAL) && !e.getPlayer().isOp()) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Teleporting while falling check");
        // If the player is allowed to teleport excuse them
        if (plugin.getPlayers().isInTeleport(e.getPlayer().getUniqueId())) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: player is allowed to teleport excuse them");
            unsetFalling(e.getPlayer().getUniqueId());
        } else if (isFalling(e.getPlayer().getUniqueId())) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: player is falling");
            // Sorry you are going to die
            Util.sendMessage(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).islandcannotTeleport);
            e.setCancelled(true);
            // Check if the player is in the void and kill them just in case
            if (e.getPlayer().getLocation().getBlockY() < 0) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: player is in the void");
                e.getPlayer().setHealth(0D);
                unsetFalling(e.getPlayer().getUniqueId());
            }
            return;
        }
    }
    // Teleporting to a locked island
    if (DEBUG)
        plugin.getLogger().info("DEBUG: getting islands for to from");
    Island islandFrom = plugin.getGrid().getProtectedIslandAt(e.getFrom());
    if (DEBUG && islandFrom != null)
        plugin.getLogger().info("DEBUG: islandFrom is not null");
    Island islandTo = plugin.getGrid().getProtectedIslandAt(e.getTo());
    if (DEBUG && islandTo != null)
        plugin.getLogger().info("DEBUG: islandTo is not null");
    // Ender pearl and chorus fruit teleport checks
    if (e.getCause() != null) {
        if (e.getCause().equals(TeleportCause.ENDER_PEARL)) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: Enderpearl");
            if (islandTo == null) {
                if (Settings.defaultWorldSettings.get(SettingsFlag.ENDER_PEARL)) {
                    return;
                }
            } else {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: islandTo is not null enderpearl");
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: islandTo is regular island");
                if (islandTo.getIgsFlag(SettingsFlag.ENDER_PEARL) || islandTo.getMembers().contains(e.getPlayer().getUniqueId())) {
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: enderpearl allowed");
                    return;
                }
            }
            if (DEBUG)
                plugin.getLogger().info("DEBUG: enderpearl not allowed");
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
            e.setCancelled(true);
            return;
        } else if (!plugin.getServer().getVersion().contains("(MC: 1.8") && !plugin.getServer().getVersion().contains("(MC: 1.7")) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: chorus fruit check");
            // Chorus fruit only exist in 1.9 and above
            if (e.getCause().equals(TeleportCause.CHORUS_FRUIT)) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: chorus fruit");
                boolean cancel = false;
                // Check both from and to islands
                if (islandTo == null) {
                    if (!Settings.defaultWorldSettings.get(SettingsFlag.CHORUS_FRUIT)) {
                        cancel = true;
                    }
                } else {
                    if (!islandTo.getIgsFlag(SettingsFlag.CHORUS_FRUIT) && !islandTo.getMembers().contains(e.getPlayer().getUniqueId())) {
                        cancel = true;
                    }
                }
                if (islandFrom == null) {
                    if (!Settings.defaultWorldSettings.get(SettingsFlag.CHORUS_FRUIT)) {
                        cancel = true;
                    }
                } else {
                    if (!islandFrom.getIgsFlag(SettingsFlag.CHORUS_FRUIT) && !islandFrom.getMembers().contains(e.getPlayer().getUniqueId())) {
                        cancel = true;
                    }
                }
                if (cancel) {
                    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                    e.setCancelled(true);
                }
                return;
            }
        }
    }
    if (DEBUG)
        plugin.getLogger().info("DEBUG: announcements");
    if (islandTo != null && islandFrom == null) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: entering");
        // Entering
        if (islandTo.getOwner() != null && (islandTo.isLocked() || plugin.getPlayers().isBanned(islandTo.getOwner(), e.getPlayer().getUniqueId()))) {
            // Locked island
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).lockIslandLocked);
            if (!plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getTo()) && !e.getPlayer().isOp() && !VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect") && !VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypasslock")) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: not allowed to enter");
                e.setCancelled(true);
                return;
            }
        }
        if (islandTo.isSpawn()) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: islandTo is locked spawn");
            if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                if (!plugin.myLocale(e.getPlayer().getUniqueId()).lockEnteringSpawn.isEmpty()) {
                    Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockEnteringSpawn);
                }
            }
        } else {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: islandTo is locked regular");
            if (islandTo.getOwner() != null && islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                if (!plugin.myLocale(e.getPlayer().getUniqueId()).lockNowEntering.isEmpty()) {
                    Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowEntering.replace("[name]", plugin.getGrid().getIslandName(islandTo.getOwner())));
                }
            }
        }
        // Fire entry event
        final IslandEnterEvent event = new IslandEnterEvent(e.getPlayer().getUniqueId(), islandTo, e.getTo());
        plugin.getServer().getPluginManager().callEvent(event);
    } else if (islandTo == null && islandFrom != null && (islandFrom.getOwner() != null || islandFrom.isSpawn())) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Leaving");
        // Leaving
        if (islandFrom.isSpawn()) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: leaving spawn");
            // Leaving
            if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                if (!plugin.myLocale(e.getPlayer().getUniqueId()).lockLeavingSpawn.isEmpty()) {
                    Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockLeavingSpawn);
                }
            }
        } else {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: leaving locked");
            if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                if (!plugin.myLocale(e.getPlayer().getUniqueId()).lockNowLeaving.isEmpty()) {
                    Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowLeaving.replace("[name]", plugin.getGrid().getIslandName(islandFrom.getOwner())));
                }
            }
        }
        // Remove temp perms
        removeTempPerms(e.getPlayer(), islandFrom, islandTo);
        // Fire exit event
        final IslandExitEvent event = new IslandExitEvent(e.getPlayer().getUniqueId(), islandFrom, e.getFrom());
        plugin.getServer().getPluginManager().callEvent(event);
    } else if (islandTo != null && islandFrom != null && !islandTo.equals(islandFrom)) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: jumping from one island to another - adjacent islands");
        // Entering
        if (islandTo.isLocked() || plugin.getPlayers().isBanned(islandTo.getOwner(), e.getPlayer().getUniqueId())) {
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).lockIslandLocked);
            if (!plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getTo()) && !e.getPlayer().isOp() && !VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect") && !VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypasslock")) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: cannot enter");
                e.setCancelled(true);
                return;
            }
        }
        if (islandFrom.isSpawn()) {
            // Leaving
            if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES) && !plugin.myLocale(e.getPlayer().getUniqueId()).lockLeavingSpawn.isEmpty()) {
                Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockLeavingSpawn);
            }
        } else if (islandFrom.getOwner() != null && !plugin.myLocale(e.getPlayer().getUniqueId()).lockNowLeaving.isEmpty()) {
            if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowLeaving.replace("[name]", plugin.getGrid().getIslandName(islandFrom.getOwner())));
            }
        }
        if (islandTo.isSpawn()) {
            if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES) && !plugin.myLocale(e.getPlayer().getUniqueId()).lockEnteringSpawn.isEmpty()) {
                Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockEnteringSpawn);
            }
        } else if (islandTo.getOwner() != null && !plugin.myLocale(e.getPlayer().getUniqueId()).lockNowEntering.isEmpty()) {
            if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendEnterExit(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).lockNowEntering.replace("[name]", plugin.getGrid().getIslandName(islandTo.getOwner())));
            }
        }
        // Remove temp perms
        if (!islandTo.getMembers().contains(e.getPlayer().getUniqueId())) {
            removeTempPerms(e.getPlayer(), islandFrom, islandTo);
        }
        // Fire exit event
        final IslandExitEvent event = new IslandExitEvent(e.getPlayer().getUniqueId(), islandFrom, e.getFrom());
        plugin.getServer().getPluginManager().callEvent(event);
        // Fire entry event
        final IslandEnterEvent event2 = new IslandEnterEvent(e.getPlayer().getUniqueId(), islandTo, e.getTo());
        plugin.getServer().getPluginManager().callEvent(event2);
    } else if (islandTo != null && islandFrom != null && (islandTo.equals(islandFrom) && !e.getFrom().getWorld().equals(e.getTo().getWorld()))) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: jumping from dimension to another - same island");
        // Fire exit event
        final IslandExitEvent event = new IslandExitEvent(e.getPlayer().getUniqueId(), islandFrom, e.getFrom());
        plugin.getServer().getPluginManager().callEvent(event);
        // Fire entry event
        final IslandEnterEvent event2 = new IslandEnterEvent(e.getPlayer().getUniqueId(), islandTo, e.getTo());
        plugin.getServer().getPluginManager().callEvent(event2);
    }
}
Also used : IslandEnterEvent(com.wasteofplastic.askyblock.events.IslandEnterEvent) IslandExitEvent(com.wasteofplastic.askyblock.events.IslandExitEvent) Island(com.wasteofplastic.askyblock.Island) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Island (com.wasteofplastic.askyblock.Island)5 IslandEnterEvent (com.wasteofplastic.askyblock.events.IslandEnterEvent)5 EventHandler (org.bukkit.event.EventHandler)5 IslandExitEvent (com.wasteofplastic.askyblock.events.IslandExitEvent)3 LivingEntity (org.bukkit.entity.LivingEntity)2 Vector (org.bukkit.util.Vector)2 Schematic (com.wasteofplastic.askyblock.schematics.Schematic)1 SafeTeleportBuilder (com.wasteofplastic.askyblock.util.teleport.SafeTeleportBuilder)1 UUID (java.util.UUID)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 Entity (org.bukkit.entity.Entity)1 Player (org.bukkit.entity.Player)1