Improve compatibility with some economy plugins (hopefully) #385

This commit is contained in:
BuildTools 2016-01-24 20:07:09 +01:00 committed by Olof Larsson
parent 6bc16d25b1
commit f77750fc91
6 changed files with 42 additions and 36 deletions

View File

@ -82,9 +82,9 @@ public class EngineEcon extends EngineAbstract
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void takeOnDisband(EventFactionsDisband event) public void takeOnDisband(EventFactionsDisband event)
{ {
// If there is a usender ... // If there is a mplayer ...
MPlayer usender = event.getMSender(); MPlayer mplayer = event.getMPlayer();
if (usender == null) return; if (mplayer == null) return;
// ... and economy is enabled ... // ... and economy is enabled ...
if (!Econ.isEnabled()) return; if (!Econ.isEnabled()) return;
@ -95,10 +95,10 @@ public class EngineEcon extends EngineAbstract
double amount = Money.get(faction); double amount = Money.get(faction);
String amountString = Money.format(amount); String amountString = Money.format(amount);
Econ.transferMoney(faction, usender, usender, amount, true); Econ.transferMoney(faction, mplayer, mplayer, amount, true);
usender.msg("<i>You have been given the disbanded faction's bank, totaling %s.", amountString); mplayer.msg("<i>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()+"."); 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) public static void payForAction(EventFactionsAbstractSender event, Double cost, String desc)
{ {
// If there is a sender ... // If there is an mplayer ...
MPlayer usender = event.getMSender(); MPlayer mplayer = event.getMPlayer();
if (usender == null) return; if (mplayer == null) return;
// ... and there is a cost ... // ... and there is a cost ...
if (cost == null) return; if (cost == null) return;
if (cost == 0) return; if (cost == 0) return;
// ... that the sender can't afford ... // ... that the sender can't afford ...
if (Econ.payForAction(cost, usender, desc)) return; if (Econ.payForAction(cost, mplayer, desc)) return;
// ... then cancel. // ... then cancel.
event.setCancelled(true); event.setCancelled(true);

View File

@ -147,14 +147,14 @@ public class EngineMain extends EngineAbstract
{ {
final int tableCols = 4; final int tableCols = 4;
final CommandSender sender = event.getSender(); final CommandSender sender = event.getSender();
final MPlayer msender = event.getMSender(); final MPlayer mplayer = event.getMPlayer();
final Faction faction = event.getFaction(); final Faction faction = event.getFaction();
final boolean normal = faction.isNormal(); final boolean normal = faction.isNormal();
final Map<String, PriorityLines> idPriorityLiness = event.getIdPriorityLiness(); final Map<String, PriorityLines> idPriorityLiness = event.getIdPriorityLiness();
final boolean peaceful = faction.getFlag(MFlag.getFlagPeaceful()); final boolean peaceful = faction.getFlag(MFlag.getFlagPeaceful());
// ID // ID
if (msender.isUsingAdminMode()) if (mplayer.isUsingAdminMode())
{ {
show(idPriorityLiness, Const.SHOW_ID_FACTION_ID, Const.SHOW_PRIORITY_FACTION_ID, "ID", faction.getId()); 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("<silver><italic>none"); String none = Txt.parse("<silver><italic>none");
String everyone = MConf.get().colorTruce.toString() + Txt.parse("<italic>*EVERYONE*"); String everyone = MConf.get().colorTruce.toString() + Txt.parse("<italic>*EVERYONE*");
Set<Rel> rels = EnumSet.of(Rel.TRUCE, Rel.ALLY, Rel.ENEMY); Set<Rel> rels = EnumSet.of(Rel.TRUCE, Rel.ALLY, Rel.ENEMY);
Map<Rel, List<String>> relNames = faction.getRelationNames(msender, rels, true); Map<Rel, List<String>> relNames = faction.getRelationNames(mplayer, rels, true);
for (Entry<Rel, List<String>> entry : relNames.entrySet()) for (Entry<Rel, List<String>> entry : relNames.entrySet())
{ {
Rel rel = entry.getKey(); Rel rel = entry.getKey();
@ -279,12 +279,12 @@ public class EngineMain extends EngineAbstract
{ {
if (follower.isOnline(sender)) if (follower.isOnline(sender))
{ {
followerNamesOnline.add(follower.getNameAndTitle(msender)); followerNamesOnline.add(follower.getNameAndTitle(mplayer));
} }
else if (normal) else if (normal)
{ {
// For the non-faction we skip the offline members since they are far to many (infinite almost) // 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) public void onChunksChangeInner(EventFactionsChunksChange event)
{ {
// Args // Args
final MPlayer msender = event.getMSender(); final MPlayer mplayer = event.getMPlayer();
final Faction newFaction = event.getNewFaction(); final Faction newFaction = event.getNewFaction();
final Map<Faction, Set<PS>> currentFactionChunks = event.getOldFactionChunks(); final Map<Faction, Set<PS>> currentFactionChunks = event.getOldFactionChunks();
final Set<Faction> currentFactions = currentFactionChunks.keySet(); final Set<Faction> currentFactions = currentFactionChunks.keySet();
final Set<PS> chunks = event.getChunks(); final Set<PS> chunks = event.getChunks();
// Admin Mode? Sure! // Admin Mode? Sure!
if (msender.isUsingAdminMode()) return; if (mplayer.isUsingAdminMode()) return;
// CALC: Is there at least one normal faction among the current ones? // CALC: Is there at least one normal faction among the current ones?
boolean currentFactionsContainsAtLeastOneNormal = false; boolean currentFactionsContainsAtLeastOneNormal = false;
@ -540,14 +540,14 @@ public class EngineMain extends EngineAbstract
if ( ! MConf.get().worldsClaimingEnabled.contains(worldId)) if ( ! MConf.get().worldsClaimingEnabled.contains(worldId))
{ {
String worldName = Mixin.getWorldDisplayName(worldId); String worldName = Mixin.getWorldDisplayName(worldId);
msender.msg("<b>Land claiming is disabled in <h>%s<b>.", worldName); mplayer.msg("<b>Land claiming is disabled in <h>%s<b>.", worldName);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
// ... ensure we have permission to alter the territory of the new faction ... // ... 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. // NOTE: No need to send a message. We send message from the permission check itself.
event.setCancelled(true); event.setCancelled(true);
@ -557,7 +557,7 @@ public class EngineMain extends EngineAbstract
// ... ensure the new faction has enough players to claim ... // ... ensure the new faction has enough players to claim ...
if (newFaction.getMPlayers().size() < MConf.get().claimsRequireMinFactionMembers) if (newFaction.getMPlayers().size() < MConf.get().claimsRequireMinFactionMembers)
{ {
msender.msg("<b>Factions must have at least <h>%s<b> members to claim land.", MConf.get().claimsRequireMinFactionMembers); mplayer.msg("<b>Factions must have at least <h>%s<b> members to claim land.", MConf.get().claimsRequireMinFactionMembers);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -566,7 +566,7 @@ public class EngineMain extends EngineAbstract
int ownedLand = newFaction.getLandCount(); int ownedLand = newFaction.getLandCount();
if (MConf.get().claimedLandsMax != 0 && ownedLand + chunks.size() > MConf.get().claimedLandsMax && ! newFaction.getFlag(MFlag.getFlagInfpower())) if (MConf.get().claimedLandsMax != 0 && ownedLand + chunks.size() > MConf.get().claimedLandsMax && ! newFaction.getFlag(MFlag.getFlagInfpower()))
{ {
msender.msg("<b>Limit reached. You can't claim more land."); mplayer.msg("<b>Limit reached. You can't claim more land.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -574,7 +574,7 @@ public class EngineMain extends EngineAbstract
// ... ensure the claim would not bypass the faction power ... // ... ensure the claim would not bypass the faction power ...
if (ownedLand + chunks.size() > newFaction.getPowerRounded()) if (ownedLand + chunks.size() > newFaction.getPowerRounded())
{ {
msender.msg("<b>You don't have enough power to claim that land."); mplayer.msg("<b>You don't have enough power to claim that land.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -592,7 +592,7 @@ public class EngineMain extends EngineAbstract
for (Faction nearbyFaction : nearbyFactions) for (Faction nearbyFaction : nearbyFactions)
{ {
if (claimnear.has(newFaction, nearbyFaction)) continue; if (claimnear.has(newFaction, nearbyFaction)) continue;
msender.message(claimnear.createDeniedMessage(msender, nearbyFaction)); mplayer.message(claimnear.createDeniedMessage(mplayer, nearbyFaction));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -615,11 +615,11 @@ public class EngineMain extends EngineAbstract
{ {
if (MConf.get().claimsCanBeUnconnectedIfOwnedByOtherFaction) if (MConf.get().claimsCanBeUnconnectedIfOwnedByOtherFaction)
{ {
msender.msg("<b>You can only claim additional land which is connected to your first claim or controlled by another faction!"); mplayer.msg("<b>You can only claim additional land which is connected to your first claim or controlled by another faction!");
} }
else else
{ {
msender.msg("<b>You can only claim additional land which is connected to your first claim!"); mplayer.msg("<b>You can only claim additional land which is connected to your first claim!");
} }
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -635,15 +635,15 @@ public class EngineMain extends EngineAbstract
// ... that is an actual faction ... // ... that is an actual faction ...
if (oldFaction.isNone()) continue; if (oldFaction.isNone()) continue;
// ... for which the msender lacks permission ... // ... for which the mplayer lacks permission ...
if (MPerm.getPermTerritory().has(msender, oldFaction, false)) continue; if (MPerm.getPermTerritory().has(mplayer, oldFaction, false)) continue;
// ... consider all reasons to forbid "overclaiming/warclaiming" ... // ... consider all reasons to forbid "overclaiming/warclaiming" ...
// ... claiming from others may be forbidden ... // ... claiming from others may be forbidden ...
if ( ! MConf.get().claimingFromOthersAllowed) if ( ! MConf.get().claimingFromOthersAllowed)
{ {
msender.msg("<b>You may not claim land from others."); mplayer.msg("<b>You may not claim land from others.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -651,7 +651,7 @@ public class EngineMain extends EngineAbstract
// ... the relation may forbid ... // ... the relation may forbid ...
if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE)) if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE))
{ {
msender.msg("<b>You can't claim this land due to your relation with the current owner."); mplayer.msg("<b>You can't claim this land due to your relation with the current owner.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -659,7 +659,7 @@ public class EngineMain extends EngineAbstract
// ... the old faction might not be inflated enough ... // ... the old faction might not be inflated enough ...
if (oldFaction.getPowerRounded() > oldFaction.getLandCount() - oldChunks.size()) if (oldFaction.getPowerRounded() > oldFaction.getLandCount() - oldChunks.size())
{ {
msender.msg("%s<i> owns this land and is strong enough to keep it.", oldFaction.getName(msender)); mplayer.msg("%s<i> owns this land and is strong enough to keep it.", oldFaction.getName(mplayer));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -667,7 +667,7 @@ public class EngineMain extends EngineAbstract
// ... and you might be trying to claim without starting at the border ... // ... and you might be trying to claim without starting at the border ...
if ( ! BoardColl.get().isAnyBorderPs(chunks)) if ( ! BoardColl.get().isAnyBorderPs(chunks))
{ {
msender.msg("<b>You must start claiming land at the border of the territory."); mplayer.msg("<b>You must start claiming land at the border of the territory.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }

View File

@ -65,8 +65,13 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
// We may move factions around during upgrades. // We may move factions around during upgrades.
if (!Factions.get().isDatabaseInitialized()) return; if (!Factions.get().isDatabaseInitialized()) return;
// Zero balance // NOTE: Existence check is required for compatibility with some plugins.
Money.set(this, null, 0); // If they have money ...
if (Money.exists(this))
{
// ... remove it.
Money.set(this, null, 0);
}
// Clean the board // Clean the board
BoardColl.get().clean(); BoardColl.get().clean();

View File

@ -13,7 +13,7 @@ public abstract class EventFactionsAbstractSender extends EventMassiveCore
private final CommandSender sender; private final CommandSender sender;
public CommandSender getSender() { return this.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 // CONSTRUCT
@ -29,4 +29,5 @@ public abstract class EventFactionsAbstractSender extends EventMassiveCore
super(async); super(async);
this.sender = sender; this.sender = sender;
} }
} }

View File

@ -60,7 +60,7 @@ public class EventFactionsChunksChange extends EventFactionsAbstractSender
this.oldChunkFaction = Collections.unmodifiableMap(BoardColl.getChunkFaction(chunks)); this.oldChunkFaction = Collections.unmodifiableMap(BoardColl.getChunkFaction(chunks));
this.oldFactionChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.oldChunkFaction)); this.oldFactionChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.oldChunkFaction));
MPlayer msender = this.getMSender(); MPlayer msender = this.getMPlayer();
Faction self = null; Faction self = null;
if (msender != null) self = msender.getFaction(); if (msender != null) self = msender.getFaction();
Map<PS, EventFactionsChunkChangeType> currentChunkType = new LinkedHashMap<PS, EventFactionsChunkChangeType>(); Map<PS, EventFactionsChunkChangeType> currentChunkType = new LinkedHashMap<PS, EventFactionsChunkChangeType>();

View File

@ -77,7 +77,7 @@ public class EngineWorldGuard extends EngineAbstract
// Permanent Factions should not apply this rule // Permanent Factions should not apply this rule
if (event.getNewFaction().getFlag(MFlag.ID_PERMANENT)) return; if (event.getNewFaction().getFlag(MFlag.ID_PERMANENT)) return;
MPlayer mplayer = event.getMSender(); MPlayer mplayer = event.getMPlayer();
if ( ! MConf.get().worldguardCheckWorldsEnabled.contains(mplayer.getPlayer())) return; if ( ! MConf.get().worldguardCheckWorldsEnabled.contains(mplayer.getPlayer())) return;