Merge pull request #163 from Alex-The-Coder/master

Adds Plant Armor, fixes Earth Armor/Fast Swim bug
This commit is contained in:
OmniCypher 2015-07-08 13:38:43 -07:00
commit 65bbe5d0a1
11 changed files with 292 additions and 10 deletions

View file

@ -132,12 +132,14 @@ public class AbilityModuleManager {
if (a == StockAbilities.PhaseChange) subabilities.add(a.name());
if (a == StockAbilities.IceSpike) subabilities.add(a.name());
if (a == StockAbilities.IceBlast) subabilities.add(a.name());
if (a == StockAbilities.PlantArmor) subabilities.add(a.name());
if (a == StockAbilities.HealingWaters) healingabilities.add(a.name());
if (a == StockAbilities.Bloodbending) bloodabilities.add(a.name());
if (a == StockAbilities.PhaseChange) iceabilities.add(a.name());
if (a == StockAbilities.IceSpike) iceabilities.add(a.name());
if (a == StockAbilities.IceBlast) iceabilities.add(a.name());
if (a == StockAbilities.PlantArmor) plantabilities.add(a.name());
}
}
else if (StockAbilities.isEarthbending(a)) {

View file

@ -18,14 +18,14 @@ public enum StockAbilities {
AvatarState,
// Project Korra
Extraction, MetalClips, Smokescreen, Combustion, LavaFlow, Suffocate, IceBlast, WarriorStance, AcrobatStance, QuickStrike, SwiftKick, EarthSmash, Flight, WaterArms, SandSpout;
Extraction, MetalClips, Smokescreen, Combustion, LavaFlow, Suffocate, IceBlast, WarriorStance, AcrobatStance, QuickStrike, SwiftKick, EarthSmash, Flight, WaterArms, SandSpout, PlantArmor;
private enum AirbendingAbilities {
AirBlast, AirBubble, AirShield, AirSuction, AirSwipe, Tornado, AirScooter, AirSpout, AirBurst, Suffocate, Flight;
}
private enum WaterbendingAbilities {
WaterBubble, PhaseChange, HealingWaters, WaterManipulation, Surge, Bloodbending, WaterSpout, IceSpike, IceBlast, OctopusForm, Torrent, WaterArms;
WaterBubble, PhaseChange, HealingWaters, WaterManipulation, Surge, Bloodbending, WaterSpout, IceSpike, IceBlast, OctopusForm, Torrent, WaterArms, PlantArmor;
}
@ -93,7 +93,7 @@ public enum StockAbilities {
private enum PlantbendingAbilities
{
;
PlantArmor;
}
private enum MultiAbilities

View file

@ -134,6 +134,7 @@ import com.projectkorra.ProjectKorra.waterbending.IceBlast;
import com.projectkorra.ProjectKorra.waterbending.IceSpike2;
import com.projectkorra.ProjectKorra.waterbending.Melt;
import com.projectkorra.ProjectKorra.waterbending.OctopusForm;
import com.projectkorra.ProjectKorra.waterbending.PlantArmor;
import com.projectkorra.ProjectKorra.waterbending.Torrent;
import com.projectkorra.ProjectKorra.waterbending.WaterArms;
import com.projectkorra.ProjectKorra.waterbending.WaterManipulation;
@ -553,6 +554,9 @@ public class PKListener implements Listener {
if (event.getSlotType() == SlotType.ARMOR
&& !EarthArmor.canRemoveArmor((Player) event.getWhoClicked()))
event.setCancelled(true);
if (event.getSlotType() == SlotType.ARMOR
&& !PlantArmor.canRemoveArmor((Player) event.getWhoClicked()))
event.setCancelled(true);
}
@ -782,6 +786,28 @@ public class PKListener implements Listener {
event.getDrops().addAll(newdrops);
EarthArmor.removeEffect(event.getEntity());
}
if (PlantArmor.instances.containsKey(event.getEntity())) {
List<ItemStack> drops = event.getDrops();
List<ItemStack> newdrops = new ArrayList<ItemStack>();
for (int i = 0; i < drops.size(); i++) {
if (!(drops.get(i).getType() == Material.LEATHER_BOOTS
|| drops.get(i).getType() == Material.LEATHER_CHESTPLATE
|| drops.get(i).getType() == Material.LEAVES
|| drops.get(i).getType() == Material.LEAVES_2
|| drops.get(i).getType() == Material.LEATHER_LEGGINGS || drops
.get(i).getType() == Material.AIR))
newdrops.add((drops.get(i)));
}
if (PlantArmor.instances.get(event.getEntity()).oldarmor != null) {
for (ItemStack is : PlantArmor.instances.get(event.getEntity()).oldarmor) {
if (!(is.getType() == Material.AIR))
newdrops.add(is);
}
}
event.getDrops().clear();
event.getDrops().addAll(newdrops);
PlantArmor.removeEffect(event.getEntity());
}
if (MetalClips.instances.containsKey(event.getEntity())) {
MetalClips.instances.get(event.getEntity()).remove();
List<ItemStack> drops = event.getDrops();
@ -1010,6 +1036,9 @@ public class PKListener implements Listener {
EarthArmor.removeEffect(event.getPlayer());
event.getPlayer().removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
}
if (PlantArmor.instances.containsKey(event.getPlayer())) {
PlantArmor.removeEffect(event.getPlayer());
}
for (Player p : MetalClips.instances.keySet()) {
if (MetalClips.instances.get(p).getTarget() != null &&
@ -1298,6 +1327,9 @@ public class PKListener implements Listener {
if (abil.equalsIgnoreCase("PhaseChange")) {
new FreezeMelt(player);
}
if (abil.equalsIgnoreCase("PlantArmor")) {
new PlantArmor(player);
}
if (abil.equalsIgnoreCase("WaterSpout")) {
new WaterSpout(player);
}

View file

@ -399,6 +399,13 @@ public class ConfigManager {
+ "sea level. ");
config.addDefault("Abilities.Water.PhaseChange.Range", 20);
config.addDefault("Abilities.Water.PhaseChange.Radius", 5);
config.addDefault("Abilities.Water.PlantArmor.Enabled", true);
config.addDefault("Abilities.Water.PlantArmor.Description", "PlantArmor is a defensive ability in the arsenal of the plantbender. Clicking on leaves with this ability will temporarily clad you in strong armor made out of plants! You can use this defensively, but you can also use the armor as a source for other plantbending skills.");
config.addDefault("Abilities.Water.PlantArmor.Duration", 10000);
config.addDefault("Abilities.Water.PlantArmor.Resistance", 1);
config.addDefault("Abilities.Water.PlantArmor.Cooldown", 17500);
config.addDefault("Abilities.Water.PlantArmor.Range", 10);
config.addDefault("Abilities.Water.Surge.Enabled", true);
config.addDefault("Abilities.Water.Surge.Description", "This ability has two distinct features. If you sneak to select a source block, you can then click in a direction and a large wave will be launched in that direction. If you sneak again while the wave is en route, the wave will freeze the next target it hits. If, instead, you click to select a source block, you can hold sneak to form a wall of water at your cursor location. Click to shift between a water wall and an ice wall. Release sneak to dissipate it.");
@ -549,7 +556,7 @@ public class ConfigManager {
config.addDefault("Abilities.Earth.EarthArmor.Description", "This ability encases the earthbender in temporary armor. To use, click on a block that is earthbendable. If there is another block under it that is earthbendable, the block will fly to you and grant you temporary armor and damage reduction. This ability has a long cooldown.");
config.addDefault("Abilities.Earth.EarthArmor.Duration", 10000);
config.addDefault("Abilities.Earth.EarthArmor.Strength", 2);
config.addDefault("Abilities.Earth.EarthArmor.Duration", 17500);
config.addDefault("Abilities.Earth.EarthArmor.Cooldown", 17500);
config.addDefault("Abilities.Earth.EarthBlast.Enabled", true);
config.addDefault("Abilities.Earth.EarthBlast.Description", "To use, place your cursor over an earthbendable object (dirt, rock, ores, etc) "

View file

@ -211,10 +211,8 @@ public class EarthArmor {
if (System.currentTimeMillis() > eartharmor.starttime + duration && !eartharmor.complete) {
eartharmor.complete = true;
eartharmor.removeEffect();
return;
}
if (System.currentTimeMillis() > eartharmor.starttime + cooldown) {
instances.remove(player);
eartharmor.cancel();
GeneralMethods.getBendingPlayer(player.getName()).addCooldown("EarthArmor", cooldown);
return;
}
} else if (System.currentTimeMillis() > eartharmor.time + interval) {

View file

@ -2,7 +2,6 @@ package com.projectkorra.ProjectKorra.waterbending;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;

View file

@ -0,0 +1,212 @@
package com.projectkorra.ProjectKorra.waterbending;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import com.projectkorra.ProjectKorra.BendingPlayer;
import com.projectkorra.ProjectKorra.GeneralMethods;
import com.projectkorra.ProjectKorra.ProjectKorra;
public class PlantArmor {
public static ConcurrentHashMap<Player, PlantArmor> instances = new ConcurrentHashMap<Player, PlantArmor>();
private static long cooldown = ProjectKorra.plugin.getConfig().getLong("Abilities.Water.PlantArmor.Cooldown");
private static long DURATION = ProjectKorra.plugin.getConfig().getLong("Abilities.Water.PlantArmor.Duration");
private static int RESISTANCE = ProjectKorra.plugin.getConfig().getInt("Abilities.Water.PlantArmor.Resistance");
private static int RANGE = ProjectKorra.plugin.getConfig().getInt("Abilities.Water.PlantArmor.Range");//7;
private Player player;
private Block block;
private Location location;
private Plantbending plantbending;
private long starttime;
private boolean formed = false;
private int resistance = RESISTANCE;
public ItemStack[] oldarmor;
public boolean hadEffect;
private double range = RANGE;
private long duration = DURATION;
private Material blocktype;
public PlantArmor(Player player) {
if (instances.containsKey(player)) {
return;
}
BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName());
if (bPlayer.isOnCooldown("PlantArmor")) return;
this.player = player;
range = WaterMethods.getWaterbendingNightAugment(player.getWorld()) * range;
Double d = WaterMethods.getWaterbendingNightAugment(player.getWorld()) * duration;
duration = d.longValue();
block = WaterMethods.getPlantSourceBlock(player, range, true);
if(block == null) {
return;
}
location = block.getLocation();
hadEffect = player.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
if(!canUse()) return;
plantbending = new Plantbending(block);
blocktype = block.getType();
block.setType(Material.AIR);
instances.put(player, this);
}
private boolean canUse() {
if (!player.getWorld().equals(block.getWorld())) {
cancel();
return false;
}
if(location.distance(player.getEyeLocation()) > range) {
cancel();
return false;
}
if(!WaterMethods.canPlantbend(player)) {
cancel();
return false;
}
return true;
}
private void playEffect() {
if(!formed) {
if (GeneralMethods.rand.nextInt(4) == 0) {
WaterMethods.playPlantbendingSound(location);
}
GeneralMethods.displayColoredParticle(location, "009933");
Vector v = player.getEyeLocation().toVector().subtract(location.toVector());
location = location.add(v.normalize());
}
}
private void cancel() {
if(plantbending != null)
plantbending.revert();
if (instances.containsKey(player))
instances.remove(player);
}
private boolean inPosition() {
if(location.distance(player.getEyeLocation()) <= 1.5) return true;
return false;
}
private void formArmor() {
oldarmor = player.getInventory().getArmorContents();
ItemStack helmet = new ItemStack(blocktype);
ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
LeatherArmorMeta im = (LeatherArmorMeta)chestplate.getItemMeta();
im.setColor(Color.GREEN);
chestplate.setItemMeta(im);
ItemStack leggings = new ItemStack(Material.LEATHER_LEGGINGS);
leggings.setItemMeta(im);
ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
boots.setItemMeta(im);
player.getInventory().setHelmet(helmet);
player.getInventory().setChestplate(chestplate);
player.getInventory().setLeggings(leggings);
player.getInventory().setBoots(boots);
if(!hadEffect)
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 1000000, resistance - 1));
formed = true;
starttime = System.currentTimeMillis();
}
public static void progressAll() {
for (Player player : instances.keySet()) {
progress(player);
}
}
public static void progress(Player player) {
if (!instances.containsKey(player))
return;
PlantArmor plantarmor = instances.get(player);
if (player.isDead() || !player.isOnline()) {
plantarmor.removeEffect();
plantarmor.cancel();
return;
}
if (plantarmor.formed) {
if (System.currentTimeMillis() > plantarmor.starttime + plantarmor.duration) {
plantarmor.removeEffect();
plantarmor.cancel();
GeneralMethods.getBendingPlayer(player.getName()).addCooldown("PlantArmor", cooldown);
return;
}
} else {
if (!plantarmor.canUse())
return;
plantarmor.playEffect();
if (plantarmor.inPosition()) {
plantarmor.formArmor();
}
}
}
private void removeEffect() {
player.getInventory().setArmorContents(oldarmor);
if(!hadEffect)
player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
}
public static void removeEffect(Player player) {
if (!instances.containsKey(player))
return;
instances.get(player).removeEffect();
}
public static void removeAll() {
for (Player player : instances.keySet()) {
PlantArmor plantarmor = instances.get(player);
plantarmor.removeEffect();
plantarmor.cancel();
}
}
public static boolean canRemoveArmor(Player player) {
if (instances.containsKey(player)) {
PlantArmor plantarmor = instances.get(player);
if (System.currentTimeMillis() < plantarmor.starttime + plantarmor.duration)
return false;
}
return true;
}
public Player getPlayer() {
return player;
}
public int getResistance() {
return resistance;
}
public void setResistance(int resistance) {
this.resistance = resistance;
if(!hadEffect) {
player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 1000000, resistance - 1));
}
}
}

View file

@ -39,7 +39,7 @@ public class Plantbending {
}
@SuppressWarnings("deprecation")
private void revert() {
public void revert() {
if (block.getType() == Material.AIR) {
block.setType(type);
block.setData(data);

View file

@ -171,6 +171,22 @@ public class WaterMethods {
return null;
}
public static Block getPlantSourceBlock(Player player, double range, boolean onlyLeaves) {
Location location = player.getEyeLocation();
Vector vector = location.getDirection().clone().normalize();
for (double i = 0; i <= range; i++) {
Block block = location.clone().add(vector.clone().multiply(i)).getBlock();
if (GeneralMethods.isRegionProtectedFromBuild(player, "PlantDisc", location))
continue;
if (isPlantbendable(block, onlyLeaves)) {
if (TempBlock.isTempBlock(block))
continue;
return block;
}
}
return null;
}
public static boolean isAdjacentToFrozenBlock(Block block) {
BlockFace[] faces = { BlockFace.DOWN, BlockFace.UP, BlockFace.NORTH,
BlockFace.EAST, BlockFace.WEST, BlockFace.SOUTH };
@ -265,6 +281,13 @@ public class WaterMethods {
return false;
}
public static boolean isPlantbendable(Block block, boolean leavesOnly) {
if (block.getType() == Material.LEAVES) return true;
if (block.getType() == Material.LEAVES_2) return true;
if (isPlant(block) && !leavesOnly) return true;
return false;
}
public static void playFocusWaterEffect(Block block) {
block.getWorld().playEffect(block.getLocation(), Effect.SMOKE, 4, 20);
}
@ -359,6 +382,12 @@ public class WaterMethods {
}
}
public static void playPlantbendingSound(Location loc) {
if (plugin.getConfig().getBoolean("Properties.Water.PlaySound")) {
loc.getWorld().playSound(loc, Sound.STEP_GRASS, 1, 10);
}
}
public static void stopBending() {
FreezeMelt.removeAll();
IceSpike.removeAll();
@ -374,5 +403,6 @@ public class WaterMethods {
WaterCombo.removeAll();
WaterReturn.removeAll();
WaterArms.removeAll();
PlantArmor.removeAll();
}
}

View file

@ -16,6 +16,7 @@ public class WaterbendingManager implements Runnable {
public void run() {
WaterPassive.handlePassive();
Plantbending.regrow();
PlantArmor.progressAll();
Bloodbending.progressAll();
WaterSpout.handleSpouts(Bukkit.getServer());
FreezeMelt.handleFrozenBlocks();

View file

@ -94,6 +94,7 @@ permissions:
bending.ability.WaterSpout: true
bending.ability.WaterSpout.Wave: true
bending.ability.WaterCombo: true
bending.ability.PlantArmor: true
bending.water.plantbending: true
bending.message.nightmessage: true
bending.water.passive: true