Fix broken island spot finder
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
It was working as long as the coordinates in the map were ordered, but since this is not ensured, we need a more complex way of checking for them.
This commit is contained in:
parent
7abfb4d536
commit
09884f1646
@ -32,6 +32,8 @@ import wtf.beatrice.limbomanager.utils.LocationUtils;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PlayerTeleporter implements Listener
|
public class PlayerTeleporter implements Listener
|
||||||
{
|
{
|
||||||
@ -76,7 +78,6 @@ public class PlayerTeleporter implements Listener
|
|||||||
// configure here
|
// configure here
|
||||||
.build();
|
.build();
|
||||||
Operations.complete(operation);
|
Operations.complete(operation);
|
||||||
editSession.flushSession();
|
|
||||||
} catch (WorldEditException e) {
|
} catch (WorldEditException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -116,22 +117,40 @@ public class PlayerTeleporter implements Listener
|
|||||||
islandSpawnLocation.getWorld().getMaxHeight(),
|
islandSpawnLocation.getWorld().getMaxHeight(),
|
||||||
islandSpawnLocation.getZ() + maxRange);
|
islandSpawnLocation.getZ() + maxRange);
|
||||||
|
|
||||||
|
// announce area cleanup
|
||||||
LimboManager.getInstance().getLogger().info("Player " + playerName + " quit, clearing region...");
|
LimboManager.getInstance().getLogger().info("Player " + playerName + " quit, clearing region...");
|
||||||
|
|
||||||
|
// WorldEdit API integration for faster area cleanup
|
||||||
World weWorld = BukkitAdapter.adapt(islandSpawnLocation.getWorld());
|
World weWorld = BukkitAdapter.adapt(islandSpawnLocation.getWorld());
|
||||||
try(EditSession editSession = WorldEdit.getInstance().newEditSession(weWorld))
|
try(EditSession editSession = WorldEdit.getInstance().newEditSession(weWorld))
|
||||||
{
|
{
|
||||||
|
// we only need to set everything to air
|
||||||
BlockState air = BukkitAdapter.adapt(Material.AIR.createBlockData());
|
BlockState air = BukkitAdapter.adapt(Material.AIR.createBlockData());
|
||||||
|
|
||||||
|
// convert our area borders to WE blockvectors
|
||||||
BlockVector3 min = BlockVector3.at(startFrom.getBlockX(), startFrom.getBlockY(), startFrom.getBlockZ());
|
BlockVector3 min = BlockVector3.at(startFrom.getBlockX(), startFrom.getBlockY(), startFrom.getBlockZ());
|
||||||
BlockVector3 max = BlockVector3.at(endAt.getBlockX(), endAt.getBlockY(), endAt.getBlockZ());
|
BlockVector3 max = BlockVector3.at(endAt.getBlockX(), endAt.getBlockY(), endAt.getBlockZ());
|
||||||
|
|
||||||
|
// create a cuboid region
|
||||||
CuboidRegion cuboidRegion = new CuboidRegion(weWorld, min, max);
|
CuboidRegion cuboidRegion = new CuboidRegion(weWorld, min, max);
|
||||||
|
|
||||||
|
// do the cleaning
|
||||||
editSession.setBlocks(cuboidRegion, air);
|
editSession.setBlocks(cuboidRegion, air);
|
||||||
|
|
||||||
|
// set that island spot to "cool-down mode"
|
||||||
|
String randUUID = UUID.randomUUID().toString();
|
||||||
|
Coordinates islandCoords = new Coordinates(Cache.playerIslands.get(playerName));
|
||||||
|
Cache.playerIslands.put(randUUID, islandCoords);
|
||||||
|
Cache.playerIslands.remove(playerName);
|
||||||
|
|
||||||
|
// start a timer to set the spot to free after X time.
|
||||||
Bukkit.getScheduler().runTaskLater(LimboManager.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(LimboManager.getInstance(), () -> {
|
||||||
|
|
||||||
LimboManager.getInstance().getLogger().info("Region for " + playerName + " is now available again.");
|
LimboManager.getInstance().getLogger().info("Region [" + randUUID + ", "
|
||||||
Cache.playerIslands.remove(playerName);
|
+ islandCoords.getX() + ", "
|
||||||
|
+ islandCoords.getZ()
|
||||||
|
+ "] of " + playerName + " is now available again.");
|
||||||
|
Cache.playerIslands.remove(randUUID);
|
||||||
|
|
||||||
}, 60 * 20L);
|
}, 60 * 20L);
|
||||||
|
|
||||||
@ -150,31 +169,26 @@ public class PlayerTeleporter implements Listener
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Coordinates islandCoords = new Coordinates(Cache.baseCoords);
|
Coordinates islandCoords = new Coordinates(Cache.baseCoords);
|
||||||
for(Coordinates currentCoords : Cache.playerIslands.values()) {
|
ArrayList<Coordinates> playerIslands = new ArrayList<>(Cache.playerIslands.values());
|
||||||
|
|
||||||
// if the two are not the same, it means we found a free spot.
|
for(int i = 0; i < playerIslands.size(); i++)
|
||||||
// we can thus quit the loop and keep the current coords as valid.
|
{
|
||||||
if(!islandCoords.equals(currentCoords)) break;
|
Coordinates checkCoords = playerIslands.get(i);
|
||||||
|
|
||||||
// else, if they are the same,
|
if(islandCoords.equals(checkCoords))
|
||||||
// we have to either increase X or move to a new row and reset X, in case it's over 10000.
|
|
||||||
if(islandCoords.getX() >= 10000) // if we need to create a new row
|
|
||||||
{
|
{
|
||||||
islandCoords.setX(1000);
|
// we have to either increase X or move to a new row and reset X, in case it's over 10000.
|
||||||
islandCoords.setZ(islandCoords.getZ() + Cache.islandsDistance);
|
if(islandCoords.getX() >= 10000) // if we need to create a new row
|
||||||
} else { // if we just need to increase the column
|
{
|
||||||
islandCoords.setX(islandCoords.getX() + Cache.islandsDistance);
|
islandCoords.setX(1000);
|
||||||
|
islandCoords.setZ(islandCoords.getZ() + Cache.islandsDistance);
|
||||||
|
} else { // if we just need to increase the column
|
||||||
|
islandCoords.setX(islandCoords.getX() + Cache.islandsDistance);
|
||||||
|
}
|
||||||
|
i = 0; // restart the loop and check again (ugh)
|
||||||
}
|
}
|
||||||
|
} // at the end of the loop, we should have unique coordinates.
|
||||||
}
|
|
||||||
|
|
||||||
return islandCoords;
|
return islandCoords;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
player joins -> we look for the first free space -> we add it to the list and generate the island
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
Loading…
Reference in New Issue
Block a user