From 972eace5d2418466fdbafbf1cf1a4ec0e015f874 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sat, 18 Oct 2014 18:30:13 +0200 Subject: [PATCH] Better MFlag description system --- .../factions/WorldExceptionSet.java | 8 +- .../factions/cmd/CmdFactionsFlag.java | 6 +- .../factions/engine/EngineMain.java | 8 +- .../massivecraft/factions/entity/Board.java | 2 +- .../factions/entity/BoardColl.java | 8 +- .../factions/entity/BoardInterface.java | 1 + .../massivecraft/factions/entity/MFlag.java | 124 +++++++++++++----- 7 files changed, 109 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/WorldExceptionSet.java b/src/main/java/com/massivecraft/factions/WorldExceptionSet.java index 21603813..9c1568ed 100644 --- a/src/main/java/com/massivecraft/factions/WorldExceptionSet.java +++ b/src/main/java/com/massivecraft/factions/WorldExceptionSet.java @@ -1,10 +1,10 @@ package com.massivecraft.factions; -import java.util.LinkedHashSet; -import java.util.Set; - import org.bukkit.World; +import com.massivecraft.massivecore.CaseInsensitiveComparator; +import com.massivecraft.massivecore.collections.MassiveTreeSet; + public class WorldExceptionSet { // -------------------------------------------- // @@ -13,7 +13,7 @@ public class WorldExceptionSet public boolean standard = true; - public Set exceptions = new LinkedHashSet(); + public MassiveTreeSet exceptions = new MassiveTreeSet(CaseInsensitiveComparator.get()); // -------------------------------------------- // // CONTAINS diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlag.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlag.java index 75289ee1..2aad078b 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlag.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlag.java @@ -49,7 +49,7 @@ public class CmdFactionsFlag extends FactionsCommand for (MFlag mflag : MFlag.getAll()) { if (!mflag.isVisible() && !msender.isUsingAdminMode()) continue; - msg(mflag.getStateInfo(faction.getFlag(mflag), true)); + msg(mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, false)); } return; } @@ -62,7 +62,7 @@ public class CmdFactionsFlag extends FactionsCommand if ( ! this.argIsSet(2)) { msg(Txt.titleize("Flag for " + faction.describeTo(msender, true))); - msg(mflag.getStateInfo(faction.getFlag(mflag), true)); + msg(mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, false)); return; } @@ -90,7 +90,7 @@ public class CmdFactionsFlag extends FactionsCommand faction.setFlag(mflag, targetValue); // Inform - String stateInfo = mflag.getStateInfo(faction.getFlag(mflag), true); + String stateInfo = mflag.getStateDesc(faction.getFlag(mflag), true, false, true, true, true); if (msender.getFaction() != faction) { // Send message to sender diff --git a/src/main/java/com/massivecraft/factions/engine/EngineMain.java b/src/main/java/com/massivecraft/factions/engine/EngineMain.java index 8bb61351..10a97e0e 100644 --- a/src/main/java/com/massivecraft/factions/engine/EngineMain.java +++ b/src/main/java/com/massivecraft/factions/engine/EngineMain.java @@ -122,7 +122,7 @@ public class EngineMain extends EngineAbstract // FACTION SHOW // -------------------------------------------- // - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onFactionShow(EventFactionsFactionShow event) { final int tableCols = 4; @@ -191,7 +191,6 @@ public class EngineMain extends EngineAbstract Double money = MConf.get().econChunkCost.get(type); if (money == null) continue; if (money == 0) continue; - System.out.println("money: "+money); money *= landCount; String word = "Cost"; @@ -202,7 +201,7 @@ public class EngineMain extends EngineAbstract } String key = Txt.parse("Total Land %s %s", type.toString().toLowerCase(), word); - String value = Money.format(money); + String value = Txt.parse("%s", Money.format(money)); String line = show(key, value); landvalueLines.add(line); } @@ -211,7 +210,8 @@ public class EngineMain extends EngineAbstract // BANK if (MConf.get().bankEnabled) { - String bankDesc = Money.format(Money.get(faction)); + double bank = Money.get(faction); + String bankDesc = Txt.parse("%s", Money.format(bank, true)); show(idPriorityLiness, Const.SHOW_ID_FACTION_BANK, Const.SHOW_PRIORITY_FACTION_BANK, "Bank", bankDesc); } } diff --git a/src/main/java/com/massivecraft/factions/entity/Board.java b/src/main/java/com/massivecraft/factions/entity/Board.java index 57889583..2ad90349 100644 --- a/src/main/java/com/massivecraft/factions/entity/Board.java +++ b/src/main/java/com/massivecraft/factions/entity/Board.java @@ -204,13 +204,13 @@ public class Board extends Entity implements BoardInterface return this.getCount(faction.getId()); } + @Override public int getCount(String factionId) { int ret = 0; for (TerritoryAccess ta : this.map.values()) { if (!ta.getHostFactionId().equals(factionId)) continue; - ret += 1; } return ret; diff --git a/src/main/java/com/massivecraft/factions/entity/BoardColl.java b/src/main/java/com/massivecraft/factions/entity/BoardColl.java index 3b0b6028..fd714f31 100644 --- a/src/main/java/com/massivecraft/factions/entity/BoardColl.java +++ b/src/main/java/com/massivecraft/factions/entity/BoardColl.java @@ -132,11 +132,17 @@ public class BoardColl extends Coll implements BoardInterface @Override public int getCount(Faction faction) + { + return this.getCount(faction.getId()); + } + + @Override + public int getCount(String factionId) { int ret = 0; for (Board board : this.getAll()) { - ret += board.getCount(faction); + ret += board.getCount(factionId); } return ret; } diff --git a/src/main/java/com/massivecraft/factions/entity/BoardInterface.java b/src/main/java/com/massivecraft/factions/entity/BoardInterface.java index 11153625..bd5a197f 100644 --- a/src/main/java/com/massivecraft/factions/entity/BoardInterface.java +++ b/src/main/java/com/massivecraft/factions/entity/BoardInterface.java @@ -27,6 +27,7 @@ public interface BoardInterface // COUNT public int getCount(Faction faction); + public int getCount(String factionId); // NEARBY DETECTION public boolean isBorderPs(PS ps); diff --git a/src/main/java/com/massivecraft/factions/entity/MFlag.java b/src/main/java/com/massivecraft/factions/entity/MFlag.java index d2d6f2cb..31620770 100644 --- a/src/main/java/com/massivecraft/factions/entity/MFlag.java +++ b/src/main/java/com/massivecraft/factions/entity/MFlag.java @@ -5,6 +5,7 @@ import java.util.List; import com.massivecraft.massivecore.PredictateIsRegistered; import com.massivecraft.massivecore.Prioritized; import com.massivecraft.massivecore.Registerable; +import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.store.Entity; import com.massivecraft.massivecore.util.Txt; @@ -70,20 +71,20 @@ public class MFlag extends Entity implements Prioritized, Registerable getFlagInfpower(); } - public static MFlag getFlagOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Open factions can be joined without invite.", false, true, true); } - public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", false, true, true); } - public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", true, false, true); } - public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", true, false, true); } - public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother here?", false, false, true); } - public static MFlag getFlagExplosions() { return getCreative(PRIORITY_EXPLOSIONS, ID_EXPLOSIONS, ID_EXPLOSIONS, "Can explosions occur in this territory?", true, false, true); } - public static MFlag getFlagOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", false, false, true); } - public static MFlag getFlagFirespread() { return getCreative(PRIORITY_FIRESPREAD, ID_FIRESPREAD, ID_FIRESPREAD, "Can fire spread in territory?", true, false, true); } - public static MFlag getFlagEndergrief() { return getCreative(PRIORITY_ENDERGRIEF, ID_ENDERGRIEF, ID_ENDERGRIEF, "Can endermen grief in this territory?", false, false, true); } - public static MFlag getFlagPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "A permanent faction will never be deleted.", false, false, true); } - public static MFlag getFlagPeaceful() { return getCreative(PRIORITY_PEACEFUL, ID_PEACEFUL, ID_PEACEFUL, "Always in truce with other factions.", false, false, true); } - public static MFlag getFlagInfpower() { return getCreative(PRIORITY_INFPOWER, ID_INFPOWER, ID_INFPOWER, "This flag gives the faction infinite power.", false, false, true); } + public static MFlag getFlagOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Can the faction be joined without an invite?", "An invite is required to join.", "Anyone can join. No invite required.", false, true, true); } + public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", "Monsters can spawn in this territory.", "Monsters can NOT spawn in this territory.", false, true, true); } + public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", "Power is lost on death in this territory.", "Power is NOT lost on death in this territory.", true, false, true); } + public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", "You can PVP in this territory.", "You can NOT PVP in this territory.", true, false, true); } + public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friends can hurt eachother in this territory.", "Friends can NOT hurt eachother in this territory.", false, false, true); } + public static MFlag getFlagExplosions() { return getCreative(PRIORITY_EXPLOSIONS, ID_EXPLOSIONS, ID_EXPLOSIONS, "Can explosions occur in this territory?", "Explosions can occur in this territory.", "Explosions can NOT occur in this territory.", true, false, true); } + public static MFlag getFlagOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", "Explosions can occur if faction is offline.", "Explosions can NOT occur if faction is offline.", false, false, true); } + public static MFlag getFlagFirespread() { return getCreative(PRIORITY_FIRESPREAD, ID_FIRESPREAD, ID_FIRESPREAD, "Can fire spread in territory?", "Fire can spread in this territory.", "Fire can NOT spread in this territory.", true, false, true); } + public static MFlag getFlagEndergrief() { return getCreative(PRIORITY_ENDERGRIEF, ID_ENDERGRIEF, ID_ENDERGRIEF, "Can endermen grief in this territory?", "Endermen can grief in this territory", "Endermen can NOT grief in this territory.", false, false, true); } + public static MFlag getFlagPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "Is the faction immune to deletion?", "The faction can NOT be deleted.", "The faction can be deleted.", false, false, true); } + public static MFlag getFlagPeaceful() { return getCreative(PRIORITY_PEACEFUL, ID_PEACEFUL, ID_PEACEFUL, "Is the faction in truce with everyone?", "The faction is in truce with everyone.", "The faction relations work as usual.", false, false, true); } + public static MFlag getFlagInfpower() { return getCreative(PRIORITY_INFPOWER, ID_INFPOWER, ID_INFPOWER, "Does the faction have infinite power?", "The faction has infinite power.", "The faction power works as usual.", false, false, true); } - public static MFlag getCreative(int priority, String id, String name, String desc, boolean standard, boolean editable, boolean visible) + public static MFlag getCreative(int priority, String id, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible) { MFlag ret = MFlagColl.get().get(id, false); if (ret != null) @@ -92,7 +93,7 @@ public class MFlag extends Entity implements Prioritized, Registerable return ret; } - ret = new MFlag(priority, name, desc, standard, editable, visible); + ret = new MFlag(priority, name, desc, descYes, descNo, standard, editable, visible); MFlagColl.get().attach(ret, id); ret.setRegistered(true); ret.sync(); @@ -110,6 +111,8 @@ public class MFlag extends Entity implements Prioritized, Registerable this.priority = that.priority; this.name = that.name; this.desc = that.desc; + this.descYes = that.descYes; + this.descNo = that.descNo; this.standard = that.standard; this.editable = that.editable; this.visible = that.visible; @@ -140,12 +143,24 @@ public class MFlag extends Entity implements Prioritized, Registerable public String getName() { return this.name; } public MFlag setName(String name) { this.name = name; this.changed(); return this; } - // Short description + // Description // Example: "Can monsters spawn in this territory?" private String desc = "defaultDesc"; public String getDesc() { return this.desc; } public MFlag setDesc(String desc) { this.desc = desc; this.changed(); return this; } + // Description Yes + // Example: "Monsters can spawn in this territory." + private String descYes = "defaultDescYes"; + public String getDescYes() { return this.descYes; } + public MFlag setDescYes(String descYes) { this.descYes = descYes; this.changed(); return this; } + + // Description No + // Example: "Monsters can NOT spawn in this territory." + private String descNo = "defaultDescNo"; + public String getDescNo() { return this.descNo; } + public MFlag setDescNo(String descNo) { this.descNo = descNo; this.changed(); return this; } + // Standard value // Example: false (per default monsters do not spawn in faction territory) private boolean standard = true; @@ -174,11 +189,13 @@ public class MFlag extends Entity implements Prioritized, Registerable // No argument constructor for GSON } - public MFlag(int priority, String name, String desc, boolean standard, boolean editable, boolean visible) + public MFlag(int priority, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible) { this.priority = priority; this.name = name; this.desc = desc; + this.descYes = descYes; + this.descNo = descNo; this.standard = standard; this.editable = editable; this.visible = visible; @@ -195,27 +212,64 @@ public class MFlag extends Entity implements Prioritized, Registerable return this.isStandard() != value; } + public String getStateDesc(boolean value, boolean withValue, boolean monospaceValue, boolean withName, boolean withDesc, boolean specificDesc) + { + List parts = new MassiveList<>(); + + if (withValue) + { + if (monospaceValue) + { + parts.add(Txt.parse(value ? "YES" : "NOO")); + } + else + { + parts.add(Txt.parse(value ? "YES" : "NO")); + } + } + + if (withName) + { + String nameFormat; + if ( ! this.isVisible()) + { + nameFormat = "%s"; + } + else if (this.isEditable()) + { + nameFormat = "%s"; + } + else + { + nameFormat = "%s"; + } + String name = this.getName(); + String nameDesc = Txt.parse(nameFormat, name); + parts.add(nameDesc); + } + + if (withDesc) + { + String desc; + if (specificDesc) + { + desc = value ? this.getDescYes() : this.getDescNo(); + } + else + { + desc = this.getDesc(); + } + String descDesc = Txt.parse("%s", desc); + parts.add(descDesc); + } + + return Txt.implode(parts, " "); + } + + @Deprecated public String getStateInfo(boolean value, boolean withDesc) { - String valueDesc = value ? "YES" : "NOO"; - - String color = ""; - if (!this.isVisible()) - { - color = ""; - } - else if (this.isEditable()) - { - color = ""; - } - - String ret = valueDesc + " " + color + this.getName(); - - if (withDesc) ret += " " + this.getDesc(); - - ret = Txt.parse(ret); - - return ret; + return this.getStateDesc(value, true, true, true, true, false); } }