mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-12 03:59:06 +00:00
Merge pull request #240 from StrangeOne101/master
Redone Temporary Fire
This commit is contained in:
commit
22c11934f9
8 changed files with 107 additions and 8 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
else FireMethods.createTempFire(block.getLocation());
|
||||
//block.setType(Material.FIRE);
|
||||
if (dissipate) {
|
||||
FireStream.ignitedblocks.put(block, player);
|
||||
FireStream.ignitedtimes.put(block, System.currentTimeMillis());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -4,26 +4,33 @@ 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<Location, Information> tempFire = new ConcurrentHashMap<Location, Information>();
|
||||
|
||||
public FireMethods(ProjectKorra plugin) {
|
||||
FireMethods.plugin = plugin;
|
||||
}
|
||||
|
@ -40,6 +47,33 @@ public class FireMethods {
|
|||
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
|
||||
* value if it is day.
|
||||
|
@ -147,6 +181,42 @@ public class FireMethods {
|
|||
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() {
|
||||
FireStream.removeAll(FireStream.class);
|
||||
Fireball.removeAll(Fireball.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Block, Player> ignitedblocks = new ConcurrentHashMap<Block, Player>();
|
||||
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>();
|
||||
|
||||
@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<? extends CoreAbility> 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());
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue