Skip to content

Commit ee7573d

Browse files
authored
Merge pull request #164 from HelpChat/issue/133
Upgraded the `/dm list` command
2 parents 813a1cb + cf907d4 commit ee7573d

38 files changed

+1902
-1771
lines changed

src/main/java/com/extendedclip/deluxemenus/DeluxeMenus.java

Lines changed: 221 additions & 241 deletions
Large diffs are not rendered by default.

src/main/java/com/extendedclip/deluxemenus/action/ClickActionTask.java

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ public void run() {
7575

7676
switch (actionType) {
7777
case META:
78-
if (!VersionHelper.IS_PDC_VERSION || DeluxeMenus.getInstance().getPersistentMetaHandler() == null) {
79-
DeluxeMenus.debug(DebugLevel.HIGHEST, Level.INFO, "Meta action not supported on this server version.");
78+
if (!VersionHelper.IS_PDC_VERSION || plugin.getPersistentMetaHandler() == null) {
79+
plugin.debug(DebugLevel.HIGHEST, Level.INFO, "Meta action not supported on this server version.");
8080
break;
8181
}
8282
try {
83-
final boolean result = DeluxeMenus.getInstance().getPersistentMetaHandler().setMeta(player, executable);
83+
final boolean result = plugin.getPersistentMetaHandler().setMeta(player, executable);
8484
if (!result) {
85-
DeluxeMenus.debug(DebugLevel.HIGHEST, Level.INFO, "Invalid meta action! Make sure you have the right syntax.");
85+
plugin.debug(DebugLevel.HIGHEST, Level.INFO, "Invalid meta action! Make sure you have the right syntax.");
8686
break;
8787
}
8888
} catch (final NumberFormatException exception) {
89-
DeluxeMenus.debug(DebugLevel.HIGHEST, Level.INFO, "Invalid integer value for meta action!");
89+
plugin.debug(DebugLevel.HIGHEST, Level.INFO, "Invalid integer value for meta action!");
9090
}
9191
break;
9292

@@ -111,11 +111,11 @@ public void run() {
111111
break;
112112

113113
case MINI_MESSAGE:
114-
plugin.adventure().player(player).sendMessage(MiniMessage.miniMessage().deserialize(executable));
114+
plugin.audiences().player(player).sendMessage(MiniMessage.miniMessage().deserialize(executable));
115115
break;
116116

117117
case MINI_BROADCAST:
118-
plugin.adventure().all().sendMessage(MiniMessage.miniMessage().deserialize(executable));
118+
plugin.audiences().all().sendMessage(MiniMessage.miniMessage().deserialize(executable));
119119
break;
120120

121121
case MESSAGE:
@@ -127,7 +127,7 @@ public void run() {
127127
break;
128128

129129
case CLOSE:
130-
Menu.closeMenu(player, true, true);
130+
Menu.closeMenu(plugin, player, true, true);
131131
break;
132132

133133
case OPEN_GUI_MENU:
@@ -136,7 +136,7 @@ public void run() {
136136
final String[] executableParts = temporaryExecutable.split(" ", 2);
137137

138138
if (executableParts.length == 0) {
139-
DeluxeMenus.debug(DebugLevel.HIGHEST, Level.WARNING, "Could not find and open menu " + executable);
139+
plugin.debug(DebugLevel.HIGHEST, Level.WARNING, "Could not find and open menu " + executable);
140140
break;
141141
}
142142

@@ -145,7 +145,7 @@ public void run() {
145145
final Optional<Menu> optionalMenuToOpen = Menu.getMenuByName(menuName);
146146

147147
if (optionalMenuToOpen.isEmpty()) {
148-
DeluxeMenus.debug(DebugLevel.HIGHEST, Level.WARNING, "Could not find and open menu " + executable);
148+
plugin.debug(DebugLevel.HIGHEST, Level.WARNING, "Could not find and open menu " + executable);
149149
break;
150150
}
151151

@@ -160,7 +160,7 @@ public void run() {
160160

161161
if (menuArgumentNames.isEmpty()) {
162162
if (passedArgumentValues != null && passedArgumentValues.length > 0) {
163-
DeluxeMenus.debug(
163+
plugin.debug(
164164
DebugLevel.HIGHEST,
165165
Level.WARNING,
166166
"Arguments were given for menu " + menuName + " in action [openguimenu] or [openmenu], but the menu does not support arguments!"
@@ -188,7 +188,7 @@ public void run() {
188188
}
189189

190190
if (passedArgumentValues.length < menuArgumentNames.size()) {
191-
DeluxeMenus.debug(
191+
plugin.debug(
192192
DebugLevel.HIGHEST,
193193
Level.WARNING,
194194
"Not enough arguments given for menu " + menuName + " when opening using the [openguimenu] or [openmenu] action!"
@@ -208,7 +208,7 @@ public void run() {
208208

209209
if (passedArgumentValues.length <= index) {
210210
// This should never be the case!
211-
DeluxeMenus.debug(
211+
plugin.debug(
212212
DebugLevel.HIGHEST,
213213
Level.WARNING,
214214
"Not enough arguments given for menu " + menuName + " when opening using the [openguimenu] or [openmenu] action!"
@@ -235,21 +235,21 @@ public void run() {
235235
break;
236236

237237
case CONNECT:
238-
DeluxeMenus.getInstance().connect(player, executable);
238+
plugin.connect(player, executable);
239239
break;
240240

241241
case JSON_MESSAGE:
242-
AdventureUtils.sendJson(player, executable);
242+
AdventureUtils.sendJson(plugin, player, executable);
243243
break;
244244

245245
case JSON_BROADCAST:
246246
case BROADCAST_JSON:
247-
plugin.adventure().all().sendMessage(AdventureUtils.fromJson(executable));
247+
plugin.audiences().all().sendMessage(AdventureUtils.fromJson(executable));
248248
break;
249249

250250
case REFRESH:
251251
if (holder.isEmpty()) {
252-
DeluxeMenus.debug(
252+
plugin.debug(
253253
DebugLevel.MEDIUM,
254254
Level.WARNING,
255255
player.getName() + " does not have menu open! Nothing to refresh!"
@@ -261,15 +261,15 @@ public void run() {
261261
break;
262262

263263
case TAKE_MONEY:
264-
if (DeluxeMenus.getInstance().getVault() == null || !DeluxeMenus.getInstance().getVault().hooked()) {
265-
DeluxeMenus.debug(DebugLevel.HIGHEST, Level.WARNING, "Vault not hooked! Cannot take money!");
264+
if (plugin.getVault() == null || !plugin.getVault().hooked()) {
265+
plugin.debug(DebugLevel.HIGHEST, Level.WARNING, "Vault not hooked! Cannot take money!");
266266
break;
267267
}
268268

269269
try {
270-
DeluxeMenus.getInstance().getVault().takeMoney(player, Double.parseDouble(executable));
270+
plugin.getVault().takeMoney(player, Double.parseDouble(executable));
271271
} catch (final NumberFormatException exception) {
272-
DeluxeMenus.debug(
272+
plugin.debug(
273273
DebugLevel.HIGHEST,
274274
Level.WARNING,
275275
"Amount for take money action: " + executable + ", is not a valid number!"
@@ -278,15 +278,15 @@ public void run() {
278278
break;
279279

280280
case GIVE_MONEY:
281-
if (DeluxeMenus.getInstance().getVault() == null || !DeluxeMenus.getInstance().getVault().hooked()) {
282-
DeluxeMenus.debug(DebugLevel.HIGHEST, Level.WARNING, "Vault not hooked! Cannot give money!");
281+
if (plugin.getVault() == null || !plugin.getVault().hooked()) {
282+
plugin.debug(DebugLevel.HIGHEST, Level.WARNING, "Vault not hooked! Cannot give money!");
283283
break;
284284
}
285285

286286
try {
287-
DeluxeMenus.getInstance().getVault().giveMoney(player, Double.parseDouble(executable));
287+
plugin.getVault().giveMoney(player, Double.parseDouble(executable));
288288
} catch (final NumberFormatException exception) {
289-
DeluxeMenus.debug(
289+
plugin.debug(
290290
DebugLevel.HIGHEST,
291291
Level.WARNING,
292292
"Amount for give money action: " + executable + ", is not a valid number!"
@@ -311,15 +311,15 @@ public void run() {
311311

312312
} catch (final NumberFormatException exception) {
313313
if (actionType == ActionType.TAKE_EXP) {
314-
DeluxeMenus.debug(
314+
plugin.debug(
315315
DebugLevel.HIGHEST,
316316
Level.WARNING,
317317
"Amount for take exp action: " + executable + ", is not a valid number!"
318318
);
319319
break;
320320
}
321321

322-
DeluxeMenus.debug(
322+
plugin.debug(
323323
DebugLevel.HIGHEST,
324324
Level.WARNING,
325325
"Amount for give exp action: " + executable + ", is not a valid number!"
@@ -328,27 +328,27 @@ public void run() {
328328
}
329329

330330
case GIVE_PERM:
331-
if (DeluxeMenus.getInstance().getVault() == null || !DeluxeMenus.getInstance().getVault().hooked()) {
332-
DeluxeMenus.debug(
331+
if (plugin.getVault() == null || !plugin.getVault().hooked()) {
332+
plugin.debug(
333333
DebugLevel.HIGHEST,
334334
Level.WARNING,
335335
"Vault not hooked! Cannot give permission: " + executable + "!");
336336
break;
337337
}
338338

339-
DeluxeMenus.getInstance().getVault().givePermission(player, executable);
339+
plugin.getVault().givePermission(player, executable);
340340
break;
341341

342342
case TAKE_PERM:
343-
if (DeluxeMenus.getInstance().getVault() == null || !DeluxeMenus.getInstance().getVault().hooked()) {
344-
DeluxeMenus.debug(
343+
if (plugin.getVault() == null || !plugin.getVault().hooked()) {
344+
plugin.debug(
345345
DebugLevel.HIGHEST,
346346
Level.WARNING,
347347
"Vault not hooked! Cannot take permission: " + executable + "!");
348348
break;
349349
}
350350

351-
DeluxeMenus.getInstance().getVault().takePermission(player, executable);
351+
plugin.getVault().takePermission(player, executable);
352352
break;
353353

354354
case BROADCAST_SOUND:
@@ -362,7 +362,7 @@ public void run() {
362362
try {
363363
sound = Sound.valueOf(executable.toUpperCase());
364364
} catch (final IllegalArgumentException exception) {
365-
DeluxeMenus.printStacktrace(
365+
plugin.printStacktrace(
366366
"Sound name given for sound action: " + executable + ", is not a valid sound!",
367367
exception
368368
);
@@ -374,7 +374,7 @@ public void run() {
374374
try {
375375
sound = Sound.valueOf(parts[0].toUpperCase());
376376
} catch (final IllegalArgumentException exception) {
377-
DeluxeMenus.printStacktrace(
377+
plugin.printStacktrace(
378378
"Sound name given for sound action: " + parts[0] + ", is not a valid sound!",
379379
exception
380380
);
@@ -385,13 +385,13 @@ public void run() {
385385
try {
386386
pitch = Float.parseFloat(parts[2]);
387387
} catch (final NumberFormatException exception) {
388-
DeluxeMenus.debug(
388+
plugin.debug(
389389
DebugLevel.HIGHEST,
390390
Level.WARNING,
391391
"Pitch given for sound action: " + parts[2] + ", is not a valid number!"
392392
);
393393

394-
DeluxeMenus.printStacktrace(
394+
plugin.printStacktrace(
395395
"Pitch given for sound action: " + parts[2] + ", is not a valid number!",
396396
exception
397397
);
@@ -402,13 +402,13 @@ public void run() {
402402
try {
403403
volume = Float.parseFloat(parts[1]);
404404
} catch (final NumberFormatException exception) {
405-
DeluxeMenus.debug(
405+
plugin.debug(
406406
DebugLevel.HIGHEST,
407407
Level.WARNING,
408408
"Volume given for sound action: " + parts[1] + ", is not a valid number!"
409409
);
410410

411-
DeluxeMenus.printStacktrace(
411+
plugin.printStacktrace(
412412
"Volume given for sound action: " + parts[1] + ", is not a valid number!",
413413
exception
414414
);
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.extendedclip.deluxemenus.command;
2+
3+
import com.extendedclip.deluxemenus.DeluxeMenus;
4+
import com.extendedclip.deluxemenus.command.subcommand.DumpCommand;
5+
import com.extendedclip.deluxemenus.command.subcommand.ExecuteCommand;
6+
import com.extendedclip.deluxemenus.command.subcommand.HelpCommand;
7+
import com.extendedclip.deluxemenus.command.subcommand.ListCommand;
8+
import com.extendedclip.deluxemenus.command.subcommand.OpenCommand;
9+
import com.extendedclip.deluxemenus.command.subcommand.ReloadCommand;
10+
import com.extendedclip.deluxemenus.command.subcommand.SubCommand;
11+
import com.extendedclip.deluxemenus.utils.Messages;
12+
import net.kyori.adventure.text.Component;
13+
import net.kyori.adventure.text.TextReplacementConfig;
14+
import net.kyori.adventure.text.format.NamedTextColor;
15+
import org.bukkit.command.Command;
16+
import org.bukkit.command.CommandExecutor;
17+
import org.bukkit.command.CommandSender;
18+
import org.bukkit.command.PluginCommand;
19+
import org.jetbrains.annotations.NotNull;
20+
21+
import java.util.Arrays;
22+
import java.util.HashMap;
23+
import java.util.List;
24+
import java.util.Map;
25+
26+
import static net.kyori.adventure.text.Component.text;
27+
28+
public class DeluxeMenusCommand implements CommandExecutor {
29+
30+
private static final TextReplacementConfig.Builder VERSION_REPLACER_BUILDER = TextReplacementConfig.builder().matchLiteral("<version>");
31+
private static final TextReplacementConfig.Builder AUTHORS_REPLACER_BUILDER = TextReplacementConfig.builder().matchLiteral("<authors>");
32+
33+
private final DeluxeMenus plugin;
34+
private final Map<String, SubCommand> subCommands = new HashMap<>();
35+
36+
public DeluxeMenusCommand(final @NotNull DeluxeMenus plugin) {
37+
this.plugin = plugin;
38+
}
39+
40+
public boolean register() {
41+
final PluginCommand command = this.plugin.getCommand("deluxemenus");
42+
if (command == null) {
43+
return false;
44+
}
45+
46+
command.setExecutor(this);
47+
registerSubCommands();
48+
return true;
49+
}
50+
51+
@Override
52+
public boolean onCommand(
53+
final @NotNull CommandSender sender,
54+
final @NotNull Command command,
55+
final @NotNull String label,
56+
final @NotNull String[] args
57+
) {
58+
final List<String> arguments = Arrays.asList(args);
59+
60+
if (arguments.isEmpty()) {
61+
plugin.sms(sender, Messages.PLUGIN_VERSION.message().replaceText(VERSION_REPLACER_BUILDER.replacement(plugin.getDescription().getVersion()).build()).replaceText(AUTHORS_REPLACER_BUILDER.replacement(plugin.getDescription().getAuthors().stream().map(author -> text(author, NamedTextColor.WHITE)).collect(Component.toComponent(text(", ", NamedTextColor.GRAY)))).build()));
62+
return true;
63+
}
64+
65+
final SubCommand subCommand = subCommands.get(arguments.get(0).toLowerCase());
66+
67+
if (subCommand != null) {
68+
subCommand.execute(sender, arguments.subList(1, arguments.size()));
69+
return true;
70+
}
71+
72+
plugin.sms(sender, Messages.WRONG_USAGE);
73+
return true;
74+
}
75+
76+
private void registerSubCommands() {
77+
subCommands.put("dump", new DumpCommand(plugin));
78+
subCommands.put("execute", new ExecuteCommand(plugin));
79+
subCommands.put("help", new HelpCommand(plugin));
80+
subCommands.put("list", new ListCommand(plugin));
81+
subCommands.put("open", new OpenCommand(plugin));
82+
subCommands.put("reload", new ReloadCommand(plugin));
83+
}
84+
}

0 commit comments

Comments
 (0)