diff --git a/src/com/projectkorra/projectkorra/PKListener.java b/src/com/projectkorra/projectkorra/PKListener.java index b1af931c..5b557a6e 100644 --- a/src/com/projectkorra/projectkorra/PKListener.java +++ b/src/com/projectkorra/projectkorra/PKListener.java @@ -254,6 +254,8 @@ public class PKListener implements Listener { EarthMethods.removeRevertIndex(block); } else if (TempBlock.isTempBlock(block)) { TempBlock.revertBlock(block, Material.AIR); + } else if (FireMethods.tempFire.keySet().contains(block.getLocation())) { + FireMethods.revertTempFire(block.getLocation()); } } diff --git a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java index 081893cf..94b5c198 100644 --- a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java +++ b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java @@ -1,7 +1,5 @@ package com.projectkorra.projectkorra.configuration; -import com.projectkorra.projectkorra.ProjectKorra; - import org.bukkit.configuration.file.FileConfiguration; import java.io.File; @@ -166,6 +164,8 @@ public class ConfigManager { config.addDefault("Properties.Fire.DayMessage", "You feel the strength of the rising sun empowering your firebending."); config.addDefault("Properties.Fire.SolarEclipseMessage", "A solar eclipse is out! Firebenders are temporarily powerless."); config.addDefault("Properties.Fire.CometMessage", "Sozin's Comet is passing overhead! Firebending is now at its most powerful."); + config.addDefault("Properties.Fire.FireGriefing", false); + config.addDefault("Properties.Fire.RevertTicks", 12000L); config.addDefault("Properties.Chi.CanBendWithWeapons", true); diff --git a/src/com/projectkorra/projectkorra/firebending/FireBlast.java b/src/com/projectkorra/projectkorra/firebending/FireBlast.java index c881da38..e524ebb7 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireBlast.java +++ b/src/com/projectkorra/projectkorra/firebending/FireBlast.java @@ -223,10 +223,15 @@ public class FireBlast extends CoreAbility { private void ignite(Location location) { for (Block block : GeneralMethods.getBlocksAroundPoint(location, affectingradius)) { if (FireStream.isIgnitable(player, block) && !safe.contains(block)) { - if (WaterMethods.isPlantbendable(block)) { + /*if (WaterMethods.isPlantbendable(block)) { new Plantbending(block); + }*/ + if (FireMethods.canFireGrief()) { + if (WaterMethods.isPlantbendable(block)) new Plantbending(block); + block.setType(Material.FIRE); } - block.setType(Material.FIRE); + else FireMethods.createTempFire(block.getLocation()); + //block.setType(Material.FIRE); if (dissipate) { FireStream.ignitedblocks.put(block, player); FireStream.ignitedtimes.put(block, System.currentTimeMillis()); diff --git a/src/com/projectkorra/projectkorra/firebending/FireJet.java b/src/com/projectkorra/projectkorra/firebending/FireJet.java index a43d069d..421f435c 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireJet.java +++ b/src/com/projectkorra/projectkorra/firebending/FireJet.java @@ -43,7 +43,10 @@ public class FireJet extends CoreAbility { Block block = player.getLocation().getBlock(); if (FireStream.isIgnitable(player, block) || block.getType() == Material.AIR || AvatarState.isAvatarState(player)) { player.setVelocity(player.getEyeLocation().getDirection().clone().normalize().multiply(factor)); - block.setType(Material.FIRE); + if (FireMethods.canFireGrief()) { + FireMethods.createTempFire(block.getLocation()); + } + else block.setType(Material.FIRE); this.player = player; // canfly = player.getAllowFlight(); new Flight(player); diff --git a/src/com/projectkorra/projectkorra/firebending/FireMethods.java b/src/com/projectkorra/projectkorra/firebending/FireMethods.java index b0a53b71..7138652a 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireMethods.java +++ b/src/com/projectkorra/projectkorra/firebending/FireMethods.java @@ -4,25 +4,32 @@ import com.projectkorra.projectkorra.BendingManager; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.AbilityModuleManager; +import com.projectkorra.projectkorra.util.Information; import com.projectkorra.rpg.RPGMethods; import com.projectkorra.rpg.WorldEvents; import org.bukkit.ChatColor; import org.bukkit.Effect; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import java.util.concurrent.ConcurrentHashMap; public class FireMethods { static ProjectKorra plugin; private static FileConfiguration config = ProjectKorra.plugin.getConfig(); + + public static ConcurrentHashMap tempFire = new ConcurrentHashMap(); public FireMethods(ProjectKorra plugin) { FireMethods.plugin = plugin; @@ -39,6 +46,33 @@ public class FireMethods { return true; return false; } + + /**Returns if fire is allowed to completely replace blocks or if it should place a temp fire block.*/ + public static boolean canFireGrief() { + return config.getBoolean("Properties.Fire.FireGriefing"); + } + + /**Creates a fire block meant to replace other blocks but reverts when the fire dissipates or is destroyed.*/ + public static void createTempFire(Location loc) { + if (loc.getBlock().getType() == Material.AIR) { + loc.getBlock().setType(Material.FIRE); + return; + } + Information info = new Information(); + long time = config.getLong("Properties.Fire.RevertTicks") + (long)(GeneralMethods.rand.nextDouble() * config.getLong("Properties.Fire.RevertTicks")); //Generate a long between the config time and config time x 2. Just so it appears random + System.out.println(time); + if (tempFire.containsKey(loc)) { + info = tempFire.get(loc); + } + else { + info.setBlock(loc.getBlock()); + info.setLocation(loc); + info.setState(loc.getBlock().getState()); + } + info.setTime(time + System.currentTimeMillis()); + loc.getBlock().setType(Material.FIRE); + tempFire.put(loc, info); + } /** * Gets the firebending dayfactor from the config multiplied by a specific @@ -146,6 +180,42 @@ public class FireMethods { list.add("FireShield"); return GeneralMethods.blockAbilities(null, list, loc, 0); } + + /**Removes all temp fire that no longer needs to be there*/ + public static void removeFire() { + Iterator it = tempFire.keySet().iterator(); + while(it.hasNext()) { + Location loc = it.next(); + Information info = tempFire.get(loc); + if (info.getLocation().getBlock().getType() != Material.FIRE && info.getLocation().getBlock().getType() != Material.AIR) { + revertTempFire(loc); + } + else if (info.getBlock().getType() == Material.AIR || System.currentTimeMillis() > info.getTime()) { + revertTempFire(loc); + } + } + } + + /** + * Revert the temp fire at the location if any is there. + * + * @param location The Location + * */ + @SuppressWarnings("deprecation") + public static void revertTempFire(Location location) { + if (!tempFire.containsKey(location)) return; + Information info = tempFire.get(location); + if (info.getLocation().getBlock().getType() != Material.FIRE && info.getLocation().getBlock().getType() != Material.AIR) { + if (info.getState().getType() == Material.RED_ROSE || info.getState().getType() == Material.YELLOW_FLOWER) { + info.getState().getBlock().getWorld().dropItemNaturally(info.getLocation(), new ItemStack(info.getState().getData().getItemType(), 1, info.getState().getRawData())); + } + } + else { + info.getBlock().setType(info.getState().getType()); + info.getBlock().setData(info.getState().getRawData()); + } + tempFire.remove(location); + } public static void stopBending() { FireStream.removeAll(FireStream.class); @@ -159,5 +229,8 @@ public class FireMethods { Cook.removeAll(Cook.class); Illumination.removeAll(Illumination.class); FireCombo.removeAll(); + for (Location loc : tempFire.keySet()){ + revertTempFire(loc); + } } } diff --git a/src/com/projectkorra/projectkorra/firebending/FireStream.java b/src/com/projectkorra/projectkorra/firebending/FireStream.java index c480e4fa..2c0fef00 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireStream.java +++ b/src/com/projectkorra/projectkorra/firebending/FireStream.java @@ -11,6 +11,7 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.material.MaterialData; import org.bukkit.util.Vector; import java.util.Arrays; @@ -20,6 +21,7 @@ public class FireStream extends AddonAbility { public static ConcurrentHashMap ignitedblocks = new ConcurrentHashMap(); public static ConcurrentHashMap ignitedtimes = new ConcurrentHashMap(); + public static ConcurrentHashMap replacedBlocks = new ConcurrentHashMap(); public static ConcurrentHashMap ignitedentities = new ConcurrentHashMap(); @SuppressWarnings("unused") @@ -94,6 +96,7 @@ public class FireStream extends AddonAbility { return false; } + @SuppressWarnings("deprecation") public static void remove(Block block) { if (ignitedblocks.containsKey(block)) { ignitedblocks.remove(block); @@ -101,6 +104,11 @@ public class FireStream extends AddonAbility { if (ignitedtimes.containsKey(block)) { ignitedtimes.remove(block); } + if (replacedBlocks.containsKey(block.getLocation())) { + block.setType(replacedBlocks.get(block.getLocation()).getItemType()); + block.setData(replacedBlocks.get(block.getLocation()).getData()); + replacedBlocks.remove(block.getLocation()); + } } public static void removeAll(Class abilityClass) { @@ -133,11 +141,15 @@ public class FireStream extends AddonAbility { } private void ignite(Block block) { - if (WaterMethods.isPlant(block)) { - new Plantbending(block); + if (block.getType() != Material.AIR) { + if (FireMethods.canFireGrief()) { + if (WaterMethods.isPlant(block)) new Plantbending(block); + } else if (block.getType() != Material.FIRE){ + replacedBlocks.put(block.getLocation(), block.getState().getData()); + } } - block.setType(Material.FIRE); + ignitedblocks.put(block, this.player); ignitedtimes.put(block, System.currentTimeMillis()); } diff --git a/src/com/projectkorra/projectkorra/firebending/Fireball.java b/src/com/projectkorra/projectkorra/firebending/Fireball.java index 774644bd..00392d86 100644 --- a/src/com/projectkorra/projectkorra/firebending/Fireball.java +++ b/src/com/projectkorra/projectkorra/firebending/Fireball.java @@ -257,6 +257,9 @@ public class Fireball extends AddonAbility { private void ignite(Location location) { for (Block block : GeneralMethods.getBlocksAroundPoint(location, FireBlast.AFFECTING_RADIUS)) { if (FireStream.isIgnitable(player, block)) { + if (block.getType() != Material.FIRE) { + FireStream.replacedBlocks.put(block.getLocation(), block.getState().getData()); + } block.setType(Material.FIRE); if (FireBlast.dissipate) { FireStream.ignitedblocks.put(block, player); diff --git a/src/com/projectkorra/projectkorra/firebending/FirebendingManager.java b/src/com/projectkorra/projectkorra/firebending/FirebendingManager.java index ba9d5e37..85903fc2 100644 --- a/src/com/projectkorra/projectkorra/firebending/FirebendingManager.java +++ b/src/com/projectkorra/projectkorra/firebending/FirebendingManager.java @@ -30,6 +30,7 @@ public class FirebendingManager implements Runnable { FireStream.ignitedblocks.remove(block); } } + FireMethods.removeFire(); HeatControl.progressAll(HeatControl.class); FireStream.dissipateAll(); FireStream.progressAll(FireStream.class);