Solved Not sure what the issue is here.

Discussion in 'Plugin Development' started by Ultracrepadarian, Sep 26, 2016.

Thread Status:
Not open for further replies.
  1. Alright; My script is supposed to (basically) run a BukkitRunnable delayed task whenever a tnt blows up in the world labeled "RageController". I've also added a delayed task during one of the for loops in hopes to stop a bit of the lag. Although now it seems to lag just as much if not more when it runs. It also crashes at the end of iterating with this error:

    Crash log (open)

    [20:53:11 ERROR]: The server has stopped responding!
    [20:53:11 ERROR]: Please report this to http://www.spigotmc.org/
    [20:53:11 ERROR]: Be sure to include ALL relevant console errors and Minecraft crash reports
    [20:53:11 ERROR]: Spigot version: git-Spigot-4af49dc-c5e9a16 (MC: 1.9.4)
    [20:53:11 ERROR]: ------------------------------
    [20:53:11 ERROR]: Server thread dump (Look for plugins here before reporting to Spigot!):
    [20:53:11 ERROR]: ------------------------------
    [20:53:11 ERROR]: Current Thread: Server thread
    [20:53:11 ERROR]: PID: 14 | Suspended: false | Native: false | State: TIMED_WAITING
    [20:53:11 ERROR]: Stack:
    [20:53:11 ERROR]: java.lang.Thread.sleep(Native Method)
    [20:53:11 ERROR]: com.krazytar.plugins.RageController.Main$1.run(Main.java:59)
    [20:53:11 ERROR]: org.bukkit.craftbukkit.v1_9_R2.scheduler.CraftTask.run(CraftTask.java:71)
    [20:53:11 ERROR]: org.bukkit.craftbukkit.v1_9_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350)
    [20:53:11 ERROR]: net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:734)
    [20:53:11 ERROR]: net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399)
    [20:53:11 ERROR]: net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665)
    [20:53:11 ERROR]: net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564)
    [20:53:11 ERROR]: java.lang.Thread.run(Unknown Source)
    [20:53:11 ERROR]: ------------------------------
    [20:53:11 ERROR]: Entire Thread Dump:
    [20:53:11 ERROR]: ------------------------------
    [20:53:11 ERROR]: Current Thread: Netty Server IO #2
    [20:53:11 ERROR]: PID: 24 | Suspended: false | Native: true | State: RUNNABLE
    [20:53:11 ERROR]: Thread is waiting on monitor(s):
    [20:53:11 ERROR]: Locked on:sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: Locked on:sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: Locked on:sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: Stack:
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl.doSelect(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.SelectorImpl.select(Unknown Source)
    [20:53:11 ERROR]: io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:622)
    [20:53:11 ERROR]: io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:310)
    [20:53:11 ERROR]: io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    [20:53:11 ERROR]: java.lang.Thread.run(Unknown Source)
    [20:53:11 ERROR]: ------------------------------
    [20:53:11 ERROR]: Current Thread: pool-6-thread-1
    [20:53:11 ERROR]: PID: 63 | Suspended: false | Native: false | State: WAITING
    [20:53:11 ERROR]: Stack:
    [20:53:11 ERROR]: sun.misc.Unsafe.park(Native Method)
    [20:53:11 ERROR]: java.util.concurrent.locks.LockSupport.park(Unknown Source)
    [20:53:11 ERROR]: java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source)
    [20:53:11 ERROR]: java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
    [20:53:11 ERROR]: java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
    [20:53:11 ERROR]: java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    [20:53:11 ERROR]: java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    [20:53:11 ERROR]: java.lang.Thread.run(Unknown Source)
    [20:53:11 ERROR]: ------------------------------
    [20:53:11 ERROR]: Current Thread: Chunk I/O Executor Thread-1
    [20:53:11 ERROR]: PID: 62 | Suspended: false | Native: false | State: WAITING
    [20:53:11 ERROR]: Stack:
    [20:53:11 ERROR]: sun.misc.Unsafe.park(Native Method)
    [20:53:11 ERROR]: java.util.concurrent.locks.LockSupport.park(Unknown Source)
    [20:53:11 ERROR]: java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source)
    [20:53:11 ERROR]: java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
    [20:53:11 ERROR]: java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
    [20:53:11 ERROR]: java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    [20:53:11 ERROR]: java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    [20:53:11 ERROR]: java.lang.Thread.run(Unknown Source)
    [20:53:11 ERROR]: ------------------------------
    [20:53:11 ERROR]: Current Thread: Netty Server IO #1
    [20:53:11 ERROR]: PID: 23 | Suspended: false | Native: true | State: RUNNABLE
    [20:53:11 ERROR]: Thread is waiting on monitor(s):
    [20:53:11 ERROR]: Locked on:sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: Locked on:sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: Locked on:sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: Stack:
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl.doSelect(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.SelectorImpl.select(Unknown Source)
    [20:53:11 ERROR]: io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:622)
    [20:53:11 ERROR]: io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:310)
    [20:53:11 ERROR]: io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    [20:53:11 ERROR]: java.lang.Thread.run(Unknown Source)
    [20:53:11 ERROR]: ------------------------------
    [20:53:11 ERROR]: Current Thread: Timer-1
    [20:53:11 ERROR]: PID: 38 | Suspended: false | Native: false | State: TIMED_WAITING
    [20:53:11 ERROR]: Stack:
    [20:53:11 ERROR]: java.lang.Object.wait(Native Method)
    [20:53:11 ERROR]: java.util.TimerThread.mainLoop(Unknown Source)
    [20:53:11 ERROR]: java.util.TimerThread.run(Unknown Source)
    [20:53:11 ERROR]: ------------------------------
    [20:53:11 ERROR]: Current Thread: Abandoned connection cleanup thread
    [20:53:11 ERROR]: PID: 37 | Suspended: false | Native: false | State: TIMED_WAITING
    [20:53:11 ERROR]: Stack:
    [20:53:11 ERROR]: java.lang.Object.wait(Native Method)
    [20:53:11 ERROR]: java.lang.ref.ReferenceQueue.remove(Unknown Source)
    [20:53:11 ERROR]: com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
    [20:53:11 ERROR]: ------------------------------
    [20:53:11 ERROR]: Current Thread: Timer-0
    [20:53:11 ERROR]: PID: 28 | Suspended: false | Native: false | State: TIMED_WAITING
    [20:53:11 ERROR]: Stack:
    [20:53:11 ERROR]: java.lang.Object.wait(Native Method)
    [20:53:11 ERROR]: java.util.TimerThread.mainLoop(Unknown Source)
    [20:53:11 ERROR]: java.util.TimerThread.run(Unknown Source)
    [20:53:11 ERROR]: ------------------------------
    [20:53:11 ERROR]: Current Thread: Netty Server IO #0
    [20:53:11 ERROR]: PID: 22 | Suspended: false | Native: true | State: RUNNABLE
    [20:53:11 ERROR]: Thread is waiting on monitor(s):
    [20:53:11 ERROR]: Locked on:sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: Locked on:sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: Locked on:sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: Stack:
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.WindowsSelectorImpl.doSelect(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    [20:53:11 ERROR]: sun.nio.ch.SelectorImpl.select(Unknown Source)
    [20:53:11 ERROR]: io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:622)
    >Press any key to continue . . .


    Code:
    /*
    package com.krazytar.plugins.RageController;
    
    import java.util.ConcurrentModificationException;
    import java.util.HashMap;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityExplodeEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
      
        HashMap<Location, Material> blocks = new HashMap<>();
        int task;
        @Override
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
      
        @EventHandler
        public void explosionEvent(EntityExplodeEvent e) {
            if(e.getLocation().getWorld().getName().equalsIgnoreCase("RageController")) {
                for(Block b: e.blockList()) {
                    if(!blocks.containsKey(e)) {
                        blocks.put(b.getLocation(), b.getType());
                        startRegenTimer();
                    } else {
                        //Ignore
                    }
                }
            }
        }
      
        public void startRegenTimer() {
            getServer().broadcastMessage("Timer started!");
            if(!Bukkit.getScheduler().isCurrentlyRunning(task)) {
          
                task = Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    @Override
                    public void run() {
                        for(Location loc: blocks.keySet()) {
                            try {
                                for(Material material: blocks.values()) {
                                    if(blocks.get(loc).equals(material)) {
                                        World world = getServer().getWorld("RageController");
                                        Block block = world.getBlockAt(loc);
                                        block.setType(material);
                                        blocks.remove(loc);
                                        try {
                                            Thread.sleep(1000);
                                        } catch (InterruptedException e) {}
                                    }
                                }
                            } catch (ConcurrentModificationException e){}
                        }
                    }
                }, 1200L);
            } else {
                //Ignore
            }
        }
    }
    
     
  2. Offline

    Zombie_Striker

    @Ultracrepadarian
    You are getting that error because of this:
    Don't sleep on the main thread! This is just crashing your server. Only use delayed tasks if you want code to be delayed.
     
  3. @Zombie_Striker
    Ah. I see. I do want to the code to run between delays, but I also want there to be a delay between iteration. Should I attempt multi-threading?
     
  4. Offline

    mythbusterma

  5. Offline

    saigonheat

    Yeah. But I'm already using one. I need to delay BETWEEN iteration. So should I put another scheduler in the middle of the current one?

    Sent from my SM-G530T using Tapatalk
     
  6. Yeah. But I'm already using one. I need to delay BETWEEN iteration. So should I put another scheduler in the middle of the current one? (Sorry, still haven't figured out tapatalk yet.) @mythbusterma
     
  7. Offline

    saigonheat

    Alright. I'll try that.

    Sent from my SM-G530T using Tapatalk
     
  8. @AlvinB If I'm not mistaken, the correct way to schedule a task is this:

    Code:
    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()) {
        @Override
        public void run() {
                                               
        }
    }
    
    Correct? So what would I name the run function if the name "run" has already been taken above?
     
  9. Offline

    Zombie_Striker

    @Ultracrepadarian
    There can be only one run method. If you want to nessle runnables, use something like the following:
    Code:
    Bukkit.getScheduler().scheduleSyncDelayedTask(The Mainclass, new Runnable()) {
    @Override
    public void run() {
    ....
    ....
    Bukkit.getScheduler().scheduleSyncDelayedTask(The Mainclass , new Runnable()) {
       @Override
       public void run() {
    
    ....
    
       }
      }
    }
    }
     
  10. @Zombie_Striker
    Thats what I did:
    Code:
    if(!Bukkit.getScheduler().isCurrentlyRunning(task)) {
          
                task = Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    @Override
                    public void run() {
                        for(Location loc: blocks.keySet()) {
                            try {
                                for(Material material: blocks.values()) {
                                    if(blocks.get(loc).equals(material)) {
                                        World world = getServer().getWorld("RageController");
                                        Block block = world.getBlockAt(loc);
                                        block.setType(material);
                                        blocks.remove(loc);
                                        Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()) {
                                            @Override
                                            public void run() {
                                              
                                            }
                                        }
                                      
                                    }
                                }
                            } catch (ConcurrentModificationException e){}
                        }
                    }
                }, 1200L);
    And it comes up with a ton of errors on the second one.
     
    Last edited: Sep 27, 2016
  11. Offline

    mythbusterma

    @Ultracrepadarian

    Like what?

    Also, don't catch ConcurrentModificationExceptions. Fix the issue.
     
  12. @mythbusterma
    Code:
    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()) {
    ^ "Runnable is abstact, cannot be instantiated. ';' expected"
    Code:
    @Override
    ^ "Annotation type not applicable to this kind of declaration"
    Code:
    public void run() {
    ^ "Illegal start of type. Modifier public not allowed here"

    I'll look into the exeption I'm attempting to catch
     
  13. @Ultracrepadarian
    Alright, you're on the right track, but these are the problems:
    1. You have a parenthesis right after the second "new Runnable", move it to after the curly brackets.
    2. You can't use "this" to reference the main class, since "this" refers to the first anonymous Runnable, you need to get the instance of the Main Class somehow.
     
  14. @AlvinB
    Alright. I fixed the first error, but another is coming up:
    [​IMG]
    On this line:
    Code:
    Bukkit.getScheduler().scheduleSyncDelayedTask(c, new Runnable() {
    Not sure if I got an instance of the class right either:
    Code:
    Class c = "Main".getClass();
     
  15. @Ultracrepadarian
    No. What you're doing there is getting the String class object.

    What I recommend doing is just making a static variable of the instance of the main class inside the main class and define it in the constructor. IE:
    Code:java
    1. class MyClass {
    2. static MyClass instance;
    3.  
    4. public MyClass {
    5. instance = this;
    6. }
    7. }
     
  16. Offline

    Zombie_Striker

    @Ultracrepadarian
    You need to provide the instance of the main class, not the String class object. Since this bit of code is in the main class, try the following:
    Code:
    final Plugin mainClass = this;
    //This creates a final version of your main class. This can be referenced from within the runnables
    
    Bukkit.getScheduler().scheduleSyncDelayedTask(mainClass, new Runnable() {
    public void run(){
      Bukkit.getScheduler().scheduleSyncDelayedTask(mainClass, new Runnable() {
    }
     
Thread Status:
Not open for further replies.

Share This Page