runTaskTimer = UnsupportedOperationException

Discussion in 'Plugin Development' started by Sw_aG, Dec 22, 2019.

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

    Sw_aG

    Hello fellow devs !

    I'm trying to run a repeating task and to end it when I need it.
    I'll start by saying I'm using scheduleAsyncRepeatingTask because runTaskTimer doesn't work for me (I did extended BukkitRunnable), I can't seem to set the taskId correct.
    here's the error "runTaskTimer" itself gives me (I gave it a full line and it proved me it was "runTaskTimer"):

    PHP:
    [08:11:25] [Server thread/ERROR]: null
    org
    .bukkit.command.CommandExceptionUnhandled exception executing command 'vanish' in plugin City v1
            at org
    .bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at org.bukkit.craftbukkit.v1_15_R1.CraftServer.dispatchCommand(CraftServer.java:711) ~[spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.PlayerConnection.handleCommand(PlayerConnection.java:1657) ~[spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:1497) ~[spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) [spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(SourceFile:144) [spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(SourceFile:118) [spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.MinecraftServer.aZ(MinecraftServer.java:917) [spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.MinecraftServer.executeNext(MinecraftServer.java:910) [spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) [spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.MinecraftServer.sleepForTick(MinecraftServer.java:894) [spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:827) [spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
    Caused byjava.lang.UnsupportedOperationException: Use BukkitRunnable#runTaskTimer(Plugin, long, long)
            
    at org.bukkit.craftbukkit.v1_15_R1.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:533) ~[spigot.jar:git-Spigot-f39a89e-4633e6c]
            
    at second.barmsg.barmsg(barmsg.java:28) ~[?:?]
            
    at main.First.vanish(First.java:1091) ~[?:?]
            
    at main.First.onCommand(First.java:673) ~[?:?]
            
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot.jar:git-Spigot-f39a89e-4633e6c]
            ... 
    17 more

    If you know any other way to cancel the repeating task is good, if you know what's wrong with the runTaskTimer, also works.
    Thanks in advance
     
    Last edited: Dec 22, 2019
  2. Offline

    LouShunt

    Hello, so to create a runtasktimer you will need to create a new BukkitRunnable. Just like this
    Code:
    new BukkitRunnable() {
    
        @Override
        public void run() {
            //Your code  
        }
              
    }.runTaskTimer(this, 20, 20);
    You can create task with a BukkitRunnable like the code before. Or a Runnable like you did but instead of "
    new BukkitRunnable()" you will have to put "new Runnable()"
     
Thread Status:
Not open for further replies.

Share This Page