Fewer runtime errors...
This commit is contained in:
		| @@ -126,7 +126,7 @@ public class Board { | |||||||
| 	 */ | 	 */ | ||||||
| 	public static ArrayList<String> getMap(Faction faction, FLocation flocation, double inDegrees) { | 	public static ArrayList<String> getMap(Faction faction, FLocation flocation, double inDegrees) { | ||||||
| 		ArrayList<String> ret = new ArrayList<String>(); | 		ArrayList<String> ret = new ArrayList<String>(); | ||||||
| 		ret.add(TextUtil.titleize("("+flocation+") "+getFactionAt(flocation).getTag(faction))); | 		ret.add(TextUtil.titleize("("+flocation.getCoordString()+") "+getFactionAt(flocation).getTag(faction))); | ||||||
| 		 | 		 | ||||||
| 		int halfWidth = Conf.mapWidth / 2; | 		int halfWidth = Conf.mapWidth / 2; | ||||||
| 		int halfHeight = Conf.mapHeight / 2; | 		int halfHeight = Conf.mapHeight / 2; | ||||||
|   | |||||||
| @@ -50,14 +50,6 @@ public class FPlayer { | |||||||
| 	// Construct | 	// Construct | ||||||
| 	// -------------------------------------------- // | 	// -------------------------------------------- // | ||||||
| 	 | 	 | ||||||
| 	public FPlayer(Player player) { |  | ||||||
| 		this.playerName = player.getName().toLowerCase(); |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	public FPlayer(String playerName) { |  | ||||||
| 		this.playerName = playerName.toLowerCase(); |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	// GSON need this noarg constructor. | 	// GSON need this noarg constructor. | ||||||
| 	public FPlayer() { | 	public FPlayer() { | ||||||
| 		this.resetFactionData(); | 		this.resetFactionData(); | ||||||
| @@ -103,6 +95,10 @@ public class FPlayer { | |||||||
| 		return Faction.get(factionId); | 		return Faction.get(factionId); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|  | 	private int getFactionId() { | ||||||
|  | 		return factionId; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
| 	public void setFaction(Faction faction) { | 	public void setFaction(Faction faction) { | ||||||
| 		this.factionId = faction.getId(); | 		this.factionId = faction.getId(); | ||||||
| 	} | 	} | ||||||
| @@ -153,7 +149,7 @@ public class FPlayer { | |||||||
| 	// Base: | 	// Base: | ||||||
| 	 | 	 | ||||||
| 	public String getTitle() { | 	public String getTitle() { | ||||||
| 		return title; | 		return this.title; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	public void setTitle(String title) { | 	public void setTitle(String title) { | ||||||
| @@ -380,7 +376,9 @@ public class FPlayer { | |||||||
| 			return instances.get(playerName); | 			return instances.get(playerName); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		FPlayer vplayer = new FPlayer(playerName); | 		FPlayer vplayer = new FPlayer(); | ||||||
|  | 		vplayer.playerName = playerName; | ||||||
|  | 		 | ||||||
| 		instances.put(playerName, vplayer); | 		instances.put(playerName, vplayer); | ||||||
| 		return vplayer; | 		return vplayer; | ||||||
| 	} | 	} | ||||||
| @@ -471,4 +469,13 @@ public class FPlayer { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|  | 	public static void clean() { | ||||||
|  | 		for (FPlayer fplayer : instances.values()) { | ||||||
|  | 			if ( ! Faction.exists(fplayer.getFactionId())) { | ||||||
|  | 				Factions.log("Reset faction data (invalid faction) for player "+fplayer.getName()); | ||||||
|  | 				fplayer.resetFactionData(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	}	 | ||||||
|  | 	 | ||||||
| } | } | ||||||
| @@ -368,8 +368,9 @@ public class Faction { | |||||||
| 	 | 	 | ||||||
| 	public static Faction get(Integer factionId) { | 	public static Faction get(Integer factionId) { | ||||||
| 		if ( ! instances.containsKey(factionId)) { | 		if ( ! instances.containsKey(factionId)) { | ||||||
| 			Factions.log(Level.WARNING, "Non existing factionId "+factionId+" requested! Issuing board cleaning!"); | 			Factions.log(Level.WARNING, "Non existing factionId "+factionId+" requested! Issuing cleaning!"); | ||||||
| 			Board.clean(); | 			Board.clean(); | ||||||
|  | 			FPlayer.clean(); | ||||||
| 		} | 		} | ||||||
| 		return instances.get(factionId); | 		return instances.get(factionId); | ||||||
| 	} | 	} | ||||||
| @@ -393,24 +394,18 @@ public class Faction { | |||||||
| 		return faction; | 		return faction; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public static boolean delete(Integer id) { | 	public static void delete(Integer id) { | ||||||
| 		// NOTE that this does not do any security checks. |  | ||||||
| 		// Follower might get orphaned foreign id's |  | ||||||
| 		 |  | ||||||
| 		// purge from all boards |  | ||||||
| 		// Board.purgeFactionFromAllBoards(id); |  | ||||||
| 		Board.clean(); |  | ||||||
| 		 |  | ||||||
| 		// Remove the file |  | ||||||
| 		//File file = new File(folderFaction, id+ext); |  | ||||||
| 		//file.delete(); |  | ||||||
| 		 |  | ||||||
| 		// Remove the faction | 		// Remove the faction | ||||||
| 		instances.remove(id); | 		instances.remove(id); | ||||||
| 		 | 		 | ||||||
| 		// TODO REMOVE ALL MEMBERS! | 		// Clean the board | ||||||
|  | 		Board.clean(); | ||||||
| 		 | 		 | ||||||
| 		// TODO SAVE files | 		// Clean the fplayers | ||||||
| 		return true; // TODO | 		FPlayer.clean(); | ||||||
|  | 		 | ||||||
|  | 		// SAVE files | ||||||
|  | 		Board.save(); | ||||||
|  | 		FPlayer.save(); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -45,7 +45,7 @@ public class FCommandDeinvite extends FBaseCommand { | |||||||
| 		 | 		 | ||||||
| 		if (you.getFaction() == myFaction) { | 		if (you.getFaction() == myFaction) { | ||||||
| 			sendMessage(you.getName()+" is already a member of "+myFaction.getTag()); | 			sendMessage(you.getName()+" is already a member of "+myFaction.getTag()); | ||||||
| 			sendMessage(new FCommandKick().getUseageTemplate()); | 			sendMessage("You might want to: " + new FCommandKick().getUseageTemplate()); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
|   | |||||||
| @@ -45,8 +45,7 @@ public class FCommandInvite extends FBaseCommand { | |||||||
| 		 | 		 | ||||||
| 		if (you.getFaction() == myFaction) { | 		if (you.getFaction() == myFaction) { | ||||||
| 			sendMessage(you.getName()+" is already a member of "+myFaction.getTag()); | 			sendMessage(you.getName()+" is already a member of "+myFaction.getTag()); | ||||||
| 			sendMessage("You might want to :"); | 			sendMessage("You might want to: " + new FCommandKick().getUseageTemplate()); | ||||||
| 			sendMessage(new FCommandKick().getUseageTemplate()); |  | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
|   | |||||||
| @@ -40,8 +40,7 @@ public class FCommandKick extends FBaseCommand { | |||||||
| 		 | 		 | ||||||
| 		if (me == you) { | 		if (me == you) { | ||||||
| 			sendMessage("You cannot kick yourself."); | 			sendMessage("You cannot kick yourself."); | ||||||
| 			sendMessage("You might want to:"); | 			sendMessage("You might want to: " + new FCommandLeave().getUseageTemplate()); | ||||||
| 			sendMessage(new FCommandLeave().getUseageTemplate()); |  | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
|   | |||||||
| @@ -29,6 +29,7 @@ public class FCommandList extends FBaseCommand { | |||||||
| 	// TODO put the 0 faction at the highest position | 	// TODO put the 0 faction at the highest position | ||||||
| 	public void perform() { | 	public void perform() { | ||||||
| 		ArrayList<Faction> FactionList = new ArrayList<Faction>(Faction.getAll()); | 		ArrayList<Faction> FactionList = new ArrayList<Faction>(Faction.getAll()); | ||||||
|  | 		FactionList.remove(Faction.get(0)); | ||||||
|  |  | ||||||
| 		int page = 1; | 		int page = 1; | ||||||
| 		if (parameters.size() > 0) { | 		if (parameters.size() > 0) { | ||||||
| @@ -44,11 +45,7 @@ public class FCommandList extends FBaseCommand { | |||||||
| 		Collections.sort(FactionList, new Comparator<Faction>(){ | 		Collections.sort(FactionList, new Comparator<Faction>(){ | ||||||
| 			@Override | 			@Override | ||||||
| 			public int compare(Faction f1, Faction f2) { | 			public int compare(Faction f1, Faction f2) { | ||||||
| 				if (f1.getId() == 0) | 				if (f1.getFPlayers().size() < f2.getFPlayers().size()) | ||||||
| 					return 1; |  | ||||||
| 				else if (f2.getId() == 0) |  | ||||||
| 					return -1; |  | ||||||
| 				else if (f1.getFPlayers().size() < f2.getFPlayers().size()) |  | ||||||
| 					return 1; | 					return 1; | ||||||
| 				else if (f1.getFPlayers().size() > f2.getFPlayers().size()) | 				else if (f1.getFPlayers().size() > f2.getFPlayers().size()) | ||||||
| 					return -1; | 					return -1; | ||||||
| @@ -68,6 +65,8 @@ public class FCommandList extends FBaseCommand { | |||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		FactionList.add(0, Faction.get(0)); | ||||||
|  | 		 | ||||||
| 		int maxPage = (int)Math.floor((double)FactionList.size() / 9D); | 		int maxPage = (int)Math.floor((double)FactionList.size() / 9D); | ||||||
| 		if (page < 0 || page > maxPage) { | 		if (page < 0 || page > maxPage) { | ||||||
| 			sendMessage("The faction list is only " + (maxPage+1) + " page(s) long"); | 			sendMessage("The faction list is only " + (maxPage+1) + " page(s) long"); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 
				 Olof Larsson
					Olof Larsson