From 677a9f1a86cb3383631de812729dfe846922df29 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 18 Jun 2013 09:07:05 +0200 Subject: [PATCH] MCore update, bug fix and some debug output that should be removed not just yet. --- src/com/massivecraft/factions/Factions.java | 6 +- .../factions/PlayerRoleComparator.java | 31 +++++++++- .../factions/cmd/CmdFactionsDisband.java | 7 +-- .../factions/cmd/CmdFactionsFaction.java | 2 +- .../factions/cmd/CmdFactionsJoin.java | 9 ++- .../massivecraft/factions/entity/Faction.java | 35 +++++++++++ .../factions/entity/FactionColl.java | 36 ----------- .../massivecraft/factions/entity/UPlayer.java | 61 ++++++++++++++++++- .../factions/entity/UPlayerColl.java | 39 ------------ 9 files changed, 137 insertions(+), 89 deletions(-) diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index d52b0b11..c5510fe6 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -82,7 +82,7 @@ public class Factions extends MPlugin public void setPowerMixin(PowerMixin powerMixin) { this.powerMixin = powerMixin; } // Gson without preprocessors - public final Gson gsonWithoutPreprocessors = this.getGsonBuilderWithotPreprocessors().create(); + public final Gson gsonWithoutPreprocessors = this.getGsonBuilderWithoutPreprocessors().create(); // -------------------------------------------- // // OVERRIDE @@ -163,7 +163,7 @@ public class Factions extends MPlugin postEnable(); } - public GsonBuilder getGsonBuilderWithotPreprocessors() + public GsonBuilder getGsonBuilderWithoutPreprocessors() { return super.getGsonBuilder() .registerTypeAdapter(TerritoryAccess.class, TerritoryAccessAdapter.get()) @@ -178,7 +178,7 @@ public class Factions extends MPlugin @Override public GsonBuilder getGsonBuilder() { - return this.getGsonBuilderWithotPreprocessors() + return this.getGsonBuilderWithoutPreprocessors() .registerTypeAdapter(Faction.class, FactionPreprocessAdapter.get()) ; } diff --git a/src/com/massivecraft/factions/PlayerRoleComparator.java b/src/com/massivecraft/factions/PlayerRoleComparator.java index fe3da2ef..f6122e8c 100644 --- a/src/com/massivecraft/factions/PlayerRoleComparator.java +++ b/src/com/massivecraft/factions/PlayerRoleComparator.java @@ -29,7 +29,36 @@ public class PlayerRoleComparator implements Comparator if (ret != 0) return ret; // Rank - return o2.getRole().getValue() - o1.getRole().getValue(); + // TODO: This error output is temporary. I need a way to detect what is going wrong. + Rel r1 = null; + Rel r2 = null; + try + { + r1 = o1.getRole(); + } + catch (Exception e) + { + System.out.println("Could not get role for o1: " + o1.getId()); + System.out.println("universe o1: " + o1.getUniverse()); + System.out.println("attached o1: " + o1.attached()); + System.out.println("Now dumping the data o1: " + Factions.get().gson.toJson(o1)); + e.printStackTrace(); + } + + try + { + r2 = o2.getRole(); + } + catch (Exception e) + { + System.out.println("Could not get role for o2: " + o2.getId()); + System.out.println("universe o2: " + o2.getUniverse()); + System.out.println("attached o2: " + o2.attached()); + System.out.println("Now dumping the data o2: " + Factions.get().gson.toJson(o2)); + e.printStackTrace(); + } + + return r2.getValue() - r1.getValue(); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java index fd812172..8c93ec19 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java @@ -15,6 +15,7 @@ import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.mcore.cmd.req.ReqHasPerm; +import com.massivecraft.mcore.util.Txt; public class CmdFactionsDisband extends FCommand { @@ -75,10 +76,8 @@ public class CmdFactionsDisband extends FCommand if (MConf.get().logFactionDisband) { - Factions.get().log("The faction "+faction.getName()+" ("+faction.getId()+") was disbanded by "+(senderIsConsole ? "console command" : usender.getName())+"."); - } - - + Factions.get().log(Txt.parse("The faction %s (%s) was disbanded by %s.", faction.getName(), faction.getId(), usender.getDisplayName())); + } faction.detach(); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java b/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java index 3c274acc..cf578c87 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java @@ -142,7 +142,7 @@ public class CmdFactionsFaction extends FCommand for (UPlayer follower : followers) { - if (follower.isOnline() && Mixin.isVisible(sender, follower.getId())) + if (follower.isOnline() && Mixin.canSee(sender, follower.getId())) { followerNamesOnline.add(follower.getNameAndTitle(usender)); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java index 71066219..baec10aa 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java @@ -12,6 +12,7 @@ import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.event.FactionsEventMembershipChange; import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason; import com.massivecraft.mcore.cmd.req.ReqHasPerm; +import com.massivecraft.mcore.util.Txt; public class CmdFactionsJoin extends FCommand { @@ -103,9 +104,13 @@ public class CmdFactionsJoin extends FCommand if (MConf.get().logFactionJoin) { if (samePlayer) - Factions.get().log("%s joined the faction %s.", uplayer.getName(), faction.getName()); + { + Factions.get().log(Txt.parse("%s joined the faction %s.", uplayer.getName(), faction.getName())); + } else - Factions.get().log("%s moved the player %s into the faction %s.", usender.getName(), uplayer.getName(), faction.getName()); + { + Factions.get().log(Txt.parse("%s moved the player %s into the faction %s.", usender.getName(), uplayer.getName(), faction.getName())); + } } } } diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index f8231081..38a21387 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -18,10 +18,12 @@ import com.massivecraft.factions.Rel; import com.massivecraft.factions.RelationParticipator; import com.massivecraft.factions.util.*; import com.massivecraft.mcore.mixin.Mixin; +import com.massivecraft.mcore.money.Money; import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.store.Entity; import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.SenderUtil; +import com.massivecraft.mcore.util.Txt; public class Faction extends Entity implements EconomyParticipator @@ -56,6 +58,20 @@ public class Faction extends Entity implements EconomyParticipator return this; } + @Override + public void preDetach(String id) + { + Money.set(this, 0); + + String universe = this.getUniverse(); + + // Clean the board + BoardColls.get().getForUniverse(universe).clean(); + + // Clean the uplayers + UPlayerColls.get().getForUniverse(universe).clean(); + } + // -------------------------------------------- // // FIELDS: RAW // -------------------------------------------- // @@ -844,8 +860,27 @@ public class Faction extends Entity implements EconomyParticipator } } + // TODO: Even though this check method removeds the invalid entries it's not a true solution. + // TODO: Find the bug causing non-attached UPlayers to be present in the index. + private void checkUPlayerIndex() + { + Iterator iter = this.uplayers.iterator(); + while (iter.hasNext()) + { + UPlayer uplayer = iter.next(); + if (!uplayer.attached()) + { + String msg = Txt.parse("WARN: Faction %s aka %s had unattached uplayer in index:", this.getName(), this.getId()); + Factions.get().log(msg); + Factions.get().log(Factions.get().gson.toJson(uplayer)); + iter.remove(); + } + } + } + public List getUPlayers() { + this.checkUPlayerIndex(); return new ArrayList(this.uplayers); } diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index 048544b8..56c4ebcc 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -4,7 +4,6 @@ import java.util.*; 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.Txt; @@ -40,23 +39,6 @@ public class FactionColl extends Coll this.createSpecialFactions(); } - // TODO: I hope this one is not crucial anymore. - // If it turns out to be I will just have to recreate the feature in the proper place. - /* - @Override - public Faction get(String id) - { - if ( ! this.exists(id)) - { - Factions.get().log(Level.WARNING, "Non existing factionId "+id+" requested! Issuing cleaning!"); - BoardColl.get().clean(); - FPlayerColl.get().clean(); - } - - return super.get(id); - } - */ - @Override public Faction get(Object oid) { @@ -74,24 +56,6 @@ public class FactionColl extends Coll return ret; } - @Override - public Faction detachId(Object oid) - { - Faction faction = this.get(oid); - Money.set(faction, 0); - String universe = faction.getUniverse(); - - Faction ret = super.detachId(oid); - - // Clean the board - BoardColls.get().getForUniverse(universe).clean(); - - // Clean the uplayers - UPlayerColls.get().getForUniverse(universe).clean(); - - return ret; - } - // -------------------------------------------- // // INDEX // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index bf3c1ec1..e785f80e 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -64,6 +64,32 @@ public class UPlayer extends SenderEntity implements EconomyParticipato return true; } + @Override + public void postAttach(String id) + { + // If inited ... + if (!Factions.get().isDatabaseInitialized()) return; + + // ... update the index. + Faction faction = this.getFaction(); + faction.uplayers.add(this); + + Factions.get().log(Txt.parse("postAttach added %s aka %s to %s aka %s.", id, Mixin.getDisplayName(id), faction.getId(), faction.getName())); + } + + @Override + public void preDetach(String id) + { + // If inited ... + if (!Factions.get().isDatabaseInitialized()) return; + + // ... update the index. + Faction faction = this.getFaction(); + faction.uplayers.remove(this); + + Factions.get().log(Txt.parse("preDetach removed %s aka %s to %s aka %s.", id, Mixin.getDisplayName(id), faction.getId(), faction.getName())); + } + // -------------------------------------------- // // FIELDS: RAW // -------------------------------------------- // @@ -219,6 +245,23 @@ public class UPlayer extends SenderEntity implements EconomyParticipato if (oldFaction != null) oldFaction.uplayers.remove(this); if (faction != null) faction.uplayers.add(this); + String oldFactionIdDesc = "NULL"; + String oldFactionNameDesc = "NULL"; + if (oldFaction != null) + { + oldFactionIdDesc = oldFaction.getId(); + oldFactionNameDesc = oldFaction.getName(); + } + String factionIdDesc = "NULL"; + String factionNameDesc = "NULL"; + if (faction != null) + { + factionIdDesc = faction.getId(); + factionNameDesc = faction.getName(); + } + + Factions.get().log(Txt.parse("setFactionId moved %s aka %s from %s aka %s to %s aka %s.", this.getId(), Mixin.getDisplayName(this.getId()), oldFactionIdDesc, oldFactionNameDesc, factionIdDesc, factionNameDesc)); + // Mark as changed this.changed(); } @@ -370,8 +413,20 @@ public class UPlayer extends SenderEntity implements EconomyParticipato public double getLimitedPower(double power) { - power = Math.max(power, this.getPowerMin()); - power = Math.min(power, this.getPowerMax()); + try + { + power = Math.max(power, this.getPowerMin()); + power = Math.min(power, this.getPowerMax()); + } + catch (Exception e) + { + System.out.println("Could not limit power for this: " + this.getId()); + System.out.println("universe this: " + this.getUniverse()); + System.out.println("attached this: " + this.attached()); + System.out.println("Now dumping the data this: " + Factions.get().gson.toJson(this)); + e.printStackTrace(); + } + return power; } @@ -606,11 +661,11 @@ public class UPlayer extends SenderEntity implements EconomyParticipato uplayer.msg("%s was disbanded.", myFaction.describeTo(uplayer, true)); } - myFaction.detach(); if (MConf.get().logFactionDisband) { Factions.get().log("The faction "+myFaction.getName()+" ("+myFaction.getId()+") was disbanded due to the last player ("+this.getName()+") leaving."); } + myFaction.detach(); } } diff --git a/src/com/massivecraft/factions/entity/UPlayerColl.java b/src/com/massivecraft/factions/entity/UPlayerColl.java index 6a94c29c..4682f057 100644 --- a/src/com/massivecraft/factions/entity/UPlayerColl.java +++ b/src/com/massivecraft/factions/entity/UPlayerColl.java @@ -20,45 +20,6 @@ public class UPlayerColl extends SenderColl super(name, UPlayer.class, MStore.getDb(ConfServer.dburi), Factions.get()); } - // -------------------------------------------- // - // OVERRIDE: COLL - // -------------------------------------------- // - - @Override - protected synchronized String attach(UPlayer entity, Object oid, boolean noteChange) - { - String ret = super.attach(entity, oid, noteChange); - - // If inited ... - if (!this.inited()) return ret; - if (!Factions.get().isDatabaseInitialized()) return ret; - - // ... update the index. - Faction faction = entity.getFaction(); - faction.uplayers.add(entity); - - return ret; - } - - @Override - public UPlayer detachId(Object oid) - { - UPlayer ret = this.get(oid); - if (ret == null) return null; - - // If inited ... - if (this.inited()) - { - // ... update the index. - Faction faction = ret.getFaction(); - faction.uplayers.remove(ret); - } - - super.detachId(oid); - - return ret; - } - // -------------------------------------------- // // EXTRAS // -------------------------------------------- //