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);
}
}
}
}
}
}
});
}
}
}
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);
}
}
}
});
}
}
Aggregations