From f77750fc912c21010a11d8c31004b4580b977475 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 24 Jan 2016 20:07:09 +0100 Subject: [PATCH] Improve compatibility with some economy plugins (hopefully) #385 --- .../factions/engine/EngineEcon.java | 20 ++++----- .../factions/engine/EngineMain.java | 42 +++++++++---------- .../massivecraft/factions/entity/Faction.java | 9 +++- .../event/EventFactionsAbstractSender.java | 3 +- .../event/EventFactionsChunksChange.java | 2 +- .../worldguard/EngineWorldGuard.java | 2 +- 6 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/com/massivecraft/factions/engine/EngineEcon.java b/src/com/massivecraft/factions/engine/EngineEcon.java index 2c603c41..8f82586d 100644 --- a/src/com/massivecraft/factions/engine/EngineEcon.java +++ b/src/com/massivecraft/factions/engine/EngineEcon.java @@ -82,9 +82,9 @@ public class EngineEcon extends EngineAbstract @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void takeOnDisband(EventFactionsDisband event) { - // If there is a usender ... - MPlayer usender = event.getMSender(); - if (usender == null) return; + // If there is a mplayer ... + MPlayer mplayer = event.getMPlayer(); + if (mplayer == null) return; // ... and economy is enabled ... if (!Econ.isEnabled()) return; @@ -95,10 +95,10 @@ public class EngineEcon extends EngineAbstract double amount = Money.get(faction); String amountString = Money.format(amount); - Econ.transferMoney(faction, usender, usender, amount, true); + Econ.transferMoney(faction, mplayer, mplayer, amount, true); - usender.msg("You have been given the disbanded faction's bank, totaling %s.", amountString); - Factions.get().log(usender.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getName()+"."); + mplayer.msg("You have been given the disbanded faction's bank, totaling %s.", amountString); + Factions.get().log(mplayer.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getName()+"."); } // -------------------------------------------- // @@ -107,16 +107,16 @@ public class EngineEcon extends EngineAbstract public static void payForAction(EventFactionsAbstractSender event, Double cost, String desc) { - // If there is a sender ... - MPlayer usender = event.getMSender(); - if (usender == null) return; + // If there is an mplayer ... + MPlayer mplayer = event.getMPlayer(); + if (mplayer == null) return; // ... and there is a cost ... if (cost == null) return; if (cost == 0) return; // ... that the sender can't afford ... - if (Econ.payForAction(cost, usender, desc)) return; + if (Econ.payForAction(cost, mplayer, desc)) return; // ... then cancel. event.setCancelled(true); diff --git a/src/com/massivecraft/factions/engine/EngineMain.java b/src/com/massivecraft/factions/engine/EngineMain.java index f2fda036..867ebf9b 100644 --- a/src/com/massivecraft/factions/engine/EngineMain.java +++ b/src/com/massivecraft/factions/engine/EngineMain.java @@ -147,14 +147,14 @@ public class EngineMain extends EngineAbstract { final int tableCols = 4; final CommandSender sender = event.getSender(); - final MPlayer msender = event.getMSender(); + final MPlayer mplayer = event.getMPlayer(); final Faction faction = event.getFaction(); final boolean normal = faction.isNormal(); final Map idPriorityLiness = event.getIdPriorityLiness(); final boolean peaceful = faction.getFlag(MFlag.getFlagPeaceful()); // ID - if (msender.isUsingAdminMode()) + if (mplayer.isUsingAdminMode()) { show(idPriorityLiness, Const.SHOW_ID_FACTION_ID, Const.SHOW_PRIORITY_FACTION_ID, "ID", faction.getId()); } @@ -242,7 +242,7 @@ public class EngineMain extends EngineAbstract String none = Txt.parse("none"); String everyone = MConf.get().colorTruce.toString() + Txt.parse("*EVERYONE*"); Set rels = EnumSet.of(Rel.TRUCE, Rel.ALLY, Rel.ENEMY); - Map> relNames = faction.getRelationNames(msender, rels, true); + Map> relNames = faction.getRelationNames(mplayer, rels, true); for (Entry> entry : relNames.entrySet()) { Rel rel = entry.getKey(); @@ -279,12 +279,12 @@ public class EngineMain extends EngineAbstract { if (follower.isOnline(sender)) { - followerNamesOnline.add(follower.getNameAndTitle(msender)); + followerNamesOnline.add(follower.getNameAndTitle(mplayer)); } else if (normal) { // For the non-faction we skip the offline members since they are far to many (infinite almost) - followerNamesOffline.add(follower.getNameAndTitle(msender)); + followerNamesOffline.add(follower.getNameAndTitle(mplayer)); } } @@ -510,14 +510,14 @@ public class EngineMain extends EngineAbstract public void onChunksChangeInner(EventFactionsChunksChange event) { // Args - final MPlayer msender = event.getMSender(); + final MPlayer mplayer = event.getMPlayer(); final Faction newFaction = event.getNewFaction(); final Map> currentFactionChunks = event.getOldFactionChunks(); final Set currentFactions = currentFactionChunks.keySet(); final Set chunks = event.getChunks(); // Admin Mode? Sure! - if (msender.isUsingAdminMode()) return; + if (mplayer.isUsingAdminMode()) return; // CALC: Is there at least one normal faction among the current ones? boolean currentFactionsContainsAtLeastOneNormal = false; @@ -540,14 +540,14 @@ public class EngineMain extends EngineAbstract if ( ! MConf.get().worldsClaimingEnabled.contains(worldId)) { String worldName = Mixin.getWorldDisplayName(worldId); - msender.msg("Land claiming is disabled in %s.", worldName); + mplayer.msg("Land claiming is disabled in %s.", worldName); event.setCancelled(true); return; } } // ... ensure we have permission to alter the territory of the new faction ... - if ( ! MPerm.getPermTerritory().has(msender, newFaction, true)) + if ( ! MPerm.getPermTerritory().has(mplayer, newFaction, true)) { // NOTE: No need to send a message. We send message from the permission check itself. event.setCancelled(true); @@ -557,7 +557,7 @@ public class EngineMain extends EngineAbstract // ... ensure the new faction has enough players to claim ... if (newFaction.getMPlayers().size() < MConf.get().claimsRequireMinFactionMembers) { - msender.msg("Factions must have at least %s members to claim land.", MConf.get().claimsRequireMinFactionMembers); + mplayer.msg("Factions must have at least %s members to claim land.", MConf.get().claimsRequireMinFactionMembers); event.setCancelled(true); return; } @@ -566,7 +566,7 @@ public class EngineMain extends EngineAbstract int ownedLand = newFaction.getLandCount(); if (MConf.get().claimedLandsMax != 0 && ownedLand + chunks.size() > MConf.get().claimedLandsMax && ! newFaction.getFlag(MFlag.getFlagInfpower())) { - msender.msg("Limit reached. You can't claim more land."); + mplayer.msg("Limit reached. You can't claim more land."); event.setCancelled(true); return; } @@ -574,7 +574,7 @@ public class EngineMain extends EngineAbstract // ... ensure the claim would not bypass the faction power ... if (ownedLand + chunks.size() > newFaction.getPowerRounded()) { - msender.msg("You don't have enough power to claim that land."); + mplayer.msg("You don't have enough power to claim that land."); event.setCancelled(true); return; } @@ -592,7 +592,7 @@ public class EngineMain extends EngineAbstract for (Faction nearbyFaction : nearbyFactions) { if (claimnear.has(newFaction, nearbyFaction)) continue; - msender.message(claimnear.createDeniedMessage(msender, nearbyFaction)); + mplayer.message(claimnear.createDeniedMessage(mplayer, nearbyFaction)); event.setCancelled(true); return; } @@ -615,11 +615,11 @@ public class EngineMain extends EngineAbstract { if (MConf.get().claimsCanBeUnconnectedIfOwnedByOtherFaction) { - msender.msg("You can only claim additional land which is connected to your first claim or controlled by another faction!"); + mplayer.msg("You can only claim additional land which is connected to your first claim or controlled by another faction!"); } else { - msender.msg("You can only claim additional land which is connected to your first claim!"); + mplayer.msg("You can only claim additional land which is connected to your first claim!"); } event.setCancelled(true); return; @@ -635,15 +635,15 @@ public class EngineMain extends EngineAbstract // ... that is an actual faction ... if (oldFaction.isNone()) continue; - // ... for which the msender lacks permission ... - if (MPerm.getPermTerritory().has(msender, oldFaction, false)) continue; + // ... for which the mplayer lacks permission ... + if (MPerm.getPermTerritory().has(mplayer, oldFaction, false)) continue; // ... consider all reasons to forbid "overclaiming/warclaiming" ... // ... claiming from others may be forbidden ... if ( ! MConf.get().claimingFromOthersAllowed) { - msender.msg("You may not claim land from others."); + mplayer.msg("You may not claim land from others."); event.setCancelled(true); return; } @@ -651,7 +651,7 @@ public class EngineMain extends EngineAbstract // ... the relation may forbid ... if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE)) { - msender.msg("You can't claim this land due to your relation with the current owner."); + mplayer.msg("You can't claim this land due to your relation with the current owner."); event.setCancelled(true); return; } @@ -659,7 +659,7 @@ public class EngineMain extends EngineAbstract // ... the old faction might not be inflated enough ... if (oldFaction.getPowerRounded() > oldFaction.getLandCount() - oldChunks.size()) { - msender.msg("%s owns this land and is strong enough to keep it.", oldFaction.getName(msender)); + mplayer.msg("%s owns this land and is strong enough to keep it.", oldFaction.getName(mplayer)); event.setCancelled(true); return; } @@ -667,7 +667,7 @@ public class EngineMain extends EngineAbstract // ... and you might be trying to claim without starting at the border ... if ( ! BoardColl.get().isAnyBorderPs(chunks)) { - msender.msg("You must start claiming land at the border of the territory."); + mplayer.msg("You must start claiming land at the border of the territory."); event.setCancelled(true); return; } diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 2cb04713..9618d4cc 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -65,8 +65,13 @@ public class Faction extends Entity implements EconomyParticipator, Nam // We may move factions around during upgrades. if (!Factions.get().isDatabaseInitialized()) return; - // Zero balance - Money.set(this, null, 0); + // NOTE: Existence check is required for compatibility with some plugins. + // If they have money ... + if (Money.exists(this)) + { + // ... remove it. + Money.set(this, null, 0); + } // Clean the board BoardColl.get().clean(); diff --git a/src/com/massivecraft/factions/event/EventFactionsAbstractSender.java b/src/com/massivecraft/factions/event/EventFactionsAbstractSender.java index d2fe9d4b..a54cff71 100644 --- a/src/com/massivecraft/factions/event/EventFactionsAbstractSender.java +++ b/src/com/massivecraft/factions/event/EventFactionsAbstractSender.java @@ -13,7 +13,7 @@ public abstract class EventFactionsAbstractSender extends EventMassiveCore private final CommandSender sender; public CommandSender getSender() { return this.sender; } - public MPlayer getMSender() { return this.sender == null ? null : MPlayer.get(this.sender); } + public MPlayer getMPlayer() { return this.sender == null ? null : MPlayer.get(this.sender); } // -------------------------------------------- // // CONSTRUCT @@ -29,4 +29,5 @@ public abstract class EventFactionsAbstractSender extends EventMassiveCore super(async); this.sender = sender; } + } diff --git a/src/com/massivecraft/factions/event/EventFactionsChunksChange.java b/src/com/massivecraft/factions/event/EventFactionsChunksChange.java index 29033dce..2dcc1c78 100644 --- a/src/com/massivecraft/factions/event/EventFactionsChunksChange.java +++ b/src/com/massivecraft/factions/event/EventFactionsChunksChange.java @@ -60,7 +60,7 @@ public class EventFactionsChunksChange extends EventFactionsAbstractSender this.oldChunkFaction = Collections.unmodifiableMap(BoardColl.getChunkFaction(chunks)); this.oldFactionChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.oldChunkFaction)); - MPlayer msender = this.getMSender(); + MPlayer msender = this.getMPlayer(); Faction self = null; if (msender != null) self = msender.getFaction(); Map currentChunkType = new LinkedHashMap(); diff --git a/src/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java b/src/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java index 5bfca3c4..22615df0 100644 --- a/src/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java +++ b/src/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java @@ -77,7 +77,7 @@ public class EngineWorldGuard extends EngineAbstract // Permanent Factions should not apply this rule if (event.getNewFaction().getFlag(MFlag.ID_PERMANENT)) return; - MPlayer mplayer = event.getMSender(); + MPlayer mplayer = event.getMPlayer(); if ( ! MConf.get().worldguardCheckWorldsEnabled.contains(mplayer.getPlayer())) return;