Skip to content

Commit

Permalink
Merge pull request #394 from Mindgamesnl/feature/one-click-fixes
Browse files Browse the repository at this point in the history
[feature] Automatically help some users setup the plugin with offlinemode
  • Loading branch information
Mindgamesnl authored Feb 8, 2024
2 parents 48a7029 + 0515e2d commit 2d0e6b4
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plugin/src/main/bash/data.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BUILD_NUM="1132"
BUILD_NUM="1132"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,9 +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("RED") + " - Install the plugin on your proxy, if you have one.");
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.");
PromptProxyError.sendTo(sender);
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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 <key> <value>");
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);
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 <key> <value>");
}
}
}

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.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.craftmend.openaudiomc.api.clients.Client;
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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/resources/data.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BUILD_NUM="1132"
BUILD_NUM="1132"
3 changes: 1 addition & 2 deletions plugin/src/main/resources/openaudiomc-build.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
BUILD_VERSION="1132"
BUILD_COMMIT="e0842006cab8285737dfa84b3a4eeeab0e4e7e13"
BUILD_AUTHOR="Mats"
BUILD_COMMIT="e0842006cab8285737dfa84b3a4eeeab0e4e7e13"

0 comments on commit 2d0e6b4

Please sign in to comment.