Bukkit runnable

Discussion in 'Plugin Development' started by EnderMage, Feb 11, 2018.

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

    EnderMage

    So I'm trying to make boats faster on land like cars and so far I got this.
    I was told to delay the setting of the velocity 1 tick but I'm getting errors...
    If anyone could help I would be very thankful

    Show Spoiler
    Code:
    package customplugin.fr;
    
    import org.bukkit.entity.Boat;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.event.vehicle.VehicleDamageEvent;
    
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
    
    public final class BoatKart extends JavaPlugin {
    final FrostKart plugin;
    public BoatKart(FrostKart instance)
    {
    plugin=instance;}
    
    
    
    
    public void onVehicleDamage(VehicleDamageEvent event)
    {
    if(event.getVehicle() instanceof Boat)
    {
    if(event.getVehicle().getPassengers() instanceof Player)
    {
    event.setCancelled(true);
    }
    }
    
    
    BukkitScheduler scheduler = getServer().getScheduler();
    scheduler.scheduleSyncDelayedTask(this, new Runnable() {
        @Override
        public void run() {
           
    public void onPlayerMove(PlayerMoveEvent event) {
    //This is where it creates problems. It says errors at tokens ( and ) replace with ;
    Player player = event.getPlayer();
        if(player.getVehicle() != null && player.getVehicle() instanceof Boat) {
           
                Boat boat = (Boat) player.getVehicle();
           
            boat.setVelocity(boat.getVelocity().multiply(2.3));}
       }
        }
    }, 1L);
    }
    }
    
     
  2. Offline

    greeves12

    You know one tick is like a fraction of a second which would probably eventually crash the server. Try setting it to 20 which is a second or atleast 10 which is half a second

    And just saying that you are extending java plugin which should only be in the main class. You also don't have an onEnable and you're using a listener without even implementing it and adding @EventHandler

    I would suggest learning a bit of Java before attempting to make plugins as it will really benefit you.

    Sent from my Pixel using Tapatalk
     
  3. Offline

    timtower Administrator Administrator Moderator

    @EnderMage You can't put a method in a method.
     
  4. Offline

    EnderMage

    I updated my code a bit but it doesn't work for some reason

    Show Spoiler

    Code:
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent event) {
    
    Player player = event.getPlayer();
        if(player.getVehicle() != null && player.getVehicle() instanceof Boat) {
           
                Boat boat = (Boat) player.getVehicle();
                plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                    public void run() { boat.setVelocity(boat.getVelocity().multiply(10));}
                       
       
       
     }, 10,20);
    


    I forgot that detail.
    I was trying to get it working that I must added java plugin by accident

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 11, 2018
  5. Offline

    timtower Administrator Administrator Moderator

  6. Offline

    EnderMage

    The boat still has the same speed from before.
     
  7. Offline

    timtower Administrator Administrator Moderator

    Cancel all velocity without the runnable, does the player stay still?
    What if you give the velocity to the player?
     
  8. Offline

    EnderMage

    I cancelled the velocity and I could still move.
    And I tried to put player.getvelocity for the his velocity but nothing changed I fear,
     
  9. Offline

    greeves12

    Did you register the listener class in the onEnable?

    Sent from my Pixel using Tapatalk
     
  10. Offline

    EnderMage

    Yep
    I register the class on my main class
     
  11. Offline

    CrazyLukeHD

    You forgot the L in 10L, 20L. Don't know if this is necessary, though.
     
  12. Offline

    EnderMage

    Nope.
    The L aren't needed I believe.
     
Thread Status:
Not open for further replies.

Share This Page