Solved "Bug" with soup chests!

Discussion in 'Plugin Development' started by APPLEisROP, Feb 22, 2014.

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

    APPLEisROP

    So this code works but, if i take soups at the same time with multiple players i can see when they take soup. I think its because i used this
    Code:java
    1. soupInv = Bukkit.getServer().createInventory(null, 54, ChatColor.RED + "RefillChest");
    it should be player instead of Bukkit but idk how to make it work that way! D:

    Here's my code:

    Code:java
    1. public class SoupChest implements Listener {
    2.  
    3. public static Inventory soupInv;
    4.  
    5. public SoupChest(mainclass plugin)
    6. {
    7. soupInv = Bukkit.getServer().createInventory(null, 54, ChatColor.RED + "RefillChest");
    8. ItemStack SOUP = new ItemStack(Material.MUSHROOM_SOUP);
    9. ItemMeta isM = SOUP.getItemMeta();
    10. isM.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD + "Soppa");
    11. SOUP.setItemMeta(isM);
    12.  
    13. for(int i = 0; i < 54; i++)
    14. {
    15. soupInv.addItem(SOUP);
    16. }
    17. }
    18.  
    19. @EventHandler
    20. public void PlayerCloseInventory(InventoryCloseEvent e)
    21. {
    22. ItemStack SOUP = new ItemStack(Material.MUSHROOM_SOUP);
    23. ItemMeta isM = SOUP.getItemMeta();
    24. isM.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD + "Soppa");
    25. SOUP.setItemMeta(isM);
    26. soupInv.clear();
    27. for(int i = 0; i < 54; i++)
    28. {
    29. soupInv.addItem(SOUP);
    30. }
    31. }
    32.  
    33. @EventHandler
    34. public void ChestClicker(PlayerInteractEvent e)
    35. {
    36. if(e.getAction() == Action.RIGHT_CLICK_BLOCK)
    37. {
    38. if(e.getClickedBlock().getType() == Material.TRAPPED_CHEST)
    39. {
    40. Player player = (Player) e.getPlayer();
    41. player.getServer().getPlayer(player.getName()).openInventory(soupInv);
    42. e.setCancelled(true);
    43. }
    44. }
    45. }
    46.  
    47. @EventHandler
    48. public void onPlayerInteract(PlayerInteractEvent event) {
    49. Player player = event.getPlayer();
    50. if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    51. if(event.getClickedBlock().getType() == Material.SIGN || event.getClickedBlock().getType () == Material.WALL_SIGN) {
    52. Block sign = event.getClickedBlock();
    53. Sign s = (Sign)sign.getState();
    54. if(s.getLine(1).equalsIgnoreCase(ChatColor.stripColor("Soup"))) {
    55. event.setCancelled(true);
    56. player.getServer().getPlayer(player.getName()).openInventory(soupInv);
    57. }
    58. }
    59. }
    60. }
    61.  
    62. }
    63.  
     
  2. Offline

    mattibijnens

    APPLEisROP Put this
    Code:java
    1. soupInv = Bukkit.getServer().createInventory(null, 54, ChatColor.RED + "RefillChest");

    Each time they interact/ when they open it.

    APPLEisROP
    For example
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5. if(event.getClickedBlock().getType() == Material.SIGN || event.getClickedBlock().getType () == Material.WALL_SIGN) {
    6. //Here
    7. Block sign = event.getClickedBlock();
    8. Sign s = (Sign)sign.getState();
    9. if(s.getLine(1).equalsIgnoreCase(ChatColor.stripColor("Soup"))) {
    10. event.setCancelled(true);
    11. player.getServer().getPlayer(player.getName()).openInventory(soupInv);
    12. }
    13. }
    14. }
    15. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page