MCore update, bug fix and some debug output that should be removed not just yet.

This commit is contained in:
Olof Larsson 2013-06-18 09:07:05 +02:00
parent 66991fba02
commit 677a9f1a86
9 changed files with 137 additions and 89 deletions

View File

@ -82,7 +82,7 @@ public class Factions extends MPlugin
public void setPowerMixin(PowerMixin powerMixin) { this.powerMixin = powerMixin; } public void setPowerMixin(PowerMixin powerMixin) { this.powerMixin = powerMixin; }
// Gson without preprocessors // Gson without preprocessors
public final Gson gsonWithoutPreprocessors = this.getGsonBuilderWithotPreprocessors().create(); public final Gson gsonWithoutPreprocessors = this.getGsonBuilderWithoutPreprocessors().create();
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
@ -163,7 +163,7 @@ public class Factions extends MPlugin
postEnable(); postEnable();
} }
public GsonBuilder getGsonBuilderWithotPreprocessors() public GsonBuilder getGsonBuilderWithoutPreprocessors()
{ {
return super.getGsonBuilder() return super.getGsonBuilder()
.registerTypeAdapter(TerritoryAccess.class, TerritoryAccessAdapter.get()) .registerTypeAdapter(TerritoryAccess.class, TerritoryAccessAdapter.get())
@ -178,7 +178,7 @@ public class Factions extends MPlugin
@Override @Override
public GsonBuilder getGsonBuilder() public GsonBuilder getGsonBuilder()
{ {
return this.getGsonBuilderWithotPreprocessors() return this.getGsonBuilderWithoutPreprocessors()
.registerTypeAdapter(Faction.class, FactionPreprocessAdapter.get()) .registerTypeAdapter(Faction.class, FactionPreprocessAdapter.get())
; ;
} }

View File

@ -29,7 +29,36 @@ public class PlayerRoleComparator implements Comparator<UPlayer>
if (ret != 0) return ret; if (ret != 0) return ret;
// Rank // 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();
} }
} }

View File

@ -15,6 +15,7 @@ import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt;
public class CmdFactionsDisband extends FCommand public class CmdFactionsDisband extends FCommand
{ {
@ -75,11 +76,9 @@ public class CmdFactionsDisband extends FCommand
if (MConf.get().logFactionDisband) 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("<i>The faction <h>%s <i>(<h>%s<i>) was disbanded by <h>%s<i>.", faction.getName(), faction.getId(), usender.getDisplayName()));
} }
faction.detach(); faction.detach();
} }
} }

View File

@ -142,7 +142,7 @@ public class CmdFactionsFaction extends FCommand
for (UPlayer follower : followers) 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)); followerNamesOnline.add(follower.getNameAndTitle(usender));
} }

View File

@ -12,6 +12,7 @@ import com.massivecraft.factions.entity.UConf;
import com.massivecraft.factions.event.FactionsEventMembershipChange; import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason; import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt;
public class CmdFactionsJoin extends FCommand public class CmdFactionsJoin extends FCommand
{ {
@ -103,9 +104,13 @@ public class CmdFactionsJoin extends FCommand
if (MConf.get().logFactionJoin) if (MConf.get().logFactionJoin)
{ {
if (samePlayer) 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 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()));
}
} }
} }
} }

View File

@ -18,10 +18,12 @@ import com.massivecraft.factions.Rel;
import com.massivecraft.factions.RelationParticipator; import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.util.*; import com.massivecraft.factions.util.*;
import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.mixin.Mixin;
import com.massivecraft.mcore.money.Money;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.store.Entity; import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.SenderUtil; import com.massivecraft.mcore.util.SenderUtil;
import com.massivecraft.mcore.util.Txt;
public class Faction extends Entity<Faction> implements EconomyParticipator public class Faction extends Entity<Faction> implements EconomyParticipator
@ -56,6 +58,20 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
return this; 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 // FIELDS: RAW
// -------------------------------------------- // // -------------------------------------------- //
@ -844,8 +860,27 @@ public class Faction extends Entity<Faction> 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<UPlayer> iter = this.uplayers.iterator();
while (iter.hasNext())
{
UPlayer uplayer = iter.next();
if (!uplayer.attached())
{
String msg = Txt.parse("<rose>WARN: <i>Faction <h>%s <i>aka <h>%s <i>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<UPlayer> getUPlayers() public List<UPlayer> getUPlayers()
{ {
this.checkUPlayerIndex();
return new ArrayList<UPlayer>(this.uplayers); return new ArrayList<UPlayer>(this.uplayers);
} }

View File

@ -4,7 +4,6 @@ import java.util.*;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import com.massivecraft.mcore.money.Money;
import com.massivecraft.mcore.store.Coll; import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.MStore; import com.massivecraft.mcore.store.MStore;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -40,23 +39,6 @@ public class FactionColl extends Coll<Faction>
this.createSpecialFactions(); 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 @Override
public Faction get(Object oid) public Faction get(Object oid)
{ {
@ -74,24 +56,6 @@ public class FactionColl extends Coll<Faction>
return ret; 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 // INDEX
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -64,6 +64,32 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
return true; 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("<g>postAttach added <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", 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("<b>preDetach removed <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", id, Mixin.getDisplayName(id), faction.getId(), faction.getName()));
}
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS: RAW // FIELDS: RAW
// -------------------------------------------- // // -------------------------------------------- //
@ -219,6 +245,23 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
if (oldFaction != null) oldFaction.uplayers.remove(this); if (oldFaction != null) oldFaction.uplayers.remove(this);
if (faction != null) faction.uplayers.add(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("<i>setFactionId moved <h>%s <i>aka <h>%s <i>from <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", this.getId(), Mixin.getDisplayName(this.getId()), oldFactionIdDesc, oldFactionNameDesc, factionIdDesc, factionNameDesc));
// Mark as changed // Mark as changed
this.changed(); this.changed();
} }
@ -370,8 +413,20 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
public double getLimitedPower(double power) public double getLimitedPower(double power)
{ {
power = Math.max(power, this.getPowerMin()); try
power = Math.min(power, this.getPowerMax()); {
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; return power;
} }
@ -606,11 +661,11 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
uplayer.msg("<i>%s<i> was disbanded.", myFaction.describeTo(uplayer, true)); uplayer.msg("<i>%s<i> was disbanded.", myFaction.describeTo(uplayer, true));
} }
myFaction.detach();
if (MConf.get().logFactionDisband) if (MConf.get().logFactionDisband)
{ {
Factions.get().log("The faction "+myFaction.getName()+" ("+myFaction.getId()+") was disbanded due to the last player ("+this.getName()+") leaving."); Factions.get().log("The faction "+myFaction.getName()+" ("+myFaction.getId()+") was disbanded due to the last player ("+this.getName()+") leaving.");
} }
myFaction.detach();
} }
} }

View File

@ -20,45 +20,6 @@ public class UPlayerColl extends SenderColl<UPlayer>
super(name, UPlayer.class, MStore.getDb(ConfServer.dburi), Factions.get()); 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 // EXTRAS
// -------------------------------------------- // // -------------------------------------------- //