legacy version chunk async load fix

This commit is contained in:
RonanCraft
2023-02-23 16:37:08 -05:00
parent 7f52c5a481
commit 34f616bd99
4 changed files with 32 additions and 23 deletions

View File

@@ -8,6 +8,7 @@ import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WORLD_TYPE;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPlayer;
import io.papermc.lib.PaperLib;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import org.apache.commons.lang.UnhandledException;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
@@ -60,30 +61,42 @@ public class RTPPlayer {
}
attempts++; //Add an attempt
//Load chunk and find out if safe location (asynchronously)
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(loc);
chunk.thenAccept(result -> {
//BetterRTP.debug("Checking location for " + p.getName());
Location tpLoc;
tpLoc = getSafeLocation(worldPlayer.getWorldtype(), worldPlayer.getWorld(), loc, worldPlayer.getMinY(), worldPlayer.getMaxY(), worldPlayer.getBiomes());
attemptedLocations.add(loc);
//Valid location?
if (tpLoc != null && checkDepends(tpLoc)) {
tpLoc.add(0.5, 0, 0.5); //Center location
if (getPl().getEco().charge(player, worldPlayer)) {
tpLoc.setYaw(player.getLocation().getYaw());
tpLoc.setPitch(player.getLocation().getPitch());
Bukkit.getScheduler().runTask(BetterRTP.getInstance(), () ->
settings.teleport.sendPlayer(sendi, player, tpLoc, worldPlayer.getPrice(), attempts, type, worldPlayer.getWorldtype()));
}
} else {
randomlyTeleport(sendi);
QueueHandler.remove(loc);
Bukkit.getScheduler().runTask(BetterRTP.getInstance(), () -> {
try { //Prior to 1.12 this async chunk will NOT work
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(loc);
chunk.thenAccept(result -> {
//BetterRTP.debug("Checking location for " + p.getName());
attempt(sendi, loc);
});
} catch (IllegalStateException e) {
attempt(sendi, loc);
} catch (Throwable ignored) {
}
});
});
}
}
private void attempt(CommandSender sendi, Location loc) {
Location tpLoc;
tpLoc = getSafeLocation(worldPlayer.getWorldtype(), worldPlayer.getWorld(), loc, worldPlayer.getMinY(), worldPlayer.getMaxY(), worldPlayer.getBiomes());
attemptedLocations.add(loc);
//Valid location?
if (tpLoc != null && checkDepends(tpLoc)) {
tpLoc.add(0.5, 0, 0.5); //Center location
if (getPl().getEco().charge(player, worldPlayer)) {
tpLoc.setYaw(player.getLocation().getYaw());
tpLoc.setPitch(player.getLocation().getPitch());
Bukkit.getScheduler().runTask(BetterRTP.getInstance(), () ->
settings.teleport.sendPlayer(sendi, player, tpLoc, worldPlayer.getPrice(), attempts, type, worldPlayer.getWorldtype()));
}
} else {
randomlyTeleport(sendi);
QueueHandler.remove(loc);
}
}
public static Location getSafeLocation(WORLD_TYPE type, World world, Location loc, int minY, int maxY, List<String> biomes) {
switch (type) { //Get a Y position and check for bad blocks
case NETHER: return getLocAtNether(loc.getBlockX(), loc.getBlockZ(), minY, maxY, world, biomes);

View File

@@ -1,7 +1,5 @@
package me.SuperRonanCraft.BetterRTP.references.depends.regionPlugins;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.settings.SoftDepends;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Location;

View File

@@ -1,7 +1,5 @@
package me.SuperRonanCraft.BetterRTP.references.depends.regionPlugins;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.settings.SoftDepends;
import net.william278.husktowns.api.HuskTownsAPI;
import org.bukkit.Location;

View File

@@ -66,7 +66,7 @@ public class HelperRTP {
return;
}
//ignore cooldown or else
BetterRTP.getInstance().getLogger().info("Center X: " + pWorld.getCenterX());
//BetterRTP.getInstance().getLogger().info("Center X: " + pWorld.getCenterX());
getPl().getRTP().start(pWorld);
}