From 825d937c841eb31f2f5354e4f8b9765c374da56d Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 24 Apr 2013 08:39:26 +0200 Subject: [PATCH] Moved the last stuff away from ConfServer. --- src/com/massivecraft/factions/ConfServer.java | 78 +------------------ src/com/massivecraft/factions/Factions.java | 10 +-- src/com/massivecraft/factions/Rel.java | 13 ---- .../factions/cmd/CmdFactionsClaim.java | 4 +- .../factions/cmd/CmdFactionsLeave.java | 2 +- .../factions/cmd/CmdFactionsShow.java | 9 ++- .../factions/cmd/CmdFactionsUnclaim.java | 4 +- .../factions/cmd/CmdFactionsUnclaimall.java | 5 +- .../cmd/req/ReqBankCommandsEnabled.java | 7 +- .../massivecraft/factions/entity/Board.java | 2 +- .../factions/entity/FactionColl.java | 50 ++++++------ .../massivecraft/factions/entity/MConf.java | 13 +++- .../massivecraft/factions/entity/UConf.java | 66 +++++++++++++++- .../massivecraft/factions/entity/UPlayer.java | 28 +++---- .../factions/entity/UPlayerColl.java | 8 +- .../factions/integration/Econ.java | 24 ++++-- .../factions/integration/Worldguard.java | 10 +-- .../listeners/FactionsListenerEcon.java | 30 +++---- .../listeners/FactionsListenerMain.java | 6 +- .../factions/task/EconRewardTask.java | 7 +- .../factions/task/PowerUpdateTask.java | 4 +- ...aveTask.java => RemovePlayerDataTask.java} | 15 ++-- 22 files changed, 195 insertions(+), 200 deletions(-) rename src/com/massivecraft/factions/task/{AutoLeaveTask.java => RemovePlayerDataTask.java} (61%) diff --git a/src/com/massivecraft/factions/ConfServer.java b/src/com/massivecraft/factions/ConfServer.java index 8dd6ca49..aaa10d3a 100644 --- a/src/com/massivecraft/factions/ConfServer.java +++ b/src/com/massivecraft/factions/ConfServer.java @@ -16,86 +16,10 @@ public class ConfServer extends SimpleConfig public ConfServer() { super(Factions.get()); } // -------------------------------------------- // - // CORE + // FIELDS // -------------------------------------------- // public static List baseCommandAliases = MUtil.list("f"); public static String dburi = "default"; - // -------------------------------------------- // - // AUTO LEAVE - // -------------------------------------------- // - - public static double autoLeaveAfterDaysOfInactivity = 10.0; - public static double autoLeaveRoutineRunsEveryXMinutes = 5.0; - public static boolean removePlayerDataWhenBanned = true; - - // -------------------------------------------- // - // CLAIMS - // -------------------------------------------- // - - public static boolean claimsMustBeConnected = false; - public static boolean claimingFromOthersAllowed = true; - public static boolean claimsCanBeUnconnectedIfOwnedByOtherFaction = true; - public static int claimsRequireMinFactionMembers = 1; - public static int claimedLandsMax = 0; - - // if someone is doing a radius claim and the process fails to claim land this many times in a row, it will exit - public static int radiusClaimFailureLimit = 9; - - - - // -------------------------------------------- // - // INTEGRATION: WORLD GUARD - // -------------------------------------------- // - - public static boolean worldGuardChecking = false; - - - - // -------------------------------------------- // - // INTEGRATION: ECONOMY - // -------------------------------------------- // - - public static int econLandRewardTaskRunsEveryXMinutes = 20; - - public static boolean econEnabled = false; - - // TODO: Rename to include unit. - public static double econLandReward = 0.00; - - public static String econUniverseAccount = ""; - - public static double econCostClaimWilderness = 30.0; - public static double econCostClaimFromFactionBonus = 30.0; - public static double econClaimAdditionalMultiplier = 0.5; - public static double econClaimRefundMultiplier = 0.7; - public static double econClaimUnconnectedFee = 0.0; - - public static double econCostCreate = 100.0; - public static double econCostSethome = 30.0; - public static double econCostJoin = 0.0; - public static double econCostLeave = 0.0; - public static double econCostKick = 0.0; - public static double econCostInvite = 0.0; - public static double econCostDeinvite = 0.0; - public static double econCostHome = 0.0; - public static double econCostTag = 0.0; - public static double econCostDescription = 0.0; - public static double econCostTitle = 0.0; - public static double econCostOpen = 0.0; - public static double econCostAlly = 0.0; - public static double econCostTruce = 0.0; - public static double econCostNeutral = 0.0; - public static double econCostEnemy = 0.0; - - - - //Faction banks, to pay for land claiming and other costs instead of individuals paying for them - public static boolean bankEnabled = true; - //public static boolean bankMembersCanWithdraw = false; //Have to be at least moderator to withdraw or pay money to another faction - public static boolean bankFactionPaysCosts = true; //The faction pays for faction command costs, such as sethome - public static boolean bankFactionPaysLandCosts = true; //The faction pays for land claiming costs. - } - diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 1bcfc324..89767c13 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -34,7 +34,7 @@ import com.massivecraft.factions.listeners.FactionsListenerMain; import com.massivecraft.factions.listeners.TodoFactionsPlayerListener; import com.massivecraft.factions.mixin.PowerMixin; import com.massivecraft.factions.mixin.PowerMixinDefault; -import com.massivecraft.factions.task.AutoLeaveTask; +import com.massivecraft.factions.task.RemovePlayerDataTask; import com.massivecraft.factions.task.EconRewardTask; import com.massivecraft.factions.task.PowerUpdateTask; @@ -137,7 +137,7 @@ public class Factions extends MPlugin // Schedule recurring non-tps-dependent tasks PowerUpdateTask.get().schedule(this); - AutoLeaveTask.get().schedule(this); + RemovePlayerDataTask.get().schedule(this); EconRewardTask.get().schedule(this); // Register built in chat modifiers @@ -160,11 +160,7 @@ public class Factions extends MPlugin this.integrate(HerochatFeatures.get()); LWCFeatures.setup(); - - if (ConfServer.worldGuardChecking) - { - Worldguard.init(this); - } + Worldguard.init(this); postEnable(); } diff --git a/src/com/massivecraft/factions/Rel.java b/src/com/massivecraft/factions/Rel.java index ce595e8e..08f79d0e 100644 --- a/src/com/massivecraft/factions/Rel.java +++ b/src/com/massivecraft/factions/Rel.java @@ -157,17 +157,4 @@ public enum Rel return ""; } - // TODO: ADD TRUCE!!!! - // TODO.... or remove it... - public double getRelationCost() - { - if (this == ENEMY) - return ConfServer.econCostEnemy; - else if (this == ALLY) - return ConfServer.econCostAlly; - else if (this == TRUCE) - return ConfServer.econCostTruce; - else - return ConfServer.econCostNeutral; - } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java index c48b28b8..016be03d 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java @@ -1,9 +1,9 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.task.SpiralTask; import com.massivecraft.mcore.cmd.arg.ARInteger; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -59,7 +59,7 @@ public class CmdFactionsClaim extends FCommand new SpiralTask(PS.valueOf(me), radius) { private int failCount = 0; - private final int limit = ConfServer.radiusClaimFailureLimit - 1; + private final int limit = UConf.get(me).radiusClaimFailureLimit - 1; @Override public boolean work() diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java b/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java index c2e02349..3697c4e6 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java @@ -18,7 +18,7 @@ public class CmdFactionsLeave extends FCommand { @Override public void perform() { - fme.leave(true); + fme.leave(); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java index 4e22857a..8264418f 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java @@ -5,8 +5,8 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.integration.Econ; @@ -65,7 +65,8 @@ public class CmdFactionsShow extends FCommand if (Econ.isEnabled(faction)) { double value = Econ.calculateTotalLandValue(faction.getLandCount()); - double refund = value * ConfServer.econClaimRefundMultiplier; + + double refund = value * UConf.get(faction).econClaimRefundMultiplier; if (value > 0) { String stringValue = Money.format(faction, value); @@ -73,8 +74,8 @@ public class CmdFactionsShow extends FCommand msg("Total land value: " + stringValue + stringRefund); } - //Show bank contents - if(ConfServer.bankEnabled) + // Show bank contents + if(UConf.get(faction).bankEnabled) { msg("Bank contains: "+Money.format(faction, Money.get(faction))); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java index 4056bf0f..0fff61c3 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java @@ -1,9 +1,9 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.event.FactionsEventLandUnclaim; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FPerm; @@ -43,7 +43,7 @@ public class CmdFactionsUnclaim extends FCommand { double refund = Econ.calculateClaimRefund(myFaction); - if (ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts) + if (UConf.get(myFaction).bankEnabled && UConf.get(myFaction).bankFactionPaysLandCosts) { if ( ! Econ.modifyMoney(myFaction, refund, "unclaim this land")) return; } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java index 65976c0c..cb2f47fc 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java @@ -1,12 +1,12 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.event.FactionsEventLandUnclaimAll; import com.massivecraft.factions.integration.Econ; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -28,7 +28,8 @@ public class CmdFactionsUnclaimall extends FCommand if (Econ.isEnabled(myFaction)) { double refund = Econ.calculateTotalLandRefund(myFaction.getLandCount()); - if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts) + + if (UConf.get(myFaction).bankEnabled && UConf.get(myFaction).bankFactionPaysLandCosts) { if ( ! Econ.modifyMoney(myFaction, refund, "unclaim all faction land")) return; } diff --git a/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java b/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java index e4838316..07c41230 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java +++ b/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java @@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd.req; import org.bukkit.command.CommandSender; -import com.massivecraft.factions.ConfServer; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.mcore.cmd.MCommand; import com.massivecraft.mcore.cmd.req.ReqAbstract; import com.massivecraft.mcore.util.Txt; @@ -25,17 +25,16 @@ public class ReqBankCommandsEnabled extends ReqAbstract @Override public boolean apply(CommandSender sender, MCommand command) { - return ConfServer.econEnabled && ConfServer.bankEnabled; + return UConf.get(sender).econEnabled && UConf.get(sender).bankEnabled; } @Override public String createErrorMessage(CommandSender sender, MCommand command) { - if (!ConfServer.bankEnabled) + if (!UConf.get(sender).bankEnabled) { return Txt.parse("The Factions bank system is disabled on this server."); } - return Txt.parse("The Factions economy features are disabled on this server."); } diff --git a/src/com/massivecraft/factions/entity/Board.java b/src/com/massivecraft/factions/entity/Board.java index 870dbee3..b9447ce0 100644 --- a/src/com/massivecraft/factions/entity/Board.java +++ b/src/com/massivecraft/factions/entity/Board.java @@ -111,7 +111,7 @@ public class Board extends Entity implements BoardInterface { // TODO: Listen to an event instead! // NOTE: And this is probably the place where the event should be triggered! - if (UConf.get(ps).onUnclaimResetLwcLocks && LWCFeatures.getEnabled()) + if (UConf.get(ps).lwcRemoveOnUnclaim && LWCFeatures.getEnabled()) { LWCFeatures.clearAllProtections(ps); } diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index b6c639b2..4ef8510b 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -120,6 +120,34 @@ public class FactionColl extends Coll return this.get(Const.FACTIONID_NONE); } + // -------------------------------------------- // + // LAND REWARD + // -------------------------------------------- // + + public void econLandRewardRoutine() + { + if (!Econ.isEnabled(this.getUniverse())) return; + + double econLandReward = UConf.get(this).econLandReward; + if (econLandReward == 0.0) return; + + Factions.get().log("Running econLandRewardRoutine..."); + for (Faction faction : this.getAll()) + { + int landCount = faction.getLandCount(); + if (!faction.getFlag(FFlag.PEACEFUL) && landCount > 0) + { + List players = faction.getUPlayers(); + int playerCount = players.size(); + double reward = econLandReward * landCount / playerCount; + for (UPlayer player : players) + { + Econ.modifyMoney(player, reward, "own " + landCount + " faction land divided among " + playerCount + " members"); + } + } + } + } + // -------------------------------------------- // // FACTION TAG // -------------------------------------------- // @@ -181,28 +209,6 @@ public class FactionColl extends Coll { return this.getByTag(str) != null; } - - public void econLandRewardRoutine() - { - if (!Econ.isEnabled(this.getUniverse())) return; - if (ConfServer.econLandReward == 0.0) return; - - Factions.get().log("Running econLandRewardRoutine..."); - for (Faction faction : this.getAll()) - { - int landCount = faction.getLandCount(); - if (!faction.getFlag(FFlag.PEACEFUL) && landCount > 0) - { - List players = faction.getUPlayers(); - int playerCount = players.size(); - double reward = ConfServer.econLandReward * landCount / playerCount; - for (UPlayer player : players) - { - Econ.modifyMoney(player, reward, "own " + landCount + " faction land divided among " + playerCount + " members"); - } - } - } - } // -------------------------------------------- // // CREATE DEFAULT FACTIONS diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index 7fe72db0..bcdb22ef 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -35,10 +35,19 @@ public class MConf extends Entity } // -------------------------------------------- // - // POWER + // TASKS // -------------------------------------------- // - public long powerTaskMillis = TimeUnit.MILLIS_PER_MINUTE; + public long taskPowerMillis = TimeUnit.MILLIS_PER_MINUTE; + public long taskEconMillis = 20 * TimeUnit.MILLIS_PER_MINUTE; + public long taskAutoLeaveMillis = 5 * TimeUnit.MILLIS_PER_MINUTE; + + // -------------------------------------------- // + // REMOVE DATA + // -------------------------------------------- // + + public boolean removePlayerDataWhenBanned = true; + public double removePlayerDataAfterInactiveDays = 20.0; // -------------------------------------------- // // CHAT diff --git a/src/com/massivecraft/factions/entity/UConf.java b/src/com/massivecraft/factions/entity/UConf.java index 75d6298c..f8759e32 100644 --- a/src/com/massivecraft/factions/entity/UConf.java +++ b/src/com/massivecraft/factions/entity/UConf.java @@ -73,6 +73,19 @@ public class UConf extends Entity public boolean canLeaveWithNegativePower = true; + // -------------------------------------------- // + // CLAIMS + // -------------------------------------------- // + + public boolean claimsMustBeConnected = false; + public boolean claimingFromOthersAllowed = true; + public boolean claimsCanBeUnconnectedIfOwnedByOtherFaction = true; + public int claimsRequireMinFactionMembers = 1; + public int claimedLandsMax = 0; + + // if someone is doing a radius claim and the process fails to claim land this many times in a row, it will exit + public int radiusClaimFailureLimit = 9; + // -------------------------------------------- // // HOMES // -------------------------------------------- // @@ -100,12 +113,61 @@ public class UConf extends Entity Rel.ALLY, new ArrayList(), Rel.MEMBER, new ArrayList() ); + + // -------------------------------------------- // + // INTEGRATION: WORLD GUARD + // -------------------------------------------- // + + public boolean worldGuardChecking = false; // -------------------------------------------- // // INTEGRATION: LWC // -------------------------------------------- // - public boolean onUnclaimResetLwcLocks = false; - public boolean onCaptureResetLwcLocks = false; + public boolean lwcRemoveOnUnclaim = false; + public boolean lwcRemoveOnCapture = false; + + // -------------------------------------------- // + // INTEGRATION: ECONOMY + // -------------------------------------------- // + + public boolean econEnabled = false; + + // TODO: Rename to include unit. + public double econLandReward = 0.00; + + public String econUniverseAccount = ""; + + public double econCostClaimWilderness = 30.0; + public double econCostClaimFromFactionBonus = 30.0; + public double econClaimAdditionalMultiplier = 0.5; + public double econClaimRefundMultiplier = 0.7; + public double econClaimUnconnectedFee = 0.0; + + public double econCostCreate = 100.0; + public double econCostSethome = 0.0; + public double econCostJoin = 0.0; + public double econCostLeave = 0.0; + public double econCostKick = 0.0; + public double econCostInvite = 0.0; + public double econCostDeinvite = 0.0; + public double econCostHome = 0.0; + public double econCostTag = 0.0; + public double econCostDescription = 0.0; + public double econCostTitle = 0.0; + public double econCostOpen = 0.0; + + public Map econRelCost = MUtil.map( + Rel.ENEMY, 0.0, + Rel.ALLY, 0.0, + Rel.TRUCE, 0.0, + Rel.NEUTRAL, 0.0 + ); + + //Faction banks, to pay for land claiming and other costs instead of individuals paying for them + public boolean bankEnabled = true; + //public static boolean bankMembersCanWithdraw = false; //Have to be at least moderator to withdraw or pay money to another faction + public boolean bankFactionPaysCosts = true; //The faction pays for faction command costs, such as sethome + public boolean bankFactionPaysLandCosts = true; //The faction pays for land claiming costs. } diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index 3c99a4b5..37dfcc0e 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -6,7 +6,6 @@ import java.util.Set; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Const; import com.massivecraft.factions.EconomyParticipator; import com.massivecraft.factions.FFlag; @@ -487,7 +486,7 @@ public class UPlayer extends SenderEntity implements EconomyParticipato // ACTIONS // -------------------------------------------- // - public void leave(boolean makePay) + public void leave() { Faction myFaction = this.getFaction(); @@ -559,7 +558,9 @@ public class UPlayer extends SenderEntity implements EconomyParticipato Faction currentFaction = BoardColls.get().getFactionAt(ps); int ownedLand = forFaction.getLandCount(); - if (ConfServer.worldGuardChecking && Worldguard.checkForRegionsInChunk(ps)) + UConf uconf = UConf.get(ps); + + if (uconf.worldGuardChecking && Worldguard.checkForRegionsInChunk(ps)) { // Checks for WorldGuard regions in the chunk attempting to be claimed error = Txt.parse("This land is protected"); @@ -580,19 +581,19 @@ public class UPlayer extends SenderEntity implements EconomyParticipato { return false; } - else if (forFaction.getUPlayers().size() < ConfServer.claimsRequireMinFactionMembers) + else if (forFaction.getUPlayers().size() < uconf.claimsRequireMinFactionMembers) { - error = Txt.parse("Factions must have at least %s members to claim land.", ConfServer.claimsRequireMinFactionMembers); + error = Txt.parse("Factions must have at least %s members to claim land.", uconf.claimsRequireMinFactionMembers); } else if (ownedLand >= forFaction.getPowerRounded()) { error = Txt.parse("You can't claim more land! You need more power!"); } - else if (ConfServer.claimedLandsMax != 0 && ownedLand >= ConfServer.claimedLandsMax && ! forFaction.getFlag(FFlag.INFPOWER)) + else if (uconf.claimedLandsMax != 0 && ownedLand >= uconf.claimedLandsMax && ! forFaction.getFlag(FFlag.INFPOWER)) { error = Txt.parse("Limit reached. You can't claim more land!"); } - else if ( ! ConfServer.claimingFromOthersAllowed && currentFaction.isNormal()) + else if ( ! uconf.claimingFromOthersAllowed && currentFaction.isNormal()) { error = Txt.parse("You may not claim land from others."); } @@ -602,14 +603,14 @@ public class UPlayer extends SenderEntity implements EconomyParticipato } else if ( - ConfServer.claimsMustBeConnected + uconf.claimsMustBeConnected && ! this.isUsingAdminMode() && myFaction.getLandCountInWorld(ps.getWorld()) > 0 && !BoardColls.get().isConnectedPs(ps, myFaction) - && (!ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal()) + && (!uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal()) ) { - if (ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction) + if (uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction) error = Txt.parse("You can only claim additional land which is connected to your first claim or controlled by another faction!"); else error = Txt.parse("You can only claim additional land which is connected to your first claim!"); @@ -653,14 +654,15 @@ public class UPlayer extends SenderEntity implements EconomyParticipato // TODO: The economy integration should cancel the event above! // Calculate the cost to claim the area double cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal()); - if (ConfServer.econClaimUnconnectedFee != 0.0 && forFaction.getLandCountInWorld(psChunk.getWorld()) > 0 && !BoardColls.get().isConnectedPs(psChunk, forFaction)) + + if (UConf.get(psChunk).econClaimUnconnectedFee != 0.0 && forFaction.getLandCountInWorld(psChunk.getWorld()) > 0 && !BoardColls.get().isConnectedPs(psChunk, forFaction)) { - cost += ConfServer.econClaimUnconnectedFee; + cost += UConf.get(psChunk).econClaimUnconnectedFee; } if (Econ.payForAction(cost, this, "claim this land")) return false; // TODO: The LWC integration should listen to Monitor for the claim event. - if (LWCFeatures.getEnabled() && forFaction.isNormal() && UConf.get(forFaction).onCaptureResetLwcLocks) + if (LWCFeatures.getEnabled() && forFaction.isNormal() && UConf.get(forFaction).lwcRemoveOnCapture) { LWCFeatures.clearOtherProtections(psChunk, this.getFaction()); } diff --git a/src/com/massivecraft/factions/entity/UPlayerColl.java b/src/com/massivecraft/factions/entity/UPlayerColl.java index e0daa851..d34df00f 100644 --- a/src/com/massivecraft/factions/entity/UPlayerColl.java +++ b/src/com/massivecraft/factions/entity/UPlayerColl.java @@ -69,12 +69,12 @@ public class UPlayerColl extends SenderColl } } - public void autoLeaveOnInactivityRoutine() + public void removePlayerDataAfterInactiveDaysRoutine() { - if (ConfServer.autoLeaveAfterDaysOfInactivity <= 0.0) return; + if (MConf.get().removePlayerDataAfterInactiveDays <= 0.0) return; long now = System.currentTimeMillis(); - double toleranceMillis = ConfServer.autoLeaveAfterDaysOfInactivity * TimeUnit.MILLIS_PER_DAY; + double toleranceMillis = MConf.get().removePlayerDataAfterInactiveDays * TimeUnit.MILLIS_PER_DAY; for (UPlayer uplayer : this.getAll()) { @@ -99,7 +99,7 @@ public class UPlayerColl extends SenderColl } } - uplayer.leave(false); + uplayer.resetFactionData(); uplayer.detach(); } } diff --git a/src/com/massivecraft/factions/integration/Econ.java b/src/com/massivecraft/factions/integration/Econ.java index d675246e..8b17d577 100644 --- a/src/com/massivecraft/factions/integration/Econ.java +++ b/src/com/massivecraft/factions/integration/Econ.java @@ -8,6 +8,7 @@ import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.EconomyParticipator; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.util.RelationUtil; @@ -23,7 +24,7 @@ public class Econ // TODO: Could we not have it enabled as long as Money.enabled is true? public static boolean isEnabled(Object universe) { - return ConfServer.econEnabled && Money.enabled(universe); + return UConf.get(universe).econEnabled && Money.enabled(universe); } // -------------------------------------------- // @@ -36,9 +37,10 @@ public class Econ if (cost == 0D) return true; if (fsender.isUsingAdminMode()) return true; + UConf uconf = UConf.get(fsender); Faction fsenderFaction = fsender.getFaction(); - - if (ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fsenderFaction.isNormal()) + + if (uconf.bankEnabled && uconf.bankFactionPaysCosts && fsenderFaction.isNormal()) { return modifyMoney(fsenderFaction, -cost, actionDescription); } @@ -55,13 +57,14 @@ public class Econ public static void modifyUniverseMoney(Object universe, double delta) { if (!isEnabled(universe)) return; + UConf uconf = UConf.get(universe); - if (ConfServer.econUniverseAccount == null) return; - if (ConfServer.econUniverseAccount.length() == 0) return; + if (uconf.econUniverseAccount == null) return; + if (uconf.econUniverseAccount.length() == 0) return; - if (!Money.exists(universe, ConfServer.econUniverseAccount)) return; + if (!Money.exists(universe, uconf.econUniverseAccount)) return; - Money.add(universe, ConfServer.econUniverseAccount, delta); + Money.add(universe, uconf.econUniverseAccount, delta); } public static void sendBalanceInfo(UPlayer to, EconomyParticipator about) @@ -281,7 +284,12 @@ public class Econ return false; } } - + + // -------------------------------------------- // + // LAND VALUE + // -------------------------------------------- // + // TODO: Clean up! + // calculate the cost for claiming land public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction) { diff --git a/src/com/massivecraft/factions/integration/Worldguard.java b/src/com/massivecraft/factions/integration/Worldguard.java index 5f36a5f4..de2137c2 100644 --- a/src/com/massivecraft/factions/integration/Worldguard.java +++ b/src/com/massivecraft/factions/integration/Worldguard.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.integration; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.mcore.ps.PS; import java.util.ArrayList; @@ -62,11 +63,9 @@ public class Worldguard // False: PVP is disallowed public static boolean isPVP(Player player) { - if ( ! enabled) - { - // No WG hooks so we'll always bypass this check. - return true; - } + // No WG hooks so we'll always bypass this check. + if (!enabled) return true; + if (!UConf.get(player).worldGuardChecking) return true; Location loc = player.getLocation(); World world = loc.getWorld(); @@ -85,6 +84,7 @@ public class Worldguard { // No WG hooks so we'll always bypass this check. if (!enabled) return false; + if (!UConf.get(psChunk).worldGuardChecking) return true; World world = null; Chunk chunk = null; diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java index 02157879..2531b9ff 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java @@ -5,8 +5,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.event.FactionsEventAbstractSender; import com.massivecraft.factions.event.FactionsEventCreate; import com.massivecraft.factions.event.FactionsEventDescriptionChange; @@ -60,56 +60,60 @@ public class FactionsListenerEcon implements Listener @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void payForCommand(FactionsEventHomeChange event) { - payForCommand(event, ConfServer.econCostSethome, Factions.get().getOuterCmdFactions().cmdFactionsSethome); + payForCommand(event, UConf.get(event.getSender()).econCostSethome, Factions.get().getOuterCmdFactions().cmdFactionsSethome); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void payForCommand(FactionsEventCreate event) { - payForCommand(event, ConfServer.econCostCreate, Factions.get().getOuterCmdFactions().cmdFactionsCreate); + payForCommand(event, UConf.get(event.getSender()).econCostCreate, Factions.get().getOuterCmdFactions().cmdFactionsCreate); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void payForCommand(FactionsEventDescriptionChange event) { - payForCommand(event, ConfServer.econCostDescription, Factions.get().getOuterCmdFactions().cmdFactionsDescription); + payForCommand(event, UConf.get(event.getSender()).econCostDescription, Factions.get().getOuterCmdFactions().cmdFactionsDescription); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void payForCommand(FactionsEventTagChange event) { - payForCommand(event, ConfServer.econCostTag, Factions.get().getOuterCmdFactions().cmdFactionsTag); + payForCommand(event, UConf.get(event.getSender()).econCostTag, Factions.get().getOuterCmdFactions().cmdFactionsTag); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void payForCommand(FactionsEventTitleChange event) { - payForCommand(event, ConfServer.econCostTitle, Factions.get().getOuterCmdFactions().cmdFactionsTitle); + payForCommand(event, UConf.get(event.getSender()).econCostTitle, Factions.get().getOuterCmdFactions().cmdFactionsTitle); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void payForCommand(FactionsEventRelationChange event) { - payForCommand(event, event.getNewRelation().getRelationCost(), Factions.get().getOuterCmdFactions().cmdFactionsRelationNeutral); + Double cost = UConf.get(event.getSender()).econRelCost.get(event.getNewRelation()); + if (cost == null) return; + if (cost == 0) return; + + payForCommand(event, cost, Factions.get().getOuterCmdFactions().cmdFactionsRelationNeutral); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void payForCommand(FactionsEventOpenChange event) { - payForCommand(event, ConfServer.econCostOpen, Factions.get().getOuterCmdFactions().cmdFactionsOpen); + payForCommand(event, UConf.get(event.getSender()).econCostOpen, Factions.get().getOuterCmdFactions().cmdFactionsOpen); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void payForCommand(FactionsEventInvitedChange event) { - double cost = event.isNewInvited() ? ConfServer.econCostInvite : ConfServer.econCostDeinvite; + double cost = event.isNewInvited() ? UConf.get(event.getSender()).econCostInvite : UConf.get(event.getSender()).econCostDeinvite; payForCommand(event, cost, Factions.get().getOuterCmdFactions().cmdFactionsInvite); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void payForCommand(FactionsEventHomeTeleport event) { - payForCommand(event, ConfServer.econCostHome, Factions.get().getOuterCmdFactions().cmdFactionsHome); + payForCommand(event, UConf.get(event.getSender()).econCostHome, Factions.get().getOuterCmdFactions().cmdFactionsHome); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @@ -120,17 +124,17 @@ public class FactionsListenerEcon implements Listener if (event.getReason() == MembershipChangeReason.JOIN) { - cost = ConfServer.econCostJoin; + cost = UConf.get(event.getSender()).econCostJoin; command = Factions.get().getOuterCmdFactions().cmdFactionsJoin; } else if (event.getReason() == MembershipChangeReason.LEAVE) { - cost = ConfServer.econCostLeave; + cost = UConf.get(event.getSender()).econCostLeave; command = Factions.get().getOuterCmdFactions().cmdFactionsLeave; } else if (event.getReason() == MembershipChangeReason.KICK) { - cost = ConfServer.econCostKick; + cost = UConf.get(event.getSender()).econCostKick; command = Factions.get().getOuterCmdFactions().cmdFactionsKick; } else diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index f06d9466..57435774 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -44,7 +44,6 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerMoveEvent; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Const; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; @@ -301,16 +300,15 @@ public class FactionsListenerMain implements Listener if (!event.getReason().equals("Banned by admin.")) return; // ... and we remove player data when banned ... - if (!ConfServer.removePlayerDataWhenBanned) return; + if (!MConf.get().removePlayerDataWhenBanned) return; // ... get rid of their stored info. if (uplayer.getRole() == Rel.LEADER) { uplayer.getFaction().promoteNewLeader(); } - uplayer.leave(false); + uplayer.leave(); uplayer.detach(); - } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/task/EconRewardTask.java b/src/com/massivecraft/factions/task/EconRewardTask.java index 6950b864..e1015fcc 100644 --- a/src/com/massivecraft/factions/task/EconRewardTask.java +++ b/src/com/massivecraft/factions/task/EconRewardTask.java @@ -1,10 +1,9 @@ package com.massivecraft.factions.task; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.FactionColls; +import com.massivecraft.factions.entity.MConf; import com.massivecraft.mcore.ModuloRepeatTask; -import com.massivecraft.mcore.util.TimeUnit; public class EconRewardTask extends ModuloRepeatTask { @@ -22,13 +21,13 @@ public class EconRewardTask extends ModuloRepeatTask @Override public long getDelayMillis() { - return (long) (ConfServer.econLandRewardTaskRunsEveryXMinutes * TimeUnit.MILLIS_PER_MINUTE); + return MConf.get().taskEconMillis; } @Override public void setDelayMillis(long delayMillis) { - throw new RuntimeException("operation not supported"); + MConf.get().taskEconMillis = delayMillis; } @Override diff --git a/src/com/massivecraft/factions/task/PowerUpdateTask.java b/src/com/massivecraft/factions/task/PowerUpdateTask.java index 279de0e8..adbcb0c9 100644 --- a/src/com/massivecraft/factions/task/PowerUpdateTask.java +++ b/src/com/massivecraft/factions/task/PowerUpdateTask.java @@ -26,13 +26,13 @@ public class PowerUpdateTask extends ModuloRepeatTask @Override public long getDelayMillis() { - return MConf.get().powerTaskMillis; + return MConf.get().taskPowerMillis; } @Override public void setDelayMillis(long delayMillis) { - MConf.get().powerTaskMillis = delayMillis; + MConf.get().taskPowerMillis = delayMillis; } @Override diff --git a/src/com/massivecraft/factions/task/AutoLeaveTask.java b/src/com/massivecraft/factions/task/RemovePlayerDataTask.java similarity index 61% rename from src/com/massivecraft/factions/task/AutoLeaveTask.java rename to src/com/massivecraft/factions/task/RemovePlayerDataTask.java index 944e29bf..677a7f2d 100644 --- a/src/com/massivecraft/factions/task/AutoLeaveTask.java +++ b/src/com/massivecraft/factions/task/RemovePlayerDataTask.java @@ -1,19 +1,18 @@ package com.massivecraft.factions.task; -import com.massivecraft.factions.ConfServer; +import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.UPlayerColl; import com.massivecraft.factions.entity.UPlayerColls; import com.massivecraft.mcore.ModuloRepeatTask; -import com.massivecraft.mcore.util.TimeUnit; -public class AutoLeaveTask extends ModuloRepeatTask +public class RemovePlayerDataTask extends ModuloRepeatTask { // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - private static AutoLeaveTask i = new AutoLeaveTask(); - public static AutoLeaveTask get() { return i; } + private static RemovePlayerDataTask i = new RemovePlayerDataTask(); + public static RemovePlayerDataTask get() { return i; } // -------------------------------------------- // // OVERRIDE: MODULO REPEAT TASK @@ -22,13 +21,13 @@ public class AutoLeaveTask extends ModuloRepeatTask @Override public long getDelayMillis() { - return (long) (ConfServer.autoLeaveRoutineRunsEveryXMinutes * TimeUnit.MILLIS_PER_MINUTE); + return MConf.get().taskAutoLeaveMillis; } @Override public void setDelayMillis(long delayMillis) { - throw new RuntimeException("operation not supported"); + MConf.get().taskAutoLeaveMillis = delayMillis; } @Override @@ -36,7 +35,7 @@ public class AutoLeaveTask extends ModuloRepeatTask { for (UPlayerColl coll : UPlayerColls.get().getColls()) { - coll.autoLeaveOnInactivityRoutine(); + coll.removePlayerDataAfterInactiveDaysRoutine(); } }