Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
This commit is contained in:
@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Econ;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.Factions;
|
||||
@ -234,6 +235,32 @@ public class FBaseCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if (!Econ.enabled() || this.me == null || cost == 0.0 || Conf.adminBypassPlayers.contains(me.getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String desc = this.helpDescription.toLowerCase();
|
||||
|
||||
// pay up
|
||||
if (cost > 0.0) {
|
||||
String costString = Econ.moneyString(cost);
|
||||
if (!Econ.deductMoney(me.getName(), cost)) {
|
||||
sendMessage("It costs "+costString+" to "+desc+", which you can't currently afford.");
|
||||
return false;
|
||||
}
|
||||
sendMessage("You have paid "+costString+" to "+desc+".");
|
||||
}
|
||||
// wait... we pay you to use this command?
|
||||
else {
|
||||
String costString = Econ.moneyString(-cost);
|
||||
Econ.addMoney(me.getName(), -cost);
|
||||
sendMessage("You have been paid "+costString+" to "+desc+".");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final List<String> aliasTrue = new ArrayList<String>(Arrays.asList("true", "yes", "y", "ok", "on", "+"));
|
||||
public static final List<String> aliasFalse = new ArrayList<String>(Arrays.asList("false", "no", "n", "off", "-"));
|
||||
|
||||
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Econ;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.Factions;
|
||||
@ -51,7 +52,12 @@ public class FCommandCreate extends FBaseCommand {
|
||||
sendMessage(tagValidationErrors);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostCreate)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction faction = Faction.create();
|
||||
faction.setTag(tag);
|
||||
me.setRole(Role.ADMIN);
|
||||
|
@ -29,7 +29,12 @@ public class FCommandDescription extends FBaseCommand {
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostDesc)) {
|
||||
return;
|
||||
}
|
||||
|
||||
me.getFaction().setDescription(TextUtil.implode(parameters));
|
||||
|
||||
// Broadcast the description to everyone
|
||||
|
@ -58,9 +58,9 @@ public class FCommandHome extends FBaseCommand {
|
||||
|
||||
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
|
||||
if (
|
||||
Conf.homesTeleportAllowedEnemyDistance > 0
|
||||
&& !faction.isSafeZone()
|
||||
&& (!me.isInOwnTerritory() || (me.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))
|
||||
Conf.homesTeleportAllowedEnemyDistance > 0
|
||||
&& !faction.isSafeZone()
|
||||
&& (!me.isInOwnTerritory() || (me.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))
|
||||
) {
|
||||
Location loc = player.getLocation();
|
||||
World w = loc.getWorld();
|
||||
@ -91,7 +91,12 @@ public class FCommandHome extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostHome)) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.teleport(myFaction.getHome());
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,12 @@ public class FCommandInvite extends FBaseCommand {
|
||||
sendMessage("You might want to: " + new FCommandKick().getUseageTemplate(false));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostInvite)) {
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.invite(you);
|
||||
|
||||
you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" invited you to "+myFaction.getTag(you));
|
||||
|
@ -54,6 +54,11 @@ public class FCommandJoin extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostJoin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
me.sendMessage(Conf.colorSystem+"You successfully joined "+faction.getTag(me));
|
||||
faction.sendMessage(me.getNameAndRelevant(faction)+Conf.colorSystem+" joined your faction.");
|
||||
|
||||
|
@ -57,6 +57,11 @@ public class FCommandKick extends FBaseCommand {
|
||||
}
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostKick)) {
|
||||
return;
|
||||
}
|
||||
|
||||
yourFaction.sendMessage(me.getNameAndRelevant(yourFaction)+Conf.colorSystem+" kicked "+you.getNameAndRelevant(yourFaction)+Conf.colorSystem+" from the faction! :O");
|
||||
you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" kicked you from "+yourFaction.getTag(you)+Conf.colorSystem+"! :O");
|
||||
if (yourFaction != myFaction) {
|
||||
|
@ -26,7 +26,7 @@ public class FCommandLeave extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
me.leave();
|
||||
me.leave(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,6 +36,11 @@ public class FCommandList extends FBaseCommand {
|
||||
FactionList.remove(Faction.getSafeZone());
|
||||
FactionList.remove(Faction.getWarZone());
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int page = 1;
|
||||
if (parameters.size() > 0) {
|
||||
try {
|
||||
|
@ -3,6 +3,7 @@ package com.massivecraft.factions.commands;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
|
||||
|
||||
@ -27,6 +28,12 @@ public class FCommandMap extends FBaseCommand {
|
||||
String mapAutoUpdating = parameters.get(0);
|
||||
if (parseBool(mapAutoUpdating)) {
|
||||
// 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(Conf.econCostMap)) {
|
||||
return;
|
||||
}
|
||||
|
||||
me.setMapAutoUpdating(true);
|
||||
sendMessage("Map auto update ENABLED.");
|
||||
|
||||
@ -38,6 +45,11 @@ public class FCommandMap extends FBaseCommand {
|
||||
sendMessage("Map auto update DISABLED.");
|
||||
}
|
||||
} else {
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostMap)) {
|
||||
return;
|
||||
}
|
||||
|
||||
showMap();
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,12 @@ public class FCommandOpen extends FBaseCommand {
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostOpen)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
myFaction.setOpen( ! me.getFaction().getOpen());
|
||||
|
||||
|
@ -94,6 +94,11 @@ public class FCommandOwner extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostOwner)) {
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.setPlayerAsOwner(playerName, flocation);
|
||||
me.sendMessage("You have added "+playerName+" to the owner list for this claimed land.");
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class FCommandPower extends FBaseCommand {
|
||||
}
|
||||
target = findFPlayer(parameters.get(0), false);
|
||||
} else if (!(sender instanceof Player)) {
|
||||
sendMessage("From the command line, you must specify a player (f power <player name>).");
|
||||
sendMessage("From the console, you must specify a player (f power <player name>).");
|
||||
return;
|
||||
} else {
|
||||
target = me;
|
||||
@ -45,7 +45,12 @@ public class FCommandPower extends FBaseCommand {
|
||||
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(Conf.econCostPower)) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendMessage(target.getNameAndRelevant(me)+Conf.colorChrome+" - Power / Maxpower: "+Conf.colorSystem+target.getPowerRounded()+" / "+target.getPowerMaxRounded());
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,12 @@ public class FCommandSethome extends FBaseCommand {
|
||||
me.sendMessage("Sorry, your faction home can only be set inside your own claimed territory.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostSethome)) {
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.setHome(player.getLocation());
|
||||
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" set the home for your faction. You can now use:");
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Econ;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
@ -45,7 +46,12 @@ public class FCommandShow extends FBaseCommand {
|
||||
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(Conf.econCostShow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<FPlayer> admins = faction.getFPlayersWhereRole(Role.ADMIN);
|
||||
Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR);
|
||||
Collection<FPlayer> normals = faction.getFPlayersWhereRole(Role.NORMAL);
|
||||
@ -62,7 +68,18 @@ public class FCommandShow extends FBaseCommand {
|
||||
sendMessage(Conf.colorChrome+"Joining: "+Conf.colorSystem+"invitation is required");
|
||||
}
|
||||
sendMessage(Conf.colorChrome+"Land / Power / Maxpower: "+Conf.colorSystem+ faction.getLandRounded()+" / "+faction.getPowerRounded()+" / "+faction.getPowerMaxRounded());
|
||||
|
||||
|
||||
// show the land value
|
||||
if (Econ.enabled()) {
|
||||
double value = Econ.calculateTotalLandValue(faction.getLandRounded());
|
||||
double refund = value * Conf.econClaimRefundMultiplier;
|
||||
if (value > 0) {
|
||||
String stringValue = Econ.moneyString(value);
|
||||
String stringRefund = (refund > 0.0) ? (" ("+Econ.moneyString(refund)+" depreciated)") : "";
|
||||
sendMessage(Conf.colorChrome+"Total land value: " + Conf.colorSystem + stringValue + stringRefund);
|
||||
}
|
||||
}
|
||||
|
||||
String listpart;
|
||||
|
||||
// List relation
|
||||
|
@ -48,6 +48,11 @@ public class FCommandTag extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(Conf.econCostTag)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
|
||||
String oldtag = myFaction.getTag();
|
||||
|
@ -40,7 +40,12 @@ public class FCommandTitle extends FBaseCommand {
|
||||
if ( ! canIAdministerYou(me, 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(Conf.econCostTitle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
you.setTitle(title);
|
||||
|
||||
// Inform
|
||||
|
@ -2,6 +2,7 @@ package com.massivecraft.factions.commands;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Econ;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.Factions;
|
||||
@ -69,10 +70,31 @@ public class FCommandUnclaim extends FBaseCommand {
|
||||
sendMessage("You don't own this land.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String moneyBack = "";
|
||||
if (Econ.enabled()) {
|
||||
double refund = Econ.calculateClaimRefund(myFaction.getLandRounded());
|
||||
// a real refund
|
||||
if (refund > 0.0) {
|
||||
Econ.addMoney(player.getName(), refund);
|
||||
moneyBack = " They received a refund of "+Econ.moneyString(refund)+".";
|
||||
}
|
||||
// wait, you're charging people to unclaim land? outrageous
|
||||
else if (refund < 0.0) {
|
||||
if (!Econ.deductMoney(player.getName(), -refund)) {
|
||||
sendMessage("Unclaiming this land will cost "+Econ.moneyString(-refund)+", which you can't currently afford.");
|
||||
return;
|
||||
}
|
||||
moneyBack = " It cost them "+Econ.moneyString(refund)+".";
|
||||
}
|
||||
// no refund
|
||||
else {
|
||||
moneyBack = "";
|
||||
}
|
||||
}
|
||||
|
||||
Board.removeAt(flocation);
|
||||
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" unclaimed some land.");
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" unclaimed some land."+moneyBack);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.massivecraft.factions.commands;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Econ;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
|
||||
@ -28,11 +29,33 @@ public class FCommandUnclaimall extends FBaseCommand {
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
|
||||
|
||||
String moneyBack = "";
|
||||
if (Econ.enabled()) {
|
||||
double refund = Econ.calculateTotalLandRefund(myFaction.getLandRounded());
|
||||
// a real refund
|
||||
if (refund > 0.0) {
|
||||
Econ.addMoney(player.getName(), refund);
|
||||
moneyBack = " They received a refund of "+Econ.moneyString(refund)+".";
|
||||
}
|
||||
// wait, you're charging people to unclaim land? outrageous
|
||||
else if (refund < 0.0) {
|
||||
if (!Econ.deductMoney(player.getName(), -refund)) {
|
||||
sendMessage("Unclaiming all faction land will cost "+Econ.moneyString(-refund)+", which you can't currently afford.");
|
||||
return;
|
||||
}
|
||||
moneyBack = " It cost them "+Econ.moneyString(refund)+".";
|
||||
}
|
||||
// no refund
|
||||
else {
|
||||
moneyBack = "";
|
||||
}
|
||||
}
|
||||
|
||||
Board.unclaimAll(myFaction.getId());
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" unclaimed ALL of your factions land.");
|
||||
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" unclaimed ALL of your factions land."+moneyBack);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,7 +46,13 @@ public class FRelationCommand extends FBaseCommand {
|
||||
sendMessage("Nope! You can't declare a relation to yourself :)");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
double cost = whishedRelation.isAlly() ? Conf.econCostAlly : (whishedRelation.isEnemy() ? Conf.econCostEnemy : Conf.econCostNeutral);
|
||||
if (!payForCommand(cost)) {
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.setRelationWish(otherFaction, whishedRelation);
|
||||
Relation currentRelation = myFaction.getRelation(otherFaction);
|
||||
ChatColor currentRelationColor = currentRelation.getColor();
|
||||
|
Reference in New Issue
Block a user