From 33fe58603399e6d6528078526b26f381f13d0b3b Mon Sep 17 00:00:00 2001 From: jakub Date: Tue, 3 Mar 2026 13:35:46 +0100 Subject: [PATCH] island expansion --- pom.xml | 2 - .../xyz/soukup/ecoCraftCore/EcoCraftCore.java | 4 +- .../{FakeWater.java => ChunkModifier.java} | 89 ++++---- .../islands/DatabaseIslandLoader.java | 2 + .../ecoCraftCore/islands/IslandCommand.java | 79 ++++++- .../ecoCraftCore/islands/IslandManager.java | 198 ++++++++++++++++-- .../soukup/ecoCraftCore/utilities/PDC.java | 18 +- 7 files changed, 312 insertions(+), 80 deletions(-) rename src/main/java/xyz/soukup/ecoCraftCore/islands/{FakeWater.java => ChunkModifier.java} (72%) diff --git a/pom.xml b/pom.xml index 1785a65..ab470a8 100644 --- a/pom.xml +++ b/pom.xml @@ -108,8 +108,6 @@ https://jitpack.io - diff --git a/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java b/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java index 0342f8d..4cf19e7 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java @@ -41,7 +41,7 @@ import java.util.logging.Logger; import com.github.retrooper.packetevents.PacketEvents; -import xyz.soukup.ecoCraftCore.islands.FakeWater; +import xyz.soukup.ecoCraftCore.islands.ChunkModifier; public final class EcoCraftCore extends JavaPlugin { @@ -227,7 +227,7 @@ public final class EcoCraftCore extends JavaPlugin { EventManager events = PacketEvents.getAPI().getEventManager(); - events.registerListener(new FakeWater(this), PacketListenerPriority.NORMAL); + events.registerListener(new ChunkModifier(this), PacketListenerPriority.NORMAL); } } diff --git a/src/main/java/xyz/soukup/ecoCraftCore/islands/FakeWater.java b/src/main/java/xyz/soukup/ecoCraftCore/islands/ChunkModifier.java similarity index 72% rename from src/main/java/xyz/soukup/ecoCraftCore/islands/FakeWater.java rename to src/main/java/xyz/soukup/ecoCraftCore/islands/ChunkModifier.java index cd9fff6..0a333a1 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/islands/FakeWater.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/islands/ChunkModifier.java @@ -23,17 +23,16 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.BitSet; import java.util.Arrays; +import java.util.HashMap; -public class FakeWater implements PacketListener { - private static final int FALLBACK_WATER_STATE_ID_1_21_1 = 12015; +public class ChunkModifier implements PacketListener { private final JavaPlugin plugin; private final NamespacedKey keyX1, keyX2, keyZ1, keyZ2, keyType; - // Resolved once (reflection), cached afterwards - private volatile Integer cachedWaterStateId; + HashMap blockStates = new HashMap<>(); - public FakeWater(JavaPlugin plugin) { + public ChunkModifier(JavaPlugin plugin) { this.plugin = plugin; this.keyX1 = new NamespacedKey(plugin, "borderx1"); this.keyX2 = new NamespacedKey(plugin, "borderx2"); @@ -53,7 +52,21 @@ public class FakeWater implements PacketListener { PersistentDataContainer pdc = world.getPersistentDataContainer(); String type = pdc.get(keyType, PersistentDataType.STRING); - if (!"flat_grass".equals(type)) return; + + String block; + + switch (type){ + case "flat_grass": + case "flat_sand": + block = "WATER"; + break; + case "flat_hell": + block = "LAVA"; + break; + default: + return; + + } Integer x1 = pdc.get(keyX1, PersistentDataType.INTEGER); Integer x2 = pdc.get(keyX2, PersistentDataType.INTEGER); @@ -75,12 +88,11 @@ public class FakeWater implements PacketListener { int chunkZ = original.getZ(); if (chunkX >= minCX && chunkX <= maxCX && chunkZ >= minCZ && chunkZ <= maxCZ) return; - Column fake = createFakeWaterColumn(world, original, resolveWaterStateId()); - if (fake == null) return; + Column ghostColumn = createGhostColumn(world, original, resolveBlockStateID(block)); + if (ghostColumn == null) return; - wrapper.setColumn(fake); + wrapper.setColumn(ghostColumn); - // Force full-bright lighting for fake chunks to avoid "goes dark after radius" wrapper.setLightData(buildFullBrightLightData(world)); } @@ -88,16 +100,14 @@ public class FakeWater implements PacketListener { int sections = (world.getMaxHeight() - world.getMinHeight()) >> 4; if (sections <= 0) sections = 24; - // 1.17+ light data uses sectionCount + 2 (one below min, one above max) int lightCount = sections + 2; - // Each light array entry is 16*16*16 nibbles = 4096 nibbles = 2048 bytes byte[] fullSky = new byte[2048]; - Arrays.fill(fullSky, (byte) 0xFF); // 0xF in every nibble => light level 15 + Arrays.fill(fullSky, (byte) 0xFF); + + byte[] noBlock = new byte[2048]; - byte[] noBlock = new byte[2048]; // default 0 => block light 0 - // If your dimension can ever be no-skylight, handle it: boolean hasSkyLight = world.getEnvironment() != World.Environment.NETHER && world.getEnvironment() != World.Environment.THE_END; // adjust if you have custom dims @@ -142,7 +152,7 @@ public class FakeWater implements PacketListener { return ld; } - private Column createFakeWaterColumn(World world, Column original, int waterStateId) { + private Column createGhostColumn(World world, Column original, int blockID) { int sections = (world.getMaxHeight() - world.getMinHeight()) >> 4; if (sections <= 0) sections = 24; @@ -178,12 +188,11 @@ public class FakeWater implements PacketListener { chunks[sectionIndex] = section; } - // Section 0 == world Y -64..-49. Set only local y=0 and y=1 to water. if (chunks[0] instanceof Chunk_v1_18 section0) { for (int localY = 0; localY <= 1; localY++) { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { - section0.set(x, localY, z, waterStateId); + section0.set(x, localY, z, blockID); } } } @@ -199,35 +208,31 @@ public class FakeWater implements PacketListener { ); } - private int resolveWaterStateId() { - Integer cached = cachedWaterStateId; - if (cached != null) return cached; + private int resolveBlockStateID(String name) { + Integer stateID = blockStates.get(name); + if (stateID != null) return stateID; - int resolved = FALLBACK_WATER_STATE_ID_1_21_1; + int resolved = 0; try { - Object waterState = resolveNmsWaterBlockState(); - if (waterState != null) { - Integer id = tryGetBlockStateIdViaBlockGetId(waterState); - if (id == null) { - id = tryGetBlockStateIdViaBuiltInRegistry(waterState); - } + Object blockState = resolveNmsBlockState(name); + if (blockState != null) { + Integer id = tryGetBlockStateIdViaBlockGetId(blockState); if (id != null && id > 0) { resolved = id; } } } catch (ReflectiveOperationException ignored) { - // fallback + } - cachedWaterStateId = resolved; - plugin.getLogger().info("[FakeWater] Using water block-state id: " + resolved); + blockStates.put(name, resolved); return resolved; } - private static Object resolveNmsWaterBlockState() throws ReflectiveOperationException { + private static Object resolveNmsBlockState(String name) throws ReflectiveOperationException { Class blocksClass = Class.forName("net.minecraft.world.level.block.Blocks"); - Field waterField = blocksClass.getField("WATER"); + Field waterField = blocksClass.getField(name); Object waterBlock = waterField.get(null); Method defaultBlockState = waterBlock.getClass().getMethod("defaultBlockState"); @@ -248,22 +253,4 @@ public class FakeWater implements PacketListener { } } - private static Integer tryGetBlockStateIdViaBuiltInRegistry(Object blockState) throws ReflectiveOperationException { - Class blockStateClass = Class.forName("net.minecraft.world.level.block.state.BlockState"); - Class builtInRegistriesClass = Class.forName("net.minecraft.core.registries.BuiltInRegistries"); - - Field blockStateRegistryField = builtInRegistriesClass.getField("BLOCK_STATE"); - Object blockStateRegistry = blockStateRegistryField.get(null); - - Method getId = blockStateRegistry.getClass().getMethod("getId", Object.class); - try { - // Prefer exact signature if present: getId(BlockState) - Method exact = blockStateRegistry.getClass().getMethod("getId", blockStateClass); - Object idObj = exact.invoke(blockStateRegistry, blockState); - return (idObj instanceof Integer i) ? i : null; - } catch (NoSuchMethodException ignored) { - Object idObj = getId.invoke(blockStateRegistry, blockState); - return (idObj instanceof Integer i) ? i : null; - } - } } diff --git a/src/main/java/xyz/soukup/ecoCraftCore/islands/DatabaseIslandLoader.java b/src/main/java/xyz/soukup/ecoCraftCore/islands/DatabaseIslandLoader.java index d6b0f26..93c8b6e 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/islands/DatabaseIslandLoader.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/islands/DatabaseIslandLoader.java @@ -38,6 +38,8 @@ public class DatabaseIslandLoader implements SlimeLoader { .setCountOf(true) .where() .eq("uuid", worldName) + .and() + .isNotNull("data") .countOf(); return count > 0; diff --git a/src/main/java/xyz/soukup/ecoCraftCore/islands/IslandCommand.java b/src/main/java/xyz/soukup/ecoCraftCore/islands/IslandCommand.java index 2c0cd2e..8589957 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/islands/IslandCommand.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/islands/IslandCommand.java @@ -3,18 +3,22 @@ package xyz.soukup.ecoCraftCore.islands; import com.infernalsuite.asp.api.AdvancedSlimePaperAPI; import com.infernalsuite.asp.api.world.SlimeWorld; import com.j256.ormlite.stmt.QueryBuilder; +import com.mojang.brigadier.Message; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.Commands; +import net.kyori.adventure.text.Component; +import org.bukkit.Location; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import xyz.soukup.ecoCraftCore.database.DaoRegistry; import xyz.soukup.ecoCraftCore.database.objects.Island; +import xyz.soukup.ecoCraftCore.messages.Messages; import java.io.IOException; import java.sql.SQLException; @@ -23,9 +27,12 @@ import java.util.List; import static xyz.soukup.ecoCraftCore.EcoCraftCore.plugin; public class IslandCommand { + private final AdvancedSlimePaperAPI asp = AdvancedSlimePaperAPI.instance(); + public static LiteralArgumentBuilder createCommand() { + LiteralArgumentBuilder tp = Commands.literal("tp") .then(Commands.argument("uuid", StringArgumentType.word()) .executes(IslandCommand::teleport) @@ -45,6 +52,18 @@ public class IslandCommand { LiteralArgumentBuilder create = Commands.literal("create") .then(Commands.argument("type", StringArgumentType.word()) + .suggests(((context, builder) -> { + try { + IslandManager islandManager = new IslandManager(); + FileIslandLoader fileLoader = islandManager.fileLoader; + for (String world: fileLoader.listWorlds()){ + builder.suggest(world); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + return builder.buildFuture(); + })) .then(Commands.argument("display_name", StringArgumentType.string()) .then(Commands.argument("description", StringArgumentType.greedyString()) .executes(IslandCommand::createWorld)))); @@ -111,10 +130,26 @@ public class IslandCommand { .then(Commands.argument("value", StringArgumentType.string()) .executes(IslandCommand::setMetadataString))); - // NEW: Branch to read all metadata + LiteralArgumentBuilder expand = Commands.literal("expand") + .then(Commands.argument("lenght", IntegerArgumentType.integer()) + .executes(IslandCommand::expandIsland)); + LiteralArgumentBuilder listMetadata = Commands.literal("listMetadata") .executes(IslandCommand::readAllMetadata); + LiteralArgumentBuilder spawn = Commands.literal("spawn") + .executes(IslandCommand::setSpawn); + + LiteralArgumentBuilder enviroment = Commands.literal("environment") + .then(Commands.argument("environment", StringArgumentType.word()) + .executes(IslandCommand::setEnvironment) + .suggests(((context, builder) -> { + builder.suggest("normal"); + builder.suggest("nether"); + builder.suggest("the_end"); + return builder.buildFuture(); + }))); + return Commands.literal("island") .then(tp) .then(create) @@ -123,10 +158,36 @@ public class IslandCommand { .then(metadata) .then(metadataString) .then(listMetadata) - .then(loadTemplate); + .then(loadTemplate) + .then(spawn) + .then(enviroment) + .then(expand); + + + } + + private static int setSpawn(CommandContext context) { + if (!(context.getSource().getSender() instanceof Player player)) return 0; + IslandManager islandManager = new IslandManager(); + Location spawn = player.getLocation(); + String uuid = player.getWorld().getName(); + islandManager.changeSpawn(spawn, uuid); + Messages.send(player, "island.setSpawn.success"); + + return 0; + } + + private static int setEnvironment(CommandContext context) { + if (!(context.getSource().getSender() instanceof Player player)) return 0; + IslandManager islandManager = new IslandManager(); + String uuid = player.getWorld().getName(); + islandManager.changeEnviroment(context.getArgument("environment", String.class), uuid); + Messages.send(player, "island.setEnvironment.success"); + return 0; } + private static int teleport(CommandContext context) { IslandManager islandManager = new IslandManager(); try { @@ -216,6 +277,20 @@ public class IslandCommand { return 1; } + private static int expandIsland(CommandContext context){ + + Player player = (Player) context.getSource().getSender(); + float yaw = player.getLocation().getYaw(); + int lenght = IntegerArgumentType.getInteger(context, "lenght"); + String uuid = player.getWorld().getName(); + + IslandManager islandManager = new IslandManager(); + islandManager.expandIsland(yaw, lenght, uuid); + + + return 0; + } + private static void saveSlimeWorld(SlimeWorld world, Player player, String key, String val) { try { AdvancedSlimePaperAPI.instance().saveWorld(world); diff --git a/src/main/java/xyz/soukup/ecoCraftCore/islands/IslandManager.java b/src/main/java/xyz/soukup/ecoCraftCore/islands/IslandManager.java index aae1ff3..9cbaec9 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/islands/IslandManager.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/islands/IslandManager.java @@ -14,13 +14,14 @@ import com.j256.ormlite.dao.Dao; import com.j256.ormlite.dao.GenericRawResults; import com.j256.ormlite.stmt.QueryBuilder; import com.j256.ormlite.stmt.UpdateBuilder; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.entity.Player; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; import xyz.soukup.ecoCraftCore.database.objects.Island; import xyz.soukup.ecoCraftCore.database.DaoRegistry; import xyz.soukup.ecoCraftCore.database.objects.TeleportRequest; +import xyz.soukup.ecoCraftCore.utilities.PDC; import java.io.IOException; import java.sql.SQLException; @@ -54,27 +55,32 @@ public class IslandManager { try { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { try { - SlimePropertyMap props = new SlimePropertyMap(); - props.setValue(SlimeProperties.ENVIRONMENT, "normal"); - props.setValue(SlimeProperties.WORLD_TYPE, "flat"); - props.setValue(SlimeProperties.ALLOW_ANIMALS, false); - props.setValue(SlimeProperties.ALLOW_MONSTERS, false); - props.setValue(SlimeProperties.SPAWN_X, 0); - props.setValue(SlimeProperties.SPAWN_Y, 2); - props.setValue(SlimeProperties.SPAWN_Z, 0); - - + SlimeWorld slimeWorld; Island island = new Island(type, uuid, displayName, descritpion, owner, ownerType, null); island.save(); - SlimeWorld slimeWorld; + if (fileLoader.worldExists(type)){ + slimeWorld = asp.readWorld(fileLoader, type, false, new SlimePropertyMap()).clone(uuid, databaseLoader); + asp.saveWorld(slimeWorld); - slimeWorld = asp.createEmptyWorld(uuid, false, props, databaseLoader); + }else { + SlimePropertyMap props = new SlimePropertyMap(); + props.setValue(SlimeProperties.ENVIRONMENT, "normal"); + props.setValue(SlimeProperties.WORLD_TYPE, "flat"); + props.setValue(SlimeProperties.ALLOW_ANIMALS, false); + props.setValue(SlimeProperties.ALLOW_MONSTERS, false); + props.setValue(SlimeProperties.SPAWN_X, 0); + props.setValue(SlimeProperties.SPAWN_Y, 2); + props.setValue(SlimeProperties.SPAWN_Z, 0); - asp.saveWorld(slimeWorld); + slimeWorld = asp.createEmptyWorld(uuid, false, props, databaseLoader); + asp.saveWorld(slimeWorld); + + } + } catch (Exception e) { e.printStackTrace(); } }); } catch (Exception e) { e.printStackTrace(); } @@ -227,6 +233,166 @@ public class IslandManager { return future; } + + public void changeSpawn(Location location, String uuid) { + SlimeWorld slimeWorld = asp.getLoadedWorld(uuid); + SlimePropertyMap slimePropertyMap = slimeWorld.getPropertyMap(); + slimePropertyMap.setValue(SlimeProperties.SPAWN_X, location.getBlockX()); + slimePropertyMap.setValue(SlimeProperties.SPAWN_Y, location.getBlockY()); + slimePropertyMap.setValue(SlimeProperties.SPAWN_Z, location.getBlockZ()); + + try { + asp.saveWorld(slimeWorld); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public void changeEnviroment( String environment, String uuid) { + SlimeWorld slimeWorld = asp.getLoadedWorld(uuid); + SlimePropertyMap slimePropertyMap = slimeWorld.getPropertyMap(); + slimePropertyMap.setValue(SlimeProperties.ENVIRONMENT, environment); + + try { + asp.saveWorld(slimeWorld); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public void expandIsland(float yaw, int lenght, String uuid){ + World world = Bukkit.getWorld(uuid); + + if (world == null){ + return; + } + + String islandType = (String) PDC.getUniversal(world, "island_type", PersistentDataType.STRING); + switch (islandType){ + case "flat_grass" -> flatExpander(world, yaw, lenght, Material.GRASS_BLOCK, Material.STONE, Material.WATER); + case "flat_sand" -> flatExpander(world, yaw, lenght, Material.SAND, Material.STONE, Material.WATER); + case "flat_hell" -> flatExpander(world, yaw, lenght, Material.SOUL_SOIL, Material.NETHERRACK, Material.LAVA); + + + } + + + } + + public void flatExpander(World world, float yaw, int lenght, Material surface, Material base, Material surrounding){ + + int x1 = (int) PDC.getUniversal(world, "borderx1", PersistentDataType.INTEGER); + int x2 = (int) PDC.getUniversal(world, "borderx2", PersistentDataType.INTEGER); + int z1 = (int) PDC.getUniversal(world, "bordery1", PersistentDataType.INTEGER); + int z2 = (int) PDC.getUniversal(world, "bordery2", PersistentDataType.INTEGER); + int y = world.getMinHeight(); + + + float yawNormalized = yaw % 360f; + if (yawNormalized < 0) yawNormalized += 360f; + + int quadrant = Math.round(yawNormalized / 90.0f) & 3; + + + int xMin; + int xMax; + int zMin; + int zMax; + + switch (quadrant) { + case 0: + //+Z + xMin = Math.min(x1, x2); + xMax = Math.max(x1, x2); + zMin = Math.max(z1, z2); + zMax = zMin + lenght; + z2 = Math.min(z1, z2); + z1 = zMax; + + break; + case 1: + //-X + zMin = Math.min(z1, z2); + zMax = Math.max(z1, z2); + xMax = Math.min(x1, x2); + xMin = xMax - lenght; + x2 = Math.max(x1, x2); + x1 = xMin; + + break; + case 2: + //-Z + xMin = Math.min(x1, x2); + xMax = Math.max(x1, x2); + zMax = Math.min(z1, z2); + zMin = zMax - lenght; + z2 = Math.max(z1, z2); + z1 = zMin; + + break; + default: + //+X + zMin = Math.min(z1, z2); + zMax = Math.max(z1, z2); + xMin = Math.max(x1, x2); + xMax = xMin + lenght; + x2 = Math.min(x1, x2); + x1 = xMax; + + break; + + } + + for (int x = xMin; x < (xMax + 1); x++) { + for (int z = zMin; z < (zMax + 1); z++) { + world.setType(x, y, z, base); + world.setType(x, y+1, z, base); + + if (((quadrant == 0 || quadrant == 2) && (x == xMin || x == xMax)) + || ((quadrant == 1 || quadrant == 3) && (z == zMin || z == zMax))) { + continue; + } + + if ((quadrant == 0 && z == zMax) + || (quadrant == 1 && x == xMin) + || (quadrant == 2 && z == zMin) + || (quadrant == 3 && x == xMax)){ + continue; + } + + world.setType(x, y+2, z, surface); + } + } + + PDC.setUniversal(world, "borderx1", x1, PersistentDataType.INTEGER); + PDC.setUniversal(world, "borderx2", x2, PersistentDataType.INTEGER); + PDC.setUniversal(world, "bordery1", z1, PersistentDataType.INTEGER); + PDC.setUniversal(world, "bordery2", z2, PersistentDataType.INTEGER); + + int chunkMaxX = ((Math.max(x1, x2) + 15) & ~15) + 16; + int chunkMinX = (Math.min(x1, x2) & ~15) - 16; + int chunkMaxZ = ((Math.max(z1, z2) + 15) & ~15) + 16; + int chunkMinZ = (Math.min(z1, z2) & ~15) - 16; + + xMin = Math.min(x1, x2); + xMax = Math.max(x1, x2); + zMin = Math.min(z1, z2); + zMax = Math.max(z1, z2); + + for (int x = chunkMinX; x < chunkMaxX + 1; x ++) { + for (int z = chunkMinZ; z < chunkMaxZ + 1; z ++) { + if ((x >= xMin && x <= xMax) && (z >= zMin && z <= zMax)) { + continue; + } + world.setType(x, y, z, surrounding); + world.setType(x, y+1, z, surrounding); + } + } + ; + } + + + private String getEmptiestServer() throws Exception { String query = "SELECT active_servers.name " + diff --git a/src/main/java/xyz/soukup/ecoCraftCore/utilities/PDC.java b/src/main/java/xyz/soukup/ecoCraftCore/utilities/PDC.java index 0d14c28..a79c19e 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/utilities/PDC.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/utilities/PDC.java @@ -9,11 +9,15 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataHolder; import org.bukkit.persistence.PersistentDataType; +import xyz.soukup.ecoCraftCore.EcoCraftCore; + +import static xyz.soukup.ecoCraftCore.EcoCraftCore.plugin; @SuppressWarnings({"unchecked", "rawtypes"}) public class PDC { - - + + + //TileState public static void set(TileState tileState, String key, Integer value){ @@ -65,7 +69,7 @@ public class PDC { return (String) get(itemStack, key, PersistentDataType.STRING); } - private static Object get(ItemStack itemStack, String key, PersistentDataType persistentDataType){ + public static Object get(ItemStack itemStack, String key, PersistentDataType persistentDataType){ ItemMeta itemMeta = itemStack.getItemMeta(); return getUniversal(itemMeta, key, persistentDataType); } @@ -80,15 +84,15 @@ public class PDC { //Univerzální set & get - private static Object getUniversal(PersistentDataHolder persistentDataHolder, String key, PersistentDataType persistentDataType){ + public static Object getUniversal(PersistentDataHolder persistentDataHolder, String key, PersistentDataType persistentDataType){ PersistentDataContainer persistentDataContainer = persistentDataHolder.getPersistentDataContainer(); - NamespacedKey namespacedKey = new NamespacedKey("ecc", key); + NamespacedKey namespacedKey = new NamespacedKey(plugin, key); return persistentDataContainer.get(namespacedKey, persistentDataType); } - private static void setUniversal(PersistentDataHolder persistentDataHolder, String key, Object value, PersistentDataType persistentDataType){ + public static void setUniversal(PersistentDataHolder persistentDataHolder, String key, Object value, PersistentDataType persistentDataType){ PersistentDataContainer persistentDataContainer = persistentDataHolder.getPersistentDataContainer(); - NamespacedKey namespacedKey = new NamespacedKey("ecc", key); + NamespacedKey namespacedKey = new NamespacedKey(plugin, key); persistentDataContainer.set(namespacedKey, persistentDataType, value); }