1.13.2 Can't figure out how to give player a permission via code

Discussion in 'Spigot Plugin Development' started by iTeChNoLoGiCi, Feb 9, 2020.

  1. I'm developing a plugin which makes part of player's inventory blocked.To do so,i coded it like this "if player has one of three permissions (level1,level2,level3),he can use one extra row of slots in his inventory (only hotbar is accesible by default).Else he will get glass panes that he can't interact with
    [​IMG]
    [​IMG]
    And in order to get the permission i have special "Inventory expander" item,which,upon use,removes glass from unlocked slots and *supposed* to give player a permission.But i can't figure out how to give player a permissions via code.
    I searched for guides,but basically all of them say same things(like in this -> https://www.spigotmc.org/threads/tutorial-giving-removing-player-permissions.53840/),and most of them <2017,so i thought maybe they're outdated.
    Following those guides (i refer to the one above and some youtube videos),i got console full of errors
    [13:48:58] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to InventoryResize v1.0
    org.bukkit.event.EventException: null
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:316) ~[server.jar:git-Spigot-1a3504a-a46fdbc]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:66) ~[server.jar:git-Spigot-1a3504a-a46fdbc]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:507) ~[server.jar:git-Spigot-1a3504a-a46fdbc]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:492) ~[server.jar:git-Spigot-1a3504a-a46fdbc]
    at org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:304) ~[server.jar:git-Spigot-1a3504a-a46fdbc]
    at net.minecraft.server.v1_13_R2.PlayerInteractManager.a(PlayerInteractManager.java:458) ~[server.jar:git-Spigot-1a3504a-a46fdbc]
    at net.minecraft.server.v1_13_R2.PlayerConnection.a(PlayerConnection.java:1222) ~[server.jar:git-Spigot-1a3504a-a46fdbc]
    at net.minecraft.server.v1_13_R2.PacketPlayInUseItem.a(PacketPlayInUseItem.java:37) ~[server.jar:git-Spigot-1a3504a-a46fdbc]
    at net.minecraft.server.v1_13_R2.PacketPlayInUseItem.a(PacketPlayInUseItem.java:1) ~[server.jar:git-Spigot-1a3504a-a46fdbc]
    at net.minecraft.server.v1_13_R2.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:9) ~[server.jar:git-Spigot-1a3504a-a46fdbc]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_191]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_191]
    at net.minecraft.server.v1_13_R2.SystemUtils.a(SourceFile:199) [server.jar:git-Spigot-1a3504a-a46fdbc]
    at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:896) [server.jar:git-Spigot-1a3504a-a46fdbc]
    at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417) [server.jar:git-Spigot-1a3504a-a46fdbc]
    at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:831) [server.jar:git-Spigot-1a3504a-a46fdbc]
    at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:729) [server.jar:git-Spigot-1a3504a-a46fdbc]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_191]
    Caused by: java.lang.NullPointerException
    at inventoryresize.inventoryresize.Commands.OnItemUse(Commands.java:20) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_191]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_191]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_191]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_191]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:312) ~[server.jar:git-Spigot-1a3504a-a46fdbc]
    ... 17 more
    "
    so i came here in search for help.

    Also,if you think there is a better way to make plugin work as intended than simple permission check,or if there are libraries which provide a simple way to give perms,i'd be happy to hear it,it's actually my first time coding a plugin so any help or advices are welcome.
     
  2. you can add permissions with vault
     
  3. Thanks,didn't know about that.
    Still,it would be nice to make plugin work without any dependencies (i assume if you use vault api you'll have to install vault as plugin on server too)
     
  4. md_5

    Administrator Developer

    • Agree Agree x 1