Solved Multiple Bucket Uses

Discussion in 'Spigot Plugin Development' started by Futurize, May 16, 2017.

  1. Hello guys, I am trying to make a water bucket with multiple uses. Right now, I am listening for the PlayerBucketEmptyEvent, cancelling it and manually placing the water, and then checking the lore for the amount of uses a player has left and subtracting it by one. Is there a more efficient way of doing this that is more flexible for plugins that prevent players from placing buckets and doesn't involve manually placing the water?
     
  2. Material bucket is passed in that event, so just change it to a full bucket?
     
  3. getBucket() just returns the material of the bucket. I tried this:
    Code (Text):
            e.getItemStack().setType(Material.WATER_BUCKET);
            e.getPlayer().updateInventory();
    and it did not work. Any extra help?
     
  4. Have you registered the event? (Can you confirm that it's firing off)
     
  5. That has nothing to do with the post, the current way is working fine but I am looking for a more efficient way that doesn't involve manually placing water.
     
  6. Player player = e.getPlayer();
    if(player.getItemInMainHand() == e.getBucket())
    make a new bucket and put it in their main hand
    if its not in the main hand check getItemInOffHand()
     
  7. Yeah I was thinking that was what I would have to do. Thank you for the help.
     
  8. I 'think' when the event fires the bucket is still full, so you might need to do a runnable and change it a tick or 2 later?
     
  9. This is definitely not hard at all.

    Basically its similar to this:

    Code (Text):

    @EventHandler
    public void placeWater(PlayerInteractEvent e){
       
        Player player = e.getPlayer();
       
        if(e.getAction() == Action.RIGHT_CLICK_BLOCK){ // Check if the Interact Action was a Right Click to a Block
           
            if(player.getItemInHand() != null){ // Make sure the Player's Item In Hand is not null / empty
               
                if(player.getItemInHand().getType() == Material.WATER_BUCKET){ // Check if the Player's Item In Hand is a Water Bucket
                   
                    e.setUseItemInHand(Event.Result.DENY); // Deny the Interaction with the Item ( So the Item won't be lost )
                   
                    e.getClickedBlock().getRelative(e.getBlockFace()).setType(Material.WATER); // Place "WATER" on the related blockface direction
                   
                }
            }
        }
    }

     
     
  10. Well gotta admit thats some clean code and it gets the job done, but he was wanting to avoid placing the water himself for whatever reason. Would it be possible to deny result in PlayerBucketEmpty result? Just check to make sure its a water bucket first and that the count isn't 0.
     
  11. Yep have seen that, but @Futurize just asking, why don't you want to place the material ? Its still the best, fastest and easiest way.
     
  12. It seems like stopping the item from being changed in the bucket event would be even easier, no placing a block, heck prolly don't even have to check action, just check that getBucket() is Material.WATER_BUCKET
     
  13. Enchanted bucket plugin, have some crafting recipe for it, something annoying to get included like a clown fish :p Yes I'm a lil evil I like making players fish o_O
     
  14. Yea could be, never used the Bucket Event maybe there's something to set the bucket state back to full
     
  15. Untested but i think this should work

    Code (Text):

    @EventHandler
    public void emptyBucket(PlayerBucketEmptyEvent e){
        if(e.getBucket() == Material.WATER_BUCKET) {
            e.setItemStack(new ItemStack(e.getBucket()));
        }
    }

     
     
  16. Why not cancel the event and just set water at the location they wanted? Unsure if it's the best option but you could do that
     
  17. Has been already mentioned by me some posts above :rolleyes:, but @Futurize said that he don't wanna like place the block at the location, he wants to update the inventory of the player then, even if its less easier ( i think )
     
  18. Ohhhh sorry my bad didn't see it, unless he sets the item to be a water bucket again, similarly to what you said.
     
  19. The reason I don't want to manually place it is because I am using factions and worldguard and I wouldn't want to manually check if the player is able to build in land.
     
  20. the plugin's are most likely cancelling the event when preventing building on certain areas, so check if the event is cancelled before executing your own stuff. they're probably checking for the interact event, rather than the bucketempty event itself, not too sure.