How to create a sort of virtual furnace?

Discussion in 'Plugin Development' started by iPoke111, Aug 14, 2013.

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

    iPoke111

    What I am trying to achieve here is making a furnace that players can open with a command. Say if Player1 types /furnace, the furnace GUI will appear and then they can smelt things in it, but if Player2 types /furnace, it opens the same furnace with the same items, sort of like a shared furnace.
    It is currently working for a workbench (although you can't share the workbench) but not for my furnace. I will post the relevant code for my furnace and my workbench.

    Workbench code:
    Code:java
    1. public InventoryType WORKBENCH;
    2. //stuff
    3. if(commandLabel.equalsIgnoreCase("bench"))
    4. {
    5. if(!p.hasPermission("pokereaper.craft"))
    6. {
    7. p.sendMessage(ChatColor.RED + "You don't have the permission " + ChatColor.YELLOW + "pokereaper.craft" + ChatColor.RED + ".");
    8. }
    9. else
    10. {
    11. Inventory craft = p.getServer().createInventory(null, WORKBENCH);
    12. p.openInventory(craft);
    13. }
    14. }


    Furnace code:
    Code:java
    1. public InventoryType FURNACE;
    2. public static int y = 1;
    3. //stuff
    4. if(commandLabel.equalsIgnoreCase("furnace"))
    5. {
    6. if(!p.hasPermission("pokereaper.craft"))
    7. {
    8. p.sendMessage(ChatColor.RED + "You don't have the permission " + ChatColor.YELLOW + "pokereaper.craft" + ChatColor.RED + ".");
    9. }
    10. else
    11. {
    12. if(y == 1)
    13. {
    14. furnace = p.getServer().createInventory(null, FURNACE);
    15. y = 0;
    16. }
    17. p.openInventory(furnace);
    18. }
    19. }


    Any clue why this doesn't work? When I type /bench, it works perfectly but when I type /furnace, it throws an error in the console and displays 'An internal error occurred while attempting to perform this command' in my chat.

    Thanks for taking the time to look at this ^^

    ~honk
     
  2. Offline

    Shzylo

    iPoke111 when it says 'An internal error occurred while attempting to perform this command' it should throw an error in the console, please tell us what that says.
     
  3. Offline

    iPoke111

    alright. Also, now my bench code doesn't work >_<

    I'll post it here
    Code:
    [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'bench' in plugin Reaper v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServer.java:523)
        at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerConnection.java:964)
        at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.java:882)
        at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:839)
        at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
        at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
        at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:118)
        at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
        at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventoryCustom$MinecraftInventory.<init>(CraftInventoryCustom.java:37)
        at org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventoryCustom.<init>(CraftInventoryCustom.java:17)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.createInventory(CraftServer.java:1264)
        at me.iPoke111.reaper.Reaper.onCommand(Reaper.java:127)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
    2013-08-14 14:54:01 [INFO] iPoke111 issued server command: /furnace
    2013-08-14 14:54:01 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'furnace' in plugin Reaper v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServer.java:523)
        at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerConnection.java:964)
        at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.java:882)
        at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:839)
        at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
        at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
        at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:118)
        at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
        at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventoryCustom$MinecraftInventory.<init>(CraftInventoryCustom.java:37)
        at org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventoryCustom.<init>(CraftInventoryCustom.java:17)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.createInventory(CraftServer.java:1264)
        at me.iPoke111.reaper.Reaper.onCommand(Reaper.java:141)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
     
  4. Offline

    Shzylo

    In your Workbench error, you get this line:
    Code:
    me.iPoke111.reaper.Reaper.onCommand(Reaper.java:127)
    Look at line 127 of your Reaper class and tell us what it is, because it is NULL

    In your Furnace error, you get this line:
    Code:
    me.iPoke111.reaper.Reaper.onCommand(Reaper.java:141)
    Another NULL :)

    So if you can paste your whole code with the java=syntax instead of code it will tell us each line easier or you can just tell us which lines are which.
     
  5. Offline

    iPoke111

    ok then c:
    I will post the relevant blocks again, but with line numbers
    code:
    Code:java
    1. if(commandLabel.equalsIgnoreCase("bench"))
    2. {
    3. if(!p.hasPermission("pokereaper.craft"))
    4. {
    5. p.sendMessage(ChatColor.RED + "You don't have the permission " + ChatColor.YELLOW + "pokereaper.craft" + ChatColor.RED + ".");
    6. }
    7. else
    8. {
    9. 127 Inventory craft = p.getServer().createInventory(null, WORKBENCH);
    10. p.openInventory(craft);
    11. }
    12. }
    13. if(commandLabel.equalsIgnoreCase("furnace"))
    14. {
    15. if(!p.hasPermission("pokereaper.craft"))
    16. {
    17. p.sendMessage(ChatColor.RED + "You don't have the permission " + ChatColor.YELLOW + "pokereaper.craft" + ChatColor.RED + ".");
    18. }
    19. else
    20. {
    21. if(y == 1)
    22. {
    23. 141 furnace = p.getServer().createInventory(null, FURNACE);
    24. y = 0;
    25. }
    26. p.openInventory(furnace);
    27. }
    28. }
     
  6. iPoke111
    use
    Code:
    Inventory furnace = p.getServer().createInventory(null, FURNACE);
    
     
  7. Offline

    iPoke111

    ^ I have a field set up earlier as public InventoryType WORKBENCH (also with FURNACE) and also a field Inventory furnace; so I don't need to define it as a variable. I got help though, thanks ^^
     
  8. Offline

    bobacadodl

    I'm guessing that your player variable (p) is null. Could you post your entire onCommand method?
     
  9. Offline

    iPoke111

    I apprectiate your trying to help, but I already got help and sorted it out. Both the workbench and the furnace are now working. Only thing I need to do now is get the furnace to smelt, as it is not doing that currently. It is just showing the window.
     
  10. Offline

    herpingdo

    Have you ever heard of a boolean? Google it, and stop using an int.
     
  11. Offline

    iPoke111

    .-. ok. I am new to Java and am just trying to work my way around a code. I know that its definitely not the most efficient way of coding this, but it works, and when I actually get decent at Java I will make all my code efficient. I will change it, but I'm still very new here ^^
     
  12. Offline

    theminerrick

    it's must be
    Code:
    Inventory furnace = Bukkit.createInventory(null, InventoryType.FURNACE);
    sorry for my bad english iam from holland
     
  13. Offline

    iPoke111

    theminerrick
    I appreciate the help, but that's kind of a necrobump .-.
     
  14. Offline

    Kassestral

    iPoke111
    If this thread is solved changed it to solved, means people wont keep posting :D
     
Thread Status:
Not open for further replies.

Share This Page