1
1
package de .eztxm .luckprefix .command ;
2
2
3
3
import de .eztxm .luckprefix .LuckPrefix ;
4
- import de .eztxm .luckprefix .util .ConfigManager ;
5
- import de .eztxm .luckprefix .util .GroupManager ;
6
- import de .eztxm .luckprefix .util .GroupType ;
7
- import de .eztxm .luckprefix .util .TextUtil ;
8
- import lombok .SneakyThrows ;
4
+ import de .eztxm .luckprefix .command .subcommand .GroupSubCommand ;
5
+ import de .eztxm .luckprefix .command .subcommand .ReloadConfigs ;
6
+ import de .eztxm .luckprefix .util .Text ;
9
7
import net .kyori .adventure .audience .Audience ;
10
- import net .kyori .adventure .text .minimessage .MiniMessage ;
11
8
import net .luckperms .api .LuckPerms ;
12
9
import net .luckperms .api .model .group .Group ;
13
- import org .bukkit .Bukkit ;
14
10
import org .bukkit .ChatColor ;
15
11
import org .bukkit .command .Command ;
16
12
import org .bukkit .command .CommandSender ;
17
13
import org .bukkit .command .TabExecutor ;
18
- import org .bukkit .configuration .file .FileConfiguration ;
19
14
import org .bukkit .entity .Player ;
20
- import org .bukkit .scoreboard .Team ;
21
15
import org .jetbrains .annotations .NotNull ;
22
16
import org .jetbrains .annotations .Nullable ;
23
17
24
- import java .io .File ;
25
18
import java .util .ArrayList ;
26
19
import java .util .Collections ;
27
20
import java .util .List ;
28
21
import java .util .Set ;
29
22
30
23
public class LuckPrefixCommand implements TabExecutor {
31
24
32
- @ SneakyThrows
33
25
@ Override
34
26
public boolean onCommand (@ NotNull CommandSender sender , @ NotNull Command cmd , @ NotNull String label , String [] args ) {
35
27
if (!(sender instanceof Player player )) {
@@ -38,11 +30,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
38
30
}
39
31
Audience adventurePlayer = LuckPrefix .getInstance ().getAdventure ().player (player );
40
32
if (!player .hasPermission ("luckprefix.command" )) {
41
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix () + "<#ff3333>You don't have the permission to use this command." ).miniMessage ());
33
+ adventurePlayer .sendMessage (new Text (LuckPrefix .getInstance ().getPrefix () + "<#ff3333>You don't have the permission to use this command." ).miniMessage ());
42
34
return false ;
43
35
}
44
36
if (args .length < 1 ) {
45
- adventurePlayer .sendMessage (new TextUtil ("""
37
+ adventurePlayer .sendMessage (new Text ("""
46
38
<dark_gray><st>------------</st><#77ef77>LuckPrefix<dark_gray><st>------------</st>
47
39
<dark_gray>» <gray>/luckprefix group <name> prefix - Shows the current prefix
48
40
<dark_gray>» <gray>/luckprefix group <name> prefix set <string> - Set the current prefix
@@ -56,161 +48,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
56
48
<dark_gray>» <gray>/luckprefix group <name> sortid set <string> - Set the current sortid
57
49
<dark_gray>» <gray>/luckprefix group <name> namecolor - Shows the current namecolor
58
50
<dark_gray>» <gray>/luckprefix group <name> namecolor set <string> - Set the current namecolor
51
+ <dark_gray>» <gray>/luckprefix reloadconfigs - Reloads all configurations
59
52
<dark_gray><st>------------</st><#77ef77>LuckPrefix<dark_gray><st>------------</st>""" ).miniMessage ());
60
53
return false ;
61
54
}
62
55
switch (args [0 ]) {
63
56
case "group" -> {
64
- if (args .length < 3 ) {
65
- adventurePlayer .sendMessage (new TextUtil ("""
66
- <dark_gray><st>------------</st><#77ef77>LuckPrefix<dark_gray><st>------------</st>
67
- <dark_gray>» <gray>/luckprefix group <name> prefix - Shows the current prefix
68
- <dark_gray>» <gray>/luckprefix group <name> prefix set <string> - Set the current prefix
69
- <dark_gray>» <gray>/luckprefix group <name> suffix - Shows the current suffix
70
- <dark_gray>» <gray>/luckprefix group <name> suffix set <string> - Set the current suffix
71
- <dark_gray>» <gray>/luckprefix group <name> tabformat - Shows the current tabformat
72
- <dark_gray>» <gray>/luckprefix group <name> tabformat set <string> - Set the current tabformat
73
- <dark_gray>» <gray>/luckprefix group <name> chatformat - Shows the current chatformat
74
- <dark_gray>» <gray>/luckprefix group <name> chatformat set <string> - Set the current chatformat
75
- <dark_gray>» <gray>/luckprefix group <name> sortid - Shows the current sortid
76
- <dark_gray>» <gray>/luckprefix group <name> sortid set <string> - Set the current sortid
77
- <dark_gray>» <gray>/luckprefix group <name> namecolor - Shows the current namecolor
78
- <dark_gray>» <gray>/luckprefix group <name> namecolor set <string> - Set the current namecolor
79
- <dark_gray><st>------------</st><#77ef77>LuckPrefix<dark_gray><st>------------</st>""" ).miniMessage ());
80
- return false ;
81
- }
82
- ConfigManager groupsFile = LuckPrefix .getInstance ().getGroupsFile ();
83
- FileConfiguration groupsConfig = LuckPrefix .getInstance ().getGroupsFile ().getConfiguration ();
84
- LuckPerms luckPerms = LuckPrefix .getInstance ().getLuckPerms ();
85
- Group group = luckPerms .getGroupManager ().getGroup (args [1 ]);
86
- if (group == null ) {
87
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix () + "<#ff3333>This group doesn't exist." ).miniMessage ());
88
- return false ;
89
- }
90
- try {
91
- GroupType groupType = GroupType .valueOf (args [2 ].toUpperCase ());
92
- switch (groupType ) {
93
- case PREFIX -> {
94
- if (args .length > 4 ) {
95
- StringBuilder builder = new StringBuilder (args [4 ]);
96
- for (int i = 5 ; i < args .length - 1 ; i ++) {
97
- builder .append (" " ).append (args [i ]);
98
- }
99
- groupsConfig .set (group .getName ().toLowerCase () + ".Prefix" , builder .toString ());
100
- groupsFile .reloadConfig ();
101
- return true ;
102
- }
103
- String prefix = groupsConfig .getString (group .getName ().toLowerCase () + ".Prefix" );
104
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix ()
105
- + "The prefix of the group <#33ffff>" + group .getName () + " <gray>is: " + prefix ).miniMessage ());
106
- return true ;
107
- }
108
- case SUFFIX -> {
109
- if (args .length > 4 ) {
110
- StringBuilder builder = new StringBuilder (args [4 ]);
111
- for (int i = 5 ; i < args .length - 1 ; i ++) {
112
- builder .append (" " ).append (args [i ]);
113
- }
114
- groupsConfig .set (group .getName ().toLowerCase () + ".Suffix" , builder .toString ());
115
- groupsFile .reloadConfig ();
116
- return true ;
117
- }
118
- String prefix = groupsConfig .getString (group .getName ().toLowerCase () + ".Suffix" );
119
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix ()
120
- + "The suffix of the group <#33ffff>" + group .getName () + " <gray>is: " + prefix ).miniMessage ());
121
- return true ;
122
- }
123
- case CHATFORMAT -> {
124
- if (args .length > 4 ) {
125
- StringBuilder builder = new StringBuilder (args [4 ]);
126
- for (int i = 5 ; i < args .length - 1 ; i ++) {
127
- builder .append (" " ).append (args [i ]);
128
- }
129
- groupsConfig .set (group .getName ().toLowerCase () + ".Chatformat" , builder .toString ());
130
- groupsFile .reloadConfig ();
131
- return true ;
132
- }
133
- String prefix = groupsConfig .getString (group .getName ().toLowerCase () + ".Chatformat" );
134
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix ()
135
- + "The chatformat of the group <#33ffff>" + group .getName () + " <gray>is: " + prefix ).miniMessage ());
136
- return true ;
137
- }
138
- case TABFORMAT -> {
139
- if (args .length > 4 ) {
140
- StringBuilder builder = new StringBuilder (args [4 ]);
141
- for (int i = 5 ; i < args .length - 1 ; i ++) {
142
- builder .append (" " ).append (args [i ]);
143
- }
144
- groupsConfig .set (group .getName ().toLowerCase () + ".Tabformat" , builder .toString ());
145
- groupsFile .reloadConfig ();
146
- return true ;
147
- }
148
- String prefix = groupsConfig .getString (group .getName ().toLowerCase () + ".Tabformat" );
149
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix ()
150
- + "The tabformat of the group <#33ffff>" + group .getName () + " <gray>is: " + prefix ).miniMessage ());
151
- return true ;
152
- }
153
- case SORTID -> {
154
- if (args .length == 5 ) {
155
- try {
156
- int sortID = Integer .parseInt (args [4 ]);
157
- groupsConfig .set (group .getName ().toLowerCase () + ".SortID" , sortID );
158
- groupsFile .reloadConfig ();
159
- return true ;
160
- } catch (NumberFormatException e ) {
161
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix () + "<#ff3333>This isn't a number." ).miniMessage ());
162
- }
163
- }
164
- String prefix = groupsConfig .getString (group .getName ().toLowerCase () + ".SortID" );
165
- adventurePlayer .sendMessage (
166
- MiniMessage .miniMessage ().deserialize (LuckPrefix .getInstance ().getPrefix ()
167
- + "The sort-id of the group <#33ffff>" + group .getName () + " <gray>is: " + prefix ));
168
- return true ;
169
- }
170
- case NAMECOLOR -> {
171
- if (args .length == 5 ) {
172
- try {
173
- ChatColor color = ChatColor .valueOf (args [4 ].toUpperCase ());
174
- if (!color .isColor () || color .isFormat ()) {
175
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix () + "<#ff3333>This isn't a color." ).miniMessage ());
176
- return false ;
177
- }
178
- groupsConfig .set (group .getName ().toLowerCase () + ".NameColor" , color .name ().toLowerCase ());
179
- groupsFile .reloadConfig ();
180
- return true ;
181
- } catch (EnumConstantNotPresentException e ) {
182
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix () + "<#ff3333>This isn't a number." ).miniMessage ());
183
- }
184
- }
185
- String prefix = groupsConfig .getString (group .getName ().toLowerCase () + ".SortID" );
186
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix ()
187
- + "The sort-id of the group <#33ffff>" + group .getName () + " <gray>is: " + prefix ).miniMessage ());
188
- return true ;
189
- }
190
- }
191
- } catch (EnumConstantNotPresentException e ) {
192
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix () + "<#ff3333>This group type doesn't exist." ).miniMessage ());
193
- }
57
+ return GroupSubCommand .execute (player , adventurePlayer , args );
194
58
}
195
59
case "reloadconfig" -> {
196
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix () + "Reloading configurations..." ).miniMessage ());
197
- LuckPrefix .getInstance ().getConfig ().load (new File ("plugins/LuckPrefix/config.yml" ));
198
- LuckPrefix .getInstance ().getDatabaseFile ().reloadConfig ();
199
- LuckPrefix .getInstance ().getGroupsFile ().reloadConfig ();
200
- GroupManager groupManager = LuckPrefix .getInstance ().getGroupManager ();
201
- for (Player onlinePlayer : Bukkit .getOnlinePlayers ()) {
202
- onlinePlayer .getScoreboard ().getTeams ().forEach (Team ::unregister );
203
- if (!groupManager .getGroups ().isEmpty ()) {
204
- List <String > groups = new ArrayList <>(groupManager .getGroups ());
205
- for (String group : groups ) {
206
- groupManager .deleteGroup (group );
207
- }
208
- }
209
- onlinePlayer .setScoreboard (Bukkit .getScoreboardManager ().getNewScoreboard ());
210
- groupManager .setupGroups (onlinePlayer );
211
- }
212
- adventurePlayer .sendMessage (new TextUtil (LuckPrefix .getInstance ().getPrefix () + "Reloaded configurations." ).miniMessage ());
213
- return true ;
60
+ return ReloadConfigs .execute (adventurePlayer );
214
61
}
215
62
}
216
63
return false ;
0 commit comments