diff --git a/lib/iConomy.jar b/lib/iConomy.jar new file mode 100644 index 00000000..0826420b Binary files /dev/null and b/lib/iConomy.jar differ diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index a5911cc4..1bd773aa 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -23,12 +23,12 @@ public class Conf { public static ChatColor colorParameter = ChatColor.DARK_AQUA; // Power - public static double powerPlayerMax = 10; - public static double powerPlayerMin = -10; + public static double powerPlayerMax = 10.0; + public static double powerPlayerMin = -10.0; public static double powerPerMinute = 0.2; // Default health rate... it takes 5 min to heal one power - public static double powerPerDeath = 4; // A death makes you lose 4 power + public static double powerPerDeath = 4.0; // A death makes you lose 4 power public static boolean powerRegenOffline = false; // does player power regenerate even while they're offline? - public static double powerFactionMax = 0; // if greater than 0, the cap on how much power a faction can have (additional power from players beyond that will act as a "buffer" of sorts) + public static double powerFactionMax = 0.0; // if greater than 0, the cap on how much power a faction can have (additional power from players beyond that will act as a "buffer" of sorts) public static String prefixAdmin = "**"; public static String prefixMod = "*"; @@ -59,7 +59,7 @@ public class Conf { public static boolean allowNoSlashCommand = true; - public static double autoLeaveAfterDaysOfInactivity = 14; + public static double autoLeaveAfterDaysOfInactivity = 14.0; public static boolean homesEnabled = true; public static boolean homesMustBeInClaimedTerritory = true; @@ -68,7 +68,7 @@ public class Conf { public static boolean homesTeleportCommandEnabled = true; public static boolean homesTeleportAllowedFromEnemyTerritory = true; public static boolean homesTeleportAllowedFromDifferentWorld = true; - public static double homesTeleportAllowedEnemyDistance = 32; + public static double homesTeleportAllowedEnemyDistance = 32.0; public static boolean homesTeleportIgnoreEnemiesIfInOwnTerritory = true; public static boolean disablePVPBetweenNeutralFactions = false; @@ -79,7 +79,7 @@ public class Conf { public static boolean claimsCanBeUnconnectedIfOwnedByOtherFaction = true; public static int claimsRequireMinFactionMembers = 1; - public static double considerFactionsReallyOfflineAfterXMinutes = 0; + public static double considerFactionsReallyOfflineAfterXMinutes = 0.0; public static double territoryShieldFactor = 0.3; public static boolean territoryDenyBuild = true; @@ -133,6 +133,32 @@ public class Conf { public static Set territoryDenyUseageMaterialsWhenOffline = EnumSet.noneOf(Material.class); public static transient Set safeZoneNerfedCreatureTypes = EnumSet.noneOf(CreatureType.class); + + // Economy settings + public static boolean econIConomyEnabled = false; + public static double econCostClaimWilderness = 30.0; + public static double econCostClaimFromFactionBonus = 30.0; + public static double econClaimAdditionalMultiplier = 0.5; + public static double econClaimRefundMultiplier = 0.7; + public static double econCostCreate = 100.0; + public static double econCostOwner = 15.0; + public static double econCostSethome = 30.0; + public static double econCostJoin = 0.0; + public static double econCostLeave = 0.0; + public static double econCostKick = 0.0; + public static double econCostInvite = 0.0; + public static double econCostHome = 0.0; + public static double econCostTag = 0.0; + public static double econCostDesc = 0.0; + public static double econCostTitle = 0.0; + public static double econCostList = 0.0; + public static double econCostMap = 0.0; + public static double econCostPower = 0.0; + public static double econCostShow = 0.0; + public static double econCostOpen = 0.0; + public static double econCostAlly = 0.0; + public static double econCostEnemy = 0.0; + public static double econCostNeutral = 0.0; public static Set worldsNoClaiming = new HashSet(); public static Set worldsNoPowerLoss = new HashSet(); @@ -182,7 +208,7 @@ public class Conf { // track players with admin access who have enabled "admin bypass" mode, and should therefore be able to build anywhere // not worth saving between server restarts, I think public static transient Set adminBypassPlayers = Collections.synchronizedSet(new HashSet()); - + // -------------------------------------------- // // Persistance // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/Econ.java b/src/com/massivecraft/factions/Econ.java new file mode 100644 index 00000000..f8052aa5 --- /dev/null +++ b/src/com/massivecraft/factions/Econ.java @@ -0,0 +1,128 @@ +package com.massivecraft.factions; + +import org.bukkit.event.Event; + +import com.massivecraft.factions.listeners.FactionsServerListener; + +import com.iConomy.*; +import com.iConomy.system.*; + + +public class Econ { + private static iConomy iConomyPlugin; + + public static void monitorPlugins() { + Factions.instance.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE, new FactionsServerListener(), Event.Priority.Monitor, Factions.instance); + Factions.instance.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_DISABLE, new FactionsServerListener(), Event.Priority.Monitor, Factions.instance); + } + + public static void iConomySet(iConomy instance) { + iConomyPlugin = instance; + } + + public static boolean iConomyHooked() { + return iConomyPlugin != null; + } + + // If economy is enabled in conf.json, and we're successfully hooked into an economy plugin + public static boolean enabled() { + return Conf.econIConomyEnabled && iConomyPlugin != null; + } + + // mainly for internal use, for a little less code repetition + public static Holdings getIconomyHoldings(String playerName) { + if (!enabled()) { + return null; + } + + Account account = iConomy.getAccount(playerName); + if (account == null) { + return null; + } + Holdings holdings = account.getHoldings(); + return holdings; + } + + + // format money string based on server's set currency type, like "24 gold" or "$24.50" + public static String moneyString(double amount) { + return iConomy.format(amount); + } + + // whether a player can afford specified amount + public static boolean canAfford(String playerName, double amount) { + // if Economy support is not enabled, they can certainly afford to pay nothing + if (!enabled()) { + return true; + } + + Holdings holdings = getIconomyHoldings(playerName); + if (holdings == null) { + return false; + } + + return holdings.hasEnough(amount); + } + + // deduct money from their account; returns true if successful + public static boolean deductMoney(String playerName, double amount) { + if (!enabled()) { + return true; + } + + Holdings holdings = getIconomyHoldings(playerName); + if (holdings == null || !holdings.hasEnough(amount)) { + return false; + } + + holdings.subtract(amount); + return true; + } + + // add money to their account; returns true if successful + public static boolean addMoney(String playerName, double amount) { + if (!enabled()) { + return true; + } + + Holdings holdings = getIconomyHoldings(playerName); + if (holdings == null) { + return false; + } + + holdings.add(amount); + return true; + } + + + // calculate the cost for claiming land + public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction) { + if (!enabled()) { + return 0.0; + } + + // basic claim cost, plus land inflation cost, minus the potential bonus given for claiming from another faction + return Conf.econCostClaimWilderness + + (Conf.econCostClaimWilderness * Conf.econClaimAdditionalMultiplier * ownedLand) + - (takingFromAnotherFaction ? Conf.econCostClaimFromFactionBonus: 0); + } + + // calculate refund amount for unclaiming land + public static double calculateClaimRefund(int ownedLand) { + return calculateClaimCost(ownedLand - 1, false) * Conf.econClaimRefundMultiplier; + } + + // calculate value of all owned land + public static double calculateTotalLandValue(int ownedLand) { + double amount = 0; + for (int x = 0; x < ownedLand; x++) { + amount += calculateClaimCost(x, false); + } + return amount; + } + + // calculate refund amount for all owned land + public static double calculateTotalLandRefund(int ownedLand) { + return calculateTotalLandValue(ownedLand) * Conf.econClaimRefundMultiplier; + } +} diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 7d757020..49cb74fe 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -434,7 +434,7 @@ public class FPlayer { // Actions // ------------------------------- - public void leave() { + public void leave(boolean makePay) { Faction myFaction = this.getFaction(); if (this.getRole() == Role.ADMIN && myFaction.getFPlayers().size() > 1) { @@ -446,7 +446,27 @@ public class FPlayer { sendMessage("You cannot leave until your power is positive."); return; } - + + // if economy is enabled and they're not on the bypass list, make 'em pay + if (makePay && Econ.enabled() && !Conf.adminBypassPlayers.contains(this.playerName)) { + double cost = Conf.econCostLeave; + // pay up + if (cost > 0.0) { + String costString = Econ.moneyString(cost); + if (!Econ.deductMoney(this.getName(), cost)) { + sendMessage("It costs "+costString+" to leave your faction, which you can't currently afford."); + return; + } + sendMessage("You have paid "+costString+" to leave your faction."); + } + // wait... we pay you to leave? + else if (cost < 0.0) { + String costString = Econ.moneyString(-cost); + Econ.addMoney(this.getName(), -cost); + sendMessage("You have been paid "+costString+" for leaving your faction."); + } + } + if (myFaction.isNormal()) { myFaction.sendMessage(this.getNameAndRelevant(myFaction) + Conf.colorSystem + " left your faction."); } @@ -502,7 +522,8 @@ public class FPlayer { return false; } - if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) { + int ownedLand = myFaction.getLandRounded(); + if (ownedLand >= myFaction.getPowerRounded()) { sendMessage("You can't claim more land! You need more power!"); return false; } @@ -527,10 +548,7 @@ public class FPlayer { return false; } - if (otherFaction.isNone()) { - myFaction.sendMessage(this.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D"); - } else { //if (otherFaction.isNormal()) { - + if (otherFaction.isNormal()) { if ( ! otherFaction.hasLandInflation()) { // TODO more messages WARN current faction most importantly sendMessage(this.getRelationColor(otherFaction)+otherFaction.getTag()+Conf.colorSystem+" owns this land and is strong enough to keep it."); @@ -541,12 +559,29 @@ public class FPlayer { sendMessage("You must start claiming land at the border of the territory."); return false; } + } + // if economy is enabled and they're not on the bypass list, make 'em pay + if (Econ.enabled() && !Conf.adminBypassPlayers.contains(this.playerName)) { + double cost = Econ.calculateClaimCost(ownedLand, otherFaction.isNormal()); + String costString = Econ.moneyString(cost); + if (!Econ.deductMoney(this.playerName, cost)) { + sendMessage("Claiming this land will cost "+costString+", which you can't currently afford."); + return false; + } + sendMessage("You have paid "+costString+" to claim this land."); + } + + // announce success + if (otherFaction.isNormal()) { // ASDF claimed some of your land 450 blocks NNW of you. // ASDf claimed some land from FACTION NAME otherFaction.sendMessage(this.getNameAndRelevant(otherFaction)+Conf.colorSystem+" stole some of your land :O"); myFaction.sendMessage(this.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some land from "+otherFaction.getTag(myFaction)); } + else { + myFaction.sendMessage(this.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D"); + } Board.setFactionAt(myFaction, flocation); return true; @@ -687,7 +722,7 @@ public class FPlayer { for (FPlayer fplayer : FPlayer.getAll()) { if (now - fplayer.getLastLoginTime() > toleranceMillis) { - fplayer.leave(); + fplayer.leave(false); } } } diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 4cad945e..40403d3e 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -147,6 +147,8 @@ public class Factions extends JavaPlugin { setupPermissions(); integrateEssentialsChat(); + Econ.monitorPlugins(); + // Register events PluginManager pm = this.getServer().getPluginManager(); pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this); diff --git a/src/com/massivecraft/factions/commands/FBaseCommand.java b/src/com/massivecraft/factions/commands/FBaseCommand.java index 4df12573..c97667ad 100644 --- a/src/com/massivecraft/factions/commands/FBaseCommand.java +++ b/src/com/massivecraft/factions/commands/FBaseCommand.java @@ -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 aliasTrue = new ArrayList(Arrays.asList("true", "yes", "y", "ok", "on", "+")); public static final List aliasFalse = new ArrayList(Arrays.asList("false", "no", "n", "off", "-")); diff --git a/src/com/massivecraft/factions/commands/FCommandCreate.java b/src/com/massivecraft/factions/commands/FCommandCreate.java index bd512e14..e833af6c 100644 --- a/src/com/massivecraft/factions/commands/FCommandCreate.java +++ b/src/com/massivecraft/factions/commands/FCommandCreate.java @@ -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); diff --git a/src/com/massivecraft/factions/commands/FCommandDescription.java b/src/com/massivecraft/factions/commands/FCommandDescription.java index 8040da19..c45049e5 100644 --- a/src/com/massivecraft/factions/commands/FCommandDescription.java +++ b/src/com/massivecraft/factions/commands/FCommandDescription.java @@ -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 diff --git a/src/com/massivecraft/factions/commands/FCommandHome.java b/src/com/massivecraft/factions/commands/FCommandHome.java index cba1ab46..a3483c22 100644 --- a/src/com/massivecraft/factions/commands/FCommandHome.java +++ b/src/com/massivecraft/factions/commands/FCommandHome.java @@ -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()); } diff --git a/src/com/massivecraft/factions/commands/FCommandInvite.java b/src/com/massivecraft/factions/commands/FCommandInvite.java index ffd3a742..3b17c6dc 100644 --- a/src/com/massivecraft/factions/commands/FCommandInvite.java +++ b/src/com/massivecraft/factions/commands/FCommandInvite.java @@ -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)); diff --git a/src/com/massivecraft/factions/commands/FCommandJoin.java b/src/com/massivecraft/factions/commands/FCommandJoin.java index d984e20c..338f31b2 100644 --- a/src/com/massivecraft/factions/commands/FCommandJoin.java +++ b/src/com/massivecraft/factions/commands/FCommandJoin.java @@ -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."); diff --git a/src/com/massivecraft/factions/commands/FCommandKick.java b/src/com/massivecraft/factions/commands/FCommandKick.java index 667f10cf..4b95faf3 100644 --- a/src/com/massivecraft/factions/commands/FCommandKick.java +++ b/src/com/massivecraft/factions/commands/FCommandKick.java @@ -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) { diff --git a/src/com/massivecraft/factions/commands/FCommandLeave.java b/src/com/massivecraft/factions/commands/FCommandLeave.java index 306bb881..a8d6dab2 100644 --- a/src/com/massivecraft/factions/commands/FCommandLeave.java +++ b/src/com/massivecraft/factions/commands/FCommandLeave.java @@ -26,7 +26,7 @@ public class FCommandLeave extends FBaseCommand { return; } - me.leave(); + me.leave(true); } } diff --git a/src/com/massivecraft/factions/commands/FCommandList.java b/src/com/massivecraft/factions/commands/FCommandList.java index 98a62517..e789d541 100644 --- a/src/com/massivecraft/factions/commands/FCommandList.java +++ b/src/com/massivecraft/factions/commands/FCommandList.java @@ -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 { diff --git a/src/com/massivecraft/factions/commands/FCommandMap.java b/src/com/massivecraft/factions/commands/FCommandMap.java index 6f567bed..71b95612 100644 --- a/src/com/massivecraft/factions/commands/FCommandMap.java +++ b/src/com/massivecraft/factions/commands/FCommandMap.java @@ -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(); } } diff --git a/src/com/massivecraft/factions/commands/FCommandOpen.java b/src/com/massivecraft/factions/commands/FCommandOpen.java index 782be865..5a378f70 100644 --- a/src/com/massivecraft/factions/commands/FCommandOpen.java +++ b/src/com/massivecraft/factions/commands/FCommandOpen.java @@ -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()); diff --git a/src/com/massivecraft/factions/commands/FCommandOwner.java b/src/com/massivecraft/factions/commands/FCommandOwner.java index 0ba17535..0b1b5860 100644 --- a/src/com/massivecraft/factions/commands/FCommandOwner.java +++ b/src/com/massivecraft/factions/commands/FCommandOwner.java @@ -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."); } diff --git a/src/com/massivecraft/factions/commands/FCommandPower.java b/src/com/massivecraft/factions/commands/FCommandPower.java index e675f4b8..a8d29dfe 100644 --- a/src/com/massivecraft/factions/commands/FCommandPower.java +++ b/src/com/massivecraft/factions/commands/FCommandPower.java @@ -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 )."); + sendMessage("From the console, you must specify a player (f power )."); 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()); } diff --git a/src/com/massivecraft/factions/commands/FCommandSethome.java b/src/com/massivecraft/factions/commands/FCommandSethome.java index bcbbc5ce..9a1d77d8 100644 --- a/src/com/massivecraft/factions/commands/FCommandSethome.java +++ b/src/com/massivecraft/factions/commands/FCommandSethome.java @@ -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:"); diff --git a/src/com/massivecraft/factions/commands/FCommandShow.java b/src/com/massivecraft/factions/commands/FCommandShow.java index 01926859..251db260 100644 --- a/src/com/massivecraft/factions/commands/FCommandShow.java +++ b/src/com/massivecraft/factions/commands/FCommandShow.java @@ -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 admins = faction.getFPlayersWhereRole(Role.ADMIN); Collection mods = faction.getFPlayersWhereRole(Role.MODERATOR); Collection 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 diff --git a/src/com/massivecraft/factions/commands/FCommandTag.java b/src/com/massivecraft/factions/commands/FCommandTag.java index fa6fa353..71c51ffd 100644 --- a/src/com/massivecraft/factions/commands/FCommandTag.java +++ b/src/com/massivecraft/factions/commands/FCommandTag.java @@ -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(); diff --git a/src/com/massivecraft/factions/commands/FCommandTitle.java b/src/com/massivecraft/factions/commands/FCommandTitle.java index c2b8d3a5..690a92ba 100644 --- a/src/com/massivecraft/factions/commands/FCommandTitle.java +++ b/src/com/massivecraft/factions/commands/FCommandTitle.java @@ -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 diff --git a/src/com/massivecraft/factions/commands/FCommandUnclaim.java b/src/com/massivecraft/factions/commands/FCommandUnclaim.java index 1577856c..ae21ddcd 100644 --- a/src/com/massivecraft/factions/commands/FCommandUnclaim.java +++ b/src/com/massivecraft/factions/commands/FCommandUnclaim.java @@ -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); } } diff --git a/src/com/massivecraft/factions/commands/FCommandUnclaimall.java b/src/com/massivecraft/factions/commands/FCommandUnclaimall.java index d8a62757..8fdb103f 100644 --- a/src/com/massivecraft/factions/commands/FCommandUnclaimall.java +++ b/src/com/massivecraft/factions/commands/FCommandUnclaimall.java @@ -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); } } diff --git a/src/com/massivecraft/factions/commands/FRelationCommand.java b/src/com/massivecraft/factions/commands/FRelationCommand.java index bf5dfeeb..4001d361 100644 --- a/src/com/massivecraft/factions/commands/FRelationCommand.java +++ b/src/com/massivecraft/factions/commands/FRelationCommand.java @@ -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(); diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 11bd1edf..3c6cb9f8 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -21,6 +21,7 @@ import org.bukkit.event.player.PlayerRespawnEvent; import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; +import com.massivecraft.factions.Econ; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; @@ -159,13 +160,14 @@ public class FactionsPlayerListener extends PlayerListener{ if (me.autoClaimEnabled()) { Faction myFaction = me.getFaction(); - FLocation flocation = new FLocation(me); + Faction otherFaction = Board.getFactionAt(to); + double cost = Econ.calculateClaimCost(myFaction.getLandRounded(), otherFaction.isNormal()); if (me.getRole().value < Role.MODERATOR.value) { me.sendMessage("You must be "+Role.MODERATOR+" to claim land."); me.enableAutoClaim(false); } - else if (Conf.worldsNoClaiming.contains(flocation.getWorldName())) { + else if (Conf.worldsNoClaiming.contains(to.getWorldName())) { me.sendMessage("Sorry, this world has land claiming disabled."); me.enableAutoClaim(false); } @@ -173,6 +175,11 @@ public class FactionsPlayerListener extends PlayerListener{ me.sendMessage("You can't claim more land! You need more power!"); me.enableAutoClaim(false); } + else if (!Econ.canAfford(player.getName(), cost)) { + String costString = Econ.moneyString(cost); + me.sendMessage("Claiming this land will cost "+costString+", which you can't currently afford."); + me.enableAutoClaim(false); + } else me.attemptClaim(false); } diff --git a/src/com/massivecraft/factions/listeners/FactionsServerListener.java b/src/com/massivecraft/factions/listeners/FactionsServerListener.java new file mode 100644 index 00000000..2e7f9460 --- /dev/null +++ b/src/com/massivecraft/factions/listeners/FactionsServerListener.java @@ -0,0 +1,39 @@ +package com.massivecraft.factions.listeners; + +import org.bukkit.plugin.Plugin; +import org.bukkit.event.server.ServerListener; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; + +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.Econ; +import com.massivecraft.factions.Factions; + +import com.iConomy.*; + + +public class FactionsServerListener extends ServerListener { + @Override + public void onPluginDisable(PluginDisableEvent event) { + if (Econ.iConomyHooked()) { + if (event.getPlugin().getDescription().getName().equals("iConomy")) { + Econ.iConomySet(null); + Factions.log("Un-hooked from iConomy."); + } + } + } + + @Override + public void onPluginEnable(PluginEnableEvent event) { + if (!Econ.iConomyHooked()) { + Plugin iConomy = Factions.instance.getServer().getPluginManager().getPlugin("iConomy"); + + if (iConomy != null) { + if (iConomy.isEnabled() && iConomy.getClass().getName().equals("com.iConomy.iConomy")) { + Econ.iConomySet((iConomy)iConomy); + Factions.log("Hooked into iConomy, "+(Conf.econIConomyEnabled ? "and interface is enabled" : "but interface is currently disabled (\"econIConomyEnabled\": false)")+"."); + } + } + } + } +} \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml index 362e1e7e..1ad3cb16 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -8,6 +8,7 @@ softdepend: - HeroChat - iChat - LocalAreaChat + - iConomy commands: f: description: All of the Factions commands