Adding in offline explosion protection per default.

This commit is contained in:
Olof Larsson 2013-08-23 10:45:27 +02:00
parent fa0a2fb90a
commit 549aaaf494
4 changed files with 45 additions and 5 deletions

View File

@ -32,6 +32,7 @@ public enum FFlag
FRIENDLYFIRE("friendlyfire", "<i>Can friends hurt eachother here?", false),
MONSTERS("monsters", "<i>Can monsters spawn in this territory?", true),
EXPLOSIONS("explosions", "<i>Can explosions occur in this territory?", true),
OFFLINE_EXPLOSIONS("offlineexplosions", "<i>Can explosions occur if faction is offline?", false),
FIRESPREAD("firespread", "<i>Can fire spread in territory?", true),
ENDERGRIEF("endergrief", "<i>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;

View File

@ -897,7 +897,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
}
}
return ret;
}
}
public List<UPlayer> getUPlayersWhereRole(Rel role)
{
@ -1008,7 +1008,40 @@ public class Faction extends Entity<Faction> 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
// -------------------------------------------- //

View File

@ -102,6 +102,7 @@ public class FactionColl extends Coll<Faction>
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>
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>
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);

View File

@ -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);