Check if Player is standing still.

Discussion in 'Plugin Development' started by VNGC, Mar 4, 2020.

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

    Kars

    @VNGC Yea, okay. Velocity is a vector, i have no idea how it works. Maybe @timtower can help you with it.
     
  2. Offline

    VNGC

    Code:
    package com.vngc.listeners;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    
    public class MoveDamage implements Listener{
      
        Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(MoveDamage, new BukkitRunnable() {
            public void run() {
                    for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                    if (player.getVelocity() > 0) {
                        // player is moving or has moved
                    } else {
                        // player is not moving
                    }
                }
            }
        }, 0L, 20L);
    }
    }
    EDIT by Moderator: added code block
     
    Last edited by a moderator: Mar 5, 2020
  3. Online

    timtower Administrator Administrator Moderator

    @VNGC Get the length of the velocity.
    You don't have a function so it will never work, it is not a listener either.
    Move it to the onEnable of the main class instead.
    MoveDamage is not the main plugin so you can't use that as plugin argument.
     
  4. Offline

    Kars

    @VNGC May i suggest wrapping code in a code block on the forum, and using proper indenting for clarity.
     
  5. Offline

    VNGC

    so like this?
    Code:
        @SuppressWarnings("deprecation")
        @Override
        public void onEnable() {
            plugin =this;
          
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new BukkitRunnable() {
                public void run() {
                        for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                        if (player.getVelocity().length() > 0) {
                            // player is moving or has moved
                        } else {
                            // player is not moving
                        }
                    }
                }
            }, 0L, 20L);

    btw sry for before, i was in trouble and forgot to put it in a codeblock :c
    well for sure i has to add the damage but i mean the base
     
  6. Online

    timtower Administrator Administrator Moderator

    @VNGC Just missing the damage part.
     
  7. Offline

    VNGC

    well, not working.

    Code:
    public class Main extends JavaPlugin {
        private static Main plugin;
    
        @SuppressWarnings("deprecation")
        @Override
        public void onEnable() {
            plugin =this;
          
    
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new BukkitRunnable() {
                public void run() {
                        for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                        if (player.getVelocity().length() > 0) {
                            //do nothing
                        } else {
                            player.damage(1);
                        }
                    }
                }
            }, 0L, 20L); 
     
  8. Offline

    Kars

    @VNGC I think getVelocity returns a vector with the 3 velocity values for X, Y and Z. Simply checking if the length is above 0 will always be true.

    Again, i can't be sure nor can i validate even syntax, but try this:
    PHP:
    public void run() {
        for (
    Player player Bukkit.getServer().getOnlinePlayers()) {
            
    boolean playerIsMoving false;
          
            for (
    Integer value player.getVelocity()) {
                if (
    value != 0) {
                    
    playerIsMoving true;
                }
            }
          
            if (!
    playerIsMoving) {
                
    player.damage(1);
            }
        }
    }
     
  9. Online

    timtower Administrator Administrator Moderator

  10. Offline

    Kars

    timtower likes this.
  11. Offline

    VNGC

    i get this error on getVelocity, same if i add .length():
    Can only iterate over an array or an instance of java.lang.Iterable

    i think if this is good it should actually work. i think.
     
    Last edited: Mar 5, 2020
  12. Online

    timtower Administrator Administrator Moderator

    @VNGC Have you printed the values of the vector length?
     
  13. Offline

    VNGC

    maybe, if i would know how...


    Code:
        @SuppressWarnings("deprecation")
        @Override
        public void onEnable() {
            plugin =this;
           
    
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new BukkitRunnable() {
                public void run() {
                    for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                        boolean playerIsMoving = false;
                     
                        for (Integer value : player.getVelocity().length()){
                            if (value != 0) {
                                playerIsMoving = true;
                            }
                        }
                     
                        if (!playerIsMoving) {
                            player.damage(1);
                        }
                    }
                }
            }, 20L, 20L);        
     
  14. Online

    timtower Administrator Administrator Moderator

    @VNGC You can't loop over length, it is a single value. A double, not an integer.
    And you do not know how you use System.out.println or Bukkit.broadcastMessage?
     
  15. Offline

    VNGC

    so i cleared the .length().
    and yes, idk how to use System.out.Println, but broadcastmessage is sending a public message on server. this i am using in my Listeners, but idk how/where to use it here

    i said often, i am a noob if i can say so
     
  16. Online

    timtower Administrator Administrator Moderator

    @VNGC Where you have the value of player.getVelocity().length() and you want to see it so you can debug it.
     
  17. Offline

    VNGC

    i dont know what you said. i never used this println or broadcast in this case. u used broadcastmessage only for telling player specific messages in listeners, not more
     
  18. Online

    timtower Administrator Administrator Moderator

    The only thing what is different is that you put a value in them, not a string.
    Bukkit.broadcastMessage(""+player.getVelocity().length()) ?
     
  19. Offline

    VNGC

    and then the actual value is giving out in chat or what

    well i used this sysout thing 1 time, on beginning. but just as test for an console print out. but not more, and i dont know anything anymore about it
     
  20. Online

    timtower Administrator Administrator Moderator

    Try it and find out.
     
  21. Offline

    VNGC

    but i still get this error and cant export with it:

    upload_2020-3-6_8-36-8.png
     
  22. Online

    timtower Administrator Administrator Moderator

    @VNGC Let me quote myself:
     
  23. Offline

    VNGC

    that means i have to do what? :c
    set the integer to double or what, i dont get it
     
  24. Online

    timtower Administrator Administrator Moderator

    Remove the loop.
     
  25. Offline

    VNGC

    i dont know if its because i am german, but what is the loop there? ouff
     
  26. Online

    timtower Administrator Administrator Moderator

    Has nothing to do with being german.
    I am not gonna help anymore.
    You lack the basics of Java in my opinion, you blankly copy pasted what was given without knowing simple loops.
     
  27. Offline

    VNGC

    can you maybe post me a link or somewhat how i can get what the loop is? :c
     
  28. Online

    timtower Administrator Administrator Moderator

    Tried google?
     
  29. Offline

    VNGC

    yeah i am googleing the whole time, because i know you dont want to spoonfeed me. but i cant find out anything. like i said, im dumb, i learned all i know from tutorials, and to be honest, there are no good german coding tutorials out there. everything is just watch and copy/paste. thats my problem
     
  30. Online

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page