Solved place boat when right click water(Need Help)

Discussion in 'Plugin Development' started by BeastCraft3, Sep 16, 2014.

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

    BeastCraft3

    Hello, I nearly done with my plugin I just dont know how to make it place the boat. My code:
    Code:java
    1. @EventHandler
    2. public void onRightClickWater(PlayerInteractEvent e){
    3. Player p = e.getPlayer();
    4. if (e.getAction() == Action.RIGHT_CLICK_BLOCK && p.hasPermission("BeastFac.boat")) {
    5. List<Block> lineOfSight = e.getPlayer().getLineOfSight(null, 5);
    6. for (Block b : lineOfSight) {
    7. if (b.getType() == Material.STATIONARY_WATER) {
    8. ItemStack is = new ItemStack(Material.BOAT);
    9. e.getClickedBlock().getLocation();
    10. break;
    11. }
    12. }
    13. }
    14. }
     
  2. Offline

    4thegame3

    Its an entity
    loc.getWorld().spawnEntity(loc, EntityType.BOAT);
     
  3. Offline

    BeastCraft3

    4thegame3
    Mind if I ask you something else as well?
    I'm wondering how to disable the boat from dropping loot when it gets destroyed.
    this is my code that didnt work.

     
  4. Offline

    4thegame3

    VehicleDestroyEvent e
     
  5. Offline

    BeastCraft3

    4thegame3
    Thank you! ;)

    4thegame3
    1) Sorry for double posting :(.
    2) I tried this but it wont work:
    Code:java
    1. @EventHandler
    2. public void onBoatDestroy(VehicleDestroyEvent event) {
    3. if(event.getVehicle().getType() == EntityType.BOAT){
    4. Vehicle boat = event.getVehicle();
    5. event.setCancelled(true);
    6. boat.remove();
    7.  
    8. }
    9. }


    And

    Code:java
    1. @EventHandler
    2. public void onBoatDestroy(VehicleDestroyEvent event) {
    3. event.getVehicle().remove();
    4. }


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

    McMhz

    BeastCraft3
    That's just removing the boat, I'd try using lists and the Item Drop Event.
     
  7. Offline

    BeastCraft3

    McMhz
    What could possible be inside the PlayerItemDropEvent?
     
  8. Offline

    McMhz

    This is basically what you want to do (not in java ofc):
    Code:
    ON BOAT BREAK{
      CHECK IF ITEM IS BOAT:
      IF TRUE THEN ADD TO LIST<BOAT>
    }
     
    ON ITEM DROP (ItemSpawnEvent){
      CHECK IF ITEM IS BOAT AND IS IN BOAT LIST.
      IF TRUE THEN REMOVE ITEMSTACK.
    }
     
     
     
     
    
     
  9. Offline

    BeastCraft3

    McMhz
    Could you give me some regular java code to work out of? and I just need the part that disable a boat to drop sticks and planks.
     
  10. Offline

    McMhz

    BeastCraft3
    Oh, a crashed boat?
    I'll test some stuff and tell you if it works.

    BeastCraft3
    Okay, Sorry for the delay I had stuff to do.
    Anyway, this code works for me:

    Code:java
    1. @EventHandler
    2. public void onDestroy(VehicleDestroyEvent e){
    3. if(e.getVehicle().getType() == EntityType.BOAT){
    4. e.setCancelled(true);
    5. e.getVehicle().remove();
    6. }
    7. }


    EDIT: If you want it to drop the boat too, you can just spawn a boat item in the onDestroy event.

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

    BeastCraft3

  12. Offline

    McMhz

    Glad to help.
     
Thread Status:
Not open for further replies.

Share This Page