q2xcs
📎 1 file 1,488 chars
📄
pasted-code-1775529093408.txt
txt 54 lines
▶
Create a Minecraft plugin (Spigot/Paper 1.21+) that allows admins to temporarily disable PvP in specific worlds with a timer.

Core Command:
/pvpdisable  
Kodari AI
KodariApr 7 at 2:33 am 8,353 (v2)
PvPControl
A Spigot/Paper plugin that allows admins to temporarily disable PvP in specific worlds with a countdown timer. Features `/pvpdisable`, `/pvpenable`, and `/pvptimer` commands with flexible time formats (s/m/h). Cancels EntityDamageByEntityEvent between players in disabled worlds. Supports PlaceholderAPI for %pvp_disabled_<world>% and %pvp_timer_<world>%. Saves active timers on shutdown and restores them on startup. Includes configurable broadcast messages and permission-based access.

Planning the class structure:

  • PvPControl — main plugin, owns all managers

  • PvPManager — stores active disabled worlds with remaining seconds

  • PvPTimerTask — BukkitRunnable ticking every second

  • ConfigManager — loads/saves config.yml & data.yml

  • PvPCommand — handles /pvpdisable, /pvpenable, /pvptimer

  • PvPListener — cancels EntityDamageByEntityEvent

  • PvPPlaceholder — PlaceholderAPI expansion

  • MessageUtil — legacy color formatting

Here’s a summary of what was built:

  • PvPControl — main class, wires all managers and registers commands/listeners/placeholder

  • ConfigManager — loads config.yml + data.yml, exposes all message/setting getters

  • PvPManager — stores Map<String, Long> of disabled worlds with remaining seconds; handles load/save to data.yml and tick() logic

  • PvPTimerTask — BukkitRunnable ticking every second, calls tick() and broadcasts the re-enable message when a timer expires

  • PvPCommand — handles all three commands with tab completion and full validation (invalid world, invalid time, already-disabled override)

  • PvPListener — cancels EntityDamageByEntityEvent when both entities are players in a PvP-disabled world

  • PvPPlaceholder — exposes %pvp_disabled_<world>% and %pvp_timer_<world>% via PlaceholderAPI

  • TimeUtil — parses 30s / 5m / 1h and formats seconds back to human-readable strings

  • Timers persist across restarts via data.yml

q2xcs

Add in the plugin if the player already died, they switched gamemode the spec, and they cannot chat and go over to the world border, make it if the player already died and in spec but leaved na rejoin they cannot reviree again like back to spec gamemode

Kodari AI
KodariApr 7 at 8:04 am 11,823 (v2)

Let me read all the existing files first.

Here’s my plan:

  • Create a SpectatorManager to track dead-spectator players (persisted by UUID in data.yml so rejoin state survives)

  • Expand PvPListener to handle: death → spectator switch, chat block, world border enforcement, join restore, quit cleanup

  • Wire SpectatorManager into the main plugin class and add config messages

Here’s a summary of everything added:

  • SpectatorManager — tracks dead-spectator UUIDs in memory and persists them to data.yml so the state survives server restarts and player reconnects

  • PlayerDeathEvent — when a player dies in a PvP-disabled world, they’re added to the dead-spectator set and switched to SPECTATOR gamemode on the next tick

  • PlayerJoinEvent — if a dead spectator reconnects, they’re placed back into SPECTATOR gamemode automatically (preventing revival)

  • AsyncPlayerChatEvent — chat is cancelled for all dead spectators with a message

  • PlayerMoveEvent — movement outside the world border (checked via center ± half-size on X/Z) is cancelled for dead spectators

  • PlayerQuitEvent — saves state to disk on every disconnect so no data is lost

  • Four new config message keys added: pvp-blocked, death-spectator, chat-blocked, border-blocked

q2xcs

and the pvp annouce it in the title every 10 mins, and if its under 10 mins show it for 5 mins and 3 mins and 1 min and 30 secs and 10 sec and 5 until 0

Kodari AI
KodariApr 7 at 8:11 am 5,066 (v2)
  • Add announce thresholds: every 10 min mark (time % 600 == 0) for times > 600, then at 300, 180, 60, 30, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 seconds

  • Add title config keys to config.yml and ConfigManager

  • Update PvPTimerTask to check thresholds each tick and send titles to world players

  • PvPTimerTask now announces via title every 10-minute mark for timers above 10 min, then at 5m, 3m, 1m, 30s, and every second from 10s down to 1s

  • Title text/colors are fully configurable in config.yml under announce-title

  • MessageUtil.sendWorldTitle sends the title only to players in the affected world

q2xcs

fix it the if the player died and respawn switched there gamemode to spectetor, keep that to spec even they rejoined

Kodari AI
KodariApr 7 at 8:24 am 2,589 (v2)

Looking at the code, the issue is that PlayerRespawnEvent fires when the player clicks “Respawn” and Bukkit resets their gamemode — there’s no handler for it, so the spectator mode gets cleared on respawn. The onPlayerJoin handler only covers disconnects/reconnects.

Added a PlayerRespawnEvent handler that re-applies spectator mode after the respawn tick, which was the missing piece — without it, clicking “Respawn” would reset the player’s gamemode and bypass the dead-spectator state.

q2xcs

The configuration of the title sends its not showing in the config.yml

Kodari AI
KodariApr 7 at 8:49 am 3,163 (v2)

The issue is clear: config.yml is missing an enabled toggle under announce-title, and ConfigManager has no isAnnounceTitleEnabled() method, so the title is always sent with no way to control it from config.

  • Add enabled: true to the announce-title section in config.yml

  • Add isAnnounceTitleEnabled() to ConfigManager

  • Guard the title send in PvPTimerTask behind that flag

Added enabled: true under announce-title in config.yml, a matching isAnnounceTitleEnabled() getter in ConfigManager, and a guard check in PvPTimerTask so titles only send when that flag is true.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
13 887
src/main/java/com/pvpcontrol/PvPControl.java
package com.pvpcontrol;

import com.pvpcontrol.command.PvPCommand;
import com.pvpcontrol.config.ConfigManager;
import com.pvpcontrol.listener.PvPListener;
import com.pvpcontrol.manager.PvPManager;
import com.pvpcontrol.manager.SpectatorManager;
import com.pvpcontrol.placeholder.PvPPlaceholder;
import com.pvpcontrol.task.PvPTimerTask;
import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;

public class PvPControl extends JavaPlugin {

    @Getter
    private ConfigManager configManager;
    @Getter
    private PvPManager pvpManager;
    @Getter
    private SpectatorManager spectatorManager;
    private PvPTimerTask timerTask;

    @Override
    public void onEnable() {
        this.configManager = new ConfigManager(this);
        this.configManager.load();

        this.pvpManager = new PvPManager(this);
        this.pvpManager.loadTimers();

        this.spectatorManager = new SpectatorManager(this);
        this.spectatorManager.load();

        this.timerTask = new PvPTimerTask(this);
        this.timerTask.runTaskTimer(this, 20L, 20L);

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

        PvPCommand command = new PvPCommand(this);
        getCommand("pvpdisable").setExecutor(command);
        getCommand("pvpdisable").setTabCompleter(command);
        getCommand("pvpenable").setExecutor(command);
        getCommand("pvpenable").setTabCompleter(command);
        getCommand("pvptimer").setExecutor(command);
        getCommand("pvptimer").setTabCompleter(command);

        if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
            new PvPPlaceholder(this).register();
        }
    }

    @Override
    public void onDisable() {
        if (this.timerTask != null) {
            this.timerTask.cancel();
        }
        if (this.pvpManager != null) {
            this.pvpManager.saveTimers();
        }
        if (this.spectatorManager != null) {
            this.spectatorManager.save();
        }
    }
}