Merge pull request #240 from StrangeOne101/master

Redone Temporary Fire
This commit is contained in:
OmniCypher 2015-09-11 15:59:30 -07:00
commit 22c11934f9
8 changed files with 107 additions and 8 deletions

View file

@ -254,6 +254,8 @@ public class PKListener implements Listener {
EarthMethods.removeRevertIndex(block); EarthMethods.removeRevertIndex(block);
} else if (TempBlock.isTempBlock(block)) { } else if (TempBlock.isTempBlock(block)) {
TempBlock.revertBlock(block, Material.AIR); TempBlock.revertBlock(block, Material.AIR);
} else if (FireMethods.tempFire.keySet().contains(block.getLocation())) {
FireMethods.revertTempFire(block.getLocation());
} }
} }

View file

@ -1,7 +1,5 @@
package com.projectkorra.projectkorra.configuration; package com.projectkorra.projectkorra.configuration;
import com.projectkorra.projectkorra.ProjectKorra;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import java.io.File; 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.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.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.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); config.addDefault("Properties.Chi.CanBendWithWeapons", true);

View file

@ -223,10 +223,15 @@ public class FireBlast extends CoreAbility {
private void ignite(Location location) { private void ignite(Location location) {
for (Block block : GeneralMethods.getBlocksAroundPoint(location, affectingradius)) { for (Block block : GeneralMethods.getBlocksAroundPoint(location, affectingradius)) {
if (FireStream.isIgnitable(player, block) && !safe.contains(block)) { if (FireStream.isIgnitable(player, block) && !safe.contains(block)) {
if (WaterMethods.isPlantbendable(block)) { /*if (WaterMethods.isPlantbendable(block)) {
new Plantbending(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) { if (dissipate) {
FireStream.ignitedblocks.put(block, player); FireStream.ignitedblocks.put(block, player);
FireStream.ignitedtimes.put(block, System.currentTimeMillis()); FireStream.ignitedtimes.put(block, System.currentTimeMillis());

View file

@ -43,7 +43,10 @@ public class FireJet extends CoreAbility {
Block block = player.getLocation().getBlock(); Block block = player.getLocation().getBlock();
if (FireStream.isIgnitable(player, block) || block.getType() == Material.AIR || AvatarState.isAvatarState(player)) { if (FireStream.isIgnitable(player, block) || block.getType() == Material.AIR || AvatarState.isAvatarState(player)) {
player.setVelocity(player.getEyeLocation().getDirection().clone().normalize().multiply(factor)); 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; this.player = player;
// canfly = player.getAllowFlight(); // canfly = player.getAllowFlight();
new Flight(player); new Flight(player);

View file

@ -4,25 +4,32 @@ import com.projectkorra.projectkorra.BendingManager;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.AbilityModuleManager; import com.projectkorra.projectkorra.ability.AbilityModuleManager;
import com.projectkorra.projectkorra.util.Information;
import com.projectkorra.rpg.RPGMethods; import com.projectkorra.rpg.RPGMethods;
import com.projectkorra.rpg.WorldEvents; import com.projectkorra.rpg.WorldEvents;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
public class FireMethods { public class FireMethods {
static ProjectKorra plugin; static ProjectKorra plugin;
private static FileConfiguration config = ProjectKorra.plugin.getConfig(); private static FileConfiguration config = ProjectKorra.plugin.getConfig();
public static ConcurrentHashMap<Location, Information> tempFire = new ConcurrentHashMap<Location, Information>();
public FireMethods(ProjectKorra plugin) { public FireMethods(ProjectKorra plugin) {
FireMethods.plugin = plugin; FireMethods.plugin = plugin;
@ -39,6 +46,33 @@ public class FireMethods {
return true; return true;
return false; 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 * Gets the firebending dayfactor from the config multiplied by a specific
@ -146,6 +180,42 @@ public class FireMethods {
list.add("FireShield"); list.add("FireShield");
return GeneralMethods.blockAbilities(null, list, loc, 0); return GeneralMethods.blockAbilities(null, list, loc, 0);
} }
/**Removes all temp fire that no longer needs to be there*/
public static void removeFire() {
Iterator<Location> 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() { public static void stopBending() {
FireStream.removeAll(FireStream.class); FireStream.removeAll(FireStream.class);
@ -159,5 +229,8 @@ public class FireMethods {
Cook.removeAll(Cook.class); Cook.removeAll(Cook.class);
Illumination.removeAll(Illumination.class); Illumination.removeAll(Illumination.class);
FireCombo.removeAll(); FireCombo.removeAll();
for (Location loc : tempFire.keySet()){
revertTempFire(loc);
}
} }
} }

View file

@ -11,6 +11,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.material.MaterialData;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.Arrays; import java.util.Arrays;
@ -20,6 +21,7 @@ public class FireStream extends AddonAbility {
public static ConcurrentHashMap<Block, Player> ignitedblocks = new ConcurrentHashMap<Block, Player>(); public static ConcurrentHashMap<Block, Player> ignitedblocks = new ConcurrentHashMap<Block, Player>();
public static ConcurrentHashMap<Block, Long> ignitedtimes = new ConcurrentHashMap<Block, Long>(); public static ConcurrentHashMap<Block, Long> ignitedtimes = new ConcurrentHashMap<Block, Long>();
public static ConcurrentHashMap<Location, MaterialData> replacedBlocks = new ConcurrentHashMap<Location, MaterialData>();
public static ConcurrentHashMap<LivingEntity, Player> ignitedentities = new ConcurrentHashMap<LivingEntity, Player>(); public static ConcurrentHashMap<LivingEntity, Player> ignitedentities = new ConcurrentHashMap<LivingEntity, Player>();
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -94,6 +96,7 @@ public class FireStream extends AddonAbility {
return false; return false;
} }
@SuppressWarnings("deprecation")
public static void remove(Block block) { public static void remove(Block block) {
if (ignitedblocks.containsKey(block)) { if (ignitedblocks.containsKey(block)) {
ignitedblocks.remove(block); ignitedblocks.remove(block);
@ -101,6 +104,11 @@ public class FireStream extends AddonAbility {
if (ignitedtimes.containsKey(block)) { if (ignitedtimes.containsKey(block)) {
ignitedtimes.remove(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<? extends CoreAbility> abilityClass) { public static void removeAll(Class<? extends CoreAbility> abilityClass) {
@ -133,11 +141,15 @@ public class FireStream extends AddonAbility {
} }
private void ignite(Block block) { private void ignite(Block block) {
if (WaterMethods.isPlant(block)) { if (block.getType() != Material.AIR) {
new Plantbending(block); 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); block.setType(Material.FIRE);
ignitedblocks.put(block, this.player); ignitedblocks.put(block, this.player);
ignitedtimes.put(block, System.currentTimeMillis()); ignitedtimes.put(block, System.currentTimeMillis());
} }

View file

@ -257,6 +257,9 @@ public class Fireball extends AddonAbility {
private void ignite(Location location) { private void ignite(Location location) {
for (Block block : GeneralMethods.getBlocksAroundPoint(location, FireBlast.AFFECTING_RADIUS)) { for (Block block : GeneralMethods.getBlocksAroundPoint(location, FireBlast.AFFECTING_RADIUS)) {
if (FireStream.isIgnitable(player, block)) { if (FireStream.isIgnitable(player, block)) {
if (block.getType() != Material.FIRE) {
FireStream.replacedBlocks.put(block.getLocation(), block.getState().getData());
}
block.setType(Material.FIRE); block.setType(Material.FIRE);
if (FireBlast.dissipate) { if (FireBlast.dissipate) {
FireStream.ignitedblocks.put(block, player); FireStream.ignitedblocks.put(block, player);

View file

@ -30,6 +30,7 @@ public class FirebendingManager implements Runnable {
FireStream.ignitedblocks.remove(block); FireStream.ignitedblocks.remove(block);
} }
} }
FireMethods.removeFire();
HeatControl.progressAll(HeatControl.class); HeatControl.progressAll(HeatControl.class);
FireStream.dissipateAll(); FireStream.dissipateAll();
FireStream.progressAll(FireStream.class); FireStream.progressAll(FireStream.class);