Solved Player Join Items

Discussion in 'Plugin Development' started by AlexHH251997, May 13, 2014.

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

    AlexHH251997

    Hey,

    I am trying to develop a custom Hub Plugin for a customer and for some reason I have had a total mind block. I am trying to give a player custom items and set them in the selected place. For example the first item goes in the first slot of your inventory bar and the second item goes in the last slot of your inventory bar. For some reason I just can't figure out why this code won't work.
    Code:java
    1. public class Main extends JavaPlugin {
    2.  
    3. public static Main main;
    4. public static Main plugin;
    5.  
    6. public static Inventory Hats;
    7. public static ItemStack JoinItemPlayersEnabled;
    8. public static ItemStack JoinItemPlayersDisabled;
    9. public static ItemStack JoinItemHats;
    10. public String Prefix = ChatColor.DARK_GRAY + "[" + ChatColor.RED + "TheRise" + ChatColor.DARK_GRAY + "] " + ChatColor.GREEN;
    11.  
    12. public void onEnable(){
    13. getLogger().info("[TheRise] HUB Plugin Enabled!");
    14. getLogger().info("[TheRise] Plugin Developed by Alex Harris (CodeChimp)");
    15. getLogger().info("[TheRise] [url]http://twitter.com/AlexHH25[/url]");
    16. getLogger().info("[TheRise] [email][email protected][/email]");
    17. getLogger().info("[TheRise] skype:ahoward-harris");
    18.  
    19. JoinItemPlayersEnabled = new ItemStack(Material.REDSTONE_TORCH_ON, 1);
    20. ItemMeta JoinItemPlayersEnabledMeta = JoinItemPlayersEnabled.getItemMeta();
    21. JoinItemPlayersEnabledMeta.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "PLAYERS → ENABLED");
    22. JoinItemPlayersEnabled.setItemMeta(JoinItemPlayersEnabledMeta);
    23.  
    24. JoinItemPlayersDisabled = new ItemStack(Material.REDSTONE_TORCH_OFF, 1);
    25. ItemMeta JoinItemPlayersDisabledMeta = JoinItemPlayersDisabled.getItemMeta();
    26. JoinItemPlayersDisabledMeta.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "PLAYERS → " + ChatColor.RED + "DISABLED");
    27. JoinItemPlayersDisabled.setItemMeta(JoinItemPlayersDisabledMeta);
    28.  
    29. JoinItemHats = new ItemStack(Material.GHAST_TEAR, 1);
    30. ItemMeta JoinItemHatsMeta = JoinItemHats.getItemMeta();
    31. JoinItemHatsMeta.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "HAT MENU");
    32. JoinItemHats.setItemMeta(JoinItemHatsMeta);
    33. }
    34.  
    35. public void onDisable(){
    36. getLogger().info("[TheRise] HUB Plugin Disabled!");
    37. getLogger().info("[TheRise] Plugin Developed by Alex Harris (CodeChimp)");
    38. getLogger().info("[TheRise] [url]http://twitter.com/AlexHH25[/url]");
    39. getLogger().info("[TheRise] [email][email protected][/email]");
    40. getLogger().info("[TheRise] skype:ahoward-harris");
    41. }
    42.  
    43. public void onPlayerInteract(PlayerInteractEvent evt){
    44. Player player = evt.getPlayer();
    45. if(player.getInventory().getItemInHand().getItemMeta().getDisplayName() == ChatColor.GREEN + "" + ChatColor.BOLD + "PLAYERS → ENABLED"){
    46. if(evt.getAction().equals(Action.RIGHT_CLICK_BLOCK) || evt.getAction().equals(Action.RIGHT_CLICK_AIR)){
    47. for(Player onlinePlayers : Bukkit.getOnlinePlayers()){
    48. player.sendMessage(Prefix + ChatColor.BOLD + "PLAYERS → " + ChatColor.RED + "DISABLED");
    49. player.hidePlayer(onlinePlayers);
    50. player.getInventory().remove(JoinItemPlayersEnabled);
    51. player.getInventory().setItem(1, JoinItemPlayersDisabled);
    52. }
    53. }
    54. }else if(player.getInventory().getItemInHand().getItemMeta().getDisplayName() == ChatColor.GREEN + "" + ChatColor.BOLD + "PLAYERS → " + ChatColor.RED + "DISABLED"){
    55. if(evt.getAction().equals(Action.RIGHT_CLICK_BLOCK) || evt.getAction().equals(Action.RIGHT_CLICK_AIR)){
    56. for(Player onlinePlayers : Bukkit.getOnlinePlayers()){
    57. player.sendMessage(Prefix + ChatColor.BOLD + "PLAYERS → ENABLED");
    58. player.showPlayer(onlinePlayers);
    59. player.getInventory().remove(JoinItemPlayersDisabled);
    60. player.getInventory().setItem(1, JoinItemPlayersEnabled);
    61. }
    62. }
    63. }
    64. }
    65.  
    66. public void onPlayerJoin(PlayerJoinEvent evt){
    67. Player player = evt.getPlayer();
    68. PlayerInventory pi = player.getInventory();
    69.  
    70. pi.clear();
    71. pi.setItem(1, JoinItemPlayersEnabled);
    72. pi.setItem(9, JoinItemHats);
    73. }
    74.  
    75. }


    Help would be greatly appreciated as I have had a total mind block ;)

    Regards,
    Alex Harris
     
  2. Offline

    XvBaseballkidvX

    You are forgetting your @EventHandler and you never registered your events in your onEnable() method.
     
  3. Offline

    Seadragon91

    Your forgot to register the listener and add then the "implements Listener" to your "public class Main extends JavaPlugin" line and add the missing @EventHandler to boths event methods.
     
    XvBaseballkidvX likes this.
  4. Offline

    AlexHH251997

    Ah thanks guys, I knew I had forgot something.
     
Thread Status:
Not open for further replies.

Share This Page