From cd91d8b4bb4bd1576fd734483fb98747c99b4591 Mon Sep 17 00:00:00 2001 From: MistPhizzle Date: Thu, 12 Jun 2014 19:23:35 -0400 Subject: [PATCH 1/4] Package Cleanup --- .../projectkorra/ProjectKorra/Ability/AbilityModule.java | 2 +- .../ProjectKorra/Ability/AbilityModuleManager.java | 2 +- src/com/projectkorra/ProjectKorra/BendingManager.java | 2 +- src/com/projectkorra/ProjectKorra/PKListener.java | 2 +- .../ProjectKorra}/Utilities/AbilityLoadEvent.java | 2 +- .../ProjectKorra}/Utilities/AbilityLoadable.java | 2 +- .../ProjectKorra}/Utilities/AbilityLoader.java | 7 ++++--- .../ProjectKorra}/Utilities/FileExtensionFilter.java | 2 +- .../{airbending => }/chiblocking/ChiPassive.java | 2 +- 9 files changed, 12 insertions(+), 11 deletions(-) rename src/{ => com/projectkorra/ProjectKorra}/Utilities/AbilityLoadEvent.java (94%) rename src/{ => com/projectkorra/ProjectKorra}/Utilities/AbilityLoadable.java (95%) rename src/{ => com/projectkorra/ProjectKorra}/Utilities/AbilityLoader.java (95%) rename src/{ => com/projectkorra/ProjectKorra}/Utilities/FileExtensionFilter.java (87%) rename src/com/projectkorra/ProjectKorra/{airbending => }/chiblocking/ChiPassive.java (97%) 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/PKListener.java b/src/com/projectkorra/ProjectKorra/PKListener.java index c35793d3..5cbc2bf1 100644 --- a/src/com/projectkorra/ProjectKorra/PKListener.java +++ b/src/com/projectkorra/ProjectKorra/PKListener.java @@ -10,7 +10,7 @@ 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.waterbending.WaterPassive; 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; From 902a0f61198cd25a35f5c228badd9fffdaada7cd Mon Sep 17 00:00:00 2001 From: MistPhizzle Date: Thu, 12 Jun 2014 19:37:51 -0400 Subject: [PATCH 2/4] Vector Methods (Comes from orion304's original plugin, credit goes to him) --- .../projectkorra/ProjectKorra/Methods.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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 From b62366cb67f1021b8b13390cf5e4fd8db00c22d2 Mon Sep 17 00:00:00 2001 From: MistPhizzle Date: Thu, 12 Jun 2014 19:39:28 -0400 Subject: [PATCH 3/4] Enflamed Created by orion304, a Firebending utility class. --- .../ProjectKorra/firebending/Enflamed.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/com/projectkorra/ProjectKorra/firebending/Enflamed.java 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 From bd90ba740dc7a1f35fa3620918f4fa947d7171ca Mon Sep 17 00:00:00 2001 From: MistPhizzle Date: Thu, 12 Jun 2014 21:53:11 -0400 Subject: [PATCH 4/4] Add FireStream Events --- .../projectkorra/ProjectKorra/PKListener.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/com/projectkorra/ProjectKorra/PKListener.java b/src/com/projectkorra/ProjectKorra/PKListener.java index 5cbc2bf1..51852ec9 100644 --- a/src/com/projectkorra/ProjectKorra/PKListener.java +++ b/src/com/projectkorra/ProjectKorra/PKListener.java @@ -1,9 +1,15 @@ 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; @@ -12,6 +18,8 @@ import org.bukkit.event.player.PlayerQuitEvent; 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();