diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java index 8264418f..03806361 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java @@ -9,6 +9,7 @@ import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.event.FactionsEventChunkChangeType; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.Perm; @@ -34,6 +35,8 @@ public class CmdFactionsShow extends FCommand { Faction faction = this.arg(0, ARFaction.get(myFaction), myFaction); if (faction == null) return; + + UConf uconf = UConf.get(faction); Collection leaders = faction.getUPlayersWhereRole(Rel.LEADER); Collection officers = faction.getUPlayersWhereRole(Rel.OFFICER); @@ -64,18 +67,30 @@ public class CmdFactionsShow extends FCommand // show the land value if (Econ.isEnabled(faction)) { - double value = Econ.calculateTotalLandValue(faction.getLandCount()); + long landCount = faction.getLandCount(); - double refund = value * UConf.get(faction).econClaimRefundMultiplier; - if (value > 0) + for (FactionsEventChunkChangeType type : FactionsEventChunkChangeType.values()) { - String stringValue = Money.format(faction, value); - String stringRefund = (refund > 0.0) ? (" ("+Money.format(faction, refund)+" depreciated)") : ""; - msg("Total land value: " + stringValue + stringRefund); + Double money = uconf.econChunkCost.get(type); + if (money == null) money = 0D; + money *= landCount; + + String word = null; + if (money > 0) + { + word = "cost"; + } + else + { + word = "reward"; + money *= -1; + } + + msg("Total land %s %s: %s", type.toString().toLowerCase(), word, Money.format(faction, money)); } // Show bank contents - if(UConf.get(faction).bankEnabled) + if (UConf.get(faction).bankEnabled) { msg("Bank contains: "+Money.format(faction, Money.get(faction))); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java index 0fff61c3..d0c2aca7 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java @@ -2,10 +2,9 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColls; import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.UConf; -import com.massivecraft.factions.event.FactionsEventLandUnclaim; -import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.event.FactionsEventChunkChange; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; @@ -30,30 +29,21 @@ public class CmdFactionsUnclaim extends FCommand PS chunk = PS.valueOf(me).getChunk(true); Faction otherFaction = BoardColls.get().getFactionAt(chunk); + Faction newFaction = FactionColls.get().get(me).getNone(); + // FPerm + // TODO: Recode so that pillage is possible if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return; // Event - FactionsEventLandUnclaim event = new FactionsEventLandUnclaim(sender, otherFaction, chunk); + FactionsEventChunkChange event = new FactionsEventChunkChange(sender, chunk, newFaction); event.run(); if (event.isCancelled()) return; - - //String moneyBack = ""; - if (Econ.isEnabled(myFaction)) - { - double refund = Econ.calculateClaimRefund(myFaction); - - if (UConf.get(myFaction).bankEnabled && UConf.get(myFaction).bankFactionPaysLandCosts) - { - if ( ! Econ.modifyMoney(myFaction, refund, "unclaim this land")) return; - } - else - { - if ( ! Econ.modifyMoney(fme, refund, "unclaim this land")) return; - } - } - BoardColls.get().removeAt(chunk); + // Apply + BoardColls.get().setFactionAt(chunk, newFaction); + + // Inform myFaction.msg("%s unclaimed some land.", fme.describeTo(myFaction, true)); if (MConf.get().logLandUnclaims) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java index cb2f47fc..cadf49b9 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java @@ -1,15 +1,19 @@ package com.massivecraft.factions.cmd; +import java.util.Set; + import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; +import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.BoardColls; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColls; import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.UConf; -import com.massivecraft.factions.event.FactionsEventLandUnclaimAll; -import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.event.FactionsEventChunkChange; import com.massivecraft.mcore.cmd.req.ReqHasPerm; +import com.massivecraft.mcore.ps.PS; public class CmdFactionsUnclaimall extends FCommand { @@ -24,32 +28,36 @@ public class CmdFactionsUnclaimall extends FCommand @Override public void perform() { - // TODO: Put this as a listener and not in here! - if (Econ.isEnabled(myFaction)) + // Args + Faction faction = myFaction; + + Faction newFaction = FactionColls.get().get(faction).getNone(); + + // Apply + BoardColl boardColl = BoardColls.get().get(faction); + Set chunks = boardColl.getChunks(faction); + int countTotal = chunks.size(); + int countSuccess = 0; + int countFail = 0; + for (PS chunk : chunks) { - double refund = Econ.calculateTotalLandRefund(myFaction.getLandCount()); - - if (UConf.get(myFaction).bankEnabled && UConf.get(myFaction).bankFactionPaysLandCosts) + FactionsEventChunkChange event = new FactionsEventChunkChange(sender, chunk, newFaction); + event.run(); + if (event.isCancelled()) { - if ( ! Econ.modifyMoney(myFaction, refund, "unclaim all faction land")) return; + countFail++; } else { - if ( ! Econ.modifyMoney(fme, refund, "unclaim all faction land")) return; + countSuccess++; + boardColl.setFactionAt(chunk, newFaction); } } - - // Event - FactionsEventLandUnclaimAll event = new FactionsEventLandUnclaimAll(sender, myFaction); - event.run(); - // TODO: this event cannot be cancelled yet. - - // Apply - BoardColls.get().removeAll(myFaction); // Inform - myFaction.msg("%s unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true)); + myFaction.msg("%s unclaimed 5 of your 200 faction land. You now have 23 land left.", fme.describeTo(myFaction, true), countSuccess, countTotal, countFail); + // Log if (MConf.get().logLandUnclaims) { Factions.get().log(fme.getName()+" unclaimed everything for the faction: "+myFaction.getTag()); diff --git a/src/com/massivecraft/factions/entity/Board.java b/src/com/massivecraft/factions/entity/Board.java index b9447ce0..15cb5472 100644 --- a/src/com/massivecraft/factions/entity/Board.java +++ b/src/com/massivecraft/factions/entity/Board.java @@ -4,8 +4,10 @@ import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.ConcurrentSkipListMap; import org.bukkit.ChatColor; @@ -177,6 +179,29 @@ public class Board extends Entity implements BoardInterface } } + // CHUNKS + + @Override + public Set getChunks(Faction faction) + { + return this.getChunks(faction.getId()); + } + + public Set getChunks(String factionId) + { + Set ret = new HashSet(); + for (Entry entry : this.map.entrySet()) + { + TerritoryAccess ta = entry.getValue(); + if (!ta.getHostFactionId().equals(factionId)) continue; + + PS ps = entry.getKey(); + ps = ps.withWorld(this.getId()); + ret.add(ps); + } + return ret; + } + // COUNT @Override @@ -188,9 +213,11 @@ public class Board extends Entity implements BoardInterface public int getCount(String factionId) { int ret = 0; - for (TerritoryAccess territoryAccess : this.map.values()) + for (TerritoryAccess ta : this.map.values()) { - if(territoryAccess.getHostFactionId().equals(factionId)) ret += 1; + if (!ta.getHostFactionId().equals(factionId)) continue; + + ret += 1; } return ret; } diff --git a/src/com/massivecraft/factions/entity/BoardColl.java b/src/com/massivecraft/factions/entity/BoardColl.java index 97eee39e..ea17dd47 100644 --- a/src/com/massivecraft/factions/entity/BoardColl.java +++ b/src/com/massivecraft/factions/entity/BoardColl.java @@ -1,6 +1,8 @@ package com.massivecraft.factions.entity; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; @@ -107,6 +109,19 @@ public class BoardColl extends Coll implements BoardInterface } } + // CHUNKS + + @Override + public Set getChunks(Faction faction) + { + Set ret = new HashSet(); + for (Board board : this.getAll()) + { + ret.addAll(board.getChunks(faction)); + } + return ret; + } + // COUNT @Override diff --git a/src/com/massivecraft/factions/entity/BoardColls.java b/src/com/massivecraft/factions/entity/BoardColls.java index 563e6763..0ad410a0 100644 --- a/src/com/massivecraft/factions/entity/BoardColls.java +++ b/src/com/massivecraft/factions/entity/BoardColls.java @@ -3,7 +3,9 @@ package com.massivecraft.factions.entity; import java.io.File; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.Map.Entry; import org.bukkit.Bukkit; @@ -194,8 +196,19 @@ public class BoardColls extends Colls implements BoardInterfac } } - // COUNT + // CHUNKS + @Override + public Set getChunks(Faction faction) + { + Set ret = new HashSet(); + for (BoardColl coll : this.getColls()) + { + ret.addAll(coll.getChunks(faction)); + } + return ret; + } + // COUNT @Override public int getCount(Faction faction) { diff --git a/src/com/massivecraft/factions/entity/BoardInterface.java b/src/com/massivecraft/factions/entity/BoardInterface.java index e1f79462..db6c4d97 100644 --- a/src/com/massivecraft/factions/entity/BoardInterface.java +++ b/src/com/massivecraft/factions/entity/BoardInterface.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.entity; import java.util.ArrayList; +import java.util.Set; import com.massivecraft.factions.RelationParticipator; import com.massivecraft.factions.TerritoryAccess; @@ -20,6 +21,9 @@ public interface BoardInterface public void removeAt(PS ps); public void removeAll(Faction faction); public void clean(); + + // CHUNKS + public Set getChunks(Faction faction); // COUNT public int getCount(Faction faction); diff --git a/src/com/massivecraft/factions/entity/UConf.java b/src/com/massivecraft/factions/entity/UConf.java index f8759e32..8342e44d 100644 --- a/src/com/massivecraft/factions/entity/UConf.java +++ b/src/com/massivecraft/factions/entity/UConf.java @@ -9,6 +9,7 @@ import com.massivecraft.factions.Const; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.event.FactionsEventChunkChangeType; import com.massivecraft.mcore.store.Entity; import com.massivecraft.mcore.util.MUtil; @@ -138,11 +139,12 @@ public class UConf extends Entity public String econUniverseAccount = ""; - public double econCostClaimWilderness = 30.0; - public double econCostClaimFromFactionBonus = 30.0; - public double econClaimAdditionalMultiplier = 0.5; - public double econClaimRefundMultiplier = 0.7; - public double econClaimUnconnectedFee = 0.0; + public Map econChunkCost = MUtil.map( + FactionsEventChunkChangeType.BUY, 30.0, + FactionsEventChunkChangeType.SELL, -20.0, + FactionsEventChunkChangeType.CONQUER, -10.0, + FactionsEventChunkChangeType.PILLAGE, -10.0 + ); public double econCostCreate = 100.0; public double econCostSethome = 0.0; diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index 37dfcc0e..9c79f888 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -14,7 +14,7 @@ import com.massivecraft.factions.Factions; import com.massivecraft.factions.Lang; import com.massivecraft.factions.Rel; import com.massivecraft.factions.RelationParticipator; -import com.massivecraft.factions.event.FactionsEventLandClaim; +import com.massivecraft.factions.event.FactionsEventChunkChange; import com.massivecraft.factions.event.FactionsEventMembershipChange; import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason; import com.massivecraft.factions.integration.Econ; @@ -641,26 +641,14 @@ public class UPlayer extends SenderEntity implements EconomyParticipato { psChunk = psChunk.getChunk(true); Faction currentFaction = BoardColls.get().getFactionAt(psChunk); - int ownedLand = forFaction.getLandCount(); if ( ! this.canClaimForFactionAtLocation(forFaction, psChunk, notifyFailure)) return false; // Event - FactionsEventLandClaim event = new FactionsEventLandClaim(sender, forFaction, psChunk); + FactionsEventChunkChange event = new FactionsEventChunkChange(sender, psChunk, forFaction); event.run(); if (event.isCancelled()) return false; - // then make 'em pay (if applicable) - // TODO: The economy integration should cancel the event above! - // Calculate the cost to claim the area - double cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal()); - - if (UConf.get(psChunk).econClaimUnconnectedFee != 0.0 && forFaction.getLandCountInWorld(psChunk.getWorld()) > 0 && !BoardColls.get().isConnectedPs(psChunk, forFaction)) - { - cost += UConf.get(psChunk).econClaimUnconnectedFee; - } - if (Econ.payForAction(cost, this, "claim this land")) return false; - // TODO: The LWC integration should listen to Monitor for the claim event. if (LWCFeatures.getEnabled() && forFaction.isNormal() && UConf.get(forFaction).lwcRemoveOnCapture) { diff --git a/src/com/massivecraft/factions/event/FactionsEventAbstractSender.java b/src/com/massivecraft/factions/event/FactionsEventAbstractSender.java index fd38499f..32aab0f8 100644 --- a/src/com/massivecraft/factions/event/FactionsEventAbstractSender.java +++ b/src/com/massivecraft/factions/event/FactionsEventAbstractSender.java @@ -13,7 +13,7 @@ public abstract class FactionsEventAbstractSender extends MCoreEvent private final CommandSender sender; public CommandSender getSender() { return this.sender; } - public UPlayer getFSender() { return UPlayer.get(this.sender); } + public UPlayer getUSender() { return this.sender == null ? null : UPlayer.get(this.sender); } // -------------------------------------------- // // CONSTRUCT diff --git a/src/com/massivecraft/factions/event/FactionsEventChunkChange.java b/src/com/massivecraft/factions/event/FactionsEventChunkChange.java new file mode 100644 index 00000000..b2414c3a --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventChunkChange.java @@ -0,0 +1,59 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.entity.BoardColls; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.UPlayer; +import com.massivecraft.mcore.ps.PS; + +public class FactionsEventChunkChange extends FactionsEventAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final PS chunk; + public PS getChunk() { return this.chunk; } + + private final Faction newFaction; + public Faction getNewFaction() { return this.newFaction; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsEventChunkChange(CommandSender sender, PS chunk, Faction newFaction) + { + super(sender); + this.chunk = chunk.getChunk(true); + this.newFaction = newFaction; + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public FactionsEventChunkChangeType getType() + { + Faction currentFaction = BoardColls.get().getFactionAt(chunk); + + if (currentFaction.isNone()) return FactionsEventChunkChangeType.BUY; + if (newFaction.isNormal()) return FactionsEventChunkChangeType.CONQUER; + + UPlayer usender = this.getUSender(); + if (usender != null && usender.getFaction() == currentFaction) return FactionsEventChunkChangeType.SELL; + + return FactionsEventChunkChangeType.PILLAGE; + } + +} diff --git a/src/com/massivecraft/factions/event/FactionsEventChunkChangeType.java b/src/com/massivecraft/factions/event/FactionsEventChunkChangeType.java new file mode 100644 index 00000000..851ef708 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventChunkChangeType.java @@ -0,0 +1,10 @@ +package com.massivecraft.factions.event; + +public enum FactionsEventChunkChangeType +{ + BUY, + SELL, + CONQUER, + PILLAGE, + ; +} diff --git a/src/com/massivecraft/factions/event/FactionsEventLandClaim.java b/src/com/massivecraft/factions/event/FactionsEventLandClaim.java deleted file mode 100644 index e57920d4..00000000 --- a/src/com/massivecraft/factions/event/FactionsEventLandClaim.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.massivecraft.factions.event; - -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.mcore.ps.PS; - -public class FactionsEventLandClaim extends FactionsEventAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private final PS chunk; - public PS getChunk() { return this.chunk; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public FactionsEventLandClaim(CommandSender sender, Faction faction, PS chunk) - { - super(sender); - this.faction = faction; - this.chunk = chunk.getChunk(true); - } - -} diff --git a/src/com/massivecraft/factions/event/FactionsEventLandUnclaim.java b/src/com/massivecraft/factions/event/FactionsEventLandUnclaim.java deleted file mode 100644 index 0abcd534..00000000 --- a/src/com/massivecraft/factions/event/FactionsEventLandUnclaim.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.massivecraft.factions.event; - -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.mcore.ps.PS; - -public class FactionsEventLandUnclaim extends FactionsEventAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private final PS chunk; - public PS getChunk() { return this.chunk; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public FactionsEventLandUnclaim(CommandSender sender, Faction faction, PS chunk) - { - super(sender); - this.chunk = chunk.getChunk(true); - this.faction = faction; - } - -} diff --git a/src/com/massivecraft/factions/event/FactionsEventLandUnclaimAll.java b/src/com/massivecraft/factions/event/FactionsEventLandUnclaimAll.java deleted file mode 100644 index 9431c411..00000000 --- a/src/com/massivecraft/factions/event/FactionsEventLandUnclaimAll.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.massivecraft.factions.event; - -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -import com.massivecraft.factions.entity.Faction; - -public class FactionsEventLandUnclaimAll extends FactionsEventAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public FactionsEventLandUnclaimAll(CommandSender sender, Faction faction) - { - super(sender); - this.faction = faction; - } - -} diff --git a/src/com/massivecraft/factions/integration/Econ.java b/src/com/massivecraft/factions/integration/Econ.java index 41f68b36..ef1ce76f 100644 --- a/src/com/massivecraft/factions/integration/Econ.java +++ b/src/com/massivecraft/factions/integration/Econ.java @@ -2,12 +2,9 @@ package com.massivecraft.factions.integration; import java.util.HashSet; import java.util.Set; -import java.util.logging.Level; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.EconomyParticipator; import com.massivecraft.factions.FPerm; -import com.massivecraft.factions.Factions; import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.Faction; @@ -279,41 +276,4 @@ public class Econ } } - // -------------------------------------------- // - // LAND VALUE - // -------------------------------------------- // - // TODO: Clean up! - - // calculate the cost for claiming land - public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction) - { - // basic claim cost, plus land inflation cost, minus the potential bonus given for claiming from another faction - return ConfServer.econCostClaimWilderness - + (ConfServer.econCostClaimWilderness * ConfServer.econClaimAdditionalMultiplier * ownedLand) - - (takingFromAnotherFaction ? ConfServer.econCostClaimFromFactionBonus: 0); - } - - // calculate refund amount for unclaiming land - public static double calculateClaimRefund(Faction forFaction) - { - return calculateClaimCost(forFaction.getLandCount() - 1, false) * ConfServer.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) * ConfServer.econClaimRefundMultiplier; - } - } diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java index 2531b9ff..dbf2821c 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java @@ -6,8 +6,12 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.UConf; +import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.event.FactionsEventAbstractSender; +import com.massivecraft.factions.event.FactionsEventChunkChange; +import com.massivecraft.factions.event.FactionsEventChunkChangeType; import com.massivecraft.factions.event.FactionsEventCreate; import com.massivecraft.factions.event.FactionsEventDescriptionChange; import com.massivecraft.factions.event.FactionsEventHomeChange; @@ -20,7 +24,6 @@ import com.massivecraft.factions.event.FactionsEventRelationChange; import com.massivecraft.factions.event.FactionsEventTagChange; import com.massivecraft.factions.event.FactionsEventTitleChange; import com.massivecraft.factions.integration.Econ; -import com.massivecraft.mcore.cmd.MCommand; public class FactionsListenerEcon implements Listener { @@ -42,106 +45,148 @@ public class FactionsListenerEcon implements Listener } // -------------------------------------------- // - // PAY FOR COMMAND + // PAY FOR ACTION // -------------------------------------------- // - public void payForCommand(FactionsEventAbstractSender event, double cost, MCommand command) + public static void payForAction(FactionsEventAbstractSender event, Double cost, String desc) { // If there is a sender ... - if (event.getSender() == null) return; + UPlayer usender = event.getUSender(); + if (usender == null) return; - // ... and the sender can't afford ... - if (Econ.payForAction(cost, event.getFSender(), command.getDesc())) 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; // ... then cancel. event.setCancelled(true); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(FactionsEventHomeChange event) + public void payForAction(FactionsEventChunkChange event) { - payForCommand(event, UConf.get(event.getSender()).econCostSethome, Factions.get().getOuterCmdFactions().cmdFactionsSethome); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(FactionsEventCreate event) - { - payForCommand(event, UConf.get(event.getSender()).econCostCreate, Factions.get().getOuterCmdFactions().cmdFactionsCreate); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(FactionsEventDescriptionChange event) - { - payForCommand(event, UConf.get(event.getSender()).econCostDescription, Factions.get().getOuterCmdFactions().cmdFactionsDescription); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(FactionsEventTagChange event) - { - payForCommand(event, UConf.get(event.getSender()).econCostTag, Factions.get().getOuterCmdFactions().cmdFactionsTag); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(FactionsEventTitleChange event) - { - payForCommand(event, UConf.get(event.getSender()).econCostTitle, Factions.get().getOuterCmdFactions().cmdFactionsTitle); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(FactionsEventRelationChange event) - { - Double cost = UConf.get(event.getSender()).econRelCost.get(event.getNewRelation()); - if (cost == null) return; - if (cost == 0) return; + Faction newFaction = event.getNewFaction(); + UConf uconf = UConf.get(newFaction); + FactionsEventChunkChangeType type = event.getType(); + Double cost = uconf.econChunkCost.get(type); - payForCommand(event, cost, Factions.get().getOuterCmdFactions().cmdFactionsRelationNeutral); + String desc = type.toString().toLowerCase() + " this land"; + + payForAction(event, cost, desc); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(FactionsEventOpenChange event) + public void payForAction(FactionsEventMembershipChange event) { - payForCommand(event, UConf.get(event.getSender()).econCostOpen, Factions.get().getOuterCmdFactions().cmdFactionsOpen); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(FactionsEventInvitedChange event) - { - double cost = event.isNewInvited() ? UConf.get(event.getSender()).econCostInvite : UConf.get(event.getSender()).econCostDeinvite; - payForCommand(event, cost, Factions.get().getOuterCmdFactions().cmdFactionsInvite); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(FactionsEventHomeTeleport event) - { - payForCommand(event, UConf.get(event.getSender()).econCostHome, Factions.get().getOuterCmdFactions().cmdFactionsHome); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(FactionsEventMembershipChange event) - { - Double cost = null; - MCommand command = null; + Double cost = null; + String desc = null; if (event.getReason() == MembershipChangeReason.JOIN) { cost = UConf.get(event.getSender()).econCostJoin; - command = Factions.get().getOuterCmdFactions().cmdFactionsJoin; + desc = "join a faction"; } else if (event.getReason() == MembershipChangeReason.LEAVE) { cost = UConf.get(event.getSender()).econCostLeave; - command = Factions.get().getOuterCmdFactions().cmdFactionsLeave; + desc = "leave a faction"; } else if (event.getReason() == MembershipChangeReason.KICK) { cost = UConf.get(event.getSender()).econCostKick; - command = Factions.get().getOuterCmdFactions().cmdFactionsKick; + desc = "kick someone from a faction"; } else { return; } - payForCommand(event, cost, command); + payForAction(event, cost, desc); } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventRelationChange event) + { + Double cost = UConf.get(event.getSender()).econRelCost.get(event.getNewRelation()); + String desc = Factions.get().getOuterCmdFactions().cmdFactionsRelationNeutral.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventHomeChange event) + { + Double cost = UConf.get(event.getSender()).econCostSethome; + String desc = Factions.get().getOuterCmdFactions().cmdFactionsSethome.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventCreate event) + { + Double cost = UConf.get(event.getSender()).econCostCreate; + String desc = Factions.get().getOuterCmdFactions().cmdFactionsCreate.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventDescriptionChange event) + { + Double cost = UConf.get(event.getSender()).econCostDescription; + String desc = Factions.get().getOuterCmdFactions().cmdFactionsDescription.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventTagChange event) + { + Double cost = UConf.get(event.getSender()).econCostTag; + String desc = Factions.get().getOuterCmdFactions().cmdFactionsTag.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventTitleChange event) + { + Double cost = UConf.get(event.getSender()).econCostTitle; + String desc = Factions.get().getOuterCmdFactions().cmdFactionsTitle.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventOpenChange event) + { + Double cost = UConf.get(event.getSender()).econCostOpen; + String desc = Factions.get().getOuterCmdFactions().cmdFactionsOpen.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventInvitedChange event) + { + Double cost = event.isNewInvited() ? UConf.get(event.getSender()).econCostInvite : UConf.get(event.getSender()).econCostDeinvite; + String desc = Factions.get().getOuterCmdFactions().cmdFactionsInvite.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventHomeTeleport event) + { + Double cost = UConf.get(event.getSender()).econCostHome; + String desc = Factions.get().getOuterCmdFactions().cmdFactionsHome.getDesc(); + + payForAction(event, cost, desc); + } + + }