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

@ -62,7 +62,10 @@ permissions:
factions.rank: {description: manage/show ranks, default: false} factions.rank: {description: manage/show ranks, default: false}
factions.rank.show: {description: show rank, default: false} factions.rank.show: {description: show rank, default: false}
factions.rank.action: {description: change rank, default: false} factions.rank.action: {description: change rank, default: false}
factions.relation: {description: set relation wish to another faction, default: false} factions.relation: {description: manage faction relations, default: false}
factions.relation.list: {description: list all factions with certain relation, default: false}
factions.relation.set: {description: set relation wish to another faction, default: false}
factions.relation.wishes: {description: list the relation wishes, default: false}
factions.seechunk: {description: see the chunk you stand in, default: false} factions.seechunk: {description: see the chunk you stand in, default: false}
factions.seechunkold: {description: see the chunk you stand in, default: false} factions.seechunkold: {description: see the chunk you stand in, default: false}
factions.sethome: {description: set the faction home, default: false} factions.sethome: {description: set the faction home, default: false}
@ -143,6 +146,9 @@ permissions:
factions.powerboost: true factions.powerboost: true
factions.promote: true factions.promote: true
factions.relation: true factions.relation: true
factions.relation.list: true
factions.relation.set: true
factions.relation.wishes: true
factions.seechunk: true factions.seechunk: true
factions.seechunkold: true factions.seechunkold: true
factions.sethome: true factions.sethome: true
@ -245,6 +251,9 @@ permissions:
factions.rank.show: true factions.rank.show: true
factions.rank.action: true factions.rank.action: true
factions.relation: true factions.relation: true
factions.relation.list: true
factions.relation.set: true
factions.relation.wishes: true
factions.seechunk: true factions.seechunk: true
factions.seechunkold: true factions.seechunkold: true
factions.sethome: true factions.sethome: true

View File

@ -31,7 +31,6 @@ public class Const
public static final String SHOW_ID_FACTION_POWER = BASENAME_ + "power"; public static final String SHOW_ID_FACTION_POWER = BASENAME_ + "power";
public static final String SHOW_ID_FACTION_LANDVALUES = BASENAME_ + "landvalue"; public static final String SHOW_ID_FACTION_LANDVALUES = BASENAME_ + "landvalue";
public static final String SHOW_ID_FACTION_BANK = BASENAME_ + "bank"; public static final String SHOW_ID_FACTION_BANK = BASENAME_ + "bank";
public static final String SHOW_ID_FACTION_RELATIONS = BASENAME_ + "relations";
public static final String SHOW_ID_FACTION_FOLLOWERS = BASENAME_ + "followers"; public static final String SHOW_ID_FACTION_FOLLOWERS = BASENAME_ + "followers";
public static final int SHOW_PRIORITY_FACTION_ID = 1000; public static final int SHOW_PRIORITY_FACTION_ID = 1000;
@ -41,7 +40,6 @@ public class Const
public static final int SHOW_PRIORITY_FACTION_POWER = 5000; public static final int SHOW_PRIORITY_FACTION_POWER = 5000;
public static final int SHOW_PRIORITY_FACTION_LANDVALUES = 6000; public static final int SHOW_PRIORITY_FACTION_LANDVALUES = 6000;
public static final int SHOW_PRIORITY_FACTION_BANK = 7000; public static final int SHOW_PRIORITY_FACTION_BANK = 7000;
public static final int SHOW_PRIORITY_FACTION_RELATIONS = 8000;
public static final int SHOW_PRIORITY_FACTION_FOLLOWERS = 9000; public static final int SHOW_PRIORITY_FACTION_FOLLOWERS = 9000;
} }

View File

@ -63,6 +63,9 @@ public enum Perm
RANK_SHOW, RANK_SHOW,
RANK_ACTION, RANK_ACTION,
RELATION, RELATION,
RELATION_SET,
RELATION_LIST,
RELATION_WISHES,
SEECHUNK, SEECHUNK,
SEECHUNKOLD, SEECHUNKOLD,
SETHOME, SETHOME,
@ -115,4 +118,4 @@ public enum Perm
return has(permissible, false); return has(permissible, false);
} }
} }

View File

@ -52,10 +52,11 @@ public class CmdFactions extends FactionsCommand
public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim();
public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim(); public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim();
public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess(); public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess();
public CmdFactionsRelationAlly cmdFactionsRelationAlly = new CmdFactionsRelationAlly(); public CmdFactionsRelation cmdFactionsRelation = new CmdFactionsRelation();
public CmdFactionsRelationTruce cmdFactionsRelationTruce = new CmdFactionsRelationTruce(); public CmdFactionsRelationOld cmdFactionsRelationOldAlly = new CmdFactionsRelationOld("ally");
public CmdFactionsRelationNeutral cmdFactionsRelationNeutral = new CmdFactionsRelationNeutral(); public CmdFactionsRelationOld cmdFactionsRelationOldTruce = new CmdFactionsRelationOld("truce");
public CmdFactionsRelationEnemy cmdFactionsRelationEnemy = new CmdFactionsRelationEnemy(); public CmdFactionsRelationOld cmdFactionsRelationOldNeutral = new CmdFactionsRelationOld("neutral");
public CmdFactionsRelationOld cmdFactionsRelationOldEnemy = new CmdFactionsRelationOld("enemy");
public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm(); public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm();
public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag(); public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag();
public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck(); public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck();
@ -106,10 +107,11 @@ public class CmdFactions extends FactionsCommand
this.addChild(this.cmdFactionsClaim); this.addChild(this.cmdFactionsClaim);
this.addChild(this.cmdFactionsUnclaim); this.addChild(this.cmdFactionsUnclaim);
this.addChild(this.cmdFactionsAccess); this.addChild(this.cmdFactionsAccess);
this.addChild(this.cmdFactionsRelationAlly); this.addChild(this.cmdFactionsRelation);
this.addChild(this.cmdFactionsRelationTruce); this.addChild(this.cmdFactionsRelationOldAlly);
this.addChild(this.cmdFactionsRelationNeutral); this.addChild(this.cmdFactionsRelationOldTruce);
this.addChild(this.cmdFactionsRelationEnemy); this.addChild(this.cmdFactionsRelationOldNeutral);
this.addChild(this.cmdFactionsRelationOldEnemy);
this.addChild(this.cmdFactionsPerm); this.addChild(this.cmdFactionsPerm);
this.addChild(this.cmdFactionsFlag); this.addChild(this.cmdFactionsFlag);
this.addChild(this.cmdFactionsUnstuck); this.addChild(this.cmdFactionsUnstuck);

View File

@ -43,7 +43,6 @@ public class CmdFactionsFaction extends FactionsCommand
{ {
// Args // Args
final Faction faction = this.readArg(msenderFaction); final Faction faction = this.readArg(msenderFaction);
final CommandSender sender = this.sender; final CommandSender sender = this.sender;
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()

View File

@ -0,0 +1,37 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.req.ReqHasFaction;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
public class CmdFactionsRelation extends FactionsCommand
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
public CmdFactionsRelationSet cmdFactionsRelationSet = new CmdFactionsRelationSet();
public CmdFactionsRelationList cmdFactionsRelationList = new CmdFactionsRelationList();
public CmdFactionsRelationWishes cmdFactionsRelationWishes = new CmdFactionsRelationWishes();
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsRelation()
{
// Children
this.addChild(this.cmdFactionsRelationSet);
this.addChild(this.cmdFactionsRelationList);
this.addChild(this.cmdFactionsRelationWishes);
// Aliases
this.addAliases("relation");
// Requirements
this.addRequirements(RequirementHasPerm.get(Perm.RELATION.node));
this.addRequirements(ReqHasFaction.get());
}
}

View File

@ -1,20 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Rel;
public class CmdFactionsRelationAlly extends CmdFactionsRelationAbstract
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsRelationAlly()
{
// Aliases
this.addAliases("ally");
// Misc
this.targetRelation = Rel.ALLY;
}
}

View File

@ -1,20 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Rel;
public class CmdFactionsRelationEnemy extends CmdFactionsRelationAbstract
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsRelationEnemy()
{
// Aliases
this.addAliases("enemy");
// Misc
this.targetRelation = Rel.ENEMY;
}
}

View File

@ -0,0 +1,110 @@
package com.massivecraft.factions.cmd;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Bukkit;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqHasFaction;
import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.factions.cmd.type.TypeRelation;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.command.Parameter;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.type.TypeNullable;
import com.massivecraft.massivecore.command.type.container.TypeSet;
import com.massivecraft.massivecore.pager.Pager;
import com.massivecraft.massivecore.pager.Stringifier;
import com.massivecraft.massivecore.util.Txt;
public class CmdFactionsRelationList extends FactionsCommand
{
// -------------------------------------------- //
// COSTANTS
// -------------------------------------------- //
public static final Set<Rel> RELEVANT_RELATIONS = new MassiveSet<Rel>(Rel.ENEMY, Rel.TRUCE, Rel.ALLY);
public static final String SEPERATOR = Txt.parse("<silver>: ");
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsRelationList()
{
// Aliases
this.addAliases("list");
// Parameter
this.addParameter(Parameter.getPage());
this.addParameter(TypeFaction.get(), "faction", "you");
this.addParameter(TypeNullable.get(TypeSet.get(TypeRelation.get()), "all"), "relation|all", "all");
// Requirements
this.addRequirements(RequirementHasPerm.get(Perm.RELATION_LIST.node));
this.addRequirements(ReqHasFaction.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
// Args
int page = this.readArg();
final Faction faction = this.readArg(msenderFaction);
final Set<Rel> rel = this.readArg();
final Set<Rel> relations = rel == null ? RELEVANT_RELATIONS : rel;
// Pager Create
final Pager<String> pager = new Pager<String>(this, "", page, new Stringifier<String>()
{
@Override
public String toString(String item, int index)
{
return item;
}
});
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
{
@Override
public void run()
{
// Prepare Items
List<String> relNames = new MassiveList<>();
for (Entry<Rel, List<String>> entry : FactionColl.get().getRelationNames(faction, relations).entrySet())
{
Rel relation = entry.getKey();
String coloredName = relation.getColor().toString() + relation.getName();
for (String name : entry.getValue())
{
relNames.add(coloredName + SEPERATOR + name);
}
}
// Pager Title
pager.setTitle(Txt.parse("<white>%s's <green>Relations <a>(%d)", faction.getName(), relNames.size()));
// Pager Items
pager.setItems(relNames);
// Pager Message
pager.message();
}
});
}
}

View File

@ -1,20 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Rel;
public class CmdFactionsRelationNeutral extends CmdFactionsRelationAbstract
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsRelationNeutral()
{
// Aliases
this.addAliases("neutral");
// Misc
this.targetRelation = Rel.NEUTRAL;
}
}

View File

@ -0,0 +1,45 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.massivecore.command.Visibility;
import com.massivecraft.massivecore.util.MUtil;
public class CmdFactionsRelationOld extends FactionsCommand
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
public final String relName;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsRelationOld(String rel)
{
// Fields
this.relName = rel.toLowerCase();
// Aliases
this.addAliases(relName);
// Parameters
this.addParameter(TypeFaction.get(), "faction");
// Visibility
this.setVisibility(Visibility.INVISIBLE);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet.execute(sender, MUtil.list(this.relName, this.argAt(0)));
}
}

View File

@ -1,34 +1,40 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.massivecore.command.MassiveCommand;
import org.bukkit.ChatColor;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqHasFaction; import com.massivecraft.factions.cmd.req.ReqHasFaction;
import com.massivecraft.factions.cmd.type.TypeFaction; import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.factions.cmd.type.TypeRelation;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.event.EventFactionsRelationChange; import com.massivecraft.factions.event.EventFactionsRelationChange;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.util.Txt;
public abstract class CmdFactionsRelationAbstract extends FactionsCommand public class CmdFactionsRelationSet extends FactionsCommand
{ {
public Rel targetRelation;
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public CmdFactionsRelationAbstract() public CmdFactionsRelationSet()
{ {
// Aliases // Aliases
this.addAliases("set");
// Parameter
this.addParameter(TypeFaction.get(), "faction"); this.addParameter(TypeFaction.get(), "faction");
this.addParameter(TypeRelation.get(), "relation");
// Requirements // Requirements
this.addRequirements(RequirementHasPerm.get(Perm.RELATION.node)); this.addRequirements(RequirementHasPerm.get(Perm.RELATION_SET.node));
this.addRequirements(ReqHasFaction.get()); this.addRequirements(ReqHasFaction.get());
} }
@ -41,30 +47,19 @@ public abstract class CmdFactionsRelationAbstract extends FactionsCommand
{ {
// Args // Args
Faction otherFaction = this.readArg(); Faction otherFaction = this.readArg();
Rel newRelation = this.readArg();
Rel newRelation = targetRelation;
/*if ( ! them.isNormal())
{
msg("<b>Nope! You can't.");
return;
}*/
// MPerm // MPerm
if ( ! MPerm.getPermRel().has(msender, msenderFaction, true)) return; if ( ! MPerm.getPermRel().has(msender, msenderFaction, true)) return;
// Verify // Verify
if (otherFaction == msenderFaction) if (otherFaction == msenderFaction)
{ {
msg("<b>Nope! You can't declare a relation to yourself :)"); throw new MassiveException().setMsg("<b>Nope! You can't declare a relation to yourself :)");
return;
} }
if (msenderFaction.getRelationWish(otherFaction) == newRelation) if (msenderFaction.getRelationWish(otherFaction) == newRelation)
{ {
msg("<b>You already have that relation wish set with %s.", otherFaction.getName()); throw new MassiveException().setMsg("<b>You already have that relation wish set with %s.", otherFaction.getName());
return;
} }
// Event // Event
@ -86,34 +81,29 @@ public abstract class CmdFactionsRelationAbstract extends FactionsCommand
// inform the other faction of your request // inform the other faction of your request
else else
{ {
MassiveCommand relationshipCommand = null; MassiveCommand command = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet;
if (newRelation.equals(Rel.NEUTRAL)) relationshipCommand = CmdFactions.get().cmdFactionsRelationNeutral; String colorOne = newRelation.getColor() + newRelation.getDescFactionOne();
else if (newRelation.equals(Rel.TRUCE)) relationshipCommand = CmdFactions.get().cmdFactionsRelationTruce;
else if (newRelation.equals(Rel.ALLY)) relationshipCommand = CmdFactions.get().cmdFactionsRelationAlly;
else if (newRelation.equals(Rel.ENEMY)) relationshipCommand = CmdFactions.get().cmdFactionsRelationEnemy;
String command = relationshipCommand.getCommandLine(msenderFaction.getName());
String tooltip = Txt.parse("<g>Click to <c>%s<i>.", command);
// Mson creation // Mson creation
Mson factionsRelationshipChange = mson( Mson factionsRelationshipChange = mson(
Mson.parse("%s<i> wishes to be %s. ", msenderFaction.describeTo(otherFaction, true), newRelation.getColor()+newRelation.getDescFactionOne()), Mson.parse("%s<i> wishes to be %s.", msenderFaction.describeTo(otherFaction, true), colorOne),
mson(tooltip).tooltipParse(tooltip).command(command) Mson.SPACE,
mson("[Accept]").color(ChatColor.AQUA).command(command, msenderFaction.getName(), newRelation.name())
); );
otherFaction.sendMessage(factionsRelationshipChange); otherFaction.sendMessage(factionsRelationshipChange);
msenderFaction.msg("%s<i> were informed that you wish to be %s<i>.", otherFaction.describeTo(msenderFaction, true), newRelation.getColor()+newRelation.getDescFactionOne()); msenderFaction.msg("%s<i> were informed that you wish to be %s<i>.", otherFaction.describeTo(msenderFaction, true), colorOne);
} }
// TODO: The ally case should work!! // TODO: The ally case should work!!
// * this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only // * this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only
if ( newRelation != Rel.TRUCE && otherFaction.getFlag(MFlag.getFlagPeaceful())) if (newRelation != Rel.TRUCE && otherFaction.getFlag(MFlag.getFlagPeaceful()))
{ {
otherFaction.msg("<i>This will have no effect while your faction is peaceful."); otherFaction.msg("<i>This will have no effect while your faction is peaceful.");
msenderFaction.msg("<i>This will have no effect while their faction is peaceful."); msenderFaction.msg("<i>This will have no effect while their faction is peaceful.");
} }
if ( newRelation != Rel.TRUCE && msenderFaction.getFlag(MFlag.getFlagPeaceful())) if (newRelation != Rel.TRUCE && msenderFaction.getFlag(MFlag.getFlagPeaceful()))
{ {
otherFaction.msg("<i>This will have no effect while their faction is peaceful."); otherFaction.msg("<i>This will have no effect while their faction is peaceful.");
msenderFaction.msg("<i>This will have no effect while your faction is peaceful."); msenderFaction.msg("<i>This will have no effect while your faction is peaceful.");

View File

@ -1,20 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Rel;
public class CmdFactionsRelationTruce extends CmdFactionsRelationAbstract
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsRelationTruce()
{
// Aliases
this.addAliases("truce");
// Misc
this.targetRelation = Rel.TRUCE;
}
}

View File

@ -0,0 +1,96 @@
package com.massivecraft.factions.cmd;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqHasFaction;
import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.MassiveMap;
import com.massivecraft.massivecore.command.Parameter;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.pager.Pager;
import com.massivecraft.massivecore.pager.Stringifier;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
public class CmdFactionsRelationWishes extends FactionsCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsRelationWishes()
{
// Aliases
this.addAliases("wishes");
// Parameter
this.addParameter(Parameter.getPage());
this.addParameter(TypeFaction.get(), "faction", "you");
// Requirements
this.addRequirements(RequirementHasPerm.get(Perm.RELATION_LIST.node));
this.addRequirements(ReqHasFaction.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
// Args
int page = this.readArg();
final Faction faction = this.readArg(msenderFaction);
// Pager Create
final Pager<Entry<Faction, Rel>> pager = new Pager<>(this, "", page, new Stringifier<Entry<Faction, Rel>>()
{
@Override
public String toString(Entry<Faction, Rel> item, int index)
{
Rel rel = item.getValue();
Faction fac = item.getKey();
return rel.getColor().toString() + rel.getName() + CmdFactionsRelationList.SEPERATOR + fac.describeTo(faction, true);
}
});
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
{
@Override
public void run()
{
Map<Faction, Rel> realWishes = new MassiveMap<>();
for (Entry<String, Rel> entry : faction.getRelationWishes().entrySet())
{
Rel rel = entry.getValue();
Faction fac = FactionColl.get().getFixed(entry.getKey());
// A wish is not a wish anymore if both factions have atleast equal "wishes"
if (fac.getRelationTo(faction).isAtLeast(rel)) continue;
realWishes.put(fac, rel);
}
// Pager Title
pager.setTitle(Txt.parse("<white>%s's <green>Relation wishes <a>(%d)", faction.getName(), realWishes.size()));
// Pager Items
pager.setItems(MUtil.entriesSortedByValues(realWishes));
// Pager Message
pager.message();
}
});
}
}

View File

@ -0,0 +1,25 @@
package com.massivecraft.factions.cmd.type;
import com.massivecraft.factions.Rel;
public class TypeRelation extends TypeRel
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TypeRelation i = new TypeRelation();
public static TypeRelation get() { return i; }
public TypeRelation() { this.setAll(Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.ENEMY); }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String getTypeName()
{
return "relation";
}
}

View File

@ -169,8 +169,7 @@ public class EngineEcon extends Engine
public void payForCommand(EventFactionsRelationChange event) public void payForCommand(EventFactionsRelationChange event)
{ {
Double cost = MConf.get().econRelCost.get(event.getNewRelation()); Double cost = MConf.get().econRelCost.get(event.getNewRelation());
String desc = CmdFactions.get().cmdFactionsRelationNeutral.getDesc(); String desc = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet.getDesc();
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }

View File

@ -138,7 +138,7 @@ public class EngineMain extends Engine
final Faction faction = event.getFaction(); final Faction faction = event.getFaction();
final boolean normal = faction.isNormal(); final boolean normal = faction.isNormal();
final Map<String, PriorityLines> idPriorityLiness = event.getIdPriorityLiness(); final Map<String, PriorityLines> idPriorityLiness = event.getIdPriorityLiness();
final boolean peaceful = faction.getFlag(MFlag.getFlagPeaceful()); String none = Txt.parse("<silver><italic>none");
// ID // ID
if (mplayer.isOverriding()) if (mplayer.isOverriding())
@ -223,37 +223,7 @@ public class EngineMain extends Engine
} }
} }
} }
// RELATIONS
List<String> relationLines = new ArrayList<String>();
String none = Txt.parse("<silver><italic>none");
String everyone = MConf.get().colorTruce.toString() + Txt.parse("<italic>*EVERYONE*");
Set<Rel> rels = EnumSet.of(Rel.TRUCE, Rel.ALLY, Rel.ENEMY);
Map<Rel, List<String>> relNames = faction.getRelationNames(mplayer, rels, true);
for (Entry<Rel, List<String>> entry : relNames.entrySet())
{
Rel rel = entry.getKey();
List<String> names = entry.getValue();
String header = Txt.parse("<a>Relation %s%s<a> (%d):", rel.getColor().toString(), Txt.getNicedEnum(rel), names.size());
relationLines.add(header);
if (rel == Rel.TRUCE && peaceful)
{
relationLines.add(everyone);
}
else
{
if (names.isEmpty())
{
relationLines.add(none);
}
else
{
relationLines.addAll(table(names, tableCols));
}
}
}
idPriorityLiness.put(Const.SHOW_ID_FACTION_RELATIONS, new PriorityLines(Const.SHOW_PRIORITY_FACTION_RELATIONS, relationLines));
// FOLLOWERS // FOLLOWERS
List<String> followerLines = new ArrayList<String>(); List<String> followerLines = new ArrayList<String>();

View File

@ -27,6 +27,7 @@ import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.collections.MassiveMapDef; import com.massivecraft.massivecore.collections.MassiveMapDef;
import com.massivecraft.massivecore.collections.MassiveTreeSetDef; import com.massivecraft.massivecore.collections.MassiveTreeSetDef;
import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive;
@ -575,32 +576,6 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
this.setRelationWish(faction.getId(), rel); 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 // FIELD: flagOverrides
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -2,12 +2,14 @@ package com.massivecraft.factions.entity;
import java.util.*; import java.util.*;
import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.Coll;
import com.massivecraft.massivecore.store.MStore; import com.massivecraft.massivecore.store.MStore;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import com.massivecraft.factions.Const; import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.MiscUtil;
@ -271,55 +273,44 @@ public class FactionColl extends Coll<Faction>
{ {
return this.getByName(str) != null; 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;
}
} }