Bonemealchanger

Discussion in 'Plugin Development' started by jenks1999, Feb 26, 2015.

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

    jenks1999

    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?
     
  2. Offline

    redside100

    @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.
     
  3. Offline

    jenks1999

    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 (open)

    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.
     
    Last edited: Feb 27, 2015
  4. Offline

    EpicCraft21

    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.
     
  5. Offline

    tomudding

  6. Offline

    guitargun

    @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
     
  7. Offline

    jenks1999

    @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 (open)

    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.
     
  8. Offline

    EpicCraft21

    Just cancel the event.
     
Thread Status:
Not open for further replies.

Share This Page