tjark427

make me a command that refills a box of whatever so if you do /returnfill and then position and then another position and then select a block then it fills that pos with blocks and after it got almost fully mined it refills again also you can remove the fill and add also a villager that trades for wood or you can set it for like 64 wood for whatever or whatever and the villager is immortal

Kodari AI
KodariYesterday at 9:48 am 2
ReturnFillSystem
Creates a Minecraft plugin with a /returnfill command allowing players to define two corner positions and select a block type to auto-refill that region. When blocks in the area are nearly fully mined, the plugin automatically restores them. Includes commands to remove active fills and configurable immortal villagers that trade wood for customizable items or currency, with adjustable trade ratios.
  • Add persistent, automatically refilling regions selected with /returnfill.

  • Add configurable, invulnerable trading villagers.

Created the refill and trader commands:

  • Stand at each corner and run /returnfill pos1 and /returnfill pos2.

  • Create a region with /returnfill add mine STONE; remove it with /returnfill remove mine.

  • Create a trader with, for example, /returnfill villager OAK_LOG 64 DIAMOND 1.

Regions refill when 20% or less of their original blocks remain. Creating or refilling a region replaces all blocks inside it. The threshold and maximum region size are configurable.

tjark427

the villager isnt immortal make it if it is low it goes back to full hp also add setspawnpoint which set spawnpoint for all players and even new players

Kodari AI
KodariYesterday at 11:11 am 2
  1. Make trading villagers invulnerable and restore their health when low.

  2. Add a global spawn point for all players, including new players.

  • Trading villagers now resist damage and return to full health when low. This also applies to existing ReturnFill traders.

  • Use /setspawnpoint where you’re standing to set the global spawn. New players spawn there on their first join, and all players respawn there after death.

tjark427

add a command that lets you remove the villager also make all blocks that the owner placed make it unbreakable

Kodari AI
KodariYesterday at 11:18 am 2
  1. Add a command to remove a ReturnFill villager.

  2. Protect blocks placed by the server owner from being broken.

  • Use /returnfill removevillager to remove the nearest ReturnFill trader within five blocks.

  • The owner must run /returnfill setowner once. Blocks they place afterward are protected from player breaking, explosions, pistons, and region refills. Existing blocks can’t be identified retroactively.

tjark427

also make it so you cant place blocks on refillable blocks make refillable blocks breakable even with set owner and also cant place also to the setownered blocks

Kodari AI
KodariYesterday at 11:24 am 1
  1. Block placement inside refill regions and against refill or owner-protected blocks.

  2. Allow refillable blocks to be mined even when their positions were owner-protected.

  • Players can no longer place blocks inside refill regions or against refillable or owner-protected blocks.

  • Refillable blocks remain breakable even if their positions were previously owner-protected.

tjark427

the owner cant break blocks with set owner

Kodari AI
KodariYesterday at 11:29 am 1

I’ll let the configured owner break protected blocks while keeping them protected from other players.

The configured owner can now break protected blocks. Other players still can’t, and protection is removed when the owner breaks one.

tjark427

also other players cant use the returnfill command and whatever only operator

Kodari AI
KodariYesterday at 11:30 am 1

I’ll restrict /returnfill and /setspawnpoint to operators.

Only operators can now use /returnfill and /setspawnpoint.

tjark427

why cant the owner place blocks on top of the owner who placed it blocks

Kodari AI
KodariYesterday at 12:28 pm 1

The placement rule was blocking everyone, including the owner, from placing against protected blocks. I changed it so the configured owner can place against them; other players still can’t. Refill-region restrictions remain in place.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 489
src/main/java/com/kodari/returnfill/ReturnFillPlugin.java
package com.kodari.returnfill;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockMultiPlaceEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class ReturnFillPlugin extends JavaPlugin implements Listener {
    private final Map<UUID, Location[]> selections = new HashMap<>();
    private final Map<String, Region> regions = new HashMap<>();
    private final Set<String> pendingChecks = new HashSet<>();
    private final Set<String> protectedBlocks = new HashSet<>();

    @Override
    public void onEnable() {
        saveDefaultConfig();
        protectedBlocks.addAll(getConfig().getStringList("protected-blocks"));
        ConfigurationSection section = getConfig().getConfigurationSection("regions");
        if (section != null) {
            for (String name : section.getKeys(false)) {
                ConfigurationSection entry = section.getConfigurationSection(name);
                if (entry == null) continue;
                Material material = parseMaterial(entry.getString("material", ""));
                String world = entry.getString("world");
                if (material == null || !material.isBlock() || world == null) {
                    getLogger().warning("Skipping invalid region: " + name);
                    continue;
                }
                regions.put(name, new Region(world, entry.getInt("min-x"), entry.getInt("min-y"), entry.getInt("min-z"),
                        entry.getInt("max-x"), entry.getInt("max-y"), entry.getInt("max-z"), material));
            }
        }
        Bukkit.getPluginManager().registerEvents(this, this);
        Bukkit.getScheduler().runTaskTimer(this, () -> {
            for (World world : Bukkit.getWorlds()) {
                for (Villager villager : world.getEntitiesByClass(Villager.class)) {
                    if (isTrader(villager) && villager.getHealth() < villager.getMaxHealth() / 2.0) {
                        villager.setHealth(villager.getMaxHealth());
                    }
                }
            }
        }, 20L, 20L);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!sender.isOp()) {
            sender.sendMessage(ChatColor.RED + "Only operators can use this command.");
            return true;
        }
        if (!(sender instanceof Player)) {
            sender.sendMessage("Only players can use this command.");
            return true;
        }
        Player player = (Player) sender;
        if (command.getName().equalsIgnoreCase("setspawnpoint")) {
            getConfig().set("spawnpoint", player.getLocation());
            saveConfig();
            player.sendMessage(ChatColor.GREEN + "Global spawn point set at your current location.");
            return true;
        }
        if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
            player.sendMessage(ChatColor.GOLD + "/returnfill pos1|pos2 - select your current block positions");
            player.sendMessage(ChatColor.GOLD + "/returnfill add <name> <block> - create and fill a region");
            player.sendMessage(ChatColor.GOLD + "/returnfill remove <name> | list");
            player.sendMessage(ChatColor.GOLD + "/returnfill villager <cost item> <amount> <reward item> <amount>");
            player.sendMessage(ChatColor.GOLD + "/returnfill removevillager - remove the nearest trader within 5 blocks");
            player.sendMessage(ChatColor.GOLD + "/returnfill setowner - protect blocks you place from now on");
            return true;
        }
        String action = args[0].toLowerCase(Locale.ROOT);
        if (action.equals("setowner") && args.length == 1) {
            getConfig().set("owner", player.getUniqueId().toString());
            saveConfig();
            player.sendMessage(ChatColor.GREEN + "You are now the owner; blocks you place will be protected.");
            return true;
        }
        if (action.equals("removevillager") && args.length == 1) {
            Villager nearest = null;
            double distance = 25.0;
            for (org.bukkit.entity.Entity entity : player.getNearbyEntities(5, 5, 5)) {
                if (entity instanceof Villager && isTrader((Villager) entity)) {
                    double candidate = entity.getLocation().distanceSquared(player.getLocation());
                    if (candidate <= distance) {
                        nearest = (Villager) entity;
                        distance = candidate;
                    }
                }
            }
            if (nearest == null) player.sendMessage(ChatColor.RED + "No ReturnFill trader within 5 blocks.");
            else {
                nearest.remove();
                player.sendMessage(ChatColor.GREEN + "Removed the nearest ReturnFill trader.");
            }
            return true;
        }
        if (action.equals("pos1") || action.equals("pos2")) {
            int index = action.equals("pos1") ? 0 : 1;
            selections.computeIfAbsent(player.getUniqueId(), id -> new Location[2])[index] = player.getLocation().getBlock().getLocation();
            player.sendMessage(ChatColor.GREEN + "Position " + (index + 1) + " set at your current block.");
            return true;
        }
        if (action.equals("list")) {
            List<String> names = new ArrayList<>(regions.keySet());
            Collections.sort(names);
            player.sendMessage(ChatColor.GREEN + "Regions: " + (names.isEmpty() ? "none" : String.join(", ", names)));
            return true;
        }
        if (action.equals("remove") && args.length == 2) {
            String name = args[1].toLowerCase(Locale.ROOT);
            if (regions.remove(name) == null) {
                player.sendMessage(ChatColor.RED + "That region does not exist.");
            } else {
                getConfig().set("regions." + name, null);
                saveConfig();
                player.sendMessage(ChatColor.GREEN + "Removed region " + name + ". Existing blocks were left in place.");
            }
            return true;
        }
        if (action.equals("add") && args.length == 3) {
            String name = args[1].toLowerCase(Locale.ROOT);
            if (!name.matches("[a-z0-9_-]+") || regions.containsKey(name)) {
                player.sendMessage(ChatColor.RED + "Use a unique name containing only letters, numbers, underscores or hyphens.");
                return true;
            }
            Location[] points = selections.get(player.getUniqueId());
            if (points == null || points[0] == null || points[1] == null || !points[0].getWorld().equals(points[1].getWorld())) {
                player.sendMessage(ChatColor.RED + "Set both positions in the same world first.");
                return true;
            }
            Material material = parseMaterial(args[2]);
            if (material == null || !material.isBlock() || material.isAir()) {
                player.sendMessage(ChatColor.RED + "Choose a valid, non-air block material.");
                return true;
            }
            Region region = new Region(points[0], points[1], material);
            long volume = region.volume();
            if (volume > Math.max(1, getConfig().getInt("max-region-blocks", 100000))) {
                player.sendMessage(ChatColor.RED + "Region exceeds the configured block limit.");
                return true;
            }
            regions.put(name, region);
            String path = "regions." + name + ".";
            getConfig().set(path + "world", region.world);
            getConfig().set(path + "min-x", region.minX);
            getConfig().set(path + "min-y", region.minY);
            getConfig().set(path + "min-z", region.minZ);
            getConfig().set(path + "max-x", region.maxX);
            getConfig().set(path + "max-y", region.maxY);
            getConfig().set(path + "max-z", region.maxZ);
            getConfig().set(path + "material", material.name());
            saveConfig();
            region.fill(points[0].getWorld());
            player.sendMessage(ChatColor.GREEN + "Created and filled region " + name + " with " + material.name() + ".");
            return true;
        }
        if (action.equals("villager") && args.length == 5) {
            Material cost = parseMaterial(args[1]);
            Material reward = parseMaterial(args[3]);
            int costAmount;
            int rewardAmount;
            try {