Fixes NPE on Saving Task onDisable MPlugin, removed Async Throw for 1.15 in F Show

This commit is contained in:
Driftay 2020-05-09 14:04:17 -04:00
parent bbaee8ab06
commit c29850eaaa
7 changed files with 59 additions and 92 deletions

View File

@ -4,7 +4,7 @@
<groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId>
<version>1.6.9.5-2.3.6-RC</version>
<version>1.6.9.5-2.3.7-RC</version>
<packaging>jar</packaging>
<name>SaberFactions</name>

View File

@ -8,11 +8,9 @@ import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TagReplacer;
import com.massivecraft.factions.zcore.util.TagUtil;
import mkremins.fanciful.FancyMessage;
import org.bukkit.scheduler.BukkitScheduler;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class CmdShow extends FCommand {
@ -85,42 +83,38 @@ public class CmdShow extends FCommand {
return; // we only show header for non-normal factions
}
List<String> finalShow = show;
Faction finalFaction = faction;
List<FancyMessage> fancy = new ArrayList<>();
instance.getServer().getScheduler().runTaskAsynchronously(instance, () -> {
for (String raw : finalShow) {
String parsed = TagUtil.parsePlain(finalFaction, context.fPlayer, raw); // use relations
if (parsed == null) {
continue; // Due to minimal f show.
}
if (context.fPlayer != null) {
parsed = TagUtil.parsePlaceholders(context.fPlayer.getPlayer(), parsed);
}
if (TagUtil.hasFancy(parsed)) {
List<FancyMessage> localFancy = TagUtil.parseFancy(finalFaction, context.fPlayer, parsed);
if (localFancy != null)
fancy.addAll(localFancy);
continue;
}
if (!parsed.contains("{notFrozen}") && !parsed.contains("{notPermanent}")) {
if (parsed.contains("{ig}")) {
// replaces all variables with no home TL
parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString();
}
if (parsed.contains("%")) {
parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it.
}
parsed = FactionsPlugin.getInstance().txt.parse(parsed);
FancyMessage localFancy = instance.txt.parseFancy(parsed);
fancy.add(localFancy);
}
for (String raw : show) {
String parsed = TagUtil.parsePlain(faction, context.fPlayer, raw); // use relations
if (parsed == null) {
continue; // Due to minimal f show.
}
instance.getServer().getScheduler().runTask(instance, () -> context.sendFancyMessage(fancy));
});
if (context.fPlayer != null) {
parsed = TagUtil.parsePlaceholders(context.fPlayer.getPlayer(), parsed);
}
if (TagUtil.hasFancy(parsed)) {
List<FancyMessage> localFancy = TagUtil.parseFancy(faction, context.fPlayer, parsed);
if (localFancy != null)
fancy.addAll(localFancy);
continue;
}
if (!parsed.contains("{notFrozen}") && !parsed.contains("{notPermanent}")) {
if (parsed.contains("{ig}")) {
// replaces all variables with no home TL
parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString();
}
if (parsed.contains("%")) {
parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it.
}
parsed = FactionsPlugin.getInstance().txt.parse(parsed);
FancyMessage localFancy = instance.txt.parseFancy(parsed);
fancy.add(localFancy);
}
}
instance.getServer().getScheduler().runTask(instance, () -> context.sendFancyMessage(fancy));
}
@Override

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.event;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import org.bukkit.event.Cancellable;
@ -10,51 +9,20 @@ import org.bukkit.event.Cancellable;
*/
public class PowerRegenEvent extends FactionPlayerEvent implements Cancellable {
/**
* @author Illyria Team
*/
private boolean cancelled = false;
private double modified = 0;
private double delta;
public PowerRegenEvent(Faction f, FPlayer p) {
public PowerRegenEvent(Faction f, FPlayer p, double delta) {
super(f, p);
this.delta = delta;
}
/**
* Get the amount of power this player will regen by default
*
* @return power amount gained as a Double.
*/
public double getDefaultPowerGained() {
return fPlayer.getMillisPassed() * Conf.powerPerMinute / 60000;
public double getDelta() {
return delta;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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() {
return modified > 0;
public void setDelta(double delta) {
this.delta = delta;
}
@Override

View File

@ -259,8 +259,6 @@ public class FactionsEntityListener implements Listener {
private boolean checkExplosionForBlock(Entity boomer, Block block) {
Faction faction = Board.getInstance().getFactionAt(new FLocation(block.getLocation()));
if(FactionsPlugin.getInstance().getTimerManager().graceTimer.getRemaining() > 0) return false;
if (faction.noExplosionsInTerritory() || (faction.isPeaceful() && Conf.peacefulTerritoryDisableBoom))
return false;
// faction is peaceful and has explosions set to disabled

View File

@ -176,15 +176,13 @@ public abstract class MPlugin extends JavaPlugin {
this.getServer().getScheduler().cancelTask(saveTask);
saveTask = null;
}
this.getServer().getScheduler().cancelTasks(this);
// only save data if plugin actually loaded successfully
if (loadSuccessful) {
Factions.getInstance().forceSave();
FPlayers.getInstance().forceSave();
Board.getInstance().forceSave();
}
log("Disabled");
}

View File

@ -663,25 +663,34 @@ public abstract class MemoryFPlayer implements FPlayer {
public void updatePower() {
if (this.isOffline()) {
losePowerFromBeingOffline();
if (!Conf.powerRegenOffline) return;
if (!Conf.powerRegenOffline) {
return;
}
} else if (hasFaction() && getFaction().isPowerFrozen()) {
return; // Don't let power regen if faction power is frozen.
}
long now = System.currentTimeMillis();
this.millisPassed = now - this.lastPowerUpdateTime;
long millisPassed = now - this.lastPowerUpdateTime;
this.lastPowerUpdateTime = now;
Player thisPlayer = this.getPlayer();
if (thisPlayer != null && thisPlayer.isDead())
if (thisPlayer != null && thisPlayer.isDead()) {
return; // don't let dead players regain power until they respawn
PowerRegenEvent powerRegenEvent = new PowerRegenEvent(getFaction(), this);
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> Bukkit.getServer().getPluginManager().callEvent(powerRegenEvent));
}
if (!powerRegenEvent.isCancelled())
if (!powerRegenEvent.usingCustomPower())
this.alterPower(millisPassed * Conf.powerPerMinute / 60000); // millisPerMinute : 60 * 1000
else this.alterPower(+powerRegenEvent.getCustomPower());
double delta = millisPassed * Conf.powerPerMinute / 60000; // millisPerMinute : 60 * 1000
if (Bukkit.getPluginManager().getPlugin("FactionsPlugin") != null) {
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> {
PowerRegenEvent powerRegenEvent = new PowerRegenEvent(getFaction(), this, delta);
Bukkit.getServer().getPluginManager().callEvent(powerRegenEvent);
if (!powerRegenEvent.isCancelled()) {
this.alterPower(powerRegenEvent.getDelta());
}
});
} else {
this.alterPower(delta);
}
}
public void losePowerFromBeingOffline() {