mirror of
https://github.com/Brettflan/WorldBorder.git
synced 2025-02-01 04:01:24 +01:00
Fix formatting (spaces/tabs)
This commit is contained in:
parent
21adadd7e6
commit
ade2ca6352
@ -71,23 +71,23 @@ public class WBListener implements Listener
|
|||||||
Config.StartBorderTimer();
|
Config.StartBorderTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if there is a fill task running, and if yes, if it's for the
|
* Check if there is a fill task running, and if yes, if it's for the
|
||||||
* world that the unload event refers to and if the chunk should be
|
* world that the unload event refers to and if the chunk should be
|
||||||
* kept in memory because generation still needs it.
|
* kept in memory because generation still needs it.
|
||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChunkUnload(ChunkUnloadEvent e)
|
public void onChunkUnload(ChunkUnloadEvent e)
|
||||||
{
|
{
|
||||||
if (Config.fillTask!=null)
|
if (Config.fillTask!=null)
|
||||||
{
|
{
|
||||||
Chunk chunk=e.getChunk();
|
Chunk chunk=e.getChunk();
|
||||||
if (e.getWorld() == Config.fillTask.getWorld()
|
if (e.getWorld() == Config.fillTask.getWorld()
|
||||||
&& Config.fillTask.chunkOnUnloadPreventionList(chunk.getX(), chunk.getZ()))
|
&& Config.fillTask.chunkOnUnloadPreventionList(chunk.getX(), chunk.getZ()))
|
||||||
{
|
{
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -57,52 +57,52 @@ public class WorldFillTask implements Runnable
|
|||||||
private transient int reportTarget = 0;
|
private transient int reportTarget = 0;
|
||||||
private transient int reportTotal = 0;
|
private transient int reportTotal = 0;
|
||||||
private transient int reportNum = 0;
|
private transient int reportNum = 0;
|
||||||
|
|
||||||
// A map that holds to-be-loaded chunks, and their coordinates
|
// A map that holds to-be-loaded chunks, and their coordinates
|
||||||
private transient Map<CompletableFuture<Chunk>, CoordXZ> pendingChunks;
|
private transient Map<CompletableFuture<Chunk>, CoordXZ> pendingChunks;
|
||||||
|
|
||||||
// and a set of "Chunk a needed for Chunk b" dependencies, which
|
// and a set of "Chunk a needed for Chunk b" dependencies, which
|
||||||
// unfortunately can't be a Map as a chunk might be needed for
|
// unfortunately can't be a Map as a chunk might be needed for
|
||||||
// several others.
|
// several others.
|
||||||
private transient Set<UnloadDependency> preventUnload;
|
private transient Set<UnloadDependency> preventUnload;
|
||||||
|
|
||||||
private class UnloadDependency
|
private class UnloadDependency
|
||||||
{
|
{
|
||||||
int neededX, neededZ;
|
int neededX, neededZ;
|
||||||
int forX, forZ;
|
int forX, forZ;
|
||||||
|
|
||||||
UnloadDependency(int neededX, int neededZ, int forX, int forZ)
|
UnloadDependency(int neededX, int neededZ, int forX, int forZ)
|
||||||
{
|
{
|
||||||
this.neededX=neededX;
|
this.neededX=neededX;
|
||||||
this.neededZ=neededZ;
|
this.neededZ=neededZ;
|
||||||
this.forX=forX;
|
this.forX=forX;
|
||||||
this.forZ=forZ;
|
this.forZ=forZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other)
|
public boolean equals(Object other)
|
||||||
{
|
{
|
||||||
if (other == null || !(other instanceof UnloadDependency))
|
if (other == null || !(other instanceof UnloadDependency))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.neededX == ((UnloadDependency) other).neededX
|
return this.neededX == ((UnloadDependency) other).neededX
|
||||||
&& this.neededZ == ((UnloadDependency) other).neededZ
|
&& this.neededZ == ((UnloadDependency) other).neededZ
|
||||||
&& this.forX == ((UnloadDependency) other).forX
|
&& this.forX == ((UnloadDependency) other).forX
|
||||||
&& this.forZ == ((UnloadDependency) other).forZ;
|
&& this.forZ == ((UnloadDependency) other).forZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
int hash = 7;
|
int hash = 7;
|
||||||
hash = 79 * hash + this.neededX;
|
hash = 79 * hash + this.neededX;
|
||||||
hash = 79 * hash + this.neededZ;
|
hash = 79 * hash + this.neededZ;
|
||||||
hash = 79 * hash + this.forX;
|
hash = 79 * hash + this.forX;
|
||||||
hash = 79 * hash + this.forZ;
|
hash = 79 * hash + this.forZ;
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldFillTask(Server theServer, Player player, String worldName, int fillDistance, int chunksPerRun, int tickFrequency, boolean forceLoad)
|
public WorldFillTask(Server theServer, Player player, String worldName, int fillDistance, int chunksPerRun, int tickFrequency, boolean forceLoad)
|
||||||
{
|
{
|
||||||
@ -139,9 +139,9 @@ public class WorldFillTask implements Runnable
|
|||||||
this.stop();
|
this.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingChunks = new HashMap<>();
|
pendingChunks = new HashMap<>();
|
||||||
preventUnload = new HashSet<>();
|
preventUnload = new HashSet<>();
|
||||||
|
|
||||||
this.border.setRadiusX(border.getRadiusX() + fillDistance);
|
this.border.setRadiusX(border.getRadiusX() + fillDistance);
|
||||||
this.border.setRadiusZ(border.getRadiusZ() + fillDistance);
|
this.border.setRadiusZ(border.getRadiusZ() + fillDistance);
|
||||||
@ -160,7 +160,7 @@ public class WorldFillTask implements Runnable
|
|||||||
this.readyToGo = true;
|
this.readyToGo = true;
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new WorldBorderFillStartEvent(this));
|
Bukkit.getServer().getPluginManager().callEvent(new WorldBorderFillStartEvent(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
// for backwards compatibility
|
// for backwards compatibility
|
||||||
public WorldFillTask(Server theServer, Player player, String worldName, int fillDistance, int chunksPerRun, int tickFrequency)
|
public WorldFillTask(Server theServer, Player player, String worldName, int fillDistance, int chunksPerRun, int tickFrequency)
|
||||||
{
|
{
|
||||||
@ -201,86 +201,86 @@ public class WorldFillTask implements Runnable
|
|||||||
// and this is tracked to keep one iteration from dragging on too long and possibly choking the system if the user specified a really high frequency
|
// and this is tracked to keep one iteration from dragging on too long and possibly choking the system if the user specified a really high frequency
|
||||||
long loopStartTime = Config.Now();
|
long loopStartTime = Config.Now();
|
||||||
|
|
||||||
// Process async results from last time. We don't make a difference
|
// Process async results from last time. We don't make a difference
|
||||||
// whether they were really async, or sync.
|
// whether they were really async, or sync.
|
||||||
|
|
||||||
// First, Check which chunk generations have been finished.
|
// First, Check which chunk generations have been finished.
|
||||||
// Mark those chunks as existing and unloadable, and remove
|
// Mark those chunks as existing and unloadable, and remove
|
||||||
// them from the pending set.
|
// them from the pending set.
|
||||||
int chunksProcessedLastTick = 0;
|
int chunksProcessedLastTick = 0;
|
||||||
Map<CompletableFuture<Chunk>, CoordXZ> newPendingChunks = new HashMap<>();
|
Map<CompletableFuture<Chunk>, CoordXZ> newPendingChunks = new HashMap<>();
|
||||||
Set<CoordXZ> chunksToUnload = new HashSet<>();
|
Set<CoordXZ> chunksToUnload = new HashSet<>();
|
||||||
for (CompletableFuture<Chunk> cf: pendingChunks.keySet())
|
for (CompletableFuture<Chunk> cf: pendingChunks.keySet())
|
||||||
{
|
{
|
||||||
if (cf.isDone())
|
if (cf.isDone())
|
||||||
{
|
{
|
||||||
++chunksProcessedLastTick;
|
++chunksProcessedLastTick;
|
||||||
// If cf.get() returned the chunk reliably, pendingChunks could
|
// If cf.get() returned the chunk reliably, pendingChunks could
|
||||||
// be a set and we wouldn't have to map CFs to coords ...
|
// be a set and we wouldn't have to map CFs to coords ...
|
||||||
CoordXZ xz=pendingChunks.get(cf);
|
CoordXZ xz=pendingChunks.get(cf);
|
||||||
worldData.chunkExistsNow(xz.x, xz.z);
|
worldData.chunkExistsNow(xz.x, xz.z);
|
||||||
chunksToUnload.add(xz);
|
chunksToUnload.add(xz);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
newPendingChunks.put(cf, pendingChunks.get(cf));
|
newPendingChunks.put(cf, pendingChunks.get(cf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pendingChunks = newPendingChunks;
|
pendingChunks = newPendingChunks;
|
||||||
|
|
||||||
// Next, check which chunks had been loaded because a to-be-generated
|
// Next, check which chunks had been loaded because a to-be-generated
|
||||||
// chunk needed them, and don't have to remain in memory any more.
|
// chunk needed them, and don't have to remain in memory any more.
|
||||||
Set<UnloadDependency> newPreventUnload = new HashSet<>();
|
Set<UnloadDependency> newPreventUnload = new HashSet<>();
|
||||||
for (UnloadDependency dependency: preventUnload)
|
for (UnloadDependency dependency: preventUnload)
|
||||||
{
|
{
|
||||||
if (worldData.doesChunkExist(dependency.forX, dependency.forZ))
|
if (worldData.doesChunkExist(dependency.forX, dependency.forZ))
|
||||||
{
|
{
|
||||||
chunksToUnload.add(new CoordXZ(dependency.neededX, dependency.neededZ));
|
chunksToUnload.add(new CoordXZ(dependency.neededX, dependency.neededZ));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
newPreventUnload.add(dependency);
|
newPreventUnload.add(dependency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
preventUnload = newPreventUnload;
|
preventUnload = newPreventUnload;
|
||||||
|
|
||||||
// Unload all chunks that aren't needed anymore. NB a chunk could have
|
// Unload all chunks that aren't needed anymore. NB a chunk could have
|
||||||
// been needed for two different others, or been generated and needed
|
// been needed for two different others, or been generated and needed
|
||||||
// for one other chunk, so it might be in the unload set wrongly.
|
// for one other chunk, so it might be in the unload set wrongly.
|
||||||
// The ChunkUnloadListener checks this anyway, but it doesn't hurt to
|
// The ChunkUnloadListener checks this anyway, but it doesn't hurt to
|
||||||
// save a few µs by not even requesting the unload.
|
// save a few µs by not even requesting the unload.
|
||||||
|
|
||||||
for (CoordXZ unload: chunksToUnload)
|
for (CoordXZ unload: chunksToUnload)
|
||||||
{
|
{
|
||||||
if (!chunkOnUnloadPreventionList(unload.x, unload.z))
|
if (!chunkOnUnloadPreventionList(unload.x, unload.z))
|
||||||
{
|
{
|
||||||
world.unloadChunkRequest(unload.x, unload.z);
|
world.unloadChunkRequest(unload.x, unload.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put some damper on chunksPerRun. We don't want the queue to be too
|
// Put some damper on chunksPerRun. We don't want the queue to be too
|
||||||
// full; only fill it to a bit more than what we can
|
// full; only fill it to a bit more than what we can
|
||||||
// process per tick. This ensures the background task can run at
|
// process per tick. This ensures the background task can run at
|
||||||
// full speed and we recover from a temporary drop in generation rate,
|
// full speed and we recover from a temporary drop in generation rate,
|
||||||
// but doesn't push user-induced chunk generations behind a very
|
// but doesn't push user-induced chunk generations behind a very
|
||||||
// long queue of fill-generations.
|
// long queue of fill-generations.
|
||||||
|
|
||||||
int chunksToProcess = chunksPerRun;
|
int chunksToProcess = chunksPerRun;
|
||||||
if (chunksProcessedLastTick > 0 || pendingChunks.size() > 0)
|
if (chunksProcessedLastTick > 0 || pendingChunks.size() > 0)
|
||||||
{
|
{
|
||||||
// Note we generally queue 3 chunks, so real numbers are 1/3 of chunksProcessedLastTick and pendingchunks.size
|
// Note we generally queue 3 chunks, so real numbers are 1/3 of chunksProcessedLastTick and pendingchunks.size
|
||||||
int chunksExpectedToGetProcessed = (chunksProcessedLastTick - pendingChunks.size()) / 3 + 3;
|
int chunksExpectedToGetProcessed = (chunksProcessedLastTick - pendingChunks.size()) / 3 + 3;
|
||||||
if (chunksExpectedToGetProcessed < chunksToProcess)
|
if (chunksExpectedToGetProcessed < chunksToProcess)
|
||||||
chunksToProcess = chunksExpectedToGetProcessed;
|
chunksToProcess = chunksExpectedToGetProcessed;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int loop = 0; loop < chunksToProcess; loop++)
|
for (int loop = 0; loop < chunksToProcess; loop++)
|
||||||
{
|
{
|
||||||
// in case the task has been paused while we're repeating...
|
// in case the task has been paused while we're repeating...
|
||||||
if (paused || pausedForMemory)
|
if (paused || pausedForMemory)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long now = Config.Now();
|
long now = Config.Now();
|
||||||
|
|
||||||
@ -299,9 +299,9 @@ public class WorldFillTask implements Runnable
|
|||||||
while (!border.insideBorder(CoordXZ.chunkToBlock(x) + 8, CoordXZ.chunkToBlock(z) + 8))
|
while (!border.insideBorder(CoordXZ.chunkToBlock(x) + 8, CoordXZ.chunkToBlock(z) + 8))
|
||||||
{
|
{
|
||||||
if (!moveToNext())
|
if (!moveToNext())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
insideBorder = true;
|
insideBorder = true;
|
||||||
|
|
||||||
@ -314,9 +314,9 @@ public class WorldFillTask implements Runnable
|
|||||||
rLoop++;
|
rLoop++;
|
||||||
insideBorder = true;
|
insideBorder = true;
|
||||||
if (!moveToNext())
|
if (!moveToNext())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (rLoop > 255)
|
if (rLoop > 255)
|
||||||
{ // only skim through max 256 chunks (~8 region files) at a time here, to allow process to take a break if needed
|
{ // only skim through max 256 chunks (~8 region files) at a time here, to allow process to take a break if needed
|
||||||
readyToGo = true;
|
readyToGo = true;
|
||||||
@ -325,25 +325,25 @@ public class WorldFillTask implements Runnable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingChunks.put(PaperLib.getChunkAtAsync(world, x, z, true), new CoordXZ(x, z));
|
pendingChunks.put(PaperLib.getChunkAtAsync(world, x, z, true), new CoordXZ(x, z));
|
||||||
|
|
||||||
// There need to be enough nearby chunks loaded to make the server populate a chunk with trees, snow, etc.
|
// There need to be enough nearby chunks loaded to make the server populate a chunk with trees, snow, etc.
|
||||||
// So, we keep the last few chunks loaded, and need to also temporarily load an extra inside chunk (neighbor closest to center of map)
|
// So, we keep the last few chunks loaded, and need to also temporarily load an extra inside chunk (neighbor closest to center of map)
|
||||||
int popX = !isZLeg ? x : (x + (isNeg ? -1 : 1));
|
int popX = !isZLeg ? x : (x + (isNeg ? -1 : 1));
|
||||||
int popZ = isZLeg ? z : (z + (!isNeg ? -1 : 1));
|
int popZ = isZLeg ? z : (z + (!isNeg ? -1 : 1));
|
||||||
|
|
||||||
pendingChunks.put(PaperLib.getChunkAtAsync(world, popX, popZ, false), new CoordXZ(popX, popZ));
|
pendingChunks.put(PaperLib.getChunkAtAsync(world, popX, popZ, false), new CoordXZ(popX, popZ));
|
||||||
preventUnload.add(new UnloadDependency(popX, popZ, x, z));
|
preventUnload.add(new UnloadDependency(popX, popZ, x, z));
|
||||||
|
|
||||||
// make sure the previous chunk in our spiral is loaded as well (might have already existed and been skipped over)
|
// make sure the previous chunk in our spiral is loaded as well (might have already existed and been skipped over)
|
||||||
pendingChunks.put(PaperLib.getChunkAtAsync(world, lastChunk.x, lastChunk.z, false), new CoordXZ(lastChunk.x, lastChunk.z)); // <-- new CoordXZ as lastChunk isn't immutable
|
pendingChunks.put(PaperLib.getChunkAtAsync(world, lastChunk.x, lastChunk.z, false), new CoordXZ(lastChunk.x, lastChunk.z)); // <-- new CoordXZ as lastChunk isn't immutable
|
||||||
preventUnload.add(new UnloadDependency(lastChunk.x, lastChunk.z, x, z));
|
preventUnload.add(new UnloadDependency(lastChunk.x, lastChunk.z, x, z));
|
||||||
|
|
||||||
// move on to next chunk
|
// move on to next chunk
|
||||||
if (!moveToNext())
|
if (!moveToNext())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ready for the next iteration to run
|
// ready for the next iteration to run
|
||||||
readyToGo = true;
|
readyToGo = true;
|
||||||
@ -451,15 +451,15 @@ public class WorldFillTask implements Runnable
|
|||||||
server.getScheduler().cancelTask(taskID);
|
server.getScheduler().cancelTask(taskID);
|
||||||
server = null;
|
server = null;
|
||||||
|
|
||||||
// go ahead and unload any chunks we still have loaded
|
// go ahead and unload any chunks we still have loaded
|
||||||
// Set preventUnload to emptry first so the ChunkUnloadEvent Listener
|
// Set preventUnload to emptry first so the ChunkUnloadEvent Listener
|
||||||
// doesn't get in our way
|
// doesn't get in our way
|
||||||
Set<UnloadDependency> tempPreventUnload = preventUnload;
|
Set<UnloadDependency> tempPreventUnload = preventUnload;
|
||||||
preventUnload = null;
|
preventUnload = null;
|
||||||
for (UnloadDependency entry: tempPreventUnload)
|
for (UnloadDependency entry: tempPreventUnload)
|
||||||
{
|
{
|
||||||
world.unloadChunkRequest(entry.neededX, entry.neededZ);
|
world.unloadChunkRequest(entry.neededX, entry.neededZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// is this task still valid/workable?
|
// is this task still valid/workable?
|
||||||
@ -494,26 +494,26 @@ public class WorldFillTask implements Runnable
|
|||||||
{
|
{
|
||||||
return this.paused || this.pausedForMemory;
|
return this.paused || this.pausedForMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean chunkOnUnloadPreventionList(int x, int z)
|
public boolean chunkOnUnloadPreventionList(int x, int z)
|
||||||
{
|
{
|
||||||
if (preventUnload != null)
|
if (preventUnload != null)
|
||||||
{
|
{
|
||||||
for (UnloadDependency entry: preventUnload)
|
for (UnloadDependency entry: preventUnload)
|
||||||
{
|
{
|
||||||
if (entry.neededX == x && entry.neededZ == z)
|
if (entry.neededX == x && entry.neededZ == z)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public World getWorld()
|
public World getWorld()
|
||||||
{
|
{
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
// let the user know how things are coming along
|
// let the user know how things are coming along
|
||||||
private void reportProgress()
|
private void reportProgress()
|
||||||
|
Loading…
Reference in New Issue
Block a user