#minecraft permission groups

1 messages · Page 1 of 1 (latest)

dense flowerBOT
#

<@&987246652869971988> please have a look, thanks.

dense flowerBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

vast dome
#

?

fallow sandal
#

id suggest u invest some time into improving ur question quality. so that its easier to help u

#

especially the title of ur thread

vast dome
#

Right now, I need to make it possible to duplicate groups in the "disabled_groups" and "enabled_groups" sections, for example, to have not only the "helper" group, but also the "sthelpher" group, and not only the "offhelper" group, but also the "offsthelpher" group.

Currently, my plugin's code for the moderator work mode does not provide such an opportunity. I would like to be able to add groups based on the "helper" and "offhelper" principles that are in the config.yml.

Here is an example of a config without the ability to add 2-3-4-5 (and so on) groups:

disabled_groups:
  offhelper: # Here player can add their own roles
    on_commands: "lp user %player_name% parent add helper"
    on_messages: "%player_name% started working."
    permissions_group: group.offhelper
enabled_groups:
  helper:
    off_commands: "lp user %player_name% parent remove helper"
    off_messages: "%player_name% finished working."
    permissions_group: group.helper

Here is an example of a config with the ability to add 2-3-4-5 (and so on) roles:

disabled_groups: #/sw on
  offsthelper: 
    on_commands: "lp user %player_name% parent add sthelper"
    on_messages: "%player_name% started working."
    permissions_group: group.offsthelper
  offhelper: # Here player can add their own roles
    on_commands: "lp user %player_name% parent add helper"
    on_messages: "%player_name% started working."
    permissions_group: group.offhelper
enabled_groups: #/sw off
  sthelper: 
    off_commands: "lp user %player_name% parent remove sthelper"
    off_messages: "%player_name% finished working."
    permissions_group: group.sthelper
  helper: 
    off_commands: "lp user %player_name% parent remove helper"
    off_messages: "%player_name% finished working."
    permissions_group: group.helper
fallow sandal
#

could u please change ur thread title? no one will click on it like that

#

and if no one clicks on it, no one will help

#

/help-thread change title

vast dome
#

/help-thread change title

dense flowerBOT
#

code help in the RwStaffWork plugin

#

Changed the title to code help in the RwStaffWork plugin.

#

minecraft permission groups

#

Changed the title to minecraft permission groups.

dense flowerBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍

vast dome
#

:/

dense flowerBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍

vast dome
#

go help me

coral ether
#

Let me take a look at it tomorrow

vast dome
vast dome
#

@coral ether

#

help)

coral ether
#

without modifying the plugin code
wdym by that?

vast dome
#

I need the player to be able to upload their groups through the config without access to class files

coral ether
#

ah ok, but you still modify the plugins code for that

#

the user of the plugin doesnt

vast dome
#

in the message I sent, you misunderstood me. I meant that the players could not change the code

coral ether
#

yeah but you said this:

I cannot create roles like sthelper, offsthelper, and similar ones without modifying the plugin code.
which is kinda missleading

#

will take a look at the code in a min

vast dome
coral ether
#

so if I understand correctly:
instead of just parsing the offhelper/helper manually, you want to parse any entry in disabled_groups and enabled_groups automatically
without knowing its name

vast dome
#

yea

coral ether
#

and all groups in disabled_groups is going to have on_commands, on_messages and permissions_group right?

#

same for the enabled_groups, are all entries supply off_commands, off_messages and permissions_group?

#

@vast dome

coral ether
#

then you could do smth like this:

FileConfiguration config = getConfig();

// handle disabled groups
List<String> disabledGroups = config.getConfigurationSection("disabled_groups").getKeys(false);
for (String entry : disabledGroups) {
    String path = "disabled_groups." + entry;
    String onCommands = config.getString(path + ".on_commands");
    String onMessages = config.getString(path + ".on_messages");
}

and so on, do the same with the enabled_groups

vast dome
#

I'll try it later

coral ether
vast dome
#

heh

#

error :/

#

code

#

what is the mistake?

coral ether
#

how would I know without seeing the error lol

#

also first I would make a class that represents an entry in enabled_groups as well as disabled_groups

#

and then store those in a List

#

smth like:

public record DisabledGroup(String onCommand, String onMessage, String permissionGroup) {
}
#

same for the EnabledGroup

vast dome
#

❤️

#

thanks!!

dense flowerBOT
#

Closed the thread.

vast dome
#

@coral ether )

coral ether
#

yeah?

vast dome
#

I have a problem, all commands in on-command and off-commands are being executed.

coral ether
#

show your code

vast dome
#

For example, I have a group called "offhelper" and I write "/sw on" and commands are executed not only from the group output parameter but also from others.

coral ether
#

commands are executed not only from the group output parameter but also from others.
idk what you mean by that

vast dome
#

second

#

I send screen

#

config:

disabled_groups:
  offsthelper:
    on_commands: "lp user %player_name% parent remove sthelper"
    on_messages: "&6StaffWork &8» %vault_rankprefix%&7%player_name% &cзакончил работу."
  offhelper:
    on_commands: "lp user %player_name% parent remove helper"
    on_messages: "&6StaffWork &8» %vault_rankprefix%&7%player_name% &cзакончил работу."
enabled_groups:
  sthelper:
    off_commands: "lp user %player_name% parent add sthelper"
    off_messages: "&6StaffWork &8» %vault_rankprefix%&7%player_name% &aначал работу."
  helper:
    off_commands: "lp user %player_name% parent add helper"
    off_messages: "&6StaffWork &8» %vault_rankprefix%&7%player_name% &aначал работу."

messages:
  no_permission_message: "&6StaffWork &8» &cУ вас нет разрешения на использование этой команды."
  reload: "&6StaffWork &8» &aКонфигурация перезагружена."
  already_enabled: "&6StaffWork &8» &cВы и так в режиме работы!"
  already_disabled: "&6StaffWork &8» &cВы не находитесь в режиме работы"
coral ether
#

ok and what is wrong

#

and what should happen instead?

vast dome
#

If I have the role 'offhelper,' then when I use the command '/sw on,' I want the command specified in 'off_commands' (which is in the 'helper' role) to be executed. However, instead of that, when I use '/sw on,' all commands from the roles in 'enabled_groups' are executed.

#

and send 2 messages

coral ether
#

so you first want to check if the player got the permission for the role right?

#

what is the permission called?

#

just add a player.hasPermission("") in the loop
also you currently looping through all online players instead of the player that used the command

vast dome
#

group.helper

#

group.nameGroup

vast dome
#

thanks

dense flowerBOT
#

Hey, what's up? How can I assist you?

vast dome
#

:d

dense flowerBOT
#

Closed the thread.

vast dome
#

help

#

)

#

@coral ether

#

The plugin does not respond to /sw off, does not execute commands, and does not write in chat, but it marks that I started working in the plugin.

coral ether
#

show your current code

vast dome
coral ether
#

first to make your code a bit cleaner I would change the onCommand to this:

if (!command.getName().equalsIgnoreCase("sw")) {
    return false;
}

if (args.length != 1) {
    sender.sendMessage(ChatColor.RED + "Использование: /sw <on/off/reload>");
    return true;
}

String action = args[0];
if (action.equalsIgnoreCase("on")) {
    if (!sender.hasPermission("blackdigo.sw.use")) { // maybe store "blackdigo.sw.use" in a constant
        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.no_permission_message")));
        return true;
    }

    if (!isEnabled) {
        enableSW(sender);
    } else {
        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.already_enabled")));
    }
    return true;
}

if (action.equalsIgnoreCase("off")) {
    if (!sender.hasPermission("blackdigo.sw.use")) { // maybe store "blackdigo.sw.use" in a constant
        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.no_permission_message")));
        return true;
    }

    if (isEnabled) {
        disableSW(sender);
    } else {
        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.already_disabled")));
    }
    return true;
}

if (action.equalsIgnoreCase("reload")) {
    if (sender.hasPermission("blackdigo.sw.reload")) { // maybe store in a constant
         reloadConfig(sender);
    } else {
        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.no_permission_message")));
    }
    return true;
}

sender.sendMessage(ChatColor.RED + "Использование: /sw <on/off/reload>");
return true;
#

maybe want to store each action in a different method

#

also is the sender.hasPermission in the enableSW/disabledSW still needed? you already check before

coral ether
#

also if you are using a newer version of java use this for instanceof checks instead:
old:

if (sender instanceof Player) {
    Player player = (Player) sender;
}

newer:

if (sender instanceof Player player) {

}

no need casting yourself

#

and again for enableSW/disableSW, try to reduce your if chaining

#

enableSW:

isEnabled = true;

ConfigurationSection enabledGroups = config.getConfigurationSection("enabled_groups");
if (enabledGroups == null) {
    return;
}

for (String group : enabledGroups.getKeys(false)) {
    String offCommands = enabledGroups.getString(groupName + ".off_commands");
    String offMessages = enabledGroups.getString(groupName + ".off_messages");
    String groupPermission = enabledGroups.getString(groupName + ".group_permission");

    if (offCommands == null || offMessages == null || groupPermission == null) {
        continue;
    }

    if (sender instanceof Player player && player.hasPermission(groupPermission)) { // you can either use sender or player.hasPermission
        getServer().dispatchCommand(getServer().getConsoleSender(), offCommands.replace("%player_name%", player.getName()));
        player.sendMessage(ChatColor.translateAlternateColorCodes('&', offMessages.replace("%player_name%", player.getName())));
    }
}

also do you really want to run the command with the console as sender instead of the player?

vast dome
coral ether
#

oh yeah renamed the variable to group

#

wrote that in discord

#

but you should be able to see that issue yourself real quick

vast dome
coral ether
#

the code does that

vast dome
coral ether
#

ah you using java 8 💀

vast dome
#

yea)

coral ether
#

why not any newer version?

vast dome
#

minecraft 1.12.2

coral ether
#

cant you still use newer version of java for compiling plugins?

vast dome
#

:/

coral ether
vast dome
#

downloaded 16 java 16

#

But still haven't figured out how to fix groupName.

coral ether
#

then you need to go back and understand your code

#

old:

// ...
            for (String groupName : enabledGroups.getKeys(false)) {
                String offCommands = enabledGroups.getString(groupName + ".off_commands");
                String offMessages = enabledGroups.getString(groupName + ".off_messages");
                String groupPermission = enabledGroups.getString(groupName + ".group_permission");

                if (offCommands != null && offMessages != null && groupPermission != null) {
                    if (sender instanceof Player && sender.hasPermission("blackdigo.sw.use") && sender.hasPermission(groupPermission)) {
                        Player player = (Player) sender;
                        getServer().dispatchCommand(getServer().getConsoleSender(), offCommands.replace("%player_name%", player.getName()));
                        player.sendMessage(ChatColor.translateAlternateColorCodes('&', offMessages.replace("%player_name%", player.getName())));
                    }
                }
            }

what is your groupName variable here?

vast dome
#
            for (String groupName : enabledGroups.getKeys(false)) {
coral ether
#

what does it represent

vast dome
#

collects groups from enabled-groups

#

for (String groupName : enabledGroups.getKeys(false)) {

coral ether
#

yeah and now check the new code

#

I changed the variable name

#

but not its usage

vast dome
#

for (String Name : enabledGroups.getKeys(false)) { rename to for (String groupName : enabledGroups.getKeys(false)) {

coral ether
#

yeah that looks good

#

but that wasnt logic changes, only to make your code more readable

#

so it still shouldnt work right?

vast dome
#

second

#

error

coral ether
#

which one

vast dome
#

[13:55:24 ERROR]: Could not load 'plugins/RwStaffWork.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: java.lang.UnsupportedClassVersionError: ru/blackdigo/rwstaffwork/RwStaffWork has been compiled by a more recent version of the Java Runtime (class file version 60.0), this version of the Java Runtime only recognizes class file versions up to 52.0

#

:/

coral ether
#

ah ok then you need to compile with java 8

coral ether
vast dome
#

Patterns in 'instanceof' are not supported at language level '8'

#

error

coral ether
#

yeah because you down graded

coral ether
vast dome
#
    private void enableSW(CommandSender sender) {
        isEnabled = true;

        ConfigurationSection enabledGroups = config.getConfigurationSection("enabled_groups");
        if (enabledGroups == null) {
            return;
        }

        for (String groupName : enabledGroups.getKeys(false)) {
            String offCommands = enabledGroups.getString(groupName + ".off_commands");
            String offMessages = enabledGroups.getString(groupName + ".off_messages");
            String groupPermission = enabledGroups.getString(groupName + ".group_permission");

            if (offCommands == null || offMessages == null || groupPermission == null) {
                continue;
            }

            if (offCommands != null && offMessages != null && groupPermission != null) {
                if (sender instanceof Player && sender.hasPermission("blackdigo.sw.use") && sender.hasPermission(groupPermission)) {
                    Player player = (Player) sender;
                    getServer().dispatchCommand(getServer().getConsoleSender(), offCommands.replace("%player_name%", player.getName()));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', offMessages.replace("%player_name%", player.getName())));
                }
            }
        }
    }
#
    private void disableSW(CommandSender sender) {
        isEnabled = true;

        ConfigurationSection disabledGroups = config.getConfigurationSection("disabled_groups");
        if (disabledGroups == null) {
            return;
        }

        for (String groupName : disabledGroups.getKeys(false)) {
            String onCommands = disabledGroups.getString(groupName + ".on_commands");
            String onMessages = disabledGroups.getString(groupName + ".on_messages");
            String groupPermission = disabledGroups.getString(groupName + ".group_permission");

            if (onCommands == null || onMessages == null || groupPermission == null) {
                continue;
            }

            if (onCommands != null && onMessages != null && groupPermission != null) {
                if (sender instanceof Player && sender.hasPermission("blackdigo.sw.use") && sender.hasPermission(groupPermission)) {
                    Player player = (Player) sender;
                    getServer().dispatchCommand(getServer().getConsoleSender(), onCommands.replace("%player_name%", player.getName()));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', onMessages.replace("%player_name%", player.getName())));
                }
            }
        }
    }
#

corrently?

coral ether
#

one of the isEnabled should be set to false

#

also the if (onCommands != null && onMessages != null && groupPermission != null) { is useless

#

because you already check that before

#

but your ide should also tell you that

vast dome
#
    private void enableSW(CommandSender sender) {
        isEnabled = true;

        ConfigurationSection enabledGroups = config.getConfigurationSection("enabled_groups");
        if (enabledGroups == null) {
            return;
        }

        for (String groupName : enabledGroups.getKeys(false)) {
            String offCommands = enabledGroups.getString(groupName + ".off_commands");
            String offMessages = enabledGroups.getString(groupName + ".off_messages");
            String groupPermission = enabledGroups.getString(groupName + ".group_permission");

            if (offCommands == null || offMessages == null || groupPermission == null) {
                continue;
            }

                if (sender instanceof Player && sender.hasPermission("blackdigo.sw.use") && sender.hasPermission(groupPermission)) {
                    Player player = (Player) sender;
                    getServer().dispatchCommand(getServer().getConsoleSender(), offCommands.replace("%player_name%", player.getName()));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', offMessages.replace("%player_name%", player.getName())));
                }
            }
        }
#
    private void disableSW(CommandSender sender) {
        isEnabled = false;

        ConfigurationSection disabledGroups = config.getConfigurationSection("disabled_groups");
        if (disabledGroups == null) {
            return;
        }

        for (String groupName : disabledGroups.getKeys(false)) {
            String onCommands = disabledGroups.getString(groupName + ".on_commands");
            String onMessages = disabledGroups.getString(groupName + ".on_messages");
            String groupPermission = disabledGroups.getString(groupName + ".group_permission");

            if (onCommands == null || onMessages == null || groupPermission == null) {
                continue;
            }

                if (sender instanceof Player && sender.hasPermission("blackdigo.sw.use") && sender.hasPermission(groupPermission)) {
                    Player player = (Player) sender;
                    getServer().dispatchCommand(getServer().getConsoleSender(), onCommands.replace("%player_name%", player.getName()));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', onMessages.replace("%player_name%", player.getName())));
                }
            }
        }
#

ops

coral ether
#

you need to remvoe one of the closing parenthesis }

vast dome
#

maybe:

    private void disableSW(CommandSender sender) {
        isEnabled = false;

        ConfigurationSection disabledGroups = config.getConfigurationSection("disabled_groups");
        if (disabledGroups == null) {
            return;
        }

        for (String groupName : disabledGroups.getKeys(false)) {
            String onCommands = disabledGroups.getString(groupName + ".on_commands");
            String onMessages = disabledGroups.getString(groupName + ".on_messages");
            String groupPermission = disabledGroups.getString(groupName + ".group_permission");

            if (onCommands == null || onMessages == null || groupPermission == null) {
                if (sender instanceof Player && sender.hasPermission("blackdigo.sw.use") && sender.hasPermission(groupPermission)) {
                    Player player = (Player) sender;
                    getServer().dispatchCommand(getServer().getConsoleSender(), onCommands.replace("%player_name%", player.getName()));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', onMessages.replace("%player_name%", player.getName())));
                }
            }
        }
    }
#

?

coral ether
#

no

coral ether
#

it just got one } too much

vast dome
#
if (onCommands == null || onMessages == null || groupPermission == null) {
                continue;
            }
#
    private void disableSW(CommandSender sender) {
        isEnabled = false;

        ConfigurationSection disabledGroups = config.getConfigurationSection("disabled_groups");
        if (disabledGroups == null) {
            return;
        }

        for (String groupName : disabledGroups.getKeys(false)) {
            String onCommands = disabledGroups.getString(groupName + ".on_commands");
            String onMessages = disabledGroups.getString(groupName + ".on_messages");
            String groupPermission = disabledGroups.getString(groupName + ".group_permission");

            if (onCommands == null || onMessages == null || groupPermission == null)
                continue;
            

            if (sender instanceof Player && sender.hasPermission("blackdigo.sw.use") && sender.hasPermission(groupPermission)) {
                Player player = (Player) sender;
                getServer().dispatchCommand(getServer().getConsoleSender(), onCommands.replace("%player_name%", player.getName()));
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', onMessages.replace("%player_name%", player.getName())));
            }
        }
    }
coral ether
#

thats not what I meant but works as well

coral ether
#

your code wasnt formatted

#

didnt notice

vast dome
#
[16:10:10] [Server thread/ERROR]: Error occurred while enabling StaffWork v1.0 (Is it up to date?)
java.lang.NullPointerException: null
    at ru.blackdigo.staffwork.StaffWork.onEnable(StaffWork.java:24) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[patched_1.12.2.jar:git-Paper-1620]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:316) ~[patched_1.12.2.jar:git-Paper-1620]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) ~[patched_1.12.2.jar:git-Paper-1620]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:395) ~[patched_1.12.2.jar:git-Paper-1620]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:344) ~[patched_1.12.2.jar:git-Paper-1620]
    at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:442) ~[patched_1.12.2.jar:git-Paper-1620]
    at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:403) ~[patched_1.12.2.jar:git-Paper-1620]
    at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:341) ~[patched_1.12.2.jar:git-Paper-1620]
    at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:289) ~[patched_1.12.2.jar:git-Paper-1620]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:616) ~[patched_1.12.2.jar:git-Paper-1620]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_312]
coral ether
#

what is line 24 in StaffWork.java?

vast dome
#

getCommand("sw").setExecutor(this);

#
    @Override
    public void onEnable() {
        saveDefaultConfig();
        config = getConfig();

        getCommand("sw").setExecutor(this);
    }
coral ether
#

show your plugin.yml

vast dome
#

am..

coral ether
#

it seems to be missing the "sw" command

vast dome
#

I forgot to register the command

#

:/

coral ether
#

all good

#

happens

vast dome
#

work only /sw on

coral ether
#

show the full class again

#

and show me your config

coral ether
#

so off doesnt work right?

#

its because your config is broken

#

the disabled groups

#

use off_commands and off_messages like the enabled group

#

but in the code you check for on_commands and on_messages

#

thus it returns null for them and the null check before skips that group then because its broken

vast dome
#

second

#

not work

#

I think the problem is in the permissions

coral ether
#

you should isntantly see if its a problem with permissions

#

because you send a message to the sender back

#

if it got no permission

vast dome
#

nothing is displayed

#

only IsEnabled changes to false

coral ether
#

add a println in the

        if (disabledGroups == null) {
            return;
        }
#

to check if you actually get groups

#

from the config

vast dome
#

private void disableSW(CommandSender sender) {
isEnabled = false;

    ConfigurationSection disabledGroups = config.getConfigurationSection("disabled_groups");
    if (disabledGroups == null) {
        System.out.println("SW disabled.");
        return;
    }
#

yes?

coral ether
#

yeah and check if it prints

vast dome
coral ether
#

then add a print to the for loop to see if there are even keys in there
and add a print to this if check:

if (onCommands == null || onMessages == null || groupPermission == null) {
    continue;
}
vast dome
#
if (onCommands == null || onMessages == null || groupPermission == null)
                continue;
            System.out.println("SW disabled.");
#

correct?

coral ether
#

you need to wrap the "content" of the if into parentheses ( { and }) if you have multiple lines of code

vast dome
#
            if (onCommands == null || onMessages == null || groupPermission == null) {
                System.out.println("SW disabled.");
                continue;
            }
#

ok

coral ether
#

also I would use a different print to see where its really at

coral ether
#

whats under that?

vast dome
#
    private void disableSW(CommandSender sender) {
        isEnabled = false;

        ConfigurationSection disabledGroups = config.getConfigurationSection("disabled_groups");
        if (disabledGroups == null) {
            System.out.println("SW disabled1.");
            return;
        }

        for (String groupName : disabledGroups.getKeys(false)) {
            String onCommands = disabledGroups.getString(groupName + ".on_commands");
            String onMessages = disabledGroups.getString(groupName + ".on_messages");
            String groupPermission = disabledGroups.getString(groupName + ".group_permission");

            if (onCommands == null || onMessages == null || groupPermission == null) {
                System.out.println("SW disabled2.");
                continue;
            }


            if (sender instanceof Player && sender.hasPermission("blackdigo.sw.use") && sender.hasPermission(groupPermission)) {
                Player player = (Player) sender;
                getServer().dispatchCommand(getServer().getConsoleSender(), onCommands.replace("%player_name%", player.getName()));
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', onMessages.replace("%player_name%", player.getName())));
            }
        }
    }
coral ether
#

you forgot to add a print at loop level

#

to see if disabledGroups.getKeys return smth

vast dome
#
    private void disableSW(CommandSender sender) {
        isEnabled = false;

        ConfigurationSection disabledGroups = config.getConfigurationSection("disabled_groups");
        if (disabledGroups == null) {
            System.out.println("SW disabled1.");
            return;
        }

        for (String groupName : disabledGroups.getKeys(false)) {
            System.out.println("disabledGroups.getKeys() return: 1");

            String onCommands = disabledGroups.getString(groupName + ".on_commands");
            String onMessages = disabledGroups.getString(groupName + ".on_messages");
            String groupPermission = disabledGroups.getString(groupName + ".group_permission");

            if (onCommands == null || onMessages == null || groupPermission == null) {
                System.out.println("SW disabled2.");
                continue;
            }

            if (sender instanceof Player && sender.hasPermission("blackdigo.sw.use") && sender.hasPermission(groupPermission)) {
                Player player = (Player) sender;
                getServer().dispatchCommand(getServer().getConsoleSender(), onCommands.replace("%player_name%", player.getName()));
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', onMessages.replace("%player_name%", player.getName())));
            }
        }
    }
#

correct?

#

for (String groupName : disabledGroups.getKeys(false)) {
System.out.println("disabledGroups.getKeys() return: 1");

coral ether
#

yeah and see if that prints

vast dome
coral ether
#

then either the sender is not instanceof player or you are missing the permission

#

print: sender.hasPermission(groupPermission)

vast dome
#

yes

#

you're asking for guidance on how to make a plugin determine the highest level of authority and operate based on it. Specifically, if a person has four levels of authority: offhelper, helper, offsthelper, and sthelper, you want the plugin to identify offsthelper and sthelper as the highest levels. Is that correct?

vast dome
# coral ether what?

If I have 4 permissions, blackdigo.sw.offhelper, blackdigo.sw.helper, blackdigo.sw.offsthelper, blackdigo.sw.sthelper, when typing /sw on, the off_commands of the helper and sthelper groups are executed. But I want the plugin to consider the highest privilege even if I have these 4 permissions and execute the off_commands of the sthelper privilege.

coral ether
#

ah ok so you dont want to execute all groups in enabled/disabled?

#

you want to execute the one that the player has the highest permission?

coral ether
#

ok give me 10min need to do smth

vast dome
#

ok)

vast dome
#

?

#

)

coral ether
#

sorry, I think my real life is more important lol

#

you first would need to specify the privilege order

#

which permission is the highest to lowest

vast dome
#

hm

#

maybe add priority?

coral ether
#

yeah you would need to map permissions to priority

vast dome
#

is it possible to make a priority after the permit?

#

group_permission: blackdigo.sw.offhelper:1

#

or
group_permissions: blackdigo.sw.offhelper
priority: 1

#

if anything, here's my code:

coral ether
#

you want to set the priority by the user (config.yml)
or in the code base?

#

doesnt make sense lol

#

I would just maybe add another property to each group

coral ether
#

for example:

disabled_groups:
  offglmoder:
    on_commands: "lp user %player_name% parent remove glmoder"
    on_messages: "&6StaffWork &8» %vault_rankprefix%&7%player_name% &aначал работу."
    group_permission: "blackdigo.sw.glmoder"
    priority: 1
coral ether
#

and then parse that with disabledGroups.getInt("priority")

#

or you could specify order of group as priority

#
disabled_groups:
  offglmoder:
    on_commands: "lp user %player_name% parent remove glmoder"
    on_messages: "&6StaffWork &8» %vault_rankprefix%&7%player_name% &aначал работу."
    group_permission: "blackdigo.sw.glmoder"
  offstmoder:
    on_commands: "lp user %player_name% parent remove stmoder"
    on_messages: "&6StaffWork &8» %vault_rankprefix%&7%player_name% &aначал работу."
    group_permission: "blackdigo.sw.stmoder"
  offmoder:
    on_commands: "lp user %player_name% parent remove moder"
    on_messages: "&6StaffWork &8» %vault_rankprefix%&7%player_name% &aначал работу."
    group_permission: "blackdigo.sw.moder"
  offsthelper:
    on_commands: "lp user %player_name% parent remove sthelper"
    on_messages: "&6StaffWork &8» %vault_rankprefix%&7%player_name% &aначал работу."
    group_permission: "blackdigo.sw.sthelper"
  offhelper:
    on_commands: "lp user %player_name% parent remove helper"
    on_messages: "&6StaffWork &8» %vault_rankprefix%&7%player_name% &aначал работу."
    group_permission: "blackdigo.sw.helper"
#

so offglmoder would be highest priority

#

and offhelper would be lowest

vast dome
#

so offglmoder would be highest priority and offhelper would be lowest

me need

coral ether
#

ok, just break the loop if the if got executed

#

because the .getKEys is ordered

vast dome
#

I thought it was better through priority:

#

more familiar)

coral ether
#

wdym

#

your english is kinda broken

#

so you want to set the priority instead of using order as priority?

coral ether
#

Just add the field to the yml Config and the manage it in the code

vast dome
#

hm

#

I added the parameter "permission_priority" to the config, but I didn't understand how to set priorities for permissions.

coral ether
#

I would first make a class for each group which stores these variables offCommands, offMessages, permission and priority
then in the for loop parse all into a List<Group> which got the same length as enabledGroups.getKeys(false). Then sort that list
by priority and iterate over it sorted and if you find one that the sender actually has permission call the command and exit the iteration

vast dome
#

hmm

#
    private class Group {
        private String offCommands;
        private String offMessages;
        private String groupPermission;
        private int permissionPriority;
coral ether
#

yeah maybe make them final

vast dome
#
        public Group(String offCommands, String offMessages, String groupPermission, int permissionPriority) {
            this.offCommands = offCommands;
            this.offMessages = offMessages;
            this.groupPermission = groupPermission;
            this.permissionPriority = permissionPriority;
        }
coral ether
#

then I would add a constructor which accepts a ConfigurationSection

#

and then get the content there

vast dome
# coral ether yeah maybe make them final
    private static class Group {
        private final String offCommands;
        private final String offMessages;
        private final String groupPermission;
        private final int permissionPriority;
coral ether
#

also I would move it to a seperate file

#

also do you know java well?

vast dome
#

70/100

coral ether
#

?

#

you now added a constructor to StaffWork

vast dome
#

yea

coral ether
#

you dont need it

#

but your enable method looks good

#

you want the higher the int for the permission the higher the priority?

vast dome
#

yes

coral ether
#

then you need to reverse it after comparingInt

#

just need to call reversed() on the Comparator

#

also idk how you want to handle if two/more got the same priority

vast dome
#

also idk how you want to handle if two/more got the same priority

maybe send error

coral ether
#

depends on you

#

what you want

#

you can just say that it will be random in that case

#

or you send an error

#

...

vast dome
#

hm

#

maybe send error command sender /sw (on/off)

coral ether
#

do what you want

vast dome
#

:/

coral ether
#

whats wrong?

vast dome
#

no wrong

coral ether
#

its your plugin, why should I tell you how to structure it etc

vast dome
coral ether
#
    public StaffWork(ConfigurationSection configSection) {
        this.config = (FileConfiguration) configSection.getRoot();
    }

remove this one

#

also you still missing the reversed on the sorting

#

and missing the implementation of priority for the disable method

vast dome
#

new code

vast dome
#

also you still missing the reversed on the sorting

I didn't quite understand.

coral ether
#

your list is now sorted by integer

#

that means from small to large

coral ether
#

so you need to call reversed() on the Comparator after comparing with int

#

to have large to small

vast dome
#

um

#

offhelper - priority 1

#

helper - priority 2

#

yes?

#

Did you mean this?

coral ether
#

ok which of these should get executed if a player got both permissions?

#

the one with priority 1

#

or the one with priority 2

vast dome
#

The tallest

coral ether
#

so priority 2 aka helper

vast dome
#

yes

#

priority:
glmoder: 10
stmoder: 9
moder: 8
sthelper:7
helper: 6
offglmoder: 5
offstmoder: 4
offmoder: 3
offsthelper: 2
offhelper: 1

#

Just to clarify, I simply wrote a list of roles and their priorities. No lists are needed.

#

)

coral ether
#

but the one are for enable and the other one are for disable right?

vast dome
#

yes

coral ether
#
glmoder: 5
stmoder: 4
moder: 3
sthelper: 2
helper: 1

offglmoder: 5
offstmoder: 4
offmoder: 3
offsthelper: 2
offhelper: 1 

why arent the priorities like this then?

#

because the enable and disable are not really related usage-wise

vast dome
#

This can also be used.

coral ether
#

ok and if you want it like this then you need to reverse the sorting

#

because comparingInt sorts from small to large (1 - 5)

#

but you want from large - small (5 - 1)

#

also why do you have a class for enable and a different one for disable?

#

they do both the same

#

just have this class

#

for both:

#
public class Group {
    private final String commands;
    private final String messages;
    private final String permission;
    private final int priority;

    public Group(String commands, String messages, String permission, int priority) {
        // initialize variables
    }

    // getters
}
coral ether
vast dome
#
        public onGroup reversed() {
            return null;
        }
#
        public offGroup reversed() {
            return null;
        }
coral ether
#

?

#

its a method provided by Comparator

#

you know what comparingInt returns?

vast dome
#

yea

sweet onyxBOT
vast dome
coral ether
#

this looks like that it could work

#

everything seems fine for me

vast dome
#

work)

#

thanks!

dense flowerBOT
#

Closed the thread.

vast dome
#

oh

#

)

coral ether
#

yeah?

vast dome
#

I have a problem with placeholders of the PlaceholderAPI plugin in my plugin. I found a solution on GitHub, but I don't understand how to modify my code by adding the code from GitHub.

#

PlaceholderAPI.setPlaceholders(player, text);

#

String text = "text123"

coral ether
#

sorry idk how the placeholder api works

#

never used it

vast dome
#

I can give help from the developer

#
package at.helpch.placeholderapi;

import me.clip.placeholderapi.PlaceholderAPI;

import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import me.clip.placeholderapi.PlaceholderAPI;

public class JoinExample extends JavaPlugin implements Listener {

    @Override
    public void onEnable() {
 
        if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
            /*
             * We register the EventListener here, when PlaceholderAPI is installed.
             * Since all events are in the main class (this class), we simply use "this"
             */
            Bukkit.getPluginManager().registerEvents(this, this);
        } else {
            /*
             * We inform about the fact that PlaceholderAPI isn't installed and then
             * disable this plugin to prevent issues.
             */
            getLogger().warn("Could not find PlaceholderAPI! This plugin is required.");
            Bukkit.getPluginManager().disablePlugin(this);
        }
    }

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onJoin(PlayerJoinEvent event) {
        String joinText = "%player_name% &ajoined the server! They are rank &f%vault_rank%";

        /*
         * We parse the placeholders using "setPlaceholders"
         * This would turn %vault_rank% into the name of the Group, that the
         * joining player has.
         */
        joinText = PlaceholderAPI.setPlaceholders(event.getPlayer(), joinText);

        event.setJoinMessage(joinText);
    }
}
coral ether
#

?

#

I have no idea what that plugin is even about

vast dome
#

(

dense flowerBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍

vast dome
#

heh

#

How to add a delay to the /sw command?

fallow sandal
vast dome
#

nonnon)

#

))

fallow sandal
#

just saying, more people would see it and respond

vast dome
#

my code

coral ether
vast dome
#

The player will be able to reuse the command after the time specified in the config

coral ether
#

so for example a player can only use the command like every 10s

vast dome
#

yes

coral ether
#

that would be normally done with a Map<UUID, Long> in combination with System#currentTimeMillis

#

and on command just store the last time that user used that command

#

and on each call check if now the currentTimeMillis - lastTimeUsedMillis is >= delay in ms

vast dome
#

em

coral ether
#

first result googling…

fallow sandal
# vast dome em

what does em mean? is it a "okay, cool. everything clear"? if not, whats unclear?

vast dome
#

I don't understand)

#

second

coral ether
#

but whats exactly unclear?

#

how to use a Map

vast dome
#

Where should the delay be added? In onCommand?

coral ether
#

or what System.currentTimeMillis is?

coral ether
vast dome
#

hm

#

?

coral ether
#

but you know that the check now happens after doing the command logic aka using the command

vast dome
fallow sandal
#

by the time u reach the check, u already executed the command

#

so users can still execute it

#

ur logic is:

  • execute command
  • check timeout
#

it has to be the other way around

vast dome
fallow sandal
#

looks better now. give it a try

#

note that a more modern and generally better approach would be to use Instant instead of a millis Long

#

but perhaps that would only confuse u at this stage

coral ether
#

I would maybe do it like this for better readabilty:

private boolean isCommandCooldownOver(CommandSender sender) { // maybe rename this method
    if (!(sender instanceof Player player)) {
        return true; // delay gets ignored for non-player usage, for example console
    }
    
    UUID playerUUID = player.getUniqueId();
    if (lastTimeUsed.containsKey(playerUUID)) {
        return true; // first time using the command
    }
    
    long currentTime = System.currentTimeMillis();
    long lastTime = lastTimeUsed.get(playerUUID);
    if (currentTime - lastTime < delayInMillis) {
        return false; // delay not done yet
    }
    
    lastTimeUsed.put(playerUUID, currentTime);
    return true;
}

to use that method just do:

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!command.getName().equalsIgnoreCase("sw")) {
        return false;
    }

    if (args.length != 1) {
        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.help")));
        return true;
    }

    // ...
    if (isCommandCooldownOver(sender)) {
        sender.sendMessage("Подождите некоторое время перед повторным использованием команды.");
        return true;
    }
    
    // ...
}
#

I suggest always making methods for such to make your onCommand more readable like:

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    checkThat();
    doThat();
    thenDoThis(); // etc, just know what the command does by reading the method names
}
vast dome
coral ether
#

sorry its missing the ! when calling isCommandCooldownExpired

#

also you now hardcoding the value 5000

#

instead of storing it in a constant variable

coral ether
#

you already fixed it

vast dome
#

What should I do next?

coral ether
#

wdym?

vast dome
#

Well, will the delay work?

coral ether
#

try it out lol

vast dome
#

How can I set up the time in the config?

coral ether
#

just like you do with any other variable

#

and did before

vast dome
#

cooldown not work)

coral ether
#

and now what should I do?

#

without any information

vast dome
coral ether
#

and now provide information

#

like whats not working

#

etc

#

what do you expect it to do

#

and what it does instead

#

...

vast dome
#

When I type /sw, the delay does not work.

coral ether
#

you didnt provide new information

#

what does not work?

#

it just executes even if the cooldown didnt expire yet?

#

or does the command never executes

#

...

vast dome
#

Everything works except for the delay

coral ether
#

bruh

#

reread what I wrote

#

also try debugging it

#

to see what actually happens

#

but I cant really help you

#

I would need more information about what you expect it to do and what happens instead

vast dome
#

I can freely execute the command /sw on/off, nothing changes, there are no messages about cooldown, the player can freely execute commands, everything works but there is no cooldown.

coral ether
#

you sure that you run back to back fast enough?

vast dome
#

yes

coral ether
#

can you show your current code again

vast dome
coral ether
#

can you print the currentTime and last Time

vast dome
#
    private boolean isCommandCooldownExpired(CommandSender sender) {
        if (!(sender instanceof Player)) {
            return true;
        }
        Player player = (Player) sender;

        UUID playerUUID = player.getUniqueId();
        if (!lastTimeUsed.containsKey(playerUUID)) {
            return true;
        }

        long currentTime = System.currentTimeMillis();
        System.out.println("currentTime");
        long lastTime = lastTimeUsed.get(playerUUID);
        System.out.println("lastTime");
        if (currentTime - lastTime < 5000) {
            return false;
        }

        lastTimeUsed.put(playerUUID, currentTime);
        return true;
    }
#

?

coral ether
#

no

#

the values

#

maybe add a prefix

#

to see which println is which value

#
System.out.println("currentTime: " + currentTime);

etc

vast dome
#
    private boolean isCommandCooldownExpired(CommandSender sender) {
        if (!(sender instanceof Player)) {
            return true;
        }
        Player player = (Player) sender;

        UUID playerUUID = player.getUniqueId();
        if (!lastTimeUsed.containsKey(playerUUID)) {
            return true;
        }

        long currentTime = System.currentTimeMillis();
        System.out.println("currentTime: " + currentTime);
        long lastTime = lastTimeUsed.get(playerUUID);
        System.out.println("currentTime: " + lastTime);
        if (currentTime - lastTime < 5000) {
            return false;
        }

        lastTimeUsed.put(playerUUID, currentTime);
        return true;
    }
coral ether
#

would need to change the prefix though lol

#

and then run and see the actual values

vast dome
#
    private boolean isCommandCooldownExpired(CommandSender sender) {
        if (!(sender instanceof Player)) {
            return true;
        }
        Player player = (Player) sender;

        UUID playerUUID = player.getUniqueId();
        if (!lastTimeUsed.containsKey(playerUUID)) {
            return true;
        }

        long currentTime = System.currentTimeMillis();
        System.out.println("currentTime: " + currentTime);
        long lastTime = lastTimeUsed.get(playerUUID);
        System.out.println("lastTime: " + lastTime);
        if (currentTime - lastTime < 5000) {
            return false;
        }

        lastTimeUsed.put(playerUUID, currentTime);
        return true;
    }
coral ether
#

hm so it doesnt even get to that point

vast dome
#

maybe problem in onCommand?

coral ether
#

maybe add prints to all the other possible scenarios to see where it stops

coral ether
vast dome
#

@coral ether

#

The last question, unfortunately or fortunately, I need the on_commands and on_messages to be executed when a player with the enabled game mode logs out of the server. isEnabled turns off by itself.