jssyro.

Compiel this 26.1.1 paper java 25 plugin without cxhanging it just compile

Kodari AI
KodariYesterday at 9:40 am 1

To compile and download the plugin:

  1. Click Compile in the top bar, or on mobile tap ⋮ → Compile Project.

  2. Click Compile in the window.

  3. Once it succeeds, click Download on the build.

No files need to be changed.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle.kts
settings.gradle.kts
Code
5 503
src/main/java/dev/tntportal/TntPortalPlugin.java
package dev.tntportal;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Axis;
import org.bukkit.Bukkit;
import org.bukkit.HeightMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Orientable;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ThreadLocalRandom;

public final class TntPortalPlugin extends JavaPlugin implements TabExecutor, Listener {

    /** Each entry = one summon / mass job. Newest first. */
    private final Deque<List<BlockState>> history = new ArrayDeque<>();
    private BukkitTask job;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        getServer().getPluginManager().registerEvents(this, this);
        var cmd = getCommand("tntportal");
        if (cmd != null) {
            cmd.setExecutor(this);
            cmd.setTabCompleter(this);
        } else {
            getLogger().warning("plugin.yml has no 'tntportal' command - registering it in code instead.");
            final TntPortalPlugin self = this;
            Command fallback = new Command("tntportal", "Summon nether portals", "/tntportal", List.of("tportal")) {
                @Override
                public boolean execute(CommandSender sender, String label, String[] args) {
                    if (!sender.hasPermission("tntportal.use")) {
                        sender.sendMessage(Component.text("You don't have permission.", NamedTextColor.RED));
                        return true;
                    }
                    return self.onCommand(sender, this, label, args);
                }

                @Override
                public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
                    if (!sender.hasPermission("tntportal.use")) return List.of();
                    return self.onTabComplete(sender, this, alias, args);
                }
            };
            getServer().getCommandMap().register("tntportal", fallback);
        }
    }

    @EventHandler
    public void onPortal(EntityPortalEvent e) {
        if (e.getEntity() instanceof TNTPrimed t && t.getScoreboardTags().contains("tntportal")) e.setCancelled(true);
    }

    // ------------------------------------------------------------------ data

    private record Placement(World world, int x, int y, int z, Axis axis) {
        double centerX() { return x + (axis == Axis.X ? 1.0 : 0.5); }
        double centerZ() { return z + (axis == Axis.Z ? 1.0 : 0.5); }
        float yaw() { return axis == Axis.X ? 0f : -90f; }

        /** Middle of the bottom of the portal interior. */
        Location bottomMiddle() { return new Location(world, centerX(), y, centerZ(), yaw(), 0f); }

        Location front(double dist) {
            double fx = centerX() + (axis == Axis.Z ? dist : 0);
            double fz = centerZ() + (axis == Axis.X ? dist : 0);
            return new Location(world, fx, y, fz, yaw(), 0f);
        }
    }

    private static final class Opts {
        World world;
        Axis axis;
        String tp;
        Integer tnt;
        Integer fuse;
        Integer spacing;
    }

    // ------------------------------------------------------------- commands

    @Override
    public boolean onCommand(CommandSender s, Command c, String label, String[] a) {
        if (a.length == 0) { help(s); return true; }
        try {
            switch (a[0].toLowerCase(Locale.ROOT)) {
                case "summon" -> summon(s, a, false);
                case "summon5" -> summon(s, a, true);
                case "mass" -> mass(s, a);
                case "undo" -> undo(s, a);
                case "reload" -> { reloadConfig(); ok(s, "Config reloaded."); }
                default -> help(s);
            }
        } catch (IllegalArgumentException ex) {
            err(s, ex.getMessage());
        }
        return true;
    }

    private void help(CommandSender s) {
        ok(s, "/tntportal summon <x> <y> <z> [flags]   - lit portal (bottom-left inside block)");
        ok(s, "/tntportal summon5 <x> <y> <z> [flags]  - same + TNT at bottom-middle (default 50)");
        ok(s, "/tntportal mass <count> <centerX> <centerZ> <radius> [flags] - hundreds of portals on the ground");
        ok(s, "/tntportal undo [n|all]                  - remove obsidian + portal blocks (restores old blocks)");
        ok(s, "Flags: -tp=<player|@a|@p|all>  -axis=x|z  -world=<name>  -tnt=<n>  -fuse=<ticks>  -spacing=<n> (mass)");
        ok(s, "Coordinates support ~ relative values.");
    }

    private void summon(CommandSender s, String[] a, boolean tntMode) {
        if (a.length < 4) throw new IllegalArgumentException("Usage: /tntportal " + a[0] + " <x> <y> <z> [flags]");
        if (job != null) throw new IllegalArgumentException("A mass job is still running.");

        Opts o = parseFlags(s, a, 4);
        World w = o.world != null ? o.world : defaultWorld(s);
        Location base = s instanceof Player p ? p.getLocation() : new Location(w, 0, 0, 0);

        int x = coord(a[1], base.getBlockX());
        int y = coord(a[2], base.getBlockY());
        int z = coord(a[3], base.getBlockZ());
        if (y < w.getMinHeight() + 1 || y > w.getMaxHeight() - 5)
            throw new IllegalArgumentException("Y is out of world bounds.");

        Axis axis = o.axis != null ? o.axis : Axis.X;
        int tnt = o.tnt != null ? o.tnt : (tntMode ? getConfig().getInt("tnt.count", 50) : 0);
        int fuse = o.fuse != null ? o.fuse : getConfig().getInt("tnt.fuse-ticks", 80);

        List<BlockState> snap = new ArrayList<>();
        Placement pl = new Placement(w, x, y, z, axis);
        build(pl, snap);
        if (tnt > 0) spawnTnt(pl, tnt, fuse);

        int tpCount = 0;
        if (o.tp != null) {
            for (Player p : resolveTargets(s, o.tp)) {
                teleport(p, pl, snap);
                tpCount++;
            }
        }
        push(snap);
        ok(s, "Portal summoned at " + x + " " + y + " " + z + " (" + w.getName() + ")"
                + (tnt > 0 ? ", " + tnt + " TNT" : "")
                + (tpCount > 0 ? ", teleported " + tpCount + " player(s)" : "") + ".");
    }

    private void mass(CommandSender s, String[] a) {
        if (a.length < 5) throw new IllegalArgumentException("Usage: /tntportal mass <count> <centerX> <centerZ> <radius> [flags]");
        if (job != null) throw new IllegalArgumentException("A mass job is already running.");

        Opts o = parseFlags(s, a, 5);
        World w = o.world != null ? o.world : defaultWorld(s);
        Location base = s instanceof Player p ? p.getLocation() : new Location(w, 0, 0, 0);

        int count = parseInt(a[1]);
        int max = getConfig().getInt("mass.max-portals", 2000);
        if (count < 1 || count > max) throw new IllegalArgumentException("Count must be 1-" + max + ".");
        int cx = coord(a[2], base.getBlockX());
        int cz = coord(a[3], base.getBlockZ());
        int radius = Math.max(1, parseInt(a[4]));
        int spacing = o.spacing != null ? o.spacing : getConfig().getInt("mass.default-spacing", 6);
        int tnt = o.tnt != null ? o.tnt : 0;
        int fuse = o.fuse != null ? o.fuse : getConfig().getInt("tnt.fuse-ticks", 80);
        int perTick = Math.max(1, getConfig().getInt("mass.per-tick", 4));

        ThreadLocalRandom r = ThreadLocalRandom.current();
        List<int[]> pts = new ArrayList<>();
        int attempts = 0, maxAttempts = count * 40;
        long minDist2 = (long) spacing * spacing;
        while (pts.size() < count && attempts++ < maxAttempts) {
            int px = cx + r.nextInt(-radius, radius + 1);
            int pz = cz + r.nextInt(-radius, radius + 1);
            boolean fine = true;
            for (int[] q : pts) {
                long dx = q[0] - px, dz = q[1] - pz;
                if (dx * dx + dz * dz < minDist2) { fine = false; break; }
            }
            if (fine) pts.add(new int[]{px, pz});