|
|
|
|
@ -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 " + |
|
|
|
|
|