From 2f8f0713e8c3573b061dbe38de52e784cb0b1397 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 19 Apr 2013 09:50:33 +0200 Subject: [PATCH] Minor touches to the Econ integration --- src/com/massivecraft/factions/ConfServer.java | 9 +- src/com/massivecraft/factions/FPlayer.java | 10 +- .../massivecraft/factions/FactionColl.java | 6 +- .../factions/cmd/CmdFactionsCreate.java | 5 +- .../factions/cmd/CmdFactionsDescription.java | 2 +- .../factions/cmd/CmdFactionsDisband.java | 2 +- .../factions/cmd/CmdFactionsHome.java | 2 +- .../factions/cmd/CmdFactionsInvite.java | 2 +- .../factions/cmd/CmdFactionsJoin.java | 5 +- .../factions/cmd/CmdFactionsKick.java | 5 +- .../factions/cmd/CmdFactionsList.java | 2 +- .../factions/cmd/CmdFactionsMap.java | 4 +- .../factions/cmd/CmdFactionsOpen.java | 2 +- .../factions/cmd/CmdFactionsPower.java | 2 +- .../cmd/CmdFactionsRelationAbstract.java | 2 +- .../factions/cmd/CmdFactionsSethome.java | 14 +- .../factions/cmd/CmdFactionsShow.java | 4 +- .../factions/cmd/CmdFactionsTag.java | 5 +- .../factions/cmd/CmdFactionsTitle.java | 2 +- .../factions/cmd/CmdFactionsUnclaim.java | 6 +- .../factions/cmd/CmdFactionsUnclaimall.java | 6 +- .../massivecraft/factions/cmd/FCommand.java | 21 +-- .../event/FactionsHomeChangedEvent.java | 57 ++++++ .../factions/integration/Econ.java | 176 +++++++++++------- ...ochatListener.java => HerochatEngine.java} | 8 +- .../herochat/HerochatFeatures.java | 4 +- 26 files changed, 223 insertions(+), 140 deletions(-) create mode 100644 src/com/massivecraft/factions/event/FactionsHomeChangedEvent.java rename src/com/massivecraft/factions/integration/herochat/{HerochatListener.java => HerochatEngine.java} (85%) diff --git a/src/com/massivecraft/factions/ConfServer.java b/src/com/massivecraft/factions/ConfServer.java index 998005fc..c0b03087 100644 --- a/src/com/massivecraft/factions/ConfServer.java +++ b/src/com/massivecraft/factions/ConfServer.java @@ -121,7 +121,7 @@ public class ConfServer extends SimpleConfig // HeroChat: The Faction Channel public static String herochatFactionName = "Faction"; public static String herochatFactionNick = "F"; - public static String herochatFactionFormat = "{color}[&l{nick}&r{color} &l{faction_roleprefix}&r{color}{faction_title_pr}{sender}{color}] &f{msg}"; + public static String herochatFactionFormat = "{color}[&l{nick}&r{color} &l{factions_roleprefix}&r{color}{factions_title|rp}{sender}{color}] &f{msg}"; public static ChatColor herochatFactionColor = ChatColor.GREEN; public static int herochatFactionDistance = 0; public static boolean herochatFactionIsShortcutAllowed = false; @@ -132,7 +132,7 @@ public class ConfServer extends SimpleConfig // HeroChat: The Allies Channel public static String herochatAlliesName = "Allies"; public static String herochatAlliesNick = "A"; - public static String herochatAlliesFormat = "{color}[&l{nick}&r&f {faction_relcolor}&l{faction_roleprefix}&r{faction_relcolor}{faction_tag_pr}{sender}{color}] &f{msg}"; + public static String herochatAlliesFormat = "{color}[&l{nick}&r&f {factions_relcolor}&l{factions_roleprefix}&r{factions_relcolor}{factions_tag|rp}{sender}{color}] &f{msg}"; public static ChatColor herochatAlliesColor = ChatColor.DARK_PURPLE; public static int herochatAlliesDistance = 0; public static boolean herochatAlliesIsShortcutAllowed = false; @@ -230,7 +230,10 @@ public class ConfServer extends SimpleConfig public static boolean pistonProtectionThroughDenyBuild = true; - // Spout features + // -------------------------------------------- // + // INTEGRATION: SPOUT + // -------------------------------------------- // + public static boolean spoutFactionTagsOverNames = true; // show faction tags over names over player heads public static boolean spoutFactionTitlesOverNames = true; // whether to include player's title in that public static boolean spoutHealthBarUnderNames = true; // Show healthbar under player names. diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index d52bf694..41cc6118 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -675,7 +675,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato public void leave(boolean makePay) { Faction myFaction = this.getFaction(); - makePay = makePay && Econ.shouldBeUsed() && ! this.isUsingAdminMode(); + makePay = makePay && Econ.isEnabled() && ! this.isUsingAdminMode(); if (myFaction == null) { @@ -705,13 +705,13 @@ public class FPlayer extends SenderEntity implements EconomyParticipato if (leaveEvent.isCancelled()) return; // then make 'em pay (if applicable) - if (makePay && ! Econ.modifyMoney(this, -ConfServer.econCostLeave, "to leave your faction.", "for leaving your faction.")) return; + if (makePay && ! Econ.modifyMoney(this, -ConfServer.econCostLeave, "leave your faction")) return; // Am I the last one in the faction? if (myFaction.getFPlayers().size() == 1) { // Transfer all money - if (Econ.shouldBeUsed()) + if (Econ.isEnabled()) Econ.transferMoney(this, myFaction, this, Econ.getBalance(myFaction.getAccountId())); } @@ -840,7 +840,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // TODO: Add flag no costs?? // if economy is enabled and they're not on the bypass list, make sure they can pay - boolean mustPay = Econ.shouldBeUsed() && ! this.isUsingAdminMode(); + boolean mustPay = Econ.isEnabled() && ! this.isUsingAdminMode(); double cost = 0.0; EconomyParticipator payee = null; if (mustPay) @@ -864,7 +864,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // then make 'em pay (if applicable) // TODO: The economy integration should cancel the event above! - if (mustPay && ! Econ.modifyMoney(payee, -cost, "to claim this land", "for claiming this land")) return false; + if (mustPay && ! Econ.modifyMoney(payee, -cost, "claim this land")) return false; // TODO: The LWC integration should listen to Monitor for the claim event. if (LWCFeatures.getEnabled() && forFaction.isNormal() && ConfServer.onCaptureResetLwcLocks) diff --git a/src/com/massivecraft/factions/FactionColl.java b/src/com/massivecraft/factions/FactionColl.java index 5b43ccb1..b4dc90e5 100644 --- a/src/com/massivecraft/factions/FactionColl.java +++ b/src/com/massivecraft/factions/FactionColl.java @@ -76,7 +76,7 @@ public class FactionColl extends Coll Faction ret = super.detachId(oid); - if (Econ.shouldBeUsed()) + if (Econ.isEnabled()) { Econ.setBalance(accountId, 0); } @@ -189,7 +189,7 @@ public class FactionColl extends Coll public void econLandRewardRoutine() { - if (!Econ.shouldBeUsed()) return; + if (!Econ.isEnabled()) return; if (ConfServer.econLandReward == 0.0) return; Factions.get().log("Running econLandRewardRoutine..."); @@ -203,7 +203,7 @@ public class FactionColl extends Coll double reward = ConfServer.econLandReward * landCount / playerCount; for (FPlayer player : players) { - Econ.modifyMoney(player, reward, "to own faction land", "for faction owning " + landCount + " land divided among " + playerCount + " member(s)"); + Econ.modifyMoney(player, reward, "own " + landCount + " faction land divided among " + playerCount + " members"); } } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java index c5a2c9fb..53109814 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java @@ -51,9 +51,6 @@ public class CmdFactionsCreate extends FCommand return; } - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay - if ( ! canAffordCommand(ConfServer.econCostCreate, "to create a new faction")) return; - // trigger the faction creation event (cancellable) String factionId = FactionColl.get().getIdStrategy().generate(FactionColl.get()); @@ -62,7 +59,7 @@ public class CmdFactionsCreate extends FCommand if(createEvent.isCancelled()) return; // then make 'em pay (if applicable) - if ( ! payForCommand(ConfServer.econCostCreate, "to create a new faction", "for creating a new faction")) return; + if (!payForCommand(ConfServer.econCostCreate)) return; Faction faction = FactionColl.get().create(factionId); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java index 176f652a..6b830559 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java @@ -24,7 +24,7 @@ public class CmdFactionsDescription extends FCommand public void perform() { // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostDesc, "to change faction description", "for changing faction description")) return; + if (!payForCommand(ConfServer.econCostDesc)) return; myFaction.setDescription(this.argConcatFrom(1)); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java index 8808f0d0..c0f511ff 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java @@ -68,7 +68,7 @@ public class CmdFactionsDisband extends FCommand if (ConfServer.logFactionDisband) Factions.get().log("The faction "+faction.getTag()+" ("+faction.getId()+") was disbanded by "+(senderIsConsole ? "console command" : fme.getName())+"."); - if (Econ.shouldBeUsed() && ! senderIsConsole) + if (Econ.isEnabled() && ! senderIsConsole) { //Give all the faction's money to the disbander double amount = Econ.getBalance(faction.getAccountId()); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java index 83722f2b..ceb305a1 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java @@ -123,7 +123,7 @@ public class CmdFactionsHome extends FCommand Mixin.teleport(me, myFaction.getHome(), "your faction home", sender); // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostHome, "to teleport to your faction home", "for teleporting to your faction home")) return; + if (!payForCommand(ConfServer.econCostHome)) return; } catch (TeleporterException e) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java index 52af9887..62ed0705 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java @@ -39,7 +39,7 @@ public class CmdFactionsInvite extends FCommand if (fme != null && ! FPerm.INVITE.has(fme, myFaction)) return; // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostInvite, "to invite someone", "for inviting someone")) return; + if (!payForCommand(ConfServer.econCostInvite)) return; myFaction.invite(you); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java index b299872e..d7099c18 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java @@ -74,16 +74,13 @@ public class CmdFactionsJoin extends FCommand return; } - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay - if (samePlayer && ! canAffordCommand(ConfServer.econCostJoin, "to join a faction")) return; - // trigger the join event (cancellable) FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.get().get(me),faction,FPlayerJoinEvent.PlayerJoinReason.COMMAND); Bukkit.getServer().getPluginManager().callEvent(joinEvent); if (joinEvent.isCancelled()) return; // then make 'em pay (if applicable) - if (samePlayer && ! payForCommand(ConfServer.econCostJoin, "to join a faction", "for joining a faction")) return; + if (samePlayer && ! payForCommand(ConfServer.econCostJoin)) return; if (!samePlayer) fplayer.msg("%s moved you into the faction %s.", fme.describeTo(fplayer, true), faction.getTag(fplayer)); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java index 9cd761d6..89cb40a8 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java @@ -54,16 +54,13 @@ public class CmdFactionsKick extends FCommand if (fme != null && ! FPerm.KICK.has(fme, yourFaction)) return; - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay - if ( ! canAffordCommand(ConfServer.econCostKick, "to kick someone from the faction")) return; - // trigger the leave event (cancellable) [reason:kicked] FPlayerLeaveEvent event = new FPlayerLeaveEvent(you, you.getFaction(), FPlayerLeaveEvent.PlayerLeaveReason.KICKED); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) return; // then make 'em pay (if applicable) - if ( ! payForCommand(ConfServer.econCostKick, "to kick someone from the faction", "for kicking someone from the faction")) return; + if (!payForCommand(ConfServer.econCostKick)) return; yourFaction.msg("%s kicked %s from the faction! :O", fme.describeTo(yourFaction, true), you.describeTo(yourFaction, true)); you.msg("%s kicked you from %s! :O", fme.describeTo(you, true), yourFaction.describeTo(you)); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsList.java b/src/com/massivecraft/factions/cmd/CmdFactionsList.java index 897d40c5..f7778c10 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsList.java @@ -32,7 +32,7 @@ public class CmdFactionsList extends FCommand if (pageHumanBased == null) return; // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostList, "to list the factions", "for listing the factions")) return; + if (!payForCommand(ConfServer.econCostList)) return; // Create Messages List lines = new ArrayList(); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java index 04a4846f..818081c1 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java @@ -27,7 +27,7 @@ public class CmdFactionsMap extends FCommand if (!this.argIsSet(0)) { // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostMap, "to show the map", "for showing the map")) return; + if (!payForCommand(ConfServer.econCostMap)) return; showMap(); return; @@ -38,7 +38,7 @@ public class CmdFactionsMap extends FCommand // Turn on // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostMap, "to show the map", "for showing the map")) return; + if (!payForCommand(ConfServer.econCostMap)) return; fme.setMapAutoUpdating(true); msg("Map auto update ENABLED."); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java b/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java index b221c3d3..21f13885 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java @@ -28,7 +28,7 @@ public class CmdFactionsOpen extends FCommand if (target == null) return; // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostOpen, "to open or close the faction", "for opening or closing the faction")) return; + if (!payForCommand(ConfServer.econCostOpen)) return; myFaction.setOpen(target); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPower.java b/src/com/massivecraft/factions/cmd/CmdFactionsPower.java index 3c4df96f..65031ab3 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPower.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPower.java @@ -27,7 +27,7 @@ public class CmdFactionsPower extends FCommand if (target != fme && ! Perm.POWER_ANY.has(sender, true)) return; // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostPower, "to show player power info", "for showing player power info")) return; + if (!payForCommand(ConfServer.econCostPower)) return; double powerBoost = target.getPowerBoost(); String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")"; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java index 23c28084..28ae0889 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java @@ -50,7 +50,7 @@ public abstract class CmdFactionsRelationAbstract extends FCommand } // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(targetRelation.getRelationCost(), "to change a relation wish", "for changing a relation wish")) return; + if (!payForCommand(targetRelation.getRelationCost())) return; // try to set the new relation Rel oldRelation = myFaction.getRelationTo(them, true); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java index 5b6cc1d5..596189ca 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java @@ -6,6 +6,7 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.event.FactionsHomeChangedEvent; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; @@ -38,19 +39,24 @@ public class CmdFactionsSethome extends FCommand // Has faction permission? if ( ! FPerm.SETHOME.has(sender, faction, true)) return; - PS ps = PS.valueOf(me.getLocation()); + PS newHome = PS.valueOf(me.getLocation()); // Can the player set the faction home HERE? - if (!fme.isUsingAdminMode() && !faction.isValidHome(ps)) + if (!fme.isUsingAdminMode() && !faction.isValidHome(newHome)) { fme.msg("Sorry, your faction home can only be set inside your own claimed territory."); return; } + + FactionsHomeChangedEvent event = new FactionsHomeChangedEvent(sender, FactionsHomeChangedEvent.REASON_COMMAND_SETHOME, faction, newHome); + event.run(); + if (event.isCancelled()) return; + newHome = event.getNewHome(); // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostSethome, "to set the faction home", "for setting the faction home")) return; + if (!payForCommand(ConfServer.econCostSethome)) return; - faction.setHome(ps); + faction.setHome(newHome); faction.msg("%s set the home for your faction. You can now use:", fme.describeTo(myFaction, true)); faction.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsHome.getUseageTemplate()); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java index a4a35ff1..011f91e7 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java @@ -35,7 +35,7 @@ public class CmdFactionsShow extends FCommand if (faction == null) return; // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostShow, "to show faction information", "for showing faction information")) return; + if (!payForCommand(ConfServer.econCostShow)) return; Collection admins = faction.getFPlayersWhereRole(Rel.LEADER); Collection mods = faction.getFPlayersWhereRole(Rel.OFFICER); @@ -64,7 +64,7 @@ public class CmdFactionsShow extends FCommand msg("Land / Power / Maxpower: %d/%d/%d %s", faction.getLandCount(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost); // show the land value - if (Econ.shouldBeUsed()) + if (Econ.isEnabled()) { double value = Econ.calculateTotalLandValue(faction.getLandCount()); double refund = value * ConfServer.econClaimRefundMultiplier; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java index 1a3b0adc..7652e60c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java @@ -48,16 +48,13 @@ public class CmdFactionsTag extends FCommand return; } - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay - if ( ! canAffordCommand(ConfServer.econCostTag, "to change the faction tag")) return; - // trigger the faction rename event (cancellable) FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag); Bukkit.getServer().getPluginManager().callEvent(renameEvent); if(renameEvent.isCancelled()) return; // then make 'em pay (if applicable) - if ( ! payForCommand(ConfServer.econCostTag, "to change the faction tag", "for changing the faction tag")) return; + if (!payForCommand(ConfServer.econCostTag)) return; String oldtag = myFaction.getTag(); myFaction.setTag(tag); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java b/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java index 11771cd6..e422ad56 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java @@ -35,7 +35,7 @@ public class CmdFactionsTitle extends FCommand if ( ! canIAdministerYou(fme, you)) return; // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostTitle, "to change a players title", "for changing a players title")) return; + if (!payForCommand(ConfServer.econCostTitle)) return; you.setTitle(title); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java index 7bd9fb23..af0a7030 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java @@ -38,17 +38,17 @@ public class CmdFactionsUnclaim extends FCommand if(unclaimEvent.isCancelled()) return; //String moneyBack = ""; - if (Econ.shouldBeUsed()) + if (Econ.isEnabled()) { double refund = Econ.calculateClaimRefund(myFaction.getLandCount()); if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts) { - if ( ! Econ.modifyMoney(myFaction, refund, "to unclaim this land", "for unclaiming this land")) return; + if ( ! Econ.modifyMoney(myFaction, refund, "unclaim this land")) return; } else { - if ( ! Econ.modifyMoney(fme , refund, "to unclaim this land", "for unclaiming this land")) return; + if ( ! Econ.modifyMoney(fme, refund, "unclaim this land")) return; } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java index ee8d113b..efc27ae9 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java @@ -26,16 +26,16 @@ public class CmdFactionsUnclaimall extends FCommand @Override public void perform() { - if (Econ.shouldBeUsed()) + if (Econ.isEnabled()) { double refund = Econ.calculateTotalLandRefund(myFaction.getLandCount()); if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts) { - if ( ! Econ.modifyMoney(myFaction, refund, "to unclaim all faction land", "for unclaiming all faction land")) return; + if ( ! Econ.modifyMoney(myFaction, refund, "unclaim all faction land")) return; } else { - if ( ! Econ.modifyMoney(fme , refund, "to unclaim all faction land", "for unclaiming all faction land")) return; + if ( ! Econ.modifyMoney(fme, refund, "unclaim all faction land")) return; } } diff --git a/src/com/massivecraft/factions/cmd/FCommand.java b/src/com/massivecraft/factions/cmd/FCommand.java index d1211fe3..e167dc6b 100644 --- a/src/com/massivecraft/factions/cmd/FCommand.java +++ b/src/com/massivecraft/factions/cmd/FCommand.java @@ -1,6 +1,5 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.Faction; @@ -62,24 +61,8 @@ public abstract class FCommand extends MCommand } // if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost - public boolean payForCommand(double cost, String toDoThis, String forDoingThis) + public boolean payForCommand(double cost) { - if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isUsingAdminMode()) return true; - - if (ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction()) - return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis); - else - return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis); - } - - // like above, but just make sure they can pay; returns true unless person can't afford the cost - public boolean canAffordCommand(double cost, String toDoThis) - { - if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isUsingAdminMode()) return true; - - if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction()) - return Econ.hasAtLeast(myFaction, cost, toDoThis); - else - return Econ.hasAtLeast(fme, cost, toDoThis); + return Econ.payForAction(cost, sender, this.getDesc()); } } diff --git a/src/com/massivecraft/factions/event/FactionsHomeChangedEvent.java b/src/com/massivecraft/factions/event/FactionsHomeChangedEvent.java new file mode 100644 index 00000000..10dca018 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsHomeChangedEvent.java @@ -0,0 +1,57 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.Faction; +import com.massivecraft.mcore.event.MCoreCancellableEvent; +import com.massivecraft.mcore.ps.PS; + +public class FactionsHomeChangedEvent extends MCoreCancellableEvent +{ + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public final static String REASON_COMMAND_SETHOME = "FACTIONS_COMMAND_SETHOME"; + public final static String REASON_VERIFY_FAILED = "FACTIONS_VERIFY_FAILED"; + public final static String REASON_UNDEFINED = "FACTIONS_UNDEFINED"; + + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final CommandSender sender; + public CommandSender getSender() { return this.sender; } + + private final String reason; + public String getReason() { return this.reason; } + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private PS newHome; + public PS getNewHome() { return this.newHome; } + public void setNewHome(PS newHome) { this.newHome = newHome; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsHomeChangedEvent(CommandSender sender, String reason, Faction faction, PS newHome) + { + this.sender = sender; + this.reason = reason; + this.faction = faction; + this.newHome = newHome; + } + +} diff --git a/src/com/massivecraft/factions/integration/Econ.java b/src/com/massivecraft/factions/integration/Econ.java index 07fd11fe..0331b1c9 100644 --- a/src/com/massivecraft/factions/integration/Econ.java +++ b/src/com/massivecraft/factions/integration/Econ.java @@ -5,6 +5,7 @@ import java.util.Set; import java.util.logging.Level; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; import org.bukkit.plugin.RegisteredServiceProvider; import com.massivecraft.factions.ConfServer; @@ -21,11 +22,13 @@ import net.milkbowl.vault.economy.EconomyResponse; public class Econ { - private static Economy econ = null; - + // -------------------------------------------- // + // DERPY OLDSCHOOL SETUP + // -------------------------------------------- // + public static void setup() { - if (isSetup()) return; + if (economy != null) return; String integrationFail = "Economy integration is "+(ConfServer.econEnabled ? "enabled, but" : "disabled, and")+" the plugin \"Vault\" "; @@ -41,7 +44,7 @@ public class Econ Factions.get().log(integrationFail+"is not hooked into an economy plugin."); return; } - econ = rsp.getProvider(); + economy = rsp.getProvider(); Factions.get().log("Economy integration through Vault plugin successful."); @@ -49,36 +52,67 @@ public class Econ Factions.get().log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true"); } - public static boolean shouldBeUsed() + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private static Economy economy = null; + + // -------------------------------------------- // + // STATE + // -------------------------------------------- // + + public static boolean isEnabled() { - return ConfServer.econEnabled && econ != null && econ.isEnabled(); + return ConfServer.econEnabled && economy != null && economy.isEnabled(); } - public static boolean isSetup() + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public static boolean payForAction(double cost, CommandSender sender, String actionDescription) { - return econ != null; - } + if (!isEnabled()) return true; + if (cost == 0D) return true; + + FPlayer fsender = FPlayer.get(sender); + if (fsender.isUsingAdminMode()) return true; + Faction fsenderFaction = fsender.getFaction(); + if (ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fsenderFaction.isNormal()) + { + return modifyMoney(fsenderFaction, -cost, actionDescription); + } + else + { + return modifyMoney(fsender, -cost, actionDescription); + } + } + + // -------------------------------------------- // + // ASSORTED + // -------------------------------------------- // public static void modifyUniverseMoney(double delta) { - if (!shouldBeUsed()) return; + if (!isEnabled()) return; if (ConfServer.econUniverseAccount == null) return; if (ConfServer.econUniverseAccount.length() == 0) return; - if ( ! econ.hasAccount(ConfServer.econUniverseAccount)) return; + if ( ! economy.hasAccount(ConfServer.econUniverseAccount)) return; modifyBalance(ConfServer.econUniverseAccount, delta); } public static void sendBalanceInfo(FPlayer to, EconomyParticipator about) { - if (!shouldBeUsed()) + if (!isEnabled()) { Factions.get().log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin."); return; } - to.msg("%s's balance is %s.", about.describeTo(to, true), Econ.moneyString(econ.getBalance(about.getAccountId()))); + to.msg("%s's balance is %s.", about.describeTo(to, true), Econ.moneyString(economy.getBalance(about.getAccountId()))); } public static boolean canIControllYou(EconomyParticipator i, EconomyParticipator you) @@ -114,7 +148,7 @@ public class Econ } public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount, boolean notify) { - if ( ! shouldBeUsed()) return false; + if ( ! isEnabled()) return false; // The amount must be positive. // If the amount is negative we must flip and multiply amount with -1. @@ -130,26 +164,34 @@ public class Econ if ( ! canIControllYou(invoker, from)) return false; // Is there enough money for the transaction to happen? - if ( ! econ.has(from.getAccountId(), amount)) + if ( ! economy.has(from.getAccountId(), amount)) { // There was not enough money to pay if (invoker != null && notify) + { invoker.msg("%s can't afford to transfer %s to %s.", from.describeTo(invoker, true), moneyString(amount), to.describeTo(invoker)); - + } return false; } // Transfer money - EconomyResponse erw = econ.withdrawPlayer(from.getAccountId(), amount); + EconomyResponse erw = economy.withdrawPlayer(from.getAccountId(), amount); - if (erw.transactionSuccess()) { - EconomyResponse erd = econ.depositPlayer(to.getAccountId(), amount); - if (erd.transactionSuccess()) { - if (notify) sendTransferInfo(invoker, from, to, amount); + if (erw.transactionSuccess()) + { + EconomyResponse erd = economy.depositPlayer(to.getAccountId(), amount); + if (erd.transactionSuccess()) + { + if (notify) + { + sendTransferInfo(invoker, from, to, amount); + } return true; - } else { + } + else + { // transaction failed, refund account - econ.depositPlayer(from.getAccountId(), amount); + economy.depositPlayer(from.getAccountId(), amount); } } @@ -220,9 +262,9 @@ public class Econ public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) { - if ( ! shouldBeUsed()) return true; + if (!isEnabled()) return true; - if ( ! econ.has(ep.getAccountId(), delta)) + if ( ! economy.has(ep.getAccountId(), delta)) { if (toDoThis != null && !toDoThis.isEmpty()) ep.msg("%s can't afford %s %s.", ep.describeTo(ep, true), moneyString(delta), toDoThis); @@ -231,34 +273,37 @@ public class Econ return true; } - public static boolean modifyMoney(EconomyParticipator ep, double delta, String toDoThis, String forDoingThis) + public static boolean modifyMoney(EconomyParticipator ep, double delta, String actionDescription) { - if ( ! shouldBeUsed()) return false; - - String acc = ep.getAccountId(); + if (!isEnabled()) return false; + if (delta == 0) return true; + + String accountId = ep.getAccountId(); String You = ep.describeTo(ep, true); - if (delta == 0) - { - // no money actually transferred? -// ep.msg("%s didn't have to pay anything %s.", You, forDoingThis); // might be for gains, might be for losses - return true; - } + boolean hasActionDesctription = (actionDescription != null && !actionDescription.isEmpty()); if (delta > 0) { // The player should gain money // The account might not have enough space - EconomyResponse er = econ.depositPlayer(acc, delta); - if (er.transactionSuccess()) { + EconomyResponse er = economy.depositPlayer(accountId, delta); + if (er.transactionSuccess()) + { modifyUniverseMoney(-delta); - if (forDoingThis != null && !forDoingThis.isEmpty()) - ep.msg("%s gained %s %s.", You, moneyString(delta), forDoingThis); + if (hasActionDesctription) + { + ep.msg("%s gained %s since did %s.", You, moneyString(delta), actionDescription); + } return true; - } else { + } + else + { // transfer to account failed - if (forDoingThis != null && !forDoingThis.isEmpty()) - ep.msg("%s would have gained %s %s, but the deposit failed.", You, moneyString(delta), forDoingThis); + if (hasActionDesctription) + { + ep.msg("%s would have gained %s since did %s, but the deposit failed.", You, moneyString(delta), actionDescription); + } return false; } @@ -267,20 +312,24 @@ public class Econ { // The player should loose money // The player might not have enough. - - if (econ.has(acc, -delta) && econ.withdrawPlayer(acc, -delta).transactionSuccess()) + EconomyResponse er = economy.withdrawPlayer(accountId, -delta); + if (er.transactionSuccess()) { // There is enough money to pay modifyUniverseMoney(-delta); - if (forDoingThis != null && !forDoingThis.isEmpty()) - ep.msg("%s lost %s %s.", You, moneyString(-delta), forDoingThis); + if (hasActionDesctription) + { + ep.msg("%s lost %s since did %s.", You, moneyString(delta), actionDescription); + } return true; } else { // There was not enough money to pay - if (toDoThis != null && !toDoThis.isEmpty()) - ep.msg("%s can't afford %s %s.", You, moneyString(-delta), toDoThis); + if (hasActionDesctription) + { + ep.msg("%s can't afford %s to %s.", You, moneyString(-delta), actionDescription); + } return false; } } @@ -289,17 +338,14 @@ public class Econ // format money string based on server's set currency type, like "24 gold" or "$24.50" public static String moneyString(double amount) { - return econ.format(amount); + return economy.format(amount); } // calculate the cost for claiming land public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction) { - if ( ! shouldBeUsed()) - { - return 0d; - } - + if (!isEnabled()) return 0D; + // basic claim cost, plus land inflation cost, minus the potential bonus given for claiming from another faction return ConfServer.econCostClaimWilderness + (ConfServer.econCostClaimWilderness * ConfServer.econClaimAdditionalMultiplier * ownedLand) @@ -316,7 +362,8 @@ public class Econ public static double calculateTotalLandValue(int ownedLand) { double amount = 0; - for (int x = 0; x < ownedLand; x++) { + for (int x = 0; x < ownedLand; x++) + { amount += calculateClaimCost(x, false); } return amount; @@ -328,45 +375,44 @@ public class Econ return calculateTotalLandValue(ownedLand) * ConfServer.econClaimRefundMultiplier; } - // -------------------------------------------- // // Standard account management methods // -------------------------------------------- // public static boolean hasAccount(String name) { - return econ.hasAccount(name); + return economy.hasAccount(name); } public static double getBalance(String account) { - return econ.getBalance(account); + return economy.getBalance(account); } public static boolean setBalance(String account, double amount) { - double current = econ.getBalance(account); + double current = economy.getBalance(account); if (current > amount) - return econ.withdrawPlayer(account, current - amount).transactionSuccess(); + return economy.withdrawPlayer(account, current - amount).transactionSuccess(); else - return econ.depositPlayer(account, amount - current).transactionSuccess(); + return economy.depositPlayer(account, amount - current).transactionSuccess(); } public static boolean modifyBalance(String account, double amount) { if (amount < 0) - return econ.withdrawPlayer(account, -amount).transactionSuccess(); + return economy.withdrawPlayer(account, -amount).transactionSuccess(); else - return econ.depositPlayer(account, amount).transactionSuccess(); + return economy.depositPlayer(account, amount).transactionSuccess(); } public static boolean deposit(String account, double amount) { - return econ.depositPlayer(account, amount).transactionSuccess(); + return economy.depositPlayer(account, amount).transactionSuccess(); } public static boolean withdraw(String account, double amount) { - return econ.withdrawPlayer(account, amount).transactionSuccess(); + return economy.withdrawPlayer(account, amount).transactionSuccess(); } } diff --git a/src/com/massivecraft/factions/integration/herochat/HerochatListener.java b/src/com/massivecraft/factions/integration/herochat/HerochatEngine.java similarity index 85% rename from src/com/massivecraft/factions/integration/herochat/HerochatListener.java rename to src/com/massivecraft/factions/integration/herochat/HerochatEngine.java index 153cf006..34ab8b2f 100644 --- a/src/com/massivecraft/factions/integration/herochat/HerochatListener.java +++ b/src/com/massivecraft/factions/integration/herochat/HerochatEngine.java @@ -13,15 +13,15 @@ import com.massivecraft.factions.Factions; import com.massivecraft.factions.chat.ChatFormatter; -public class HerochatListener implements Listener +public class HerochatEngine implements Listener { // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - private static HerochatListener i = new HerochatListener(); - public static HerochatListener get() { return i; } - private HerochatListener() {} + private static HerochatEngine i = new HerochatEngine(); + public static HerochatEngine get() { return i; } + private HerochatEngine() {} // -------------------------------------------- // // ACTIVATE & DEACTIVATE diff --git a/src/com/massivecraft/factions/integration/herochat/HerochatFeatures.java b/src/com/massivecraft/factions/integration/herochat/HerochatFeatures.java index b77691ea..c63c5773 100644 --- a/src/com/massivecraft/factions/integration/herochat/HerochatFeatures.java +++ b/src/com/massivecraft/factions/integration/herochat/HerochatFeatures.java @@ -19,13 +19,13 @@ public class HerochatFeatures extends IntegrationFeaturesAbstract @Override public void activate() { - HerochatListener.get().activate(); + HerochatEngine.get().activate(); } @Override public void deactivate() { - HerochatListener.get().deactivate(); + HerochatEngine.get().deactivate(); } }