ehtiyar
📎 1 file 1,710 chars
📄
pasted-code-1779930559583.txt
txt 27 lines
▶
Write a complete, optimized, and ready-to-compile Minecraft Paper plugin for version 1.21.4. The plugin must hook into WorldGuard and provide region-enter titles with an anti-spam system.

Core Features:

Region Enter Title: When a player enters a specifically configured WorldGuard region, display a Title and Subtitle on their screen (e.g., "Welcome to Castle Island"). Do not display any messages or titles when the player leaves the region.

Anti-Spam Cooldown System: To prevent players from spamming the title by constantly entering and exiting the region boundary, implement a per-player, per-region cooldown timer. If a player re-enters the same region before the cooldown expires, the title will not be shown.

Configuration (config.yml) Requirements:

Regions Setup: A section to map WorldGuard region names to their specific Title and Subtitle texts.

Cooldown Setting: A configurable integer (e.g., cooldown-seconds: 30) that applies globally to the anti-spam system.

Localization (Messages): A dedicated messages section for all chat outputs (like plugin reload messages, lack of permission, etc.) so I can easily translate them into Turkish.

Modern Text Support: Please use the Paper Component API (MiniMessage format like , , ) or Hex color codes for all titles and messages.

Technical Requirements:

Ensure proper integration with the latest WorldGuard API for 1.21.4.

Use optimized methods to check player movement/region entry to prevent server lag.

Include a /regiontitle reload command (with a permission node) to reload the config in-game without restarting the server.

Provide the full source code (Main class, Event Listeners, and plugin.yml/paper-plugin.yml).
Kodari AI
KodariMay 28 at 1:10 am 8
RegionTitles
A Paper 1.21.4 plugin that hooks into WorldGuard to display MiniMessage-formatted titles and subtitles when players enter configured regions. Features a per-player, per-region anti-spam cooldown system, full MiniMessage/hex color support for all text, a dedicated messages section for easy localization, and a /regiontitle reload command with permission control.

Planning:

  1. plugin.yml — commands, permissions, depend on WorldGuard/WorldEdit

  2. config.yml — regions map, cooldown, messages

  3. RegionTitles.java — main plugin class, loads config, exposes managers

  4. ConfigManager.java — typed config access

  5. CooldownManager.java — per-player per-region cooldown tracking

  6. RegionListener.java — PlayerMoveEvent → WorldGuard region check → title display

  7. ReloadCommand.java — /regiontitle reload

Here’s what was built:

7 files, zero external runtime deps.

File
Role
RegionTitles.java
Main class — wires everything together
ConfigManager.java
Typed config access,
load()
called on reload
CooldownManager.java
uuid:regionName
keyed cooldown map
RegionListener.java
Block-boundary-only move check → WorldGuard region diff → title
ReloadCommand.java
/regiontitle reload
with permission check
config.yml
Regions map + cooldown + messages (all MiniMessage)
plugin.yml
Depends on WorldEdit + WorldGuard

Key design decisions:

  • Move event optimization — skips the WorldGuard lookup entirely if the player hasn’t crossed a block boundary (head rotation, etc. are ignored)

  • Region diff — computes fromRegions vs toRegions sets so only newly entered regions trigger a title, never re-fires while standing inside

  • Cooldown key — uuid:regionId string map, cleared on player quit to prevent memory leaks

  • MiniMessage everywhere — titles, subtitles, and all chat messages support full gradient/hex/formatting syntax

  • /regiontitle reload — calls ConfigManager.load() which does reloadConfig() + re-parses all sections in-place

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
8 379
src/main/java/com/kodari/regiontitles/RegionTitles.java
package com.kodari.regiontitles;

import com.kodari.regiontitles.command.ReloadCommand;
import com.kodari.regiontitles.config.ConfigManager;
import com.kodari.regiontitles.cooldown.CooldownManager;
import com.kodari.regiontitles.listener.RegionListener;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

public class RegionTitles extends JavaPlugin {

    private ConfigManager configManager;
    private CooldownManager cooldownManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        this.configManager = new ConfigManager(this);
        this.cooldownManager = new CooldownManager();

        getServer().getPluginManager().registerEvents(new RegionListener(this), this);

        PluginCommand cmd = getCommand("regiontitle");
        if (cmd != null) {
            cmd.setExecutor(new ReloadCommand(this));
        }

        getLogger().info("RegionTitles enabled.");
    }

    @Override
    public void onDisable() {
        getLogger().info("RegionTitles disabled.");
    }

    public ConfigManager cfg() {
        return configManager;
    }

    public CooldownManager getCooldownManager() {
        return cooldownManager;
    }
}