chunk load on teleport fix + rtp shape implementation

This commit is contained in:
SuperRonanCraft 2021-01-13 13:05:24 -05:00
parent a18c71f27b
commit 563baee57e
6 changed files with 49 additions and 22 deletions

View File

@ -7,7 +7,7 @@
<groupId>me.SuperRonanCraft</groupId>
<artifactId>BetterRTP</artifactId>
<packaging>jar</packaging>
<version>3.0.3</version>
<version>3.0.4</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>

View File

@ -42,9 +42,9 @@ public class RTPPlayer {
if (event.getLocation() != null && pWorld.checkIsValid(event.getLocation()))
loc = event.getLocation();
else
loc = pWorld.generateRandomXZ();
loc = pWorld.generateLocation();
//Load chunk and find out if safe location
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(pWorld.getWorld(), loc.getBlockX(), loc.getBlockZ());
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(loc);
chunk.thenAccept(result -> {
//BetterRTP.debug("Checking location for " + p.getName());
Location tpLoc;

View File

@ -131,13 +131,12 @@ public class RTPTeleport {
private List<CompletableFuture<Chunk>> getChunks(Location loc) { //List all chunks in range to load
List<CompletableFuture<Chunk>> asyncChunks = new ArrayList<>();
int range = Math.round(Math.max(0, Math.min(16, getPl().getSettings().preloadRadius)));
for (int x = -range; x <= range; x++) {
for (int x = -range; x <= range; x++)
for (int z = -range; z <= range; z++) {
Location locLoad = new Location(loc.getWorld(), loc.getX() + (x * 16), loc.getY(), loc.getZ() + (z * 16));
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(locLoad, true);
asyncChunks.add(chunk);
}
}
return asyncChunks;
}

View File

@ -0,0 +1,6 @@
package me.SuperRonanCraft.BetterRTP.player.rtp;
public enum RTP_SHAPE {
SQUARE, //Square shaped location finder
ROUND //Circled area location finder
}

View File

@ -2,6 +2,7 @@ package me.SuperRonanCraft.BetterRTP.references.worlds;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPPermissionGroup;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_SHAPE;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldBorder;
@ -20,6 +21,7 @@ public class WorldPlayer implements RTPWorld {
private final World world;
private WORLD_TYPE world_type;
private RTPPermissionGroup.RTPPermConfiguration config = null;
private RTP_SHAPE shape = RTP_SHAPE.SQUARE;
//Economy
public boolean eco_money_taken = false;
@ -106,40 +108,60 @@ public class WorldPlayer implements RTPWorld {
int _zRMax = getCenterZ() + getMaxRad(); //||-|I
int _zRMin = getCenterZ() + getMinRad(); //||-I|
int _zLoc = loc.getBlockX();
if (_zLoc < _zLMax || (_zLoc > _zLMin && _zLoc < _zRMin) || _zLoc > _zRMax)
return false;
return true;
return _zLoc >= _zLMax && (_zLoc <= _zLMin || _zLoc >= _zRMin) && _zLoc <= _zRMax;
}
public Location generateRandomXZ() {
int borderRad = getMaxRad();
int minVal = getMinRad();
public Location generateLocation() {
Location loc = null;
switch (shape) {
//case ROUND: //DISABLED UNTIL NEXT PATCH
// loc = generateRound(getMaxRad(), getMinRad()); break;
default:
loc = generateSquare(getMaxRad(), getMinRad()); break;
}
addAttempt(); //Add an attempt to keep track of the times we've attempted to generate a good location
return loc;
}
private Location generateSquare(int maxRad, int min) {
//Generate a random X and Z based off the quadrant selected
int max = borderRad - minVal;
int max = maxRad - min;
int x, z;
int quadrant = new Random().nextInt(4);
switch (quadrant) {
case 0: // Positive X and Z
x = new Random().nextInt(max) + minVal;
z = new Random().nextInt(max) + minVal; break;
x = new Random().nextInt(max) + min;
z = new Random().nextInt(max) + min; break;
case 1: // Negative X and Z
x = -new Random().nextInt(max) - minVal;
z = -(new Random().nextInt(max) + minVal); break;
x = -new Random().nextInt(max) - min;
z = -(new Random().nextInt(max) + min); break;
case 2: // Negative X and Positive Z
x = -new Random().nextInt(max) - minVal;
z = new Random().nextInt(max) + minVal; break;
x = -new Random().nextInt(max) - min;
z = new Random().nextInt(max) + min; break;
default: // Positive X and Negative Z
x = new Random().nextInt(max) + minVal;
z = -(new Random().nextInt(max) + minVal); break;
x = new Random().nextInt(max) + min;
z = -(new Random().nextInt(max) + min); break;
}
x += getCenterX();
z += getCenterZ();
addAttempt();
//System.out.println(quadrant);
return new Location(getWorld(), x, 0, z);
}
private Location generateRound(int maxRad, int min) {
//Generate a random X and Z based off the quadrant selected
int max = maxRad - min;
int x, z;
double r = max * Math.sqrt(new Random().nextDouble());
double theta = (new Random().nextDouble()) * 2 * Math.PI;
x = (int) (r * Math.cos(theta));
z = (int) (r * Math.sin(theta));
x += getCenterX();
z += getCenterZ();
return new Location(getWorld(), x, 0, z);
}
@Override
public World getWorld() {
return world;

View File

@ -1,5 +1,5 @@
main: me.SuperRonanCraft.BetterRTP.BetterRTP
version: '3.0.3'
version: '3.0.4'
name: BetterRTP
author: SuperRonanCraft
softdepend: