Skip to content

Commit

Permalink
Implement new config options for future features
Browse files Browse the repository at this point in the history
  • Loading branch information
benwoo1110 committed Jan 12, 2025
1 parent 6d08d15 commit 8793aa5
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 24 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/mvplugins/multiverse/core/api/MVConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.vavr.control.Try;
import org.jvnet.hk2.annotations.Contract;

import org.mvplugins.multiverse.core.commandtools.queue.ConfirmMode;
import org.mvplugins.multiverse.core.configuration.handle.StringPropertyHandle;
import org.mvplugins.multiverse.core.placeholders.MultiverseCorePlaceholders;

Expand Down Expand Up @@ -73,6 +74,14 @@ public interface MVConfig {
*/
boolean isAutoPurgeEntities();

void setUseFinerTeleportPermissions(boolean useFinerTeleportPermissions);

boolean getUseFinerTeleportPermissions();

void setConcurrentTeleportLimit(int concurrentTeleportLimit);

int getConcurrentTeleportLimit();

/**
* Sets teleportIntercept.
* @param teleportIntercept The new value.
Expand Down Expand Up @@ -233,6 +242,14 @@ public interface MVConfig {
*/
boolean getPerPlayerLocale();

void setConfirmMode(ConfirmMode confirmMode);

ConfirmMode getConfirmMode();

void setUseConfirmOtp(boolean useConfirmOtp);

boolean getUseConfirmOtp();

/**
* Sets globalDebug.
* @param globalDebug The new value.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.mvplugins.multiverse.core.commandtools.queue;

public enum ConfirmMode {
ENABLE,
PLAYER_ONLY,
DISABLE_COMMAND_BLOCKS,
DISABLE_CONSOLE,
DISABLE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import java.util.Objects;

import com.dumptruckman.minecraft.util.Logging;
import io.vavr.control.Try;
Expand All @@ -13,12 +12,12 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.PluginManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jvnet.hk2.annotations.Service;

import org.mvplugins.multiverse.core.MultiverseCore;
import org.mvplugins.multiverse.core.api.MVConfig;
import org.mvplugins.multiverse.core.commandtools.MVCommandManager;
import org.mvplugins.multiverse.core.commandtools.queue.ConfirmMode;
import org.mvplugins.multiverse.core.configuration.handle.CommentedYamlConfigHandle;
import org.mvplugins.multiverse.core.configuration.handle.StringPropertyHandle;
import org.mvplugins.multiverse.core.configuration.migration.BooleanMigratorAction;
Expand All @@ -31,7 +30,6 @@
@Service
public class MVCoreConfig implements MVConfig {
public static final String CONFIG_FILENAME = "config.yml";
public static final double CONFIG_VERSION = 5.0;

private final Path configPath;
private final MVCoreConfigNodes configNodes;
Expand Down Expand Up @@ -76,6 +74,10 @@ public class MVCoreConfig implements MVConfig {
.addAction(BooleanMigratorAction.of("misc.show-donation-message"))
.addAction(InvertBoolMigratorAction.of("misc.show-donation-message"))
.build())
.addVersionMigrator(VersionMigrator.builder(5.1)
.addAction(MoveMigratorAction.of("world.teleport-intercept", "teleport.teleport-intercept"))
.addAction(MoveMigratorAction.of("world.resolve-alias-name", "command.resolve-alias-name"))
.build())
.build())
.build();
this.stringPropertyHandle = new StringPropertyHandle(configHandle);
Expand Down Expand Up @@ -153,23 +155,33 @@ public boolean isAutoPurgeEntities() {
}

@Override
public void setTeleportIntercept(boolean teleportIntercept) {
configHandle.set(configNodes.TELEPORT_INTERCEPT, teleportIntercept);
public void setUseFinerTeleportPermissions(boolean useFinerTeleportPermissions) {
configHandle.set(configNodes.USE_FINER_TELEPORT_PERMISSIONS, useFinerTeleportPermissions);
}

@Override
public boolean getTeleportIntercept() {
return configHandle.get(configNodes.TELEPORT_INTERCEPT);
public boolean getUseFinerTeleportPermissions() {
return configHandle.get(configNodes.USE_FINER_TELEPORT_PERMISSIONS);
}

@Override
public void setResolveAliasName(boolean resolveAliasInCommands) {
configHandle.set(configNodes.RESOLVE_ALIAS_NAME, resolveAliasInCommands);
public void setConcurrentTeleportLimit(int concurrentTeleportLimit) {
configHandle.set(configNodes.CONCURRENT_TELEPORT_LIMIT, concurrentTeleportLimit);
}

@Override
public boolean getResolveAliasName() {
return configHandle.get(configNodes.RESOLVE_ALIAS_NAME);
public int getConcurrentTeleportLimit() {
return configHandle.get(configNodes.CONCURRENT_TELEPORT_LIMIT);
}

@Override
public void setTeleportIntercept(boolean teleportIntercept) {
configHandle.set(configNodes.TELEPORT_INTERCEPT, teleportIntercept);
}

@Override
public boolean getTeleportIntercept() {
return configHandle.get(configNodes.TELEPORT_INTERCEPT);
}

@Override
Expand Down Expand Up @@ -282,6 +294,36 @@ public boolean getPerPlayerLocale() {
return configHandle.get(configNodes.PER_PLAYER_LOCALE);
}

@Override
public void setResolveAliasName(boolean resolveAliasInCommands) {
configHandle.set(configNodes.RESOLVE_ALIAS_NAME, resolveAliasInCommands);
}

@Override
public boolean getResolveAliasName() {
return configHandle.get(configNodes.RESOLVE_ALIAS_NAME);
}

@Override
public void setConfirmMode(ConfirmMode confirmMode) {
configHandle.set(configNodes.CONFIRM_MODE, confirmMode);
}

@Override
public ConfirmMode getConfirmMode() {
return configHandle.get(configNodes.CONFIRM_MODE);
}

@Override
public void setUseConfirmOtp(boolean useConfirmOtp) {
configHandle.set(configNodes.USE_CONFIRM_OTP, useConfirmOtp);
}

@Override
public boolean getUseConfirmOtp() {
return configHandle.get(configNodes.USE_CONFIRM_OTP);
}

@Override
public void setGlobalDebug(int globalDebug) {
configHandle.set(configNodes.GLOBAL_DEBUG, globalDebug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.core.commandtools.MVCommandManager;
import org.mvplugins.multiverse.core.commandtools.queue.ConfirmMode;
import org.mvplugins.multiverse.core.configuration.node.ConfigHeaderNode;
import org.mvplugins.multiverse.core.configuration.node.ConfigNode;
import org.mvplugins.multiverse.core.configuration.node.Node;
Expand Down Expand Up @@ -98,22 +99,35 @@ private <N extends Node> N node(N node) {
.name("auto-purge-entities")
.build());

final ConfigNode<Boolean> TELEPORT_INTERCEPT = node(ConfigNode.builder("world.teleport-intercept", Boolean.class)
private final ConfigHeaderNode TELEPORT_HEADER = node(ConfigHeaderNode.builder("teleport")
.comment("")
.comment("If this is set to true, Multiverse will enforce access permissions for all teleportation,")
.comment("including teleportation from other plugins. You should not disable this unless you are facing")
.comment("conflict with another plugin handling teleportation.")
.comment("")
.build());

final ConfigNode<Boolean> USE_FINER_TELEPORT_PERMISSIONS = node(ConfigNode.builder("teleport.use-finer-teleport-permissions", Boolean.class)
.comment("Sets whether Multiverse will use more fine-grained teleport permissions.")
.comment("If enabled, Multiverse will use the `multiverse.teleport.<self|other>.<type>.<target>` permission to determine whether")
.comment("a player can teleport to a world. If disabled, Multiverse will use the `mulitverse.teleport.<self|other>.<type>`")
.comment("permission to determine whether a player can teleport to a world.")
.comment("For example, if `multiverse.teleport.self.w.world2` is set, Multiverse will only allow the player to teleport to the world2")
.defaultValue(true)
.name("teleport-intercept")
.name("use-finer-teleport-permissions")
.build());

final ConfigNode<Boolean> RESOLVE_ALIAS_NAME = node(ConfigNode.builder("world.resolve-alias-name", Boolean.class)
final ConfigNode<Integer> CONCURRENT_TELEPORT_LIMIT = node(ConfigNode.builder("teleport.concurrent-teleport-limit", Integer.class)
.comment("")
.comment("If this is set to true, Multiverse will resolve world based on their alias names for commands and destinations.")
.comment("Normal world names will still be accepted.")
.comment("In the event you have multiple worlds with the same alias name, the first world found will be used.")
.comment("Sets the maximum number of players allowed to be teleported at once with `/mv teleport` command")
.defaultValue(50)
.name("concurrent-teleport-limit")
.build());

final ConfigNode<Boolean> TELEPORT_INTERCEPT = node(ConfigNode.builder("teleport.teleport-intercept", Boolean.class)
.comment("")
.comment("If this is set to true, Multiverse will enforce access permissions for all teleportation,")
.comment("including teleportation from other plugins. You should not disable this unless you are facing")
.comment("conflict with another plugin handling teleportation.")
.defaultValue(true)
.name("resolve-alias-name")
.name("teleport-intercept")
.build());

private final ConfigHeaderNode SPAWN_HEADER = node(ConfigHeaderNode.builder("spawn")
Expand Down Expand Up @@ -225,6 +239,39 @@ private <N extends Node> N node(N node) {
})
.build());

private final ConfigHeaderNode COMMAND_HEADER = node(ConfigHeaderNode.builder("command")
.comment("")
.comment("")
.build());

final ConfigNode<Boolean> RESOLVE_ALIAS_NAME = node(ConfigNode.builder("command.resolve-alias-name", Boolean.class)
.comment("If this is set to true, Multiverse will resolve world based on their alias names for commands and destinations.")
.comment("Normal world names will still be accepted.")
.comment("In the event you have multiple worlds with the same alias name, the first world found will be used.")
.defaultValue(true)
.name("resolve-alias-name")
.build());

final ConfigNode<ConfirmMode> CONFIRM_MODE = node(ConfigNode.builder("command.confirm-mode", ConfirmMode.class)
.comment("")
.comment("This config option defines whether `/mv confirm` is needed before running a DANGEROUS action.")
.comment(" enable: `/mv confirm` is required.")
.comment(" player_only: `/mv confirm` only required when running command as a player.")
.comment(" disable_command_blocks: `/mv confirm` not required for command blocks.")
.comment(" disable_console: `/mv confirm` not required for the console.")
.comment(" disable: `/mv confirm` is not required.")
.defaultValue(ConfirmMode.ENABLE)
.name("confirm-mode")
.build());

final ConfigNode<Boolean> USE_CONFIRM_OTP = node(ConfigNode.builder("command.use-confirm-otp", Boolean.class)
.comment("")
.comment("If this is set to true, `/mv confirm` will include a 3 digit random number that must be entered to confirm the command.")
.comment("For example: `/mv confirm 726`")
.defaultValue(true)
.name("use-confirm-otp")
.build());

private final ConfigHeaderNode MISC_HEADER = node(ConfigHeaderNode.builder("misc")
.comment("")
.comment("")
Expand Down Expand Up @@ -272,7 +319,7 @@ private <N extends Node> N node(N node) {
.comment("")
.comment("This just signifies the version number so we can see what version of config you have.")
.comment("NEVER TOUCH THIS VALUE")
.defaultValue(MVCoreConfig.CONFIG_VERSION)
.defaultValue(0.0)
.name(null)
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public void migrate(ConfigurationSection config) {
if (versionNumber < versionMigrator.getVersion()) {
Logging.info("Migrating config from version %s to %s...", versionNumber, versionMigrator.getVersion());
versionMigrator.migrate(config);
// Set the version number to the latest version number
config.set(versionNode.getPath(), versionMigrator.getVersion());
}
}
// Set the version number to the latest version number
config.set(versionNode.getPath(), versionNode.getDefaultValue());
}

/**
Expand Down

0 comments on commit 8793aa5

Please sign in to comment.