HELP PLZ i need a way of making it so when you sprint you get the potion buff confused after running

Discussion in 'Spigot Plugin Help' started by dmb219910, Jun 10, 2016.

  1. Hey i need a way of making it so you get potion effect type confusion after 15 seconds of sprinting i tried adding a
    void run but that didnt work because i cant add extends java plugin to a listener is there a way for the timer to start in my main class when the player starts sprinting?

    My classes

    Code (Text):
    package me.dmb219910;

    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerToggleSprintEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class PlayerListener implements Listener{

        public PlayerListener(StartUp plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);

        public void OnSprint (PlayerToggleSprintEvent e ) {
            Player player = e.getPlayer();
            player.addPotionEffect((new PotionEffect(PotionEffectType.CONFUSION, 200, 10)));  


    Code (Text):
    package me.dmb219910;


    import net.md_5.bungee.api.ChatColor;

    public class StartUp extends JavaPlugin {

        public void onEnable() {
        new PlayerListener(this);
        getLogger().info(ChatColor.GREEN + "Spring Effects HAVE BEEN SUCCESFULLY ENABLED!");  

            public void onDisable() {
                getLogger().info(ChatColor.GREEN + "Spring Effects HAVE BEEN SUCCESFULLY DISABLED!");  

  2. Try registering your event in your main class in onEnable.
  3. Did you try: *for the delay*
    Code (Text):
            Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                public void run() {
                    // TODO Auto-generated method stub
            }, <timeinticks>)
  4. Yes
  5. See it wount work with implements only with the extends java plugin but i cant add that to a listener clas
  6. You could send an instance to the listener class

    Use this in your main class:

    public static StartUp getInstance(){

    return JavaPlugin.getPlugin(StartUp.class);


    Then to use something that requires the class to be extended by javaplugin use:

  7. So in your case: StartUp.getInstance().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    • Useful Useful x 1
  8. That dosent seem to work im getting a error on getScheduler
  9. Can you direct me on how to do that sorry D;
  10. D;
  11. Please only bump once per day.
  12. ok D:
  13. do you know how to solve this problem sir?
  14. Fixed for OP. Surprised how you guys wanted to do all that hard work when you can easily do this:

    Code (Text):
            try {
                Thread.sleep(15000); //This is 15 seconds in milliseconds
            } catch(InterruptedException ex) {
            player.addPotionEffect((new PotionEffect(PotionEffectType.CONFUSION, 200, 10)));
  15. I need to put it under if plaayer is sprinting but it works but it puts hole bunch of lag on the server