MCore update, bug fix and some debug output that should be removed not just yet.
This commit is contained in:
@ -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<Faction> implements EconomyParticipator
|
||||
@ -56,6 +58,20 @@ public class Faction extends Entity<Faction> 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<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()
|
||||
{
|
||||
this.checkUPlayerIndex();
|
||||
return new ArrayList<UPlayer>(this.uplayers);
|
||||
}
|
||||
|
||||
|
@ -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<Faction>
|
||||
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<Faction>
|
||||
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
|
||||
// -------------------------------------------- //
|
||||
|
@ -64,6 +64,32 @@ public class UPlayer extends SenderEntity<UPlayer> 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("<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
|
||||
// -------------------------------------------- //
|
||||
@ -219,6 +245,23 @@ public class UPlayer extends SenderEntity<UPlayer> 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("<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
|
||||
this.changed();
|
||||
}
|
||||
@ -370,8 +413,20 @@ public class UPlayer extends SenderEntity<UPlayer> 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<UPlayer> implements EconomyParticipato
|
||||
uplayer.msg("<i>%s<i> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,45 +20,6 @@ public class UPlayerColl extends SenderColl<UPlayer>
|
||||
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
|
||||
// -------------------------------------------- //
|
||||
|
Reference in New Issue
Block a user