Better events! Will be making them even better tmr (:

This commit is contained in:
DroppingAnvil 2019-11-01 04:52:42 -05:00
parent bbed3f0bb0
commit 5556458c93
4 changed files with 30 additions and 1 deletions

View File

@ -281,6 +281,10 @@ public interface FPlayer extends EconomyParticipator {
int getPowerMinRounded(); int getPowerMinRounded();
long getMillisPassed();
long getLastPowerUpdateTime();
void updatePower(); void updatePower();
void losePowerFromBeingOffline(); void losePowerFromBeingOffline();

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -68,6 +69,12 @@ public class PowerLossEvent extends FactionPlayerEvent implements Cancellable {
this.message = message; this.message = message;
} }
/**
* Gets the damage to a players individual power
* @return power lost as a Double.
*/
public Double getPowerLost() {return Conf.powerPerDeath;}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;

View File

@ -1,7 +1,10 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.zcore.persist.MemoryFPlayer;
import com.massivecraft.factions.zcore.persist.MemoryFPlayers;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
/** /**
@ -15,6 +18,14 @@ public class PowerRegenEvent extends FactionPlayerEvent implements Cancellable {
super(f, p); super(f, p);
} }
/**
* Get the amount of power this player will regen
* @return power amount gained as a Double.
*/
public Double getPowerGained() {
return fPlayer.getMillisPassed() * Conf.powerPerMinute / 60000;
}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;

View File

@ -49,6 +49,7 @@ public abstract class MemoryFPlayer implements FPlayer {
protected double power; protected double power;
protected double powerBoost; protected double powerBoost;
protected long lastPowerUpdateTime; protected long lastPowerUpdateTime;
protected long millisPassed;
protected long lastLoginTime; protected long lastLoginTime;
protected ChatMode chatMode; protected ChatMode chatMode;
protected boolean ignoreAllianceChat = false; protected boolean ignoreAllianceChat = false;
@ -599,6 +600,12 @@ public abstract class MemoryFPlayer implements FPlayer {
public int getPowerMinRounded() { public int getPowerMinRounded() {
return (int) Math.round(this.getPowerMin()); return (int) Math.round(this.getPowerMin());
} }
public long getMillisPassed() {
return this.millisPassed;
}
public long getLastPowerUpdateTime() {
return this.millisPassed;
}
public void updatePower() { public void updatePower() {
if (this.isOffline()) { if (this.isOffline()) {
@ -611,7 +618,7 @@ public abstract class MemoryFPlayer implements FPlayer {
} }
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long millisPassed = now - this.lastPowerUpdateTime; this.millisPassed = now - this.lastPowerUpdateTime;
this.lastPowerUpdateTime = now; this.lastPowerUpdateTime = now;
Player thisPlayer = this.getPlayer(); Player thisPlayer = this.getPlayer();