How To Make Infinite Chest Plugin?

Discussion in 'Plugin Development' started by Ambamore2000, Dec 24, 2013.

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

    Ambamore2000

    All I got so far:
    Code:java
    1. package me.Ambamore2000.Plugin;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. public final class Plugin extends JavaPlugin {
    6.  
    7. @Override
    8. public void onEnable(){
    9. getLogger().info("Enabled!");
    10.  
    11. }
    12. @Override
    13. public void onDisable(){
    14. getLogger().info("Disabled!");
    15. }
    16.  
    17. }

    I wanted to make an infinite chest thing (Part of a plugin I am working on) but I am stuck. Please help me.
     
  2. Offline

    Gater12

  3. Offline

    Ambamore2000

    Gater12 No, like, it is infinite. So, like, when you take something out, the items are put back in, but you still keep it.
     
  4. Offline

    Gater12

    Ambamore2000 Listen for InventoryClickEvent. If it's from a special inventory, get the clicked item, cancel the event, and add the clicked item to the player's inventory.
     
  5. Offline

    Ambamore2000

    Gater12
    Can you show me how to, just incase, 'cause I'm not sure if I'm correct.

    Gater12
    Hello?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  6. Offline

    Gater12

  7. Offline

    Ambamore2000

    Code:java
    1. package me.Ambamore2000.Plugin;
    2.  
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.inventory.InventoryDragEvent;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public final class Mainclass extends JavaPlugin implements Listener {
    9. @Override
    10. public void onEnable(){
    11. getLogger().info("onEnable has been invoked!");
    12. }
    13. @Override
    14. public void onDisable(){
    15. getLogger().info("onDisable has been invoked!");
    16. }
    17. @EventHandler
    18. public void InvChest (InventoryDragEvent event) {
    19. }
    20. }


    --I only got the event part
    ----There is no InventoryClickEvent, so I put InventoryDragEvent, cause that sounds the closest related.
     
  8. Offline

    Gater12

  9. Offline

    Ambamore2000

    Gater12
    Are you working on it?

    Gater12
    Maybe, but can you do the rest for me? I'm not a... profetional.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  10. Offline

    sgavster

    Code:java
    1. public void onClick(InventoryClickEvent e) {
    2. //check if it's the right inventory
    3. if(e.getCurrentItem() == null) return;//make sure it's not null
    4. e.setCancelled(true);//cancel it
    5. Player p = (Player) e.getWhoClicked();
    6. p.getInventory().addItem(new ItemStack(e.getCurrentItem().getType(), e.getCurrentItem().getAmount(), (byte) e.getCurrentItem().getData());//add the item to their inventory
    7. }
     
  11. Offline

    Ambamore2000

    sgavster
    So would it be:
    Code:java
    1. package me.Ambamore2000.Plugin;
    2.  
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.inventory.InventoryDragEvent;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public final class Mainclass extends JavaPlugin implements Listener {
    9. @Override
    10. public void onEnable(){
    11. getLogger().info("onEnable has been invoked!");
    12. }
    13. @Override
    14. public void onDisable(){
    15. getLogger().info("onDisable has been invoked!");
    16. }
    17. @EventHandler
    18. public void onClick(InventoryClickEvent e) {
    19. //check if it's the right inventory
    20. if(e.getCurrentItem() == null) return;//make sure it's not null
    21. e.setCancelled(true);//cancel it
    22. Player p = (Player) e.getWhoClicked();
    23. p.getInventory().addItem(new ItemStack(e.getCurrentItem().getType(), e.getCurrentItem().getAmount(), (byte) e.getCurrentItem().getData());//add the item to their inventory
    24. }


    Gater12
    Am I correct?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  12. Offline

    Darkrunner999

    This is not correct. You say that you want infinite 'chests'. You need to get the contents of the chest, then return the item clicked by the player while the event is cancelled. However, your code does work, just not with chests.
     
  13. Offline

    Ambamore2000

  14. Offline

    repsor

    If you want others to code it for you, why don't you just make a plugin in request? :p
     
    _Cookie_ likes this.
  15. Offline

    sgavster

    You need to register your events.
     
  16. Offline

    _AdamGinger

    I'm not very good with coding but is it similar to the [Free] signs from essentials? Is that what you are trying to achieve?
     
  17. Offline

    Ambamore2000

    @AdamGinger
    Sortof.
     
  18. Offline

    AoH_Ruthless

    Ambamore2000
    You cannot expect others to code for you ... The answer was given to you several times. I'm sorry to be rude, but you cannot just blindly copy and paste code, say it does not work, and expect someone else to spoonfeed you the answer.

    In your other recent posts, you mention not having a complete understanding of Java. I would strongly advise you to stop where you are and learn the fundamentals of java first.
     
    xTigerRebornx likes this.
  19. Offline

    Luke_Lax

    Like suggested before, either make a plugin request or take a look at TheNewBoston's YouTube bukkit coding tutorials :) asking people to do it for you and saying here's what I have (onEnable & disable) is kind of insulting :3
     
  20. Offline

    Ambamore2000

    Gater12
    Somethings wrong. It doesn't say it exists on my eclipse.
     
  21. Offline

    Gater12

  22. Offline

    Ambamore2000

    Gater12
    No, it's fixed. I typed it wrong before (InventoryClikEvent) and then now typed it correctly, and imported it.

    --When you say, "Listen for InventoryClickEvent. If it's from a special inventory, get the clicked item, cancel the event, and add the clicked item to the player's inventory."
    I don't get the part from "If it's from a special inventory" thru the end.
     
  23. Offline

    xTigerRebornx

    Ambamore2000 Check something about the inventory that would guarantees it is the inventory you want it to be (I.E. Give the inventory a unique name, then check for that name), "special inventory" is just referring to the inventory that you want to have infinite of the item
     
  24. Offline

    CeramicTitan

    Ambamore2000
    Why dont you look at the source of essentials and see how they do their free signs
     
  25. Offline

    xTigerRebornx

    CeramicTitan Eh, I can pseudo-code the Free sign
    Player clicks sign->check if it is free sign->get block from sign->create inventory with max stack of item in everyslot->profit
     
  26. Offline

    CeramicTitan

    The infinite chest plugin is actually quite easy in heinsight.
    Listen to PlayerInteractEvent, check If the right clicked block is a chest, create a fake inventory and set that inventory to the chests inventory
     
  27. Offline

    Ambamore2000

    CeramicTitan
    How to do "check If the right clicked block is a chest" and "create a fake inventory and set that inventory to the chests inventory"?
     
  28. Offline

    xTigerRebornx

  29. Offline

    Ambamore2000

Thread Status:
Not open for further replies.

Share This Page