Solved Boat doesn't break

Discussion in 'Plugin Development' started by Vaughan, Nov 8, 2012.

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

    Vaughan

    Hi guys,

    Yeah another thread (hopefully this doesn't count as "spam"). Basically, I want a plugin that when you're in a boat and it hits an object; it will not break and just leaves you as you where.

    If I'm semi-right it would look something like: (This isn't obviously the Java, just the logic)

    Code:
    method being boatEvent
     
    if {the player is in a boat
    and it hits an object
     
    then
     
    do not break the boat
    }
    Is this possible? Again, if anyone answers could you explain why it's happening. It help's a lot.

    I know the basic's of Java, learning more every day (hour in fact) and I'm also sorry if these thread are some what "spamming" this section of the forum. I believe that they're good not just for me but others who do a search on a similar topic and see a solution to my problem (which they may have too).
     
  2. Offline

    Keeschaap

    I don't know if I'm right, but maybe you can change something in the metadata? http://jd.bukkit.org/apidocs/ Interface Boat -> inherited method getMetadata() . Can't try it now, but maybe it works :3 (I'm new to Bukkit, so I don't have any experience with this..)
     
  3. Offline

    SyTeck

    You can listen to an event checking if a vehicle was destroyed.

    Code:
    public void onBoat(VehicleDestroyEvent e) { //the void that reacts when the event is throwed
     
            if(!(e.getVehicle() instanceof Boat)) return; //checks if the vehicle is a boat, and returns if it isn't
     
            e.setCancelled(true); //cancels the event
     
        }
     
    Vaughan likes this.
  4. Offline

    fireblast709

    How about this, not 100% sure if it works
    Code:java
    1. @EventHandler
    2. public void onCollision(VehicleCollisionEvent event)
    3. {
    4. if(event.getVehicle() instanceof Boat && event.getVehicle().getPassenger() instanceof Player)
    5. {
    6. event.setCancelled(true);
    7. }
    8. }
     
    Vaughan likes this.
  5. Offline

    Vaughan

    SyTeck Thank you, nicely explained! :)

    When I used this, it set the "event.setCancelled(true);" as an error.

    Also, is there another method I could include so players can actually break the boat?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  6. Offline

    SyTeck

    Does eclipse give you an error?

    EDIT: Just set event.cancelled(true); to event.cancelled(false);. It's pretty self explaining.
     
  7. Offline

    Vaughan

    I mean.. so they dont break UNLESS a player breaks it if that makes sence. So I could set an if statement to say if a play left clicks a lot?
     
  8. Offline

    SyTeck

    Try this:
    Code:
    public void onBoat(VehicleDestroyEvent e) { //the void that reacts when the event is throwed
     
            if(!(e.getVehicle() instanceof Boat)) return; //checks if the vehicle is a boat, and returns if it isn't
     
            if(e.getAttacker() instanceof Player) { //checks if the attacker is a player
     
            e.setCancelled(false); // 
     
            } else {
     
            e.setCancelled(true); //cancels the event
     
        }
    }
    (not tested)

    edit: Use this instead:

    Code:
    public void onBoat(VehicleDestroyEvent e) { //the void that reacts when the event is throwed
     
            if(!(e.getVehicle() instanceof Boat)) return; //checks if the vehicle is a boat, and returns if it isn't
     
            if(e.getAttacker() instanceof Player) return; // ^
     
     
            e.setCancelled(true); //cancels the event
     
        }
     
    Vaughan likes this.
  9. Offline

    Vaughan

    That worked great! Thank you very much!

    So.. this adds the player instance and says if the player (getAttacker) then destroy the boat .. if not, cancel the event?
     
  10. Offline

    SyTeck

    No problem :)

    It checks if the attacker is an instance of a EntityPlayer, if it is it returns, if not it cancels the event.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  11. Offline

    Vaughan

    Thank you. :)
     
Thread Status:
Not open for further replies.

Share This Page