Search in sources :

Example 21 with Island

use of com.wasteofplastic.acidisland.Island in project acidisland 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.acidisland.events.IslandEnterEvent) SafeTeleportBuilder(com.wasteofplastic.acidisland.util.teleport.SafeTeleportBuilder) UUID(java.util.UUID) World(org.bukkit.World) Island(com.wasteofplastic.acidisland.Island) Schematic(com.wasteofplastic.acidisland.schematics.Schematic) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 22 with Island

use of com.wasteofplastic.acidisland.Island in project acidisland 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.acidisland.events.IslandEnterEvent) IslandExitEvent(com.wasteofplastic.acidisland.events.IslandExitEvent) Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 23 with Island

use of com.wasteofplastic.acidisland.Island in project acidisland 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.acidisland.events.IslandEnterEvent) Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 24 with Island

use of com.wasteofplastic.acidisland.Island in project acidisland 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.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 25 with Island

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

the class BiomesPanel method onInventoryClick.

@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClick(InventoryClickEvent event) {
    // The player that
    Player player = (Player) event.getWhoClicked();
    // clicked the item
    UUID playerUUID = player.getUniqueId();
    // The inventory that was
    Inventory inventory = event.getInventory();
    // clicked in
    int slot = event.getRawSlot();
    // Check this is the right panel
    if (inventory.getName() == null || !inventory.getName().equals(plugin.myLocale().biomePanelTitle)) {
        return;
    }
    if (slot == -999) {
        inventory.clear();
        player.closeInventory();
        event.setCancelled(true);
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        event.setCancelled(true);
        inventory.clear();
        player.closeInventory();
        player.updateInventory();
        return;
    }
    // Get the list of items for this player
    List<BiomeItem> thisPanel = biomeItems.get(player.getUniqueId());
    if (thisPanel == null) {
        inventory.clear();
        player.closeInventory();
        event.setCancelled(true);
        return;
    }
    if (slot >= 0 && slot < thisPanel.size()) {
        event.setCancelled(true);
        // plugin.getLogger().info("DEBUG: slot is " + slot);
        // Do something
        // Check this player has an island
        Island island = plugin.getGrid().getIsland(playerUUID);
        if (island == null) {
            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
            return;
        }
        // Check ownership
        if (!island.getOwner().equals(playerUUID)) {
            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).levelerrornotYourIsland);
            return;
        }
        if (!plugin.getGrid().playerIsOnIsland(player)) {
            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).challengeserrorNotOnIsland);
            return;
        }
        Biome biome = thisPanel.get(slot).getBiome();
        if (biome != null) {
            event.setCancelled(true);
            if (Settings.useEconomy) {
                // Check cost
                double cost = thisPanel.get(slot).getPrice();
                if (cost > 0D) {
                    if (!VaultHelper.econ.has(player, Settings.worldName, cost)) {
                        Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).minishopYouCannotAfford.replace("[description]", VaultHelper.econ.format(cost)));
                        return;
                    } else {
                        VaultHelper.econ.withdrawPlayer(player, Settings.worldName, cost);
                        Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).biomeYouBought.replace("[cost]", VaultHelper.econ.format(cost)));
                    }
                }
            }
        }
        inventory.clear();
        // Closes the inventory
        player.closeInventory();
        // Actually set the biome
        Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).biomePleaseWait);
        new SetBiome(plugin, island, biome, player);
    }
    return;
}
Also used : Player(org.bukkit.entity.Player) Biome(org.bukkit.block.Biome) UUID(java.util.UUID) Island(com.wasteofplastic.acidisland.Island) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Island (com.wasteofplastic.acidisland.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.acidisland.ASkyBlock)5 IslandEnterEvent (com.wasteofplastic.acidisland.events.IslandEnterEvent)5 Material (org.bukkit.Material)5 Block (org.bukkit.block.Block)5 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5 IslandExitEvent (com.wasteofplastic.acidisland.events.IslandExitEvent)4 Inventory (org.bukkit.inventory.Inventory)4 BlockIterator (org.bukkit.util.BlockIterator)4 Vector (org.bukkit.util.Vector)4 SettingsFlag (com.wasteofplastic.acidisland.Island.SettingsFlag)3