From 47332f96d58038bd92ea79d82918211e68100d49 Mon Sep 17 00:00:00 2001 From: ulumulu1510 Date: Thu, 25 Feb 2016 09:48:02 +0100 Subject: [PATCH] 5h- Rework relation commands. --- plugin.yml | 11 +- src/com/massivecraft/factions/Const.java | 2 - src/com/massivecraft/factions/Perm.java | 5 +- .../factions/cmd/CmdFactions.java | 18 +-- .../factions/cmd/CmdFactionsFaction.java | 1 - .../factions/cmd/CmdFactionsRelation.java | 37 ++++++ .../factions/cmd/CmdFactionsRelationAlly.java | 20 ---- .../cmd/CmdFactionsRelationEnemy.java | 20 ---- .../factions/cmd/CmdFactionsRelationList.java | 110 ++++++++++++++++++ .../cmd/CmdFactionsRelationNeutral.java | 20 ---- .../factions/cmd/CmdFactionsRelationOld.java | 45 +++++++ ...tract.java => CmdFactionsRelationSet.java} | 60 ++++------ .../cmd/CmdFactionsRelationTruce.java | 20 ---- .../cmd/CmdFactionsRelationWishes.java | 96 +++++++++++++++ .../factions/cmd/type/TypeRelation.java | 25 ++++ .../factions/engine/EngineEcon.java | 3 +- .../factions/engine/EngineMain.java | 34 +----- .../massivecraft/factions/entity/Faction.java | 27 +---- .../factions/entity/FactionColl.java | 89 +++++++------- 19 files changed, 406 insertions(+), 237 deletions(-) create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsRelation.java delete mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsRelationAlly.java delete mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsRelationEnemy.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java delete mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsRelationNeutral.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsRelationOld.java rename src/com/massivecraft/factions/cmd/{CmdFactionsRelationAbstract.java => CmdFactionsRelationSet.java} (63%) delete mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsRelationTruce.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java create mode 100644 src/com/massivecraft/factions/cmd/type/TypeRelation.java diff --git a/plugin.yml b/plugin.yml index d909d6a7..508e6682 100644 --- a/plugin.yml +++ b/plugin.yml @@ -62,7 +62,10 @@ permissions: factions.rank: {description: manage/show ranks, default: false} factions.rank.show: {description: show 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.seechunkold: {description: see the chunk you stand in, default: false} factions.sethome: {description: set the faction home, default: false} @@ -143,6 +146,9 @@ permissions: factions.powerboost: true factions.promote: true factions.relation: true + factions.relation.list: true + factions.relation.set: true + factions.relation.wishes: true factions.seechunk: true factions.seechunkold: true factions.sethome: true @@ -245,6 +251,9 @@ permissions: factions.rank.show: true factions.rank.action: true factions.relation: true + factions.relation.list: true + factions.relation.set: true + factions.relation.wishes: true factions.seechunk: true factions.seechunkold: true factions.sethome: true diff --git a/src/com/massivecraft/factions/Const.java b/src/com/massivecraft/factions/Const.java index 628d3b60..a0d0d8a6 100644 --- a/src/com/massivecraft/factions/Const.java +++ b/src/com/massivecraft/factions/Const.java @@ -31,7 +31,6 @@ public class Const 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_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 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_LANDVALUES = 6000; 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; } diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java index c22f35f4..ff0d6a90 100644 --- a/src/com/massivecraft/factions/Perm.java +++ b/src/com/massivecraft/factions/Perm.java @@ -63,6 +63,9 @@ public enum Perm RANK_SHOW, RANK_ACTION, RELATION, + RELATION_SET, + RELATION_LIST, + RELATION_WISHES, SEECHUNK, SEECHUNKOLD, SETHOME, @@ -115,4 +118,4 @@ public enum Perm return has(permissible, false); } -} +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactions.java b/src/com/massivecraft/factions/cmd/CmdFactions.java index 99c6bd9f..3d33f1e9 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/com/massivecraft/factions/cmd/CmdFactions.java @@ -52,10 +52,11 @@ public class CmdFactions extends FactionsCommand public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim(); public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess(); - public CmdFactionsRelationAlly cmdFactionsRelationAlly = new CmdFactionsRelationAlly(); - public CmdFactionsRelationTruce cmdFactionsRelationTruce = new CmdFactionsRelationTruce(); - public CmdFactionsRelationNeutral cmdFactionsRelationNeutral = new CmdFactionsRelationNeutral(); - public CmdFactionsRelationEnemy cmdFactionsRelationEnemy = new CmdFactionsRelationEnemy(); + public CmdFactionsRelation cmdFactionsRelation = new CmdFactionsRelation(); + public CmdFactionsRelationOld cmdFactionsRelationOldAlly = new CmdFactionsRelationOld("ally"); + public CmdFactionsRelationOld cmdFactionsRelationOldTruce = new CmdFactionsRelationOld("truce"); + public CmdFactionsRelationOld cmdFactionsRelationOldNeutral = new CmdFactionsRelationOld("neutral"); + public CmdFactionsRelationOld cmdFactionsRelationOldEnemy = new CmdFactionsRelationOld("enemy"); public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm(); public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag(); public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck(); @@ -106,10 +107,11 @@ public class CmdFactions extends FactionsCommand this.addChild(this.cmdFactionsClaim); this.addChild(this.cmdFactionsUnclaim); this.addChild(this.cmdFactionsAccess); - this.addChild(this.cmdFactionsRelationAlly); - this.addChild(this.cmdFactionsRelationTruce); - this.addChild(this.cmdFactionsRelationNeutral); - this.addChild(this.cmdFactionsRelationEnemy); + this.addChild(this.cmdFactionsRelation); + this.addChild(this.cmdFactionsRelationOldAlly); + this.addChild(this.cmdFactionsRelationOldTruce); + this.addChild(this.cmdFactionsRelationOldNeutral); + this.addChild(this.cmdFactionsRelationOldEnemy); this.addChild(this.cmdFactionsPerm); this.addChild(this.cmdFactionsFlag); this.addChild(this.cmdFactionsUnstuck); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java b/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java index dd37cdce..e7ea1f6e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java @@ -43,7 +43,6 @@ public class CmdFactionsFaction extends FactionsCommand { // Args final Faction faction = this.readArg(msenderFaction); - final CommandSender sender = this.sender; Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelation.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelation.java new file mode 100644 index 00000000..c6053d9d --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelation.java @@ -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()); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAlly.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAlly.java deleted file mode 100644 index 0a813f87..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAlly.java +++ /dev/null @@ -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; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationEnemy.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationEnemy.java deleted file mode 100644 index e4ddf510..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationEnemy.java +++ /dev/null @@ -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; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java new file mode 100644 index 00000000..66fc043f --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java @@ -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 RELEVANT_RELATIONS = new MassiveSet(Rel.ENEMY, Rel.TRUCE, Rel.ALLY); + public static final String SEPERATOR = Txt.parse(": "); + + // -------------------------------------------- // + // 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 = this.readArg(); + final Set relations = rel == null ? RELEVANT_RELATIONS : rel; + + // Pager Create + final Pager pager = new Pager(this, "", page, new Stringifier() + { + @Override + public String toString(String item, int index) + { + return item; + } + }); + + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() + { + @Override + public void run() + { + // Prepare Items + List relNames = new MassiveList<>(); + for (Entry> 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("%s's Relations (%d)", faction.getName(), relNames.size())); + + // Pager Items + pager.setItems(relNames); + + // Pager Message + pager.message(); + } + }); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationNeutral.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationNeutral.java deleted file mode 100644 index aa918a04..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationNeutral.java +++ /dev/null @@ -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; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationOld.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationOld.java new file mode 100644 index 00000000..0d51a517 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationOld.java @@ -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))); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationSet.java similarity index 63% rename from src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java rename to src/com/massivecraft/factions/cmd/CmdFactionsRelationSet.java index 8a398516..f17a044a 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationSet.java @@ -1,34 +1,40 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.massivecore.command.MassiveCommand; + +import org.bukkit.ChatColor; + 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.MFlag; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.event.EventFactionsRelationChange; + import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.MassiveCommand; import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; 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 // -------------------------------------------- // - public CmdFactionsRelationAbstract() + public CmdFactionsRelationSet() { // Aliases + this.addAliases("set"); + + // Parameter this.addParameter(TypeFaction.get(), "faction"); + this.addParameter(TypeRelation.get(), "relation"); // Requirements - this.addRequirements(RequirementHasPerm.get(Perm.RELATION.node)); + this.addRequirements(RequirementHasPerm.get(Perm.RELATION_SET.node)); this.addRequirements(ReqHasFaction.get()); } @@ -41,30 +47,19 @@ public abstract class CmdFactionsRelationAbstract extends FactionsCommand { // Args Faction otherFaction = this.readArg(); - - Rel newRelation = targetRelation; - - /*if ( ! them.isNormal()) - { - msg("Nope! You can't."); - return; - }*/ + Rel newRelation = this.readArg(); // MPerm if ( ! MPerm.getPermRel().has(msender, msenderFaction, true)) return; // Verify - if (otherFaction == msenderFaction) { - msg("Nope! You can't declare a relation to yourself :)"); - return; + throw new MassiveException().setMsg("Nope! You can't declare a relation to yourself :)"); } - if (msenderFaction.getRelationWish(otherFaction) == newRelation) { - msg("You already have that relation wish set with %s.", otherFaction.getName()); - return; + throw new MassiveException().setMsg("You already have that relation wish set with %s.", otherFaction.getName()); } // Event @@ -86,34 +81,29 @@ public abstract class CmdFactionsRelationAbstract extends FactionsCommand // inform the other faction of your request else { - MassiveCommand relationshipCommand = null; - if (newRelation.equals(Rel.NEUTRAL)) relationshipCommand = CmdFactions.get().cmdFactionsRelationNeutral; - 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("Click to %s.", command); - + MassiveCommand command = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet; + String colorOne = newRelation.getColor() + newRelation.getDescFactionOne(); + // Mson creation Mson factionsRelationshipChange = mson( - Mson.parse("%s wishes to be %s. ", msenderFaction.describeTo(otherFaction, true), newRelation.getColor()+newRelation.getDescFactionOne()), - mson(tooltip).tooltipParse(tooltip).command(command) + Mson.parse("%s wishes to be %s.", msenderFaction.describeTo(otherFaction, true), colorOne), + Mson.SPACE, + mson("[Accept]").color(ChatColor.AQUA).command(command, msenderFaction.getName(), newRelation.name()) ); otherFaction.sendMessage(factionsRelationshipChange); - msenderFaction.msg("%s were informed that you wish to be %s.", otherFaction.describeTo(msenderFaction, true), newRelation.getColor()+newRelation.getDescFactionOne()); + msenderFaction.msg("%s were informed that you wish to be %s.", otherFaction.describeTo(msenderFaction, true), colorOne); } // TODO: The ally case should work!! // * 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("This will have no effect while your faction is peaceful."); msenderFaction.msg("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("This will have no effect while their faction is peaceful."); msenderFaction.msg("This will have no effect while your faction is peaceful."); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationTruce.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationTruce.java deleted file mode 100644 index 19aeef71..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationTruce.java +++ /dev/null @@ -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; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java new file mode 100644 index 00000000..ba7e3640 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java @@ -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> pager = new Pager<>(this, "", page, new Stringifier>() + { + @Override + public String toString(Entry 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 realWishes = new MassiveMap<>(); + + for (Entry 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("%s's Relation wishes (%d)", faction.getName(), realWishes.size())); + + // Pager Items + pager.setItems(MUtil.entriesSortedByValues(realWishes)); + + // Pager Message + pager.message(); + } + }); + } +} diff --git a/src/com/massivecraft/factions/cmd/type/TypeRelation.java b/src/com/massivecraft/factions/cmd/type/TypeRelation.java new file mode 100644 index 00000000..4f574566 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/type/TypeRelation.java @@ -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"; + } + +} diff --git a/src/com/massivecraft/factions/engine/EngineEcon.java b/src/com/massivecraft/factions/engine/EngineEcon.java index 73c8a39a..d5c4e049 100644 --- a/src/com/massivecraft/factions/engine/EngineEcon.java +++ b/src/com/massivecraft/factions/engine/EngineEcon.java @@ -169,8 +169,7 @@ public class EngineEcon extends Engine public void payForCommand(EventFactionsRelationChange event) { 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); } diff --git a/src/com/massivecraft/factions/engine/EngineMain.java b/src/com/massivecraft/factions/engine/EngineMain.java index 5c35f251..93245c79 100644 --- a/src/com/massivecraft/factions/engine/EngineMain.java +++ b/src/com/massivecraft/factions/engine/EngineMain.java @@ -138,7 +138,7 @@ public class EngineMain extends Engine final Faction faction = event.getFaction(); final boolean normal = faction.isNormal(); final Map idPriorityLiness = event.getIdPriorityLiness(); - final boolean peaceful = faction.getFlag(MFlag.getFlagPeaceful()); + String none = Txt.parse("none"); // ID if (mplayer.isOverriding()) @@ -223,37 +223,7 @@ public class EngineMain extends Engine } } } - - // RELATIONS - List relationLines = new ArrayList(); - String none = Txt.parse("none"); - String everyone = MConf.get().colorTruce.toString() + Txt.parse("*EVERYONE*"); - Set rels = EnumSet.of(Rel.TRUCE, Rel.ALLY, Rel.ENEMY); - Map> relNames = faction.getRelationNames(mplayer, rels, true); - for (Entry> entry : relNames.entrySet()) - { - Rel rel = entry.getKey(); - List names = entry.getValue(); - String header = Txt.parse("Relation %s%s (%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 List followerLines = new ArrayList(); diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 919843c2..4101bc66 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -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 implements EconomyParticipator, Nam this.setRelationWish(faction.getId(), rel); } - public Map> getRelationNames(RelationParticipator rp, Set rels, boolean skipPeaceful) - { - // Create Ret - Map> ret = new LinkedHashMap>(); - for (Rel rel : rels) - { - ret.put(rel, new ArrayList()); - } - - for (Faction faction : FactionColl.get().getAll()) - { - if (skipPeaceful && faction.getFlag(MFlag.getFlagPeaceful())) continue; - - Rel rel = faction.getRelationTo(this); - - List names = ret.get(rel); - if (names == null) continue; - - String name = faction.getName(rp); - names.add(name); - } - - // Return Ret - return ret; - } - // -------------------------------------------- // // FIELD: flagOverrides // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index 98725f24..c58f224a 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -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 { 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 factionIdsToDelete = MUtil.set("0", "-1", "-2"); - - // Read the file content through GSON. - Type type = new TypeToken>(){}.getType(); - Map id2faction = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type); - - // The Coll - FactionColl coll = this.getForUniverse(MassiveCore.DEFAULT); - - // Set the data - for (Entry 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> getRelationNames(Faction faction, Set rels) + { + // Create + Map> ret = new LinkedHashMap>(); + boolean peaceful = faction.getFlag(MFlag.getFlagPeaceful()); + for (Rel rel : rels) + { + ret.put(rel, new ArrayList()); + } + + // Fill + for (Faction fac : FactionColl.get().getAll()) + { + if (fac.getFlag(MFlag.getFlagPeaceful())) continue; + + Rel rel = fac.getRelationTo(faction); + List 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 names = ret.get(Rel.TRUCE); + if (names == null) return ret; + + ret.put(Rel.TRUCE, Collections.singletonList(MConf.get().colorTruce.toString() + Txt.parse("*EVERYONE*"))); + + // Return + return ret; + } }