Use PS instead of FLocation in a few places.

This commit is contained in:
Olof Larsson 2013-04-11 11:11:31 +02:00
parent 4cc36b8d96
commit 4a63d50cbb
22 changed files with 217 additions and 187 deletions

View File

@ -21,7 +21,7 @@ import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.util.AsciiCompass; import com.massivecraft.factions.util.AsciiCompass;
public class BoardOld public class BoardOldDepr
{ {
private static transient File file = new File(Factions.get().getDataFolder(), "board.json"); private static transient File file = new File(Factions.get().getDataFolder(), "board.json");
private static transient HashMap<FLocation, TerritoryAccess> flocationIds = new HashMap<FLocation, TerritoryAccess>(); private static transient HashMap<FLocation, TerritoryAccess> flocationIds = new HashMap<FLocation, TerritoryAccess>();

View File

@ -10,6 +10,7 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.mcore.ps.PS;
/** /**
* Permissions that you (a player) may or may not have in the territory of a certain faction. * Permissions that you (a player) may or may not have in the territory of a certain faction.
@ -171,9 +172,10 @@ public enum FPerm
{ {
return this.has(testSubject, hostFaction, false); return this.has(testSubject, hostFaction, false);
} }
public boolean has(Object testSubject, FLocation floc, boolean informIfNot) public boolean has(Object testSubject, PS ps, boolean informIfNot)
{ {
TerritoryAccess access = BoardOld.getTerritoryAccessAt(floc); TerritoryAccess access = BoardColl.get().getTerritoryAccessAt(ps);
if (this.isTerritoryPerm()) if (this.isTerritoryPerm())
{ {
if (access.subjectHasAccess(testSubject)) return true; if (access.subjectHasAccess(testSubject)) return true;
@ -196,15 +198,15 @@ public enum FPerm
} }
public boolean has(Object testSubject, Location loc, boolean informIfNot) public boolean has(Object testSubject, Location loc, boolean informIfNot)
{ {
FLocation floc = new FLocation(loc); PS ps = PS.valueOf(loc);
return this.has(testSubject, floc, informIfNot); return this.has(testSubject, ps, informIfNot);
} }
public boolean has(Object testSubject, Location loc) public boolean has(Object testSubject, Location loc)
{ {
return this.has(testSubject, loc, false); return this.has(testSubject, loc, false);
} }
public boolean has(Object testSubject, FLocation floc) public boolean has(Object testSubject, PS ps)
{ {
return this.has(testSubject, floc, false); return this.has(testSubject, ps, false);
} }
} }

View File

@ -18,6 +18,7 @@ import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.factions.zcore.persist.PlayerEntity; import com.massivecraft.factions.zcore.persist.PlayerEntity;
import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -36,9 +37,12 @@ import com.massivecraft.mcore.util.Txt;
public class FPlayer extends PlayerEntity implements EconomyParticipator public class FPlayer extends PlayerEntity implements EconomyParticipator
{ {
// FIELD: lastStoodAt // FIELD: lastStoodAt
private transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked? // Where did this player stand the last time we checked?
public FLocation getLastStoodAt() { return this.lastStoodAt; } // This is a "chunk".
public void setLastStoodAt(FLocation flocation) { this.lastStoodAt = flocation; } // Rename to "currentChunk"?
private transient PS lastStoodAt = PS.NULL;
public PS getLastStoodAt() { return this.lastStoodAt; }
public void setLastStoodAt(PS lastStoodAt) { this.lastStoodAt = lastStoodAt.getChunk(true); }
// FIELD: factionId // FIELD: factionId
private String factionId; private String factionId;
@ -101,7 +105,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
public String getAccountId() { return this.getId(); } public String getAccountId() { return this.getId(); }
// -------------------------------------------- // // -------------------------------------------- //
// Construct // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
// GSON need this noarg constructor. // GSON need this noarg constructor.
@ -153,7 +157,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
} }
// -------------------------------------------- // // -------------------------------------------- //
// Getters And Setters // GETTERS AND SETTERS
// -------------------------------------------- // // -------------------------------------------- //
public long getLastLoginTime() public long getLastLoginTime()
@ -187,7 +191,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
} }
//----------------------------------------------// //----------------------------------------------//
// Title, Name, Faction Tag and Chat // TITLE, NAME, FACTION TAG AND CHAT
//----------------------------------------------// //----------------------------------------------//
public String getName() public String getName()
{ {
@ -270,7 +274,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
} }
// ------------------------------- // -------------------------------
// Relation and relation colors // RELATION AND RELATION COLORS
// ------------------------------- // -------------------------------
@Override @Override
@ -299,7 +303,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
public Rel getRelationToLocation() public Rel getRelationToLocation()
{ {
return BoardOld.getFactionAt(new FLocation(this)).getRelationTo(this); // TODO: Use some built in system to get sender
return BoardColl.get().getFactionAt(PS.valueOf(this.getPlayer())).getRelationTo(this);
} }
@Override @Override
@ -309,7 +314,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
} }
//----------------------------------------------// //----------------------------------------------//
// Health // HEALTH
//----------------------------------------------// //----------------------------------------------//
public void heal(int amnt) public void heal(int amnt)
{ {
@ -323,7 +328,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
//----------------------------------------------// //----------------------------------------------//
// Power // POWER
//----------------------------------------------// //----------------------------------------------//
public double getPower() public double getPower()
{ {
@ -416,11 +421,12 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
} }
//----------------------------------------------// //----------------------------------------------//
// Territory // TERRITORY
//----------------------------------------------// //----------------------------------------------//
public boolean isInOwnTerritory() public boolean isInOwnTerritory()
{ {
return BoardOld.getFactionAt(new FLocation(this)) == this.getFaction(); // TODO: Use Mixin to get this PS instead
return BoardColl.get().getFactionAt(PS.valueOf(this.getPlayer())) == this.getFaction();
} }
/*public boolean isInOthersTerritory() /*public boolean isInOthersTerritory()
@ -441,7 +447,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
public boolean isInEnemyTerritory() public boolean isInEnemyTerritory()
{ {
return BoardOld.getFactionAt(new FLocation(this)).getRelationTo(this) == Rel.ENEMY; // TODO: Use Mixin to get this PS instead
return BoardColl.get().getFactionAt(PS.valueOf(this.getPlayer())).getRelationTo(this) == Rel.ENEMY;
} }
public void sendFactionHereMessage() public void sendFactionHereMessage()
@ -450,7 +457,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
{ {
return; return;
} }
Faction factionHere = BoardOld.getFactionAt(this.getLastStoodAt()); Faction factionHere = BoardColl.get().getFactionAt(this.getLastStoodAt());
String msg = Txt.parse("<i>")+" ~ "+factionHere.getTag(this); String msg = Txt.parse("<i>")+" ~ "+factionHere.getTag(this);
if (factionHere.getDescription().length() > 0) if (factionHere.getDescription().length() > 0)
{ {
@ -460,7 +467,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
} }
// ------------------------------- // -------------------------------
// Actions // ACTIONS
// ------------------------------- // -------------------------------
public void leave(boolean makePay) public void leave(boolean makePay)
@ -536,9 +543,10 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure) public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure)
{ {
String error = null; String error = null;
FLocation flocation = new FLocation(location);
Faction myFaction = getFaction(); PS ps = PS.valueOf(location);
Faction currentFaction = BoardOld.getFactionAt(flocation); Faction myFaction = this.getFaction();
Faction currentFaction = BoardColl.get().getFactionAt(ps);
int ownedLand = forFaction.getLandRounded(); int ownedLand = forFaction.getLandRounded();
if (ConfServer.worldGuardChecking && Worldguard.checkForRegionsInChunk(location)) if (ConfServer.worldGuardChecking && Worldguard.checkForRegionsInChunk(location))
@ -546,7 +554,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
// Checks for WorldGuard regions in the chunk attempting to be claimed // Checks for WorldGuard regions in the chunk attempting to be claimed
error = Txt.parse("<b>This land is protected"); error = Txt.parse("<b>This land is protected");
} }
else if (ConfServer.worldsNoClaiming.contains(flocation.getWorldName())) else if (ConfServer.worldsNoClaiming.contains(ps.getWorld()))
{ {
error = Txt.parse("<b>Sorry, this world has land claiming disabled."); error = Txt.parse("<b>Sorry, this world has land claiming disabled.");
} }
@ -586,8 +594,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
( (
ConfServer.claimsMustBeConnected ConfServer.claimsMustBeConnected
&& ! this.hasAdminMode() && ! this.hasAdminMode()
&& myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && myFaction.getLandRoundedInWorld(ps.getWorld()) > 0
&& !BoardOld.isConnectedLocation(flocation, myFaction) && !BoardColl.get().isConnectedPs(ps, myFaction)
&& (!ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal()) && (!ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())
) )
{ {
@ -603,7 +611,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
// TODO more messages WARN current faction most importantly // TODO more messages WARN current faction most importantly
error = Txt.parse("%s<i> owns this land and is strong enough to keep it.", currentFaction.getTag(this)); error = Txt.parse("%s<i> owns this land and is strong enough to keep it.", currentFaction.getTag(this));
} }
else if ( ! BoardOld.isBorderLocation(flocation)) else if ( ! BoardColl.get().isBorderPs(ps))
{ {
error = Txt.parse("<b>You must start claiming land at the border of the territory."); error = Txt.parse("<b>You must start claiming land at the border of the territory.");
} }
@ -621,8 +629,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
// notifyFailure is false if called by auto-claim; no need to notify on every failure for it // notifyFailure is false if called by auto-claim; no need to notify on every failure for it
// return value is false on failure, true on success // return value is false on failure, true on success
FLocation flocation = new FLocation(location); PS flocation = PS.valueOf(location).getChunk(true);
Faction currentFaction = BoardOld.getFactionAt(flocation); Faction currentFaction = BoardColl.get().getFactionAt(flocation);
int ownedLand = forFaction.getLandRounded(); int ownedLand = forFaction.getLandRounded();
@ -637,7 +645,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
{ {
cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal()); cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
if (ConfServer.econClaimUnconnectedFee != 0.0 && forFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !BoardOld.isConnectedLocation(flocation, forFaction)) if (ConfServer.econClaimUnconnectedFee != 0.0 && forFaction.getLandRoundedInWorld(flocation.getWorld()) > 0 && !BoardColl.get().isConnectedPs(flocation, forFaction))
cost += ConfServer.econClaimUnconnectedFee; cost += ConfServer.econClaimUnconnectedFee;
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts && this.hasFaction()) if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts && this.hasFaction())
@ -667,17 +675,17 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
fp.msg("<h>%s<i> claimed land for <h>%s<i> from <h>%s<i>.", this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp)); fp.msg("<h>%s<i> claimed land for <h>%s<i> from <h>%s<i>.", this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp));
} }
BoardOld.setFactionAt(forFaction, flocation); BoardColl.get().setFactionAt(flocation, forFaction);
SpoutFeatures.updateTerritoryDisplayLoc(flocation); SpoutFeatures.updateTerritoryDisplayLoc(flocation);
if (ConfServer.logLandClaims) if (ConfServer.logLandClaims)
Factions.get().log(this.getName()+" claimed land at ("+flocation.getCoordString()+") for the faction: "+forFaction.getTag()); Factions.get().log(this.getName()+" claimed land at ("+flocation.getChunkX()+","+flocation.getChunkZ()+") for the faction: "+forFaction.getTag());
return true; return true;
} }
// -------------------------------------------- // // -------------------------------------------- //
// Persistance // PERSISTANCE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override

View File

@ -12,6 +12,7 @@ import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.util.*; import com.massivecraft.factions.util.*;
import com.massivecraft.factions.zcore.persist.Entity; import com.massivecraft.factions.zcore.persist.Entity;
import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -74,7 +75,7 @@ public class Faction extends Entity implements EconomyParticipator
} }
public void confirmValidHome() public void confirmValidHome()
{ {
if (!ConfServer.homesMustBeInClaimedTerritory || this.home == null || (this.home.getLocation() != null && BoardOld.getFactionAt(new FLocation(this.home.getLocation())) == this)) if (!ConfServer.homesMustBeInClaimedTerritory || this.home == null || (this.home.getLocation() != null && BoardColl.get().getFactionAt(PS.valueOf(this.home.getLocation())) == this))
return; return;
msg("<b>Your faction home has been un-set since it is no longer in your territory."); msg("<b>Your faction home has been un-set since it is no longer in your territory.");
@ -348,13 +349,14 @@ public class Faction extends Entity implements EconomyParticipator
return (int) Math.round(this.getPowerMax()); return (int) Math.round(this.getPowerMax());
} }
public int getLandRounded() { // TODO: Why "rounded"? Rename to getLandCount? or getChunkCount?
return BoardOld.getFactionCoordCount(this); public int getLandRounded()
{
return BoardColl.get().getCount(this);
} }
public int getLandRoundedInWorld(String worldName) public int getLandRoundedInWorld(String worldName)
{ {
return BoardOld.getFactionCoordCountInWorld(this, worldName); return BoardColl.get().get(worldName).getCount(this);
} }
public boolean hasLandInflation() public boolean hasLandInflation()
@ -548,7 +550,8 @@ public class Faction extends Entity implements EconomyParticipator
} }
// Clean the board // Clean the board
BoardOld.clean(); // TODO: Use events for this instead
BoardColl.get().clean();
// Clean the fplayers // Clean the fplayers
FPlayerColl.i.clean(); FPlayerColl.i.clean();

View File

@ -188,7 +188,7 @@ public class FactionColl extends EntityCollection<Faction>
if ( ! this.exists(id)) if ( ! this.exists(id))
{ {
Factions.get().log(Level.WARNING, "Non existing factionId "+id+" requested! Issuing cleaning!"); Factions.get().log(Level.WARNING, "Non existing factionId "+id+" requested! Issuing cleaning!");
BoardOld.clean(); BoardColl.get().clean();
FPlayerColl.i.clean(); FPlayerColl.i.clean();
} }

View File

@ -77,14 +77,12 @@ public class Factions extends MPlugin
// Load Server Config // Load Server Config
ConfServer.get().load(); ConfServer.get().load();
this.loadSuccessful = false;
// Load Conf from disk // Load Conf from disk
FPlayerColl.i.loadFromDisc(); FPlayerColl.i.loadFromDisc();
FactionColl.i.loadFromDisc(); FactionColl.i.loadFromDisc();
BoardOld.load(); BoardColl.get().init();
// Add Base Commands // Add Base Commands
this.cmdAutoHelp = new CmdFactionsAutoHelp(); this.cmdAutoHelp = new CmdFactionsAutoHelp();
this.cmdBase = new CmdFactions(); this.cmdBase = new CmdFactions();
@ -125,7 +123,6 @@ public class Factions extends MPlugin
getServer().getPluginManager().registerEvents(this.blockListener, this); getServer().getPluginManager().registerEvents(this.blockListener, this);
postEnable(); postEnable();
this.loadSuccessful = true;
} }
@Override @Override
@ -147,11 +144,6 @@ public class Factions extends MPlugin
@Override @Override
public void onDisable() public void onDisable()
{ {
// only save data if plugin actually completely loaded successfully
if (this.loadSuccessful)
{
BoardOld.save();
}
EssentialsFeatures.unhookChat(); EssentialsFeatures.unhookChat();
if (AutoLeaveTask != null) if (AutoLeaveTask != null)
{ {
@ -194,12 +186,6 @@ public class Factions extends MPlugin
econLandRewardTaskID = getServer().getScheduler().scheduleSyncRepeatingTask(this, new EconLandRewardTask(), ticks, ticks); econLandRewardTaskID = getServer().getScheduler().scheduleSyncRepeatingTask(this, new EconLandRewardTask(), ticks, ticks);
} }
} }
@Override
public void postAutoSave()
{
BoardOld.save();
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) public boolean onCommand(CommandSender sender, Command command, String label, String[] split)

View File

@ -1,13 +1,13 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.BoardOld; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -36,9 +36,9 @@ public class CmdFactionsAccess extends FCommand
{ {
String type = this.argAsString(0); String type = this.argAsString(0);
type = (type == null) ? "" : type.toLowerCase(); type = (type == null) ? "" : type.toLowerCase();
FLocation loc = new FLocation(me.getLocation()); PS loc = PS.valueOf(me);
TerritoryAccess territory = BoardOld.getTerritoryAccessAt(loc); TerritoryAccess territory = BoardColl.get().getTerritoryAccessAt(loc);
Faction locFaction = territory.getHostFaction(); Faction locFaction = territory.getHostFaction();
boolean accessAny = Perm.ACCESS_ANY.has(sender, false); boolean accessAny = Perm.ACCESS_ANY.has(sender, false);

View File

@ -7,16 +7,16 @@ import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.factions.BoardOld; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.integration.EssentialsFeatures; import com.massivecraft.factions.integration.EssentialsFeatures;
import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.SmokeUtil; import com.massivecraft.mcore.util.SmokeUtil;
@ -75,7 +75,8 @@ public class CmdFactionsHome extends FCommand
return; return;
} }
Faction faction = BoardOld.getFactionAt(new FLocation(me.getLocation()));
Faction faction = BoardColl.get().getFactionAt(PS.valueOf(me));
Location loc = me.getLocation().clone(); Location loc = me.getLocation().clone();
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby // if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby

View File

@ -1,9 +1,9 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.BoardOld; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.ps.PS;
public class CmdFactionsMap extends FCommand public class CmdFactionsMap extends FCommand
@ -61,7 +61,7 @@ public class CmdFactionsMap extends FCommand
public void showMap() public void showMap()
{ {
sendMessage(BoardOld.getMap(myFaction, new FLocation(fme), fme.getPlayer().getLocation().getYaw())); sendMessage(BoardColl.get().getMap(myFaction, PS.valueOf(me), fme.getPlayer().getLocation().getYaw()));
} }
} }

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.BoardOld;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.FactionColl; import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
@ -34,12 +33,7 @@ public class CmdFactionsReload extends FCommand
String fileName; String fileName;
if (file.startsWith("b")) if (file.startsWith("f"))
{
BoardOld.load();
fileName = "board.json";
}
else if (file.startsWith("f"))
{ {
FactionColl.i.loadFromDisc(); FactionColl.i.loadFromDisc();
fileName = "factions.json"; fileName = "factions.json";
@ -54,7 +48,6 @@ public class CmdFactionsReload extends FCommand
fileName = "all"; fileName = "all";
FPlayerColl.i.loadFromDisc(); FPlayerColl.i.loadFromDisc();
FactionColl.i.loadFromDisc(); FactionColl.i.loadFromDisc();
BoardOld.load();
} }
else else
{ {

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.BoardOld;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.FactionColl; import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
@ -31,7 +30,6 @@ public class CmdFactionsSaveAll extends FCommand
{ {
FPlayerColl.i.saveToDisc(); FPlayerColl.i.saveToDisc();
FactionColl.i.saveToDisc(); FactionColl.i.saveToDisc();
BoardOld.save();
msg("<i>Factions saved to disk!"); msg("<i>Factions saved to disk!");
} }

View File

@ -1,11 +1,11 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.BoardOld; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.ps.PS;
public class CmdFactionsSethome extends FCommand public class CmdFactionsSethome extends FCommand
{ {
@ -47,7 +47,7 @@ public class CmdFactionsSethome extends FCommand
&& &&
ConfServer.homesMustBeInClaimedTerritory ConfServer.homesMustBeInClaimedTerritory
&& &&
BoardOld.getFactionAt(new FLocation(me)) != faction BoardColl.get().getFactionAt(PS.valueOf(me)) != faction
) )
{ {
fme.msg("<b>Sorry, your faction home can only be set inside your own claimed territory."); fme.msg("<b>Sorry, your faction home can only be set inside your own claimed territory.");

View File

@ -2,16 +2,16 @@ package com.massivecraft.factions.cmd;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.massivecraft.factions.BoardOld;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.event.LandUnclaimEvent; import com.massivecraft.factions.event.LandUnclaimEvent;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.FLocation; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.ps.PS;
public class CmdFactionsUnclaim extends FCommand public class CmdFactionsUnclaim extends FCommand
{ {
@ -35,12 +35,12 @@ public class CmdFactionsUnclaim extends FCommand
@Override @Override
public void perform() public void perform()
{ {
FLocation flocation = new FLocation(fme); PS chunk = PS.valueOf(me).getChunk(true);
Faction otherFaction = BoardOld.getFactionAt(flocation); Faction otherFaction = BoardColl.get().getFactionAt(chunk);
if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return; if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return;
LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(flocation, otherFaction, fme); LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(chunk, otherFaction, fme);
Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); Bukkit.getServer().getPluginManager().callEvent(unclaimEvent);
if(unclaimEvent.isCancelled()) return; if(unclaimEvent.isCancelled()) return;
@ -59,12 +59,14 @@ public class CmdFactionsUnclaim extends FCommand
} }
} }
BoardOld.removeAt(flocation); BoardColl.get().removeAt(chunk);
SpoutFeatures.updateTerritoryDisplayLoc(flocation); SpoutFeatures.updateTerritoryDisplayLoc(chunk);
myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true)); myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true));
if (ConfServer.logLandUnclaims) if (ConfServer.logLandUnclaims)
Factions.get().log(fme.getName()+" unclaimed land at ("+flocation.getCoordString()+") from the faction: "+otherFaction.getTag()); {
Factions.get().log(fme.getName()+" unclaimed land at ("+chunk.getChunkX()+","+chunk.getChunkZ()+") from the faction: "+otherFaction.getTag());
}
} }
} }

View File

@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.massivecraft.factions.BoardOld; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
@ -46,15 +46,17 @@ public class CmdFactionsUnclaimall extends FCommand
} }
LandUnclaimAllEvent unclaimAllEvent = new LandUnclaimAllEvent(myFaction, fme); LandUnclaimAllEvent unclaimAllEvent = new LandUnclaimAllEvent(myFaction, fme);
Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent); Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent);
// this event cannot be cancelled // this event cannot be cancelled
BoardOld.unclaimAll(myFaction.getId()); BoardColl.get().removeAll(myFaction);
myFaction.msg("%s<i> unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true)); myFaction.msg("%s<i> unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true));
SpoutFeatures.updateTerritoryDisplayLoc(null); SpoutFeatures.updateTerritoryDisplayLoc(null);
if (ConfServer.logLandUnclaims) if (ConfServer.logLandUnclaims)
{
Factions.get().log(fme.getName()+" unclaimed everything for the faction: "+myFaction.getTag()); Factions.get().log(fme.getName()+" unclaimed everything for the faction: "+myFaction.getTag());
}
} }
} }

View File

@ -4,9 +4,10 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.mcore.ps.PS;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class LandClaimEvent extends Event implements Cancellable public class LandClaimEvent extends Event implements Cancellable
@ -27,8 +28,8 @@ public class LandClaimEvent extends Event implements Cancellable
@Override public boolean isCancelled() { return this.cancelled; } @Override public boolean isCancelled() { return this.cancelled; }
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
private final FLocation location; private final PS chunk;
public FLocation getLocation() { return this.location; } public PS getChunk() { return this.chunk; }
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
@ -45,10 +46,10 @@ public class LandClaimEvent extends Event implements Cancellable
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public LandClaimEvent(FLocation location, Faction faction, FPlayer fplayer) public LandClaimEvent(PS chunk, Faction faction, FPlayer fplayer)
{ {
this.cancelled = false; this.cancelled = false;
this.location = location; this.chunk = chunk.getChunk(true);
this.faction = faction; this.faction = faction;
this.fplayer = fplayer; this.fplayer = fplayer;
} }

View File

@ -4,9 +4,10 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.mcore.ps.PS;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class LandUnclaimEvent extends Event implements Cancellable public class LandUnclaimEvent extends Event implements Cancellable
@ -27,8 +28,8 @@ public class LandUnclaimEvent extends Event implements Cancellable
@Override public boolean isCancelled() { return this.cancelled; } @Override public boolean isCancelled() { return this.cancelled; }
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
private final FLocation location; private final PS chunk;
public FLocation getLocation() { return this.location; } public PS getChunk() { return this.chunk; }
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
@ -45,10 +46,10 @@ public class LandUnclaimEvent extends Event implements Cancellable
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public LandUnclaimEvent(FLocation location, Faction faction, FPlayer fplayer) public LandUnclaimEvent(PS chunk, Faction faction, FPlayer fplayer)
{ {
this.cancelled = false; this.cancelled = false;
this.location = location; this.chunk = chunk.getChunk(true);
this.faction = faction; this.faction = faction;
this.fplayer = fplayer; this.fplayer = fplayer;
} }

View File

@ -5,7 +5,6 @@ import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -14,7 +13,6 @@ import org.bukkit.block.BlockState;
import com.griefcraft.lwc.LWC; import com.griefcraft.lwc.LWC;
import com.griefcraft.lwc.LWCPlugin; import com.griefcraft.lwc.LWCPlugin;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
@ -38,11 +36,18 @@ public class LWCFeatures
return ConfServer.lwcIntegration && lwc != null; return ConfServer.lwcIntegration && lwc != null;
} }
public static void clearOtherChests(FLocation flocation, Faction faction) public static void clearOtherChests(PS ps, Faction faction)
{ {
Location location = new Location(Bukkit.getWorld(flocation.getWorldName()), flocation.getX() * 16, 5, flocation.getZ() * 16); Chunk chunk = null;
if (location.getWorld() == null) return; // world not loaded or something? cancel out to prevent error try
Chunk chunk = location.getChunk(); {
chunk = ps.asBukkitChunk(true);
}
catch (Exception e)
{
return;
}
BlockState[] blocks = chunk.getTileEntities(); BlockState[] blocks = chunk.getTileEntities();
List<Block> chests = new LinkedList<Block>(); List<Block> chests = new LinkedList<Block>();

View File

@ -8,7 +8,6 @@ import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -17,6 +16,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.factions.util.HealthBarUtil; import com.massivecraft.factions.util.HealthBarUtil;
import com.massivecraft.mcore.ps.PS;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.SpoutManager;
@ -246,7 +246,7 @@ public class SpoutFeatures
// -------------------------------------------- // // -------------------------------------------- //
// update displayed current territory for all players inside a specified chunk; if specified chunk is null, then simply update everyone online // update displayed current territory for all players inside a specified chunk; if specified chunk is null, then simply update everyone online
public static void updateTerritoryDisplayLoc(FLocation fLoc) public static void updateTerritoryDisplayLoc(PS chunk)
{ {
if ( ! isEnabled()) return; if ( ! isEnabled()) return;
@ -254,10 +254,14 @@ public class SpoutFeatures
for (FPlayer player : players) for (FPlayer player : players)
{ {
if (fLoc == null) if (chunk == null)
{
mainListener.updateTerritoryDisplay(player, false); mainListener.updateTerritoryDisplay(player, false);
else if (player.getLastStoodAt().equals(fLoc)) }
else if (player.getLastStoodAt().equals(chunk))
{
mainListener.updateTerritoryDisplay(player, true); mainListener.updateTerritoryDisplay(player, true);
}
} }
} }
@ -269,15 +273,17 @@ public class SpoutFeatures
} }
// update access info for all players inside a specified chunk; if specified chunk is null, then simply update everyone online // update access info for all players inside a specified chunk; if specified chunk is null, then simply update everyone online
public static void updateAccessInfoLoc(FLocation fLoc) public static void updateAccessInfoLoc(PS chunk)
{ {
if ( ! isEnabled()) return; if ( ! isEnabled()) return;
chunk = chunk.getChunk(true);
Set<FPlayer> players = FPlayerColl.i.getOnline(); Set<FPlayer> players = FPlayerColl.i.getOnline();
for (FPlayer player : players) for (FPlayer player : players)
{ {
if (fLoc == null || player.getLastStoodAt().equals(fLoc)) if (chunk == null || player.getLastStoodAt().equals(chunk))
mainListener.updateAccessInfo(player); mainListener.updateAccessInfo(player);
} }
} }

View File

@ -8,14 +8,14 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import com.massivecraft.factions.BoardOld; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.mcore.ps.PS;
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent; import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
import org.getspout.spoutapi.gui.Color; import org.getspout.spoutapi.gui.Color;
@ -72,9 +72,9 @@ public class SpoutMainListener implements Listener
if (!sPlayer.isSpoutCraftEnabled() || (ConfServer.spoutTerritoryDisplaySize <= 0 && ! ConfServer.spoutTerritoryNoticeShow)) if (!sPlayer.isSpoutCraftEnabled() || (ConfServer.spoutTerritoryDisplaySize <= 0 && ! ConfServer.spoutTerritoryNoticeShow))
return false; return false;
FLocation here = player.getLastStoodAt(); PS here = player.getLastStoodAt();
doAccessInfo(player, sPlayer, here); this.doAccessInfo(player, sPlayer, here);
return true; return true;
} }
@ -89,8 +89,8 @@ public class SpoutMainListener implements Listener
private void doLabels(FPlayer player, SpoutPlayer sPlayer, boolean notify) private void doLabels(FPlayer player, SpoutPlayer sPlayer, boolean notify)
{ {
FLocation here = player.getLastStoodAt(); PS here = player.getLastStoodAt();
Faction factionHere = BoardOld.getFactionAt(here); Faction factionHere = BoardColl.get().getFactionAt(here);
String tag = factionHere.getColorTo(player).toString() + factionHere.getTag(); String tag = factionHere.getColorTo(player).toString() + factionHere.getTag();
// ---------------------- // ----------------------
@ -156,7 +156,7 @@ public class SpoutMainListener implements Listener
private static final Color accessGrantedColor = new Color(0.2f, 1.0f, 0.2f); private static final Color accessGrantedColor = new Color(0.2f, 1.0f, 0.2f);
private static final Color accessDeniedColor = new Color(1.0f, 0.2f, 0.2f); private static final Color accessDeniedColor = new Color(1.0f, 0.2f, 0.2f);
private void doAccessInfo(FPlayer player, SpoutPlayer sPlayer, FLocation here) private void doAccessInfo(FPlayer player, SpoutPlayer sPlayer, PS here)
{ {
if (ConfServer.spoutTerritoryDisplayPosition <= 0 || ConfServer.spoutTerritoryDisplaySize <= 0 || ! ConfServer.spoutTerritoryAccessShow) return; if (ConfServer.spoutTerritoryDisplayPosition <= 0 || ConfServer.spoutTerritoryDisplaySize <= 0 || ! ConfServer.spoutTerritoryAccessShow) return;
@ -177,7 +177,7 @@ public class SpoutMainListener implements Listener
} }
String msg = ""; String msg = "";
TerritoryAccess access = BoardOld.getTerritoryAccessAt(here); TerritoryAccess access = BoardColl.get().getTerritoryAccessAt(here);
if ( ! access.isDefault()) if ( ! access.isDefault())
{ {

View File

@ -3,51 +3,73 @@ package com.massivecraft.factions.listeners;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import com.massivecraft.factions.BoardOld; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.mcore.ps.PS;
public class FactionsBlockListener implements Listener public class FactionsBlockListener implements Listener
{ {
@EventHandler(priority = EventPriority.NORMAL) public void blockFireSpread(Block block, Cancellable cancellable)
public void onBlockSpread(BlockSpreadEvent event)
{ {
if (event.isCancelled()) return; // If the faction at the block has firespread disabled ...
if (event.getSource().getTypeId() != 51) return; // Must be Fire PS ps = PS.valueOf(block);
Faction faction = BoardOld.getFactionAt(event.getBlock()); Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.getFlag(FFlag.FIRESPREAD) == false) if (faction.getFlag(FFlag.FIRESPREAD)) return;
{
event.setCancelled(true); // then cancel the event.
} cancellable.setCancelled(true);
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockBurn(BlockBurnEvent event) public void blockFireSpread(BlockIgniteEvent event)
{ {
if (event.isCancelled()) return; // If fire is spreading ...
Faction faction = BoardOld.getFactionAt(event.getBlock()); if (event.getCause() != IgniteCause.SPREAD && event.getCause() != IgniteCause.LAVA) return;
if (faction.getFlag(FFlag.FIRESPREAD) == false)
{ // ... consider blocking it.
event.setCancelled(true); blockFireSpread(event.getBlock(), event);
}
} }
// TODO: Is use of this event deprecated?
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockFireSpread(BlockSpreadEvent event)
{
// If fire is spreading ...
if (event.getNewState().getTypeId() != 51) return;
// ... consider blocking it.
blockFireSpread(event.getBlock(), event);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockFireSpread(BlockBurnEvent event)
{
// If a block is burning ...
// ... consider blocking it.
blockFireSpread(event.getBlock(), event);
}
public static boolean playerCanBuildDestroyBlock(Player player, Block block, String action, boolean justCheck) public static boolean playerCanBuildDestroyBlock(Player player, Block block, String action, boolean justCheck)
{ {
@ -62,8 +84,8 @@ public class FactionsBlockListener implements Listener
FPlayer me = FPlayerColl.i.get(name); FPlayer me = FPlayerColl.i.get(name);
if (me.hasAdminMode()) return true; if (me.hasAdminMode()) return true;
FLocation loc = new FLocation(location); PS ps = PS.valueOf(location);
Faction factionHere = BoardOld.getFactionAt(loc); Faction factionHere = BoardColl.get().getFactionAt(ps);
if ( ! FPerm.BUILD.has(me, location) && FPerm.PAINBUILD.has(me, location)) if ( ! FPerm.BUILD.has(me, location) && FPerm.PAINBUILD.has(me, location))
{ {
@ -75,7 +97,7 @@ public class FactionsBlockListener implements Listener
return true; return true;
} }
return FPerm.BUILD.has(me, loc, true); return FPerm.BUILD.has(me, ps, true);
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
@ -117,13 +139,13 @@ public class FactionsBlockListener implements Listener
if (event.isCancelled()) return; if (event.isCancelled()) return;
if ( ! ConfServer.pistonProtectionThroughDenyBuild) return; if ( ! ConfServer.pistonProtectionThroughDenyBuild) return;
Faction pistonFaction = BoardOld.getFactionAt(new FLocation(event.getBlock())); Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock()));
// target end-of-the-line empty (air) block which is being pushed into, including if piston itself would extend into air // target end-of-the-line empty (air) block which is being pushed into, including if piston itself would extend into air
Block targetBlock = event.getBlock().getRelative(event.getDirection(), event.getLength() + 1); Block targetBlock = event.getBlock().getRelative(event.getDirection(), event.getLength() + 1);
// members of faction might not have build rights in their own territory, but pistons should still work regardless; so, address that corner case // members of faction might not have build rights in their own territory, but pistons should still work regardless; so, address that corner case
Faction targetFaction = BoardOld.getFactionAt(new FLocation(targetBlock)); Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(targetBlock));
if (targetFaction == pistonFaction) return; if (targetFaction == pistonFaction) return;
// if potentially pushing into air/water/lava in another territory, we need to check it out // if potentially pushing into air/water/lava in another territory, we need to check it out
@ -150,10 +172,10 @@ public class FactionsBlockListener implements Listener
// if potentially retracted block is just air/water/lava, no worries // if potentially retracted block is just air/water/lava, no worries
if (targetLoc.getBlock().isEmpty() || targetLoc.getBlock().isLiquid()) return; if (targetLoc.getBlock().isEmpty() || targetLoc.getBlock().isLiquid()) return;
Faction pistonFaction = BoardOld.getFactionAt(new FLocation(event.getBlock())); Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock()));
// members of faction might not have build rights in their own territory, but pistons should still work regardless; so, address that corner case // members of faction might not have build rights in their own territory, but pistons should still work regardless; so, address that corner case
Faction targetFaction = BoardOld.getFactionAt(new FLocation(targetLoc)); Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(targetLoc));
if (targetFaction == pistonFaction) return; if (targetFaction == pistonFaction) return;
if ( ! FPerm.BUILD.has(pistonFaction, targetLoc)) if ( ! FPerm.BUILD.has(pistonFaction, targetLoc))

View File

@ -3,7 +3,6 @@ package com.massivecraft.factions.listeners;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -38,16 +37,16 @@ import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import com.massivecraft.factions.BoardOld; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Const; import com.massivecraft.factions.Const;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.event.PowerLossEvent; import com.massivecraft.factions.event.PowerLossEvent;
import com.massivecraft.mcore.ps.PS;
public class FactionsEntityListener implements Listener public class FactionsEntityListener implements Listener
@ -61,7 +60,8 @@ public class FactionsEntityListener implements Listener
Player player = (Player) entity; Player player = (Player) entity;
FPlayer fplayer = FPlayerColl.i.get(player); FPlayer fplayer = FPlayerColl.i.get(player);
Faction faction = BoardOld.getFactionAt(new FLocation(player.getLocation()));
Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player));
PowerLossEvent powerLossEvent = new PowerLossEvent(faction,fplayer); PowerLossEvent powerLossEvent = new PowerLossEvent(faction,fplayer);
// Check for no power loss conditions // Check for no power loss conditions
@ -117,26 +117,23 @@ public class FactionsEntityListener implements Listener
}*/ }*/
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) public void onEntityExplode(EntityExplodeEvent event)
{ {
if (event.isCancelled()) return; Iterator<Block> iter = event.blockList().iterator();
while (iter.hasNext())
{
Block block = iter.next();
Faction faction = BoardColl.get().getFactionAt(PS.valueOf(block));
if (faction.getFlag(FFlag.EXPLOSIONS) == false) iter.remove();
}
Set<FLocation> explosionLocs = new HashSet<FLocation>(); if (BoardColl.get().getFactionAt(PS.valueOf(event.getEntity())).getFlag(FFlag.EXPLOSIONS) == false)
for (Block block : event.blockList())
{ {
explosionLocs.add(new FLocation(block)); event.setCancelled(true);
} return;
for (FLocation loc : explosionLocs)
{
Faction faction = BoardOld.getFactionAt(loc);
if (faction.getFlag(FFlag.EXPLOSIONS) == false)
{
// faction has explosions disabled
event.setCancelled(true);
return;
}
} }
// TNT in water/lava doesn't normally destroy any surrounding blocks, which is usually desired behavior, but... // TNT in water/lava doesn't normally destroy any surrounding blocks, which is usually desired behavior, but...
// this optional change below provides workaround for waterwalling providing perfect protection, // this optional change below provides workaround for waterwalling providing perfect protection,
@ -231,7 +228,7 @@ public class FactionsEntityListener implements Listener
Location defenderLoc = defender.getPlayer().getLocation(); Location defenderLoc = defender.getPlayer().getLocation();
Faction defLocFaction = BoardOld.getFactionAt(new FLocation(defenderLoc)); Faction defLocFaction = BoardColl.get().getFactionAt(PS.valueOf(defenderLoc));
// for damage caused by projectiles, getDamager() returns the projectile... what we need to know is the source // for damage caused by projectiles, getDamager() returns the projectile... what we need to know is the source
if (damager instanceof Projectile) if (damager instanceof Projectile)
@ -272,7 +269,7 @@ public class FactionsEntityListener implements Listener
return false; return false;
} }
Faction locFaction = BoardOld.getFactionAt(new FLocation(attacker)); Faction locFaction = BoardColl.get().getFactionAt(PS.valueOf(damager));
// so we know from above that the defender isn't in a safezone... what about the attacker, sneaky dog that he might be? // so we know from above that the defender isn't in a safezone... what about the attacker, sneaky dog that he might be?
if (locFaction.getFlag(FFlag.PVP) == false) if (locFaction.getFlag(FFlag.PVP) == false)
@ -350,8 +347,8 @@ public class FactionsEntityListener implements Listener
if (event.isCancelled()) return; if (event.isCancelled()) return;
if (event.getLocation() == null) return; if (event.getLocation() == null) return;
FLocation floc = new FLocation(event.getLocation()); PS ps = PS.valueOf(event.getLocation());
Faction faction = BoardOld.getFactionAt(floc); Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.getFlag(FFlag.MONSTERS)) return; if (faction.getFlag(FFlag.MONSTERS)) return;
if ( ! Const.ENTITY_TYPES_MONSTERS.contains(event.getEntityType())) return; if ( ! Const.ENTITY_TYPES_MONSTERS.contains(event.getEntityType())) return;
@ -373,8 +370,8 @@ public class FactionsEntityListener implements Listener
if ( ! Const.ENTITY_TYPES_MONSTERS.contains(event.getEntity().getType())) return; if ( ! Const.ENTITY_TYPES_MONSTERS.contains(event.getEntity().getType())) return;
FLocation floc = new FLocation(target.getLocation()); PS ps = PS.valueOf(target.getLocation());
Faction faction = BoardOld.getFactionAt(floc); Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.getFlag(FFlag.MONSTERS)) return; if (faction.getFlag(FFlag.MONSTERS)) return;
@ -388,7 +385,7 @@ public class FactionsEntityListener implements Listener
if (event.getCause() == RemoveCause.EXPLOSION) if (event.getCause() == RemoveCause.EXPLOSION)
{ {
Faction faction = BoardOld.getFactionAt(new FLocation(event.getEntity().getLocation())); Faction faction = BoardColl.get().getFactionAt(PS.valueOf(event.getEntity()));
if (faction.getFlag(FFlag.EXPLOSIONS) == false) if (faction.getFlag(FFlag.EXPLOSIONS) == false)
{ // faction has explosions disabled { // faction has explosions disabled
event.setCancelled(true); event.setCancelled(true);
@ -434,8 +431,8 @@ public class FactionsEntityListener implements Listener
// for now, only interested in Enderman and Wither boss tomfoolery // for now, only interested in Enderman and Wither boss tomfoolery
if (!(entity instanceof Enderman) && !(entity instanceof Wither)) return; if (!(entity instanceof Enderman) && !(entity instanceof Wither)) return;
FLocation floc = new FLocation(event.getBlock()); PS ps = PS.valueOf(event.getBlock());
Faction faction = BoardOld.getFactionAt(floc); Faction faction = BoardColl.get().getFactionAt(ps);
if (entity instanceof Enderman) if (entity instanceof Enderman)
{ {

View File

@ -24,11 +24,10 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.util.NumberConversions; import org.bukkit.util.NumberConversions;
import com.massivecraft.factions.BoardOld; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Const; import com.massivecraft.factions.Const;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
@ -36,6 +35,7 @@ import com.massivecraft.factions.Rel;
import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.mcore.ps.PS;
public class FactionsPlayerListener implements Listener public class FactionsPlayerListener implements Listener
@ -49,10 +49,13 @@ public class FactionsPlayerListener implements Listener
// Update the lastLoginTime for this fplayer // Update the lastLoginTime for this fplayer
me.setLastLoginTime(System.currentTimeMillis()); me.setLastLoginTime(System.currentTimeMillis());
// Store player's current FLocation and notify them where they are // Store player's current Chunk and notify them where they are
me.setLastStoodAt(new FLocation(event.getPlayer().getLocation())); me.setLastStoodAt(PS.valueOf(event.getPlayer()));
if ( ! SpoutFeatures.updateTerritoryDisplay(me)) if ( ! SpoutFeatures.updateTerritoryDisplay(me))
{
me.sendFactionHereMessage(); me.sendFactionHereMessage();
}
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
@ -88,25 +91,25 @@ public class FactionsPlayerListener implements Listener
FPlayer me = FPlayerColl.i.get(player); FPlayer me = FPlayerColl.i.get(player);
// Did we change coord? // Did we change coord?
FLocation from = me.getLastStoodAt(); PS from = me.getLastStoodAt();
FLocation to = new FLocation(event.getTo()); PS to = PS.valueOf(event.getTo()).getChunk(true);
if (from.equals(to)) return; if (from.equals(to)) return;
// Yes we did change coord (: // Yes we did change coord (:
me.setLastStoodAt(to); me.setLastStoodAt(to);
TerritoryAccess access = BoardOld.getTerritoryAccessAt(to); TerritoryAccess access = BoardColl.get().getTerritoryAccessAt(to);
// Did we change "host"(faction)? // Did we change "host"(faction)?
boolean changedFaction = (BoardOld.getFactionAt(from) != access.getHostFaction()); boolean changedFaction = (BoardColl.get().getFactionAt(from) != access.getHostFaction());
// let Spout handle most of this if it's available // let Spout handle most of this if it's available
boolean handledBySpout = changedFaction && SpoutFeatures.updateTerritoryDisplay(me); boolean handledBySpout = changedFaction && SpoutFeatures.updateTerritoryDisplay(me);
if (me.isMapAutoUpdating()) if (me.isMapAutoUpdating())
{ {
me.sendMessage(BoardOld.getMap(me.getFaction(), to, player.getLocation().getYaw())); me.sendMessage(BoardColl.get().getMap(me.getFaction(), to, player.getLocation().getYaw()));
} }
else if (changedFaction && ! handledBySpout) else if (changedFaction && ! handledBySpout)
{ {
@ -303,7 +306,7 @@ public class FactionsPlayerListener implements Listener
} }
Rel rel = me.getRelationToLocation(); Rel rel = me.getRelationToLocation();
if (BoardOld.getFactionAt(me.getLastStoodAt()).isNone()) return; if (BoardColl.get().getFactionAt(me.getLastStoodAt()).isNone()) return;
if (rel == Rel.NEUTRAL && isCommandInList(fullCmd, ConfServer.territoryNeutralDenyCommands)) if (rel == Rel.NEUTRAL && isCommandInList(fullCmd, ConfServer.territoryNeutralDenyCommands))
{ {