kitti.g

plugin ใช้คำสั่งจาก consol แบบ อัตโนมัติ ทุกๆ 2 ชั่วโมง และจะแจ้งเตือน ช่องแชททุก 1 ชั่วโมง,30 นาที,10 นาที,5 นาที ตั้งคำอธิบายแจ้งเตือนผ่าน config ได้ คำสั่งจาก consol ที่จะใช้คือ /pparty spawn spawn

Kodari AI
KodariJul 1 at 3:22 pm 1
AutoCommandRunner
A plugin that automatically executes a configurable console command on a repeating timer (default every 2 hours). Broadcasts countdown reminder messages to chat at configurable intervals before execution (e.g., 1 hour, 30 minutes, 10 minutes, 5 minutes). All messages are fully customizable through the config file to support any language. Includes automatic timer management with server start/stop handling.

Creating the plugin structure now.

Project structure:

  • Main.java — Plugin entry point, loads config on enable, starts the scheduler

  • CommandScheduler.java — Runs a timer task every 1 second, tracks countdown, executes console command when it hits 0, broadcasts reminder messages at configured intervals

  • config.yml — All messages fully customizable, set interval in minutes, configure reminder times as keys and messages as values

  • plugin.yml — Minimal Bukkit plugin descriptor

  • build.gradle — Spigot dependency

How it works:

  1. On enable, timer starts counting down from interval-minutes (default 120 min = 7200 seconds)

  2. Every second the timer decrements. When it matches a reminder time (e.g. 3600s = 1h), broadcasts that message to all players

  3. When timer hits 0, runs /pparty spawn spawn via console, broadcasts the execution message, then resets the countdown

  4. All message text and colors use & color codes — editable in config.yml

kitti.g
📎 1 file 1,665 chars
📄
pasted-code-1782919733287.txt
txt 12 lines
▶
[22:28:41 WARN]: [AutoCommandRunner] Task #1675929 for AutoCommandRunner v1.0.0 generated an exception
java.lang.IllegalAccessError: class com.autocommandrunner.CommandScheduler$1 tried to access private method 'void com.autocommandrunner.CommandScheduler.tick()' (com.autocommandrunner.CommandScheduler$1 and com.autocommandrunner.CommandScheduler are in unnamed module of loader 'AutoCommandRunner-1.0.0.jar' @708a568b)
        at AutoCommandRunner-1.0.0.jar//com.autocommandrunner.CommandScheduler$1.run(CommandScheduler.java:64) ~[?:?]
        at org.bukkit.craftbukkit.scheduler.CraftTask.run(CraftTask.java:78) ~[purpur-26.1.2.jar:26.1.2-2587-dc4a255]
        at org.bukkit.craftbukkit.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:474) ~[purpur-26.1.2.jar:26.1.2-2587-dc4a255]
        at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1838) ~[purpur-26.1.2.jar:26.1.2-2587-dc4a255]
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1691) ~[purpur-26.1.2.jar:26.1.2-2587-dc4a255]
        at net.minecraft.server.dedicated.DedicatedServer.tickServer(DedicatedServer.java:495) ~[purpur-26.1.2.jar:26.1.2-2587-dc4a255]
        at net.minecraft.server.MinecraftServer.processPacketsAndTick(MinecraftServer.java:1749) ~[purpur-26.1.2.jar:26.1.2-2587-dc4a255]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1419) ~[purpur-26.1.2.jar:26.1.2-2587-dc4a255]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:304) ~[purpur-26.1.2.jar:26.1.2-2587-dc4a255]
        at java.base/java.lang.Thread.run(Thread.java:1474) ~[?:?]
Kodari AI
KodariJul 1 at 3:29 pm 1

The error is IllegalAccessError — the anonymous BukkitRunnable inner class can’t access a private method. Changed private void tick() to package-private (void tick()). The anonymous class is in the same package, so it can now call tick() without issue.

kitti.g

เพิ่ม หลังจากคำสั่งเริ่มทำงานแล้ว 5 นาที ให้ใช้คำสั่งใหม่อีกครั้ง คำสั่งใหม่หลังจากใช้ คำสั่งเริ่มต้น /pparty killall ปรับเวลาผ่าน config ได้

Kodari AI
KodariJul 1 at 3:35 pm 1
kitti.g

แก้ไขคำสั่งที่ 2 ไม่ทำงาน

Kodari AI
KodariJul 1 at 3:40 pm 1
kitti.g

แก้ไขคำสั่งที่ 2 ไม่ทำงาน

Kodari AI
KodariJul 1 at 3:44 pm 1

ปัญหาคือตอนนี้เมื่อคำสั่งแรกทำงาน มัน reset counter กลับไปที่ interval ทันที โดยไม่มีขั้นตอนรอให้คำสั่งที่ 2 ทำงาน

แก้ไขแล้ว ปัญหาคือเดิมใช้ ticksToExecute แยกต่างหากแต่ไม่ sync กับตัวนับหลัก ตอนนี้เปลี่ยนเป็นใช้ state secondCommandPending ร่วมกับ secondsRemaining ตัวเดียวกัน:

  1. คำสั่งแรกทำงาน → ถ้ามี second-command ให้ตั้ง secondCommandPending=true และนับถอยหลัง secondCommandDelaySeconds

  2. เมื่อนับถึง 0 อีกครั้ง → รันคำสั่งที่ 2, reset กลับไป interval ปกติ

kitti.g

เพิ่มคำสั่งรีโหลด config

Kodari AI
KodariJul 1 at 3:49 pm 1
kitti.g

เพิ่มคำสั่งรีโหลด config

Kodari AI
KodariJul 1 at 3:50 pm 1

<kodariReadFile>src/main/resources/plugin.yml

kitti.g

เพิ่มคำสั่งรีโหลด config

Kodari AI
KodariJul 1 at 3:50 pm 1

<kodariReadFile>src/main/resources/plugin.yml

kitti.g

เพิ่มคำสั่งรีโหลด config

Kodari AI
KodariJul 1 at 3:50 pm 1
<kodariReadFile> </kodarireadfile>
kitti.g

เพิ่มคำสั่งรีโหลด config ให้กับ plugin

Kodari AI
KodariJul 1 at 3:51 pm 1

เพิ่มคำสั่ง /acr reload แล้ว:

plugin.yml — ลงทะเบียนคำสั่ง acr พร้อม permission acr.admin

Main.java — เพิ่ม onCommand() จัดการ /acr reload:

  • เช็ค permission acr.admin

  • เรียก reloadConfig() + scheduler.reload()

CommandScheduler.java — เพิ่มเมธอด reload() ที่โหลด config ใหม่และ restart scheduler

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
5 240
src/main/java/com/autocommandrunner/Main.java
package com.autocommandrunner;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin {

    private CommandScheduler scheduler;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        scheduler = new CommandScheduler(this);
        scheduler.start();
        getLogger().info("AutoCommandRunner enabled.");
    }

    @Override
    public void onDisable() {
        if (scheduler != null) {
            scheduler.stop();
        }
        getLogger().info("AutoCommandRunner disabled.");
    }

    public CommandScheduler getScheduler() {
        return scheduler;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (!cmd.getName().equalsIgnoreCase("acr")) return false;

        if (!sender.hasPermission("acr.admin")) {
            sender.sendMessage(ChatColor.RED + "You don't have permission.");
            return true;
        }

        if (args.length < 1 || !args[0].equalsIgnoreCase("reload")) {
            sender.sendMessage(ChatColor.RED + "Usage: /acr reload");
            return true;
        }

        reloadConfig();
        scheduler.reload();
        sender.sendMessage(ChatColor.GREEN + "AutoCommandRunner config reloaded.");
        getLogger().info("Config reloaded by " + sender.getName());
        return true;
    }
}