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() {
                LoadAll();
            }
        };
        public static void start() {
            timer.schedule(task, 0, 5000);
        }
        public static void stop() {
            timer.cancel();
        }
    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(PluginCommand.java:46)
    [22:16:18 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
    [22:16:18 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:640)
    [22:16:18 WARN]:        at org.bukkit.Bukkit.dispatchCommand(Bukkit.java:575)
    [22:16:18 WARN]:        at Scoreboard.Score.SetPlayer(Score.java:46)
    [22:16:18 WARN]:        at Scoreboard.Score.LoadAll(Score.java:66)
    [22:16:18 WARN]:        at Scoreboard.Score$1.run(Score.java:52)
    [22:16:18 WARN]:        at java.util.TimerThread.mainLoop(Unknown Source)
    [22:16:18 WARN]:        at java.util.TimerThread.run(Unknown Source)
    [22:16:18 WARN]: Caused by: java.lang.IllegalArgumentException: Async entity add
    [22:16:18 WARN]:        at com.gmail.filoghost.holographicdisplays.util.Validator.isTrue(Validator.java:27)
    [22:16:18 WARN]:        at com.gmail.filoghost.holographicdisplays.nms.v1_8_R3.NmsManagerImpl.addEntityToWorld(NmsManagerImpl.java:100)
    [22:16:18 WARN]:        at com.gmail.filoghost.holographicdisplays.nms.v1_8_R3.NmsManagerImpl.spawnNMSArmorStand(NmsManagerImpl.java:93)
    [22:16:18 WARN]:        at com.gmail.filoghost.holographicdisplays.object.line.CraftTextLine.spawn(CraftTextLine.java:101)
    [22:16:18 WARN]:        at com.gmail.filoghost.holographicdisplays.object.CraftHologram.spawnEntities(CraftHologram.java:299)
    [22:16:18 WARN]:        at com.gmail.filoghost.holographicdisplays.object.CraftHologram.refreshAll(CraftHologram.java:246)
    [22:16:18 WARN]:        at com.gmail.filoghost.holographicdisplays.commands.main.subs.SetlineCommand.execute(SetlineCommand.java:76)
    [22:16:18 WARN]:        at com.gmail.filoghost.holographicdisplays.commands.main.HologramsCommandHandler.onCommand(HologramsCommandHandler.java:115)
    [22:16:18 WARN]:        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    [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?

    Also
    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
    at com.gmail.filoghost.holographicdisplays.util.Validator.isTrue(Validator.java:27)
    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.