ok so i have been working on this very simple plugin that blocks the use of bonemeal completely. I am looking to mainly block it from being used in a dispenser or dropper also which is where my problem comes in. I found this was previously discussed and have snipped and adjusted it via a previous conversation based off the new 1.8. package me.jenks1999.bonemealchanger; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.plugin.java.JavaPlugin; public class bonemealchanger extends JavaPlugin implements Listener { public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } public void onDisable() { } { if (player.getItemInHand().getData().getData() == 15) { event.setCancelled(true); { } This throws 2 errors and i need to add dispensers and droppers to block the prospect of afk farms. Can anyone assist?
@jenks1999 Ok so first, you need to create a void, so that the event will actually be called. It should look like this: Code: @EventListener public void onBoneMealPlace(PlayerInteractEvent e){ // Your code here } Then, you should check for if it was a right click on block action. Code: if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){ // Your code here } After you check the action, you then check if it was bonemeal, and then cancel the event.
can you provide more information on this please? as it seems to produce too many errors in the 1.8 bukkit version. i # the locations where error is thrown thank you guys again for all your help on this im learning alot. My code so far (Move your mouse to reveal the content) My code so far (open) My code so far (close) import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.plugin.java.JavaPlugin; public class bonemealchanger extends JavaPlugin implements Listener { public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } public void onDisable() { } #@EventListener throws error @EventListener public void onBoneMealPlace(PlayerInteractEvent e) { if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { } #player throws error if (player.getItemInHand().getData().getData() == 15) { #event throws error event.setCancelled(true); } Side note this has to prevent dispensers and droppers also being used for this.
It is @EventHandler, not event listener. Maybe you should get the player first with Player player = e.getPlayer(); And you defined PlayerInteractEvent with "e". Why are you using event.setCancelled()? Use e.setCancelled(); Also use the insert code button.
1. Use google to see if other people did asked something similar 2. I'll help you with the dispenser thing, for dispensers you have to do it like this: https://bukkit.org/threads/remove-an-item-from-a-dispenser-on-item-dispense.163818/
@jenks1999 where did you get your player? did you check it for null? where did you get event? it surely is stated as e. it kinda looks like your java knowledge is not sufficient for programming plugins
@EpicCraft21 Thank you for your assistance. @tomudding That link helped loads thank you so much sir. @guitargun Thank you for your insults. In the help section. Bonemeal Code (Move your mouse to reveal the content) Bonemeal Code (open) Bonemeal Code (close) public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } public void onDisable() { } @EventHandler public void onDispenseItem(BlockDispenseEvent event) { ItemStack bone_meal = new ItemStack(Material.Bone_Meal); if(event.getItem().equals(Bone_Meal)) { event.setItem(new ItemStack(Material.REDSTONE)); } } } This alone should solve my problems but after careful investigating i have found an event that tracks dispensing in 1.8 net.minecraft.server.v1_8_R1; DispenseBehaviourBoneMeal I was wondering how this could simple be nulled or blocked from working? This specific event would solve all the issues i have.