Riding Animals Cancel Event Help

Discussion in 'Plugin Development' started by XinityDevs, Mar 29, 2016.

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



    I am trying to limit only setting a passenger to a cow but can not work it out for some reason. My code seems logical but I dont know why it doesnt work. Here it is.

    package com.xinity.dreamanimals;
    import org.bukkit.entity.Cow;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Main extends JavaPlugin implements Listener {
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent e) {
            if(e.getPlayer().hasPermission("dreamscape.ride.cow")) {
            if (e instanceof Cow);
            if (!(e instanceof Cow));
  2. Offline


    • You're checking if the event is instanceof a Cow. Instead, check if the right clicked entity is a cow, not the event itself.
    • Also, instead of ending your if statements with semicolons, end them with curly brackets, or none at all.
    Zombie_Striker and Gonmarte like this.
  3. Offline


    I've tried doing that but nothing is working for me. How do you actually define the entity? I thought making a variable would do the trick but I don't know what to put it down to. Like what do I put in e.getRightClicked([Here]) to get the Cow, I am unfamiliar with entities in the Bukkit API so I was wondering if someone could point me to somewhere I could get some help or let me know here please? Thank you by the way for labeling what I've done wrong, I fixed it up apart from the getting the Cow part.
  4. Offline


    Well, there are not arguments to getRightClicked, so you don't need to put anything inside those brackets to get the entity. Check if the right clicked entity is an instanceOf Cow, and set the player has the passage. BTW: replace the next if statement with "Else", as it is the reverse of the first if statement.
  5. Offline


    Your only problem is that you don't know, how 1-line-ifs work. Remove the semicolons after the if statements, and format your code.
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page