From f8f3704cd41abb6ab16d1833b2cc9a209ff66c36 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sun, 23 Oct 2011 12:50:02 -0500 Subject: [PATCH] Additional logging, with new conf.json settings to enable/disable logging of specific events: "logFactionCreate": true, - log faction creation "logFactionDisband": true, - log factions being disbanded, by command or by circumstance "logFactionJoin": true, - log player joining a faction "logFactionKick": true, - log player being kicked from a faction "logFactionLeave": true, - log player leaving a faction "logLandClaims": true, - log land being claimed (including safe zone and war zone) "logLandUnclaims": true, - log land being unclaimed (including safe zone and war zone) "logMoneyTransactions": true, - log money being deposited, withdrawn, and otherwise transferred in relation to faction banks Also a fix for a potential NPE from players logging out and Spout appearance handler referencing them afterwards --- src/com/massivecraft/factions/Conf.java | 10 ++++++++++ src/com/massivecraft/factions/FPlayer.java | 9 +++++++++ src/com/massivecraft/factions/cmd/CmdCreate.java | 4 ++++ src/com/massivecraft/factions/cmd/CmdDisband.java | 6 ++++-- src/com/massivecraft/factions/cmd/CmdJoin.java | 4 ++++ src/com/massivecraft/factions/cmd/CmdKick.java | 7 +++++++ .../massivecraft/factions/cmd/CmdMoneyDeposit.java | 5 +++++ .../factions/cmd/CmdMoneyTransferFf.java | 11 ++++++++--- .../factions/cmd/CmdMoneyTransferFp.java | 12 +++++++++--- .../factions/cmd/CmdMoneyTransferPf.java | 12 +++++++++--- .../factions/cmd/CmdMoneyWithdraw.java | 5 +++++ .../factions/cmd/CmdSafeunclaimall.java | 5 +++++ src/com/massivecraft/factions/cmd/CmdUnclaim.java | 14 ++++++++++++++ .../massivecraft/factions/cmd/CmdUnclaimall.java | 4 ++++ .../factions/cmd/CmdWarunclaimall.java | 5 +++++ .../factions/integration/SpoutFeatures.java | 3 +++ 16 files changed, 105 insertions(+), 11 deletions(-) diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index fff1c4e2..038b669e 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -68,6 +68,16 @@ public class Conf public static double autoLeaveAfterDaysOfInactivity = 10.0; public static boolean worldGuardChecking = false; + + // server logging options + public static boolean logFactionCreate = true; + public static boolean logFactionDisband = true; + public static boolean logFactionJoin = true; + public static boolean logFactionKick = true; + public static boolean logFactionLeave = true; + public static boolean logLandClaims = true; + public static boolean logLandUnclaims = true; + public static boolean logMoneyTransactions = true; public static boolean homesEnabled = true; public static boolean homesMustBeInClaimedTerritory = true; diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 463f8d16..62f9cd07 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -611,6 +611,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator { fplayer.msg("%s left %s.", this.describeTo(fplayer, true), myFaction.describeTo(fplayer)); } + + if (Conf.logFactionLeave) + P.p.log(this.getName()+" left the faction: "+myFaction.getTag()); } this.resetFactionData(); @@ -624,6 +627,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator } myFaction.detach(); + if (Conf.logFactionDisband) + P.p.log("The faction "+myFaction.getTag()+" ("+myFaction.getId()+") was disbanded due to the last player ("+this.getName()+") leaving."); } } @@ -772,6 +777,10 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator Board.setFactionAt(forFaction, flocation); SpoutFeatures.updateTerritoryDisplayLoc(flocation); + + if (Conf.logLandClaims) + P.p.log(this.getName()+" claimed land at ("+flocation.getCoordString()+") for the faction: "+forFaction.getTag()); + return true; } diff --git a/src/com/massivecraft/factions/cmd/CmdCreate.java b/src/com/massivecraft/factions/cmd/CmdCreate.java index 965616eb..fd9b0b88 100644 --- a/src/com/massivecraft/factions/cmd/CmdCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdCreate.java @@ -7,6 +7,7 @@ import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; @@ -76,6 +77,9 @@ public class CmdCreate extends FCommand } msg("You should now: %s", p.cmdBase.cmdDescription.getUseageTemplate()); + + if (Conf.logFactionCreate) + P.p.log(fme.getName()+" created a new faction: "+tag); } } diff --git a/src/com/massivecraft/factions/cmd/CmdDisband.java b/src/com/massivecraft/factions/cmd/CmdDisband.java index b3cc410b..a1cb62ff 100644 --- a/src/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdDisband.java @@ -1,5 +1,6 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.Conf; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; @@ -69,7 +70,8 @@ public class CmdDisband extends FCommand fplayer.msg("%s disbanded the faction %s.", who, faction.getTag(fplayer)); } } - P.p.log("The faction "+faction.getTag()+" ("+faction.getId()+") was disbanded by "+(senderIsConsole ? "console command" : fme.getName())+"."); + if (Conf.logFactionDisband) + P.p.log("The faction "+faction.getTag()+" ("+faction.getId()+") was disbanded by "+(senderIsConsole ? "console command" : fme.getName())+"."); if (Econ.shouldBeUsed()) { @@ -87,7 +89,7 @@ public class CmdDisband extends FCommand } faction.detach(); - + SpoutFeatures.updateAppearances(); } } diff --git a/src/com/massivecraft/factions/cmd/CmdJoin.java b/src/com/massivecraft/factions/cmd/CmdJoin.java index bfe80358..8560eb5c 100644 --- a/src/com/massivecraft/factions/cmd/CmdJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdJoin.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Permission; public class CmdJoin extends FCommand @@ -69,5 +70,8 @@ public class CmdJoin extends FCommand fme.resetFactionData(); fme.setFaction(faction); faction.deinvite(fme); + + if (Conf.logFactionJoin) + P.p.log(fme.getName()+" joined the faction: "+faction.getTag()); } } diff --git a/src/com/massivecraft/factions/cmd/CmdKick.java b/src/com/massivecraft/factions/cmd/CmdKick.java index 8dbbca99..2318a855 100644 --- a/src/com/massivecraft/factions/cmd/CmdKick.java +++ b/src/com/massivecraft/factions/cmd/CmdKick.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Permission; public class CmdKick extends FCommand @@ -77,6 +78,9 @@ public class CmdKick extends FCommand yourFaction.deinvite(you); you.resetFactionData(); + if (Conf.logFactionKick) + P.p.log(fme.getName()+" kicked "+you.getName()+" from the faction: "+yourFaction.getTag()); + if (yourFaction.getFPlayers().isEmpty() && !yourFaction.isPermanent()) { // Remove this faction @@ -85,6 +89,9 @@ public class CmdKick extends FCommand fplayer.msg("The faction %s was disbanded.", yourFaction.getTag(fplayer)); } yourFaction.detach(); + + if (Conf.logFactionDisband) + P.p.log("The faction "+yourFaction.getTag()+" ("+yourFaction.getId()+") was disbanded since the last player was kicked by "+(senderIsConsole ? "console command" : fme.getName())+"."); } } diff --git a/src/com/massivecraft/factions/cmd/CmdMoneyDeposit.java b/src/com/massivecraft/factions/cmd/CmdMoneyDeposit.java index a4a69071..52183d02 100644 --- a/src/com/massivecraft/factions/cmd/CmdMoneyDeposit.java +++ b/src/com/massivecraft/factions/cmd/CmdMoneyDeposit.java @@ -1,6 +1,8 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.P; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; @@ -33,6 +35,9 @@ public class CmdMoneyDeposit extends FCommand Faction faction = this.argAsFaction(1, myFaction); if (faction == null) return; Econ.transferMoney(fme, fme, faction, amount); + + if (Conf.logMoneyTransactions) + P.p.log(fme.getName()+" deposited "+Econ.moneyString(amount)+" into the faction bank: "+faction.getTag()); } } diff --git a/src/com/massivecraft/factions/cmd/CmdMoneyTransferFf.java b/src/com/massivecraft/factions/cmd/CmdMoneyTransferFf.java index 08615c01..ae869825 100644 --- a/src/com/massivecraft/factions/cmd/CmdMoneyTransferFf.java +++ b/src/com/massivecraft/factions/cmd/CmdMoneyTransferFf.java @@ -1,6 +1,8 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.iface.EconomyParticipator; +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.P; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; @@ -30,11 +32,14 @@ public class CmdMoneyTransferFf extends FCommand public void perform() { double amount = this.argAsDouble(0, 0d); - EconomyParticipator from = this.argAsFaction(1); + Faction from = this.argAsFaction(1); if (from == null) return; - EconomyParticipator to = this.argAsFaction(2); + Faction to = this.argAsFaction(2); if (to == null) return; Econ.transferMoney(fme, from, to, amount); + + if (Conf.logMoneyTransactions) + P.p.log(fme.getName()+" transferred "+Econ.moneyString(amount)+" from the faction \""+from.getTag()+"\" to the faction \""+to.getTag()+"\""); } } diff --git a/src/com/massivecraft/factions/cmd/CmdMoneyTransferFp.java b/src/com/massivecraft/factions/cmd/CmdMoneyTransferFp.java index 30435a87..7887f590 100644 --- a/src/com/massivecraft/factions/cmd/CmdMoneyTransferFp.java +++ b/src/com/massivecraft/factions/cmd/CmdMoneyTransferFp.java @@ -1,6 +1,9 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.iface.EconomyParticipator; +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.P; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; @@ -30,11 +33,14 @@ public class CmdMoneyTransferFp extends FCommand public void perform() { double amount = this.argAsDouble(0, 0d); - EconomyParticipator from = this.argAsFaction(1); + Faction from = this.argAsFaction(1); if (from == null) return; - EconomyParticipator to = this.argAsBestFPlayerMatch(2); + FPlayer to = this.argAsBestFPlayerMatch(2); if (to == null) return; Econ.transferMoney(fme, from, to, amount); + + if (Conf.logMoneyTransactions) + P.p.log(fme.getName()+" transferred "+Econ.moneyString(amount)+" from the faction \""+from.getTag()+"\" to the player \""+to.getName()+"\""); } } diff --git a/src/com/massivecraft/factions/cmd/CmdMoneyTransferPf.java b/src/com/massivecraft/factions/cmd/CmdMoneyTransferPf.java index ac1af4bb..5e881cd3 100644 --- a/src/com/massivecraft/factions/cmd/CmdMoneyTransferPf.java +++ b/src/com/massivecraft/factions/cmd/CmdMoneyTransferPf.java @@ -1,6 +1,9 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.iface.EconomyParticipator; +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.P; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; @@ -30,11 +33,14 @@ public class CmdMoneyTransferPf extends FCommand public void perform() { double amount = this.argAsDouble(0, 0d); - EconomyParticipator from = this.argAsBestFPlayerMatch(1); + FPlayer from = this.argAsBestFPlayerMatch(1); if (from == null) return; - EconomyParticipator to = this.argAsFaction(2); + Faction to = this.argAsFaction(2); if (to == null) return; Econ.transferMoney(fme, from, to, amount); + + if (Conf.logMoneyTransactions) + P.p.log(fme.getName()+" transferred "+Econ.moneyString(amount)+" from the player \""+from.getName()+"\" to the faction \""+to.getTag()+"\""); } } diff --git a/src/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java b/src/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java index 2b588d17..b394e9e0 100644 --- a/src/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java +++ b/src/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java @@ -1,6 +1,8 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.P; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; @@ -30,5 +32,8 @@ public class CmdMoneyWithdraw extends FCommand Faction faction = this.argAsFaction(1, myFaction); if (faction == null) return; Econ.transferMoney(fme, faction, fme, amount); + + if (Conf.logMoneyTransactions) + P.p.log(fme.getName()+" withdrew "+Econ.moneyString(amount)+" from the faction bank: "+faction.getTag()); } } diff --git a/src/com/massivecraft/factions/cmd/CmdSafeunclaimall.java b/src/com/massivecraft/factions/cmd/CmdSafeunclaimall.java index 16cc36e5..08a90c8f 100644 --- a/src/com/massivecraft/factions/cmd/CmdSafeunclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdSafeunclaimall.java @@ -1,7 +1,9 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Board; +import com.massivecraft.factions.Conf; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Permission; public class CmdSafeunclaimall extends FCommand @@ -31,6 +33,9 @@ public class CmdSafeunclaimall extends FCommand { Board.unclaimAll(Factions.i.getSafeZone().getId()); msg("You unclaimed ALL safe zone land."); + + if (Conf.logLandUnclaims) + P.p.log(fme.getName()+" unclaimed all safe zones."); } } diff --git a/src/com/massivecraft/factions/cmd/CmdUnclaim.java b/src/com/massivecraft/factions/cmd/CmdUnclaim.java index f203fd04..f643e615 100644 --- a/src/com/massivecraft/factions/cmd/CmdUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdUnclaim.java @@ -6,6 +6,7 @@ import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; @@ -41,6 +42,9 @@ public class CmdUnclaim extends FCommand Board.removeAt(flocation); SpoutFeatures.updateTerritoryDisplayLoc(flocation); msg("Safe zone was unclaimed."); + + if (Conf.logLandUnclaims) + P.p.log(fme.getName()+" unclaimed land at ("+flocation.getCoordString()+") from the faction: "+otherFaction.getTag()); } else { @@ -55,6 +59,9 @@ public class CmdUnclaim extends FCommand Board.removeAt(flocation); SpoutFeatures.updateTerritoryDisplayLoc(flocation); msg("War zone was unclaimed."); + + if (Conf.logLandUnclaims) + P.p.log(fme.getName()+" unclaimed land at ("+flocation.getCoordString()+") from the faction: "+otherFaction.getTag()); } else { @@ -70,6 +77,10 @@ public class CmdUnclaim extends FCommand otherFaction.msg("%s unclaimed some of your land.", fme.describeTo(otherFaction, true)); msg("You unclaimed this land."); + + if (Conf.logLandUnclaims) + P.p.log(fme.getName()+" unclaimed land at ("+flocation.getCoordString()+") from the faction: "+otherFaction.getTag()); + return; } @@ -154,6 +165,9 @@ public class CmdUnclaim extends FCommand Board.removeAt(flocation); SpoutFeatures.updateTerritoryDisplayLoc(flocation); myFaction.msg("%s unclaimed some land.", fme.describeTo(myFaction, true)); + + if (Conf.logLandUnclaims) + P.p.log(fme.getName()+" unclaimed land at ("+flocation.getCoordString()+") from the faction: "+otherFaction.getTag()); } } diff --git a/src/com/massivecraft/factions/cmd/CmdUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdUnclaimall.java index 0a6a73af..00ea10f7 100644 --- a/src/com/massivecraft/factions/cmd/CmdUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdUnclaimall.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; +import com.massivecraft.factions.P; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.struct.Permission; @@ -44,6 +45,9 @@ public class CmdUnclaimall extends FCommand Board.unclaimAll(myFaction.getId()); myFaction.msg("%s unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true)); SpoutFeatures.updateTerritoryDisplayLoc(null); + + if (Conf.logLandUnclaims) + P.p.log(fme.getName()+" unclaimed everything for the faction: "+myFaction.getTag()); } } diff --git a/src/com/massivecraft/factions/cmd/CmdWarunclaimall.java b/src/com/massivecraft/factions/cmd/CmdWarunclaimall.java index 4caac2eb..4e3c10f7 100644 --- a/src/com/massivecraft/factions/cmd/CmdWarunclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdWarunclaimall.java @@ -1,7 +1,9 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Board; +import com.massivecraft.factions.Conf; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Permission; public class CmdWarunclaimall extends FCommand @@ -31,6 +33,9 @@ public class CmdWarunclaimall extends FCommand { Board.unclaimAll(Factions.i.getWarZone().getId()); msg("You unclaimed ALL war zone land."); + + if (Conf.logLandUnclaims) + P.p.log(fme.getName()+" unclaimed all war zones."); } } diff --git a/src/com/massivecraft/factions/integration/SpoutFeatures.java b/src/com/massivecraft/factions/integration/SpoutFeatures.java index 1eda111f..905279db 100644 --- a/src/com/massivecraft/factions/integration/SpoutFeatures.java +++ b/src/com/massivecraft/factions/integration/SpoutFeatures.java @@ -221,6 +221,9 @@ public class SpoutFeatures SpoutPlayer sPlayer = SpoutManager.getPlayer(viewer.getPlayer()); Player pViewed = viewed.getPlayer(); + if (pViewed == null || viewer.getPlayer() == null) + return; + String viewedTitle = viewed.getTitle(); Role viewedRole = viewed.getRole();