Vault API

Discussion in 'Plugin Development' started by ProMCKingz, Aug 26, 2014.

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

    ProMCKingz

    Hey there,
    I have come accross this error message that I receive in console.
    PHP:
    [22:06:03 ERROR]: Error occurred while enabling WardrobePlus v1.0 (Is it up to d
    ate
    ?)
    java.lang.NullPointerException
            at me
    .ProMCKingz.Hope.ClickListener.<init>(ClickListener.java:19) ~[?:?]
     
            
    at me.ProMCKingz.Hope.CompassPort.onEnable(CompassPort.java:41) ~[?:?]
            
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:250) ~[c
    raftbukkit
    .jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:324) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r
    .java:404) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(CraftServer.jav
    a
    :439) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(CraftServer.
    java:375) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at net.minecraft.server.v1_7_R1.MinecraftServer.m(MinecraftServer.java:3
    42
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at net.minecraft.server.v1_7_R1.MinecraftServer.g(MinecraftServer.java:3
    19
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at net.minecraft.server.v1_7_R1.MinecraftServer.a(MinecraftServer.java:2
    75
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.jav
    a
    :175) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :424) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    This is my code (Note: I am trying this in a class, which is NOT my main class!) Also, I have only shown the bits that are the problem.
    Code:java
    1. public class ClickListener implements Listener {
    2.  
    3. SettingsManager settings = SettingsManager.getInstance();
    4. CompassPort CP = CompassPort.getInstance();
    5. CompassPort plugin;
    6. public int Beacon = plugin.config.getInt("Teleport_Cost");
    7. public ClickListener(CompassPort instance) {
    8. plugin = instance;
    9. }
    10.  
    11. @EventHandler
    12. //Code above, not shown - for clearer view of the problem itself.
    13. } if (clicked.getType() == Material.BEACON) {
    14. player.closeInventory();
    15. String pn = player.getName();
    16. if(CP.economy.getBalance(pn)>=Beacon){
    17. EconomyResponse er = CP.economy.withdrawPlayer(pn, Beacon);
    18. if(er.transactionSuccess()){
    19. settings.getData().set(player.getName() + " .z", player.getLocation().getBlockZ());
    20. settings.getData().set(player.getName() + " .y", player.getLocation().getBlockY());
    21. settings.getData().set(player.getName() + " .x", player.getLocation().getBlockX());
    22. CompassPort.setTarget(player.getLocation());
    23. plugin.saveConfig();
    24. plugin.reloadConfig();
    25.  
    26. player.closeInventory();
    27. player.sendMessage(ChatColor.GOLD
    28. + plugin.config.getString("Teleport_Update_Message".replaceAll("(&([a-f0-9]))", "\u00A7$2")));
    29. }
    30. + "Point not yet set!");
    31. //code below, not shown
    32. }

    This is my main file (onEnable):
    Code:java
    1. public class CompassPort extends JavaPlugin {
    2. final FileConfiguration config = this.getConfig();
    3. private static Location targetPoint = null;
    4. public static Economy economy = null;
    5. SettingsManager settings = SettingsManager.getInstance();
    6. private boolean setupEconomy()
    7. {
    8. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    9. if (economyProvider != null) {
    10. economy = economyProvider.getProvider();
    11. }
    12.  
    13. return (economy != null);
    14. }
    15. @Override
    16. public void onEnable() {
    17. CompassPort.getTarget();
    18. String BukkitV = Bukkit.getBukkitVersion();
    19. getLogger().info("Wardrobe is currently running on" + BukkitV);
    20. getLogger().warning("Thanks for supporting this plugin, and keep supporting us, by downloading our new versions!");
    21. getServer().getPluginManager().registerEvents(new InteractListener(), this);
    22. getServer().getPluginManager().registerEvents(new ClickListener(this), this);
    23. getCommand("wardrobe").setExecutor(new ConsoleListener());
    24. getCommand("wardrobe").setExecutor(new Commands(this));
    25. settings.setup(this);
    26. getConfig().options().copyDefaults(true);
    27. saveDefaultConfig();
    28. if(!setupEconomy()){
    29. getLogger().severe("THE PLUGIN REQUIRES VAULT, IN ORDER TO FUNCTION CORRECTLY");
    30.  
    31. }
    32. }

    Also note, that I do not get the error after I remove my vault changes. Please also note that, there are no error on eclipse, however there are yellow line suppression errors on
    Code:java
    1. if(CP.economy.getBalance(pn)>=Beacon){
    2. EconomyResponse er = CP.economy.withdrawPlayer(pn, Beacon);

    Thanks!
     
  2. Offline

    _LB

    What are lines 41 and 19?
     
  3. Offline

    ProMCKingz

    _LB Where? in my main or my ClickListener Class?
    Click Listener: Line 19:
    Code:java
    1. public int Beacon = plugin.config.getInt("Teleport_Cost");

    Line:41
    Code:java
    1. player.sendMessage(ChatColor.GOLD + "You now have a" + ChatColor.AQUA + " Diamond Helmet!");


    Main: Line 19:
    Code:java
    1. public class CompassPort extends JavaPlugin {

    Line 41:
    Code:java
    1. getCommand("wardrobe").setExecutor(new ConsoleListener());
     
  4. Offline

    MnMaxon

    ProMCKingz
    I think the problem is here:
    Code:java
    1. public int Beacon = plugin.config.getInt("Teleport_Cost");

    Plugin equals null. You haven't set it to anything yet.
     
  5. Offline

    _LB

    Just to be extra sure, recompile your plugin and make sure you're using the latest JAR to reproduce the stack trace again. MnMaxon probably has the right idea though.
     
  6. Offline

    1Rogue


    Close.

    config is null because the "config" field is set upon the class instantiation, where .getConfig() will return null. Don't initialize plugin fields outside of your onEnable bar excruciating circumstances.
     
  7. Offline

    ProMCKingz

    1Rogue
    What do you mean?
    So how can I make it take money, and be editable in the config?
     
  8. Offline

    MnMaxon

    I think what 1Rogue was saying to do this
    Code:java
    1. public class CompassPort extends JavaPlugin {
    2. FileConfiguration config;//This was moved
    3. private static Location targetPoint = null;
    4. public static Economy economy = null;
    5. SettingsManager settings = SettingsManager.getInstance();
    6. private boolean setupEconomy()
    7. {
    8. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    9. if (economyProvider != null) {
    10. economy = economyProvider.getProvider();
    11. }
    12.  
    13. return (economy != null);
    14. }
    15. @Override
    16. public void onEnable() {
    17. CompassPort.getTarget();
    18. String BukkitV = Bukkit.getBukkitVersion();
    19. getLogger().info("Wardrobe is currently running on" + BukkitV);
    20. getLogger().warning("Thanks for supporting this plugin, and keep supporting us, by downloading our new versions!");
    21. config = this.getConfig();//This was moved from up top
    22. getServer().getPluginManager().registerEvents(new InteractListener(), this);
    23. getServer().getPluginManager().registerEvents(new ClickListener(this), this);
    24. getCommand("wardrobe").setExecutor(new ConsoleListener());
    25. getCommand("wardrobe").setExecutor(new Commands(this));
    26. settings.setup(this);
    27. getConfig().options().copyDefaults(true);
    28. saveDefaultConfig();
    29. if(!setupEconomy()){
    30. getLogger().severe("THE PLUGIN REQUIRES VAULT, IN ORDER TO FUNCTION CORRECTLY");
    31.  
    32. }
    33. }


    I think you should also make this change to your Listener class:
    Code:java
    1. public class ClickListener implements Listener {
    2.  
    3. SettingsManager settings = SettingsManager.getInstance();
    4. CompassPort CP = CompassPort.getInstance();
    5. CompassPort plugin;
    6. public int Beacon;//This was moved
    7. public ClickListener(CompassPort instance) {
    8. plugin = instance;
    9. Beacon= plugin.config.getInt("Teleport_Cost"); //This was moved from the top
    10. }
    11.  
    12. @EventHandler
    13. } if (clicked.getType() == Material.BEACON) {
    14. player.closeInventory();
    15. String pn = player.getName();
    16. if(CP.economy.getBalance(pn)>=Beacon){
    17. EconomyResponse er = CP.economy.withdrawPlayer(pn, Beacon);
    18. if(er.transactionSuccess()){
    19. settings.getData().set(player.getName() + " .z", player.getLocation().getBlockZ());
    20. settings.getData().set(player.getName() + " .y", player.getLocation().getBlockY());
    21. settings.getData().set(player.getName() + " .x", player.getLocation().getBlockX());
    22. CompassPort.setTarget(player.getLocation());
    23. plugin.saveConfig();
    24. plugin.reloadConfig();
    25.  
    26. player.closeInventory();
    27. player.sendMessage(ChatColor.GOLD
    28. + plugin.config.getString("Teleport_Update_Message".replaceAll("(&([a-f0-9]))", "\u00A7$2")));
    29. }
    30. + "Point not yet set!");
    31. //code below, not shown
    32. }
     
  9. Offline

    ProMCKingz

    MnMaxon
    That does get rid of the error.
    However now my ClickListener class will not function at all.
    Here is the full code update:
    Click Listener:
    Code:java
    1. package me.ProMCKingz.Hope;
    2.  
    3. import net.milkbowl.vault.economy.EconomyResponse;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.HumanEntity;
    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.inventory.ItemStack;
    13.  
    14. public class ClickListener implements Listener {
    15.  
    16. SettingsManager settings = SettingsManager.getInstance();
    17. CompassPort CP = CompassPort.getInstance();
    18. CompassPort plugin;
    19. public int Beacon;//This was moved
    20. public ClickListener(CompassPort instance) {
    21. plugin = instance;
    22. Beacon= plugin.config.getInt("Teleport_Cost"); //This was moved from the top
    23. }
    24.  
    25. @EventHandler
    26. public void onClick(InventoryClickEvent event) {
    27. HumanEntity entity = event.getWhoClicked();
    28. if ((entity instanceof Player)) {
    29. Player player = (Player) entity;
    30. if (event.getInventory().getName()
    31. .equals(CompassPort.getCompassInventory().getName())) {
    32. event.setCancelled(true);
    33. ItemStack clicked = event.getCurrentItem();
    34. if (clicked != null) {
    35. if (clicked.getType() == Material.DIAMOND_HELMET) {
    36. if (player.getEquipment().getHelmet().equals(Material.DIAMOND_HELMET)){
    37. player.sendMessage(ChatColor.RED + "You already have a diamond helmet!");
    38. }
    39. else {
    40. player.closeInventory();
    41. player.getEquipment().setHelmet (new ItemStack (Material.DIAMOND_HELMET));
    42. player.sendMessage(ChatColor.GOLD + "You now have a" + ChatColor.AQUA + " Diamond Helmet!");
    43. }
    44. } else if (clicked.getType() == Material.ENDER_PEARL) {
    45. player.closeInventory();
    46. if (CompassPort.getTarget() != null) {
    47. player.teleport(CompassPort.getTarget());
    48. player.sendMessage(plugin.config.getString("Teleport_Message".replaceAll("§", "&")));
    49. return;
    50. } else {
    51. player.sendMessage(ChatColor.RED
    52. + "Point not yet set!");
    53. }
    54. } else if (clicked.getType() == Material.GOLD_HELMET) {
    55. player.closeInventory();
    56. }
    57. } if (clicked.getType() == Material.BEACON) {
    58. player.closeInventory();
    59. String pn = player.getName();
    60. if(CP.economy.getBalance(pn)>=Beacon){
    61. EconomyResponse er = CP.economy.withdrawPlayer(pn, Beacon);
    62. if(er.transactionSuccess()){
    63. settings.getData().set(player.getName() + " .z", player.getLocation().getBlockZ());
    64. settings.getData().set(player.getName() + " .y", player.getLocation().getBlockY());
    65. settings.getData().set(player.getName() + " .x", player.getLocation().getBlockX());
    66. CompassPort.setTarget(player.getLocation());
    67. plugin.saveConfig();
    68. plugin.reloadConfig();
    69.  
    70. player.closeInventory();
    71. player.sendMessage(ChatColor.GOLD
    72. + plugin.config.getString("Teleport_Update_Message".replaceAll("(&([a-f0-9]))", "\u00A7$2")));
    73. }
    74. if (clicked.getType() == Material.GOLD_HELMET) {
    75. player.closeInventory();
    76. player.openInventory(SubHelmet.getHelmetInventory());
    77. }
    78. if (clicked.getType() == Material.GOLD_CHESTPLATE){
    79. player.closeInventory();
    80. player.openInventory(SubChestPlate.getChestplateInventory());
    81. }
    82. if (clicked.getType() == Material.GOLD_LEGGINGS){
    83. player.closeInventory();
    84. player.openInventory(SubLeggings.getLeggingsInventory());
    85. }
    86. if (clicked.getType() == Material.GOLD_BOOTS){
    87. player.closeInventory();
    88. player.openInventory(SubBoots.getBootsInventory());
    89. }
    90. if (clicked.getType() == Material.BOWL){
    91. player.closeInventory();
    92. }
    93. if (clicked.getType() == Material.CARPET){
    94. player.closeInventory();
    95. player.getEquipment().setHelmet(null);
    96. player.getEquipment().setChestplate(null);
    97. player.getEquipment().setLeggings(null);
    98. player.getEquipment().setBoots(null);
    99. }
    100. if (clicked.getType() == Material.NETHER_STAR){
    101. player.closeInventory();
    102. player.sendMessage(ChatColor.DARK_AQUA + "[Wardrobe+] " + ChatColor.RED + "This feature will be added in a future update!");
    103. }
    104. if (clicked.getType() == Material.GLASS){
    105. player.closeInventory();
    106. player.sendMessage(ChatColor.DARK_AQUA + "[Wardrobe+] " + ChatColor.RED + "This feature will be added in a future update!");
    107. }
    108. if (clicked.getType() == Material.TRAPPED_CHEST){
    109. player.closeInventory();
    110. player.sendMessage(ChatColor.DARK_AQUA + "[Wardrobe+] " + ChatColor.RED + "This feature will be added in a future update!");
    111. }
    112. }
    113. }
    114. }
    115. }
    116. }
    117. }

    Main:
    Code:java
    1. package me.ProMCKingz.Hope;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import net.milkbowl.vault.economy.Economy;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.Location;
    11. import org.bukkit.Material;
    12. import org.bukkit.configuration.file.FileConfiguration;
    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 CompassPort extends JavaPlugin {
    20. FileConfiguration config;// This was moved
    21. private static Location targetPoint = null;
    22. public static Economy economy = null;
    23. SettingsManager settings = SettingsManager.getInstance();
    24.  
    25. private boolean setupEconomy() {
    26. RegisteredServiceProvider<Economy> economyProvider = getServer()
    27. .getServicesManager().getRegistration(
    28. net.milkbowl.vault.economy.Economy.class);
    29. if (economyProvider != null) {
    30. economy = economyProvider.getProvider();
    31. }
    32.  
    33. return (economy != null);
    34. }
    35.  
    36. @Override
    37. public void onEnable() {
    38. CompassPort.getTarget();
    39. String BukkitV = Bukkit.getBukkitVersion();
    40. getLogger().info("Wardrobe is currently running on" + BukkitV);
    41. getLogger()
    42. .warning(
    43. "Thanks for supporting this plugin, and keep supporting us, by downloading our new versions!");
    44. config = this.getConfig();// This was moved from up top
    45. getServer().getPluginManager().registerEvents(new InteractListener(),
    46. this);
    47. getServer().getPluginManager().registerEvents(new ClickListener(this),
    48. this);
    49. getCommand("wardrobe").setExecutor(new ConsoleListener());
    50. getCommand("wardrobe").setExecutor(new Commands(this));
    51. settings.setup(this);
    52. getConfig().options().copyDefaults(true);
    53. saveDefaultConfig();
    54. if (!setupEconomy()) {
    55. getLogger()
    56. .severe("THE PLUGIN REQUIRES VAULT, IN ORDER TO FUNCTION CORRECTLY");
    57.  
    58. }
    59. }
    60.  
    61. @Override
    62. public void onDisable() {
    63. if (config == null) {
    64. getLogger().warning(
    65. ChatColor.RED + "Your Config has been corrupted!");
    66. }
    67. }
    68.  
    69. public static Inventory getCompassInventory() {
    70. Inventory inv = Bukkit.createInventory(null, 54,
    71. " Wardrobe");
    72. // Needs to be a multiple of nine! Else will will not work
    73. {
    74. ItemStack item = new ItemStack(Material.ENDER_PEARL, 1);
    75. ItemMeta meta = item.getItemMeta();
    76. meta.setDisplayName(ChatColor.WHITE + "Pickup Point");
    77. List<String> lore = new ArrayList<String>();
    78. lore.add("Teleports you to a delivery point.");
    79. meta.setLore(lore);
    80. item.setItemMeta(meta);
    81. inv.addItem(item);
    82. }
    83. {
    84. ItemStack Deselect = new ItemStack(Material.GOLD_BOOTS);
    85. ItemMeta meta = Deselect.getItemMeta();
    86. meta.setDisplayName(ChatColor.GOLD + "Open the Boots menu");
    87. List<String> lore = new ArrayList<String>();
    88. meta.setLore(lore);
    89. Deselect.setItemMeta(meta);
    90. inv.setItem(40, Deselect);
    91. }
    92. {
    93. ItemStack Deselect = new ItemStack(Material.GOLD_LEGGINGS);
    94. ItemMeta meta = Deselect.getItemMeta();
    95. meta.setDisplayName(ChatColor.GOLD + "Open the Leggings menu");
    96. List<String> lore = new ArrayList<String>();
    97. meta.setLore(lore);
    98. Deselect.setItemMeta(meta);
    99. inv.setItem(31, Deselect);
    100. }
    101. {
    102. ItemStack Deselect = new ItemStack(Material.GOLD_CHESTPLATE);
    103. ItemMeta meta = Deselect.getItemMeta();
    104. meta.setDisplayName(ChatColor.GOLD + "Open the Chestplate menu");
    105. List<String> lore = new ArrayList<String>();
    106. meta.setLore(lore);
    107. Deselect.setItemMeta(meta);
    108. inv.setItem(22, Deselect);
    109. }
    110. {
    111. ItemStack Deselect = new ItemStack(Material.NETHER_STAR);
    112. ItemMeta meta = Deselect.getItemMeta();
    113. meta.setDisplayName(ChatColor.GOLD + "Trading Centre");
    114. List<String> lore = new ArrayList<String>();
    115. lore.add(ChatColor.RED + "Soon!");
    116. meta.setLore(lore);
    117. Deselect.setItemMeta(meta);
    118. inv.setItem(19, Deselect);
    119. }
    120. {
    121. ItemStack Deselect = new ItemStack(Material.TRAPPED_CHEST);
    122. ItemMeta meta = Deselect.getItemMeta();
    123. meta.setDisplayName(ChatColor.GOLD + "My Wardrobe");
    124. List<String> lore = new ArrayList<String>();
    125. lore.add(ChatColor.RED + "Soon!");
    126. meta.setLore(lore);
    127. Deselect.setItemMeta(meta);
    128. inv.setItem(25, Deselect);
    129. }
    130. {
    131. ItemStack Deselect = new ItemStack(Material.GOLD_HELMET);
    132. ItemMeta meta = Deselect.getItemMeta();
    133. meta.setDisplayName(ChatColor.GOLD + "Open the helmets menu");
    134. List<String> lore = new ArrayList<String>();
    135. meta.setLore(lore);
    136. Deselect.setItemMeta(meta);
    137. inv.setItem(13, Deselect);
    138. }
    139. {
    140. ItemStack Deselect = new ItemStack(Material.GLASS);
    141. ItemMeta meta = Deselect.getItemMeta();
    142. meta.setDisplayName(ChatColor.BLUE + "Disco Helmet");
    143. List<String> lore = new ArrayList<String>();
    144. lore.add(ChatColor.BOLD + "" + ChatColor.RED + ""
    145. + ChatColor.UNDERLINE + "Comming Soon!");
    146. meta.setLore(lore);
    147. Deselect.setItemMeta(meta);
    148. inv.setItem(45, Deselect);
    149. }
    150. {
    151. ItemStack Deselect = new ItemStack(Material.BOWL);
    152. ItemMeta meta = Deselect.getItemMeta();
    153. meta.setDisplayName(ChatColor.GOLD + "Close Wardrobe");
    154. List<String> lore = new ArrayList<String>();
    155. meta.setLore(lore);
    156. Deselect.setItemMeta(meta);
    157. inv.setItem(51, Deselect);
    158. }
    159. {
    160. ItemStack Deselect = new ItemStack(Material.CARPET);
    161. ItemMeta meta = Deselect.getItemMeta();
    162. meta.setDisplayName(ChatColor.GOLD + "Deselect all items.");
    163. List<String> lore = new ArrayList<String>();
    164. lore.add(ChatColor.RED
    165. + "WARNING: This will remove all your bought items!");
    166. meta.setLore(lore);
    167. Deselect.setItemMeta(meta);
    168. inv.setItem(52, Deselect);
    169. }
    170. {
    171. ItemStack BEACON = new ItemStack(Material.BEACON);
    172. ItemMeta meta = BEACON.getItemMeta();
    173. meta.setDisplayName(ChatColor.WHITE + "Set Delivery Point");
    174. List<String> lore = new ArrayList<String>();
    175. lore.add("Sets delivery location.");
    176. lore.add(ChatColor.RED + "" + ChatColor.UNDERLINE + "$90");
    177. meta.setLore(lore);
    178. BEACON.setItemMeta(meta);
    179. inv.setItem(53, BEACON);
    180. }
    181. return inv;
    182. }
    183.  
    184. Location target = CompassPort.getTarget();
    185.  
    186. public static Location getTarget() {
    187. return targetPoint;
    188. }
    189.  
    190. public static void setTarget(Location loc) {
    191. CompassPort.targetPoint = loc;
    192. }
    193.  
    194. public static CompassPort getInstance() {
    195. // TODO Auto-generated method stub
    196. return null;
    197. }
    198.  
    199. }

    Also, I have no errors. except those standard yellow liners, that I have stated before.

    1Rogue _LB MnMaxon Dragonphase GarrisOn SistanceCoding Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  10. Offline

    Garris0n

  11. Offline

    ProMCKingz

    Garris0n
    My code works fine, except when I try to implement the Vault API, and the lores. So I don't think its the naming
     
  12. Offline

    Garris0n

    The naming is not the problem, it's a problem that you need to fix (and do correctly in future projects).
     
  13. Offline

    ProMCKingz

    Garris0n
    Thanks, but how can i solve my current problem?
     
  14. Offline

    Garris0n

    As I do with every other post using incorrect naming conventions, I'll help you with your original issue once you fix the names.

    I tend to be ignored otherwise.
     
  15. Offline

    ProMCKingz

    Garris0n

    ok, so I have changed my package name to lowerCamelCase, and my constant names to CONSTANT_CASE
     
  16. Offline

    Garris0n

    Package names are lowercase, variables/methods lowerCamelCase.

    When you've fixed them, post the updated code and error.
     
  17. Offline

    ProMCKingz

    Garris0n Sorry, I meant lowecase for package names.. Also what errors?
     
  18. Offline

    Garris0n

    I didn't notice you said you'd fixed the error(s).

    Anyway, code?
     
  19. Offline

    ProMCKingz

    Garris0n
    Main:
    Code:java
    1. package mc.promckingz.wardrobe;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import net.milkbowl.vault.economy.Economy;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.Location;
    11. import org.bukkit.Material;
    12. import org.bukkit.configuration.file.FileConfiguration;
    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 CompassPort extends JavaPlugin {
    20. FileConfiguration config;
    21. private static Location targetPoint = null;
    22. public static Economy economy = null;
    23. SettingsManager settings = SettingsManager.getInstance();
    24.  
    25. private boolean setupEconomy() {
    26. RegisteredServiceProvider<Economy> economyProvider = getServer()
    27. .getServicesManager().getRegistration(
    28. net.milkbowl.vault.economy.Economy.class);
    29. if (economyProvider != null) {
    30. economy = economyProvider.getProvider();
    31. }
    32.  
    33. return (economy != null);
    34. }
    35.  
    36. @Override
    37. public void onEnable() {
    38. CompassPort.getTarget();
    39. String BukkitV = Bukkit.getBukkitVersion();
    40. getLogger().info("Wardrobe is currently running on" + BukkitV);
    41. getLogger()
    42. .warning(
    43. "Thanks for supporting this plugin, and keep supporting us, by downloading our new versions!");
    44. config = this.getConfig();
    45. getServer().getPluginManager().registerEvents(new InteractListener(),
    46. this);
    47. getServer().getPluginManager().registerEvents(new ClickListener(this),
    48. this);
    49. getCommand("wardrobe").setExecutor(new ConsoleListener());
    50. getCommand("wardrobe").setExecutor(new Commands(this));
    51. settings.setup(this);
    52. getConfig().options().copyDefaults(true);
    53. saveDefaultConfig();
    54. if (!setupEconomy()) {
    55. getLogger()
    56. .severe("THE PLUGIN REQUIRES VAULT, IN ORDER TO FUNCTION CORRECTLY");
    57.  
    58. }
    59. }
    60.  
    61. @Override
    62. public void onDisable() {
    63. if (config == null) {
    64. getLogger().warning(
    65. ChatColor.RED + "Your Config has been corrupted!");
    66. }
    67. }
    68.  
    69. public static Inventory getCompassInventory() {
    70. Inventory inv = Bukkit.createInventory(null, 54,
    71. " Wardrobe");
    72. // Needs to be a multiple of nine! Else will will not work
    73. {
    74. ItemStack item = new ItemStack(Material.ENDER_PEARL, 1);
    75. ItemMeta meta = item.getItemMeta();
    76. meta.setDisplayName(ChatColor.WHITE + "Pickup Point");
    77. List<String> lore = new ArrayList<String>();
    78. lore.add("Teleports you to a delivery point.");
    79. meta.setLore(lore);
    80. item.setItemMeta(meta);
    81. inv.addItem(item);
    82. }
    83. {
    84. ItemStack Deselect = new ItemStack(Material.GOLD_BOOTS);
    85. ItemMeta meta = Deselect.getItemMeta();
    86. meta.setDisplayName(ChatColor.GOLD + "Open the Boots menu");
    87. List<String> lore = new ArrayList<String>();
    88. meta.setLore(lore);
    89. Deselect.setItemMeta(meta);
    90. inv.setItem(40, Deselect);
    91. }
    92. {
    93. ItemStack Deselect = new ItemStack(Material.GOLD_LEGGINGS);
    94. ItemMeta meta = Deselect.getItemMeta();
    95. meta.setDisplayName(ChatColor.GOLD + "Open the Leggings menu");
    96. List<String> lore = new ArrayList<String>();
    97. meta.setLore(lore);
    98. Deselect.setItemMeta(meta);
    99. inv.setItem(31, Deselect);
    100. }
    101. {
    102. ItemStack Deselect = new ItemStack(Material.GOLD_CHESTPLATE);
    103. ItemMeta meta = Deselect.getItemMeta();
    104. meta.setDisplayName(ChatColor.GOLD + "Open the Chestplate menu");
    105. List<String> lore = new ArrayList<String>();
    106. meta.setLore(lore);
    107. Deselect.setItemMeta(meta);
    108. inv.setItem(22, Deselect);
    109. }
    110. {
    111. ItemStack Deselect = new ItemStack(Material.NETHER_STAR);
    112. ItemMeta meta = Deselect.getItemMeta();
    113. meta.setDisplayName(ChatColor.GOLD + "Trading Centre");
    114. List<String> lore = new ArrayList<String>();
    115. lore.add(ChatColor.RED + "Soon!");
    116. meta.setLore(lore);
    117. Deselect.setItemMeta(meta);
    118. inv.setItem(19, Deselect);
    119. }
    120. {
    121. ItemStack Deselect = new ItemStack(Material.TRAPPED_CHEST);
    122. ItemMeta meta = Deselect.getItemMeta();
    123. meta.setDisplayName(ChatColor.GOLD + "My Wardrobe");
    124. List<String> lore = new ArrayList<String>();
    125. lore.add(ChatColor.RED + "Soon!");
    126. meta.setLore(lore);
    127. Deselect.setItemMeta(meta);
    128. inv.setItem(25, Deselect);
    129. }
    130. {
    131. ItemStack Deselect = new ItemStack(Material.GOLD_HELMET);
    132. ItemMeta meta = Deselect.getItemMeta();
    133. meta.setDisplayName(ChatColor.GOLD + "Open the helmets menu");
    134. List<String> lore = new ArrayList<String>();
    135. meta.setLore(lore);
    136. Deselect.setItemMeta(meta);
    137. inv.setItem(13, Deselect);
    138. }
    139. {
    140. ItemStack Deselect = new ItemStack(Material.GLASS);
    141. ItemMeta meta = Deselect.getItemMeta();
    142. meta.setDisplayName(ChatColor.BLUE + "Disco Helmet");
    143. List<String> lore = new ArrayList<String>();
    144. lore.add(ChatColor.BOLD + "" + ChatColor.RED + ""
    145. + ChatColor.UNDERLINE + "Comming Soon!");
    146. meta.setLore(lore);
    147. Deselect.setItemMeta(meta);
    148. inv.setItem(45, Deselect);
    149. }
    150. {
    151. ItemStack Deselect = new ItemStack(Material.BOWL);
    152. ItemMeta meta = Deselect.getItemMeta();
    153. meta.setDisplayName(ChatColor.GOLD + "Close Wardrobe");
    154. List<String> lore = new ArrayList<String>();
    155. meta.setLore(lore);
    156. Deselect.setItemMeta(meta);
    157. inv.setItem(51, Deselect);
    158. }
    159. {
    160. ItemStack Deselect = new ItemStack(Material.CARPET);
    161. ItemMeta meta = Deselect.getItemMeta();
    162. meta.setDisplayName(ChatColor.GOLD + "Deselect all items.");
    163. List<String> lore = new ArrayList<String>();
    164. lore.add(ChatColor.RED
    165. + "WARNING: This will remove all your bought items!");
    166. meta.setLore(lore);
    167. Deselect.setItemMeta(meta);
    168. inv.setItem(52, Deselect);
    169. }
    170. {
    171. ItemStack BEACON = new ItemStack(Material.BEACON);
    172. ItemMeta meta = BEACON.getItemMeta();
    173. meta.setDisplayName(ChatColor.WHITE + "Set Delivery Point");
    174. List<String> lore = new ArrayList<String>();
    175. lore.add("Sets delivery location.");
    176. lore.add(ChatColor.RED + "" + ChatColor.UNDERLINE + "$90");
    177. meta.setLore(lore);
    178. BEACON.setItemMeta(meta);
    179. inv.setItem(53, BEACON);
    180. }
    181. return inv;
    182. }
    183.  
    184. Location target = CompassPort.getTarget();
    185.  
    186. public static Location getTarget() {
    187. return targetPoint;
    188. }
    189.  
    190. public static void setTarget(Location loc) {
    191. CompassPort.targetPoint = loc;
    192. }
    193.  
    194. public static CompassPort getInstance() {
    195. // TODO Auto-generated method stub
    196. return null;
    197. }
    198.  
    199. }

    ClickListener Class:!
    Code:java
    1. package mc.promckingz.wardrobe;
    2.  
    3. import net.milkbowl.vault.economy.EconomyResponse;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.HumanEntity;
    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.inventory.ItemStack;
    13.  
    14. public class ClickListener implements Listener {
    15.  
    16. SettingsManager settings = SettingsManager.getInstance();
    17. CompassPort CP = CompassPort.getInstance();
    18. CompassPort plugin;
    19. public int BEACON;//This was moved
    20. public ClickListener(CompassPort instance) {
    21. plugin = instance;
    22. BEACON= plugin.config.getInt("Teleport_Cost"); //This was moved from the top
    23. }
    24.  
    25. @EventHandler
    26. public void onClick(InventoryClickEvent event) {
    27. HumanEntity entity = event.getWhoClicked();
    28. if ((entity instanceof Player)) {
    29. Player player = (Player) entity;
    30. if (event.getInventory().getName()
    31. .equals(CompassPort.getCompassInventory().getName())) {
    32. event.setCancelled(true);
    33. ItemStack clicked = event.getCurrentItem();
    34. if (clicked != null) {
    35. if (clicked.getType() == Material.DIAMOND_HELMET) {
    36. if (player.getEquipment().getHelmet().equals(Material.DIAMOND_HELMET)){
    37. player.sendMessage(ChatColor.RED + "You already have a diamond helmet!");
    38. }
    39. else {
    40. player.closeInventory();
    41. player.getEquipment().setHelmet (new ItemStack (Material.DIAMOND_HELMET));
    42. player.sendMessage(ChatColor.GOLD + "You now have a" + ChatColor.AQUA + " Diamond Helmet!");
    43. }
    44. } else if (clicked.getType() == Material.ENDER_PEARL) {
    45. player.closeInventory();
    46. if (CompassPort.getTarget() != null) {
    47. player.teleport(CompassPort.getTarget());
    48. player.sendMessage(plugin.config.getString("Teleport_Message".replaceAll("§", "&")));
    49. return;
    50. } else {
    51. player.sendMessage(ChatColor.RED
    52. + "Point not yet set!");
    53. }
    54. } else if (clicked.getType() == Material.GOLD_HELMET) {
    55. player.closeInventory();
    56. }
    57. } if (clicked.getType() == Material.BEACON) {
    58. player.closeInventory();
    59. String pn = player.getName();
    60. if(CP.economy.getBalance(pn)>=BEACON){
    61. EconomyResponse er = CP.economy.withdrawPlayer(pn, BEACON);
    62. if(er.transactionSuccess()){
    63. settings.getData().set(player.getName() + " .z", player.getLocation().getBlockZ());
    64. settings.getData().set(player.getName() + " .y", player.getLocation().getBlockY());
    65. settings.getData().set(player.getName() + " .x", player.getLocation().getBlockX());
    66. CompassPort.setTarget(player.getLocation());
    67. plugin.saveConfig();
    68. plugin.reloadConfig();
    69.  
    70. player.closeInventory();
    71. player.sendMessage(ChatColor.GOLD
    72. + plugin.config.getString("Teleport_Update_Message".replaceAll("(&([a-f0-9]))", "\u00A7$2")));
    73. }
    74. if (clicked.getType() == Material.GOLD_HELMET) {
    75. player.closeInventory();
    76. player.openInventory(SubHelmet.getHelmetInventory());
    77. }
    78. if (clicked.getType() == Material.GOLD_CHESTPLATE){
    79. player.closeInventory();
    80. player.openInventory(SubChestPlate.getChestplateInventory());
    81. }
    82. if (clicked.getType() == Material.GOLD_LEGGINGS){
    83. player.closeInventory();
    84. player.openInventory(SubLeggings.getLeggingsInventory());
    85. }
    86. if (clicked.getType() == Material.GOLD_BOOTS){
    87. player.closeInventory();
    88. player.openInventory(SubBoots.getBootsInventory());
    89. }
    90. if (clicked.getType() == Material.BOWL){
    91. player.closeInventory();
    92. }
    93. if (clicked.getType() == Material.CARPET){
    94. player.closeInventory();
    95. player.getEquipment().setHelmet(null);
    96. player.getEquipment().setChestplate(null);
    97. player.getEquipment().setLeggings(null);
    98. player.getEquipment().setBoots(null);
    99. }
    100. if (clicked.getType() == Material.NETHER_STAR){
    101. player.closeInventory();
    102. player.sendMessage(ChatColor.DARK_AQUA + "[Wardrobe+] " + ChatColor.RED + "This feature will be added in a future update!");
    103. }
    104. if (clicked.getType() == Material.GLASS){
    105. player.closeInventory();
    106. player.sendMessage(ChatColor.DARK_AQUA + "[Wardrobe+] " + ChatColor.RED + "This feature will be added in a future update!");
    107. }
    108. if (clicked.getType() == Material.TRAPPED_CHEST){
    109. player.closeInventory();
    110. player.sendMessage(ChatColor.DARK_AQUA + "[Wardrobe+] " + ChatColor.RED + "This feature will be added in a future update!");
    111. }
    112. }
    113. }
    114. }
    115. }
    116. }
    117. }
     
  20. Offline

    Garris0n

    There are still quite a few variables that have incorrect names ("Deselect", "BEACON" (the ItemStack(s) in the getCompassInventory method, etc).

    Also, you should mark constants (the BEACON in ClickListener, for example) as "final".

    There's also quite a bit of weird formatting that makes the code harder to read, so you should consider fixing that.
     
  21. Offline

    ProMCKingz

    Garris0n
    Its been 32 minutes... Can you please just get to the solution I was here for?
    I can fix the variables any time later!
     
    SistanceCoding likes this.
  22. Offline

    Garris0n

    Well, as a start, add some debug messages (just broadcast or print to sysout) to see where the execution of the event is ending.
     
  23. Offline

    ProMCKingz

  24. Offline

    Garris0n

    Well where does it stop executing?
     
  25. Offline

    ProMCKingz

    Garris0n
    None of the click listener class works
     
  26. Offline

    SistanceCoding

    ProMCKingz likes this.
  27. Offline

    ProMCKingz

  28. Offline

    SistanceCoding

    k what I usually do when I can't get help for anyone is google the problem and find other projects that had similar errors or problems and I look at how they were fixed and I fix mines myself.
     
  29. Offline

    ProMCKingz

    SistanceCoding
    There are a few, however they are usually the ones where people who orignally posted them, are the ones that have solved them, and they provide no info on how they did so. So its frustrating how there are people who can help, just don't want to do it passionately!

    SistanceCoding there is even a whole video, however I have followed it and it just doesn't work out for me!
    Void Nation's Video

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  30. Offline

    SistanceCoding

    ProMCKingz Yeah I understand I would help if I knew what the problem was. These guys are just well they are just acting that way well actually I don't know. I don't understand why it matter what YOU name the variables when you already have the solution just tell the solution instead of wasting time.
     
    ProMCKingz likes this.
Thread Status:
Not open for further replies.

Share This Page