mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-09-27 13:32:38 +02:00
Merge pull request #228 from squidicuzz/1.8.x
Implemented Offline Faction Explosion Protection
This commit is contained in:
commit
424027045a
@ -162,6 +162,9 @@ public class Conf
|
||||
|
||||
//public static double considerFactionsReallyOfflineAfterXMinutes = 0.0;
|
||||
|
||||
public static boolean protectOfflineFactionsFromExplosions = false;
|
||||
public static double offlineExplosionProtectionDelay = 2.0;
|
||||
|
||||
public static int actionDeniedPainAmount = 2;
|
||||
|
||||
// commands which will be prevented if the player is a member of a permanent faction
|
||||
|
@ -83,6 +83,9 @@ public class Faction extends Entity implements EconomyParticipator
|
||||
this.home = null;
|
||||
}
|
||||
|
||||
// FIELD: lastOnlineTime
|
||||
private long lastOnlineTime;
|
||||
|
||||
// FIELD: account (fake field)
|
||||
// Bank functions
|
||||
public double money;
|
||||
@ -536,6 +539,53 @@ public class Faction extends Entity implements EconomyParticipator
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
// Offline Faction Protection
|
||||
//----------------------------------------------//
|
||||
public void updateOfflineExplosionProtection() {
|
||||
// We have either gained or a lost a player.
|
||||
if (this.id == "-2" || this.id == "-1" || this.id == "0") {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasOfflineExplosionProtection() {
|
||||
if (!Conf.protectOfflineFactionsFromExplosions) {
|
||||
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()) {
|
||||
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()) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public long getLastOnlineTime() {
|
||||
return this.lastOnlineTime;
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
// Deprecated
|
||||
//----------------------------------------------//
|
||||
|
@ -12,8 +12,11 @@ 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;
|
||||
@ -127,6 +130,14 @@ 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())
|
||||
@ -136,7 +147,7 @@ public class FactionsEntityListener implements Listener
|
||||
for (FLocation loc : explosionLocs)
|
||||
{
|
||||
Faction faction = Board.getFactionAt(loc);
|
||||
if (faction.getFlag(FFlag.EXPLOSIONS) == false)
|
||||
if (faction.getFlag(FFlag.EXPLOSIONS) == false || faction.hasOfflineExplosionProtection())
|
||||
{
|
||||
// faction has explosions disabled
|
||||
event.setCancelled(true);
|
||||
|
@ -29,6 +29,7 @@ import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.integration.SpoutFeatures;
|
||||
import com.massivecraft.factions.struct.FFlag;
|
||||
@ -59,6 +60,13 @@ public class FactionsPlayerListener implements Listener
|
||||
me.setLastStoodAt(new FLocation(event.getPlayer().getLocation()));
|
||||
if ( ! SpoutFeatures.updateTerritoryDisplay(me))
|
||||
me.sendFactionHereMessage();
|
||||
|
||||
// Set NoBoom timer update.
|
||||
Faction faction = me.getFaction();
|
||||
if (me.hasFaction() && Conf.protectOfflineFactionsFromExplosions) {
|
||||
//Notify our faction that the number of online players has changed.
|
||||
faction.updateOfflineExplosionProtection();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
@ -72,6 +80,13 @@ public class FactionsPlayerListener implements Listener
|
||||
me.setLastLoginTime(System.currentTimeMillis());
|
||||
|
||||
SpoutFeatures.playerDisconnect(me);
|
||||
|
||||
// Set NoBoom timer update.
|
||||
Faction faction = me.getFaction();
|
||||
if(me.hasFaction() && Conf.protectOfflineFactionsFromExplosions) {
|
||||
//Notify our faction that the number of online players has changed.
|
||||
faction.updateOfflineExplosionProtection();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
|
Loading…
Reference in New Issue
Block a user