LavaFlow: Moved everything to instance variables, and cleaned up

Lightning: Code cleanup
This commit is contained in:
nathank33 2015-02-01 11:16:18 -08:00
parent 82614d0ea3
commit 326d37f28a

View file

@ -195,7 +195,12 @@ public class Lightning {
} }
} }
/** Checks if a block is transparent, also considers the ARC_ON_ICE config option **/ /**
* Checks if a block is transparent, also considers the ARC_ON_ICE config option.
* @param player the player that is viewing the block
* @param block the block
* @return true if the block is transparent
*/
public boolean isTransparent(Player player, Block block) { public boolean isTransparent(Player player, Block block) {
if (Arrays.asList(Methods.transparentToEarthbending).contains(block.getTypeId())) { if (Arrays.asList(Methods.transparentToEarthbending).contains(block.getTypeId())) {
if(Methods.isRegionProtectedFromBuild(player, "Lightning", block.getLocation())) if(Methods.isRegionProtectedFromBuild(player, "Lightning", block.getLocation()))
@ -241,7 +246,9 @@ public class Lightning {
} }
} }
/** Removes the instance of this ability and cancels any current runnables **/ /**
* Removes the instance of this ability and cancels any current runnables
*/
public void removeWithTasks() { public void removeWithTasks() {
for(int i = 0; i < tasks.size(); i++) { for(int i = 0; i < tasks.size(); i++) {
tasks.get(i).cancel(); tasks.get(i).cancel();
@ -250,11 +257,15 @@ public class Lightning {
remove(); remove();
} }
/** Removes this ability instance **/ public void remove() { /**
* Removes this ability instance
*/ public void remove() {
instances.remove(this); instances.remove(this);
} }
/** Removes every instance of this ability **/ /**
* Removes every instance of this ability
*/
public static void removeAll() { public static void removeAll() {
for (int i = 0; i < instances.size(); i++) { for (int i = 0; i < instances.size(); i++) {
instances.get(i).remove(); instances.get(i).remove();
@ -262,13 +273,19 @@ public class Lightning {
} }
} }
/** Progresses every instance of this ability by 1 tick **/ /**
* Progresses every instance of this ability by 1 tick
*/
public static void progressAll() { public static void progressAll() {
for (int i = 0; i < instances.size(); i++) for (int i = 0; i < instances.size(); i++)
instances.get(i).progress(); instances.get(i).progress();
} }
/** Returns an instance of this ability if it was initialized by player **/ /**
* Returns an instance of this ability if it was initialized by player
* @param player that created the instance
* @return the ability
*/
public static Lightning getLightning(Player player) { public static Lightning getLightning(Player player) {
for(Lightning light : instances) { for(Lightning light : instances) {
if(light.player == player) if(light.player == player)
@ -277,28 +294,35 @@ public class Lightning {
return null; return null;
} }
/** Checks if a location contains an ice block **/ /**
* Checks if a location contains an ice block
* @param loc the location to check
* @return true if it is ice
*/
public static boolean isIce(Location loc) { public static boolean isIce(Location loc) {
Material mat = loc.getBlock().getType(); Material mat = loc.getBlock().getType();
return mat == Material.ICE || mat == Material.PACKED_ICE; return mat == Material.ICE || mat == Material.PACKED_ICE;
} }
/** Checks if a location contains a water block **/ /**
* Checks if a location contains a water block
* @param loc the location to check
* @return true if it is water
*/
public static boolean isWater(Location loc) { public static boolean isWater(Location loc) {
Material mat = loc.getBlock().getType(); Material mat = loc.getBlock().getType();
return mat == Material.WATER || mat == Material.STATIONARY_WATER; return mat == Material.WATER || mat == Material.STATIONARY_WATER;
} }
/** Checks if a location is ice or water **/ /**
* Checks if a location is ice or water
* @param loc the location to check
* @return true if it is water or ice
*/
public static boolean isWaterOrIce(Location loc) { public static boolean isWaterOrIce(Location loc) {
return isIce(loc) || isWater(loc); return isIce(loc) || isWater(loc);
} }
public static String getDescription() {
return "Hold sneak while selecting this ability to charge up a lightning strike. Once "
+ "charged, release sneak to discharge the lightning to the targetted location.";
}
/** An Arc represents a Lightning arc for the specific ability. /** An Arc represents a Lightning arc for the specific ability.
* These Arcs contain a list of Particles that are used to display * These Arcs contain a list of Particles that are used to display
* the entire arc. Arcs can also generate a list of subarcs that * the entire arc. Arcs can also generate a list of subarcs that
@ -380,7 +404,9 @@ public class Lightning {
return arcs; return arcs;
} }
/** Stops this Arc from further animating or doing damage. **/ /**
* Stops this Arc from further animating or doing damage.
*/
public void cancel() { public void cancel() {
for(int i = 0; i < particles.size(); i++) { for(int i = 0; i < particles.size(); i++) {
particles.get(i).cancel(); particles.get(i).cancel();
@ -391,12 +417,10 @@ public class Lightning {
} }
} }
/** Gets every point that makes up this arc. **/
public ArrayList<Location> getPoints() { public ArrayList<Location> getPoints() {
return points; return points;
} }
/** Below are accessor and mutators**/
public void setPoints(ArrayList<Location> points) { public void setPoints(ArrayList<Location> points) {
this.points = points; this.points = points;
} }
@ -437,7 +461,8 @@ public class Lightning {
/** Represents a Lightning Arc Point particle animation. /** Represents a Lightning Arc Point particle animation.
* This basically just holds a location and counts the * This basically just holds a location and counts the
* amount of times that a particle has been animated. **/ * amount of times that a particle has been animated.
* **/
public class AnimLocation { public class AnimLocation {
private Location loc; private Location loc;
private int animCounter; private int animCounter;
@ -470,7 +495,8 @@ public class Lightning {
* These LightningParticles do the actual checking for player collision * These LightningParticles do the actual checking for player collision
* and handle damaging any entities. These Runnables also * and handle damaging any entities. These Runnables also
* check to see if they reach water, in which case they will generate * check to see if they reach water, in which case they will generate
* subarcs to branch out.**/ * subarcs to branch out.
* **/
public class LightningParticle extends BukkitRunnable { public class LightningParticle extends BukkitRunnable {
private Arc arc; private Arc arc;
private Location loc; private Location loc;