mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 14:00:14 +00:00
Ensure player is online before messaging/teleporting after feature location.
This commit is contained in:
1 parent
c495d44d58
commit
b6f354c630
2 files changed
+40
-17
No files matched your search
@@ -10,7 +10,7 @@ import org.polydev.gaea.biome.Biome;
|
|||||||
import org.polydev.gaea.generation.GenerationPhase;
|
import org.polydev.gaea.generation.GenerationPhase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runnable that locates a biome
|
* Runnable that locates a biome asynchronously
|
||||||
*/
|
*/
|
||||||
public class AsyncBiomeFinder implements Runnable {
|
public class AsyncBiomeFinder implements Runnable {
|
||||||
private final TerraBiomeGrid grid;
|
private final TerraBiomeGrid grid;
|
||||||
@@ -21,6 +21,7 @@ public class AsyncBiomeFinder implements Runnable {
|
|||||||
private final Biome target;
|
private final Biome target;
|
||||||
private final Player p;
|
private final Player p;
|
||||||
private final boolean tp;
|
private final boolean tp;
|
||||||
|
|
||||||
public AsyncBiomeFinder(TerraBiomeGrid grid, Biome target, Player p, int startRadius, int maxRadius, boolean tp) {
|
public AsyncBiomeFinder(TerraBiomeGrid grid, Biome target, Player p, int startRadius, int maxRadius, boolean tp) {
|
||||||
this.grid = grid;
|
this.grid = grid;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
@@ -31,6 +32,7 @@ public class AsyncBiomeFinder implements Runnable {
|
|||||||
this.maxRadius = maxRadius;
|
this.maxRadius = maxRadius;
|
||||||
this.tp = tp;
|
this.tp = tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int x = centerX;
|
int x = centerX;
|
||||||
@@ -51,16 +53,24 @@ public class AsyncBiomeFinder implements Runnable {
|
|||||||
run++;
|
run++;
|
||||||
toggle = !toggle;
|
toggle = !toggle;
|
||||||
}
|
}
|
||||||
if(checkBiome(x, z).equals(target) && p.isOnline()) {
|
if(p.isOnline()) {
|
||||||
LangUtil.send("command.biome.biome-found", p, String.valueOf(x), String.valueOf(z));
|
if(checkBiome(x, z).equals(target)) {
|
||||||
if(tp) {
|
LangUtil.send("command.biome.biome-found", p, String.valueOf(x), String.valueOf(z));
|
||||||
int finalX = x;
|
if(tp) {
|
||||||
int finalZ = z;
|
int finalX = x;
|
||||||
Bukkit.getScheduler().runTask(Terra.getInstance(), () -> p.teleport(new Location(p.getWorld(), finalX, p.getLocation().getY(), finalZ)));
|
int finalZ = z;
|
||||||
}
|
Bukkit.getScheduler().runTask(Terra.getInstance(), () -> p.teleport(new Location(p.getWorld(), finalX, p.getLocation().getY(), finalZ)));
|
||||||
} else if(p.isOnline()) LangUtil.send("command.biome.unable-to-locate", p);
|
}
|
||||||
|
} else LangUtil.send("command.biome.unable-to-locate", p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to get biome at location
|
||||||
|
* @param x X coordinate
|
||||||
|
* @param z Z coordinate
|
||||||
|
* @return Biome at coordinates
|
||||||
|
*/
|
||||||
private Biome checkBiome(int x, int z) {
|
private Biome checkBiome(int x, int z) {
|
||||||
return grid.getBiome(x, z, GenerationPhase.POST_GEN);
|
return grid.getBiome(x, z, GenerationPhase.POST_GEN);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ import org.bukkit.util.Vector;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runnable to locate structures asynchronously
|
||||||
|
*/
|
||||||
public class AsyncStructureFinder implements Runnable {
|
public class AsyncStructureFinder implements Runnable {
|
||||||
private final TerraBiomeGrid grid;
|
private final TerraBiomeGrid grid;
|
||||||
private final StructureConfig target;
|
private final StructureConfig target;
|
||||||
@@ -74,15 +77,25 @@ public class AsyncStructureFinder implements Runnable {
|
|||||||
run++;
|
run++;
|
||||||
toggle = !toggle;
|
toggle = !toggle;
|
||||||
}
|
}
|
||||||
if(found) {
|
if(p.isOnline()) {
|
||||||
p.sendMessage("Located structure at (" + spawn.getBlockX() + ", " + spawn.getBlockZ() + ").");
|
if(found) {
|
||||||
if(tp) {
|
p.sendMessage("Located structure at (" + spawn.getBlockX() + ", " + spawn.getBlockZ() + ").");
|
||||||
int finalX = spawn.getBlockX();
|
if(tp) {
|
||||||
int finalZ = spawn.getBlockZ();
|
int finalX = spawn.getBlockX();
|
||||||
Bukkit.getScheduler().runTask(Terra.getInstance(), () -> p.teleport(new Location(p.getWorld(), finalX, p.getLocation().getY(), finalZ)));
|
int finalZ = spawn.getBlockZ();
|
||||||
|
Bukkit.getScheduler().runTask(Terra.getInstance(), () -> p.teleport(new Location(p.getWorld(), finalX, p.getLocation().getY(), finalZ)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if(p.isOnline()) p.sendMessage("Unable to locate structure. " + spawn);
|
p.sendMessage("Unable to locate structure. " + spawn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if coordinate pair is a valid structure spawn
|
||||||
|
* @param x X coordinate
|
||||||
|
* @param z Z coordinate
|
||||||
|
* @return Whether location is a valid spawn for StructureConfig
|
||||||
|
*/
|
||||||
private boolean isValidSpawn(int x, int z) {
|
private boolean isValidSpawn(int x, int z) {
|
||||||
Location spawn = target.getSpawn().getNearestSpawn(x, z, world.getSeed()).toLocation(world);
|
Location spawn = target.getSpawn().getNearestSpawn(x, z, world.getSeed()).toLocation(world);
|
||||||
if(! TerraWorld.getWorld(world).getConfig().getBiome((UserDefinedBiome) grid.getBiome(spawn)).getStructures().contains(target)) return false;
|
if(! TerraWorld.getWorld(world).getConfig().getBiome((UserDefinedBiome) grid.getBiome(spawn)).getStructures().contains(target)) return false;
|
||||||
|
|||||||
Reference in new issue
Block a user