island expansion

island-experimenty
jakub 3 weeks ago
parent 67d0ec7def
commit 33fe586033
  1. 2
      pom.xml
  2. 4
      src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java
  3. 89
      src/main/java/xyz/soukup/ecoCraftCore/islands/ChunkModifier.java
  4. 2
      src/main/java/xyz/soukup/ecoCraftCore/islands/DatabaseIslandLoader.java
  5. 79
      src/main/java/xyz/soukup/ecoCraftCore/islands/IslandCommand.java
  6. 186
      src/main/java/xyz/soukup/ecoCraftCore/islands/IslandManager.java
  7. 14
      src/main/java/xyz/soukup/ecoCraftCore/utilities/PDC.java

@ -108,8 +108,6 @@
<url>https://jitpack.io</url> <url>https://jitpack.io</url>
</repository> </repository>
<!-- PacketEvents is commonly consumed via CodeMC. If this repo isn't in your environment,
tell me and I’ll give you the exact repo you prefer (jitpack/shade/plugin). -->
</repositories> </repositories>

@ -41,7 +41,7 @@ import java.util.logging.Logger;
import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.PacketEvents;
import xyz.soukup.ecoCraftCore.islands.FakeWater; import xyz.soukup.ecoCraftCore.islands.ChunkModifier;
public final class EcoCraftCore extends JavaPlugin { public final class EcoCraftCore extends JavaPlugin {
@ -227,7 +227,7 @@ public final class EcoCraftCore extends JavaPlugin {
EventManager events = PacketEvents.getAPI().getEventManager(); EventManager events = PacketEvents.getAPI().getEventManager();
events.registerListener(new FakeWater(this), PacketListenerPriority.NORMAL); events.registerListener(new ChunkModifier(this), PacketListenerPriority.NORMAL);
} }
} }

@ -23,17 +23,16 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.BitSet; import java.util.BitSet;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
public class FakeWater implements PacketListener { public class ChunkModifier implements PacketListener {
private static final int FALLBACK_WATER_STATE_ID_1_21_1 = 12015;
private final JavaPlugin plugin; private final JavaPlugin plugin;
private final NamespacedKey keyX1, keyX2, keyZ1, keyZ2, keyType; private final NamespacedKey keyX1, keyX2, keyZ1, keyZ2, keyType;
// Resolved once (reflection), cached afterwards HashMap<String, Integer> blockStates = new HashMap<>();
private volatile Integer cachedWaterStateId;
public FakeWater(JavaPlugin plugin) { public ChunkModifier(JavaPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.keyX1 = new NamespacedKey(plugin, "borderx1"); this.keyX1 = new NamespacedKey(plugin, "borderx1");
this.keyX2 = new NamespacedKey(plugin, "borderx2"); this.keyX2 = new NamespacedKey(plugin, "borderx2");
@ -53,7 +52,21 @@ public class FakeWater implements PacketListener {
PersistentDataContainer pdc = world.getPersistentDataContainer(); PersistentDataContainer pdc = world.getPersistentDataContainer();
String type = pdc.get(keyType, PersistentDataType.STRING); 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 x1 = pdc.get(keyX1, PersistentDataType.INTEGER);
Integer x2 = pdc.get(keyX2, PersistentDataType.INTEGER); Integer x2 = pdc.get(keyX2, PersistentDataType.INTEGER);
@ -75,12 +88,11 @@ public class FakeWater implements PacketListener {
int chunkZ = original.getZ(); int chunkZ = original.getZ();
if (chunkX >= minCX && chunkX <= maxCX && chunkZ >= minCZ && chunkZ <= maxCZ) return; if (chunkX >= minCX && chunkX <= maxCX && chunkZ >= minCZ && chunkZ <= maxCZ) return;
Column fake = createFakeWaterColumn(world, original, resolveWaterStateId()); Column ghostColumn = createGhostColumn(world, original, resolveBlockStateID(block));
if (fake == null) return; 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)); wrapper.setLightData(buildFullBrightLightData(world));
} }
@ -88,16 +100,14 @@ public class FakeWater implements PacketListener {
int sections = (world.getMaxHeight() - world.getMinHeight()) >> 4; int sections = (world.getMaxHeight() - world.getMinHeight()) >> 4;
if (sections <= 0) sections = 24; if (sections <= 0) sections = 24;
// 1.17+ light data uses sectionCount + 2 (one below min, one above max)
int lightCount = sections + 2; int lightCount = sections + 2;
// Each light array entry is 16*16*16 nibbles = 4096 nibbles = 2048 bytes
byte[] fullSky = new byte[2048]; 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 boolean hasSkyLight = world.getEnvironment() != World.Environment.NETHER
&& world.getEnvironment() != World.Environment.THE_END; // adjust if you have custom dims && world.getEnvironment() != World.Environment.THE_END; // adjust if you have custom dims
@ -142,7 +152,7 @@ public class FakeWater implements PacketListener {
return ld; 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; int sections = (world.getMaxHeight() - world.getMinHeight()) >> 4;
if (sections <= 0) sections = 24; if (sections <= 0) sections = 24;
@ -178,12 +188,11 @@ public class FakeWater implements PacketListener {
chunks[sectionIndex] = section; 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) { if (chunks[0] instanceof Chunk_v1_18 section0) {
for (int localY = 0; localY <= 1; localY++) { for (int localY = 0; localY <= 1; localY++) {
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) { 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() { private int resolveBlockStateID(String name) {
Integer cached = cachedWaterStateId; Integer stateID = blockStates.get(name);
if (cached != null) return cached; if (stateID != null) return stateID;
int resolved = FALLBACK_WATER_STATE_ID_1_21_1; int resolved = 0;
try { try {
Object waterState = resolveNmsWaterBlockState(); Object blockState = resolveNmsBlockState(name);
if (waterState != null) { if (blockState != null) {
Integer id = tryGetBlockStateIdViaBlockGetId(waterState); Integer id = tryGetBlockStateIdViaBlockGetId(blockState);
if (id == null) {
id = tryGetBlockStateIdViaBuiltInRegistry(waterState);
}
if (id != null && id > 0) { if (id != null && id > 0) {
resolved = id; resolved = id;
} }
} }
} catch (ReflectiveOperationException ignored) { } catch (ReflectiveOperationException ignored) {
// fallback
} }
cachedWaterStateId = resolved; blockStates.put(name, resolved);
plugin.getLogger().info("[FakeWater] Using water block-state id: " + resolved);
return 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"); 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); Object waterBlock = waterField.get(null);
Method defaultBlockState = waterBlock.getClass().getMethod("defaultBlockState"); 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;
}
}
} }

@ -38,6 +38,8 @@ public class DatabaseIslandLoader implements SlimeLoader {
.setCountOf(true) .setCountOf(true)
.where() .where()
.eq("uuid", worldName) .eq("uuid", worldName)
.and()
.isNotNull("data")
.countOf(); .countOf();
return count > 0; return count > 0;

@ -3,18 +3,22 @@ package xyz.soukup.ecoCraftCore.islands;
import com.infernalsuite.asp.api.AdvancedSlimePaperAPI; import com.infernalsuite.asp.api.AdvancedSlimePaperAPI;
import com.infernalsuite.asp.api.world.SlimeWorld; import com.infernalsuite.asp.api.world.SlimeWorld;
import com.j256.ormlite.stmt.QueryBuilder; import com.j256.ormlite.stmt.QueryBuilder;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands; import io.papermc.paper.command.brigadier.Commands;
import net.kyori.adventure.text.Component;
import org.bukkit.Location;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import xyz.soukup.ecoCraftCore.database.DaoRegistry; import xyz.soukup.ecoCraftCore.database.DaoRegistry;
import xyz.soukup.ecoCraftCore.database.objects.Island; import xyz.soukup.ecoCraftCore.database.objects.Island;
import xyz.soukup.ecoCraftCore.messages.Messages;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
@ -23,9 +27,12 @@ import java.util.List;
import static xyz.soukup.ecoCraftCore.EcoCraftCore.plugin; import static xyz.soukup.ecoCraftCore.EcoCraftCore.plugin;
public class IslandCommand { public class IslandCommand {
private final AdvancedSlimePaperAPI asp = AdvancedSlimePaperAPI.instance();
public static LiteralArgumentBuilder<CommandSourceStack> createCommand() { public static LiteralArgumentBuilder<CommandSourceStack> createCommand() {
LiteralArgumentBuilder<CommandSourceStack> tp = Commands.literal("tp") LiteralArgumentBuilder<CommandSourceStack> tp = Commands.literal("tp")
.then(Commands.argument("uuid", StringArgumentType.word()) .then(Commands.argument("uuid", StringArgumentType.word())
.executes(IslandCommand::teleport) .executes(IslandCommand::teleport)
@ -45,6 +52,18 @@ public class IslandCommand {
LiteralArgumentBuilder<CommandSourceStack> create = Commands.literal("create") LiteralArgumentBuilder<CommandSourceStack> create = Commands.literal("create")
.then(Commands.argument("type", StringArgumentType.word()) .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("display_name", StringArgumentType.string())
.then(Commands.argument("description", StringArgumentType.greedyString()) .then(Commands.argument("description", StringArgumentType.greedyString())
.executes(IslandCommand::createWorld)))); .executes(IslandCommand::createWorld))));
@ -111,10 +130,26 @@ public class IslandCommand {
.then(Commands.argument("value", StringArgumentType.string()) .then(Commands.argument("value", StringArgumentType.string())
.executes(IslandCommand::setMetadataString))); .executes(IslandCommand::setMetadataString)));
// NEW: Branch to read all metadata LiteralArgumentBuilder<CommandSourceStack> expand = Commands.literal("expand")
.then(Commands.argument("lenght", IntegerArgumentType.integer())
.executes(IslandCommand::expandIsland));
LiteralArgumentBuilder<CommandSourceStack> listMetadata = Commands.literal("listMetadata") LiteralArgumentBuilder<CommandSourceStack> listMetadata = Commands.literal("listMetadata")
.executes(IslandCommand::readAllMetadata); .executes(IslandCommand::readAllMetadata);
LiteralArgumentBuilder<CommandSourceStack> spawn = Commands.literal("spawn")
.executes(IslandCommand::setSpawn);
LiteralArgumentBuilder<CommandSourceStack> 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") return Commands.literal("island")
.then(tp) .then(tp)
.then(create) .then(create)
@ -123,10 +158,36 @@ public class IslandCommand {
.then(metadata) .then(metadata)
.then(metadataString) .then(metadataString)
.then(listMetadata) .then(listMetadata)
.then(loadTemplate); .then(loadTemplate)
.then(spawn)
.then(enviroment)
.then(expand);
} }
private static int setSpawn(CommandContext<CommandSourceStack> 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<CommandSourceStack> 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<CommandSourceStack> context) { private static int teleport(CommandContext<CommandSourceStack> context) {
IslandManager islandManager = new IslandManager(); IslandManager islandManager = new IslandManager();
try { try {
@ -216,6 +277,20 @@ public class IslandCommand {
return 1; return 1;
} }
private static int expandIsland(CommandContext<CommandSourceStack> 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) { private static void saveSlimeWorld(SlimeWorld world, Player player, String key, String val) {
try { try {
AdvancedSlimePaperAPI.instance().saveWorld(world); AdvancedSlimePaperAPI.instance().saveWorld(world);

@ -14,13 +14,14 @@ import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.GenericRawResults; import com.j256.ormlite.dao.GenericRawResults;
import com.j256.ormlite.stmt.QueryBuilder; import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.UpdateBuilder; import com.j256.ormlite.stmt.UpdateBuilder;
import org.bukkit.Bukkit; import org.bukkit.*;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player; 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.objects.Island;
import xyz.soukup.ecoCraftCore.database.DaoRegistry; import xyz.soukup.ecoCraftCore.database.DaoRegistry;
import xyz.soukup.ecoCraftCore.database.objects.TeleportRequest; import xyz.soukup.ecoCraftCore.database.objects.TeleportRequest;
import xyz.soukup.ecoCraftCore.utilities.PDC;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
@ -54,6 +55,16 @@ public class IslandManager {
try { try {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try { try {
SlimeWorld slimeWorld;
Island island = new Island(type, uuid, displayName, descritpion, owner, ownerType, null);
island.save();
if (fileLoader.worldExists(type)){
slimeWorld = asp.readWorld(fileLoader, type, false, new SlimePropertyMap()).clone(uuid, databaseLoader);
asp.saveWorld(slimeWorld);
}else {
SlimePropertyMap props = new SlimePropertyMap(); SlimePropertyMap props = new SlimePropertyMap();
props.setValue(SlimeProperties.ENVIRONMENT, "normal"); props.setValue(SlimeProperties.ENVIRONMENT, "normal");
props.setValue(SlimeProperties.WORLD_TYPE, "flat"); props.setValue(SlimeProperties.WORLD_TYPE, "flat");
@ -63,17 +74,12 @@ public class IslandManager {
props.setValue(SlimeProperties.SPAWN_Y, 2); props.setValue(SlimeProperties.SPAWN_Y, 2);
props.setValue(SlimeProperties.SPAWN_Z, 0); props.setValue(SlimeProperties.SPAWN_Z, 0);
Island island = new Island(type, uuid, displayName, descritpion, owner, ownerType, null);
island.save();
SlimeWorld slimeWorld;
slimeWorld = asp.createEmptyWorld(uuid, false, props, databaseLoader); slimeWorld = asp.createEmptyWorld(uuid, false, props, databaseLoader);
asp.saveWorld(slimeWorld); asp.saveWorld(slimeWorld);
}
} catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); }
}); });
@ -228,6 +234,166 @@ public class IslandManager {
return future; 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 { private String getEmptiestServer() throws Exception {
String query = "SELECT active_servers.name " + String query = "SELECT active_servers.name " +
"FROM active_servers " + "FROM active_servers " +

@ -9,11 +9,15 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataHolder; import org.bukkit.persistence.PersistentDataHolder;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import xyz.soukup.ecoCraftCore.EcoCraftCore;
import static xyz.soukup.ecoCraftCore.EcoCraftCore.plugin;
@SuppressWarnings({"unchecked", "rawtypes"}) @SuppressWarnings({"unchecked", "rawtypes"})
public class PDC { public class PDC {
//TileState //TileState
public static void set(TileState tileState, String key, Integer value){ public static void set(TileState tileState, String key, Integer value){
@ -65,7 +69,7 @@ public class PDC {
return (String) get(itemStack, key, PersistentDataType.STRING); 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(); ItemMeta itemMeta = itemStack.getItemMeta();
return getUniversal(itemMeta, key, persistentDataType); return getUniversal(itemMeta, key, persistentDataType);
} }
@ -80,15 +84,15 @@ public class PDC {
//Univerzální set & get //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(); PersistentDataContainer persistentDataContainer = persistentDataHolder.getPersistentDataContainer();
NamespacedKey namespacedKey = new NamespacedKey("ecc", key); NamespacedKey namespacedKey = new NamespacedKey(plugin, key);
return persistentDataContainer.get(namespacedKey, persistentDataType); 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(); PersistentDataContainer persistentDataContainer = persistentDataHolder.getPersistentDataContainer();
NamespacedKey namespacedKey = new NamespacedKey("ecc", key); NamespacedKey namespacedKey = new NamespacedKey(plugin, key);
persistentDataContainer.set(namespacedKey, persistentDataType, value); persistentDataContainer.set(namespacedKey, persistentDataType, value);
} }

Loading…
Cancel
Save