Increasing speed of a player with vectors

Discussion in 'Plugin Development' started by zaregg, Nov 16, 2019.

  1. Offline

    zaregg

    I started coding a plugin that increased speed every couple of seconds. I could use setWalkSpeed() because you can't have a higher speed than 1 and I wanted to get faster speeds.

    Code:
    package zar.eggermont.customessentials.commands;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    import zar.eggermont.customessentials.Main;
    import zar.eggermont.customessentials.utils.Utils;
    
    public class SpeedChallengeCommand implements CommandExecutor {
    
        Main plugin;
    
        public SpeedChallengeCommand(Main plugin) {
            this.plugin = plugin;
    
            plugin.getCommand("speedchallenge").setExecutor(this);
        }
    
        List<String> toggled = new ArrayList<String>();
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage(Utils.chat(plugin.getConfig().getString("console_error_message")));
                return false;
            }
            if (!(toggled.contains(sender.getName()))) {
                for (Player p : Bukkit.getOnlinePlayers()) {
                    Bukkit.broadcastMessage(Utils.chat("&CThe &LSpeedChallenge &Chas now begun! "));
                    toggled.add(p.getName());
                    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
                        Bukkit.broadcastMessage(Utils.chat("Speed has &L&Cincreased!"));
                        p.setVelocity(p.getLocation());
                    }, 20L, 80L);
                }
                return false;
            } else if (toggled.contains(sender.getName())) {
                for (Player p : Bukkit.getOnlinePlayers()) {
                    toggled.remove(p.getName());
                    Bukkit.broadcastMessage(Utils.chat("&AThe &LSpeedChallenge &Ahas stopped"));
                    Bukkit.getScheduler().cancelTasks(plugin);
                    p.setWalkSpeed(0.2F);
                    return true;
                }
            }
            return false;
        }
    }
    it's not done and you can see where it went wrong. Can someone help me?
     

Share This Page