mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-09-27 13:32:38 +02:00
cleanup, fixes, and optimization to offline explosion protection code
This commit is contained in:
parent
0cfa179537
commit
e1b2e4eb6c
@ -520,6 +520,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
|
||||
}
|
||||
|
||||
this.resetFactionData();
|
||||
myFaction.updateLastOnlineTime();
|
||||
|
||||
if (myFaction.isNormal() && !perm && myFaction.getFPlayers().isEmpty())
|
||||
{
|
||||
|
@ -542,50 +542,38 @@ public class Faction extends Entity implements EconomyParticipator
|
||||
//----------------------------------------------//
|
||||
// Offline Faction Protection
|
||||
//----------------------------------------------//
|
||||
public void updateOfflineExplosionProtection() {
|
||||
public void updateLastOnlineTime()
|
||||
{
|
||||
// We have either gained or a lost a player.
|
||||
if (this.id == "-2" || this.id == "-1" || this.id == "0") {
|
||||
if (this.isNone())
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getOnlinePlayers().size() <=1 && (this.getLastOnlineTime() + (Conf.offlineExplosionProtectionDelay * 60 * 1000)) < System.currentTimeMillis()) {
|
||||
//No one is online, set the last online time
|
||||
this.lastOnlineTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
this.lastOnlineTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public boolean hasOfflineExplosionProtection() {
|
||||
if (!Conf.protectOfflineFactionsFromExplosions) {
|
||||
|
||||
public boolean hasOfflineExplosionProtection()
|
||||
{
|
||||
if (!Conf.protectOfflineFactionsFromExplosions || this.isNone())
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.id == "-2" || this.id == "-1") {
|
||||
return true;
|
||||
} else if ((this.id == "-2" || this.id == "-1") && this.getFlag(FFlag.EXPLOSIONS) == false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
long timeUntilNoboom = (long) (this.getLastOnlineTime() + (Conf.offlineExplosionProtectionDelay * 60 * 1000));
|
||||
|
||||
//No protection if we are online.
|
||||
if (this.getOnlinePlayers().size() > 0 || this.isNone()) {
|
||||
|
||||
long timeUntilNoboom = this.getLastOnlineTime() + (long)(Conf.offlineExplosionProtectionDelay * 60 * 1000);
|
||||
|
||||
//No protection if players are online.
|
||||
if (this.getOnlinePlayers().size() > 0)
|
||||
return false;
|
||||
} else if (this.getOnlinePlayers().size() == 0 && timeUntilNoboom > System.currentTimeMillis()) {
|
||||
updateOfflineExplosionProtection();
|
||||
}
|
||||
|
||||
|
||||
// No Protection while timeUntilNoboom is greater than current system time.
|
||||
if (timeUntilNoboom > System.currentTimeMillis()) {
|
||||
if (timeUntilNoboom > System.currentTimeMillis())
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public long getLastOnlineTime() {
|
||||
|
||||
public long getLastOnlineTime()
|
||||
{
|
||||
return this.lastOnlineTime;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------//
|
||||
// Deprecated
|
||||
//----------------------------------------------//
|
||||
|
@ -12,11 +12,8 @@ import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Explosive;
|
||||
import org.bukkit.entity.Fireball;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
@ -130,14 +127,6 @@ public class FactionsEntityListener implements Listener
|
||||
public void onEntityExplode(EntityExplodeEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
// NoBoom Explosion Protection
|
||||
if (event.getEntity() instanceof Fireball || event.getEntity() instanceof Creeper || event.getEntity() instanceof Explosive) {
|
||||
Faction faction = Board.getFactionAt(new FLocation(event.getLocation().getBlock()));
|
||||
|
||||
if (!faction.hasOfflineExplosionProtection())
|
||||
faction.updateOfflineExplosionProtection();
|
||||
}
|
||||
|
||||
Set<FLocation> explosionLocs = new HashSet<FLocation>();
|
||||
for (Block block : event.blockList())
|
||||
|
@ -63,9 +63,10 @@ public class FactionsPlayerListener implements Listener
|
||||
|
||||
// Set NoBoom timer update.
|
||||
Faction faction = me.getFaction();
|
||||
if (me.hasFaction() && Conf.protectOfflineFactionsFromExplosions) {
|
||||
if (me.hasFaction() && Conf.protectOfflineFactionsFromExplosions)
|
||||
{
|
||||
//Notify our faction that the number of online players has changed.
|
||||
faction.updateOfflineExplosionProtection();
|
||||
faction.updateLastOnlineTime();
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,9 +84,10 @@ public class FactionsPlayerListener implements Listener
|
||||
|
||||
// Set NoBoom timer update.
|
||||
Faction faction = me.getFaction();
|
||||
if(me.hasFaction() && Conf.protectOfflineFactionsFromExplosions) {
|
||||
if(me.hasFaction() && Conf.protectOfflineFactionsFromExplosions)
|
||||
{
|
||||
//Notify our faction that the number of online players has changed.
|
||||
faction.updateOfflineExplosionProtection();
|
||||
faction.updateLastOnlineTime();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user