Testing the new money interface
This commit is contained in:
parent
d1cebc351e
commit
ae61ef4c37
31
src/com/massivecraft/factions/ExtractorFactionAccountId.java
Normal file
31
src/com/massivecraft/factions/ExtractorFactionAccountId.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import com.massivecraft.mcore.util.extractor.Extractor;
|
||||
|
||||
public class ExtractorFactionAccountId implements Extractor
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ExtractorFactionAccountId i = new ExtractorFactionAccountId();
|
||||
public static ExtractorFactionAccountId get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: EXTRACTOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Object extract(Object o)
|
||||
{
|
||||
if (o instanceof Faction)
|
||||
{
|
||||
String factionId = ((Faction)o).getId();
|
||||
if (factionId == null) return null;
|
||||
return "faction-"+factionId;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -10,7 +10,6 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.iface.EconomyParticipator;
|
||||
import com.massivecraft.factions.iface.RelationParticipator;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.integration.SpoutFeatures;
|
||||
import com.massivecraft.factions.util.*;
|
||||
import com.massivecraft.mcore.mixin.Mixin;
|
||||
@ -130,12 +129,6 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
{
|
||||
String accountId = "faction-"+this.getId();
|
||||
|
||||
// We need to override the default money given to players.
|
||||
if ( ! Econ.hasAccount(accountId))
|
||||
{
|
||||
Econ.setBalance(accountId, 0);
|
||||
}
|
||||
|
||||
return accountId;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.mcore.money.Money;
|
||||
import com.massivecraft.mcore.store.Coll;
|
||||
import com.massivecraft.mcore.store.MStore;
|
||||
import com.massivecraft.mcore.util.DiscUtil;
|
||||
@ -69,18 +70,31 @@ public class FactionColl extends Coll<Faction>
|
||||
oldFile.renameTo(newFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized String attach(Faction faction, Object oid, boolean noteChange)
|
||||
{
|
||||
String ret = super.attach(faction, oid, noteChange);
|
||||
|
||||
// Factions start with 0 money.
|
||||
if (!Money.exists(faction, faction))
|
||||
{
|
||||
Money.set(faction, faction, 0);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Faction detachId(Object oid)
|
||||
{
|
||||
String accountId = this.get(oid).getAccountId();
|
||||
Faction faction = this.get(oid);
|
||||
if (faction != null)
|
||||
{
|
||||
Money.set(faction, faction, 0);
|
||||
}
|
||||
|
||||
Faction ret = super.detachId(oid);
|
||||
|
||||
if (Econ.isEnabled())
|
||||
{
|
||||
Econ.setBalance(accountId, 0);
|
||||
}
|
||||
|
||||
// Clean the board
|
||||
// TODO: Use events for this instead?
|
||||
BoardColl.get().clean();
|
||||
|
@ -34,6 +34,7 @@ import com.massivecraft.factions.task.AutoLeaveTask;
|
||||
import com.massivecraft.factions.task.EconLandRewardTask;
|
||||
|
||||
import com.massivecraft.mcore.MPlugin;
|
||||
import com.massivecraft.mcore.util.MUtil;
|
||||
import com.massivecraft.mcore.xlib.gson.GsonBuilder;
|
||||
|
||||
|
||||
@ -69,6 +70,10 @@ public class Factions extends MPlugin
|
||||
|
||||
// Load Server Config
|
||||
ConfServer.get().load();
|
||||
|
||||
// Register Faction accountId Extractor
|
||||
// TODO: Perhaps this should be placed in the econ integration somewhere?
|
||||
MUtil.registerExtractor(String.class, "accountId", ExtractorFactionAccountId.get());
|
||||
|
||||
// Initialize Collections
|
||||
FPlayerColl.get().init();
|
||||
|
Loading…
Reference in New Issue
Block a user