diff --git a/src/com/massivecraft/factions/Board.java b/src/com/massivecraft/factions/Board.java index 10f232ae..af2f61d3 100644 --- a/src/com/massivecraft/factions/Board.java +++ b/src/com/massivecraft/factions/Board.java @@ -1,6 +1,7 @@ package com.massivecraft.factions; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -50,8 +51,24 @@ public class Board extends Entity implements BoardInterface // FIELDS // -------------------------------------------- // - // TODO: Make TerritoryAccess immutable! - private ConcurrentSkipListMap map = new ConcurrentSkipListMap(); + // TODO: Make TerritoryAccess immutable. + + private ConcurrentSkipListMap map; + public Map getMap() { return Collections.unmodifiableMap(this.map); } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public Board() + { + this.map = new ConcurrentSkipListMap(); + } + + public Board(Map map) + { + this.map = new ConcurrentSkipListMap(map); + } // -------------------------------------------- // // OVERRIDE: BOARD diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 329ac037..30ad53ca 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -4,6 +4,7 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; +import com.massivecraft.factions.adapters.BoardAdapter; import com.massivecraft.factions.adapters.FFlagAdapter; import com.massivecraft.factions.adapters.FPermAdapter; import com.massivecraft.factions.adapters.LazyLocationAdapter; @@ -135,6 +136,7 @@ public class Factions extends MPlugin .excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE) .registerTypeAdapter(LazyLocation.class, new LazyLocationAdapter()) .registerTypeAdapter(TerritoryAccess.class, TerritoryAccessAdapter.get()) + .registerTypeAdapter(Board.class, BoardAdapter.get()) .registerTypeAdapter(Rel.class, new RelAdapter()) .registerTypeAdapter(FPerm.class, new FPermAdapter()) .registerTypeAdapter(FFlag.class, new FFlagAdapter()); diff --git a/src/com/massivecraft/factions/adapters/BoardAdapter.java b/src/com/massivecraft/factions/adapters/BoardAdapter.java new file mode 100644 index 00000000..eeaf86db --- /dev/null +++ b/src/com/massivecraft/factions/adapters/BoardAdapter.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.adapters; + +import java.lang.reflect.Type; +import java.util.Map; + +import com.massivecraft.mcore.ps.PS; +import com.massivecraft.mcore.xlib.gson.JsonDeserializationContext; +import com.massivecraft.mcore.xlib.gson.JsonDeserializer; +import com.massivecraft.mcore.xlib.gson.JsonElement; +import com.massivecraft.mcore.xlib.gson.JsonParseException; +import com.massivecraft.mcore.xlib.gson.JsonSerializationContext; +import com.massivecraft.mcore.xlib.gson.JsonSerializer; +import com.massivecraft.mcore.xlib.gson.reflect.TypeToken; + +import com.massivecraft.factions.Board; +import com.massivecraft.factions.TerritoryAccess; + +public class BoardAdapter implements JsonDeserializer, JsonSerializer +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static BoardAdapter i = new BoardAdapter(); + public static BoardAdapter get() { return i; } + + //----------------------------------------------// + // OVERRIDE + //----------------------------------------------// + + private static final Type mapType = new TypeToken>(){}.getType(); + + @SuppressWarnings("unchecked") + @Override + public Board deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException + { + return new Board((Map) context.deserialize(json, mapType)); + } + + @Override + public JsonElement serialize(Board src, Type typeOfSrc, JsonSerializationContext context) + { + return context.serialize(src.getMap(), mapType); + } + +} \ No newline at end of file