affan95.
📎 1 file 3,045 chars
📄
pasted-code-1785949819322.txt
txt 47 lines
▶
Act as an expert Minecraft Paper/Spigot Java Plugin developer (Minecraft 1.20+).

Create a unique, production-ready AFK plugin named "PocketAFK". 

Instead of traditional static AFK plugins, "PocketAFK" introduces an interactive AFK system featuring an isolated AFK Realm, anti-farm protection, passive rewards, and full configuration.

### Core Architecture & Mechanics

1. **Auto-AFK & Detection Engine**:
   - Track player activity (Movement, Chat, Block Break/Place, Command execution).
   - If idle for 300 seconds (configurable), trigger AFK state automatically.
   - Bypasses: Players with `pocketafk.bypass` or standing near active spawners/redstone won't gain passive rewards to prevent farm abuse.

2. **Pocket Realm Teleportation (Optional Mode)**:
   - In `config.yml`, add an option: `teleport-to-afk-zone: true/false`.
   - Admin command `/afk setzone` saves the current location as the "AFK Zone" (e.g., a custom lobby floating island or sanctuary).
   - When going AFK, save the player's original location and gently teleport them to the AFK Zone.
   - When exiting AFK (by moving, chatting, or typing /afk), immediately restore their inventory, health, and teleport them back to their exact previous location safely (check for ground to prevent falling into void/lava).

3. **Passive AFK Economy / Rewards**:
   - While AFK in the AFK Zone, run a task every X minutes (default: 5 minutes).
   - Execute configurable rewards (e.g., console command rewards like `/eco give %player% 50`, `/xp give %player% 10`, or custom item drops).
   - Cap maximum AFK reward time per day (e.g., max 2 hours of rewards per day) to maintain server economy balance.

4. **Visual & Interactive Features**:
   - **Glow & Particle Effect**: Apply an glowing aura effect (using Glow API or Team Packet) and ambient particles around AFK players.
   - **Tablist Status**: Add dynamic tablist prefix `&7[AFK] %player%`.
   - **Action Bar**: Send action bar countdown to next reward payout: `&eAFK Status: Active &7| Next Reward in: &a%time%s`.
   - **Anti-Damage**: Complete invulnerability against mobs, players, and environmental damage while AFK.

5. **Commands & Permissions**:
   - `/afk [reason]` - Manual toggle (Permission: `pocketafk.use`)
   - `/afk setzone` - Sets the AFK sanctuary location (Permission: `pocketafk.admin`)
   - `/afk reload` - Reloads configuration (Permission: `pocketafk.admin`)

6. **Configuration (`config.yml`)**:
   - Include clear yaml structure for:
     - `idle-time-seconds`: 300
     - `teleport-to-zone`: true
     - `reward-interval-minutes`: 5
     - `daily-reward-limit-minutes`: 120
     - `reward-commands`:
       - "eco give %player% 25"
       - "tm message %player% &aYou received an AFK reward!"
     - `messages` block with customizable colors and placeholders (`%player%`, `%reason%`, `%time%`).

Ensure the code uses clean Spigot/Paper Event Listeners, runs idle checks asynchronously to prevent main-thread tick lag, and generates a valid `plugin.yml`.
Kodari AI
KodariAug 5 at 5:13 pm 2
PocketAFK
PocketAFK is an interactive AFK plugin for Paper/Spigot 1.20+ that transforms idle players into a rewarding sanctuary experience. It features an auto-detection engine tracking movement, chat, block interactions, and commands, triggering AFK state after a configurable idle period. Players can optionally teleport to a designated AFK Zone via /afk setzone, with safe return to their original location. While AFK, players receive passive economy rewards at configurable intervals, capped by a daily limit to prevent abuse. Visual feedback includes glowing aura effects, particles, tablist prefix, and action bar countdowns. Complete invulnerability protects AFK players, with bypass permissions for spawner/redstone farm areas. Commands include /afk toggle, /afk setzone, and /afk reload with full configurable messages and rewards.
  1. Create the Gradle Paper project and plugin metadata.

  2. Add AFK state, settings, reward-ledger, and manager classes.

  3. Add command and event-listener handling for activity, protection, teleport restoration, and GUI-independent status effects.

  4. Add production defaults and configurable messages/reward settings.

[Generation stopped]

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
11 855
src/main/java/com/kodari/pocketafk/PocketAFK.java
package com.kodari.pocketafk;

import com.kodari.pocketafk.afk.AfkManager;
import com.kodari.pocketafk.config.AfkSettings;
import com.kodari.pocketafk.command.AfkCommand;
import com.kodari.pocketafk.listener.AfkListener;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Map;

public final class PocketAFK extends JavaPlugin {
    private AfkSettings settings;
    private AfkManager afkManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        settings = AfkSettings.from(getConfig());
        afkManager = new AfkManager(this, settings);

        Bukkit.getPluginManager().registerEvents(new AfkListener(this, afkManager), this);
        AfkCommand command = new AfkCommand(this, afkManager);
        if (getCommand("afk") != null) {
            getCommand("afk").setExecutor(command);
            getCommand("afk").setTabCompleter(command);
        }
        afkManager.start();
    }

    @Override
    public void onDisable() {
        if (afkManager != null) {
            afkManager.shutdown();
        }
    }

    public void reloadPlugin() {
        reloadConfig();
        settings = AfkSettings.from(getConfig());
        afkManager.applySettings(settings);
    }

    public AfkSettings getSettings() {
        return settings;
    }

    public String message(String key, Player player, String reason, String time) {
        String value = getConfig().getString("messages." + key, "");
        value = value.replace("%player%", player == null ? "" : player.getName())
                .replace("%reason%", reason == null ? "" : reason)
                .replace("%time%", time == null ? "" : time);
        return ChatColor.translateAlternateColorCodes('&', value);
    }

    public void saveZone(Location location) {
        getConfig().set("afk-zone.world", location.getWorld().getName());
        getConfig().set("afk-zone.x", location.getX());
        getConfig().set("afk-zone.y", location.getY());
        getConfig().set("afk-zone.z", location.getZ());
        getConfig().set("afk-zone.yaw", location.getYaw());
        getConfig().set("afk-zone.pitch", location.getPitch());
        saveConfig();
    }

    public Location getAfkZone() {
        ConfigurationSection section = getConfig().getConfigurationSection("afk-zone");
        if (section == null) {
            return null;
        }
        String worldName = section.getString("world", "");
        World world = Bukkit.getWorld(worldName);
        if (world == null || worldName.isEmpty()) {
            return null;
        }
        return new Location(world, section.getDouble("x"), section.getDouble("y"),
                section.getDouble("z"), (float) section.getDouble("yaw"),
                (float) section.getDouble("pitch"));
    }
}