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 remove everything in the onlinePlayers loop except the broadcastMessage and see what velocity is for you in different scenarios while walking around in game. It should print your getVelocity.length every second if you do that.

    Furthermore, if you can't code at all, this isn't the right section for you. Maybe try putting this in the plugin request section.
     
    timtower likes this.
  2. Offline

    VNGC

    @Kars so only this?

    Code:
     Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new BukkitRunnable() {
                public void run() {
                    for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                    Bukkit.broadcastMessage(""+player.getVelocity().length());                  
                    }
                }
            }, 20L, 20L);        
     
  3. Online

    timtower Administrator Administrator Moderator

    @VNGC Also a thing about programming: best way to find out if something is good is by trying it.
     
  4. Offline

    VNGC

    Error occurred while enabling Challenges (Is it up to date?) java.lang.UnsupportedOperationException: Use BukkitRunnable#runTaskTimer(Plugin, long, long)

    i tought it works if i add @SuppressWarnings("deprecation")
     
  5. Online

    timtower Administrator Administrator Moderator

    @VNGC Nope, you are using old tutorials.
     
  6. Offline

    VNGC

    Code:
      Bukkit.getServer().getScheduler().runTaskTimer(this, new BukkitRunnable() {
    aren't they there? doesnt looks wrong
     
  7. Online

    timtower Administrator Administrator Moderator

    @VNGC Is that code throwing errors?
     
  8. Offline

    VNGC

    in the console it says that its the fault of this line.
     
  9. Online

    timtower Administrator Administrator Moderator

    Then you make a BukkitRunnable, call runTaskTimer on it WITHOUT using the scheduler.
     
  10. Offline

    VNGC

    now working. but it is showing me in chat only the Y-Velocity i think? the value is only changing if i jump, not if running
     
  11. Offline

    Kars

    @VNGC So you need to apply the method that i initially suggested.
    Make a static variable that is able to store a players location. In the repeating task, if the variable is set, compare it to the players current location and if it is different, you will know that they have moved. After that, save the players current location to the static variable.

    If you don't understand, that is fine. This is too big a task to assist with. Make a plugin request.
     
  12. Online

    timtower Administrator Administrator Moderator

    Could you post your new code?
     
  13. Offline

    VNGC

    @timtower

    Code:
    public class Main extends JavaPlugin {
        private static Main plugin;
    
        @Override
        public void onEnable() {
            plugin =this;
         
    
            new BukkitRunnable() {
                public void run() {
                    for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                    Bukkit.broadcastMessage("" + player.getVelocity().length()); 
                 
                    }
                }
            }.runTaskTimer(plugin, 20L, 20L);
            //Commands
         
            getCommand("noblockplace").setExecutor(new Command_NoBlockPlace());
            getCommand("noblockbreak").setExecutor(new Command_NoBlockBreak());
            getCommand("nocrafting").setExecutor(new Command_NoCrafting());
            getCommand("noexp").setExecutor(new Command_NoExp());
            getCommand("nosneak").setExecutor(new Command_NoSneak());
            getCommand("chatdamage").setExecutor(new Command_ChatDamage());
            getCommand("cutclean").setExecutor(new Command_CutClean());
            getCommand("nofalldamage").setExecutor(new Command_NoFallDamage());
            getCommand("heal").setExecutor(new Command_Heal());
            getCommand("hp").setExecutor(new Command_HP());
            getCommand("reset").setExecutor(new Command_Reset());
            getCommand("movedamage").setExecutor(new Command_MoveDamage());
         
         
            //Listener
         
            PluginManager pm = Bukkit.getPluginManager();
            pm.registerEvents(new NoBlockPlaceListener(), this);
            pm.registerEvents(new NoBlockBreakListener(), this);
            pm.registerEvents(new NoCraftingListener(), this);
            pm.registerEvents(new OnPlayerJoinListener(), this);
            pm.registerEvents(new NoExpListener(), this);
            pm.registerEvents(new NoSneakListener(), this);
            pm.registerEvents(new DeathMessageListener(), this);
            pm.registerEvents(new ChatDamageListener(), this);             
            pm.registerEvents(new CutCleanListener(), this);
            pm.registerEvents(new NoFallDamageListener(), this);
         
         
         
         
         
            }
     
         
    
    
        @Override
            public void onLoad() {      
                plugin =this;
                deleteWorld("world");
                deleteWorld("world_nether");
                deleteWorld("world_the_end");
         }
         public void deleteWorld(String worldName) {
                Path pathToBeDeleted = Bukkit.getWorldContainer().toPath().resolve(worldName);
    
                try {
                    Files.walk(pathToBeDeleted)
                      .sorted(Comparator.reverseOrder())
                      .map(Path::toFile)
                      .forEach(File::delete);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        public static Main getPlugin() {
            return plugin;    
        }
        @Override
        public void onDisable() {
            plugin =this;
         
        }
    
    }
    the only thing i edited now:
    if(Command_MoveDamage.movedamage){
    so i can turn it on/off.
     
    Last edited: Mar 6, 2020
Thread Status:
Not open for further replies.

Share This Page