Search in sources :

Example 1 with Island

use of com.wasteofplastic.askyblock.Island 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 Island

use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.

the class PlayerEvents method onVistorDeath.

/*
     * Prevent dropping items if player dies on another island
     * This option helps reduce the down side of dying due to traps, etc.
     * Also handles muting of death messages
     */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVistorDeath(final PlayerDeathEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    // Mute death messages
    if (Settings.muteDeathMessages) {
        e.setDeathMessage(null);
    }
    // This will override any global settings
    if (Settings.allowVisitorKeepInvOnDeath) {
        // If the player is not a visitor then they die and lose everything -
        // sorry :-(
        Island island = plugin.getGrid().getProtectedIslandAt(e.getEntity().getLocation());
        if (island != null && !island.getMembers().contains(e.getEntity().getUniqueId())) {
            // They are a visitor
            InventorySave.getInstance().savePlayerInventory(e.getEntity());
            e.getDrops().clear();
            e.setKeepLevel(true);
            e.setDroppedExp(0);
        }
    }
}
Also used : Island(com.wasteofplastic.askyblock.Island) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Island

use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.

the class PlayerEvents2 method onVisitorPickup.

/*
     * Prevent item pickup by visitors for servers before 1.12.
     */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorPickup(final PlayerPickupItemEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    Island island = plugin.getGrid().getIslandAt(e.getItem().getLocation());
    if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_PICKUP)) || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect") || plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getItem().getLocation())) {
        return;
    }
    e.setCancelled(true);
}
Also used : Island(com.wasteofplastic.askyblock.Island) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Island

use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.

the class PlayerEvents3 method onVisitorPickup.

/*
     * Prevent item pickup by visitors for 1.12+.
     */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorPickup(final EntityPickupItemEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (e.getEntity() instanceof Player) {
        Player player = (Player) e.getEntity();
        if (!IslandGuard.inWorld(player)) {
            return;
        }
        Island island = plugin.getGrid().getIslandAt(e.getItem().getLocation());
        if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_PICKUP)) || player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect") || plugin.getGrid().locationIsOnIsland(player, e.getItem().getLocation())) {
            return;
        }
        e.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) Island(com.wasteofplastic.askyblock.Island) EventHandler(org.bukkit.event.EventHandler)

Example 5 with Island

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

Aggregations

Island (com.wasteofplastic.askyblock.Island)57 EventHandler (org.bukkit.event.EventHandler)42 Player (org.bukkit.entity.Player)27 UUID (java.util.UUID)13 Location (org.bukkit.Location)12 LivingEntity (org.bukkit.entity.LivingEntity)8 ItemStack (org.bukkit.inventory.ItemStack)8 ArrayList (java.util.ArrayList)7 Entity (org.bukkit.entity.Entity)7 Animals (org.bukkit.entity.Animals)6 ASkyBlock (com.wasteofplastic.askyblock.ASkyBlock)5 IslandEnterEvent (com.wasteofplastic.askyblock.events.IslandEnterEvent)5 Material (org.bukkit.Material)5 Block (org.bukkit.block.Block)5 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5 IslandExitEvent (com.wasteofplastic.askyblock.events.IslandExitEvent)4 Monster (org.bukkit.entity.Monster)4 Projectile (org.bukkit.entity.Projectile)4 Slime (org.bukkit.entity.Slime)4 Vector (org.bukkit.util.Vector)4