When right-click a player, I want to milk the bucket. but. After the item is milk, it will go back to the empty bucket. Do you have a good idea? test code: Code: @EventHandler public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) { Entity entity = event.getRightClicked(); Player player = event.getPlayer(); ItemStack itemStack = player.getItemInHand(); if (entity.getType() == EntityType.PLAYER && itemStack.getType() == Material.BUCKET) { player.setItemInHand(new ItemStack(Material.MILK_BUCKET)); } } I'm sorry not good at English...
You'll need to add 'itemStack != null' before you check the type of the item just to prevent errors when the player has nothing in their hand. Also, what's wrong with your current code, it seems as though it should work properly.
This isn't a bug; 'eating' (or drinking, in this case) of milk removes all bad active potion effects from the user.
Not hold down the right-click. ended up drinking with a single click. My screen effects that are not drinking(or eating). From the point of view of other users, seem to like (or eating) are drinking.
I don't understand, you want to: when a player right click another one, the bucket become full of milk and then the bucket return empty? For this, try this code: Code: @EventHandler public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) { Player clicked = (Player) event.getRightClicked(); Player player = event.getPlayer(); ItemStack milkbucket = new ItemStack(Material.MILK_BUCKET); ItemStack emptybucket = new ItemStack(Material.BUCKET); if (player.getItemInHand().getType() == Material.BUCKET && event.getPlayer() == player && event.getRightClicked() == clicked) { player.setItemInHand(milkbucket); // milk the bucket player.setItemInHand(emptybucket); // the milk bucket return empty return; } }
I want to: 1.Right-click on the player 2.If I have an empty bucket 3.Replace the milk bucket 4.End. But. In the test code after this, they drink the milk. I want to not drink it.
event.setCancelled(true) might cancel the attempt to drik the milk ? Still, doesn't drinking involve an animation and a delay on drinking... ? Why are you holding the click then ?
They drink even if event.setCancelled(true). Please try. https://www.dropbox.com/s/qn4ckl8xful7261/GetMilk.jar
I just tested it and it works for PlayerInteractEvent, only it doesn't block the animation and the sound, as long as you hold down the button you'll hear the sound, the animation will play once, but the item will not be consumed. You might also check if your setCancelled even triggers, maybe there's something wrong with the conditions.
Hmm .... In my environment, I did not hold down the button, But,Goes back to the empty bucket. I do cause unknown... My environment Server: Bukkit 1.2.5-R4.0 #2222 This plugin only. Client: Minecraft1.2.5 NoMOD. GetMilk Code Code: @EventHandler public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) { if (event.isCancelled()) { return; } Entity entity = event.getRightClicked(); Player player = event.getPlayer(); ItemStack itemStack = player.getItemInHand(); Material material = itemStack.getType(); if (entity.getType() == EntityType.PLAYER) { if (material == Material.BUCKET) { ItemStack milk = new ItemStack(Material.MILK_BUCKET); player.setItemInHand(milk); event.setCancelled(true); } } }
Not related to your issue but you can just add 'ignoreCancelled = true' to your eventhandler annotation and remove the return code.