How to make a waiting time while an event has begun/Scheduler error

Discussion in 'Spigot Plugin Development' started by Froyzz, May 27, 2016.

  1. Hi guys ! :)
    I did an event, when you kill a specific entity :
    ( with theese conditions i detect the specific entity death ):
    Code (Text):
            if (herobrine instanceof PigZombie){
                if (herobrine.isCustomNameVisible()){
                if (herobrine.getWorld().getName().equalsIgnoreCase("world")){{
    it runs a command among four randomly.
    Code (Text):
    Random r = new Random();
                        int aléatoire = r.nextInt(4);                    
                        switch(aléatoire){
                        case 0:
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5286,81,3775");                    
                        break;

                        case 1:
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5286,81,3778");
                        break;
                     
                        case 2:
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5289,81,3778");
                        break;
                     
                        case 3:
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5289,81,3775");
                         
                        break;
                     
                        case 4:
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5289,81,3775");
                         
                        break;
                     
                        default:;
                        break;                        
    But i want to make a delay before the commands are executed, so a delay next these conditions, so when this entity will die i want to wait 1 day( not a minecraft day ) before these commands are executed.
    Is it possible ? If yes may you help me please :(.
     
    #1 Froyzz, May 27, 2016
    Last edited: May 27, 2016
  2. Code (Text):
        int startCount = 5;
                     
                        while(startCount != 0) {
                         
                            startCount--;
                            try {
                                Thread.sleep(1000);
                            }catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
    Probably not efficient though so i would just use a syncdelayed task :/
     
    • Agree Agree x 1
  3. Yes doesn't works, it's just making the server in pause for 10 seconds,
    I tried a syncdelayed task but it doesn't works too :/
    Code (Text):
    @EventHandler
        public void onmort(EntityDeathEvent event) throws IOException{
            Entity p = event.getEntity();
            if (p instanceof PigZombie){
                if (p.isCustomNameVisible()){
                    if (p.getWorld().getName().equals("world")){
                        Bukkit.broadcastMessage("Step 2 h");
                         nhi.getServer().getScheduler().scheduleSyncDelayedTask(nhi, new Runnable(){

                            @Override
                            public void run() {
                               
                                 
                        Random r = new Random();
                        int aléatoire = r.nextInt(4);                      
                        switch(aléatoire){
                        case 0:
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5286,81,3775");                      
                        break;

                        case 1:
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5286,81,3778");
                        break;
                       
                        case 2:
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5289,81,3778");
                        break;
                       
                        case 3:
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5289,81,3775");
                           
                        break;
                       
                        case 4:
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5289,81,3775");
                           
                        break;
                       
                        default:;
                        break;      
                        }
                       
                            }
                         }, 600L);
                         }
                        }
                        }
                                           
                    }
     
  4. It makes me this error
    Code (couldnotpassevententitydeatheventtonpcheroinfov10orgbukkiteventeventexceptionatorgbukkitpluginjavajavapluginloaderexecutejavapluginloaderjava310spigot-192jargit-spigot-944aa20-420b983atorgbukkitpluginregisteredlistenercalleventregisteredlistenerjava62spigot-192jargit-spigot-944aa20-420b983atorgbukkitpluginsimplepluginmanagerfireeventsimplepluginmanagerjava502spigot-192jargit-spigot-944aa20-420b983atorgbukkitpluginsimplepluginmanagercalleventsimplepluginmanagerjava487spigot-192jargit-spigot-944aa20-420b983atorgbukkitcraftbukkitv1_9_r1eventcrafteventfactorycallentitydeatheventcrafteventfactoryjava391spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1entitylivingdieentitylivingjava983spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1entityzombiedieentityzombiejava549spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1entitylivingdamageentityentitylivingjava900spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1entitymonsterdamageentityentitymonsterjava44spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1entityzombiedamageentityentityzombiejava179spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1entitypigzombiedamageentitysourcefile148spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1entityhumanattackentityhumanjava999spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1entityplayerattackentityplayerjava1129spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1playerconnectionaplayerconnectionjava1577spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1packetplayinuseentityasourcefile68spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1packetplayinuseentityasourcefile12spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1playerconnectionutilsrunsourcefile13spigot-192jargit-spigot-944aa20-420b983atjavautilconcurrentexecutorsrunnableadaptercallunknownsource180_66atjavautilconcurrentfuturetaskrununknownsource180_66atnetminecraftserverv1_9_r1systemutilsasourcefile45spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1minecraftserverdminecraftserverjava721spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1dedicatedserverddedicatedserverjava400spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1minecraftservercminecraftserverjava660spigot-192jargit-spigot-944aa20-420b983atnetminecraftserverv1_9_r1minecraftserverrunminecraftserverjava559spigot-192jargit-spigot-944aa20-420b983atjavalangthreadrununknownsource180_66causedbyjavalangillegalargumentexceptionplugincannotbenullatorgapachecommonslangvalidatenotnullvalidatejava192spigot-192jargit-spigot-944aa20-420b983atorgbukkitcraftbukkitv1_9_r1schedulercraftschedulervalidatecraftschedulerjava397spigot-192jargit-spigot-944aa20-420b983atorgbukkitcraftbukkitv1_9_r1schedulercraftschedulerruntasktimercraftschedulerjava123spigot-192jargit-spigot-944aa20-420b983atorgbukkitcraftbukkitv1_9_r1schedulercraftschedulerschedulesyncrepeatingtaskcraftschedulerjava119spigot-192jargit-spigot-944aa20-420b983atorgbukkitcraftbukkitv1_9_r1schedulercraftschedulerschedulesyncdelayedtaskcraftschedulerjava102spigot-192jargit-spigot-944aa20-420b983atfrfroyznpcheroinfoeventsonmorteventsjava66atsunreflectnativemethodaccessorimplinvoke0nativemethod180_66atsunreflectnativemethodaccessorimplinvokeunknownsource180_66atsunreflectdelegatingmethodaccessorimplinvokeunknownsource180_66atjavalangreflectmethodinvokeunknownsource180_66atorgbukkitpluginjavajavapluginloaderexecutejavapluginloaderjava306spigot-192jargit-spigot-944aa20-420b98324more (Unknown Language)):
     
    The line Events.java:66 is
    Code (Text):
     Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(nhi, new Runnable() {
    nhi is :
    Code (Text):
        public static Main nhi;
     
  5. The Main instance nhi is null. Assign your plugin instance to it.
     
    • Like Like x 1
  6. Your plugin variable is null..

    Freaking sniped by StalexDev :/
     
    • Like Like x 1
  7. Ah yes ! thanks you very much, it works
    If i restart the server or i reload, this delay will be stop ?
     
  8. Yes.
     
    • Like Like x 1
  9. Arg, is there a way to save this delay in a file for prevent reload/reboot ?
     
  10. You could save the System.currentTimeMillis() to the config together with a value of how long it will still have left and when the plugin starts again, check if there is a value saved in the config. If so, create the runnable with the remaining delay.
     
    • Winner Winner x 1