From a40a1e5f0cd9d451cbc310dd175e8648bdd69f7e Mon Sep 17 00:00:00 2001 From: Mats Date: Wed, 7 Feb 2024 22:22:20 +0100 Subject: [PATCH 1/3] Automatically help some users setup the plugin with offlinemode, or during support --- .../generic/commands/CommandService.java | 3 +- .../commands/subcommands/LinkSubCommand.java | 7 +++ .../commands/subcommands/SetKvSubCommand.java | 61 +++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/CommandService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/CommandService.java index e9ad72184..ea7936479 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/CommandService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/CommandService.java @@ -52,7 +52,8 @@ public CommandService() { new ClientsSubCommand(), new StopSubCommand(), new PlaySubCommand(), - new PreloadSubCommand() + new PreloadSubCommand(), + new SetKvSubCommand() ); // add accept sub command if the player is new diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/LinkSubCommand.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/LinkSubCommand.java index e4d6f53d9..37b85a2d1 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/LinkSubCommand.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/LinkSubCommand.java @@ -24,8 +24,15 @@ public LinkSubCommand() { public void onExecute(User sender, String[] args) { if (OpenAudioMc.getInstance().getInvoker().isNodeServer()) { message(sender, Platform.makeColor("RED") + "WARNING! This OpenAudioMc can't accept links, because it's running in node mode."); + message(sender, Platform.makeColor("Yellow") + "If you run a proxy (Bunguard, Velocity, Waterfall, etc), then:"); message(sender, Platform.makeColor("RED") + " - Install the plugin on your proxy, if you have one."); + message(sender, Platform.makeColor("YELLOW") + "Or, if you don't run one or don't know what this means:"); message(sender, Platform.makeColor("RED") + " - Enable " + Platform.makeColor("WHITE") + "force-offline-mode" + Platform.makeColor("RED") + " in the config.yml if your host doesn't support proxies."); + sender.sendClickableCommandMessage( + Platform.makeColor("RED") + " - Or click here to do it automatically, but you need to restart your server after doing this.", + "Automatically enable force-offline-mode", + "oa config setkv SETTINGS_FORCE_OFFLINE_MODE true" + ); return; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java new file mode 100644 index 000000000..66c60c5a0 --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java @@ -0,0 +1,61 @@ +package com.craftmend.openaudiomc.generic.commands.subcommands; + +import com.craftmend.openaudiomc.OpenAudioMc; +import com.craftmend.openaudiomc.generic.commands.interfaces.SubCommand; +import com.craftmend.openaudiomc.generic.storage.enums.StorageKey; +import com.craftmend.openaudiomc.generic.user.User; + +public class SetKvSubCommand extends SubCommand { + + private static final StorageKey[] allowedKeys = new StorageKey[] { + StorageKey.SETTINGS_FORCE_OFFLINE_MODE, + StorageKey.SETTINGS_REGIONS_SYNC, + StorageKey.SETTINGS_SPEAKER_SYNC, + StorageKey.SETTINGS_HYDRATE_REGIONS_ON_BOOT, + StorageKey.SETTINGS_VOICE_FILTERS_GAMEMODE, + StorageKey.SETTINGS_VOICE_FILTERS_TEAM + }; + + public SetKvSubCommand() { + super("setkv"); + + // This is a 'hidden' utility command which allows some specific config values to be changed through a command + // which is used by some error messages to help server users configure their server. + // It scares me how many support tickets we get about people not understanding configs, + // or reading an error message for that matter, and providing them with a one-click solution + // to the problem is a great way to improve the user experience. + // values may only be booleans, so we don't need to add a value type argument + + // hide it from the help command, as it's not really a feature or something you should use + this.listed = false; + } + + @Override + public void onExecute(User sender, String[] args) { + if (args.length != 2) { + message(sender, "Invalid arguments. Usage: /openaudio setkv "); + return; + } + + String key = args[0].toUpperCase(); + String value = args[1].toLowerCase(); + + boolean found = false; + for (StorageKey storageKey : allowedKeys) { + if (storageKey.name().equals(key)) { + found = true; + if (value.equals("true") || value.equals("false")) { + // set the value + OpenAudioMc.getInstance().getInvoker().getConfigurationProvider().setBoolean(storageKey, Boolean.parseBoolean(value)); + message(sender, "Set " + key + " to " + value); + } else { + message(sender, "Invalid value. Usage: /openaudio setkv "); + } + } + } + + if (!found) { + message(sender, "Invalid key. This command can only be used to set some specific keys as part of simple problem solving or support."); + } + } +} From 4d66d124894730a6b5daea5dd03de6d4b3ce0f4b Mon Sep 17 00:00:00 2001 From: Mats Date: Wed, 7 Feb 2024 22:25:04 +0100 Subject: [PATCH 2/3] Add restart message --- .../generic/commands/subcommands/SetKvSubCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java index 66c60c5a0..01741f6a6 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java @@ -48,6 +48,7 @@ public void onExecute(User sender, String[] args) { // set the value OpenAudioMc.getInstance().getInvoker().getConfigurationProvider().setBoolean(storageKey, Boolean.parseBoolean(value)); message(sender, "Set " + key + " to " + value); + message(sender, "Please restart your server to apply this change."); } else { message(sender, "Invalid value. Usage: /openaudio setkv "); } From 275d7801c5b81ac21540559527a67ca6d720f945 Mon Sep 17 00:00:00 2001 From: Mats Date: Thu, 8 Feb 2024 19:28:20 +0100 Subject: [PATCH 3/3] Fixes, and also include the /audio command --- plugin/src/main/bash/data.bin | 2 +- .../commands/helpers/PromptProxyError.java | 22 +++++++++++++++++++ .../commands/subcommands/LinkSubCommand.java | 13 ++--------- .../commands/subcommands/SetKvSubCommand.java | 2 ++ .../commands/command/SpigotAudioCommand.java | 4 ++-- plugin/src/main/resources/data.bin | 2 +- .../resources/openaudiomc-build.properties | 4 ++-- 7 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/helpers/PromptProxyError.java diff --git a/plugin/src/main/bash/data.bin b/plugin/src/main/bash/data.bin index 240378200..70b80529e 100755 --- a/plugin/src/main/bash/data.bin +++ b/plugin/src/main/bash/data.bin @@ -1 +1 @@ -BUILD_NUM="1118" +BUILD_NUM="1125" diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/helpers/PromptProxyError.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/helpers/PromptProxyError.java new file mode 100644 index 000000000..01739fdba --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/helpers/PromptProxyError.java @@ -0,0 +1,22 @@ +package com.craftmend.openaudiomc.generic.commands.helpers; + +import com.craftmend.openaudiomc.generic.platform.OaColor; +import com.craftmend.openaudiomc.generic.platform.Platform; +import com.craftmend.openaudiomc.generic.user.User; + +public class PromptProxyError { + + public static void sendTo(User sender) { + sender.sendMessage(OaColor.RED + "WARNING! This OpenAudioMc can't accept links, because it's running in node mode."); + sender.sendMessage(OaColor.YELLOW + "If you run a proxy (Bunguard, Velocity, Waterfall, etc), then:"); + sender.sendMessage(OaColor.GRAY + " - Install the plugin on your proxy, if you have one."); + sender.sendMessage(OaColor.YELLOW + "Or, if you don't run one or don't know what this means:"); + sender.sendMessage(OaColor.GRAY + " - Enable " + Platform.makeColor("WHITE") + "force-offline-mode" + Platform.makeColor("RED") + " in the config.yml if your host doesn't support proxies."); + sender.sendClickableCommandMessage( + Platform.makeColor("RED") + " - Or click here to do it automatically, but you need to restart your server after doing this.", + "Automatically enable force-offline-mode", + "oa setkv SETTINGS_FORCE_OFFLINE_MODE true" + ); + } + +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/LinkSubCommand.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/LinkSubCommand.java index 37b85a2d1..f00eaa14f 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/LinkSubCommand.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/LinkSubCommand.java @@ -1,11 +1,11 @@ package com.craftmend.openaudiomc.generic.commands.subcommands; import com.craftmend.openaudiomc.OpenAudioMc; +import com.craftmend.openaudiomc.generic.commands.helpers.PromptProxyError; import com.craftmend.openaudiomc.generic.commands.interfaces.SubCommand; import com.craftmend.openaudiomc.generic.commands.objects.Argument; import com.craftmend.openaudiomc.generic.networking.interfaces.NetworkingService; import com.craftmend.openaudiomc.generic.platform.OaColor; -import com.craftmend.openaudiomc.generic.platform.Platform; import com.craftmend.openaudiomc.generic.rest.RestRequest; import com.craftmend.openaudiomc.generic.rest.routes.Endpoint; import com.craftmend.openaudiomc.generic.rest.types.ClaimCodeResponse; @@ -23,16 +23,7 @@ public LinkSubCommand() { @Override public void onExecute(User sender, String[] args) { if (OpenAudioMc.getInstance().getInvoker().isNodeServer()) { - message(sender, Platform.makeColor("RED") + "WARNING! This OpenAudioMc can't accept links, because it's running in node mode."); - message(sender, Platform.makeColor("Yellow") + "If you run a proxy (Bunguard, Velocity, Waterfall, etc), then:"); - message(sender, Platform.makeColor("RED") + " - Install the plugin on your proxy, if you have one."); - message(sender, Platform.makeColor("YELLOW") + "Or, if you don't run one or don't know what this means:"); - message(sender, Platform.makeColor("RED") + " - Enable " + Platform.makeColor("WHITE") + "force-offline-mode" + Platform.makeColor("RED") + " in the config.yml if your host doesn't support proxies."); - sender.sendClickableCommandMessage( - Platform.makeColor("RED") + " - Or click here to do it automatically, but you need to restart your server after doing this.", - "Automatically enable force-offline-mode", - "oa config setkv SETTINGS_FORCE_OFFLINE_MODE true" - ); + PromptProxyError.sendTo(sender); return; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java index 01741f6a6..4ef7df0a4 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/SetKvSubCommand.java @@ -49,6 +49,8 @@ public void onExecute(User sender, String[] args) { OpenAudioMc.getInstance().getInvoker().getConfigurationProvider().setBoolean(storageKey, Boolean.parseBoolean(value)); message(sender, "Set " + key + " to " + value); message(sender, "Please restart your server to apply this change."); + // flush the change + OpenAudioMc.getInstance().getInvoker().getConfigurationProvider().saveAll(true); } else { message(sender, "Invalid value. Usage: /openaudio setkv "); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/command/SpigotAudioCommand.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/command/SpigotAudioCommand.java index 4686d8c04..5f64b3a76 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/command/SpigotAudioCommand.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/command/SpigotAudioCommand.java @@ -6,6 +6,7 @@ import com.craftmend.openaudiomc.api.interfaces.AudioApi; import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; import com.craftmend.openaudiomc.generic.commands.helpers.CommandMiddewareExecutor; +import com.craftmend.openaudiomc.generic.commands.helpers.PromptProxyError; import com.craftmend.openaudiomc.generic.commands.interfaces.CommandMiddleware; import com.craftmend.openaudiomc.generic.commands.middleware.CatchCrashMiddleware; import com.craftmend.openaudiomc.generic.commands.middleware.CatchLegalBindingMiddleware; @@ -70,8 +71,7 @@ public boolean onCommand(CommandSender commandSender, Command command, String s, OpenAudioMc.resolveDependency(UserHooks.class).sendPacket(user, new ClientRunAudioPacket(user.getUniqueId(), enteredToken)); } else { // its on a sub-server without an activated proxy, so completely ignore it - commandSender.sendMessage(MagicValue.COMMAND_PREFIX.get(String.class) + - state.getDescription()); + PromptProxyError.sendTo(sua); } return true; } diff --git a/plugin/src/main/resources/data.bin b/plugin/src/main/resources/data.bin index 240378200..70b80529e 100755 --- a/plugin/src/main/resources/data.bin +++ b/plugin/src/main/resources/data.bin @@ -1 +1 @@ -BUILD_NUM="1118" +BUILD_NUM="1125" diff --git a/plugin/src/main/resources/openaudiomc-build.properties b/plugin/src/main/resources/openaudiomc-build.properties index ebb66bab8..054e5ff92 100644 --- a/plugin/src/main/resources/openaudiomc-build.properties +++ b/plugin/src/main/resources/openaudiomc-build.properties @@ -1,3 +1,3 @@ -BUILD_VERSION="1118" -BUILD_COMMIT="196427046234ca343f2f9f3db23c8311909e9609" +BUILD_VERSION="1125" +BUILD_COMMIT="4d66d124894730a6b5daea5dd03de6d4b3ce0f4b" BUILD_AUTHOR="Mats"