Search in sources :

Example 1 with IslandExitEvent

use of com.wasteofplastic.askyblock.events.IslandExitEvent 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 2 with IslandExitEvent

use of com.wasteofplastic.askyblock.events.IslandExitEvent 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 3 with IslandExitEvent

use of com.wasteofplastic.askyblock.events.IslandExitEvent 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)

Example 4 with IslandExitEvent

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

the class PlayerEvents method onPlayerLeave.

/**
 * Removes temporary perms when the player log out
 * @param event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerLeave(PlayerQuitEvent event) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: Removing fly and all temp perms");
    Player player = event.getPlayer();
    if (temporaryPerms.containsKey(player.getUniqueId())) {
        for (String perm : temporaryPerms.get(player.getUniqueId())) {
            VaultHelper.removePerm(player, perm, ASkyBlock.getIslandWorld());
            if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
                VaultHelper.removePerm(player, perm, ASkyBlock.getNetherWorld());
            }
        }
        temporaryPerms.remove(player.getUniqueId());
    }
    if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "islandfly")) {
        if (player.getGameMode().equals(GameMode.SURVIVAL)) {
            player.setAllowFlight(false);
            player.setFlying(false);
        }
    }
    final Island island = plugin.getGrid().getProtectedIslandAt(event.getPlayer().getLocation());
    if (island != null) {
        // Fire exit event
        final IslandExitEvent e = new IslandExitEvent(event.getPlayer().getUniqueId(), island, event.getPlayer().getLocation());
        plugin.getServer().getPluginManager().callEvent(e);
    }
}
Also used : Player(org.bukkit.entity.Player) IslandExitEvent(com.wasteofplastic.askyblock.events.IslandExitEvent) Island(com.wasteofplastic.askyblock.Island) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Island (com.wasteofplastic.askyblock.Island)4 IslandExitEvent (com.wasteofplastic.askyblock.events.IslandExitEvent)4 EventHandler (org.bukkit.event.EventHandler)4 IslandEnterEvent (com.wasteofplastic.askyblock.events.IslandEnterEvent)3 LivingEntity (org.bukkit.entity.LivingEntity)2 Player (org.bukkit.entity.Player)2 Vector (org.bukkit.util.Vector)2 Entity (org.bukkit.entity.Entity)1