Skip to content

Commit

Permalink
Merge pull request #164 from HelpChat/issue/133
Browse files Browse the repository at this point in the history
Upgraded the `/dm list` command
  • Loading branch information
BlitzOffline authored Jan 2, 2025
2 parents 813a1cb + cf907d4 commit ee7573d
Show file tree
Hide file tree
Showing 38 changed files with 1,902 additions and 1,771 deletions.
462 changes: 221 additions & 241 deletions src/main/java/com/extendedclip/deluxemenus/DeluxeMenus.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ public void run() {

switch (actionType) {
case META:
if (!VersionHelper.IS_PDC_VERSION || DeluxeMenus.getInstance().getPersistentMetaHandler() == null) {
DeluxeMenus.debug(DebugLevel.HIGHEST, Level.INFO, "Meta action not supported on this server version.");
if (!VersionHelper.IS_PDC_VERSION || plugin.getPersistentMetaHandler() == null) {
plugin.debug(DebugLevel.HIGHEST, Level.INFO, "Meta action not supported on this server version.");
break;
}
try {
final boolean result = DeluxeMenus.getInstance().getPersistentMetaHandler().setMeta(player, executable);
final boolean result = plugin.getPersistentMetaHandler().setMeta(player, executable);
if (!result) {
DeluxeMenus.debug(DebugLevel.HIGHEST, Level.INFO, "Invalid meta action! Make sure you have the right syntax.");
plugin.debug(DebugLevel.HIGHEST, Level.INFO, "Invalid meta action! Make sure you have the right syntax.");
break;
}
} catch (final NumberFormatException exception) {
DeluxeMenus.debug(DebugLevel.HIGHEST, Level.INFO, "Invalid integer value for meta action!");
plugin.debug(DebugLevel.HIGHEST, Level.INFO, "Invalid integer value for meta action!");
}
break;

Expand All @@ -111,11 +111,11 @@ public void run() {
break;

case MINI_MESSAGE:
plugin.adventure().player(player).sendMessage(MiniMessage.miniMessage().deserialize(executable));
plugin.audiences().player(player).sendMessage(MiniMessage.miniMessage().deserialize(executable));
break;

case MINI_BROADCAST:
plugin.adventure().all().sendMessage(MiniMessage.miniMessage().deserialize(executable));
plugin.audiences().all().sendMessage(MiniMessage.miniMessage().deserialize(executable));
break;

case MESSAGE:
Expand All @@ -127,7 +127,7 @@ public void run() {
break;

case CLOSE:
Menu.closeMenu(player, true, true);
Menu.closeMenu(plugin, player, true, true);
break;

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

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

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

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

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

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

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

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

case CONNECT:
DeluxeMenus.getInstance().connect(player, executable);
plugin.connect(player, executable);
break;

case JSON_MESSAGE:
AdventureUtils.sendJson(player, executable);
AdventureUtils.sendJson(plugin, player, executable);
break;

case JSON_BROADCAST:
case BROADCAST_JSON:
plugin.adventure().all().sendMessage(AdventureUtils.fromJson(executable));
plugin.audiences().all().sendMessage(AdventureUtils.fromJson(executable));
break;

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

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

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

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

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

} catch (final NumberFormatException exception) {
if (actionType == ActionType.TAKE_EXP) {
DeluxeMenus.debug(
plugin.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Amount for take exp action: " + executable + ", is not a valid number!"
);
break;
}

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

case GIVE_PERM:
if (DeluxeMenus.getInstance().getVault() == null || !DeluxeMenus.getInstance().getVault().hooked()) {
DeluxeMenus.debug(
if (plugin.getVault() == null || !plugin.getVault().hooked()) {
plugin.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Vault not hooked! Cannot give permission: " + executable + "!");
break;
}

DeluxeMenus.getInstance().getVault().givePermission(player, executable);
plugin.getVault().givePermission(player, executable);
break;

case TAKE_PERM:
if (DeluxeMenus.getInstance().getVault() == null || !DeluxeMenus.getInstance().getVault().hooked()) {
DeluxeMenus.debug(
if (plugin.getVault() == null || !plugin.getVault().hooked()) {
plugin.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Vault not hooked! Cannot take permission: " + executable + "!");
break;
}

DeluxeMenus.getInstance().getVault().takePermission(player, executable);
plugin.getVault().takePermission(player, executable);
break;

case BROADCAST_SOUND:
Expand All @@ -362,7 +362,7 @@ public void run() {
try {
sound = Sound.valueOf(executable.toUpperCase());
} catch (final IllegalArgumentException exception) {
DeluxeMenus.printStacktrace(
plugin.printStacktrace(
"Sound name given for sound action: " + executable + ", is not a valid sound!",
exception
);
Expand All @@ -374,7 +374,7 @@ public void run() {
try {
sound = Sound.valueOf(parts[0].toUpperCase());
} catch (final IllegalArgumentException exception) {
DeluxeMenus.printStacktrace(
plugin.printStacktrace(
"Sound name given for sound action: " + parts[0] + ", is not a valid sound!",
exception
);
Expand All @@ -385,13 +385,13 @@ public void run() {
try {
pitch = Float.parseFloat(parts[2]);
} catch (final NumberFormatException exception) {
DeluxeMenus.debug(
plugin.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Pitch given for sound action: " + parts[2] + ", is not a valid number!"
);

DeluxeMenus.printStacktrace(
plugin.printStacktrace(
"Pitch given for sound action: " + parts[2] + ", is not a valid number!",
exception
);
Expand All @@ -402,13 +402,13 @@ public void run() {
try {
volume = Float.parseFloat(parts[1]);
} catch (final NumberFormatException exception) {
DeluxeMenus.debug(
plugin.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Volume given for sound action: " + parts[1] + ", is not a valid number!"
);

DeluxeMenus.printStacktrace(
plugin.printStacktrace(
"Volume given for sound action: " + parts[1] + ", is not a valid number!",
exception
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.extendedclip.deluxemenus.command;

import com.extendedclip.deluxemenus.DeluxeMenus;
import com.extendedclip.deluxemenus.command.subcommand.DumpCommand;
import com.extendedclip.deluxemenus.command.subcommand.ExecuteCommand;
import com.extendedclip.deluxemenus.command.subcommand.HelpCommand;
import com.extendedclip.deluxemenus.command.subcommand.ListCommand;
import com.extendedclip.deluxemenus.command.subcommand.OpenCommand;
import com.extendedclip.deluxemenus.command.subcommand.ReloadCommand;
import com.extendedclip.deluxemenus.command.subcommand.SubCommand;
import com.extendedclip.deluxemenus.utils.Messages;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static net.kyori.adventure.text.Component.text;

public class DeluxeMenusCommand implements CommandExecutor {

private static final TextReplacementConfig.Builder VERSION_REPLACER_BUILDER = TextReplacementConfig.builder().matchLiteral("<version>");
private static final TextReplacementConfig.Builder AUTHORS_REPLACER_BUILDER = TextReplacementConfig.builder().matchLiteral("<authors>");

private final DeluxeMenus plugin;
private final Map<String, SubCommand> subCommands = new HashMap<>();

public DeluxeMenusCommand(final @NotNull DeluxeMenus plugin) {
this.plugin = plugin;
}

public boolean register() {
final PluginCommand command = this.plugin.getCommand("deluxemenus");
if (command == null) {
return false;
}

command.setExecutor(this);
registerSubCommands();
return true;
}

@Override
public boolean onCommand(
final @NotNull CommandSender sender,
final @NotNull Command command,
final @NotNull String label,
final @NotNull String[] args
) {
final List<String> arguments = Arrays.asList(args);

if (arguments.isEmpty()) {
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()));
return true;
}

final SubCommand subCommand = subCommands.get(arguments.get(0).toLowerCase());

if (subCommand != null) {
subCommand.execute(sender, arguments.subList(1, arguments.size()));
return true;
}

plugin.sms(sender, Messages.WRONG_USAGE);
return true;
}

private void registerSubCommands() {
subCommands.put("dump", new DumpCommand(plugin));
subCommands.put("execute", new ExecuteCommand(plugin));
subCommands.put("help", new HelpCommand(plugin));
subCommands.put("list", new ListCommand(plugin));
subCommands.put("open", new OpenCommand(plugin));
subCommands.put("reload", new ReloadCommand(plugin));
}
}
Loading

0 comments on commit ee7573d

Please sign in to comment.