88import dev .kitteh .factions .command .Cmd ;
99import dev .kitteh .factions .command .FactionParser ;
1010import dev .kitteh .factions .command .Sender ;
11- import dev .kitteh .factions .permissible .Relation ;
12- import dev .kitteh .factions .plugin .AbstractFactionsPlugin ;
1311import dev .kitteh .factions .tag .FactionTag ;
1412import dev .kitteh .factions .tag .FancyTag ;
1513import dev .kitteh .factions .tag .Tag ;
14+ import dev .kitteh .factions .tagresolver .FactionResolver ;
1615import dev .kitteh .factions .util .ComponentDispatcher ;
17- import dev .kitteh .factions .util .MiscUtil ;
16+ import dev .kitteh .factions .util .Mini ;
1817import dev .kitteh .factions .util .Permission ;
1918import dev .kitteh .factions .util .TL ;
2019import dev .kitteh .factions .util .TextUtil ;
20+ import dev .kitteh .factions .util .TriConsumer ;
2121import net .kyori .adventure .text .Component ;
22- import net .kyori .adventure .text .serializer .legacy .LegacyComponentSerializer ;
23- import org .bukkit .Bukkit ;
24- import org .bukkit .OfflinePlayer ;
25- import org .bukkit .command .CommandSender ;
26- import org .bukkit .entity .Player ;
27- import org .bukkit .scheduler .BukkitRunnable ;
2822import org .incendo .cloud .Command ;
2923import org .incendo .cloud .CommandManager ;
3024import org .incendo .cloud .context .CommandContext ;
25+ import org .incendo .cloud .minecraft .extras .MinecraftHelp ;
3126
3227import java .util .ArrayList ;
33- import java .util .HashMap ;
3428import java .util .List ;
35- import java .util .Map ;
36- import java .util .Set ;
37- import java .util .UUID ;
38- import dev .kitteh .factions .util .TriConsumer ;
39- import org .incendo .cloud .minecraft .extras .MinecraftHelp ;
40- import java .util .stream .Collectors ;
4129
4230public class CmdShow implements Cmd {
4331 @ Override
@@ -56,19 +44,17 @@ public TriConsumer<CommandManager<Sender>, Command.Builder<Sender>, MinecraftHel
5644
5745 public CmdShow () {
5846 // add defaults to /f show in case config doesn't have it
59- defaults .add ("{header}" );
60- defaults .add ("&6Description: &e{description}" );
61- defaults .add ("&6Joining: &e{joining} {peaceful}" );
62- defaults .add ("&6Land / Power / Maxpower: &e {chunks} / {power} / {maxPower}" );
63- defaults .add ("&6Raidable: {raidable}" );
64- defaults .add ("&6Founded: &e{create-date}" );
65- defaults .add ("&6This faction is permanent, remaining even with no members." );
66- defaults .add ("&6Land value: &e{land-value} {land-refund}" );
67- defaults .add ("&6Balance: &e{faction-balance}" );
68- defaults .add ("&6Bans: &e{faction-bancount}" );
69- defaults .add ("&6Allies(&e{allies}&6/&e{max-allies}&6): {allies-list}" );
70- defaults .add ("&6Online: (&e{online}&6/&e{members}&6): {online-list}" );
71- defaults .add ("&6Offline: (&e{offline}&6/&e{members}&6): {offline-list}" );
47+ defaults .add ("<fuuid:title><faction:relation_color><faction:name>" );
48+ defaults .add ("<gold>Description: <yellow><faction:description>" );
49+ defaults .add ("<gold><faction:if_open>No invitation required</faction:if_open><faction:if_open:else>Invitation required</faction:if_open:else><faction:if_peaceful>. <fuuid:color:peaceful>Peaceful" );
50+ defaults .add ("<gold>Land / Power / Max Power: <yellow><faction:claims_count></yellow> / <yellow><faction:power></yellow> / <yellow><faction:power_max>" );
51+ defaults .add ("<gold>Raidable: <faction:if_raidable><green>Yes</faction:if_raidable><faction:if_raidable:else><red>No" );
52+ defaults .add ("<gold>Founded: <yellow><faction:creation_date>" );
53+ defaults .add ("<faction:if_permanent><gold>This faction is permanent, remaining even with no members." );
54+ defaults .add ("<fuuid:if_economy><fuuid:if_banks><gold>Balance: <yellow><faction:bank_balance></fuuid:if_banks> <gold>Land value: <yellow><faction:claims_value>" );
55+ defaults .add ("<faction:if_allies><gold>Allies (<yellow><faction:allies_count></yellow>/<yellow><faction:allies_max></yellow>): {allies-list}" );
56+ defaults .add ("<faction:if_online><gold>Online: (<yellow><faction:members_online_count></yellow>/<yellow><faction:members_total_count></yellow>)<faction:if_online>: {online-list}" );
57+ defaults .add ("<faction:if_offline><gold>Offline: (<yellow><faction:members_offline_count></yellow>/<yellow><faction:members_total_count></yellow>)<faction:if_offline>: {offline-list}" );
7258 }
7359
7460 private void handle (CommandContext <Sender > context ) {
@@ -91,168 +77,37 @@ private void handle(CommandContext<Sender> context) {
9177 return ;
9278 }
9379
94- List <String > show = FactionsPlugin .instance ().conf ().commands ().show ().getFormat ();
80+ var tl = FactionsPlugin .instance ().tl ().commands ().show ();
81+ List <String > show = tl .getNormalFormat ();
9582 if (show == null || show .isEmpty ()) {
9683 show = defaults ;
9784 }
9885
99- if (!faction .isNormal ()) {
100- String tag = faction .tagLegacy (fPlayer );
101- // send header and that's all
102- String header = show .getFirst ();
103- if (FactionTag .HEADER .foundInString (header )) {
104- context .sender ().sender ().sendMessage (TextUtil .titleizeLegacy (tag ));
105- } else {
106- String message = header .replace (FactionTag .FACTION .getTag (), tag );
107- message = Tag .parsePlain (faction , fPlayer , message );
108- context .sender ().sender ().sendMessage (TextUtil .parse (message ));
109- }
110- return ; // we only show header for non-normal factions
86+ if (faction .isSafeZone ()) {
87+ show = tl .getSafezoneFormat ();
88+ }
89+ if (faction .isWarZone ()) {
90+ show = tl .getWarzoneFormat ();
11191 }
11292
113- List <String > messageList = new ArrayList <>();
11493 for (String raw : show ) {
115- String parsed = Tag .parsePlain (faction , fPlayer , raw ); // use relations
116- if (parsed == null ) {
117- continue ; // Due to minimal f show.
118- }
94+ String msg = raw ;
11995
120- if (fPlayer != null ) {
121- parsed = Tag .parsePlaceholders (fPlayer .asPlayer (), parsed );
96+ FancyTag tag = FancyTag .getMatch (raw );
97+ if (tag != null ) {
98+ msg = msg .replace (tag .getTag (), "" );
12299 }
123-
124- if (!parsed .contains ("{notFrozen}" ) && !parsed .contains ("{notPermanent}" )) {
125- if (parsed .contains ("{ig}" )) {
126- // replaces all variables with no home TL
127- parsed = parsed .substring (0 , parsed .indexOf ("{ig}" )) + TL .COMMAND_SHOW_NOHOME ;
128- }
129- parsed = parsed .replace ("%" , "" ); // Just in case it got in there before we disallowed it.
130- messageList .add (parsed );
100+ Component component = Mini .parse (msg , FactionResolver .of (fPlayer , faction ));
101+ if (component == Component .empty ()) {
102+ continue ; // Due to minimal f show.
131103 }
132- }
133- if (fPlayer != null && this .groupPresent ()) {
134- new GroupGetter (messageList , fPlayer , faction ).runTaskAsynchronously (AbstractFactionsPlugin .instance ());
135- } else {
136- this .sendMessages (messageList , context .sender ().sender (), faction , fPlayer );
137- }
138- }
139-
140- private void sendMessages (List <String > messageList , CommandSender recipient , Faction faction , FPlayer player ) {
141- this .sendMessages (messageList , recipient , faction , player , null );
142- }
143104
144- private void sendMessages (List <String > messageList , CommandSender recipient , Faction faction , FPlayer player , Map <UUID , String > groupMap ) {
145- FancyTag tag ;
146- for (String parsed : messageList ) {
147- if ((tag = FancyTag .getMatch (parsed )) != null ) {
148- if (player != null ) {
149- List <Component > fancy = FancyTag .parse (parsed , faction , player , groupMap );
150- if (fancy != null ) {
151- for (Component component : fancy ) {
152- ComponentDispatcher .send (recipient , component );
153- }
154- }
155- } else {
156- StringBuilder builder = new StringBuilder ();
157- builder .append (parsed .replace (tag .getTag (), "" ));
158- switch (tag ) {
159- case ONLINE_LIST :
160- this .onOffLineMessage (builder , recipient , faction , true );
161- break ;
162- case OFFLINE_LIST :
163- this .onOffLineMessage (builder , recipient , faction , false );
164- break ;
165- case ALLIES_LIST :
166- this .relationMessage (builder , recipient , faction , Relation .ALLY );
167- break ;
168- case ENEMIES_LIST :
169- this .relationMessage (builder , recipient , faction , Relation .ENEMY );
170- break ;
171- case TRUCES_LIST :
172- this .relationMessage (builder , recipient , faction , Relation .TRUCE );
173- break ;
174- default :
175- // NO
176- }
177- }
105+ if (tag == null ) {
106+ ComponentDispatcher .send (context .sender ().sender (), component );
178107 } else {
179- ComponentDispatcher .send (recipient , LegacyComponentSerializer .legacySection ().deserialize (TextUtil .parse (parsed )));
180- }
181- }
182- }
183-
184- private void onOffLineMessage (StringBuilder builder , CommandSender recipient , Faction faction , boolean online ) {
185- boolean first = true ;
186- for (FPlayer p : MiscUtil .rankOrder (faction .membersOnline (online ))) {
187- String name = p .nameWithTitleLegacy ();
188- builder .append (first ? name : ", " + name );
189- first = false ;
190- }
191- recipient .sendMessage (TextUtil .parse (builder .toString ()));
192- }
193-
194- private void relationMessage (StringBuilder builder , CommandSender recipient , Faction faction , Relation relation ) {
195- boolean first = true ;
196- for (Faction otherFaction : Factions .factions ().all ()) {
197- if (otherFaction != faction && otherFaction .relationTo (faction ) == relation ) {
198- String s = otherFaction .tag ();
199- builder .append (first ? s : ", " + s );
200- first = false ;
201- }
202- }
203- recipient .sendMessage (TextUtil .parse (builder .toString ()));
204- }
205-
206- private boolean groupPresent () {
207- for (String line : FactionsPlugin .instance ().conf ().commands ().toolTips ().getPlayer ()) {
208- if (line .contains ("{group}" )) {
209- return true ;
210- }
211- }
212- return false ;
213- }
214-
215- private class GroupGetter extends BukkitRunnable {
216- private final List <String > messageList ;
217- private final FPlayer sender ;
218- private final Faction faction ;
219- private final Set <OfflinePlayer > players ;
220-
221- private GroupGetter (List <String > messageList , FPlayer sender , Faction faction ) {
222- this .messageList = messageList ;
223- this .sender = sender ;
224- this .faction = faction ;
225- this .players = faction .members ().stream ().map (fp -> AbstractFactionsPlugin .instance ().getOfflinePlayer (fp .name (), fp .uniqueId ())).collect (Collectors .toSet ());
226- }
227-
228- @ Override
229- public void run () {
230- Map <UUID , String > map = new HashMap <>();
231- for (OfflinePlayer player : this .players ) {
232- map .put (player .getUniqueId (), AbstractFactionsPlugin .instance ().getPrimaryGroup (player ));
233- }
234- new SenderRunner (this .messageList , this .sender , this .faction , map ).runTask (AbstractFactionsPlugin .instance ());
235- }
236- }
237-
238- private class SenderRunner extends BukkitRunnable {
239- private final List <String > messageList ;
240- private final FPlayer sender ;
241- private final Faction faction ;
242- private final Map <UUID , String > map ;
243-
244- private SenderRunner (List <String > messageList , FPlayer sender , Faction faction , Map <UUID , String > map ) {
245- this .messageList = messageList ;
246- this .sender = sender ;
247- this .faction = faction ;
248- this .map = map ;
249- }
250-
251- @ Override
252- public void run () {
253- Player player = Bukkit .getPlayerExact (sender .name ());
254- if (player != null ) {
255- CmdShow .this .sendMessages (messageList , player , faction , sender , map );
108+ for (Component comp : tag .getMessage (component , faction , fPlayer )) {
109+ ComponentDispatcher .send (context .sender ().sender (), comp );
110+ }
256111 }
257112 }
258113 }
0 commit comments