Minor touches to the Econ integration

This commit is contained in:
Olof Larsson
2013-04-19 09:50:33 +02:00
parent 1df5638903
commit 2f8f0713e8
26 changed files with 223 additions and 140 deletions

View File

@ -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);

View File

@ -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));

View File

@ -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());

View File

@ -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)
{

View File

@ -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);

View File

@ -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("<i>%s moved you into the faction %s.", fme.describeTo(fplayer, true), faction.getTag(fplayer));

View File

@ -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<i> kicked %s<i> from the faction! :O", fme.describeTo(yourFaction, true), you.describeTo(yourFaction, true));
you.msg("%s<i> kicked you from %s<i>! :O", fme.describeTo(you, true), yourFaction.describeTo(you));

View File

@ -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<String> lines = new ArrayList<String>();

View File

@ -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("<i>Map auto update <green>ENABLED.");

View File

@ -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);

View File

@ -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 + ")";

View File

@ -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);

View File

@ -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("<b>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<i> set the home for your faction. You can now use:", fme.describeTo(myFaction, true));
faction.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsHome.getUseageTemplate());

View File

@ -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<FPlayer> admins = faction.getFPlayersWhereRole(Rel.LEADER);
Collection<FPlayer> mods = faction.getFPlayersWhereRole(Rel.OFFICER);
@ -64,7 +64,7 @@ public class CmdFactionsShow extends FCommand
msg("<a>Land / Power / Maxpower: <i> %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;

View File

@ -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);

View File

@ -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);

View File

@ -38,17 +38,17 @@ public class CmdFactionsUnclaim extends FCommand
if(unclaimEvent.isCancelled()) return;
//String moneyBack = "<i>";
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;
}
}

View File

@ -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;
}
}

View File

@ -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());
}
}