Beta6. Supports CB493

This commit is contained in:
Olof Larsson 2011-03-05 11:39:14 +01:00
parent afde3e188b
commit 429e86fd4b
5 changed files with 20 additions and 20 deletions

View File

@ -36,13 +36,13 @@ Note that you may optionally skip the slash and just write
Installing
----------
1. Download the latest release: [https://github.com/oloflarsson/Factions/tree/master/releases](https://github.com/oloflarsson/Factions/tree/master/releases)<br/>
1. Download the latest release: [https://github.com/oloflarsson/Factions/tree/master/releases](https://github.com/oloflarsson/Factions/tree/master/releases)<br>
1. Put Factions.jar in the plugins folder.
A default config file will be created on the first run.
License
----------
This project has a LGPL license just like the Bukkit project.
This project has a LGPL license just like the Bukkit project.<br>
This project uses [GSON](http://code.google.com/p/google-gson/) which has a [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0 ).

View File

@ -1,3 +1,3 @@
name: Factions
version: 1.0 beta5
version: 1.0 beta6
main: com.bukkit.mcteam.factions.Factions

Binary file not shown.

View File

@ -13,7 +13,7 @@ import com.bukkit.mcteam.util.AsciiCompass;
//import com.bukkit.mcteam.factions.util.*;
public class Board {
public transient Long id;
public transient String worldName;
protected Map<Coord, Integer> coordFactionIds;
public Board() {
@ -72,7 +72,7 @@ public class Board {
public static void cleanAll() {
for (Board board : getAll()) {
Log.debug("Cleaning board: "+board.id);
Log.debug("Cleaning board for world "+board.worldName);
board.clean();
}
}
@ -187,7 +187,7 @@ public class Board {
//----------------------------------------------//
public boolean save() {
return EM.boardSave(this.id);
return EM.boardSave(this.worldName);
}
public static Board get(World world) {

View File

@ -20,7 +20,7 @@ import com.bukkit.mcteam.gson.*;
public class EM {
protected static Map<String, Follower> followers = new HashMap<String, Follower>(); // Where String is a lowercase playername
protected static Map<Integer, Faction> factions = new HashMap<Integer, Faction>(); // Where Integer is a primary auto increment key
protected static Map<Long, Board> boards = new HashMap<Long, Board>(); // Where Long is the semi (sadly) unique world id.
protected static Map<String, Board> boards = new HashMap<String, Board>(); // Where Long is the semi (sadly) unique world id.
protected static int nextFactionId;
// hardcoded config
@ -139,8 +139,8 @@ public class EM {
name = name.substring(0, name.length() - ext.length());
try {
Board board = gson.fromJson(DiscUtil.read(jsonFile), Board.class);
board.id = Long.parseLong(name);
boards.put(board.id, board);
board.worldName = name;
boards.put(board.worldName, board);
Log.debug("loaded board "+name);
} catch (Exception e) {
e.printStackTrace();
@ -158,37 +158,37 @@ public class EM {
* A new Board will be created if the world did not have one
*/
public static Board boardGet(World world) {
if (boards.containsKey(world.getId())) {
return boards.get(world.getId());
if (boards.containsKey(world.getName())) {
return boards.get(world.getName());
}
return boardCreate(world);
}
public static boolean boardSave(long id) {
Object obj = boards.get(id);
public static boolean boardSave(String worldName) {
Object obj = boards.get(worldName);
if (obj == null) {
Log.warn("Could not save board "+id+" as it was not loaded");
Log.warn("Could not save board "+worldName+" as it was not loaded");
return false;
}
folderBoard.mkdirs();
File file = new File(folderBoard, id+ext);
File file = new File(folderBoard, worldName+ext);
try {
DiscUtil.write(file, gson.toJson(obj));
Log.debug("Saved the board "+id);
Log.debug("Saved the board "+worldName);
return true;
} catch (IOException e) {
e.printStackTrace();
Log.warn("Failed to save the board "+id);
Log.warn("Failed to save the board "+worldName);
return false;
}
}
protected static Board boardCreate(World world) {
Log.debug("Creating new board "+world.getId());
Log.debug("Creating new board for "+world.getName());
Board board = new Board();
board.id = world.getId();
boards.put(board.id, board);
board.worldName = world.getName();
boards.put(board.worldName, board);
board.save();
return board;
}