Search in sources :

Example 26 with Island

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

the class SettingsPanel method onInventoryClick.

/**
 * Handle clicks to the Settings panel
 * @param event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
    // The player that clicked the item
    Player player = (Player) event.getWhoClicked();
    // The inventory that was clicked in
    Inventory inventory = event.getInventory();
    if (inventory.getName() == null) {
        return;
    }
    int slot = event.getRawSlot();
    // Check this is the right panel
    if (!inventory.getName().equals(plugin.myLocale(player.getUniqueId()).igsTitle)) {
        return;
    }
    // Stop removal of items
    event.setCancelled(true);
    if (event.getSlotType() == SlotType.OUTSIDE) {
        player.closeInventory();
        inventory.clear();
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        player.closeInventory();
        inventory.clear();
        player.updateInventory();
        return;
    }
    // Check world
    if (!player.getLocation().getWorld().equals(ASkyBlock.getIslandWorld()) && !player.getLocation().getWorld().equals(ASkyBlock.getNetherWorld())) {
        return;
    }
    // 1.7.x server
    if (!hasArmorStand && slot > lookup.size()) {
        return;
    }
    // 1.8.x server
    if (slot > (lookup.size() + 1)) {
        return;
    }
    // Get the flag
    SettingsFlag flag = null;
    if (lookup.containsKey(event.getCurrentItem().getType())) {
        // All other items
        flag = lookup.get(event.getCurrentItem().getType());
    } else if (hasArmorStand && event.getCurrentItem().getType() == Material.ARMOR_STAND) {
        // Special handling to avoid errors on 1.7.x servers
        flag = SettingsFlag.ARMOR_STAND;
    }
    // If flag is null, do nothing
    if (flag == null) {
        return;
    }
    // Players can only do something if they own the island or are op
    Island island = plugin.getGrid().getIslandAt(player.getLocation());
    if (island != null && (player.isOp() || (island.getOwner() != null && island.getOwner().equals(player.getUniqueId())))) {
        // Check perms
        if (player.isOp() || player.hasPermission(Settings.PERMPREFIX + "settings." + flag.toString())) {
            // plugin.getLogger().info("DEBUG: Player has perm " + flag.toString());
            if (flag.equals(SettingsFlag.PVP) || flag.equals(SettingsFlag.NETHER_PVP)) {
                // PVP always results in an inventory closure
                player.closeInventory();
                inventory.clear();
                // PVP activation
                if (!island.getIgsFlag(flag)) {
                    // plugin.getLogger().info("DEBUG: attempt to activate PVP");
                    if (pvpCoolDown.containsKey(player.getUniqueId())) {
                        // plugin.getLogger().info("DEBUG: player is in the cooldown list");
                        long setTime = pvpCoolDown.get(player.getUniqueId());
                        // plugin.getLogger().info("DEBUG: set time is " + setTime);
                        long secondsLeft = Settings.pvpRestartCooldown - (System.currentTimeMillis() - setTime) / 1000;
                        // plugin.getLogger().info("DEBUG: seconds left = " + secondsLeft);
                        if (secondsLeft > 0) {
                            Util.sendMessage(player, ChatColor.RED + "You must wait " + secondsLeft + " seconds until you can do that again!");
                            return;
                        }
                        // Tidy up
                        pvpCoolDown.remove(player.getUniqueId());
                    }
                    // Warn players on the island
                    for (Player p : plugin.getServer().getOnlinePlayers()) {
                        if (island.onIsland(p.getLocation())) {
                            if (flag.equals(SettingsFlag.NETHER_PVP)) {
                                Util.sendMessage(p, ChatColor.RED + "" + ChatColor.BOLD + plugin.myLocale(p.getUniqueId()).igs.get(SettingsFlag.NETHER_PVP) + " " + plugin.myLocale(p.getUniqueId()).igsAllowed);
                            } else {
                                Util.sendMessage(p, ChatColor.RED + "" + ChatColor.BOLD + plugin.myLocale(p.getUniqueId()).igs.get(SettingsFlag.PVP) + " " + plugin.myLocale(p.getUniqueId()).igsAllowed);
                            }
                            if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
                                player.getWorld().playSound(player.getLocation(), Sound.valueOf("ARROW_HIT"), 1F, 1F);
                            } else {
                                player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
                            }
                        }
                    }
                    // Toggle the flag
                    island.toggleIgs(flag);
                    // Update warp signs
                    final List<UUID> members = island.getMembers();
                    // Run one tick later because text gets updated at the end of tick
                    plugin.getServer().getScheduler().runTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            for (UUID playerUUID : members) {
                                plugin.getWarpPanel().updateWarp(playerUUID);
                            }
                        }
                    });
                    return;
                } else {
                    // PVP deactivation
                    // Store this deactivation time
                    pvpCoolDown.put(player.getUniqueId(), System.currentTimeMillis());
                    // Immediately toggle the setting
                    island.toggleIgs(flag);
                    // Update warp signs
                    final List<UUID> members = island.getMembers();
                    // Run one tick later because text gets updated at the end of tick
                    plugin.getServer().getScheduler().runTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            for (UUID playerUUID : members) {
                                plugin.getWarpPanel().updateWarp(playerUUID);
                            }
                        }
                    });
                    // Warn players of change
                    for (Player p : plugin.getServer().getOnlinePlayers()) {
                        if (island.onIsland(p.getLocation())) {
                            // Deactivate PVP
                            if (flag.equals(SettingsFlag.NETHER_PVP)) {
                                Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).igs.get(SettingsFlag.NETHER_PVP) + " " + plugin.myLocale(p.getUniqueId()).igsDisallowed);
                            } else {
                                Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).igs.get(SettingsFlag.PVP) + " " + plugin.myLocale(p.getUniqueId()).igsDisallowed);
                            }
                            if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
                                p.getWorld().playSound(p.getLocation(), Sound.valueOf("FIREWORK_TWINKLE"), 1F, 1F);
                            } else {
                                p.getWorld().playSound(p.getLocation(), Sound.ENTITY_FIREWORK_TWINKLE, 1F, 1F);
                            }
                        }
                    }
                }
            } else {
                island.toggleIgs(flag);
            }
        }
        // player.closeInventory();
        inventory.clear();
        player.openInventory(islandGuardPanel(player));
    }
}
Also used : SettingsFlag(com.wasteofplastic.askyblock.Island.SettingsFlag) Player(org.bukkit.entity.Player) UUID(java.util.UUID) Island(com.wasteofplastic.askyblock.Island) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 27 with Island

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

the class PlayerEvents method onPlayerRespawn.

/**
 * Places player back on their island if the setting is true
 * @param e - event
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerRespawn(final PlayerRespawnEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!Settings.respawnOnIsland) {
        return;
    }
    if (respawn.contains(e.getPlayer().getUniqueId())) {
        respawn.remove(e.getPlayer().getUniqueId());
        Location respawnLocation = plugin.getGrid().getSafeHomeLocation(e.getPlayer().getUniqueId(), 1);
        if (respawnLocation != null) {
            // plugin.getLogger().info("DEBUG: Setting respawn location to " + respawnLocation);
            e.setRespawnLocation(respawnLocation);
            // Get island
            Island island = plugin.getGrid().getIslandAt(respawnLocation);
            if (island != null) {
                // Run perms etc.
                processPerms(e.getPlayer(), island);
            }
        }
    }
}
Also used : Island(com.wasteofplastic.askyblock.Island) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 28 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)

Example 29 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 30 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)

Aggregations

Island (com.wasteofplastic.askyblock.Island)58 EventHandler (org.bukkit.event.EventHandler)43 Player (org.bukkit.entity.Player)28 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 Projectile (org.bukkit.entity.Projectile)5 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5 IslandExitEvent (com.wasteofplastic.askyblock.events.IslandExitEvent)4 Monster (org.bukkit.entity.Monster)4 Vector (org.bukkit.util.Vector)4 SettingsFlag (com.wasteofplastic.askyblock.Island.SettingsFlag)3