5h- Rework relation commands.

This commit is contained in:
ulumulu1510
2016-02-25 09:48:02 +01:00
committed by Olof Larsson
parent 1f5e591ce6
commit 47332f96d5
19 changed files with 406 additions and 237 deletions

View File

@@ -27,6 +27,7 @@ import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.collections.MassiveMapDef;
import com.massivecraft.massivecore.collections.MassiveTreeSetDef;
import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive;
@@ -575,32 +576,6 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
this.setRelationWish(faction.getId(), rel);
}
public Map<Rel, List<String>> getRelationNames(RelationParticipator rp, Set<Rel> rels, boolean skipPeaceful)
{
// Create Ret
Map<Rel, List<String>> ret = new LinkedHashMap<Rel, List<String>>();
for (Rel rel : rels)
{
ret.put(rel, new ArrayList<String>());
}
for (Faction faction : FactionColl.get().getAll())
{
if (skipPeaceful && faction.getFlag(MFlag.getFlagPeaceful())) continue;
Rel rel = faction.getRelationTo(this);
List<String> names = ret.get(rel);
if (names == null) continue;
String name = faction.getName(rp);
names.add(name);
}
// Return Ret
return ret;
}
// -------------------------------------------- //
// FIELD: flagOverrides
// -------------------------------------------- //

View File

@@ -2,12 +2,14 @@ package com.massivecraft.factions.entity;
import java.util.*;
import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.store.Coll;
import com.massivecraft.massivecore.store.MStore;
import com.massivecraft.massivecore.util.Txt;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.util.MiscUtil;
@@ -271,55 +273,44 @@ public class FactionColl extends Coll<Faction>
{
return this.getByName(str) != null;
}
// -------------------------------------------- //
// OLD MIGRATION COMMENT
// -------------------------------------------- //
/*
@Override
public void init()
{
super.init();
this.migrate();
}
// This method is for the 1.8.X --> 2.0.0 migration
public void migrate()
{
// Create file objects
File oldFile = new File(Factions.get().getDataFolder(), "factions.json");
File newFile = new File(Factions.get().getDataFolder(), "factions.json.migrated");
// Already migrated?
if ( ! oldFile.exists()) return;
// Faction ids /delete
// For simplicity we just drop the old special factions.
// They will be replaced with new autogenerated ones per universe.
Set<String> factionIdsToDelete = MUtil.set("0", "-1", "-2");
// Read the file content through GSON.
Type type = new TypeToken<Map<String, Faction>>(){}.getType();
Map<String, Faction> id2faction = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type);
// The Coll
FactionColl coll = this.getForUniverse(MassiveCore.DEFAULT);
// Set the data
for (Entry<String, Faction> entry : id2faction.entrySet())
{
String factionId = entry.getKey();
if (factionIdsToDelete.contains(factionId)) continue;
Faction faction = entry.getValue();
coll.attach(faction, factionId);
}
// Mark as migrated
oldFile.renameTo(newFile);
}
*/
// -------------------------------------------- //
// PREDICATE LOGIC
// -------------------------------------------- //
public Map<Rel, List<String>> getRelationNames(Faction faction, Set<Rel> rels)
{
// Create
Map<Rel, List<String>> ret = new LinkedHashMap<Rel, List<String>>();
boolean peaceful = faction.getFlag(MFlag.getFlagPeaceful());
for (Rel rel : rels)
{
ret.put(rel, new ArrayList<String>());
}
// Fill
for (Faction fac : FactionColl.get().getAll())
{
if (fac.getFlag(MFlag.getFlagPeaceful())) continue;
Rel rel = fac.getRelationTo(faction);
List<String> names = ret.get(rel);
if (names == null) continue;
String name = fac.describeTo(faction, true);
names.add(name);
}
// Replace TRUCE if peasceful
if ( ! peaceful) return ret;
List<String> names = ret.get(Rel.TRUCE);
if (names == null) return ret;
ret.put(Rel.TRUCE, Collections.singletonList(MConf.get().colorTruce.toString() + Txt.parse("<italic>*EVERYONE*")));
// Return
return ret;
}
}