Unifying, simplifying and messing around with land claiming and the related costs.

This commit is contained in:
Olof Larsson 2013-04-24 11:16:37 +02:00
parent 8ac19453b6
commit 05da06594a
17 changed files with 312 additions and 291 deletions

View File

@ -9,6 +9,7 @@ import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.entity.UConf;
import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.UPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.event.FactionsEventChunkChangeType;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
@ -35,6 +36,8 @@ public class CmdFactionsShow extends FCommand
Faction faction = this.arg(0, ARFaction.get(myFaction), myFaction); Faction faction = this.arg(0, ARFaction.get(myFaction), myFaction);
if (faction == null) return; if (faction == null) return;
UConf uconf = UConf.get(faction);
Collection<UPlayer> leaders = faction.getUPlayersWhereRole(Rel.LEADER); Collection<UPlayer> leaders = faction.getUPlayersWhereRole(Rel.LEADER);
Collection<UPlayer> officers = faction.getUPlayersWhereRole(Rel.OFFICER); Collection<UPlayer> officers = faction.getUPlayersWhereRole(Rel.OFFICER);
Collection<UPlayer> normals = faction.getUPlayersWhereRole(Rel.MEMBER); Collection<UPlayer> normals = faction.getUPlayersWhereRole(Rel.MEMBER);
@ -64,14 +67,26 @@ public class CmdFactionsShow extends FCommand
// show the land value // show the land value
if (Econ.isEnabled(faction)) if (Econ.isEnabled(faction))
{ {
double value = Econ.calculateTotalLandValue(faction.getLandCount()); long landCount = faction.getLandCount();
double refund = value * UConf.get(faction).econClaimRefundMultiplier; for (FactionsEventChunkChangeType type : FactionsEventChunkChangeType.values())
if (value > 0)
{ {
String stringValue = Money.format(faction, value); Double money = uconf.econChunkCost.get(type);
String stringRefund = (refund > 0.0) ? (" ("+Money.format(faction, refund)+" depreciated)") : ""; if (money == null) money = 0D;
msg("<a>Total land value: <i>" + stringValue + stringRefund); money *= landCount;
String word = null;
if (money > 0)
{
word = "cost";
}
else
{
word = "reward";
money *= -1;
}
msg("<a>Total land %s %s: <i>%s", type.toString().toLowerCase(), word, Money.format(faction, money));
} }
// Show bank contents // Show bank contents

View File

@ -2,10 +2,9 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.BoardColls;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColls;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.event.FactionsEventChunkChange;
import com.massivecraft.factions.event.FactionsEventLandUnclaim;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
@ -30,30 +29,21 @@ public class CmdFactionsUnclaim extends FCommand
PS chunk = PS.valueOf(me).getChunk(true); PS chunk = PS.valueOf(me).getChunk(true);
Faction otherFaction = BoardColls.get().getFactionAt(chunk); Faction otherFaction = BoardColls.get().getFactionAt(chunk);
Faction newFaction = FactionColls.get().get(me).getNone();
// FPerm // FPerm
// TODO: Recode so that pillage is possible
if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return; if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return;
// Event // Event
FactionsEventLandUnclaim event = new FactionsEventLandUnclaim(sender, otherFaction, chunk); FactionsEventChunkChange event = new FactionsEventChunkChange(sender, chunk, newFaction);
event.run(); event.run();
if (event.isCancelled()) return; if (event.isCancelled()) return;
//String moneyBack = "<i>"; // Apply
if (Econ.isEnabled(myFaction)) BoardColls.get().setFactionAt(chunk, newFaction);
{
double refund = Econ.calculateClaimRefund(myFaction);
if (UConf.get(myFaction).bankEnabled && UConf.get(myFaction).bankFactionPaysLandCosts) // Inform
{
if ( ! Econ.modifyMoney(myFaction, refund, "unclaim this land")) return;
}
else
{
if ( ! Econ.modifyMoney(fme, refund, "unclaim this land")) return;
}
}
BoardColls.get().removeAt(chunk);
myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true)); myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true));
if (MConf.get().logLandUnclaims) if (MConf.get().logLandUnclaims)

View File

@ -1,15 +1,19 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import java.util.Set;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.BoardColls; 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.MConf;
import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.event.FactionsEventChunkChange;
import com.massivecraft.factions.event.FactionsEventLandUnclaimAll;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.ps.PS;
public class CmdFactionsUnclaimall extends FCommand public class CmdFactionsUnclaimall extends FCommand
{ {
@ -24,32 +28,36 @@ public class CmdFactionsUnclaimall extends FCommand
@Override @Override
public void perform() public void perform()
{ {
// TODO: Put this as a listener and not in here! // Args
if (Econ.isEnabled(myFaction)) Faction faction = myFaction;
{
double refund = Econ.calculateTotalLandRefund(myFaction.getLandCount());
if (UConf.get(myFaction).bankEnabled && UConf.get(myFaction).bankFactionPaysLandCosts) Faction newFaction = FactionColls.get().get(faction).getNone();
// Apply
BoardColl boardColl = BoardColls.get().get(faction);
Set<PS> chunks = boardColl.getChunks(faction);
int countTotal = chunks.size();
int countSuccess = 0;
int countFail = 0;
for (PS chunk : chunks)
{ {
if ( ! Econ.modifyMoney(myFaction, refund, "unclaim all faction land")) return; FactionsEventChunkChange event = new FactionsEventChunkChange(sender, chunk, newFaction);
event.run();
if (event.isCancelled())
{
countFail++;
} }
else 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 // Inform
myFaction.msg("%s<i> unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true)); myFaction.msg("%s<i> unclaimed <h>5 <i> of your <h>200 <i>faction land. You now have <h>23 <i>land left.", fme.describeTo(myFaction, true), countSuccess, countTotal, countFail);
// Log
if (MConf.get().logLandUnclaims) if (MConf.get().logLandUnclaims)
{ {
Factions.get().log(fme.getName()+" unclaimed everything for the faction: "+myFaction.getTag()); Factions.get().log(fme.getName()+" unclaimed everything for the faction: "+myFaction.getTag());

View File

@ -4,8 +4,10 @@ import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListMap;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -177,6 +179,29 @@ public class Board extends Entity<Board> implements BoardInterface
} }
} }
// CHUNKS
@Override
public Set<PS> getChunks(Faction faction)
{
return this.getChunks(faction.getId());
}
public Set<PS> getChunks(String factionId)
{
Set<PS> ret = new HashSet<PS>();
for (Entry<PS, TerritoryAccess> 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 // COUNT
@Override @Override
@ -188,9 +213,11 @@ public class Board extends Entity<Board> implements BoardInterface
public int getCount(String factionId) public int getCount(String factionId)
{ {
int ret = 0; 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; return ret;
} }

View File

@ -1,6 +1,8 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
@ -107,6 +109,19 @@ public class BoardColl extends Coll<Board> implements BoardInterface
} }
} }
// CHUNKS
@Override
public Set<PS> getChunks(Faction faction)
{
Set<PS> ret = new HashSet<PS>();
for (Board board : this.getAll())
{
ret.addAll(board.getChunks(faction));
}
return ret;
}
// COUNT // COUNT
@Override @Override

View File

@ -3,7 +3,9 @@ package com.massivecraft.factions.entity;
import java.io.File; import java.io.File;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -194,8 +196,19 @@ public class BoardColls extends Colls<BoardColl, Board> implements BoardInterfac
} }
} }
// COUNT // CHUNKS
@Override
public Set<PS> getChunks(Faction faction)
{
Set<PS> ret = new HashSet<PS>();
for (BoardColl coll : this.getColls())
{
ret.addAll(coll.getChunks(faction));
}
return ret;
}
// COUNT
@Override @Override
public int getCount(Faction faction) public int getCount(Faction faction)
{ {

View File

@ -1,6 +1,7 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set;
import com.massivecraft.factions.RelationParticipator; import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.TerritoryAccess;
@ -21,6 +22,9 @@ public interface BoardInterface
public void removeAll(Faction faction); public void removeAll(Faction faction);
public void clean(); public void clean();
// CHUNKS
public Set<PS> getChunks(Faction faction);
// COUNT // COUNT
public int getCount(Faction faction); public int getCount(Faction faction);

View File

@ -9,6 +9,7 @@ import com.massivecraft.factions.Const;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.event.FactionsEventChunkChangeType;
import com.massivecraft.mcore.store.Entity; import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.MUtil;
@ -138,11 +139,12 @@ public class UConf extends Entity<UConf>
public String econUniverseAccount = ""; public String econUniverseAccount = "";
public double econCostClaimWilderness = 30.0; public Map<FactionsEventChunkChangeType, Double> econChunkCost = MUtil.map(
public double econCostClaimFromFactionBonus = 30.0; FactionsEventChunkChangeType.BUY, 30.0,
public double econClaimAdditionalMultiplier = 0.5; FactionsEventChunkChangeType.SELL, -20.0,
public double econClaimRefundMultiplier = 0.7; FactionsEventChunkChangeType.CONQUER, -10.0,
public double econClaimUnconnectedFee = 0.0; FactionsEventChunkChangeType.PILLAGE, -10.0
);
public double econCostCreate = 100.0; public double econCostCreate = 100.0;
public double econCostSethome = 0.0; public double econCostSethome = 0.0;

View File

@ -14,7 +14,7 @@ import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Lang; import com.massivecraft.factions.Lang;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.RelationParticipator; 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;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason; import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
@ -641,26 +641,14 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
{ {
psChunk = psChunk.getChunk(true); psChunk = psChunk.getChunk(true);
Faction currentFaction = BoardColls.get().getFactionAt(psChunk); Faction currentFaction = BoardColls.get().getFactionAt(psChunk);
int ownedLand = forFaction.getLandCount();
if ( ! this.canClaimForFactionAtLocation(forFaction, psChunk, notifyFailure)) return false; if ( ! this.canClaimForFactionAtLocation(forFaction, psChunk, notifyFailure)) return false;
// Event // Event
FactionsEventLandClaim event = new FactionsEventLandClaim(sender, forFaction, psChunk); FactionsEventChunkChange event = new FactionsEventChunkChange(sender, psChunk, forFaction);
event.run(); event.run();
if (event.isCancelled()) return false; 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. // TODO: The LWC integration should listen to Monitor for the claim event.
if (LWCFeatures.getEnabled() && forFaction.isNormal() && UConf.get(forFaction).lwcRemoveOnCapture) if (LWCFeatures.getEnabled() && forFaction.isNormal() && UConf.get(forFaction).lwcRemoveOnCapture)
{ {

View File

@ -13,7 +13,7 @@ public abstract class FactionsEventAbstractSender extends MCoreEvent
private final CommandSender sender; private final CommandSender sender;
public CommandSender getSender() { return this.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 // CONSTRUCT

View File

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

View File

@ -0,0 +1,10 @@
package com.massivecraft.factions.event;
public enum FactionsEventChunkChangeType
{
BUY,
SELL,
CONQUER,
PILLAGE,
;
}

View File

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

View File

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

View File

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

View File

@ -2,12 +2,9 @@ package com.massivecraft.factions.integration;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.EconomyParticipator; import com.massivecraft.factions.EconomyParticipator;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.entity.UConf;
import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.UPlayer;
import com.massivecraft.factions.entity.Faction; 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;
}
} }

View File

@ -6,8 +6,12 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.entity.UConf;
import com.massivecraft.factions.entity.UPlayer;
import com.massivecraft.factions.event.FactionsEventAbstractSender; 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.FactionsEventCreate;
import com.massivecraft.factions.event.FactionsEventDescriptionChange; import com.massivecraft.factions.event.FactionsEventDescriptionChange;
import com.massivecraft.factions.event.FactionsEventHomeChange; 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.FactionsEventTagChange;
import com.massivecraft.factions.event.FactionsEventTitleChange; import com.massivecraft.factions.event.FactionsEventTitleChange;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.cmd.MCommand;
public class FactionsListenerEcon implements Listener 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 there is a sender ...
if (event.getSender() == null) return; UPlayer usender = event.getUSender();
if (usender == null) return;
// ... and the sender can't afford ... // ... and there is a cost ...
if (Econ.payForAction(cost, event.getFSender(), command.getDesc())) return; if (cost == null) return;
if (cost == 0) return;
// ... that the sender can't afford ...
if (Econ.payForAction(cost, usender, desc)) return;
// ... then cancel. // ... then cancel.
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = 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); Faction newFaction = event.getNewFaction();
UConf uconf = UConf.get(newFaction);
FactionsEventChunkChangeType type = event.getType();
Double cost = uconf.econChunkCost.get(type);
String desc = type.toString().toLowerCase() + " this land";
payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(FactionsEventCreate event) public void payForAction(FactionsEventMembershipChange 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;
payForCommand(event, cost, Factions.get().getOuterCmdFactions().cmdFactionsRelationNeutral);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(FactionsEventOpenChange 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; Double cost = null;
MCommand command = null; String desc = null;
if (event.getReason() == MembershipChangeReason.JOIN) if (event.getReason() == MembershipChangeReason.JOIN)
{ {
cost = UConf.get(event.getSender()).econCostJoin; cost = UConf.get(event.getSender()).econCostJoin;
command = Factions.get().getOuterCmdFactions().cmdFactionsJoin; desc = "join a faction";
} }
else if (event.getReason() == MembershipChangeReason.LEAVE) else if (event.getReason() == MembershipChangeReason.LEAVE)
{ {
cost = UConf.get(event.getSender()).econCostLeave; cost = UConf.get(event.getSender()).econCostLeave;
command = Factions.get().getOuterCmdFactions().cmdFactionsLeave; desc = "leave a faction";
} }
else if (event.getReason() == MembershipChangeReason.KICK) else if (event.getReason() == MembershipChangeReason.KICK)
{ {
cost = UConf.get(event.getSender()).econCostKick; cost = UConf.get(event.getSender()).econCostKick;
command = Factions.get().getOuterCmdFactions().cmdFactionsKick; desc = "kick someone from a faction";
} }
else else
{ {
return; 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);
}
} }