Created
July 26, 2012 17:21
-
-
Save Xyene/3183305 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.github.Icyene.Storm.Rain.Listeners; | |
| import com.github.Icyene.Storm.Storm; | |
| import com.github.Icyene.Storm.Rain.Destructors.Deteriorator; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.Random; | |
| import org.bukkit.*; | |
| import org.bukkit.block.Biome; | |
| import org.bukkit.block.Block; | |
| import org.bukkit.event.*; | |
| import org.bukkit.event.weather.WeatherChangeEvent; | |
| public class AcidicWeatherListener implements Listener { | |
| private Storm storm; | |
| public static String acidRainMessage = "Acid has started to fall from the sky!"; | |
| public static final Random rand = new Random(); | |
| public static int scheduleId = -1; | |
| public static Chunk[] loadedChunk; | |
| public static Chunk chunkToDissolve; | |
| public static Block toDeteriorate; | |
| public static List<Integer> chunkScheduleManager = new ArrayList<Integer>(); | |
| public static int x, z = 0; | |
| public static final int y = 4; | |
| static final boolean debug = false; | |
| public static int deteriorationPercentage = 25; | |
| public static int acidRainChance = 100; | |
| public static int chunkDissolveChance = 75; | |
| public static int blocksPerChunk = 10; | |
| public static int chunksToCalculate = 4; | |
| public static boolean acidRain = true; | |
| public static boolean acidSnow = true; | |
| public static int delayTicks = 100; | |
| public static List<Biome> canAcidify = new ArrayList<Biome>(); | |
| public AcidicWeatherListener(Storm storm) { | |
| this.storm = storm; | |
| } | |
| @EventHandler(priority = EventPriority.HIGHEST) | |
| public void acidicWeatherListener(WeatherChangeEvent event) { | |
| if (event.isCancelled()) { | |
| return; | |
| } | |
| final World affectedWorld = event.getWorld(); | |
| if (!(rand.nextInt(100) < acidRainChance) || affectedWorld.hasStorm()) { | |
| if (debug) | |
| System.out.println("Acid rain averted."); | |
| return; // return if not acid rain | |
| } | |
| if (!affectedWorld.hasStorm()) { | |
| storm.getServer() | |
| .broadcastMessage(ChatColor.GRAY + acidRainMessage); | |
| loadedChunk = affectedWorld.getLoadedChunks(); | |
| if (debug) | |
| System.out | |
| .println("[Total chunks: " + loadedChunk.length + "]"); | |
| scheduleId = Bukkit.getScheduler().scheduleSyncRepeatingTask(storm, | |
| new Runnable() { | |
| public void run() { | |
| for (int ch = 0; ch <= chunksToCalculate; ++ch) { | |
| chunkToDissolve = loadedChunk[rand | |
| .nextInt(loadedChunk.length)]; | |
| if (rand.nextInt(100) < chunkDissolveChance) { | |
| for (int i = 0; i <= blocksPerChunk; ++i) { | |
| if (debug) | |
| System.out | |
| .println("Block for chunk " | |
| + chunkToDissolve | |
| + ". Index: " + i); | |
| x = rand.nextInt(16); | |
| z = rand.nextInt(16); | |
| if (debug) | |
| System.out.println("X: " + x | |
| + " Z: " + z); | |
| toDeteriorate = affectedWorld | |
| .getHighestBlockAt( | |
| chunkToDissolve | |
| .getBlock(x, y, | |
| z) | |
| .getLocation()) | |
| .getLocation() | |
| .subtract(0, 1, 0).getBlock(); | |
| if (rand.nextInt(100) < deteriorationPercentage) { | |
| if (debug) | |
| System.out | |
| .println(toDeteriorate); | |
| if (toDeteriorate.getTypeId() != 0) { | |
| if (debug) | |
| System.out | |
| .println("Pushed block to deteriorator: " | |
| + toDeteriorate); | |
| Deteriorator | |
| .dissolve(toDeteriorate); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }, delayTicks, delayTicks); | |
| if (debug) | |
| System.out.println("Added new chunk scheduler."); | |
| chunkScheduleManager.add(scheduleId); | |
| } else { | |
| if (debug) | |
| System.out.println("Cleared schedulers."); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment