From ae61ef4c37bc8c5f0a868b09636412a6fdf89685 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 19 Apr 2013 18:34:21 +0200 Subject: [PATCH] Testing the new money interface --- .../factions/ExtractorFactionAccountId.java | 31 +++++++++++++++++++ src/com/massivecraft/factions/Faction.java | 7 ----- .../massivecraft/factions/FactionColl.java | 26 ++++++++++++---- src/com/massivecraft/factions/Factions.java | 5 +++ 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 src/com/massivecraft/factions/ExtractorFactionAccountId.java diff --git a/src/com/massivecraft/factions/ExtractorFactionAccountId.java b/src/com/massivecraft/factions/ExtractorFactionAccountId.java new file mode 100644 index 00000000..14438a72 --- /dev/null +++ b/src/com/massivecraft/factions/ExtractorFactionAccountId.java @@ -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; + } + +} diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 07e1e4f9..4a477aac 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -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 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; } diff --git a/src/com/massivecraft/factions/FactionColl.java b/src/com/massivecraft/factions/FactionColl.java index b4dc90e5..07c2b65d 100644 --- a/src/com/massivecraft/factions/FactionColl.java +++ b/src/com/massivecraft/factions/FactionColl.java @@ -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 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(); diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index fa89e602..2ee49bf9 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -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();