Would this work?

Discussion in 'Plugin Development' started by XgXXSnipz, Jan 22, 2015.

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

    XgXXSnipz

    @BaconStripzMan to use it: just shift click and place the chest.. make sure your op... also if it doesnt work can you try to fix it :( Im not trying to be spoonfed <Edit by Moderator: Redacted mediafire url>
     
    Last edited by a moderator: Oct 30, 2016
  2. Offline

    BaconStripzMan

    Send me it :p
     
  3. Offline

    XgXXSnipz

  4. Offline

    sirrus86

    That's an NMS method, unless you know what you're doing you're gonna have a bad time.
     
  5. Offline

    XgXXSnipz

  6. Offline

    BaconStripzMan

    @XgXXSnipz Error in Main line 87, what's the line?
     
  7. Offline

    XgXXSnipz

    @BaconStripzMan
    Code:
    if(e.getBlock().equals(Block.getById(54)) && p.isOp() && p.isSneaking()){
    thats checking to see if the player places down a chest
     
  8. Offline

    Konato_K

    @XgXXSnipz Or you can, you know... get the type of the block and compare it with Material.CHEST?
     
    BaconStripzMan likes this.
  9. Offline

    BaconStripzMan

    e.getBlock().getType() == Material.REDSTONE_BLOCK

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

    XgXXSnipz

    @BaconStripzMan @Konato_K :'( wow... how did I not know that

    @BaconStripzMan @Konato_K @sirrus86 K all of it works except cancelling the chest opening then giving them random items: Scroll back to the first page to see that code

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

    teej107

  12. Offline

    XgXXSnipz

    @teej107 clicking the double chest.. and giving random items
     
  13. Offline

    BladeXTD

    Also try using NotePad++ for formatting errors.
     
  14. Offline

    teej107

    @XgXXSnipz So no errors in the console? If it's a logical error, put in debug code.
     
  15. I was reading this post and i was thinking "is getType(), is getType()" like this was a questions game .

    That's pretty easy when i get in home ill help you .

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

    Burnett

    @XgXXSnipz Create an EventListener for PlayerInteractEvent. Check if action is right click. If yes, check if block clicked is a chest. Finally check if the chest clicked is a chest that you want players to be able to get random items from (location of chest from config etc.), cancel the event and proceed to give them the items.
     
  17. Offline

    ZanderMan9

    I'd recommend putting Listeners in a different class. I have run into issues with making my main JavaPlugin class the same one that implements Listener before. Just to be sure that won't cause issues, you should separate it.
     
  18. Offline

    XgXXSnipz

  19. Create the method in another place .

    Something like this should work
    Code:java
    1.  
    2. public ItemStack getRandomItem() {
    3. int random = new Random().nextInt(4);
    4. if(random == 1) {
    5. return new ItemStack(276, 1);
    6. }
    7. return null;
    8. }
    9.  
     
  20. Offline

    sirrus86

    When you say random items, do you mean random items from within the chest, or random items from a list, or just completely random items?
     
  21. Offline

    XgXXSnipz

    @sirrus86 completely random Items, so it gives a player random items when he clicks a chest that is created by a admin

    @MaTaMoR_ and this will give a player 4 random items?

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

    ColonelHedgehog

    No. All it does is make it 25% likely that if you call the method, it will not return null.
     
  23. Offline

    SuperOriginal

    @XgXXSnipz Have a list of items, and pick a random one out of it 4 times..
     
  24. Yes this is a really basic example, with basic java knowledge you can do it much better.

    Code:java
    1.  
    2. //You can do something like this
    3. public void giveRandomItems(Player player) {
    4. //List with your items called something like "list"
    5. //You can just do it 4 times ... why not ?
    6. player./give/.(list.get(Random().nextInt(list.getSize()));
    7. player./give/.(list.get(Random().nextInt(list.getSize()));
    8. player./give/.(list.get(Random().nextInt(list.getSize()));
    9. player./give/.(list.get(Random().nextInt(list.getSize()));
    10. }
    11.  


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

    XgXXSnipz

    @MaTaMoR_ how do I add items to a list: like this?
    Code:
    ItemStack hubitems = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
                       ItemMeta hubmeta = hubitems.getItemMeta();
                       ArrayList<String> hub = new ArrayList<String>();
                       hubmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD + "Wingsuit");
                       hub.add(ChatColor.RED +  "I CAN FLY!");
                       hubmeta.setLore(hub);
                       hubitems.setItemMeta(hubmeta);
     
  26. Offline

    Skionz

  27. Offline

    XgXXSnipz

    @Skionz how do I "list" them.. Im sorta new to all of this
     
  28. Offline

    Skionz

  29. Offline

    XgXXSnipz

    @Skionz
    Code:
    private ItemStack test;
    ?
     
  30. Offline

    Skionz

Thread Status:
Not open for further replies.

Share This Page