cannonplugin: Combine nested if statements

This commit is contained in:
sdburns1998
2019-07-07 02:31:46 +02:00
parent 6c04132d74
commit aceaf81060

View File

@@ -229,16 +229,14 @@ public class CannonPlugin extends Plugin
GameObject gameObject = event.getGameObject(); GameObject gameObject = event.getGameObject();
Player localPlayer = client.getLocalPlayer(); Player localPlayer = client.getLocalPlayer();
if (gameObject.getId() == CANNON_BASE && !cannonPlaced) if (gameObject.getId() == CANNON_BASE && !cannonPlaced &&
{ localPlayer.getWorldLocation().distanceTo(gameObject.getWorldLocation()) <= 2 &&
if (localPlayer.getWorldLocation().distanceTo(gameObject.getWorldLocation()) <= 2 localPlayer.getAnimation() == AnimationID.BURYING_BONES)
&& localPlayer.getAnimation() == AnimationID.BURYING_BONES)
{ {
cannonPosition = gameObject.getWorldLocation(); cannonPosition = gameObject.getWorldLocation();
cannon = gameObject; cannon = gameObject;
} }
} }
}
@Subscribe @Subscribe
public void onProjectileMoved(ProjectileMoved event) public void onProjectileMoved(ProjectileMoved event)
@@ -250,20 +248,18 @@ public class CannonPlugin extends Plugin
WorldPoint projectileLoc = WorldPoint.fromLocal(client, projectile.getX1(), projectile.getY1(), client.getPlane()); WorldPoint projectileLoc = WorldPoint.fromLocal(client, projectile.getX1(), projectile.getY1(), client.getPlane());
//Check to see if projectile x,y is 0 else it will continuously decrease while ball is flying. //Check to see if projectile x,y is 0 else it will continuously decrease while ball is flying.
if (projectileLoc.equals(cannonPosition) && projectile.getX() == 0 && projectile.getY() == 0) if (projectileLoc.equals(cannonPosition) && projectile.getX() == 0 && projectile.getY() == 0 &&
{
// When there's a chat message about cannon reloaded/unloaded/out of ammo, // When there's a chat message about cannon reloaded/unloaded/out of ammo,
// the message event runs before the projectile event. However they run // the message event runs before the projectile event. However they run
// in the opposite order on the server. So if both fires in the same tick, // in the opposite order on the server. So if both fires in the same tick,
// we don't want to update the cannonball counter if it was set to a specific // we don't want to update the cannonball counter if it was set to a specific
// amount. // amount.
if (!skipProjectileCheckThisTick) !skipProjectileCheckThisTick)
{ {
cballsLeft--; cballsLeft--;
} }
} }
} }
}
@Subscribe @Subscribe
public void onChatMessage(ChatMessage event) public void onChatMessage(ChatMessage event)
@@ -366,14 +362,11 @@ public class CannonPlugin extends Plugin
{ {
return Color.orange; return Color.orange;
} }
else if (cballsLeft <= this.ammoAmount) else if (cballsLeft <= this.ammoAmount && this.notifyAmmoLeft && !lock)
{
if (this.notifyAmmoLeft && !lock)
{ {
notifier.notify("Your cannon has " + this.ammoAmount + " balls left!"); notifier.notify("Your cannon has " + this.ammoAmount + " balls left!");
lock = true; lock = true;
} }
}
return Color.red; return Color.red;
} }