Inventory Error

Discussion in 'Plugin Development' started by candyfloss20, Jun 18, 2014.

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

    candyfloss20

    Help, I keep getting a error at Java:77 or player.openInvetory(inv);
    and the inv wont open but the chest sound plays
    Errorr: http://pastebin.com/MWHfb4cx (Mcprohosting prints in reverse sorry :( )
    Java Class:
    Code:java
    1. package com.xCraft.xSuite.Hub;
    2.  
    3. import com.xCraft.xSuite.xSuite;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.Location;
    6. import org.bukkit.Material;
    7. import org.bukkit.Sound;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.inventory.InventoryClickEvent;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.event.player.PlayerJoinEvent;
    15. import org.bukkit.inventory.Inventory;
    16. import org.bukkit.inventory.ItemStack;
    17. import org.bukkit.inventory.meta.ItemMeta;
    18. import org.bukkit.plugin.Plugin;
    19.  
    20. import java.util.ArrayList;
    21. import java.util.List;
    22.  
    23.  
    24. public class HUB_Compass implements Listener {
    25. private Inventory inv;
    26. private Location CTFlobby = new Location(Bukkit.getWorld("world"),345,3454,345); //find out cords
    27. private Location SGlobby = new Location(Bukkit.getWorld("world"),345,3454,345); //find out cords
    28.  
    29. public HUB_Compass(Plugin p) {
    30. Bukkit.getServer().getPluginManager().registerEvents(this, p);
    31.  
    32. Inventory inv = Bukkit.getServer().createInventory(null, 27, "§aServer Select");
    33.  
    34. // GET MORE SEVRERS!//
    35.  
    36. ItemStack CTF = new ItemStack(Material.GOLD_BOOTS);
    37. ItemMeta CTFmeta = CTF.getItemMeta();
    38. List<String> CTFlore = new ArrayList<String>();
    39. CTFmeta.setDisplayName("§dCapture The Flag");
    40. CTFlore.add("§7§oClick to teleport to: §dCapture The Flag §7§oLobby");
    41. CTFmeta.setLore(CTFlore);
    42. CTF.setItemMeta(CTFmeta);
    43. inv.setItem(1, CTF);
    44.  
    45. ItemStack SG = new ItemStack(Material.IRON_SWORD);
    46. ItemMeta SGmeta = SG.getItemMeta();
    47. List<String> SGlore = new ArrayList<String>();
    48. CTFmeta.setDisplayName("§dSurvival Games");
    49. CTFlore.add("§7§oClick to teleport to: §dSurvival Games §7§oLobby");
    50. SGmeta.setLore(SGlore);
    51. SG.setItemMeta(SGmeta);
    52. inv.setItem(3, SG);
    53. }
    54.  
    55. @EventHandler
    56. public void onJoin(PlayerJoinEvent event) {
    57. if (Bukkit.getServer().getMotd().equalsIgnoreCase("xcraft HUB")) {
    58. event.getPlayer().getInventory().clear();
    59.  
    60. ItemStack compass = new ItemStack(Material.COMPASS);
    61. ItemMeta compassmeta = compass.getItemMeta();
    62. List<String> compasslore = new ArrayList<String>();
    63. compassmeta.setDisplayName("§d§lxCraft §aServer Select");
    64. compasslore.add("§7§oClick to open");
    65. compassmeta.setLore(compasslore);
    66. compass.setItemMeta(compassmeta);
    67. event.getPlayer().getInventory().setHeldItemSlot(0);
    68. event.getPlayer().getInventory().setItemInHand(compass);
    69. }
    70. }
    71.  
    72. @EventHandler
    73. public void OpenCompass(PlayerInteractEvent event) {
    74. if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR && event.getPlayer().getItemInHand().getType() == Material.COMPASS && Bukkit.getMotd().equalsIgnoreCase("xcraft hub")) {
    75. Player player = event.getPlayer();
    76. player.playSound(event.getPlayer().getLocation(), Sound.CHEST_OPEN,1,1);
    77. player.openInventory(inv);
    78. }
    79. }
    80. @EventHandler
    81. public void ClickInCompass(InventoryClickEvent event) {
    82. if (event.getInventory() == inv) {
    83. Player player = (Player) event.getWhoClicked();
    84. if (event.getCurrentItem().getType() == Material.GOLD_BOOTS) {
    85. player.sendMessage(xSuite.TAG+"Teleporting to: §dCapture The Flag §eLobby");
    86. player.teleport(CTFlobby);
    87. }
    88. else if (event.getCurrentItem().getType() == Material.IRON_SWORD) {
    89. player.sendMessage(xSuite.TAG+"Teleporting to: §dSurvival Games §eLobby");
    90. player.teleport(SGlobby);
    91. }
    92. }
    93. }
    94. }
    95. /syntax]
     
  2. Offline

    THEREDBARON24

    Try and put the inventory code in the interact method? Or inside its own method and then call that method inside the interact event block?
     
  3. Offline

    candyfloss20

    THEREDBARON24 how would i do that i said Java:75 Sorry Its Java:77

    Code:java
    1. @EventHandler
    2. public void OpenCompass(PlayerInteractEvent event) {
    3. if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR && event.getPlayer().getItemInHand().getType() == Material.COMPASS && Bukkit.getMotd().equalsIgnoreCase("xcraft hub")) {
    4. Player player = event.getPlayer();
    5. player.playSound(event.getPlayer().getLocation(), Sound.CHEST_OPEN,1,1);
    6. player.openInventory(inv);
    7. }
    8. }
     
  4. Offline

    THEREDBARON24

    Put lines 32 -43 ish inside the interact method. This way, It runs through the code every time the interactions are correct. I would also put the locations in there as well. That way, you can make sure that they are defined correctly.
     
  5. Offline

    candyfloss20

    THEREDBARON24 that means nothing to me can so show me IE: post the code i should change ?
    Thanks :)
     
  6. Offline

    THEREDBARON24

    candyfloss20 uhh, just cut and paste the code used to modify the inventory and put it in the block of code used for the interact event.
     
Thread Status:
Not open for further replies.

Share This Page