Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Fix double jumps with 0 recharge not being instant
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablete1234 committed Jun 2, 2016
1 parent 9d764e9 commit 0e0de0c
Showing 1 changed file with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,43 @@ public class DoubleJumpKit implements KitRemovable {

private boolean enabled;
private int power;
private float rechargePerTick;
private double rechargeTime;
private boolean rechargeBeforeLanding;
private long lastUpdate = 0L;

List<UUID> players = new ArrayList<>();
List<UUID> landed = new ArrayList<>();

public DoubleJumpKit(boolean enabled, int power, double rechargeTime, final boolean rechargeBeforeLanding) {
this.enabled = enabled;
this.power = power;
this.rechargePerTick = (float)(0.1D / rechargeTime);
this.rechargeTime = rechargeTime;
this.rechargeBeforeLanding = rechargeBeforeLanding;

Bukkit.getScheduler().runTaskTimer(Cardinal.getInstance(), new Runnable() {
public void run() {
for(UUID uuid : players) {
Player player = Bukkit.getPlayer(uuid);
if(player.getExp() < 1.0f && (rechargeBeforeLanding || landed.contains(uuid))) {
player.setExp(player.getExp() + rechargePerTick);
} else if(player.getExp() > 1.0f) {
player.setExp(1.0f);
}
if(player.getExp() >= 1.0f) {
player.setAllowFlight(true);
}
}
DoubleJumpKit.this.update();
}
}, 0, 2);
}

private void update() {
int diff = (int) (System.currentTimeMillis() - lastUpdate);
lastUpdate = System.currentTimeMillis();
float toAddExp = rechargeTime > 0 ? (float) (diff / (rechargeTime * 1000)) : 1.0f;
for(UUID uuid : players) {
Player player = Bukkit.getPlayer(uuid);
if(player.getExp() < 1.0f && (rechargeBeforeLanding || landed.contains(uuid))) {
player.setExp(player.getExp() + toAddExp > 1.0f ? 1.0f : player.getExp() + toAddExp);
} else if(player.getExp() > 1.0f) {
player.setExp(1.0f);
}
if(player.getExp() >= 1.0f) {
player.setAllowFlight(true);
}
}
}

@Override
public void unload() {
HandlerList.unregisterAll(this);
Expand Down Expand Up @@ -113,6 +121,8 @@ public void onPlayerToggleFly(PlayerToggleFlightEvent event) {
event.getPlayer().setVelocity(normal);

player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ZOMBIE_INFECT, 0.5f, 1.8f);

update();
}

}

0 comments on commit 0e0de0c

Please sign in to comment.