From 549aaaf4943be1954225cdcb15ac43313558c232 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 23 Aug 2013 10:45:27 +0200 Subject: [PATCH] Adding in offline explosion protection per default. --- src/com/massivecraft/factions/FFlag.java | 2 ++ .../massivecraft/factions/entity/Faction.java | 35 ++++++++++++++++++- .../factions/entity/FactionColl.java | 3 ++ .../listeners/FactionsListenerMain.java | 10 +++--- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/com/massivecraft/factions/FFlag.java b/src/com/massivecraft/factions/FFlag.java index 6b412549..bce7fb26 100644 --- a/src/com/massivecraft/factions/FFlag.java +++ b/src/com/massivecraft/factions/FFlag.java @@ -32,6 +32,7 @@ public enum FFlag FRIENDLYFIRE("friendlyfire", "Can friends hurt eachother here?", false), MONSTERS("monsters", "Can monsters spawn in this territory?", true), EXPLOSIONS("explosions", "Can explosions occur in this territory?", true), + OFFLINE_EXPLOSIONS("offlineexplosions", "Can explosions occur if faction is offline?", false), FIRESPREAD("firespread", "Can fire spread in territory?", true), ENDERGRIEF("endergrief", "Can endermen grief in this territory?", false), @@ -98,6 +99,7 @@ public enum FFlag if (str.startsWith("fr") || str.startsWith("ff")) return FRIENDLYFIRE; if (str.startsWith("m")) return MONSTERS; if (str.startsWith("ex")) return EXPLOSIONS; + if (str.startsWith("o")) return OFFLINE_EXPLOSIONS; if (str.startsWith("fi")) return FIRESPREAD; if (str.startsWith("en")) return ENDERGRIEF; return null; diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 38a21387..b919f284 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -897,7 +897,7 @@ public class Faction extends Entity implements EconomyParticipator } } return ret; - } + } public List getUPlayersWhereRole(Rel role) { @@ -1008,7 +1008,40 @@ public class Faction extends Entity implements EconomyParticipator Factions.get().log("Faction "+this.getName()+" ("+this.getId()+") leader was removed. Replacement leader: "+replacements.get(0).getName()); } } + + // -------------------------------------------- // + // FACTION ONLINE STATE + // -------------------------------------------- // + public boolean isAllUPlayersOffline() + { + return this.getUPlayersWhereOnline(true).size() == 0; + } + + public boolean isAnyUPlayersOnline() + { + return !this.isAllUPlayersOffline(); + } + + public boolean isFactionConsideredOffline() + { + return this.isAllUPlayersOffline(); + } + + public boolean isFactionConsideredOnline() + { + return !this.isFactionConsideredOffline(); + } + + public boolean isExplosionsAllowed() + { + boolean explosions = this.getFlag(FFlag.EXPLOSIONS); + boolean offlineexplosions = this.getFlag(FFlag.OFFLINE_EXPLOSIONS); + boolean online = this.isFactionConsideredOnline(); + + return (online && explosions) || (!online && offlineexplosions); + } + // -------------------------------------------- // // MESSAGES // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index 76e247da..b6766e52 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -102,6 +102,7 @@ public class FactionColl extends Coll faction.setFlag(FFlag.FRIENDLYFIRE, false); faction.setFlag(FFlag.MONSTERS, true); faction.setFlag(FFlag.EXPLOSIONS, true); + faction.setFlag(FFlag.OFFLINE_EXPLOSIONS, true); faction.setFlag(FFlag.FIRESPREAD, true); faction.setFlag(FFlag.ENDERGRIEF, true); @@ -134,6 +135,7 @@ public class FactionColl extends Coll faction.setFlag(FFlag.FRIENDLYFIRE, false); faction.setFlag(FFlag.MONSTERS, false); faction.setFlag(FFlag.EXPLOSIONS, false); + faction.setFlag(FFlag.OFFLINE_EXPLOSIONS, false); faction.setFlag(FFlag.FIRESPREAD, false); faction.setFlag(FFlag.ENDERGRIEF, false); @@ -166,6 +168,7 @@ public class FactionColl extends Coll faction.setFlag(FFlag.FRIENDLYFIRE, true); faction.setFlag(FFlag.MONSTERS, true); faction.setFlag(FFlag.EXPLOSIONS, true); + faction.setFlag(FFlag.OFFLINE_EXPLOSIONS, true); faction.setFlag(FFlag.FIRESPREAD, true); faction.setFlag(FFlag.ENDERGRIEF, true); diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index eac5f29d..d5922600 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -573,7 +573,7 @@ public class FactionsListenerMain implements Listener // ... and the faction there has explosions disabled ... Faction faction = BoardColls.get().getFactionAt(PS.valueOf(entity)); - if (faction.getFlag(FFlag.EXPLOSIONS)) return; + if (faction.isExplosionsAllowed()) return; // ... then cancel. event.setCancelled(true); @@ -589,7 +589,8 @@ public class FactionsListenerMain implements Listener if (UConf.isDisabled(location)) return; // Check the entity. Are explosions disabled there? - if (BoardColls.get().getFactionAt(PS.valueOf(location)).getFlag(FFlag.EXPLOSIONS) == false) + + if (BoardColls.get().getFactionAt(PS.valueOf(location)).isExplosionsAllowed() == false) { event.setCancelled(true); return; @@ -601,7 +602,7 @@ public class FactionsListenerMain implements Listener { Block block = iter.next(); Faction faction = BoardColls.get().getFactionAt(PS.valueOf(block)); - if (faction.getFlag(FFlag.EXPLOSIONS) == false) iter.remove(); + if (faction.isExplosionsAllowed() == false) iter.remove(); } } @@ -618,7 +619,8 @@ public class FactionsListenerMain implements Listener // ... and the faction there has explosions disabled ... PS ps = PS.valueOf(event.getBlock()); Faction faction = BoardColls.get().getFactionAt(ps); - if (faction.getFlag(FFlag.EXPLOSIONS)) return; + + if (faction.isExplosionsAllowed()) return; // ... stop the block alteration. event.setCancelled(true);