#minecraft permission groups
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
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.
?
id suggest u invest some time into improving ur question quality. so that its easier to help u
especially the title of ur thread
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
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
/help-thread change title
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.
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 👍
:/
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 👍
go help me
Let me take a look at it tomorrow
ok
without modifying the plugin code
wdym by that?
I need the player to be able to upload their groups through the config without access to class files
in the message I sent, you misunderstood me. I meant that the players could not change the code
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
the sw on/sw off commands work in my code, but even when I have, for example, offsthelper, I get a helper group when /sw on
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
yea
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
yes
yes
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
I'll try it later
look into this class for more information gathering stuff from a FileConfig:
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/configuration/MemorySection.html
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
Closed the thread.
@coral ether )
yeah?
I have a problem, all commands in on-command and off-commands are being executed.
show your code
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.
commands are executed not only from the group output parameter but also from others.
idk what you mean by that
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Вы не находитесь в режиме работы"
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
but thats what your code currently does
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
thanks
Hey, what's up? How can I assist you?
:d
Closed the thread.
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.
show your current code
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
you get any error?
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?
Cannot resolve symbol 'groupName'
oh yeah renamed the variable to group
wrote that in discord
but you should be able to see that issue yourself real quick
||also do you really want to run the command with the console as sender instead of the player?||
I need %player_name% to be the player who executed the command, meaning the console executes the command to grant privileges to the command sender.
the code does that
hm ok fine
Patterns in 'instanceof' are not supported at language level '8'
ah you using java 8 💀
yea)
why not any newer version?
minecraft 1.12.2
cant you still use newer version of java for compiling plugins?
:/
anyways then use the old of this
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?
for (String groupName : enabledGroups.getKeys(false)) {
what does it represent
collects groups from enabled-groups
for (String groupName : enabledGroups.getKeys(false)) {
for (String Name : enabledGroups.getKeys(false)) { rename to for (String groupName : enabledGroups.getKeys(false)) {
yeah that looks good
but that wasnt logic changes, only to make your code more readable
so it still shouldnt work right?
which one
[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
:/
ah ok then you need to compile with java 8
@vast dome and?
yeah because you down graded
need to use the old one instead
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?
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
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
you need to remvoe one of the closing parenthesis }
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())));
}
}
}
}
?
no
this is correct
it just got one } too much
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())));
}
}
}
thats not what I meant but works as well
actually I was wrong with this
your code wasnt formatted
didnt notice
so this is fine
[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]
what is line 24 in StaffWork.java?
getCommand("sw").setExecutor(this);
@Override
public void onEnable() {
saveDefaultConfig();
config = getConfig();
getCommand("sw").setExecutor(this);
}
show your plugin.yml
am..
it seems to be missing the "sw" command
work only /sw on
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
you should isntantly see if its a problem with permissions
because you send a message to the sender back
if it got no permission
add a println in the
if (disabledGroups == null) {
return;
}
to check if you actually get groups
from the config
private void disableSW(CommandSender sender) {
isEnabled = false;
ConfigurationSection disabledGroups = config.getConfigurationSection("disabled_groups");
if (disabledGroups == null) {
System.out.println("SW disabled.");
return;
}
yes?
yeah and check if it prints
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;
}
if (onCommands == null || onMessages == null || groupPermission == null)
continue;
System.out.println("SW disabled.");
correct?
you need to wrap the "content" of the if into parentheses ( { and }) if you have multiple lines of code
if (onCommands == null || onMessages == null || groupPermission == null) {
System.out.println("SW disabled.");
continue;
}
ok
also I would use a different print to see where its really at
whats under that?
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())));
}
}
}
you forgot to add a print at loop level
to see if disabledGroups.getKeys return smth
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");
yeah and see if that prints
then either the sender is not instanceof player or you are missing the permission
print: sender.hasPermission(groupPermission)
.
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?
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.
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?
ok give me 10min need to do smth
ok)
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
yeah you would need to map permissions to priority
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:
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
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
yes
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
yes
so offglmoder would be highest priority and offhelper would be lowest
me need
wdym
your english is kinda broken
so you want to set the priority instead of using order as priority?
Just add the field to the yml Config and the manage it in the code
hm
I added the parameter "permission_priority" to the config, but I didn't understand how to set priorities for permissions.
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
hmm
private class Group {
private String offCommands;
private String offMessages;
private String groupPermission;
private int permissionPriority;
yeah maybe make them final
public Group(String offCommands, String offMessages, String groupPermission, int permissionPriority) {
this.offCommands = offCommands;
this.offMessages = offMessages;
this.groupPermission = groupPermission;
this.permissionPriority = permissionPriority;
}
then I would add a constructor which accepts a ConfigurationSection
and then get the content there
private static class Group {
private final String offCommands;
private final String offMessages;
private final String groupPermission;
private final int permissionPriority;
.
also I would move it to a seperate file
also do you know java well?
70/100
yea
you dont need it
but your enable method looks good
you want the higher the int for the permission the higher the priority?
yes
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
also idk how you want to handle if two/more got the same priority
maybe send error
depends on you
what you want
you can just say that it will be random in that case
or you send an error
...
do what you want
:/
whats wrong?
no wrong
its your plugin, why should I tell you how to structure it etc
Is there no error in this code? https://paste.helpch.at/fawecebido.java
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
?
also you still missing the reversed on the sorting
I didn't quite understand.
but you said you want this
so you need to call reversed() on the Comparator after comparing with int
to have large to small
ok which of these should get executed if a player got both permissions?
the one with priority 1
or the one with priority 2
The tallest
so priority 2 aka helper
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.
)
but the one are for enable and the other one are for disable right?
yes
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
This can also be used.
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
}
so like this:
groups.sort(Comparator.comparingInt(onGroup::getPermissionPriority).reversed());
public onGroup reversed() {
return null;
}
public offGroup reversed() {
return null;
}
yea
public Comparator<T> reversed()
Returns a comparator that imposes the reverse ordering of this comparator.
Closed the thread.
yeah?
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"
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);
}
}
(
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 👍
might want to create a new post, with appropriate title 🙂
just saying, more people would see it and respond
wdym by delay?
The player will be able to reuse the command after the time specified in the config
so for example a player can only use the command like every 10s
yes
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
em
first result googling…
what does em mean? is it a "okay, cool. everything clear"? if not, whats unclear?
Where should the delay be added? In onCommand?
or what System.currentTimeMillis is?
yeah, check the link
but you know that the check now happens after doing the command logic aka using the command
u are doing the check at the end, but that is wrong
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
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
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
}
sorry its missing the ! when calling isCommandCooldownExpired
also you now hardcoding the value 5000
instead of storing it in a constant variable
nvm
you already fixed it
What should I do next?
wdym?
Well, will the delay work?
try it out lol
How can I set up the time in the config?
cooldown not work)
and now provide information
like whats not working
etc
what do you expect it to do
and what it does instead
...
When I type /sw, the delay does not work.
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
...
Everything works except for the delay
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
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.
you sure that you run back to back fast enough?
yes
can you show your current code again
can you print the currentTime and last Time
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;
}
?
no
the values
maybe add a prefix
to see which println is which value
System.out.println("currentTime: " + currentTime);
etc
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;
}
oops)
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;
}
hm so it doesnt even get to that point
maybe problem in onCommand?
maybe add prints to all the other possible scenarios to see where it stops
- possible scenarios of that method