Search in sources :

Example 6 with ASkyBlock

use of com.wasteofplastic.acidisland.ASkyBlock 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 7 with ASkyBlock

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

the class LavaCheck method onCleanstoneGen.

/**
 * Removes stone generated by lava pouring onto water
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCleanstoneGen(BlockFromToEvent e) {
    // Only do this in ASkyBlock world
    if (!e.getBlock().getWorld().equals(ASkyBlock.getIslandWorld())) {
        return;
    }
    // Do nothing if a new island is being created
    if (plugin.isNewIsland())
        return;
    final Block to = e.getToBlock();
    /*
		plugin.getLogger().info("From material is " + e.getBlock().toString());
		plugin.getLogger().info("To material is " + to.getType().toString());
		plugin.getLogger().info("---------------------------------");
         */
    if (Settings.acidDamage > 0) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: cleanstone gen " + e.getEventName());
        final Material prev = to.getType();
        // plugin.getLogger().info("To material was " +
        // to.getType().toString());
        plugin.getServer().getScheduler().runTask(plugin, new Runnable() {

            @Override
            public void run() {
                // to.getType().toString());
                if ((prev.equals(Material.WATER) || prev.equals(Material.STATIONARY_WATER)) && to.getType().equals(Material.STONE)) {
                    to.setType(prev);
                    if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
                        to.getWorld().playSound(to.getLocation(), Sound.valueOf("FIZZ"), 1F, 2F);
                    } else {
                        to.getWorld().playSound(to.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 1F, 2F);
                    }
                }
            }
        });
    }
}
Also used : Block(org.bukkit.block.Block) ASkyBlock(com.wasteofplastic.acidisland.ASkyBlock) Material(org.bukkit.Material) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)7 Material (org.bukkit.Material)5 Block (org.bukkit.block.Block)5 EventHandler (org.bukkit.event.EventHandler)4 HashMultiset (com.google.common.collect.HashMultiset)2 Multiset (com.google.common.collect.Multiset)2 Island (com.wasteofplastic.acidisland.Island)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2 Location (org.bukkit.Location)2 Biome (org.bukkit.block.Biome)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 ASLocale (com.wasteofplastic.acidisland.ASLocale)1 FileLister (com.wasteofplastic.acidisland.FileLister)1 SettingsFlag (com.wasteofplastic.acidisland.Island.SettingsFlag)1 AcidEvent (com.wasteofplastic.acidisland.events.AcidEvent)1