Help!

Discussion in 'Plugin Development' started by david123718, Sep 14, 2014.

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

    david123718

    Yes I am new to Eclipse Bukkit and I want to know why this isnt working please help!

    Plugin.yml:
    Code:
    main: me.david.Prickled.GUI
    version: 1.0
    name: Prickled
    author: david123718
    I have 2 classes:

    First Main Class:
    Code:java
    1. package me.david.Prickled;
    2.  
    3. import net.milkbowl.vault.economy.Economy;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.inventory.InventoryClickEvent;
    12. import org.bukkit.event.player.PlayerJoinEvent;
    13. import org.bukkit.inventory.Inventory;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.RegisteredServiceProvider;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. public class GUI extends JavaPlugin implements Listener {
    20.  
    21. public static Economy econ = null;
    22.  
    23. public void onEnable() {
    24. if (!setupEconomy() ) {
    25. getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    26. getServer().getPluginManager().disablePlugin(this);
    27. getServer().getPluginManager().registerEvents(this, this);
    28. return;
    29. }
    30. getServer().getPluginManager().registerEvents(this, this);
    31. }
    32.  
    33.  
    34. private boolean setupEconomy() {
    35. if (getServer().getPluginManager().getPlugin("Vault") == null ) {
    36. return false;
    37. }
    38. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    39. if (rsp == null) {
    40. }
    41. econ = rsp.getProvider();
    42. return econ != null;
    43. }
    44. private void teleportInWord(Player player, int x, int y, int z) {
    45. }
    46.  
    47. private void openGUI(Player player) {
    48. Inventory inv = Bukkit.createInventory(null, 9, ChatColor.GREEN
    49. + "Warp Selector");
    50.  
    51. ItemStack spawn = new ItemStack(Material.DIAMOND_SWORD);
    52. ItemMeta spawnMeta = spawn.getItemMeta();
    53. ItemStack mine = new ItemStack(Material.DIAMOND_PICKAXE);
    54. ItemMeta mineMeta = mine.getItemMeta();
    55. ItemStack skyblock = new ItemStack(Material.LOG);
    56. ItemMeta skyblockMeta = skyblock.getItemMeta();
    57.  
    58. spawnMeta.setDisplayName(ChatColor.AQUA + "Spawn");
    59. spawn.setItemMeta(spawnMeta);
    60.  
    61. mineMeta.setDisplayName(ChatColor.BLUE + "Mine");
    62. mine.setItemMeta(mineMeta);
    63.  
    64. skyblockMeta.setDisplayName(ChatColor.GOLD + "Skyblock");
    65. skyblock.setItemMeta(skyblockMeta);
    66.  
    67. inv.setItem(0, skyblock);
    68. inv.setItem(3, spawn);
    69. inv.setItem(5, mine);
    70.  
    71. player.openInventory(inv);
    72. }
    73. @EventHandler
    74. public void onInventoryClick(InventoryClickEvent event) {
    75. if (!ChatColor.stripColor(event.getInventory().getName())
    76. .equalsIgnoreCase("Warp Selector"))
    77. return;
    78. Player player = (Player) event.getWhoClicked();
    79. event.setCancelled(true);
    80.  
    81. if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR||!event.getCurrentItem().hasItemMeta()){
    82. player.closeInventory();
    83. return;
    84. }
    85. switch (event.getCurrentItem().getType()) {
    86. case DIAMOND_SWORD:
    87. player.chat("/spawn");
    88. player.closeInventory();
    89.  
    90. }
    91. switch (event.getCurrentItem().getType()) {
    92. case DIAMOND_PICKAXE:
    93. player.chat("/warp mine");
    94. player.closeInventory();
    95.  
    96. }
    97. switch (event.getCurrentItem().getType()) {
    98. case LOG:
    99. player.chat("/warp skyblock");
    100. player.closeInventory(); }
    101.  
    102. }
    103. @EventHandler
    104. public void onPlayerJoin(PlayerJoinEvent event) {
    105. event.getPlayer().getInventory().addItem(new ItemStack(Material.COMPASS));
    106. }
    107. }
    108.  



    Second Class:

    Code:java
    1. package me.david.Prickled;
    2.  
    3. import net.milkbowl.vault.economy.Economy;
    4. import net.milkbowl.vault.economy.EconomyResponse;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.entity.PlayerDeathEvent;
    10.  
    11. public class money {
    12. public static Economy econ = null;
    13.  
    14.  
    15. @EventHandler
    16. public void PlayerDeath(PlayerDeathEvent e){
    17. Player player = e.getEntity();
    18. Player killer = player.getKiller();
    19. EconomyResponse r = econ.depositPlayer(killer.getName(), 0.50);
    20. killer.sendMessage(ChatColor.BLUE + "You have earned 0.50 cents for killing " + player.getName() + ".");
    21. }
    22. }


    Console log:

    Code:
    [21:40:55] [Server thread/INFO]: Starting minecraft server version 1.7.9
    [21:40:56] [Server thread/INFO]: Loading properties
    [21:40:56] [Server thread/INFO]: Default game type: SURVIVAL
    [21:40:56] [Server thread/INFO]: Generating keypair
    [21:40:56] [Server thread/INFO]: Starting Minecraft server on *:25565
    [21:40:57] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks (MC: 1.7.9) (Implementing API version 1.7.9-R0.3-SNAPSHOT)
    [21:40:58] [Server thread/INFO]: [Prickled] Loading Prickled v1.0
    [21:40:58] [Server thread/INFO]: [Vault] Loading Vault v1.4.1-b436
    [21:40:58] [Server thread/INFO]: [Vault] Enabling Vault v1.4.1-b436
    [21:40:58] [Thread-7/WARN]: Could not get information about this CraftBukkit version; perhaps you are running a custom one?: IOException
    [21:40:58] [Server thread/INFO]: [Vault] [Permission] SuperPermissions loaded as backup permission system.
    [21:40:58] [Thread-7/WARN]: Could not get latest artifact information: IOException
    [21:40:58] [Server thread/INFO]: [Vault] Enabled Version 1.4.1-b436
    [21:40:58] [Server thread/INFO]: Preparing level "world"
    [21:40:58] [Server thread/INFO]: Preparing start region for level 0 (Seed: -1797287879248858028)
    [21:40:59] [Server thread/INFO]: Preparing spawn area: 4%
    [21:41:00] [Server thread/INFO]: Preparing spawn area: 38%
    [21:41:01] [Server thread/INFO]: Preparing spawn area: 69%
    [21:41:02] [Server thread/INFO]: Preparing start region for level 1 (Seed: -1797287879248858028)
    [21:41:03] [Server thread/INFO]: Preparing spawn area: 62%
    [21:41:04] [Server thread/INFO]: Preparing start region for level 2 (Seed: -1797287879248858028)
    [21:41:05] [Server thread/INFO]: [Prickled] Enabling Prickled v1.0
    [21:41:05] [Server thread/ERROR]: Error occurred while enabling Prickled v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at me.david.Prickled.GUI.setupEconomy(GUI.java:41) ~[?:?]
        at me.david.Prickled.GUI.onEnable(GUI.java:24) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugin(CraftServer.java:455) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.enablePlugins(CraftServer.java:389) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.n(MinecraftServer.java:352) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.g(MinecraftServer.java:326) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.a(MinecraftServer.java:282) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.init(DedicatedServer.java:182) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:436) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
    [21:41:05] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [21:41:05] [Server thread/INFO]: Done (6.903s)! For help, type "help" or "?"
    [21:41:09] [pool-3-thread-2/INFO]: [Vault] Checking for Updates:
    [21:41:09] [pool-3-thread-2/INFO]: [Vault] No new version available
    [21:41:48] [Server thread/INFO]: CONSOLE: Stopping the server..[m
    [21:41:48] [Server thread/INFO]: Stopping server
    [21:41:48] [Server thread/INFO]: [Vault] Disabling Vault v1.4.1-b436
    [21:41:48] [Server thread/INFO]: [Prickled] Disabling Prickled v1.0
    [21:41:48] [Server thread/INFO]: Saving players
    [21:41:48] [Server thread/INFO]: Saving worlds
    [21:41:48] [Server thread/INFO]: Saving chunks for level 'world'/Overworld
    [21:41:48] [Server thread/INFO]: Saving chunks for level 'world_nether'/Nether
    [21:41:48] [Server thread/INFO]: Saving chunks for level 'world_the_end'/The End
    [21:41:48] [Thread-4/INFO]: Stopping server
    [21:41:48] [Thread-4/INFO]: Saving players
    [21:41:48] [Thread-4/INFO]: Saving worlds
    [21:41:48] [Thread-4/INFO]: Saving chunks for level 'world'/Overworld
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  2. Offline

    teej107

  3. Offline

    david123718

    I found the problem at line 24 and 41 I just dont know how to fix it i tried fixing it but no idea how
     
  4. Offline

    Totom3

    david123718
    Code:java
    1. if (rsp == null) {
    2. }
    3. econ = rsp.getProvider();

    You forgot to return false or do stuff inside the if statement, so that the line 41 doesn't get executed if rsp is null.
     
  5. Offline

    david123718

    This didnt work Here is the code
    Code:java
    1. public void onEnable() {
    2. if (!setupEconomy() ) {
    3. getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    4. getServer().getPluginManager().disablePlugin(this);
    5. getServer().getPluginManager().registerEvents(this, this);
    6. return;
    7. }
    8. getServer().getPluginManager().registerEvents(this, this);
    9. }
    10.  
    11.  
    12. private boolean setupEconomy() {
    13. if (getServer().getPluginManager().getPlugin("Vault") == null ) {
    14. return false;
    15. }
    16. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    17. if (rsp == null) {
    18. }
    19. econ = rsp.getProvider();
    20. return false;
    21. }


    Console error:

    Code:
    [21:40:10] [Server thread/INFO]: Starting minecraft server version 1.7.9
    [21:40:10] [Server thread/INFO]: Loading properties
    [21:40:10] [Server thread/INFO]: Default game type: SURVIVAL
    [21:40:10] [Server thread/INFO]: Generating keypair
    [21:40:10] [Server thread/INFO]: Starting Minecraft server on *:25565
    [21:40:11] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks (MC: 1.7.9) (Implementing API version 1.7.9-R0.3-SNAPSHOT)
    [21:40:11] [Server thread/INFO]: [Prickled] Loading Prickled v1.0
    [21:40:11] [Server thread/INFO]: [Vault] Loading Vault v1.4.1-b436
    [21:40:11] [Server thread/INFO]: [Vault] Enabling Vault v1.4.1-b436
    [21:40:11] [Thread-7/WARN]: Could not get information about this CraftBukkit version; perhaps you are running a custom one?: IOException
    [21:40:11] [Server thread/INFO]: [Vault] [Permission] SuperPermissions loaded as backup permission system.
    [21:40:11] [Server thread/INFO]: [Vault] Enabled Version 1.4.1-b436
    [21:40:11] [Server thread/INFO]: Preparing level "world"
    [21:40:11] [Thread-7/WARN]: Could not get latest artifact information: IOException
    [21:40:11] [Server thread/INFO]: Preparing start region for level 0 (Seed: -1797287879248858028)
    [21:40:12] [Server thread/INFO]: Preparing spawn area: 13%
    [21:40:13] [Server thread/INFO]: Preparing spawn area: 74%
    [21:40:13] [Server thread/INFO]: Preparing start region for level 1 (Seed: -1797287879248858028)
    [21:40:14] [Server thread/INFO]: Preparing spawn area: 68%
    [21:40:15] [Server thread/INFO]: Preparing start region for level 2 (Seed: -1797287879248858028)
    [21:40:15] [Server thread/INFO]: [Prickled] Enabling Prickled v1.0
    [21:40:15] [Server thread/ERROR]: Error occurred while enabling Prickled v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at me.david.Prickled.GUI.setupEconomy(GUI.java:41) ~[?:?]
        at me.david.Prickled.GUI.onEnable(GUI.java:24) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugin(CraftServer.java:455) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.enablePlugins(CraftServer.java:389) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.n(MinecraftServer.java:352) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.g(MinecraftServer.java:326) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.a(MinecraftServer.java:282) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.init(DedicatedServer.java:182) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:436) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
    [21:40:15] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [21:40:16] [Server thread/INFO]: Done (4.381s)! For help, type "help" or "?"
    [21:40:17] [pool-3-thread-2/INFO]: [Vault] Checking for Updates:
    [21:40:17] [pool-3-thread-2/INFO]: [Vault] No new version available
    [21:40:18] [Server thread/INFO]: CONSOLE: Stopping the server..
    [21:40:18] [Server thread/INFO]: Stopping server
    [21:40:18] [Server thread/INFO]: [Vault] Disabling Vault v1.4.1-b436
    [21:40:18] [Server thread/INFO]: [Prickled] Disabling Prickled v1.0
    [21:40:18] [Server thread/INFO]: Saving players
    [21:40:18] [Server thread/INFO]: Saving worlds
    [21:40:18] [Server thread/INFO]: Saving chunks for level 'world'/Overworld
    [21:40:19] [Server thread/INFO]: Saving chunks for level 'world_nether'/Nether
    [21:40:20] [Server thread/INFO]: Saving chunks for level 'world_the_end'/The End
    [21:40:20] [Thread-4/INFO]: Stopping server
    [21:40:20] [Thread-4/INFO]: Saving players
    
     
  6. Offline

    david123718

  7. Offline

    Da_Co0k1eZ

    Add in a null check first of all, and whatever variable rsp.getProvider() is returning something that is null.

    Null check:
    Code:java
    1. if(rsp.getProvider() != null) {
    2. //code
    3. }
    4.  
     
  8. Offline

    david123718

    this did not work new code:
    Code:java
    1.  
    2.  
    3. public void onEnable() {
    4. if (!setupEconomy() ) {
    5. getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    6. getServer().getPluginManager().disablePlugin(this);
    7. getServer().getPluginManager().registerEvents(this, this);
    8. return;
    9. }
    10. getServer().getPluginManager().registerEvents(this, this);
    11. }
    12.  
    13.  
    14. private boolean setupEconomy() {
    15. if (getServer().getPluginManager().getPlugin("Vault") == null ) {
    16. return false;
    17. }
    18. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    19. if(rsp.getProvider() != null) {
    20. }
    21. return false;
    22. }
     
  9. Offline

    Skionz

    david123718 You are getting a null pointer error which are super annoying. Anyway to get rid of it just check if something equals null before checking for a value.
     
  10. Offline

    david123718

    I did equal Null still doesnt work Look at my code
     
  11. Offline

    Da_Co0k1eZ

    david123718
    Also, why are you registering events even though your plugin is disabled?
    And from what I can tell, you need to be checking if the entire variable rsp is null, not just the get provider portion of it.
     
  12. Offline

    david123718

    The one in the code is from I know the only one
     
  13. Offline

    Totom3

    david123718
     
  14. Offline

    david123718

    Im getting errors by setupEconomy please give me a example
     
  15. Offline

    david123718

  16. Offline

    Skionz

  17. Offline

    MineStein

    When writing a forum post, please consider professionalism. Ensure you have an adequate title so that the developers can help you. I recommend you do the following:
    - Write what you are trying to achieve.
    - Read the stacktrace and be sure to check the line number included.
    - Include what you think the problem is.
    - Post the code.
    - Post the stack trace (not the entire log).

    Thanks.
     
  18. Offline

    david123718

    Ok can i just have help for now
     
  19. Offline

    MineStein

    I use my own economy plugins. I have no idea pertaining to your problem.
     
  20. Offline

    Totom3

    david123718 I gave you the solution already You forgot to end the method in the if statement.
    Code:java
    1. if (rsp == null) {
    2. logger.severe("Economy Service Provider is null.");
    3. return false;
    4. }
     
  21. Offline

    david123718

    Code:java
    1.  
     
  22. Skionz I don't find NPEs that annoying - they only happen because someone somewhere made a mistake. And if I'm going to get an exception, NullPointerException would probably be the one I'm hoping for.

    david123718 Please learn Java before trying to make a plugin otherwise things go wrong. The fact that you're having trouble with a method that is literally provided to you is definitely proof of this.
     
  23. Offline

    david123718

    I know java I am very confused about this I followed the exact method and did not work.
     
  24. Offline

    Skionz

    AdamQpzm That's true I would rather have an NPE than anything else but they are just annoying when you make a stupid mistake and have to reload the test server and export it and everything.
     
  25. Offline

    david123718

  26. Offline

    AronTheGamer

    'Understanding java' means more than being able to make a text based calculator, my friend.

    Before you start on developing a plugin using an API, take some time and read the API documentation. This site gives a lot of information about all the methods available in the Bukkit API.

    You should also know some things about bugfixing. The best thing to do is learn proper english first. When you don't know the meaning of words like 'false', 'exception', 'reference' and others, it will be fairly difficult to understand a complex syntax that is made out of special characters like {, ", || and $ rather than normal, human understandable words.

    You already noticed the RSP seemed to be null, meaning: it couldn't find the object the reference named 'rsp' was pointing too, probably because it didn't ... exist.

    Before you are including any dependencies in your projects, make sure you are loading them too. It might be the case Vault is just not in the plugins directory of your server...

    It's always useful to write down things you do wrong (and maybe the solution), and save them on a place you can easily find them back when you do something wrong again.

    I hope this had helped you a little bit, and as always, thanks for watching.

    Oops, no no no, I'm not Vsauce.
     
    Totom3 likes this.
  27. Offline

    david123718

    bump did not help
     
  28. Offline

    Totom3

    david123718 You aren't helping either... We gave you the solution 10 times + explanation for the NPE + AronTheGamer took 5 hours to tell you exactly what's wrong AND give you tips to progress... What can we do more ? Read again our posts, if you chose not to learn Java, then it's your fault if no one can help you, you basically decided to write a book in Chinese without knowing Chinese...

    Now before you say "BUMP your no helping either" look at my last post.
     
  29. Offline

    david123718

    I looked at it its not working im getting errors
     
Thread Status:
Not open for further replies.

Share This Page