peckster
📎 1 file 3,361 chars
📄
pasted-code-1776769428774.txt
txt 101 lines
▶
Create a simple Paper 1.20.4 plugin that removes player-placed blocks after a configurable amount of time, only inside specific WorldGuard regions.

Plugin purpose:
- This plugin should ONLY track player-placed blocks
- After a configurable delay, those placed blocks should be removed automatically
- It should only work in configured worlds/regions
- It should NOT do rollback, terrain restore, explosion handling, or anything else

Required behavior:
1. Listen to BlockPlaceEvent
2. If the block was placed in an enabled world and allowed WorldGuard region, track it
3. After the configured delay, remove that placed block by setting it to AIR
4. Only remove the block if it is still the same tracked placement
5. If a player places a newer block at the same location, the old cleanup task must not remove the newer one
6. If the block is already gone, do nothing
7. Do not affect naturally generated blocks
8. Do not track or remove blocks outside the configured region/world

WorldGuard support:
- Add optional WorldGuard integration
- Config should support:
  - enabled: true/false
  - allowed-regions: []
  - blocked-regions: []
- Only track placements if:
  - world is enabled
  - location is inside an allowed region
  - location is not inside a blocked region

Important anti-bug requirement:
Use per-location versioning or timestamps so stale cleanup tasks cannot remove newer blocks placed later at the same location.

Implementation details:
1. Use a Map
2. TrackedPlacement should include:
   - material
   - blockData
   - placedAt or expireAt
   - version or unique id
3. On BlockPlaceEvent:
   - create/update the tracked entry for that location
   - schedule cleanup for that specific version
4. On cleanup:
   - get the current tracked entry for the location
   - if no entry exists, do nothing
   - if the version does not match, do nothing
   - if the block at the location is still the same placement, set it to AIR
   - remove the tracking entry
5. If the block is broken or removed before cleanup, remove the tracking entry when appropriate

Required config.yml:
cleanup-delay: 5

enabled-worlds:
  - Spawn

worldguard:
  enabled: true
  allowed-regions:
    - cpvp
  blocked-regions:
    - safezone

ignored-materials:
  - BEDROCK
  - BARRIER
  - COMMAND_BLOCK
  - CHAIN_COMMAND_BLOCK
  - REPEATING_COMMAND_BLOCK
  - STRUCTURE_BLOCK
  - STRUCTURE_VOID
  - JIGSAW

debug: false

Extra requirements:
1. Add a clean main class
2. Add a listener class for block placement
3. Add a small WorldGuard hook/helper class
4. Add a TrackedPlacement data class
5. Add debug logging when:
   - a block is tracked
   - a block is skipped
   - a block is removed
   - a cleanup is ignored because a newer version exists
6. Add a reload command: /tempblocks reload
7. Validate config on startup

Do NOT:
- Do not restore terrain
- Do not track explosions
- Do not snapshot the map
- Do not block crystal damage
- Do not do anything except temporary removal of player-placed blocks

Desired result:
- A player places obsidian in cpvp
- 5 seconds later it disappears
- If they place another block at the same spot before then, only the newest one is respected
- Blocks outside cpvp are ignored
- Blocks in safezone are ignored
Kodari AI
KodariApr 21 at 11:06 am 10,640 (v2)

I’ll create a temporary block removal plugin with WorldGuard region support and per-location versioning.

TempBlocks
Automatically removes player-placed blocks after a configurable delay in specific WorldGuard regions. Features per-location versioning to prevent stale cleanup tasks from removing newer blocks placed at the same location. Supports configurable world and region filters, material ignore list, and detailed debug logging. Includes reload command and validation. Only tracks blocks placed by players in enabled regions, with no impact on naturally generated terrain.

All files created successfully! The plugin features:

Core functionality:

  • Tracks player-placed blocks with unique UUID versioning per location

  • Automatically removes tracked blocks after configurable delay

  • Prevents stale cleanup tasks from removing newer blocks via version checking

WorldGuard integration:

  • Optional region filtering (allowed/blocked regions)

  • Checks both allowed and blocked region lists before tracking

Safety features:

  • Only tracks blocks in enabled worlds

  • Ignores configured materials (command blocks, bedrock, etc.)

  • Removes tracking when blocks are broken early

  • Validates block material hasn’t changed before cleanup

  • Comprehensive config validation on startup

Debug system:

  • Detailed logging for tracking, skipping, and cleanup events

  • Shows version mismatches and block state changes

Management:

  • /tempblocks reload command with permission check

  • Clean shutdown with tracked block cleanup

The versioning system ensures that if a player places obsidian, then breaks it and places stone at the same location, the original obsidian cleanup task won’t remove the stone.

peckster

everything is great but if a player builds just before the server restarts it doesnt remove the blocks

Kodari AI
KodariApr 30 at 8:58 pm 10,011 (v2)

I’ll add data persistence so tracked blocks are saved to disk and restored on restart, with cleanup tasks rescheduled.

Perfect! I’ve added data persistence to the plugin. Here’s what changed:

BlockTracker enhancements:

  • data.yml file: All tracked blocks are now saved to plugins/TempBlocks/data.yml

  • loadData(): On startup, loads all tracked blocks and:

    • Calculates remaining cleanup time for each block

    • Schedules cleanup tasks with correct remaining delay

    • Immediately cleans up blocks that expired during downtime

    • Shows stats: “Loaded X tracked blocks (Y scheduled, Z immediate cleanup)”

  • saveData(): Automatically called after every tracking change (add/remove/cleanup)

  • Data structure: Stores world, x/y/z, material, version UUID, and placedAt timestamp

Startup behavior:

  • Loads tracked blocks immediately after initialization

  • If a block was placed 3 seconds before restart with 5-second delay, it will be removed 2 seconds after restart

  • If a block expired during downtime, it’s cleaned up immediately on first tick

Shutdown behavior:

  • clearAll() now saves data before clearing, ensuring blocks placed right before shutdown are persisted

Now blocks placed before server restart will be properly tracked and removed after the configured delay, even across restarts!

peckster

can you add a permission that can bypass the plugin

Kodari AI
KodariApr 30 at 8:59 pm 5,545 (v2)

I’ll add a bypass permission so players with it won’t have their blocks tracked.

Done! I’ve added the bypass permission:

Changes:

  1. plugin.yml - Added two permissions:

    • tempblocks.bypass - Blocks placed by players with this permission won’t be tracked or removed

    • tempblocks.reload - Allows reloading the plugin configuration

  2. BlockListener - Added permission check as the first validation before any tracking occurs

    • If player has tempblocks.bypass, their blocks are ignored

    • Debug log shows when blocks are skipped due to bypass permission

Now players with the tempblocks.bypass permission can place blocks that will remain permanently, even in tracked regions!

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
10 606
src/main/java/com/tempblocks/TempBlocks.java
package com.tempblocks;

import com.tempblocks.commands.ReloadCommand;
import com.tempblocks.hooks.WorldGuardHook;
import com.tempblocks.listeners.BlockListener;
import com.tempblocks.managers.BlockTracker;
import com.tempblocks.managers.ConfigManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class TempBlocks extends JavaPlugin {
    
    private ConfigManager configManager;
    private WorldGuardHook worldGuardHook;
    private BlockTracker blockTracker;
    
    @Override
    public void onEnable() {
        this.saveDefaultConfig();
        
        this.configManager = new ConfigManager(this);
        this.configManager.load();
        
        this.worldGuardHook = new WorldGuardHook(this);
        
        this.blockTracker = new BlockTracker(this);
        this.blockTracker.loadData();
        
        Bukkit.getPluginManager().registerEvents(new BlockListener(this), this);
        
        this.getCommand("tempblocks").setExecutor(new ReloadCommand(this));
        
        this.getLogger().info("TempBlocks enabled successfully!");
        if (this.worldGuardHook.isEnabled()) {
            this.getLogger().info("WorldGuard integration enabled");
        }
    }
    
    @Override
    public void onDisable() {
        if (this.blockTracker != null) {
            this.blockTracker.clearAll();
        }
        this.getLogger().info("TempBlocks disabled");
    }
}