Z

stworz mi plugin na paper 26.3 na to ze moge ustawic teren wpisujac komende na permisje dla administracji /teren ustaw <1 kordynaty np 300 0 300> i <drugie kordynaty np 1000 0 1000> <kolor np &a> <nazwa terenu> i w tym obrebie stworzy sie teren i jak gracz bedzie w tym regionie / terenie to gracz bedzie mial bossbara u gory prze caly czas bossbar z kolorem ktory ustawilem np &a to zielony bossbar i ma byc tekst &7ᴢɴᴀᴊᴅᴜᴊᴇѕᴢ ѕɪᴇ ɴᴀ ᴛᴇʀᴇɴɪᴇ &c<nazwa terenu> i jak wyjde z tego obszaru to zniknie i moge kilka takich dodac i dodaj ze moge je tez usuwac komende /teren usun <nazwa terenu> i nazwij plugin Zentrix-Tereny i dodaj komende /teren reload co przeladuje config jesli cos zmienilem i dodaj tez ze wszystko mozna zmienic w configu komende permisje napisy doslownie wszystko co ci napisalem ma byc edytowalne w configu

Kodari AI
KodariOct 29 at 5:39 pm 1
ZentrixTerrainManager
ZentrixTerrainManager is a Paper 2.6.3 plugin that allows administrators to define custom terrain zones with colored boss bars. Admins use /teren ustaw &lt;x1 y1 z1&gt; &lt;x2 y2 z2&gt; &lt;color&gt; &lt;name&gt; to create zones, /teren usun &lt;name&gt; to remove them, and /teren reload to refresh configuration. Players inside a zone see a persistent boss bar displaying a customizable message with the zone name in the configured color. All messages, permissions, colors, and settings are fully configurable via a YAML config file. Supports multiple simultaneous zones with individual colors and names.
  1. Przygotuję konfigurację Gradle, plugin.yml i domyślny config.yml dla Paper 26.3.

  2. Dodam komendy tworzenia, usuwania i przeładowania terenów z ustawieniami oraz wiadomościami w configu.

  3. Dodam zapisywanie terenów i bossbar widoczny wyłącznie podczas przebywania gracza na danym terenie.

Utworzyłem plugin Zentrix-Tereny dla Paper 26.3.

  • /teren ustaw <x1> <y1> <z1> <x2> <y2> <z2> <kolor> <nazwa> tworzy teren w świecie gracza. Nazwa może zawierać spacje.

  • /teren usun <nazwa> usuwa teren, a /teren reload przeładowuje config i zapisane tereny.

  • Gracze widzą bossbar tylko na terenie. Domyślnie granice sprawdzają X/Z, więc przykładowe współrzędne z Y równym 0 działają na każdej wysokości. Ustaw region.check-y: true, aby uwzględniać też Y.

  • Uprawnienie, nazwy podkomend, wiadomości, tekst bossbara i mapowanie kolorów można zmienić w src/main/resources/config.yml. Tereny zapisują się w tym samym pliku.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 452
src/main/java/pl/zentrix/tereny/ZentrixTerenyPlugin.java
package pl.zentrix.tereny;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;

public final class ZentrixTerenyPlugin extends JavaPlugin implements Listener, CommandExecutor, TabCompleter {
    private final Map<String, Territory> territories = new LinkedHashMap<>();
    private final Map<UUID, String> activeTerritories = new HashMap<>();
    private final Map<UUID, BossBar> bossBars = new HashMap<>();

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadTerritories();
        getServer().getPluginManager().registerEvents(this, this);
        if (getCommand("teren") != null) {
            getCommand("teren").setExecutor(this);
            getCommand("teren").setTabCompleter(this);
        }
    }

    @Override
    public void onDisable() {
        bossBars.values().forEach(BossBar::removeAll);
        bossBars.clear();
        activeTerritories.clear();
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length == 0) {
            sendMessage(sender, "unknown-command", Map.of());
            return true;
        }

        String permission = getConfig().getString("permission", "zentrix.tereny.admin");
        if (!permission.isEmpty() && !sender.hasPermission(permission)) {
            sendMessage(sender, "no-permission", Map.of());
            return true;
        }

        String setCommand = getConfig().getString("commands.set", "ustaw");
        String removeCommand = getConfig().getString("commands.remove", "usun");
        String reloadCommand = getConfig().getString("commands.reload", "reload");

        if (args[0].equalsIgnoreCase(reloadCommand)) {
            reloadConfig();
            loadTerritories();
            refreshOnlinePlayers();
            sendMessage(sender, "reloaded", Map.of());
            return true;
        }

        if (args[0].equalsIgnoreCase(setCommand)) {
            createTerritory(sender, args);
            return true;
        }

        if (args[0].equalsIgnoreCase(removeCommand)) {
            removeTerritory(sender, args);
            return true;
        }

        sendMessage(sender, "unknown-command", Map.of());
        return true;
    }

    private void createTerritory(CommandSender sender, String[] args) {
        if (!(sender instanceof Player player)) {
            sendMessage(sender, "player-only", Map.of());
            return;
        }
        if (args.length < 9) {
            sendMessage(sender, "usage-set", Map.of());
            return;
        }

        int x1;
        int y1;
        int z1;
        int x2;
        int y2;
        int z2;
        try {
            x1 = Integer.parseInt(args[1]);
            y1 = Integer.parseInt(args[2]);
            z1 = Integer.parseInt(args[3]);
            x2 = Integer.parseInt(args[4]);
            y2 = Integer.parseInt(args[5]);
            z2 = Integer.parseInt(args[6]);
        } catch (NumberFormatException exception) {
            sendMessage(sender, "invalid-coordinates", Map.of());
            return;
        }

        BarColor barColor = resolveBarColor(args[7]);
        if (barColor == null) {
            sendMessage(sender, "invalid-color", Map.of());
            return;
        }

        String name = String.join(" ", java.util.Arrays.copyOfRange(args, 8, args.length));
        if (name.isBlank()) {
            sendMessage(sender, "usage-set", Map.of());
            return;
        }

        String id = UUID.randomUUID().toString();
        Territory territory = new Territory(id, name, player.getWorld().getName(),
                Math.min(x1, x2), Math.max(x1, x2), Math.min(y1, y2), Math.max(y1, y2),
                Math.min(z1, z2), Math.max(z1, z2), args[7]);
        territories.put(id, territory);
        saveTerritory(territory);
        refreshOnlinePlayers();

        sendMessage(sender, "region-created", Map.of("name", name, "world", territory.world));
    }

    private void removeTerritory(CommandSender sender, String[] args) {
        if (args.length < 2) {
            sendMessage(sender, "usage-remove", Map.of());
            return;
        }

        String name = String.join(" ", java.util.Arrays.copyOfRange(args, 1, args.length));
        Territory found = territories.values().stream()
                .filter(territory -> territory.name.equalsIgnoreCase(name))
                .findFirst()
                .orElse(null);
        if (found == null) {
            sendMessage(sender, "region-not-found", Map.of("name", name));
            return;
        }

        territories.remove(found.id);
        getConfig().set("regions." + found.id, null);
        saveConfig();
        refreshOnlinePlayers();
        sendMessage(sender, "region-removed", Map.of("name", found.name));
    }

    private void saveTerritory(Territory territory) {
        String path = "regions." + territory.id + ".";
        getConfig().set(path + "name", territory.name);
        getConfig().set(path + "world", territory.world);
        getConfig().set(path + "x1", territory.minX);
        getConfig().set(path + "x2", territory.maxX);
        getConfig().set(path + "y1", territory.minY);
        getConfig().set(path + "y2", territory.maxY);
        getConfig().set(path + "z1", territory.minZ);
        getConfig().set(path + "z2", territory.maxZ);
        getConfig().set(path + "color", territory.color);
        saveConfig();
    }

    private void loadTerritories() {
        bossBars.values().forEach(BossBar::removeAll);
        bossBars.clear();
        activeTerritories.clear();
        territories.clear();
        ConfigurationSection section = getConfig().getConfigurationSection("regions");
        if (section == null) {
            return;
        }

        for (String id : section.getKeys(false)) {
            ConfigurationSection data = section.getConfigurationSection(id);
            if (data == null) {
                continue;
            }
            String name = data.getString("name");
            String world = data.getString("world");
            if (name == null || world == null) {
                continue;
            }
            territories.put(id, new Territory(id, name, world,