Completed Recode and added getters and setters.

This commit is contained in:
jedk1 2015-05-31 21:22:12 +01:00
parent 706ee1cd8c
commit 50e83f6e35

View file

@ -11,9 +11,6 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.projectkorra.ProjectKorra.GeneralMethods;
@ -39,9 +36,9 @@ public class WaterArms{
public static ConcurrentHashMap<Player, WaterArms> instances = new ConcurrentHashMap<Player, WaterArms>();
public static ConcurrentHashMap<Block, Long> revert = new ConcurrentHashMap<Block, Long>();
public static ConcurrentHashMap<FallingBlock, Player> falling = new ConcurrentHashMap<FallingBlock, Player>();
private static Integer[] unbreakable = {7, 8, 9, 10, 11, 49, 54, 90, 119, 120, 130, 146};
private static Integer[] unbreakable = { 7, 8, 9, 10, 11, 49, 54, 90, 119,
120, 130, 146 };
private Player player;
private World world;
@ -57,20 +54,30 @@ public class WaterArms{
private int lengthReduction = 0;
private int initLength = config.getInt("Abilities.Water.WaterArms.Arms.InitialLength");
private int sourceGrabRange = config.getInt("Abilities.Water.WaterArms.Arms.SourceGrabRange");
private int maxPunches = config.getInt("Abilities.Water.WaterArms.Arms.MaxAttacks");
private int maxIceBlasts = config.getInt("Abilities.Water.WaterArms.Arms.MaxIceShots");
private int maxUses = config.getInt("Abilities.Water.WaterArms.Arms.MaxAlternateUsage");
private long cooldown = config.getLong("Abilities.Water.WaterArms.Arms.cooldown");
private boolean canUsePlantSource = config.getBoolean("Abilities.Water.WaterArms.Arms.AllowPlantSource");
private int initLength = config
.getInt("Abilities.Water.WaterArms.Arms.InitialLength");
private int sourceGrabRange = config
.getInt("Abilities.Water.WaterArms.Arms.SourceGrabRange");
private int maxPunches = config
.getInt("Abilities.Water.WaterArms.Arms.MaxAttacks");
private int maxIceBlasts = config
.getInt("Abilities.Water.WaterArms.Arms.MaxIceShots");
private int maxUses = config
.getInt("Abilities.Water.WaterArms.Arms.MaxAlternateUsage");
private long cooldown = config
.getLong("Abilities.Water.WaterArms.Arms.Cooldown");
private boolean canUsePlantSource = config
.getBoolean("Abilities.Water.WaterArms.Arms.AllowPlantSource");
private boolean lightningEnabled = config.getBoolean("Abilities.Water.WaterArms.Arms.Lightning.Enabled");
private double lightningDamage = config.getDouble("Abilities.Water.WaterArms.Arms.Lightning.Damage");
private boolean lightningKill = config.getBoolean("Abilities.Water.WaterArms.Arms.Lightning.KillUser");
private boolean lightningEnabled = config
.getBoolean("Abilities.Water.WaterArms.Arms.Lightning.Enabled");
private double lightningDamage = config
.getDouble("Abilities.Water.WaterArms.Arms.Lightning.Damage");
private boolean lightningKill = config
.getBoolean("Abilities.Water.WaterArms.Arms.Lightning.KillUser");
private static double blockDamage = config.getDouble("Abilities.Water.WaterArms.WhipMode.Pull.BlockDamage");
private static boolean pullBlocksDamageUser = config.getBoolean("Abilities.Water.WaterArms.WhipMode.Pull.BlockDamageUser");
private static String sneakMsg = config
.getString("Abilities.Water.WaterArms.SneakMessage");
private int selectedSlot = 0;
private int freezeSlot = 4;
@ -84,22 +91,41 @@ public class WaterArms{
} else {
switch (player.getInventory().getHeldItemSlot()) {
case 0:
if (player.hasPermission("bending.ability.WaterArms.Pull")) {
new WaterArmsWhip(player, Whip.Pull);
}
break;
case 1:
if (player.hasPermission("bending.ability.WaterArms.Punch")) {
new WaterArmsWhip(player, Whip.Punch);
}
break;
case 2:
if (player
.hasPermission("bending.ability.WaterArms.Grapple")) {
new WaterArmsWhip(player, Whip.Grapple);
}
break;
case 3:
if (player.hasPermission("bending.ability.WaterArms.Grab")) {
new WaterArmsWhip(player, Whip.Grab);
}
break;
case 4:
//new WaterArmsIce(player);
if (player
.hasPermission("bending.ability.WaterArms.Freeze")
&& WaterMethods.canIcebend(player)) {
new WaterArmsFreeze(player);
}
break;
case 5:
//new WaterArmsSpear(player);
if (player.hasPermission("bending.ability.WaterArms.Spear")) {
if (WaterMethods.canIcebend(player)) {
new WaterArmsSpear(player, true);
} else {
new WaterArmsSpear(player, false);
}
}
break;
default:
break;
@ -116,6 +142,8 @@ public class WaterArms{
remove();
return;
}
player.sendMessage(WaterMethods.getWaterColor() + sneakMsg + " "
+ GeneralMethods.getBoundAbility(player));
}
}
@ -124,22 +152,30 @@ public class WaterArms{
return false;
if (!GeneralMethods.canBend(player.getName(), "WaterArms"))
return false;
if(GeneralMethods.isRegionProtectedFromBuild(player, "WaterArms", player.getLocation()))
if (GeneralMethods.isRegionProtectedFromBuild(player, "WaterArms",
player.getLocation()))
return false;
if(GeneralMethods.getBendingPlayer(player.getName()).isOnCooldown("WaterArms"))
if (GeneralMethods.getBendingPlayer(player.getName()).isOnCooldown(
"WaterArms"))
return false;
if(GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterArms"))
if (GeneralMethods.getBoundAbility(player)
.equalsIgnoreCase("WaterArms"))
return true;
return false;
}
private boolean prepare() {
Block sourceblock = WaterMethods.getWaterSourceBlock(player, sourceGrabRange, canUsePlantSource);
Block sourceblock = WaterMethods.getWaterSourceBlock(player,
sourceGrabRange, canUsePlantSource);
if (sourceblock != null) {
if (WaterMethods.isPlant(sourceblock)) {
fullSource = false;
}
ParticleEffect.LARGE_SMOKE.display(WaterMethods.getWaterSourceBlock(player, sourceGrabRange, canUsePlantSource).getLocation().clone().add(0.5,0.5,0.5), 0, 0, 0, 0F, 4);
ParticleEffect.LARGE_SMOKE.display(
WaterMethods
.getWaterSourceBlock(player, sourceGrabRange,
canUsePlantSource).getLocation().clone()
.add(0.5, 0.5, 0.5), 0, 0, 0, 0F, 4);
return true;
} else if (WaterReturn.hasWaterBottle(player)) {
WaterReturn.emptyWaterBottle(player);
@ -165,7 +201,8 @@ public class WaterArms{
remove();
return;
}
if(maxPunches == 0 || maxUses == 0 || maxIceBlasts == 0 || (leftArmConsumed && rightArmConsumed)){
if (maxPunches == 0 || maxUses == 0 || maxIceBlasts == 0
|| (leftArmConsumed && rightArmConsumed)) {
remove();
return;
}
@ -179,30 +216,36 @@ public class WaterArms{
}
private boolean canPlaceBlock(Block block) {
if(!EarthMethods.isTransparentToEarthbending(player, block) && !(WaterMethods.isWater(block) && TempBlock.isTempBlock(block)))
if (!EarthMethods.isTransparentToEarthbending(player, block)
&& !(WaterMethods.isWater(block) && TempBlock
.isTempBlock(block)))
return false;
return true;
}
/**
* Displays the right arm.
* Returns false if the arm cannot be fully displayed.
* Displays the right arm. Returns false if the arm cannot be fully
* displayed.
*
* @return
*/
public boolean displayRightArm() {
if (rightArmConsumed)
return false;
Location r1 = GeneralMethods.getRightSide(player.getLocation(), 1).add(0, 1.5, 0);
Location r1 = GeneralMethods.getRightSide(player.getLocation(), 1).add(
0, 1.5, 0);
if (!canPlaceBlock(r1.getBlock()))
return false;
if(!(getRightHandPos().getBlock().getLocation().equals(r1.getBlock().getLocation()))){
if (!(getRightHandPos().getBlock().getLocation().equals(r1.getBlock()
.getLocation()))) {
new TempBlock(r1.getBlock(), Material.STATIONARY_WATER, (byte) 5);
revert.put(r1.getBlock(), 0L);
}
Location r2 = GeneralMethods.getRightSide(player.getLocation(), 2).add(0, 1.5, 0);
Location r2 = GeneralMethods.getRightSide(player.getLocation(), 2).add(
0, 1.5, 0);
if (!canPlaceBlock(r2.getBlock()))
return false;
@ -210,18 +253,25 @@ public class WaterArms{
revert.put(r2.getBlock(), 0L);
for (int j = 0; j <= initLength; j++) {
Location r3 = r2.clone().toVector().add(player.getLocation().clone().getDirection().multiply(j)).toLocation(player.getWorld());
Location r3 = r2
.clone()
.toVector()
.add(player.getLocation().clone().getDirection()
.multiply(j)).toLocation(player.getWorld());
if (!canPlaceBlock(r3.getBlock())) {
if(selectedSlot == freezeSlot && r3.getBlock().getType().equals(Material.ICE))
if (selectedSlot == freezeSlot
&& r3.getBlock().getType().equals(Material.ICE))
continue;
return false;
}
if(j >= 1 && selectedSlot == freezeSlot){
if (j >= 1 && selectedSlot == freezeSlot
&& WaterMethods.canIcebend(player)) {
new TempBlock(r3.getBlock(), Material.ICE, (byte) 0);
revert.put(r3.getBlock(), 0L);
} else {
new TempBlock(r3.getBlock(), Material.STATIONARY_WATER, (byte) 0);
new TempBlock(r3.getBlock(), Material.STATIONARY_WATER,
(byte) 0);
revert.put(r3.getBlock(), 0L);
}
}
@ -230,24 +280,28 @@ public class WaterArms{
}
/**
* Displays the left arm.
* Returns false if the arm cannot be fully displayed.
* Displays the left arm. Returns false if the arm cannot be fully
* displayed.
*
* @return
*/
public boolean displayLeftArm() {
if (leftArmConsumed)
return false;
Location l1 = GeneralMethods.getLeftSide(player.getLocation(), 1).add(0, 1.5, 0);
Location l1 = GeneralMethods.getLeftSide(player.getLocation(), 1).add(
0, 1.5, 0);
if (!canPlaceBlock(l1.getBlock()))
return false;
if(!(getLeftHandPos().getBlock().getLocation().equals(l1.getBlock().getLocation()))){
if (!(getLeftHandPos().getBlock().getLocation().equals(l1.getBlock()
.getLocation()))) {
new TempBlock(l1.getBlock(), Material.STATIONARY_WATER, (byte) 5);
revert.put(l1.getBlock(), 0L);
}
Location l2 = GeneralMethods.getLeftSide(player.getLocation(), 2).add(0, 1.5, 0);
Location l2 = GeneralMethods.getLeftSide(player.getLocation(), 2).add(
0, 1.5, 0);
if (!canPlaceBlock(l2.getBlock()))
return false;
@ -255,18 +309,25 @@ public class WaterArms{
revert.put(l2.getBlock(), 0L);
for (int j = 0; j <= initLength; j++) {
Location l3 = l2.clone().toVector().add(player.getLocation().clone().getDirection().multiply(j)).toLocation(player.getWorld());
Location l3 = l2
.clone()
.toVector()
.add(player.getLocation().clone().getDirection()
.multiply(j)).toLocation(player.getWorld());
if (!canPlaceBlock(l3.getBlock())) {
if(selectedSlot == freezeSlot && l3.getBlock().getType().equals(Material.ICE))
if (selectedSlot == freezeSlot
&& l3.getBlock().getType().equals(Material.ICE))
continue;
return false;
}
if(j >= 1 && selectedSlot == freezeSlot){
if (j >= 1 && selectedSlot == freezeSlot
&& WaterMethods.canIcebend(player)) {
new TempBlock(l3.getBlock(), Material.ICE, (byte) 0);
revert.put(l3.getBlock(), 0L);
} else {
new TempBlock(l3.getBlock(), Material.STATIONARY_WATER, (byte) 0);
new TempBlock(l3.getBlock(), Material.STATIONARY_WATER,
(byte) 0);
revert.put(l3.getBlock(), 0L);
}
}
@ -276,38 +337,50 @@ public class WaterArms{
/**
* Calculate roughly where the player's right hand is.
*
* @return
*/
private Location getRightHandPos() {
return GeneralMethods.getRightSide(player.getLocation(), .34).add(0, 1.5, 0);
return GeneralMethods.getRightSide(player.getLocation(), .34).add(0,
1.5, 0);
}
/**
* Calculate roughly where the player's left hand is.
*
* @return
*/
private Location getLeftHandPos() {
return GeneralMethods.getLeftSide(player.getLocation(), .34).add(0, 1.5, 0);
return GeneralMethods.getLeftSide(player.getLocation(), .34).add(0,
1.5, 0);
}
/**
* Returns the location of the tip of the right arm, assuming it is fully extended.
* Use the displayRightArm() check to see if it is fully extended.
* Returns the location of the tip of the right arm, assuming it is fully
* extended. Use the displayRightArm() check to see if it is fully extended.
*
* @return
*/
public Location getRightArmEnd() {
Location r1 = GeneralMethods.getRightSide(player.getLocation(), 2).add(0, 1.5, 0);
return r1.clone().add(player.getLocation().getDirection().normalize().multiply(initLength));
Location r1 = GeneralMethods.getRightSide(player.getLocation(), 2).add(
0, 1.5, 0);
return r1.clone().add(
player.getLocation().getDirection().normalize()
.multiply(initLength));
}
/**
* Returns the location of the tip of the left arm assuming it is fully extended.
* Use the displayLeftArm() check to see if it is fully extended.
* Returns the location of the tip of the left arm assuming it is fully
* extended. Use the displayLeftArm() check to see if it is fully extended.
*
* @return
*/
public Location getLeftArmEnd() {
Location l1 = GeneralMethods.getLeftSide(player.getLocation(), 2).add(0, 1.5, 0);
return l1.clone().add(player.getLocation().getDirection().normalize().multiply(initLength));
Location l1 = GeneralMethods.getLeftSide(player.getLocation(), 2).add(
0, 1.5, 0);
return l1.clone().add(
player.getLocation().getDirection().normalize()
.multiply(initLength));
}
private static void progressRevert(boolean ignoreTime) {
@ -321,40 +394,24 @@ public class WaterArms{
}
}
private static void trackEntities(boolean remove){
for(FallingBlock fallingBlock : falling.keySet()){
if(remove){
fallingBlock.remove();
falling.remove(fallingBlock);
}
if(!fallingBlock.isDead()){
for(Entity entity : GeneralMethods.getEntitiesAroundPoint(fallingBlock.getLocation(), 2.0)){
if(entity instanceof LivingEntity){
if(!pullBlocksDamageUser && entity.getEntityId() == falling.get(fallingBlock).getEntityId())
continue;
GeneralMethods.damageEntity(falling.get(fallingBlock), entity, blockDamage);
fallingBlock.remove();
falling.remove(fallingBlock);
}
}
}
}
}
private void checkIfZapped() {
for (int i = 0; i < Lightning.instances.size(); i++) {
Lightning l = Lightning.instances.get(i);
for (Lightning.Arc arc : l.getArcs()) {
for (Block arm : revert.keySet()) {
for (Location loc : arc.getPoints()) {
if(arm.getLocation().getWorld() == loc.getWorld() && loc.distance(arm.getLocation()) <= 2.5){
for(Location l1 : getOffsetLocations(4, arm.getLocation(), 1.25))
if (arm.getLocation().getWorld() == loc.getWorld()
&& loc.distance(arm.getLocation()) <= 2.5) {
for (Location l1 : getOffsetLocations(4,
arm.getLocation(), 1.25))
FireMethods.playLightningbendingParticle(l1);
if (lightningKill)
GeneralMethods.damageEntity(Lightning.instances.get(i).getPlayer(), player, 60D);
GeneralMethods.damageEntity(Lightning.instances
.get(i).getPlayer(), player, 60D);
else
GeneralMethods.damageEntity(Lightning.instances.get(i).getPlayer(), player, lightningDamage);
GeneralMethods.damageEntity(Lightning.instances
.get(i).getPlayer(), player,
lightningDamage);
}
}
}
@ -362,10 +419,14 @@ public class WaterArms{
}
}
private static List<Location> getOffsetLocations(int amount, Location location, double offset){
private static List<Location> getOffsetLocations(int amount,
Location location, double offset) {
List<Location> locations = new ArrayList<Location>();
for (int i = 0; i < amount; i++)
locations.add(location.clone().add((float) (Math.random()*offset), (float) (Math.random()*offset), (float) (Math.random()*offset)));
locations.add(location.clone().add(
(float) (Math.random() * offset),
(float) (Math.random() * offset),
(float) (Math.random() * offset)));
return locations;
}
@ -377,7 +438,8 @@ public class WaterArms{
public void remove() {
MultiAbilityManager.unbindMultiAbility(player);
if (player.isOnline())
GeneralMethods.getBendingPlayer(player.getName()).addCooldown("WaterArms", cooldown);
GeneralMethods.getBendingPlayer(player.getName()).addCooldown(
"WaterArms", cooldown);
instances.remove(player);
}
@ -391,30 +453,42 @@ public class WaterArms{
public static void progressAll() {
progressRevert(false);
trackEntities(false);
for (Player p : instances.keySet())
instances.get(p).progress();
WaterArmsWhip.progressAll();
WaterArmsFreeze.progressAll();
WaterArmsSpear.progressAll();
}
public static void removeAll() {
progressRevert(true);
trackEntities(true);
revert.clear();
falling.clear();
instances.clear();
WaterArmsWhip.removeAll();
WaterArmsFreeze.removeAll();
WaterArmsSpear.removeAll();
}
@SuppressWarnings("deprecation")
public static boolean isUnbreakable(Block block) {
if (Arrays.asList(unbreakable).contains(block.getTypeId())) return true;
if (Arrays.asList(unbreakable).contains(block.getTypeId()))
return true;
return false;
}
public static void displayBoundMsg(Player player){
player.sendMessage(WaterMethods.getWaterColor() + sneakMsg + " "
+ GeneralMethods.getBoundAbility(player));
}
public void displayBoundMsg(){
player.sendMessage(WaterMethods.getWaterColor() + sneakMsg + " "
+ GeneralMethods.getBoundAbility(player));
}
/**
* Returns the active arm of the player.
*
* @return
*/
public Arm getActiveArm() {
@ -433,6 +507,7 @@ public class WaterArms{
/**
* Switches to the most suitable arm for the player.
*
* @return
*/
public Arm switchPreferredArm() {
@ -450,7 +525,7 @@ public class WaterArms{
return getActiveArm();
}
public boolean canDisplayCurrentArm(){
public boolean canDisplayActiveArm() {
switch (activeArm) {
case Left:
return displayLeftArm();
@ -461,6 +536,24 @@ public class WaterArms{
}
}
public Location getActiveArmEnd() {
switch (activeArm) {
case Left:
return getLeftArmEnd();
case Right:
return getRightArmEnd();
default:
return null;
}
}
public static boolean hasPlayer(Player player) {
if (instances.containsKey(player)) {
return true;
}
return false;
}
public Player getPlayer() {
return player;
}
@ -469,6 +562,22 @@ public class WaterArms{
return fullSource;
}
public boolean getLeftArmConsumed() {
return leftArmConsumed;
}
public void setLeftArmConsumed(boolean consumed) {
this.leftArmConsumed = consumed;
}
public boolean getRightArmConsumed() {
return rightArmConsumed;
}
public void setRightArmConsumed(boolean consumed) {
this.rightArmConsumed = consumed;
}
public Integer getLengthReduction() {
return lengthReduction;
}