Solved Shop plugin help!

Discussion in 'Plugin Development' started by PixBenchMC, Sep 27, 2014.

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

    PixBenchMC

    I am working on my friend's factions server and the players requested to make a shop. I am almost done with the plugin. I just need to make that the shop work, but first I need to test if my menu works. And I am done with the menu. I use IntelliJ IDEA 13.4 Community Edition.
    The shop menu must be opened when a player right clicks air or a block with stick, but the plugin didn't work for me. I just right click with stick and nothing happens. Here is my code:

    This is the class Core:

    Code:java
    1. package me.PixBenchMC.PixelShop;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.inventory.Inventory;
    7. import org.bukkit.inventory.ItemStack;
    8. import org.bukkit.inventory.meta.ItemMeta;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. import java.util.ArrayList;
    13. import java.util.List;
    14.  
    15. public class Core extends JavaPlugin {
    16.  
    17. @Override
    18. public void onEnable() {
    19. PluginDescriptionFile pluginDescriptionFile = getDescription();
    20. getLogger().info("[" + pluginDescriptionFile.getName() + "] Version: " + pluginDescriptionFile.getVersion() + " is now enabled!");
    21. }
    22.  
    23. public static Inventory getShopMenu() {
    24. Inventory inventory = Bukkit.createInventory(null, 9, "Click an item!");
    25. {
    26. ItemStack diamond = new ItemStack(Material.DIAMOND, 1);
    27. ItemMeta meta = diamond.getItemMeta();
    28. meta.setDisplayName(ChatColor.GOLD + "§lDiamond");
    29. List<String> lore = new ArrayList<String>();
    30. lore.add(ChatColor.GOLD + "§lSells for : 1500$");
    31. meta.setLore(lore);
    32. diamond.setItemMeta(meta);
    33. inventory.addItem(diamond);
    34. }
    35. {
    36. ItemStack emerald = new ItemStack(Material.EMERALD, 1);
    37. ItemMeta meta = emerald.getItemMeta();
    38. meta.setDisplayName(ChatColor.GOLD + "§lEmerald");
    39. List<String> lore = new ArrayList<String>();
    40. lore.add(ChatColor.GOLD + "§lSells for : 2000$");
    41. meta.setLore(lore);
    42. emerald.setItemMeta(meta);
    43. inventory.addItem(emerald);
    44. }
    45. {
    46. ItemStack iron = new ItemStack(Material.IRON_INGOT, 1);
    47. ItemMeta meta = iron.getItemMeta();
    48. meta.setDisplayName(ChatColor.GOLD + "§lIron ingot");
    49. List<String> lore = new ArrayList<String>();
    50. lore.add(ChatColor.GOLD + "§lSells for : 1000$");
    51. meta.setLore(lore);
    52. iron.setItemMeta(meta);
    53. inventory.addItem(iron);
    54. }
    55. {
    56. ItemStack gold_ingot = new ItemStack(Material.GOLD_INGOT, 1);
    57. ItemMeta meta = gold_ingot.getItemMeta();
    58. meta.setDisplayName(ChatColor.GOLD + "§lGolden ingot");
    59. List<String> lore = new ArrayList<String>();
    60. lore.add(ChatColor.GOLD + "§lSells for : 1250$");
    61. meta.setLore(lore);
    62. gold_ingot.setItemMeta(meta);
    63. inventory.addItem(gold_ingot);
    64. }
    65. {
    66. ItemStack lapis_block = new ItemStack(Material.LAPIS_BLOCK, 1);
    67. ItemMeta meta = lapis_block.getItemMeta();
    68. meta.setDisplayName(ChatColor.GOLD + "§lLapis block");
    69. List<String> lore = new ArrayList<String>();
    70. lore.add(ChatColor.GOLD + "§lSells for : 800$");
    71. meta.setLore(lore);
    72. lapis_block.setItemMeta(meta);
    73. inventory.addItem(lapis_block);
    74. }
    75. {
    76. ItemStack redstone = new ItemStack(Material.REDSTONE_WIRE, 1);
    77. ItemMeta meta = redstone.getItemMeta();
    78. meta.setDisplayName(ChatColor.GOLD + "§lRedstone");
    79. List<String> lore = new ArrayList<String>();
    80. lore.add(ChatColor.GOLD + "§lSells for : 150$");
    81. meta.setLore(lore);
    82. redstone.setItemMeta(meta);
    83. inventory.addItem(redstone);
    84. }
    85. return inventory;
    86. }
    87.  
    88. @Override
    89. public void onDisable() {
    90. PluginDescriptionFile pluginDescriptionFile = getDescription();
    91. getLogger().info("[" + pluginDescriptionFile.getName() + "] Version: " + pluginDescriptionFile.getVersion() + " is now disabled!");
    92. }
    93. }


    And this is the InteractListener:

    Code:java
    1. package me.PixBenchMC.PixelShop;
    2.  
    3. import me.confuser.barapi.BarAPI;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11.  
    12. public class InteractListener {
    13.  
    14. @EventHandler
    15. public void onInteract(PlayerInteractEvent event) {
    16. Player player = event.getPlayer();
    17. Location location = player.getLocation();
    18.  
    19. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    20. if (player.getItemInHand().getType() == Material.STICK) {
    21. BarAPI.setHealth(player, 300);
    22. BarAPI.setMessage(player, ChatColor.DARK_PURPLE + "Open Shop right now!", 10);
    23. player.openInventory(Core.getShopMenu());
    24. }
    25. }
    26. }
    27.  
    28. }
    29.  


    I also used BarAPI to make the plugin look cooler, but it did't show me the bar. I need help for that too.

    That is the console output:
    Loading libraries, please wait...
    [15:06:54 INFO]: Starting minecraft server version 1.7.9
    [15:06:55 INFO]: Loading properties
    [15:06:55 INFO]: Default game type: SURVIVAL
    [15:06:55 INFO]: Generating keypair
    [15:06:55 INFO]: Starting Minecraft server on *:25565
    [15:06:55 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-SNAPSHO
    T)
    [15:06:56 INFO]: [PixelShop] Loading PixelShop v1.0.1
    [15:06:56 INFO]: [Pickaxes] Loading Pickaxes v1.0.1
    [15:06:56 INFO]: [WorldEdit] Loading WorldEdit v5.6.3
    [15:06:56 INFO]: [BarAPI] Loading BarAPI v3.1
    [15:06:56 INFO]: [Essentials] Loading Essentials v2.13.1
    [15:06:56 INFO]: [EssentialsChat] Loading EssentialsChat v2.13.1
    [15:06:56 INFO]: [EssentialsProtect] Loading EssentialsProtect v2.13.1
    [15:06:56 INFO]: [EssentialsSpawn] Loading EssentialsSpawn v2.13.1
    [15:06:56 INFO]: [EssentialsAntiBuild] Loading EssentialsAntiBuild v2.13.1
    [15:06:56 WARN]: Could not get information about this CraftBukkit version; perha
    ps you are running a custom one?: IOException
    [15:06:56 INFO]: Preparing level "world"
    [15:06:56 WARN]: Could not get latest artifact information: IOException
    [15:06:56 INFO]: Preparing start region for level 0 (Seed: 7691256666968651621)
    [15:06:57 INFO]: Preparing spawn area: 13%
    [15:06:58 INFO]: Preparing spawn area: 64%
    [15:06:59 INFO]: Preparing start region for level 1 (Seed: 7691256666968651621)
    [15:07:00 INFO]: Preparing spawn area: 44%
    [15:07:01 INFO]: Preparing spawn area: 92%
    [15:07:01 INFO]: Preparing start region for level 2 (Seed: 7691256666968651621)
    [15:07:02 INFO]: Preparing spawn area: 84%
    [15:07:02 INFO]: [PixelShop] Enabling PixelShop v1.0.1
    [15:07:02 INFO]: [PixelShop] [PixelShop] Version: 1.0.1 is now enabled!
    [15:07:02 INFO]: [Pickaxes] Enabling Pickaxes v1.0.1
    [15:07:02 INFO]: [Pickaxes] Pickaxes Version: 1.0.1 is now enabled!
    [15:07:02 INFO]: [WorldEdit] Enabling WorldEdit v5.6.3
    [15:07:02 INFO]: WEPIF: Using the Bukkit Permissions API.
    [15:07:02 INFO]: [BarAPI] Enabling BarAPI v3.1
    [15:07:02 INFO]: [BarAPI] Loaded
    [15:07:02 INFO]: [Essentials] Enabling Essentials v2.13.1
    [15:07:03 INFO]: Essentials: Using config file enhanced permissions.
    [15:07:03 INFO]: Permissions listed in as player-commands will be given to all u
    sers.
    [15:07:03 INFO]: [EssentialsChat] Enabling EssentialsChat v2.13.1
    [15:07:03 INFO]: [EssentialsProtect] Enabling EssentialsProtect v2.13.1
    [15:07:03 INFO]: [EssentialsSpawn] Enabling EssentialsSpawn v2.13.1
    [15:07:03 INFO]: [EssentialsAntiBuild] Enabling EssentialsAntiBuild v2.13.1
    [15:07:03 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [15:07:03 INFO]: Done (7,418s)! For help, type "help" or "?"
    [15:07:03 INFO]: Starting remote control listener
    [15:07:03 INFO]: RCON running on __________________



    Please reply if you know how to fix this error
     
  2. Offline

    fireblast709

    PixBenchMC You forgot to register your Listener
     
  3. Offline

    PixBenchMC

    I doesn't work. I removed the class InteractListener because IntelliJ was giving me an error. Here is my Core class and i made a new class called coins.
    Core :
    Code:java
    1. package me.PixBenchMC.PixelShop;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14. import org.bukkit.plugin.PluginDescriptionFile;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. import java.util.ArrayList;
    18. import java.util.List;
    19.  
    20. public class Core extends JavaPlugin {
    21.  
    22. @Override
    23. public void onEnable() {
    24. PluginDescriptionFile pluginDescriptionFile = getDescription();
    25. getLogger().info("[" + pluginDescriptionFile.getName() + "] Version: " + pluginDescriptionFile.getVersion() + " is now enabled!");
    26. PluginManager pluginManager = getServer().getPluginManager();
    27. pluginManager.registerEvents(Coins, this);
    28.  
    29.  
    30. }
    31.  
    32. public static Inventory getShopMenu() {
    33. Inventory inventory = Bukkit.createInventory(null, 9, "Click an item!");
    34. {
    35. ItemStack diamond = new ItemStack(Material.DIAMOND, 1);
    36. ItemMeta meta = diamond.getItemMeta();
    37. meta.setDisplayName(ChatColor.GOLD + "§lDiamond");
    38. List<String> lore = new ArrayList<String>();
    39. lore.add(ChatColor.GOLD + "§lSells for : 1500$");
    40. meta.setLore(lore);
    41. diamond.setItemMeta(meta);
    42. inventory.addItem(diamond);
    43. }
    44. {
    45. ItemStack emerald = new ItemStack(Material.EMERALD, 1);
    46. ItemMeta meta = emerald.getItemMeta();
    47. meta.setDisplayName(ChatColor.GOLD + "§lEmerald");
    48. List<String> lore = new ArrayList<String>();
    49. lore.add(ChatColor.GOLD + "§lSells for : 2000$");
    50. meta.setLore(lore);
    51. emerald.setItemMeta(meta);
    52. inventory.addItem(emerald);
    53. }
    54. {
    55. ItemStack iron = new ItemStack(Material.IRON_INGOT, 1);
    56. ItemMeta meta = iron.getItemMeta();
    57. meta.setDisplayName(ChatColor.GOLD + "§lIron ingot");
    58. List<String> lore = new ArrayList<String>();
    59. lore.add(ChatColor.GOLD + "§lSells for : 1000$");
    60. meta.setLore(lore);
    61. iron.setItemMeta(meta);
    62. inventory.addItem(iron);
    63. }
    64. {
    65. ItemStack gold_ingot = new ItemStack(Material.GOLD_INGOT, 1);
    66. ItemMeta meta = gold_ingot.getItemMeta();
    67. meta.setDisplayName(ChatColor.GOLD + "§lGolden ingot");
    68. List<String> lore = new ArrayList<String>();
    69. lore.add(ChatColor.GOLD + "§lSells for : 1250$");
    70. meta.setLore(lore);
    71. gold_ingot.setItemMeta(meta);
    72. inventory.addItem(gold_ingot);
    73. }
    74. {
    75. ItemStack lapis_block = new ItemStack(Material.LAPIS_BLOCK, 1);
    76. ItemMeta meta = lapis_block.getItemMeta();
    77. meta.setDisplayName(ChatColor.GOLD + "§lLapis block");
    78. List<String> lore = new ArrayList<String>();
    79. lore.add(ChatColor.GOLD + "§lSells for : 800$");
    80. meta.setLore(lore);
    81. lapis_block.setItemMeta(meta);
    82. inventory.addItem(lapis_block);
    83. }
    84. {
    85. ItemStack redstone = new ItemStack(Material.REDSTONE_WIRE, 1);
    86. ItemMeta meta = redstone.getItemMeta();
    87. meta.setDisplayName(ChatColor.GOLD + "§lRedstone");
    88. List<String> lore = new ArrayList<String>();
    89. lore.add(ChatColor.GOLD + "§lSells for : 150$");
    90. meta.setLore(lore);
    91. redstone.setItemMeta(meta);
    92. inventory.addItem(redstone);
    93. }
    94. return inventory;
    95. }
    96.  
    97.  
    98. @EventHandler
    99. public void onInteract(PlayerInteractEvent event) {
    100. Player player = event.getPlayer();
    101. Location location = player.getLocation();
    102.  
    103. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    104. if (player.getItemInHand().getType() == Material.STICK) {
    105.  
    106. player.openInventory(Core.getShopMenu());
    107. }
    108. }
    109. }
    110.  
    111. @Override
    112. public void onDisable() {
    113. PluginDescriptionFile pluginDescriptionFile = getDescription();
    114. getLogger().info("[" + pluginDescriptionFile.getName() + "] Version: " + pluginDescriptionFile.getVersion() + " is now disabled!");
    115. }
    116. }

    When i register the class "Coins" it gives me an error : "Expression expected"

    And Coins class:

    Code:java
    1. package me.PixBenchMC.PixelShop;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.entity.EntityDeathEvent;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. import java.util.HashMap;
    11. import java.util.UUID;
    12.  
    13. public class Coins extends JavaPlugin implements Listener {
    14.  
    15. HashMap<UUID, Integer> money = new HashMap<UUID, Integer>();
    16.  
    17. @Override
    18. public void onEnable() {
    19. getServer().getPluginManager().registerEvents(this, this);
    20. }
    21.  
    22. @EventHandler
    23. public void onJoin(PlayerJoinEvent event) {
    24. Player player = event.getPlayer();
    25.  
    26. if (!getConfig().contains(player.getUniqueId().toString())) {
    27. getConfig().set(player.getUniqueId() + ".Normal craft coins", 0);
    28. money.put(player.getUniqueId(), 0);
    29. } else {
    30. money.put(player.getUniqueId(), getConfig().getInt(player.getUniqueId() + ".Normal craft coins"));
    31. }
    32. }
    33.  
    34. @EventHandler
    35. public void onKill(EntityDeathEvent event) {
    36.  
    37. if (event.getEntity() instanceof Player) {
    38. Player player = (Player) event.getEntity();
    39. if (player.getKiller() instanceof Player) {
    40. Player player1 = player.getKiller();
    41. giveNormal_craft_coins(player, 200);
    42.  
    43. }
    44. }
    45. }
    46.  
    47. public void giveNormal_craft_coins(Player p, int i) {
    48. UUID uuid = p.getUniqueId();
    49. money.put(uuid, money.get(uuid) +i);
    50. p.sendMessage("§2§l$" + i + " Normal craft coins received!");
    51.  
    52. saveConfig();
    53. }
    54.  
    55. public void takeNormal_craft_coins(Player p, int i) {
    56. UUID uuid = p.getUniqueId();
    57. money.put(uuid, money.get(uuid) -i);
    58. p.sendMessage("§c§l$" + i + " Normal craft coins taken!");
    59. }
    60.  
    61. @Override
    62. public void onDisable() {
    63. for (UUID u : money.keySet()) {
    64. getConfig().set(u + ".NormalCraft coins", money.get(u));
    65. }
    66. }
    67. }
     
  4. Offline

    PixBenchMC

    Thanks! I solved it!
     
Thread Status:
Not open for further replies.

Share This Page