1.16.5 Disable redstone&piston crashes the server

Discussion in 'Spigot Plugin Development' started by i998979, Aug 7, 2020.

  1. So I'm coding a redstone limiter for my skyblock server, but the server is crashing again and again even if only a few people (5 players) online.

    So the logic is, when the plugin start, start a checker with a specified period (10 seconds), it checks how many times the redstsone&piston has been activated. If the count reached a specified amount, it disables ALL redstone&pistons in that player's island

    Here is my code

    Checker (triggered only once when the plugin starts)
    Code (Java):
        public static void startChecking() {
           
            BukkitRunnable runnable = new BukkitRunnable() {
                @Override
                public void run() {
                   
                    // Loop through all saved datas
                    for (Map.Entry<String, Integer> entry : RedstoneLimiter.datas.entrySet()) {
                        String uuid = entry.getKey();
                        int count = entry.getValue();
                       
                       
                       
                        // Get all island owner and members
                        List<String> isPlayers = new ArrayList<>(User.getUser(uuid.toString()).getIsland().getMembers());
                       
                       
                       
                        if (count < plugin.getConfig().getInt("BSAS.RedstoneLimiter.Warn")) {
                            RedstoneLimiter.disabled.remove(uuid);
                            RedstoneLimiter.warned.remove(uuid);
                        }
                       
                        // If the count has already reached warn limit
                        if (count >= plugin.getConfig().getInt("BSAS.RedstoneLimiter.Warn")) {
                           
                            // If the redstone of him is already disabled
                            if (RedstoneLimiter.disabled.contains(uuid)) continue;
                           
                            if (count >= plugin.getConfig().getInt("BSAS.RedstoneLimiter.Max"))
                                RedstoneLimiter.disabled.add(uuid);
                           
                           
                           
                            // If the island has already warned
                            if (RedstoneLimiter.warned.contains(uuid) && !RedstoneLimiter.disabled.contains(uuid)) continue;
                           
                            RedstoneLimiter.warned.add(uuid);
                           
                           
                           
                           
                           
                           
                            // Loop all island players
                            for (String uid : isPlayers) {
                                // If looping player is online
                                if (Bukkit.getOfflinePlayer(UUID.fromString(uid)).isOnline()) {
                                    Player player = Bukkit.getPlayer(UUID.fromString(uid));
                                   
                                    // If the count exceed the limit
                                    if (count >= plugin.getConfig().getInt("BSAS.RedstoneLimiter.Max")) {
                                        player.sendMessage("§c你的島嶼紅石數量已到達限制 , 島嶼的紅石已被停止 , 請盡快移除高用量的紅石機器 . (" + count + ")");
                                        player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 1);
                                    }
                                    // If the count exceed the warn
                                    else {
                                        player.sendMessage("§c你的島嶼紅石數量將接近限制 , 請盡快移除高用量的紅石機器 . 當到達限制時 , 你島嶼的紅石將會被停止 . (" + count + ")");
                                        player.playSound(player.getLocation(), Sound.ENTITY_BAT_HURT, 1, 1);
                                    }
                                }
                            }
                        }
                    }
                   
                    RedstoneLimiter.datas.clear();
                }
            };
            runnable.runTaskTimer(plugin, 0, plugin.getConfig().getInt("BSAS.RedstoneLimiter.Period"));
        }

    BlockRedstoneEvent listener
    Code (Java):
        @EventHandler
        public void onRedstone(BlockRedstoneEvent event) {
           
            String ownerid = IridiumSkyblock.getIslandManager().getIslandViaLocation(event.getBlock().getLocation()).getOwner();
           
            if (RedstoneLimiter.disabled.contains(ownerid))
                event.setNewCurrent(0);
           
           
           
            HashMap<String, Integer> ticks = RedstoneLimiter.datas;
           
            if (RedstoneLimiter.datas.containsKey(ownerid)) {
                ticks.put(ownerid, ticks.get(ownerid) + 1);
            }
            else {
                ticks.put(ownerid, 1);
            }
        }
    PistonEvent handler
    Code (Java):
        @EventHandler
        public void onPistonMove(BlockPistonExtendEvent event) {
           
            String ownerid = IridiumSkyblock.getIslandManager().getIslandViaLocation(event.getBlock().getLocation()).getOwner();
           
            if (RedstoneLimiter.disabled.contains(ownerid))
                event.setCancelled(true);
           
           
           
            HashMap<String, Integer> ticks = RedstoneLimiter.datas;
           
            if (RedstoneLimiter.datas.containsKey(ownerid)) {
                ticks.put(ownerid, ticks.get(ownerid) + 1);
            }
            else {
                ticks.put(ownerid, 1);
            }
        }
       
        @EventHandler
        public void onPistonMove(BlockPistonRetractEvent event) {
           
            String ownerid = IridiumSkyblock.getIslandManager().getIslandViaLocation(event.getBlock().getLocation()).getOwner();
           
            if (RedstoneLimiter.disabled.contains(ownerid))
                event.setCancelled(true);
           
           
           
            HashMap<String, Integer> ticks = RedstoneLimiter.datas;
           
            if (RedstoneLimiter.datas.containsKey(ownerid)) {
                ticks.put(ownerid, ticks.get(ownerid) + 1);
            }
            else {
                ticks.put(ownerid, 1);
            }
        }
    The plugin works fine on my new pc (good spec) and crashes in the server pc (bad spec)
    So maybe some part of the code consumed lots of resources and I didn't notice when I run it on my new pc?
     
  2. Check console for errors. It helps to have a stack trace.
     
  3. Code (Text):
    [15:12:13] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:13] [Spigot Watchdog Thread/ERROR]: The server has stopped responding! This is (probably) not a Spigot bug.
    [15:12:13] [Spigot Watchdog Thread/ERROR]: If you see a plugin in the Server thread dump below, then please report it to that author
    [15:12:13] [Spigot Watchdog Thread/ERROR]:   *Especially* if it looks like HTTP or MySQL operations are occurring
    [15:12:13] [Spigot Watchdog Thread/ERROR]: If you see a world save or edit, then it means you did far more than your server can handle at once
    [15:12:13] [Spigot Watchdog Thread/ERROR]:   If this is the case, consider increasing timeout-time in spigot.yml but note that this will replace the crash with LARGE lag spikes
    [15:12:13] [Spigot Watchdog Thread/ERROR]: If you are unsure or still think this is a Spigot bug, please report to https://www.spigotmc.org/
    [15:12:13] [Spigot Watchdog Thread/ERROR]: Be sure to include ALL relevant console errors and Minecraft crash reports
    [15:12:13] [Spigot Watchdog Thread/ERROR]: Spigot version: git-Spigot-0287a20-7560f5f (MC: 1.16.1)
    [15:12:13] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:13] [Spigot Watchdog Thread/ERROR]: During the run of the server, a physics stackoverflow was supressed
    [15:12:13] [Spigot Watchdog Thread/ERROR]: near BlockPosition{x=-298, y=93, z=446}
    [15:12:13] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:13] [Spigot Watchdog Thread/ERROR]: Server thread dump (Look for plugins here before reporting to Spigot!):
    [15:12:13] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:13] [Spigot Watchdog Thread/ERROR]: Current Thread: Server thread
    [15:12:13] [Spigot Watchdog Thread/ERROR]:  PID: 20 | Suspended: false | Native: false | State: RUNNABLE
    [15:12:13] [Spigot Watchdog Thread/ERROR]:  Stack:
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.World.getChunkAt(World.java:249)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.IWorldReader.getChunkAt(SourceFile:128)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.World.getChunkAt(World.java:244)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.World.getType(World.java:552)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.WorldServer.getTileEntity(WorldServer.java:146)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.World.getTileEntity(World.java:784)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.BlockRedstoneComparator.b(BlockRedstoneComparator.java:25)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.BlockDiodeAbstract.a(BlockDiodeAbstract.java:61)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.BlockBase$BlockData.b(BlockBase.java:403)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.World.getBlockFacePower(World.java:1081)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.World.s(World.java:1097)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.BlockRedstoneWire.a(BlockRedstoneWire.java:255)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.BlockRedstoneWire.a(BlockRedstoneWire.java:216)
    [15:12:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.BlockRedstoneWire.doPhysics(BlockRedstoneWire.java:366)
    The server is spamming same errors, after thousands of same lines,
    Code (Text):
    [15:12:14] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:14] [Spigot Watchdog Thread/ERROR]: Current Thread: NonBlockingInputStreamThread
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  PID: 23 | Suspended: false | Native: false | State: WAITING
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  Stack:
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.Object.wait(Native Method)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      org.bukkit.craftbukkit.libs.jline.internal.NonBlockingInputStream.run(NonBlockingInputStream.java:278)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.Thread.run(Unknown Source)
    [15:12:14] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:14] [Spigot Watchdog Thread/ERROR]: Current Thread: Snooper Timer
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  PID: 21 | Suspended: false | Native: false | State: WAITING
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  Stack:
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.Object.wait(Native Method)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.Object.wait(Unknown Source)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.util.TimerThread.mainLoop(Unknown Source)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.util.TimerThread.run(Unknown Source)
    [15:12:14] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:14] [Spigot Watchdog Thread/ERROR]: Current Thread: Timer hack thread
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  PID: 16 | Suspended: false | Native: false | State: TIMED_WAITING
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  Stack:
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.Thread.sleep(Native Method)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_16_R1.SystemUtils$2.run(SourceFile:524)
    [15:12:14] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:14] [Spigot Watchdog Thread/ERROR]: Current Thread: Attach Listener
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  PID: 5 | Suspended: false | Native: false | State: RUNNABLE
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  Stack:
    [15:12:14] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:14] [Spigot Watchdog Thread/ERROR]: Current Thread: Signal Dispatcher
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  PID: 4 | Suspended: false | Native: false | State: RUNNABLE
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  Stack:
    [15:12:14] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:14] [Spigot Watchdog Thread/ERROR]: Current Thread: Finalizer
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  PID: 3 | Suspended: false | Native: false | State: WAITING
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  Stack:
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.Object.wait(Native Method)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.ref.ReferenceQueue.remove(Unknown Source)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.ref.ReferenceQueue.remove(Unknown Source)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)
    [15:12:14] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:14] [Spigot Watchdog Thread/ERROR]: Current Thread: Reference Handler
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  PID: 2 | Suspended: false | Native: false | State: WAITING
    [15:12:14] [Spigot Watchdog Thread/ERROR]:  Stack:
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.Object.wait(Native Method)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.Object.wait(Unknown Source)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.ref.Reference.tryHandlePending(Unknown Source)
    [15:12:14] [Spigot Watchdog Thread/ERROR]:      java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
    [15:12:14] [Spigot Watchdog Thread/ERROR]: ------------------------------
    [15:12:14] [Spigot Watchdog Thread/INFO]: Startup script './start.sh' does not exist! Stopping server.
    [15:12:14] [Spigot Watchdog Thread/INFO]: Stopping server
    this is the rest of the errors