rackyrb

Create a .yml that executes /coinsengine shards give %amount% every 60 seconds.

Kodari AI
KodariJan 25 at 9:31 pm 4,867 (v2)

I’ll create a scheduler plugin to execute the CoinsEngine command periodically.

CoinsScheduler
A lightweight task scheduler designed to execute console commands at configurable intervals. Features support for placeholders like %player% and %amount%, allowing for automated currency distribution using CoinsEngine or similar plugins.

I will create a lightweight scheduler plugin that executes the specified command.

  1. Create build.gradle: Define project dependencies (Spigot API).

  2. Create src/main/resources/plugin.yml: Register the plugin.

  3. Create src/main/resources/config.yml: The requested configuration file with the command and interval.

  4. Create src/main/java/com/example/coinsscheduler/CoinsScheduler.java: The main logic to handle the scheduling and placeholder replacement.

I have created the plugin with the requested configuration structure.

  • config.yml contains the exact command pattern requested.

  • The scheduler runs every 60 seconds (configurable).

  • It supports %amount% and optionally %player% if you need to target specific players in the future.

rackyrb

I'm use paper.

Kodari AI
KodariJan 25 at 9:37 pm 872 (v2)

batch_operations with operations array containing:

  • action: “read”, path: “build.gradle”

  • action: “read”, path: “src/main/resources/plugin.yml”

  • action: “read”, path: “src/main/java/com/example/ShardsSchedular/ShardsSchedular.java”

rackyrb

How do I download and upload as a .jar?

Kodari AI
KodariJan 25 at 9:38 pm 3,174 (v2)

batch_operations with operations array containing:

  • action: “read”, path: “build.gradle”

  • action: “read”, path: “src/main/resources/plugin.yml”

  • action: “read”, path: “src/main/java/com/example/ShardsSchedular/ShardsSchedular.java”

I will resolve the critical compilation errors caused by the mismatch between your file names, package declarations, and plugin.yml. This ensures the plugin can actually be built into a JAR.

  1. Fixing File Structure: Deleting the mismatched ShardsSchedular.java (typo in name) which contained CoinsScheduler code.

  2. Creating Correct Class: Creating ShardsScheduler.java in the correct package com.example.shardsscheduler.

  3. Updating Configuration: Correcting plugin.yml to point to the new main class location.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 114
src/main/java/com/example/shardsscheduler/ShardsScheduler.java
package com.example.shardsscheduler;

import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

import java.util.List;

public class ShardsScheduler extends JavaPlugin {

    private BukkitTask task;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        startScheduler();
        getLogger().info("ShardsScheduler has been enabled!");
    }

    @Override
    public void onDisable() {
        if (task != null && !task.isCancelled()) {
            task.cancel();
        }
        getLogger().info("ShardsScheduler has been disabled!");
    }

    private void startScheduler() {
        FileConfiguration config = getConfig();
        long intervalSeconds = config.getLong("scheduler.interval", 60);
        long intervalTicks = intervalSeconds * 20L;
        
        task = Bukkit.getScheduler().runTaskTimer(this, this::executeCommands, intervalTicks, intervalTicks);
    }

    private void executeCommands() {
        FileConfiguration config = getConfig();
        int amount = config.getInt("scheduler.amount", 10);
        List<String> commands = config.getStringList("scheduler.commands");

        if (commands.isEmpty()) return;

        for (String cmd : commands) {
            // Pre-process global placeholders
            String processedCmd = cmd.replace("%amount%", String.valueOf(amount));

            if (processedCmd.contains("%player%")) {
                // Execute for each player
                for (Player player : Bukkit.getOnlinePlayers()) {
                    String playerCmd = processedCmd.replace("%player%", player.getName());
                    dispatchCommand(playerCmd);
                }
            } else {
                // Execute once as console
                dispatchCommand(processedCmd);
            }
        }
    }

    private void dispatchCommand(String command) {
        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
    }
}