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();
long getMillisPassed();
long getLastPowerUpdateTime();
void updatePower();
void losePowerFromBeingOffline();

View File

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

View File

@ -1,7 +1,10 @@
package com.massivecraft.factions.event;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.zcore.persist.MemoryFPlayer;
import com.massivecraft.factions.zcore.persist.MemoryFPlayers;
import org.bukkit.event.Cancellable;
/**
@ -15,6 +18,14 @@ public class PowerRegenEvent extends FactionPlayerEvent implements Cancellable {
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
public boolean isCancelled() {
return cancelled;

View File

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