Solved PotionEffect doesn't work

Discussion in 'Plugin Development' started by nightwolf111, Sep 11, 2016.

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

    nightwolf111

    Hey guys, so as the title says i don't know why but when i coded a plugin that gives the player potion effect(absorption) it throws an exception in my server's console :

    Code:
    2:55:41] [Craft Scheduler Thread - 0/WARN]: Exception in thread "Craft Scheduler Thread - 0"
    [12:55:41] [Craft Scheduler Thread - 0/WARN]: org.apache.commons.lang.UnhandledException: Plugin 8omidha v1.0 generated an exception while executing task 2
        at org.bukkit.craftbukkit.v1_10_R1.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.IllegalStateException: Asynchronous effect add!
        at org.spigotmc.AsyncCatcher.catchOp(AsyncCatcher.java:14)
        at net.minecraft.server.v1_10_R1.EntityLiving.addEffect(EntityLiving.java:648)
        at org.bukkit.craftbukkit.v1_10_R1.entity.CraftLivingEntity.addPotionEffect(CraftLivingEntity.java:300)
        at org.bukkit.craftbukkit.v1_10_R1.entity.CraftLivingEntity.addPotionEffect(CraftLivingEntity.java:290)
        at com.night.Game.StartGame(Game.java:135)
        at com.night.Game$1.run(Game.java:114)
        at org.bukkit.craftbukkit.v1_10_R1.scheduler.CraftTask.run(CraftTask.java:71)
        at org.bukkit.craftbukkit.v1_10_R1.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
        ... 3 more

    and this is my code :
    Code:
    @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (!(sender instanceof Player))
                return false;
            Player player = (Player) sender;
            if (label.equalsIgnoreCase("Start")) {                       
                player.sendMessage(ChatColor.GREEN + "You've started the Countdown !!");
    
        Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
       
                    public void run(){
                        if (CountDown >= 0) {
                            for (Player p : Bukkit.getOnlinePlayers()) {
                                p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 10f, 10f);
                                CountDown--;
                               
                            }
                               
                           
                        } else if (CountDown == -1) {
                            for (Player p : Bukkit.getOnlinePlayers()) {
                                p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 10f, 10f);
                                p.sendMessage(ChatColor.GREEN + "The Game Has Started");
                                CountDown --;
                                StartGame();
                               
                            }
                           
                       
                    }
    
                    }
                }, 0L, 20L);
            }
            return true;
        }
    
        public void StartGame(){
            Hiders hiders = new Hiders(this);
            Seekers seekers = new Seekers(this);
           
            for (Player player : Bukkit.getOnlinePlayers()){
    
                if(hiders.getAllPlayers().contains(player)){
                    player.sendMessage(ChatColor.GOLD + "Test 1");
                    player.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION,10,10,false));
               
               
                }else if(seekers.getAllPlayers().contains(player)){
                    player.sendMessage("Test 2 ");
                }
            }
            Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "TEST");
       
            GameStarted = true;
        }
     
  2. @nightwolf111
    The problem is that the task is asyncronous. I have to ask, is there a reason for it to be asynchronous? Because if there isn't you could just switch it to a synchronous task and that'd fix you problem.
     
  3. Offline

    nightwolf111

    thanx it worked fine ^^, but can you explain to me why it threw the exception when i make sychronized task ? what does that mean ?
     
Thread Status:
Not open for further replies.

Share This Page