Item not going in Inventory

Discussion in 'Plugin Development' started by PieMan456, Mar 1, 2014.

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

    PieMan456

    Hello Everyone,

    I am making a hide plugin that when you right click on a redstone torch it is supposed to hide all the other players and then the redstone torch will turn off. I am trying so that when you right click the redstone torch it hides all players and it then turns into an unlit redstone torch.
    Here is my code:
    Code:java
    1. package me.pieman.morepvpcore;
    2.  
    3. import java.util.ArrayList;
    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.block.Action;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.event.player.PlayerJoinEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class Main extends JavaPlugin implements Listener {
    19.  
    20. ArrayList<String> cooldown = new ArrayList<String>();
    21.  
    22. public void onEnable(){
    23. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    24. }
    25.  
    26. @EventHandler
    27. public void onPlayerJoin(PlayerJoinEvent e){
    28. Player p = e.getPlayer();
    29.  
    30. ItemStack torch = new ItemStack(Material.REDSTONE_TORCH_ON);
    31. ItemMeta torchmeta = torch.getItemMeta();
    32. ArrayList<String> torcha = new ArrayList<String>();
    33. torcha.add(ChatColor.YELLOW + "Click to Show/Hide Players");
    34. torchmeta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "Player Visibility");
    35. torchmeta.setLore(torcha);
    36. torch.setItemMeta(torchmeta);
    37.  
    38. p.getInventory().setItem(2, torch);
    39. }
    40.  
    41. @SuppressWarnings("deprecation")
    42. @EventHandler
    43. public void onPlayerInteract(PlayerInteractEvent e){
    44. final Player p = e.getPlayer();
    45. if(p.getItemInHand() == null) return;
    46. System.out.println("Working");
    47. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
    48. System.out.println("Still Working");
    49. if(p.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + "" + ChatColor.BOLD + "Player Visibility")){
    50. System.out.println("Still Working!!!!!");
    51. if(cooldown.contains(p.getName())){
    52. p.sendMessage(ChatColor.YELLOW + "Cooling Down");
    53. return;
    54. }
    55. for(Player ps : Bukkit.getOnlinePlayers()){
    56. p.hidePlayer(ps);
    57. p.sendMessage(ChatColor.AQUA + "Players have been vanished!");
    58.  
    59. ItemStack torch = new ItemStack(Material.REDSTONE_TORCH_OFF);
    60. ItemMeta torchmeta = torch.getItemMeta();
    61. ArrayList<String> torcha = new ArrayList<String>();
    62. torcha.add(ChatColor.YELLOW + "Click to Show/Hide Players");
    63. torchmeta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "Player Visibility");
    64. torchmeta.setLore(torcha);
    65. torch.setItemMeta(torchmeta);
    66.  
    67. p.setItemInHand(null);
    68. p.setItemInHand(torch);
    69. System.out.println("Yo");
    70. p.updateInventory();
    71. cooldown.add(p.getName());
    72. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    73. public void run(){
    74. cooldown.remove(p.getName());
    75. }
    76. }, 20 * 3);
    77. return;
    78. }
    79. }
    80. if(p.getItemInHand() == new ItemStack(Material.REDSTONE_TORCH_OFF)){
    81. if(cooldown.contains(p.getName())){
    82. p.sendMessage(ChatColor.YELLOW + "Cooling Down");
    83. return;
    84. }
    85. for(Player ps : Bukkit.getOnlinePlayers()){
    86. p.hidePlayer(ps);
    87. p.sendMessage(ChatColor.DARK_AQUA + "Players are no longer vanished!");
    88.  
    89. ItemStack torch = new ItemStack(Material.REDSTONE_TORCH_ON);
    90. ItemMeta torchmeta = torch.getItemMeta();
    91. ArrayList<String> torcha = new ArrayList<String>();
    92. torcha.add(ChatColor.YELLOW + "Click to Show/Hide Players");
    93. torchmeta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "Player Visibility");
    94. torchmeta.setLore(torcha);
    95. torch.setItemMeta(torchmeta);
    96.  
    97. p.setItemInHand(null);
    98. p.setItemInHand(torch);
    99. p.updateInventory();
    100. cooldown.add(p.getName());
    101. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    102. public void run(){
    103. cooldown.remove(p.getName());
    104. }
    105. }, 20 * 3);
    106. return;
    107. }
    108. }
    109. }
    110. }
    111. }
    112.  
     
  2. Offline

    JeZPvP

    • Your not showing the players, you're hiding them again.


      for(Player ps : Bukkit.getOnlinePlayers()){
      p.hidePlayer(ps);
      p.sendMessage(ChatColor.DARK_AQUA + "Players are no longer vanished!");
     
  3. Offline

    97WaterPolo

    I bbelieve that you can no longer have items like that in 1.7. If you check the mc wiki items like the piston head, half item doors, redstone torch off, are no longer able to have it in the game. Hopefully someone else can shed some more light in case I am kissing something or am wrong.
     
  4. Offline

    PieMan456

    JeZPvP
    I don't need help hiding I need to know why the redstone torch won't be displayed in the inventory
     
  5. Offline

    97WaterPolo

  6. Offline

    PieMan456

    97waterpolo
    I know I saw yours. I'm just seeing if anyone knows if that is why or it's something else.
     
  7. Offline

    97WaterPolo

  8. Offline

    PieMan456

    97waterpolo
    What about it? I see the unlit redstone torch part but it doesnt say it has been removed.
     
  9. Offline

    97WaterPolo

    PieMan456

    Opening paragraph.

    Technical blocks are blocks that cannot be acquired without commands or mods, but have independent block IDs, and serve various purposes during events within the game. The ability to obtain the item form of most technical blocks (block IDs 26, 34, 36, 55, 59, 63, 64, 68, 71, 74, 75, 83, 92, 93, 94, 104, 105, 115, 117, 118, 124, 132, 140, 144, 149, and 150) was removed in the 1.7.2 update. Fluidblocks, both types of Portal blocks, Farmland, Monster Spawners, Carrots and Potatoes Crops, and Burning Furnaces remain available.

    Item ids that are removed are mentioned. The item id for an off redstone torch is.... 75, thus meaning it was removed in the last update.
     
Thread Status:
Not open for further replies.

Share This Page