diff --git a/src/com/projectkorra/ProjectKorra/Ability/AbilityModule.java b/src/com/projectkorra/ProjectKorra/Ability/AbilityModule.java index 3d7c0e29..a32172df 100644 --- a/src/com/projectkorra/ProjectKorra/Ability/AbilityModule.java +++ b/src/com/projectkorra/ProjectKorra/Ability/AbilityModule.java @@ -1,6 +1,6 @@ package com.projectkorra.ProjectKorra.Ability; -import Utilities.AbilityLoadable; +import com.projectkorra.ProjectKorra.Utilities.AbilityLoadable; public class AbilityModule extends AbilityLoadable implements Cloneable { diff --git a/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java b/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java index 50409057..74479ee6 100644 --- a/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java +++ b/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java @@ -7,8 +7,8 @@ import java.util.List; import com.projectkorra.ProjectKorra.Element; import com.projectkorra.ProjectKorra.ProjectKorra; +import com.projectkorra.ProjectKorra.Utilities.AbilityLoader; -import Utilities.AbilityLoader; public class AbilityModuleManager { diff --git a/src/com/projectkorra/ProjectKorra/BendingManager.java b/src/com/projectkorra/ProjectKorra/BendingManager.java index 521fd1e7..072179f4 100644 --- a/src/com/projectkorra/ProjectKorra/BendingManager.java +++ b/src/com/projectkorra/ProjectKorra/BendingManager.java @@ -10,7 +10,7 @@ import org.bukkit.WorldType; import org.bukkit.entity.Player; import com.projectkorra.ProjectKorra.airbending.AirPassive; -import com.projectkorra.ProjectKorra.airbending.chiblocking.ChiPassive; +import com.projectkorra.ProjectKorra.chiblocking.ChiPassive; import com.projectkorra.ProjectKorra.earthbending.EarthPassive; import com.projectkorra.ProjectKorra.firebending.FirePassive; import com.projectkorra.ProjectKorra.waterbending.Plantbending; diff --git a/src/com/projectkorra/ProjectKorra/Methods.java b/src/com/projectkorra/ProjectKorra/Methods.java index 020153d1..a56d6ba8 100644 --- a/src/com/projectkorra/ProjectKorra/Methods.java +++ b/src/com/projectkorra/ProjectKorra/Methods.java @@ -378,6 +378,34 @@ public class Methods { } return true; } + + public static Vector rotateVectorAroundVector(Vector axis, Vector rotator, + double degrees) { + double angle = Math.toRadians(degrees); + Vector rotation = axis.clone(); + Vector rotate = rotator.clone(); + rotation = rotation.normalize(); + + Vector thirdaxis = rotation.crossProduct(rotate).normalize() + .multiply(rotate.length()); + + return rotate.multiply(Math.cos(angle)).add( + thirdaxis.multiply(Math.sin(angle))); + + // return new Vector(x, z, y); + } + + public static Vector getOrthogonalVector(Vector axis, double degrees, + double length) { + + Vector ortho = new Vector(axis.getY(), -axis.getX(), 0); + ortho = ortho.normalize(); + ortho = ortho.multiply(length); + + return rotateVectorAroundVector(axis, ortho, degrees); + + } + public static boolean isWeapon(Material mat) { if (mat == null) return false; if (mat == Material.WOOD_AXE || mat == Material.WOOD_PICKAXE diff --git a/src/com/projectkorra/ProjectKorra/PKListener.java b/src/com/projectkorra/ProjectKorra/PKListener.java index c35793d3..51852ec9 100644 --- a/src/com/projectkorra/ProjectKorra/PKListener.java +++ b/src/com/projectkorra/ProjectKorra/PKListener.java @@ -1,17 +1,25 @@ package com.projectkorra.ProjectKorra; +import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import com.projectkorra.ProjectKorra.airbending.chiblocking.ChiPassive; +import com.projectkorra.ProjectKorra.chiblocking.ChiPassive; import com.projectkorra.ProjectKorra.earthbending.EarthPassive; +import com.projectkorra.ProjectKorra.firebending.Enflamed; +import com.projectkorra.ProjectKorra.firebending.FireStream; import com.projectkorra.ProjectKorra.waterbending.WaterPassive; public class PKListener implements Listener { @@ -33,6 +41,38 @@ public class PKListener implements Listener { BendingPlayer.players.remove(e.getPlayer().getName()); } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityCombust(EntityCombustEvent event) { + Entity entity = event.getEntity(); + Block block = entity.getLocation().getBlock(); + if (FireStream.ignitedblocks.containsKey(block) && entity instanceof LivingEntity) { + new Enflamed(entity, FireStream.ignitedblocks.get(block)); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityDamageEvent(EntityDamageEvent event) { + Entity entity = event.getEntity(); + if (event.getCause() == DamageCause.FIRE && FireStream.ignitedblocks.containsKey(entity.getLocation().getBlock())) { + new Enflamed(entity, FireStream.ignitedblocks.get(entity.getLocation().getBlock())); + } + + if (Enflamed.isEnflamed(entity) && event.getCause() == DamageCause.FIRE_TICK) { + event.setCancelled(true); + Enflamed.dealFlameDamage(entity); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockMeltEvent(BlockFadeEvent event) { + Block block = event.getBlock(); + if (block.getType() == Material.FIRE) { + return; + } + if (FireStream.ignitedblocks.containsKey(block)) { + FireStream.remove(block); + } + } @EventHandler public void onPlayerDamageByPlayer(EntityDamageByEntityEvent e) { Entity en = e.getEntity(); diff --git a/src/Utilities/AbilityLoadEvent.java b/src/com/projectkorra/ProjectKorra/Utilities/AbilityLoadEvent.java similarity index 94% rename from src/Utilities/AbilityLoadEvent.java rename to src/com/projectkorra/ProjectKorra/Utilities/AbilityLoadEvent.java index 279f5e9b..3cb210bc 100644 --- a/src/Utilities/AbilityLoadEvent.java +++ b/src/com/projectkorra/ProjectKorra/Utilities/AbilityLoadEvent.java @@ -1,4 +1,4 @@ -package Utilities; +package com.projectkorra.ProjectKorra.Utilities; import java.util.jar.JarFile; diff --git a/src/Utilities/AbilityLoadable.java b/src/com/projectkorra/ProjectKorra/Utilities/AbilityLoadable.java similarity index 95% rename from src/Utilities/AbilityLoadable.java rename to src/com/projectkorra/ProjectKorra/Utilities/AbilityLoadable.java index ee2321dc..3e40e939 100644 --- a/src/Utilities/AbilityLoadable.java +++ b/src/com/projectkorra/ProjectKorra/Utilities/AbilityLoadable.java @@ -1,4 +1,4 @@ -package Utilities; +package com.projectkorra.ProjectKorra.Utilities; public class AbilityLoadable implements Cloneable { diff --git a/src/Utilities/AbilityLoader.java b/src/com/projectkorra/ProjectKorra/Utilities/AbilityLoader.java similarity index 95% rename from src/Utilities/AbilityLoader.java rename to src/com/projectkorra/ProjectKorra/Utilities/AbilityLoader.java index f572e4d0..3d83e8d3 100644 --- a/src/Utilities/AbilityLoader.java +++ b/src/com/projectkorra/ProjectKorra/Utilities/AbilityLoader.java @@ -1,4 +1,4 @@ -package Utilities; +package com.projectkorra.ProjectKorra.Utilities; import java.io.BufferedReader; import java.io.File; @@ -17,8 +17,9 @@ import java.util.logging.Logger; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; -import Utilities.AbilityLoadable.LoadResult; -import Utilities.AbilityLoadable.LoadResult.Result; +import com.projectkorra.ProjectKorra.Utilities.AbilityLoadable.LoadResult; +import com.projectkorra.ProjectKorra.Utilities.AbilityLoadable.LoadResult.Result; + public class AbilityLoader implements Listener { diff --git a/src/Utilities/FileExtensionFilter.java b/src/com/projectkorra/ProjectKorra/Utilities/FileExtensionFilter.java similarity index 87% rename from src/Utilities/FileExtensionFilter.java rename to src/com/projectkorra/ProjectKorra/Utilities/FileExtensionFilter.java index 409693aa..d8a2f156 100644 --- a/src/Utilities/FileExtensionFilter.java +++ b/src/com/projectkorra/ProjectKorra/Utilities/FileExtensionFilter.java @@ -1,4 +1,4 @@ -package Utilities; +package com.projectkorra.ProjectKorra.Utilities; import java.io.File; diff --git a/src/com/projectkorra/ProjectKorra/airbending/chiblocking/ChiPassive.java b/src/com/projectkorra/ProjectKorra/chiblocking/ChiPassive.java similarity index 97% rename from src/com/projectkorra/ProjectKorra/airbending/chiblocking/ChiPassive.java rename to src/com/projectkorra/ProjectKorra/chiblocking/ChiPassive.java index 91309241..d115afed 100644 --- a/src/com/projectkorra/ProjectKorra/airbending/chiblocking/ChiPassive.java +++ b/src/com/projectkorra/ProjectKorra/chiblocking/ChiPassive.java @@ -1,4 +1,4 @@ -package com.projectkorra.ProjectKorra.airbending.chiblocking; +package com.projectkorra.ProjectKorra.chiblocking; import java.util.Random; diff --git a/src/com/projectkorra/ProjectKorra/firebending/Enflamed.java b/src/com/projectkorra/ProjectKorra/firebending/Enflamed.java new file mode 100644 index 00000000..95cfdc99 --- /dev/null +++ b/src/com/projectkorra/ProjectKorra/firebending/Enflamed.java @@ -0,0 +1,67 @@ +package com.projectkorra.ProjectKorra.firebending; + +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + +public class Enflamed { + + private static ConcurrentHashMap instances = new ConcurrentHashMap(); + private static ConcurrentHashMap times = new ConcurrentHashMap(); + + private static final int damage = 1; + private static final int max = 90; + private static final long buffer = 30; + + public Enflamed(Entity entity, Player source) { + if (entity.getEntityId() == source.getEntityId()) + return; + if (instances.containsKey(entity)) { + instances.replace(entity, source); + } else { + instances.put(entity, source); + } + } + + public static boolean isEnflamed(Entity entity) { + // return false; + if (instances.containsKey(entity)) { + if (times.containsKey(entity)) { + long time = times.get(entity); + if (System.currentTimeMillis() < time + buffer) { + return false; + } + } + times.put(entity, System.currentTimeMillis()); + return true; + } else { + return false; + } + } + + public static void dealFlameDamage(Entity entity) { + if (instances.containsKey(entity) && entity instanceof LivingEntity) { +// if (entity instanceof Player) { +// if (!Extinguish.canBurn((Player) entity)) { +// return; +// } +// } + LivingEntity Lentity = (LivingEntity) entity; + Player source = instances.get(entity); + Lentity.damage(damage, source); + if (entity.getFireTicks() > max) + entity.setFireTicks(max); + } + } + + public static void handleFlames() { + for (Entity entity : instances.keySet()) { + if (entity.getFireTicks() <= 0) { + instances.remove(entity); + } + } + } + +} \ No newline at end of file