From 27d414ffc4ff184001fd0d8c284707c0f52835fd Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 22 Mar 2011 19:25:11 +0100 Subject: [PATCH] Fewer runtime errors... --- src/com/bukkit/mcteam/factions/Board.java | 2 +- src/com/bukkit/mcteam/factions/FPlayer.java | 27 ++++++++++++------- src/com/bukkit/mcteam/factions/Faction.java | 27 ++++++++----------- .../factions/commands/FCommandDeinvite.java | 2 +- .../factions/commands/FCommandInvite.java | 3 +-- .../factions/commands/FCommandKick.java | 3 +-- .../factions/commands/FCommandList.java | 9 +++---- test.jpage | 0 8 files changed, 36 insertions(+), 37 deletions(-) delete mode 100644 test.jpage diff --git a/src/com/bukkit/mcteam/factions/Board.java b/src/com/bukkit/mcteam/factions/Board.java index 015f96de..60478b10 100644 --- a/src/com/bukkit/mcteam/factions/Board.java +++ b/src/com/bukkit/mcteam/factions/Board.java @@ -126,7 +126,7 @@ public class Board { */ public static ArrayList getMap(Faction faction, FLocation flocation, double inDegrees) { ArrayList ret = new ArrayList(); - 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 halfHeight = Conf.mapHeight / 2; diff --git a/src/com/bukkit/mcteam/factions/FPlayer.java b/src/com/bukkit/mcteam/factions/FPlayer.java index ae3d500f..98efd557 100644 --- a/src/com/bukkit/mcteam/factions/FPlayer.java +++ b/src/com/bukkit/mcteam/factions/FPlayer.java @@ -50,14 +50,6 @@ public class FPlayer { // Construct // -------------------------------------------- // - public FPlayer(Player player) { - this.playerName = player.getName().toLowerCase(); - } - - public FPlayer(String playerName) { - this.playerName = playerName.toLowerCase(); - } - // GSON need this noarg constructor. public FPlayer() { this.resetFactionData(); @@ -103,6 +95,10 @@ public class FPlayer { return Faction.get(factionId); } + private int getFactionId() { + return factionId; + } + public void setFaction(Faction faction) { this.factionId = faction.getId(); } @@ -153,7 +149,7 @@ public class FPlayer { // Base: public String getTitle() { - return title; + return this.title; } public void setTitle(String title) { @@ -380,7 +376,9 @@ public class FPlayer { return instances.get(playerName); } - FPlayer vplayer = new FPlayer(playerName); + FPlayer vplayer = new FPlayer(); + vplayer.playerName = playerName; + instances.put(playerName, 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(); + } + } + } + } \ No newline at end of file diff --git a/src/com/bukkit/mcteam/factions/Faction.java b/src/com/bukkit/mcteam/factions/Faction.java index 8eb2e31a..baa53493 100644 --- a/src/com/bukkit/mcteam/factions/Faction.java +++ b/src/com/bukkit/mcteam/factions/Faction.java @@ -368,8 +368,9 @@ public class Faction { public static Faction get(Integer 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(); + FPlayer.clean(); } return instances.get(factionId); } @@ -393,24 +394,18 @@ public class Faction { return faction; } - public static boolean 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(); - + public static void delete(Integer id) { // Remove the faction instances.remove(id); - // TODO REMOVE ALL MEMBERS! + // Clean the board + Board.clean(); - // TODO SAVE files - return true; // TODO + // Clean the fplayers + FPlayer.clean(); + + // SAVE files + Board.save(); + FPlayer.save(); } } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java b/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java index f01c0211..4d72b128 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java @@ -45,7 +45,7 @@ public class FCommandDeinvite extends FBaseCommand { if (you.getFaction() == myFaction) { sendMessage(you.getName()+" is already a member of "+myFaction.getTag()); - sendMessage(new FCommandKick().getUseageTemplate()); + sendMessage("You might want to: " + new FCommandKick().getUseageTemplate()); return; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java b/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java index 0a694079..98e79e3f 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java @@ -45,8 +45,7 @@ public class FCommandInvite extends FBaseCommand { if (you.getFaction() == myFaction) { sendMessage(you.getName()+" is already a member of "+myFaction.getTag()); - sendMessage("You might want to :"); - sendMessage(new FCommandKick().getUseageTemplate()); + sendMessage("You might want to: " + new FCommandKick().getUseageTemplate()); return; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandKick.java b/src/com/bukkit/mcteam/factions/commands/FCommandKick.java index 20f78095..0b1c7efe 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandKick.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandKick.java @@ -40,8 +40,7 @@ public class FCommandKick extends FBaseCommand { if (me == you) { sendMessage("You cannot kick yourself."); - sendMessage("You might want to:"); - sendMessage(new FCommandLeave().getUseageTemplate()); + sendMessage("You might want to: " + new FCommandLeave().getUseageTemplate()); return; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandList.java b/src/com/bukkit/mcteam/factions/commands/FCommandList.java index 15b46d76..a5044af9 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandList.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandList.java @@ -29,6 +29,7 @@ public class FCommandList extends FBaseCommand { // TODO put the 0 faction at the highest position public void perform() { ArrayList FactionList = new ArrayList(Faction.getAll()); + FactionList.remove(Faction.get(0)); int page = 1; if (parameters.size() > 0) { @@ -44,11 +45,7 @@ public class FCommandList extends FBaseCommand { Collections.sort(FactionList, new Comparator(){ @Override public int compare(Faction f1, Faction f2) { - if (f1.getId() == 0) - return 1; - else if (f2.getId() == 0) - return -1; - else if (f1.getFPlayers().size() < f2.getFPlayers().size()) + if (f1.getFPlayers().size() < f2.getFPlayers().size()) return 1; else if (f1.getFPlayers().size() > f2.getFPlayers().size()) 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); if (page < 0 || page > maxPage) { sendMessage("The faction list is only " + (maxPage+1) + " page(s) long"); diff --git a/test.jpage b/test.jpage deleted file mode 100644 index e69de29b..00000000