Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jun 4, 2018 5:56:38 GMT
So basically I want to make customizable login messages that are permission based (not stored by playername in a players.yml file). I want the config to look sort of like this: What I'm confused on is how the plugin is supposed to read the Moderator or Admin part. Since I want this to be 100% changeable by the user, I'm not sure how I can get the plugin to read the Moderator/Admin (or whatever they want) part. I'm prety sure once you figure that out you can use the same logic to see if the player has that permission and if so, broadcast the message. Any suggestions on how I could get the plugin to read the Moderator/Admin part? Thanks
|
|
Fleek
Veteran Member
Posts: 3,548
|
Post by Fleek on Jun 4, 2018 6:05:03 GMT
Use getConfigurationSection(“login-messages”).getKeys(false) code in for statement. For example:
for (String string : config.getConfigurationSection("login-messages").getKeys(false)) { if (string.equals("enabled") { return; // Don't want to get the boolean }
if (player.hasPermission(config.getString("login-messages." + string + ".permission") { // do shit here } }
|
|
Mafrans
Veteran Member
We assholes need to stick together, if you're a fellow asshole please pm me.
Posts: 1,760
| Likes: 1,703
|
Post by Mafrans on Jun 4, 2018 14:53:21 GMT
|
|
Lemon
Veteran Member
Insert status here.
Posts: 2,491
| Likes: 2,165
|
Post by Lemon on Jun 4, 2018 18:07:47 GMT
This is untested but:
((Map<String, List<String>>) config.get("login-messages")
The enabled would need to be in a different section, or you need to make the admin and mod parts in a different section in the login-messages section like in this code (with the admin and mod parts section named messages):
((Map<String, List<String>>) config.get("login-messages.messages")
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jun 4, 2018 21:38:41 GMT
So now I get a NPE: [17:24:12 ERROR]: Could not pass event PlayerJoinEvent to Fuse v4.0.0 org.bukkit.event.EventException: null at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin(PlayerList.java:346) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:166) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:159) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:845) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at java.lang.Thread.run(Thread.java:844) [?:?] Caused by: java.lang.IllegalArgumentException: Permission name cannot be null at org.bukkit.permissions.PermissibleBase.hasPermission(PermissibleBase.java:66) ~[spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at org.bukkit.craftbukkit.v1_12_R1.entity.CraftHumanEntity.hasPermission(CraftHumanEntity.java:112) ~[spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] at us.flowdesigns.listener.LoginMessages.onPlayerJoin(LoginMessages.java:37) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:564) ~[?:?] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.12.2.jar:git-Spigot-2086bb0-8cc5a7e] ... 14 more the loginmessages is here: github.com/FuseMinecraft/Fuse/blob/master/src/main/java/us/flowdesigns/listener/LoginMessages.javaafaik it has something to do with the string part not being read correctly, so thats why it throws the npe it does detect that login messages are enabled but nothing past that
|
|
StevenNL2000
Forum Admin
Posts: 6,415
| Likes: 6,936
IGN: StevenNL2000
Timezone: UTC+01:00
Member is Staff. Need immediate assistance? Send a PM
|
Post by StevenNL2000 on Jun 5, 2018 11:39:45 GMT
You're including the boolean login-messages.enabled while iterating the rank names. Also, you should really cache those config reads unless you want the server to freeze for a short time every time someone joins.
|
|
Mafrans
Veteran Member
We assholes need to stick together, if you're a fellow asshole please pm me.
Posts: 1,760
| Likes: 1,703
|
Post by Mafrans on Jun 5, 2018 11:44:44 GMT
I managed to trace the error back to the if (player.hasPermission(plugin.getConfig().getString("login-messages." + string + ".permission"))) statement. You'll probably have to run a null check on the "wtf" variable, maybe something like this? if (wtf != null && player.hasPermission(wtf))
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jun 6, 2018 2:44:17 GMT
You're including the boolean login-messages.enabled while iterating the rank names. Also, you should really cache those config reads unless you want the server to freeze for a short time every time someone joins. Never heard of caching the config reads before, and server has never lagged because of that. So I got the plugin to read the strings in the login message part, but now i don't know how i will get it to add the .permission or .message part as it'll just return null (I tried using plugin.getConfig.get("server.login_messages_enabled." + groups2 + ".permission" and it doesn't seem to read it (source code updated on github)
|
|
StevenNL2000
Forum Admin
Posts: 6,415
| Likes: 6,936
IGN: StevenNL2000
Timezone: UTC+01:00
Member is Staff. Need immediate assistance? Send a PM
|
Post by StevenNL2000 on Jun 6, 2018 11:15:58 GMT
You're including the boolean login-messages.enabled while iterating the rank names. Also, you should really cache those config reads unless you want the server to freeze for a short time every time someone joins. Never heard of caching the config reads before, and server has never lagged because of that. So I got the plugin to read the strings in the login message part, but now i don't know how i will get it to add the .permission or .message part as it'll just return null (I tried using plugin.getConfig.get("server.login_messages_enabled." + groups2 + ".permission" and it doesn't seem to read it (source code updated on github) Well, yes, it's not lagging now, but it might when there are a lot of ranks because you're reading all of them synchronously each time someone logs in. Does the current GitHub implementation work? It looks like you updated it again. Also, you should know that Bukkit has a method for each primitive type that can be used in a config, e.g. boolean login_messages_enabled = plugin.getConfig().getBoolean("server.login_messages_enabled"); It looks a bit weird when you make everything a String.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jun 6, 2018 17:37:46 GMT
Never heard of caching the config reads before, and server has never lagged because of that. So I got the plugin to read the strings in the login message part, but now i don't know how i will get it to add the .permission or .message part as it'll just return null (I tried using plugin.getConfig.get("server.login_messages_enabled." + groups2 + ".permission" and it doesn't seem to read it (source code updated on github) Well, yes, it's not lagging now, but it might when there are a lot of ranks because you're reading all of them synchronously each time someone logs in. Does the current GitHub implementation work? It looks like you updated it again. Also, you should know that Bukkit has a method for each primitive type that can be used in a config, e.g. boolean login_messages_enabled = plugin.getConfig().getBoolean("server.login_messages_enabled"); It looks a bit weird when you make everything a String. I can't use booleans because they don't save in the config without having to entirely restart the server, and it breaks other commands
|
|
Mafrans
Veteran Member
We assholes need to stick together, if you're a fellow asshole please pm me.
Posts: 1,760
| Likes: 1,703
|
Post by Mafrans on Jun 6, 2018 22:35:57 GMT
Well, yes, it's not lagging now, but it might when there are a lot of ranks because you're reading all of them synchronously each time someone logs in. Allow me to quote the well respected computer scientist Michael A. Jackson: (From "Principles of program design") If that was not enough for you, here are some other respected computer scientists' opinions regarding the matter: - "Premature optimization is the root of all evil." - Sir Tony Hoare - "The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times." - Donald Knuth My point: get the entire thing actually working before trying to optimize it.
|
|
StevenNL2000
Forum Admin
Posts: 6,415
| Likes: 6,936
IGN: StevenNL2000
Timezone: UTC+01:00
Member is Staff. Need immediate assistance? Send a PM
|
Post by StevenNL2000 on Jun 6, 2018 22:48:45 GMT
Allow me to quote the well respected computer scientist Michael A. Jackson: (From "Principles of program design") If that was not enough for you, here are some other respected computer scientists' opinions regarding the matter: - "Premature optimization is the root of all evil." - Sir Tony Hoare - "The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times." - Donald Knuth My point: get the entire thing actually working before trying to optimize it. Optimization is a process. If you don't want to fix it, that's fine, but don't come to me if it starts lagging because you didn't bother to test the edge case someone gave you on a plate.
|
|
Mafrans
Veteran Member
We assholes need to stick together, if you're a fellow asshole please pm me.
Posts: 1,760
| Likes: 1,703
|
Post by Mafrans on Jun 6, 2018 22:52:22 GMT
Allow me to quote the well respected computer scientist Michael A. Jackson: (From "Principles of program design") If that was not enough for you, here are some other respected computer scientists' opinions regarding the matter: - "Premature optimization is the root of all evil." - Sir Tony Hoare - "The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times." - Donald Knuth My point: get the entire thing actually working before trying to optimize it. Optimization is a process. If you don't want to fix it, that's fine, but don't come to me if it starts lagging because you didn't bother to test the edge case someone gave you on a plate. Not saying your answer wasn't correct. Just reminding you that the system doesn't even work yet in the first place, and that there are other things to prioritize instead of optimization. I'm also fairly sure that the entire config is automatically cached when the plugin loads, as changes in the config file don't load until the plugin gets reloaded.
|
|
Lemon
Veteran Member
Insert status here.
Posts: 2,491
| Likes: 2,165
|
Post by Lemon on Jun 7, 2018 11:24:37 GMT
|
|