Punishments

Discussion in 'Plugin Development' started by jacobsscoots, Jul 23, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    jacobsscoots

    Hi there,

    I'm trying to code a plugin but my GUI isn't working when i do /punish {player}.

    Error in console:

    Code:
    [14:57:52 INFO]: SickNation issued server command: /punish YoloxSwagger
    [14:57:52 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'punish' in plugin Punishments v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-9797151-301db84]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-9797151-301db84]
            at org.bukkit.craftbukkit.v1_10_R1.CraftServer.dispatchCommand(CraftServer.java:646) ~[spigot.jar:git-Spigot-9797151-301db84]
            at net.minecraft.server.v1_10_R1.PlayerConnection.handleCommand(PlayerConnection.java:1351) [spigot.jar:git-Spigot-9797151-301db84]
            at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1186) [spigot.jar:git-Spigot-9797151-301db84]
            at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-9797151-301db84]
            at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-9797151-301db84]
            at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-9797151-301db84]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_91]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_91]
            at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-9797151-301db84]
            at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:737) [spigot.jar:git-Spigot-9797151-301db84]
            at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-9797151-301db84]
            at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:673) [spigot.jar:git-Spigot-9797151-301db84]
            at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:572) [spigot.jar:git-Spigot-9797151-301db84]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_10_R1.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:183) ~[spigot.jar:git-Spigot-9797151-301db84]
            at ml.sicknation.main.Main.onCommand(Main.java:39) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-9797151-301db84]
            ... 15 more

    Please help me below.

    Thanks, Jacob.
     
    Last edited: Jul 23, 2016
  2. Offline

    Caedus

    Just post your code here, if you actually want help.
     
  3. Offline

    jacobsscoots

    Main: http://pastebin.com/5ZKr0fXN

    GUI: http://pastebin.com/tTrf1ASm

    If possible please play around with my code and paste it back here after, as I'm not that good when it comes to programming language (such as arrays etc).
     
  4. Offline

    Caedus

    @jacobsscoots

    Hi, i'll give you a few pointers.

    People here won't generally spoon feed you code, rather tell you what's wrong and point to where to fix it.
    People here will also advise you to learn/become proficient Java first before diving into Bukkit.

    Now to some things I noticed in your code:

    As of right now in your code, you don't need to have your onEnable() or onDisable(), as nothing happens in them.
    It is generally considered bad practice to name your main class Main.
    You are blind casting sender to a player. What if console sent the command? Then you'd receive errors for days. Make sure you check that sender is an instanceof Player before casting.
    Your error is seemingly on line 39, where null is returned.

    Code:
    p.openInventory(ml.sicknation.gui.BanGUI.inv);
    On a different note, in your GUI class, on line 94:
    Code:
    if(a.equals(Action.PHYSICAL) || is == null || is.getType().equals(Material.BLAZE_ROD)){
    It should be a == Action.PHYSICAL and is.getType() == Material.BLAZE_ROD.

    (I'd like someone with more Java knowledge to confirm this, but I believe it has something to do with comparing objects with .equals() and using == for primitive types/enumerators.)

    I imagine i've skipped some errors or flaws, i'll post them if I notice them.
     
  5. Offline

    ipodtouch0218

    @jacobsscoots
    No one is going to spoonfeed you code.
    There is a NullPointerException on 39 (p.openInventory(ml.sicknation.gui.BanGUI.inv);)

    Which means "ml.sicknation.gui.BanGUI.inv" is null.

    EDIT: Ninja'd
     
  6. Offline

    jacobsscoots

    @Caedus

    How can I fix:
    Code:
    p.openInventory(ml.sicknation.gui.BanGUI.inv);
    if thats the main reason why its not working.
     
    Last edited: Jul 23, 2016
  7. Offline

    FrostedSnowman

    ml.sicknation.gui.BanGUI.inv

    is returning null.

    I'm not sure why you are reaching the value from the packages, get it from the class directly.

    • If you're going to get the inventory, then use the method you provided #getGUI, otherwise it has no point
    • The inventory can be declared private, considering the method mentioned above
    • You're not setting any values to the inventory or really initializing it anywhere
    • Make sure you are really defining getters and setters for values in the class

    Code:
    private static Inventory inv;
    
    inv = Bukkit.createInventory(..);
    
    public Inventory getInventory()
    {
         return inv;
    }
    
     
Thread Status:
Not open for further replies.

Share This Page