33import com .mojang .brigadier .CommandDispatcher ;
44import com .mojang .brigadier .arguments .StringArgumentType ;
55import net .azisaba .interchatmod .blueberry .Mod ;
6+ import net .azisaba .interchatmod .common .model .GuildMember ;
7+ import net .azisaba .interchatmod .common .util .Constants ;
68import net .blueberrymc .client .commands .ClientCommandHandler ;
9+ import net .minecraft .ChatFormatting ;
710import net .minecraft .commands .CommandSourceStack ;
8- import net .minecraft .commands .Commands ;
11+ import net .minecraft .commands .SharedSuggestionProvider ;
12+ import net .minecraft .network .chat .ClickEvent ;
13+ import net .minecraft .network .chat .Component ;
14+ import net .minecraft .network .chat .HoverEvent ;
915import org .jetbrains .annotations .NotNull ;
1016
17+ import java .util .Collections ;
18+ import java .util .Locale ;
19+ import java .util .function .Consumer ;
20+ import java .util .stream .Collectors ;
21+ import java .util .stream .Stream ;
22+
23+ import static net .minecraft .commands .Commands .argument ;
24+ import static net .minecraft .commands .Commands .literal ;
25+
26+ @ SuppressWarnings ("SameReturnValue" )
1127public class GuildCommand implements ClientCommandHandler {
1228 private final Mod mod ;
1329
@@ -18,29 +34,140 @@ public GuildCommand(Mod mod) {
1834 @ Override
1935 public void register (@ NotNull CommandDispatcher <CommandSourceStack > commandDispatcher ) {
2036 commandDispatcher .register (
21- Commands . literal ("cguild" )
22- .then (Commands . literal ("invite" )
23- .then (Commands . argument ("player" , StringArgumentType .word ())
37+ literal ("cguild" )
38+ .then (literal ("invite" )
39+ .then (argument ("player" , StringArgumentType .word ())
2440 .executes (ctx -> executeInvite (StringArgumentType .getString (ctx , "player" )))
2541 )
2642 )
27- .then (Commands . literal ("accept" )
28- .then (Commands . argument ("guild" , StringArgumentType .word ())
43+ .then (literal ("accept" )
44+ .then (argument ("guild" , StringArgumentType .word ())
2945 .executes (ctx -> executeRespondInvite (StringArgumentType .getString (ctx , "guild" ), true ))
3046 )
3147 )
32- .then (Commands . literal ("reject" )
33- .then (Commands . argument ("guild" , StringArgumentType .word ())
48+ .then (literal ("reject" )
49+ .then (argument ("guild" , StringArgumentType .word ())
3450 .executes (ctx -> executeRespondInvite (StringArgumentType .getString (ctx , "guild" ), false ))
3551 )
3652 )
37- .then (Commands . literal ("nick" )
53+ .then (literal ("nick" )
3854 .executes (ctx -> executeNick (null ))
39- .then (Commands . argument ("nickname" , StringArgumentType .greedyString ())
55+ .then (argument ("nickname" , StringArgumentType .greedyString ())
4056 .executes (ctx -> executeNick (StringArgumentType .getString (ctx , "nickname" )))
4157 )
4258 )
59+ .then (literal ("jp-on" )
60+ .executes (ctx -> {
61+ mod .client .toggleTranslate (true );
62+ return 0 ;
63+ })
64+ )
65+ .then (literal ("jp-off" )
66+ .executes (ctx -> {
67+ mod .client .toggleTranslate (false );
68+ return 0 ;
69+ })
70+ )
71+ .then (literal ("role" )
72+ .then (argument ("member" , StringArgumentType .word ())
73+ .suggests ((ctx , builder ) -> {
74+ var set = mod .guildMembers .getOrDefault (mod .client .getSelectedGuild (), Collections .emptySet ());
75+ return SharedSuggestionProvider .suggest (set .stream ().map (GuildMember ::name ), builder );
76+ })
77+ .then (argument ("role" , StringArgumentType .word ())
78+ .suggests ((ctx , builder ) -> SharedSuggestionProvider .suggest (Stream .of ("owner" , "moderator" , "member" ), builder ))
79+ .executes (ctx -> {
80+ mod .client .role (StringArgumentType .getString (ctx , "member" ), StringArgumentType .getString (ctx , "role" ));
81+ return 0 ;
82+ })
83+ )
84+ )
85+ )
86+ .then (literal ("toggleinvites" )
87+ .executes (ctx -> {
88+ mod .client .toggleInvites ();
89+ return 0 ;
90+ })
91+ )
92+ .then (literal ("hide-guild" )
93+ .executes (ctx -> {
94+ mod .client .hideGuild ();
95+ return 0 ;
96+ })
97+ )
98+ .then (literal ("hideall" )
99+ .executes (ctx -> {
100+ mod .client .hideAll ("" );
101+ return 0 ;
102+ })
103+ .then (argument ("duration" , StringArgumentType .greedyString ())
104+ .executes (ctx -> {
105+ mod .client .hideAll (StringArgumentType .getString (ctx , "duration" ));
106+ return 0 ;
107+ })
108+ )
109+ )
110+ .then (literal ("format" )
111+ .then (argument ("format" , StringArgumentType .greedyString ())
112+ .suggests ((ctx , builder ) -> SharedSuggestionProvider .suggest (Constants .FORMAT_VARIABLES .stream (), builder ))
113+ .executes (ctx -> {
114+ mod .client .format (StringArgumentType .getString (ctx , "format" ));
115+ return 0 ;
116+ })
117+ )
118+ )
119+ .then (literal ("info" ).executes (ctx -> executeInfo (ctx .getSource ())))
120+ );
121+ }
122+
123+ private int executeInfo (CommandSourceStack source ) {
124+ var guild = mod .guilds .stream ().filter (g -> g .id () == mod .client .getSelectedGuild ()).findAny ().orElse (null );
125+ if (guild == null ) {
126+ source .sendFailure (Component .literal ("無効なギルドが指定されています。/cgs (ギルド)で選択してください。" ));
127+ return 0 ;
128+ }
129+ var members = mod .guildMembers .getOrDefault (guild .id (), Collections .emptySet ());
130+ source .sendSystemMessage (
131+ Component .literal ("--- ギルド" ).withStyle (ChatFormatting .GOLD )
132+ .append (Component .literal (guild .name ()).withStyle (ChatFormatting .AQUA ))
133+ .append (Component .literal ("の情報 ---" ).withStyle (ChatFormatting .GOLD ))
134+ );
135+ source .sendSystemMessage (
136+ Component .literal ("メンバー数: " ).withStyle (ChatFormatting .GOLD )
137+ .append (Component .literal (String .valueOf (members .size ())).withStyle (ChatFormatting .RED ))
138+ .append (Component .literal ("/" ).withStyle (ChatFormatting .GOLD ))
139+ .append (Component .literal (String .valueOf (guild .capacity ())).withStyle (ChatFormatting .RED ))
140+ );
141+ Consumer <String > sendRole = (role ) -> {
142+ String players =
143+ members .stream ()
144+ .filter (m -> m .role ().equals (role .toUpperCase (Locale .ROOT )))
145+ .map (GuildMember ::name )
146+ .collect (Collectors .joining (", " ));
147+ source .sendSystemMessage (
148+ Component .literal (role + ": " ).withStyle (ChatFormatting .GOLD )
149+ .append (Component .literal (players ).withStyle (ChatFormatting .WHITE ))
150+ );
151+ };
152+ sendRole .accept ("Owner" );
153+ sendRole .accept ("Moderator" );
154+ sendRole .accept ("Member" );
155+ source .sendSystemMessage (Component .empty ());
156+ source .sendSystemMessage (
157+ Component .literal ("公開: " ).withStyle (ChatFormatting .GOLD )
158+ .append (Component .literal (String .valueOf (guild .open ())).withStyle (guild .open () ? ChatFormatting .GREEN : ChatFormatting .RED ))
159+ );
160+ source .sendSystemMessage (
161+ Component .literal ("チャット形式: " ).withStyle (ChatFormatting .GOLD )
162+ .append (Component .literal (guild .format ())
163+ .withStyle (ChatFormatting .WHITE )
164+ .withStyle (style ->
165+ style .withHoverEvent (new HoverEvent (HoverEvent .Action .SHOW_TEXT , Component .literal ("クリックでコピー" )))
166+ .withClickEvent (new ClickEvent (ClickEvent .Action .COPY_TO_CLIPBOARD , guild .format ()))
167+ )
168+ )
43169 );
170+ return 0 ;
44171 }
45172
46173 private int executeInvite (String player ) {
0 commit comments