Much needed additions to events.

This commit is contained in:
DroppingAnvil 2019-11-01 13:15:18 -05:00
parent d379f22d46
commit dd02853934
4 changed files with 59 additions and 6 deletions

View File

@ -13,6 +13,7 @@ public class PowerLossEvent extends FactionPlayerEvent implements Cancellable {
private boolean cancelled = false; private boolean cancelled = false;
private String message; private String message;
private double modified = 0;
public PowerLossEvent(Faction f, FPlayer p) { public PowerLossEvent(Faction f, FPlayer p) {
super(f, p); super(f, p);
@ -70,11 +71,33 @@ public class PowerLossEvent extends FactionPlayerEvent implements Cancellable {
} }
/** /**
* Gets the damage to a players individual power * Gets the configured damage to a players individual power on death
* @return power lost as a Double. * @return power to be lost as a Double.
*/ */
public Double getPowerLost() {return Conf.powerPerDeath;} public Double getDefaultPowerLost() {return Conf.powerPerDeath;}
/**
* Gets the variable power lost. Custom power ignored when less than or equal to zero.
* @return custom power to be lost as a Double.
*/
public Double getCustomPowerLost() {return this.modified;}
/**
* Sets the variable power lost. Custom power ignored when less than or equal to zero.
* @param loss Double amount for the custom power loss to be set to.
*/
public void setCustomPowerLost(Double loss) {modified = loss;}
/**
* Determines if custom power is to be used.
* @return If custom power is to be used as a boolean.
*/
public boolean usingCustomPower() {
if (modified > 0) {
return true;
}
return false;
}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;

View File

@ -13,6 +13,7 @@ import org.bukkit.event.Cancellable;
public class PowerRegenEvent extends FactionPlayerEvent implements Cancellable { public class PowerRegenEvent extends FactionPlayerEvent implements Cancellable {
private boolean cancelled = false; private boolean cancelled = false;
private double modified = 0;
public PowerRegenEvent(Faction f, FPlayer p) { public PowerRegenEvent(Faction f, FPlayer p) {
super(f, p); super(f, p);
@ -26,6 +27,29 @@ public class PowerRegenEvent extends FactionPlayerEvent implements Cancellable {
return fPlayer.getMillisPassed() * Conf.powerPerMinute / 60000; return fPlayer.getMillisPassed() * Conf.powerPerMinute / 60000;
} }
/**
* Get the amount of custom power this player will gain. Ignored if less than or equal to 0.
* @return Custom power as a double
*/
public double getCustomPower() {return modified;}
/**
* Get if we will be using the custom power gain instead of default.
* @return If we will process the event custom returned as a Boolean.
*/
public boolean usingCustomPower() {
if (modified > 0) {
return true;
}
return false;
}
/**
* Set the custom power gain for this event.
* @param gain Amount of power to be added to player.
*/
public void setCustomPower(Double gain) {modified = gain;}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;

View File

@ -80,9 +80,11 @@ public class FactionsEntityListener implements Listener {
// call Event // call Event
Bukkit.getPluginManager().callEvent(powerLossEvent); Bukkit.getPluginManager().callEvent(powerLossEvent);
// Call player onDeath if the event is not cancelled // Call player onDeath if the event is not cancelled and not using custom power
if (!powerLossEvent.isCancelled()) { if (!powerLossEvent.isCancelled() && !powerLossEvent.usingCustomPower()) {
fplayer.onDeath(); fplayer.onDeath();
} else if (powerLossEvent.usingCustomPower() && !powerLossEvent.isCancelled()) {
fplayer.alterPower(-powerLossEvent.getCustomPowerLost());
} }
// Send the message from the powerLossEvent // Send the message from the powerLossEvent
final String msg = powerLossEvent.getMessage(); final String msg = powerLossEvent.getMessage();

View File

@ -630,7 +630,11 @@ public abstract class MemoryFPlayer implements FPlayer {
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> Bukkit.getServer().getPluginManager().callEvent(powerRegenEvent)); Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> Bukkit.getServer().getPluginManager().callEvent(powerRegenEvent));
if (!powerRegenEvent.isCancelled()) if (!powerRegenEvent.isCancelled())
if (!powerRegenEvent.usingCustomPower()) {
this.alterPower(millisPassed * Conf.powerPerMinute / 60000); // millisPerMinute : 60 * 1000 this.alterPower(millisPassed * Conf.powerPerMinute / 60000); // millisPerMinute : 60 * 1000
} else {
this.alterPower(+powerRegenEvent.getCustomPower());
}
} }
public void losePowerFromBeingOffline() { public void losePowerFromBeingOffline() {