mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 17:15:47 +00:00
chunk load on teleport fix + rtp shape implementation
This commit is contained in:
parent
a18c71f27b
commit
563baee57e
2
pom.xml
2
pom.xml
@ -7,7 +7,7 @@
|
|||||||
<groupId>me.SuperRonanCraft</groupId>
|
<groupId>me.SuperRonanCraft</groupId>
|
||||||
<artifactId>BetterRTP</artifactId>
|
<artifactId>BetterRTP</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>3.0.3</version>
|
<version>3.0.4</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
@ -42,9 +42,9 @@ public class RTPPlayer {
|
|||||||
if (event.getLocation() != null && pWorld.checkIsValid(event.getLocation()))
|
if (event.getLocation() != null && pWorld.checkIsValid(event.getLocation()))
|
||||||
loc = event.getLocation();
|
loc = event.getLocation();
|
||||||
else
|
else
|
||||||
loc = pWorld.generateRandomXZ();
|
loc = pWorld.generateLocation();
|
||||||
//Load chunk and find out if safe location
|
//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 -> {
|
chunk.thenAccept(result -> {
|
||||||
//BetterRTP.debug("Checking location for " + p.getName());
|
//BetterRTP.debug("Checking location for " + p.getName());
|
||||||
Location tpLoc;
|
Location tpLoc;
|
||||||
|
@ -131,13 +131,12 @@ public class RTPTeleport {
|
|||||||
private List<CompletableFuture<Chunk>> getChunks(Location loc) { //List all chunks in range to load
|
private List<CompletableFuture<Chunk>> getChunks(Location loc) { //List all chunks in range to load
|
||||||
List<CompletableFuture<Chunk>> asyncChunks = new ArrayList<>();
|
List<CompletableFuture<Chunk>> asyncChunks = new ArrayList<>();
|
||||||
int range = Math.round(Math.max(0, Math.min(16, getPl().getSettings().preloadRadius)));
|
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++) {
|
for (int z = -range; z <= range; z++) {
|
||||||
Location locLoad = new Location(loc.getWorld(), loc.getX() + (x * 16), loc.getY(), loc.getZ() + (z * 16));
|
Location locLoad = new Location(loc.getWorld(), loc.getX() + (x * 16), loc.getY(), loc.getZ() + (z * 16));
|
||||||
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(locLoad, true);
|
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(locLoad, true);
|
||||||
asyncChunks.add(chunk);
|
asyncChunks.add(chunk);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return asyncChunks;
|
return asyncChunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
||||||
|
|
||||||
|
public enum RTP_SHAPE {
|
||||||
|
SQUARE, //Square shaped location finder
|
||||||
|
ROUND //Circled area location finder
|
||||||
|
}
|
@ -2,6 +2,7 @@ package me.SuperRonanCraft.BetterRTP.references.worlds;
|
|||||||
|
|
||||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPPermissionGroup;
|
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPPermissionGroup;
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
|
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_SHAPE;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.WorldBorder;
|
import org.bukkit.WorldBorder;
|
||||||
@ -20,6 +21,7 @@ public class WorldPlayer implements RTPWorld {
|
|||||||
private final World world;
|
private final World world;
|
||||||
private WORLD_TYPE world_type;
|
private WORLD_TYPE world_type;
|
||||||
private RTPPermissionGroup.RTPPermConfiguration config = null;
|
private RTPPermissionGroup.RTPPermConfiguration config = null;
|
||||||
|
private RTP_SHAPE shape = RTP_SHAPE.SQUARE;
|
||||||
//Economy
|
//Economy
|
||||||
public boolean eco_money_taken = false;
|
public boolean eco_money_taken = false;
|
||||||
|
|
||||||
@ -106,40 +108,60 @@ public class WorldPlayer implements RTPWorld {
|
|||||||
int _zRMax = getCenterZ() + getMaxRad(); //||-|I
|
int _zRMax = getCenterZ() + getMaxRad(); //||-|I
|
||||||
int _zRMin = getCenterZ() + getMinRad(); //||-I|
|
int _zRMin = getCenterZ() + getMinRad(); //||-I|
|
||||||
int _zLoc = loc.getBlockX();
|
int _zLoc = loc.getBlockX();
|
||||||
if (_zLoc < _zLMax || (_zLoc > _zLMin && _zLoc < _zRMin) || _zLoc > _zRMax)
|
return _zLoc >= _zLMax && (_zLoc <= _zLMin || _zLoc >= _zRMin) && _zLoc <= _zRMax;
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location generateRandomXZ() {
|
public Location generateLocation() {
|
||||||
int borderRad = getMaxRad();
|
Location loc = null;
|
||||||
int minVal = getMinRad();
|
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
|
//Generate a random X and Z based off the quadrant selected
|
||||||
int max = borderRad - minVal;
|
int max = maxRad - min;
|
||||||
int x, z;
|
int x, z;
|
||||||
int quadrant = new Random().nextInt(4);
|
int quadrant = new Random().nextInt(4);
|
||||||
switch (quadrant) {
|
switch (quadrant) {
|
||||||
case 0: // Positive X and Z
|
case 0: // Positive X and Z
|
||||||
x = new Random().nextInt(max) + minVal;
|
x = new Random().nextInt(max) + min;
|
||||||
z = new Random().nextInt(max) + minVal; break;
|
z = new Random().nextInt(max) + min; break;
|
||||||
case 1: // Negative X and Z
|
case 1: // Negative X and Z
|
||||||
x = -new Random().nextInt(max) - minVal;
|
x = -new Random().nextInt(max) - min;
|
||||||
z = -(new Random().nextInt(max) + minVal); break;
|
z = -(new Random().nextInt(max) + min); break;
|
||||||
case 2: // Negative X and Positive Z
|
case 2: // Negative X and Positive Z
|
||||||
x = -new Random().nextInt(max) - minVal;
|
x = -new Random().nextInt(max) - min;
|
||||||
z = new Random().nextInt(max) + minVal; break;
|
z = new Random().nextInt(max) + min; break;
|
||||||
default: // Positive X and Negative Z
|
default: // Positive X and Negative Z
|
||||||
x = new Random().nextInt(max) + minVal;
|
x = new Random().nextInt(max) + min;
|
||||||
z = -(new Random().nextInt(max) + minVal); break;
|
z = -(new Random().nextInt(max) + min); break;
|
||||||
}
|
}
|
||||||
x += getCenterX();
|
x += getCenterX();
|
||||||
z += getCenterZ();
|
z += getCenterZ();
|
||||||
addAttempt();
|
|
||||||
//System.out.println(quadrant);
|
//System.out.println(quadrant);
|
||||||
return new Location(getWorld(), x, 0, z);
|
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
|
@Override
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return world;
|
return world;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
main: me.SuperRonanCraft.BetterRTP.BetterRTP
|
main: me.SuperRonanCraft.BetterRTP.BetterRTP
|
||||||
version: '3.0.3'
|
version: '3.0.4'
|
||||||
name: BetterRTP
|
name: BetterRTP
|
||||||
author: SuperRonanCraft
|
author: SuperRonanCraft
|
||||||
softdepend:
|
softdepend:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user