Solved Console Command Help

Discussion in 'Spigot Plugin Development' started by fangshenghan, Feb 14, 2020.

  1. I'm making a plugin.I want to type a command(hologram command) in console between 5 seconds, so i use the timer. ↓
    Code (Java):
    static java.util.Timer timer = new java.util.Timer(true);
        static TimerTask task = new TimerTask() {
            public void run() {
        public static void start() {
            timer.schedule(task, 0, 5000);
        public static void stop() {
    But when timer run
    Code (Java):
    Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "My Command");
    There is an error, how can i do that?
    If i don't use timer, it works.
  2. You didn't post the error...
    Based on your description I'd say you are dealing with some sort of concurrent exception which can be resolved by using a synchronous Bukkit-task.
  3. Code (Java):
    [22:16:18 WARN]: Exception in thread "Timer-39"
    [22:16:18 WARN]: org.bukkit.command.CommandException: Unhandled exception executing command 'holograms' in plugin HolographicDisplays v2.4.0
    [22:16:18 WARN]:        at org.bukkit.command.PluginCommand.execute(
    [22:16:18 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(
    [22:16:18 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(
    [22:16:18 WARN]:        at org.bukkit.Bukkit.dispatchCommand(
    [22:16:18 WARN]:        at Scoreboard.Score.SetPlayer(
    [22:16:18 WARN]:        at Scoreboard.Score.LoadAll(
    [22:16:18 WARN]:        at Scoreboard.Score$
    [22:16:18 WARN]:        at java.util.TimerThread.mainLoop(Unknown Source)
    [22:16:18 WARN]:        at Source)
    [22:16:18 WARN]: Caused by: java.lang.IllegalArgumentException: Async entity add
    [22:16:18 WARN]:        at
    [22:16:18 WARN]:        at
    [22:16:18 WARN]:        at
    [22:16:18 WARN]:        at
    [22:16:18 WARN]:        at
    [22:16:18 WARN]:        at
    [22:16:18 WARN]:        at
    [22:16:18 WARN]:        at
    [22:16:18 WARN]:        at org.bukkit.command.PluginCommand.execute(
    [22:16:18 WARN]:        ... 8 more
    i tried essentials's command,it works but hologram plugin's command didn't work
  4. Jesus,did we all forgot about BukkitRunnable for timers?

    Code (Text):
     java.lang.IllegalArgumentException: Async entity add
    • Agree Agree x 1
  5. dont use random asynchronous apis without a specific goal. use the ones that are provided with spigot unless you have good reason to use another.
    the error tells you your issue, all you have to do is read.
    Caused by: java.lang.IllegalArgumentException: Async entity add
    it comes from
    so holographic displays is catching you asynchronously adding an entity. you cant do that. jump on the main thread. schedule a synchronized task
  6. Thanks all of you,i used BukkitRunnable solve it.