Lukaszpp Janusz

stwórz mi mape na której widac gdzie są skrzynie i spawnery

Kodari AI
KodariNov 11 at 7:16 pm 1
MapVisualizer
Generates an interactive map image showing the locations of all chests and spawners in the Minecraft world. The plugin scans loaded chunks for chest blocks and spawner blocks, records their coordinates, and renders a top-down map visualization with distinct markers for each block type. Players can view the map via command, with options to filter by block type, zoom level, and world dimension. The map is saved as a PNG file in the plugin folder and can be refreshed on demand. Supports multiple worlds and provides a legend showing marker colors for chests and spawners.
  1. Dodam /lokator, który tworzy mapę w ekwipunku.

  2. Mapa zaznaczy skrzynie i spawnery z załadowanych chunków w promieniu 64 bloków.

  3. Dodam konfigurację komendy i projektu pluginu.

Utworzyłem plugin z komendą /lokator. Daje ona mapę skrzyń i spawnerów w promieniu 64 bloków; mapa uwzględnia tylko załadowane chunki w pobliżu gracza.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 234
src/main/java/com/kodari/locator/ChestSpawnerMapPlugin.java
package com.kodari.locator;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MapMeta;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.List;

public final class ChestSpawnerMapPlugin extends JavaPlugin implements CommandExecutor {
    private static final int MAP_MIN_OFFSET = -64;
    private static final int MAP_MAX_OFFSET = 63;
    private static final int CHUNK_SCAN_DISTANCE = 5;

    @Override
    public void onEnable() {
        getCommand("lokator").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage(ChatColor.RED + "Tej komendy może użyć tylko gracz.");
            return true;
        }

        if (player.getInventory().firstEmpty() == -1) {
            player.sendMessage(ChatColor.RED + "Zrób miejsce w ekwipunku na mapę.");
            return true;
        }

        Location playerLocation = player.getLocation();
        int centerX = playerLocation.getBlockX();
        int centerZ = playerLocation.getBlockZ();
        List<LocatorMapRenderer.Marker> markers = findMarkers(player.getWorld(), centerX, centerZ);

        MapView mapView = Bukkit.createMap(player.getWorld());
        mapView.setCenterX(centerX);
        mapView.setCenterZ(centerZ);
        mapView.setScale(MapView.Scale.NORMAL);
        mapView.setTrackingPosition(false);
        mapView.setUnlimitedTracking(false);
        mapView.setLocked(true);
        for (MapRenderer renderer : mapView.getRenderers()) {
            mapView.removeRenderer(renderer);
        }
        mapView.addRenderer(new LocatorMapRenderer(centerX, centerZ, markers));

        ItemStack mapItem = XMaterial.matchXMaterial("FILLED_MAP")
                .map(XMaterial::parseItem)
                .orElse(null);
        if (mapItem == null || !(mapItem.getItemMeta() instanceof MapMeta mapMeta)) {
            player.sendMessage(ChatColor.RED + "Nie udało się utworzyć mapy.");
            return true;
        }

        mapMeta.setMapView(mapView);
        mapMeta.setDisplayName(ChatColor.GOLD + "Lokator skrzyń i spawnerów");
        mapMeta.setLore(List.of(
                ChatColor.YELLOW + "Pomarańczowy: skrzynia",
                ChatColor.LIGHT_PURPLE + "Fioletowy: spawner",
                ChatColor.GRAY + "Zasięg: 64 bloki"
        ));
        mapItem.setItemMeta(mapMeta);
        player.getInventory().addItem(mapItem);
        player.sendMessage(ChatColor.GREEN + "Otrzymujesz mapę lokatora. "
                + ChatColor.GRAY + "Pokazuje obiekty w promieniu 64 bloków, w załadowanych chunkach.");
        return true;
    }

    private List<LocatorMapRenderer.Marker> findMarkers(World world, int centerX, int centerZ) {
        List<LocatorMapRenderer.Marker> markers = new ArrayList<>();
        for (Chunk chunk : world.getLoadedChunks()) {
            if (Math.abs(chunk.getX() - (centerX >> 4)) > CHUNK_SCAN_DISTANCE
                    || Math.abs(chunk.getZ() - (centerZ >> 4)) > CHUNK_SCAN_DISTANCE) {
                continue;
            }

            for (BlockState state : chunk.getTileEntities()) {
                LocatorMapRenderer.MarkerType type;
                if (state instanceof CreatureSpawner) {
                    type = LocatorMapRenderer.MarkerType.SPAWNER;
                } else if (state instanceof Chest) {
                    type = LocatorMapRenderer.MarkerType.CHEST;
                } else {
                    continue;
                }

                Location location = state.getLocation();
                int offsetX = location.getBlockX() - centerX;
                int offsetZ = location.getBlockZ() - centerZ;
                if (offsetX < MAP_MIN_OFFSET || offsetX > MAP_MAX_OFFSET
                        || offsetZ < MAP_MIN_OFFSET || offsetZ > MAP_MAX_OFFSET) {
                    continue;
                }
                markers.add(new LocatorMapRenderer.Marker(location.getBlockX(), location.getBlockZ(), type));
            }
        }
        return markers;
    }
}