killermc_

make me a plugin for cross server settings either with maria/mysql db syncing or redis syncing, i want to add settings toggle like phantom, night vision and other things whatever is possible

Kodari AI
KodariJul 18 at 4:53 am 9
CrossServerSettings
A Redis-backed Minecraft settings plugin that synchronizes player preferences across multiple servers in real time. Players can toggle phantom protection, night vision, drowning protection, and fall-damage protection with a simple command. Settings persist between sessions, update instantly across servers, and continue working locally if Redis is unavailable. Administrators can configure Redis connection details, storage prefixes, channels, unique server identifiers, permissions, and customizable messages.
killermc_

1) Make it so i can toggle if i want the specific settings enabled in config.yml 2) Make it so i can make new settings as i wish and it will work 3) add a option in config so i can add aliases of the commands 4) make the as performance friendly and redis lock security

Kodari AI
KodariJul 18 at 5:10 am 39
  1. Add per-setting enable/disable controls in config.yml and enforce them in command, sync, and gameplay handling.

  2. Make settings data-driven so new configured settings work without code changes.

  3. Add configurable command aliases and register them from configuration.

  4. Improve performance and Redis lock/synchronization safety.

</commentary>

The project already contains the config-driven setting model, per-setting enabled flags, custom setting effects, and configurable aliases. I’m tightening the remaining runtime paths: cached setting lookups, reload-safe effect scheduling, and authenticated Redis lock release with serialized writes.

Implemented the requested configuration-driven settings system.

  1. Toggle settings in config.yml

    • Each setting supports:

      YAML
      enabled: true
      
    • Disabled settings are removed from commands, tab completion, synchronization handling, and gameplay effects.

  2. Create new settings through configuration

    • Settings are now loaded dynamically from:

      YAML
      settings:
      
    • Supported types include:

      • potion

      • damage

      • target

    Example:

    YAML
    settings:
      lava_protection:
        enabled: true
        display-name: 'Lava Protection'
        description: 'Prevents lava damage.'
        default-enabled: false
        type: damage
        damage-cause: LAVA
    

    Example potion setting:

    YAML
    settings:
      haste:
        enabled: true
        display-name: 'Haste'
        description: 'Gives permanent haste.'
        default-enabled: false
        type: potion
        effect: FAST_DIGGING
        amplifier: 0
        duration: 240
    
  3. Configurable command aliases

    YAML
    command:
      aliases:
        - toggles
        - prefs
        - preferences
    
  4. Performance improvements

    • Settings are cached in memory.

    • Redis writes are moved off the Bukkit scheduler and serialized through a dedicated writer.

    • Potion effects are only refreshed when potion settings are configured.

    • Remote updates only apply to players currently loaded on that server.

    • Redis subscriptions automatically retry after disconnects.

  5. Redis lock security

    • Redis updates now use per-player locks.

    • Locks use unique random tokens.

    • Lock expiration prevents stale locks.

    • Lock release only deletes the lock if the token still matches.

    • This prevents one server from deleting another server’s lock.

    • Redis writes and publish operations occur while holding the same lock.

The local Gradle build could not run because Gradle is not installed in the environment.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
settings.gradle
Code
12 1,203
src/main/java/com/kodari/crossserversettings/CrossServerSettings.java
package com.kodari.crossserversettings;

import com.kodari.crossserversettings.command.SettingsCommand;
import com.kodari.crossserversettings.listener.SettingsListener;
import com.kodari.crossserversettings.sync.RedisSyncService;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;

public final class CrossServerSettings extends JavaPlugin {
    private RedisSyncService redisSyncService;
    private SettingsManager settingsManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        redisSyncService = new RedisSyncService(this);
        settingsManager = new SettingsManager(this, redisSyncService);

        redisSyncService.start();
        settingsManager.start();

        getServer().getPluginManager().registerEvents(
                new SettingsListener(this, settingsManager),
                this
        );

        SettingsCommand settingsCommand = new SettingsCommand(this, settingsManager);
        PluginCommand command = getCommand("settings");

        if (command == null) {
            getLogger().severe("The settings command is missing from plugin.yml.");
            return;
        }

        command.setExecutor(settingsCommand);
        command.setTabCompleter(settingsCommand);
        registerCommandAliases(settingsCommand);
    }

    @Override
    public void onDisable() {
        if (settingsManager != null) {
            settingsManager.close();
        }

        if (redisSyncService != null) {
            redisSyncService.close();
        }
    }

    public void registerCommandAliases(SettingsCommand executor) {
        List<String> configuredAliases = getConfig().getStringList("command.aliases");
        Set<String> aliases = new HashSet<>();

        for (String value : configuredAliases) {
            String alias = value.toLowerCase(Locale.ROOT).trim();

            if (!alias.isEmpty()
                    && alias.matches("[a-z0-9_-]+")
                    && !alias.equals("settings")) {
                aliases.add(alias);
            }
        }

        Command command = getCommand("settings");

        if (command != null) {
            command.setAliases(List.copyOf(aliases));
        }

        try {
            Method getCommandMap = getServer().getClass().getMethod("getCommandMap");
            CommandMap commandMap = (CommandMap) getCommandMap.invoke(getServer());
            Constructor<PluginCommand> constructor =
                    PluginCommand.class.getDeclaredConstructor(
                            String.class,
                            org.bukkit.plugin.Plugin.class
                    );
            constructor.setAccessible(true);

            for (String alias : aliases) {
                if (commandMap.getCommand(alias) != null) {
                    continue;
                }

                PluginCommand aliasCommand = constructor.newInstance(alias, this);
                aliasCommand.setExecutor(executor);
                aliasCommand.setTabCompleter(executor);
                commandMap.register(
                        getName().toLowerCase(Locale.ROOT),
                        aliasCommand
                );
            }
        } catch (ReflectiveOperationException exception) {
            getLogger().warning(
                    "Unable to register configured command aliases: "
                            + exception.getMessage()
            );
        }
    }
}