Search in sources :

Example 51 with Island

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

the class LavaCheck method onCobbleGen.

/**
 * Magic Cobble Generator
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCobbleGen(BlockFromToEvent e) {
    // If magic cobble gen isnt used
    if (!Settings.useMagicCobbleGen) {
        // plugin.getLogger().info("DEBUG: no magic cobble gen");
        return;
    }
    // Only do this in ASkyBlock world
    if (!e.getBlock().getWorld().equals(ASkyBlock.getIslandWorld())) {
        // plugin.getLogger().info("DEBUG: wrong world");
        return;
    }
    // Do nothing if a new island is being created
    if (plugin.isNewIsland()) {
        // plugin.getLogger().info("DEBUG: new island in creation");
        return;
    }
    // If only at spawn, do nothing if we're not at spawn
    if (Settings.magicCobbleGenOnlyAtSpawn && (!ASkyBlockAPI.getInstance().isAtSpawn(e.getBlock().getLocation()))) {
        return;
    }
    final Block b = e.getBlock();
    if (b.getType().equals(Material.WATER) || b.getType().equals(Material.STATIONARY_WATER) || b.getType().equals(Material.LAVA) || b.getType().equals(Material.STATIONARY_LAVA)) {
        // plugin.getLogger().info("DEBUG: From block is water or lava. To = " + e.getToBlock().getType());
        final Block toBlock = e.getToBlock();
        if (toBlock.getType().equals(Material.AIR) && generatesCobble(b, toBlock)) {
            // plugin.getLogger().info("DEBUG: potential cobble gen");
            // Get island level or use default
            long l = Long.MIN_VALUE;
            Island island = plugin.getGrid().getIslandAt(b.getLocation());
            if (island != null) {
                if (island.getOwner() != null) {
                    l = plugin.getPlayers().getIslandLevel(island.getOwner());
                // plugin.getLogger().info("DEBUG: level " + level);
                }
            }
            final long level = l;
            // Check if cobble was generated next tick
            // Store surrounding blocks and their current material types
            final List<Block> prevBlock = new ArrayList<Block>();
            final List<Material> prevMat = new ArrayList<Material>();
            for (BlockFace face : FACES) {
                Block r = toBlock.getRelative(face);
                prevBlock.add(r);
                prevMat.add(r.getType());
            // r = toBlock.getRelative(face,2);
            // prevBlock.add(r);
            // prevMat.add(r.getType());
            }
            // Check if they became cobblestone next tick
            plugin.getServer().getScheduler().runTask(plugin, new Runnable() {

                @Override
                public void run() {
                    Iterator<Block> blockIt = prevBlock.iterator();
                    Iterator<Material> matIt = prevMat.iterator();
                    while (blockIt.hasNext() && matIt.hasNext()) {
                        Block block = blockIt.next();
                        Material material = matIt.next();
                        if (block.getType().equals(Material.COBBLESTONE) && !block.getType().equals(material)) {
                            // plugin.getLogger().info("DEBUG: Cobble generated. Island level = " + level);
                            if (!Settings.magicCobbleGenChances.isEmpty()) {
                                Entry<Long, TreeMap<Double, Material>> entry = Settings.magicCobbleGenChances.floorEntry(level);
                                double maxValue = entry.getValue().lastKey();
                                double rnd = Util.randomDouble() * maxValue;
                                Entry<Double, Material> en = entry.getValue().ceilingEntry(rnd);
                                // plugin.getLogger().info("DEBUG: material = " + en.getValue());
                                if (en != null) {
                                    block.setType(en.getValue());
                                    // Record stats, per level
                                    if (stats.containsKey(entry.getKey())) {
                                        stats.get(entry.getKey()).add(en.getValue());
                                    } else {
                                        Multiset<Material> set = HashMultiset.create();
                                        set.add(en.getValue());
                                        stats.put(entry.getKey(), set);
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) ArrayList(java.util.ArrayList) Material(org.bukkit.Material) Island(com.wasteofplastic.acidisland.Island) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) Block(org.bukkit.block.Block) ASkyBlock(com.wasteofplastic.acidisland.ASkyBlock) Multiset(com.google.common.collect.Multiset) HashMultiset(com.google.common.collect.HashMultiset) EventHandler(org.bukkit.event.EventHandler)

Example 52 with Island

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

Example 53 with Island

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

Example 54 with Island

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

the class PlayerEvents method onVisitorDrop.

/*
     * Prevent item drop by visitors
     */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorDrop(final PlayerDropItemEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    Island island = plugin.getGrid().getIslandAt(e.getItemDrop().getLocation());
    if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_DROP)) || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect") || plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getItemDrop().getLocation())) {
        return;
    }
    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
    e.setCancelled(true);
}
Also used : Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 55 with Island

use of com.wasteofplastic.acidisland.Island in project acidisland 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.acidisland.Island) 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