Search in sources :

Example 56 with Island

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

Example 57 with Island

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