2.12.1 - Chunk async support on older servers

Reason for this change is that in previous versions on MC the spigot api would load a chunk prior to finding the tallest block in the world. So a full recode on the random location has been issued, first generating a random x/z coordinates, then loading that locations chunk, grabbing the tallest block making sure its a valid block, and then checking for griefprevention/worldguard, and then teleporting the player if its valid, else loop again until it finds a valid location, or cancel if there are too many attempts.
This commit is contained in:
SuperRonanCraft 2020-08-12 13:35:47 -04:00
parent 3b8b7b0b38
commit fd1c7c5c14
9 changed files with 244 additions and 160 deletions

View File

@ -6,7 +6,7 @@
<groupId>me.SuperRonanCraft</groupId> <groupId>me.SuperRonanCraft</groupId>
<artifactId>BetterRTP</artifactId> <artifactId>BetterRTP</artifactId>
<version>2.12.0</version> <version>2.12.1</version>
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>

View File

@ -86,14 +86,14 @@ public class CmdInfo implements RTPCommand {
else { else {
info.add("&7- &6WorldType: &f" + pl.getRTP().world_type.getOrDefault(w.getName(), RTP_WORLD_TYPE.NORMAL).name()); info.add("&7- &6WorldType: &f" + pl.getRTP().world_type.getOrDefault(w.getName(), RTP_WORLD_TYPE.NORMAL).name());
info.add("&7- &6Overriden: &cFalse"); info.add("&7- &6Overriden: &cFalse");
RTPWorld _rtpworld = pl.getRTP().Default; RTPWorld _rtpworld = pl.getRTP().defaultWorld;
for (RTPWorld __rtpworld : pl.getRTP().customWorlds.values()) { for (RTPWorld __rtpworld : pl.getRTP().customWorlds.values()) {
if (__rtpworld.getWorld().equals(w.getName())) { if (__rtpworld.getWorld().equals(w.getName())) {
_rtpworld = __rtpworld; _rtpworld = __rtpworld;
break; break;
} }
} }
if (_rtpworld == pl.getRTP().Default) if (_rtpworld == pl.getRTP().defaultWorld)
info.add("&7- &6Custom: &cFalse"); info.add("&7- &6Custom: &cFalse");
else else
info.add("&7- &6Custom: &bTrue"); info.add("&7- &6Custom: &bTrue");

View File

@ -4,14 +4,12 @@ import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.WGBukkit; import com.sk89q.worldguard.bukkit.WGBukkit;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.managers.RegionManager;
import io.papermc.lib.PaperLib;
import me.SuperRonanCraft.BetterRTP.Main; import me.SuperRonanCraft.BetterRTP.Main;
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics; import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import me.SuperRonanCraft.BetterRTP.references.worlds.*; import me.SuperRonanCraft.BetterRTP.references.worlds.*;
import me.ryanhamshire.GriefPrevention.GriefPrevention; import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Bukkit; import org.bukkit.*;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -21,6 +19,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.concurrent.CompletableFuture;
public class RTP { public class RTP {
@ -28,7 +27,7 @@ public class RTP {
//Cache //Cache
public HashMap<String, RTPWorld> customWorlds = new HashMap<>(); public HashMap<String, RTPWorld> customWorlds = new HashMap<>();
public HashMap<String, String> overriden = new HashMap<>(); public HashMap<String, String> overriden = new HashMap<>();
public Default Default = new Default(); public Default defaultWorld = new Default();
private Random rn = new Random(); private Random rn = new Random();
private List<String> disabledWorlds, blockList; private List<String> disabledWorlds, blockList;
private int maxAttempts, delayTime; private int maxAttempts, delayTime;
@ -40,7 +39,7 @@ public class RTP {
} }
public void load() { public void load() {
Default.setup(); defaultWorld.setup();
FileBasics.FILETYPE config = getPl().getFiles().getType(FileBasics.FILETYPE.CONFIG); FileBasics.FILETYPE config = getPl().getFiles().getType(FileBasics.FILETYPE.CONFIG);
disabledWorlds = config.getStringList("DisabledWorlds"); disabledWorlds = config.getStringList("DisabledWorlds");
maxAttempts = config.getInt("Settings.MaxAttempts"); maxAttempts = config.getInt("Settings.MaxAttempts");
@ -122,38 +121,42 @@ public class RTP {
return disabledWorlds; return disabledWorlds;
} }
public void start(Player p, CommandSender sendi, String worl, List<String> biomes, boolean delay) { public void start(Player p, CommandSender sendi, String worldName, List<String> biomes, boolean delay) {
// Check overrides // Check overrides
String world = worl; if (worldName == null)
if (world == null) worldName = p.getWorld().getName();
world = p.getWorld().getName(); if (overriden.containsKey(worldName))
if (overriden.containsKey(world)) worldName = overriden.get(worldName);
world = overriden.get(world);
// Not forced and has 'betterrtp.world.<world>' // Not forced and has 'betterrtp.world.<world>'
if (sendi == p && !getPl().getPerms().getAWorld(sendi, world)) { if (sendi == p && !getPl().getPerms().getAWorld(sendi, worldName)) {
getPl().getCmd().cooldowns.remove(p.getUniqueId()); getPl().getCmd().cooldowns.remove(p.getUniqueId());
getPl().getText().getNoPermissionWorld(p, world); getPl().getText().getNoPermissionWorld(p, worldName);
return; return;
} }
// Check disabled worlds // Check disabled worlds
if (disabledWorlds.contains(world)) { if (disabledWorlds.contains(worldName)) {
getPl().getText().getDisabledWorld(sendi, world); getPl().getText().getDisabledWorld(sendi, worldName);
getPl().getCmd().cooldowns.remove(p.getUniqueId()); getPl().getCmd().cooldowns.remove(p.getUniqueId());
return; return;
} }
// Check if nulled // Check if nulled or world doesnt exist
if (Bukkit.getWorld(world) == null) { if (Bukkit.getWorld(worldName) == null) {
getPl().getText().getNotExist(sendi, world); getPl().getText().getNotExist(sendi, worldName);
getPl().getCmd().cooldowns.remove(p.getUniqueId()); getPl().getCmd().cooldowns.remove(p.getUniqueId());
return; return;
} }
PlayerWorld pWorld = new PlayerWorld(p, world); PlayerWorld pWorld = new PlayerWorld(p, Bukkit.getWorld(worldName));
// Set all methods // Set all methods
if (customWorlds.containsKey(world)) { if (customWorlds.containsKey(worldName)) {
RTPWorld cWorld = customWorlds.get(pWorld.getWorld()); RTPWorld cWorld = customWorlds.get(pWorld.getWorld().getName());
pWorld.setup(cWorld, cWorld.getPrice(), biomes); pWorld.setup(cWorld, cWorld.getPrice(), biomes);
} else } else
pWorld.setup(Default, Default.getPrice(), biomes); pWorld.setup(defaultWorld, defaultWorld.getPrice(), biomes);
//World type
RTP_WORLD_TYPE world_type = RTP_WORLD_TYPE.NORMAL; //World rtp type
if (this.world_type.containsKey(worldName))
world_type = this.world_type.get(worldName);
pWorld.setWorldtype(world_type);
// Check world price // Check world price
if (!getPl().getEco().charge(p, pWorld.getPrice())) { if (!getPl().getEco().charge(p, pWorld.getPrice())) {
getPl().getText().getFailedPrice(p, pWorld.getPrice()); getPl().getText().getFailedPrice(p, pWorld.getPrice());
@ -165,20 +168,45 @@ public class RTP {
if (getPl().getSettings().delayEnabled && delay) { if (getPl().getSettings().delayEnabled && delay) {
new RTPDelay(sendi, pWorld, delayTime, cancelOnMove, cancelOnDamage); new RTPDelay(sendi, pWorld, delayTime, cancelOnMove, cancelOnDamage);
} else } else
tp(sendi, pWorld); findSafeLocation(sendi, pWorld);
} }
void tp(CommandSender sendi, PlayerWorld pWorld) { // void findSafeLocation(CommandSender sendi, PlayerWorld pWorld) {
new BukkitRunnable(){ // new BukkitRunnable(){
@Override // @Override
public void run() { // public void run() {
Location loc = randomLoc(pWorld); // f
if (loc != null) // if (loc != null)
teleport.sendPlayer(sendi, pWorld.getPlayer(), loc, pWorld.getPrice(), pWorld.getAttempts()); // teleport.sendPlayer(sendi, pWorld.getPlayer(), loc, pWorld.getPrice(), pWorld.getAttempts());
// else
// metMax(sendi, pWorld.getPlayer(), pWorld.getPrice());
// }
// }.runTaskAsynchronously(getPl());
// }
void findSafeLocation(CommandSender sendi, PlayerWorld pWorld) {
if (pWorld.getAttempts() >= maxAttempts) //Cancel out, too many tried
metMax(sendi, pWorld.getPlayer(), pWorld.getPrice());
else { //Try again to find a safe location
Location loc = pWorld.generateRandomXZ(defaultWorld, rn.nextInt(4)); //randomLoc(pWorld);
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(pWorld.getWorld(), loc.getBlockX(), loc.getBlockZ());
chunk.thenAccept(result -> {
Location tpLoc;
float yaw = pWorld.getPlayer().getLocation().getYaw();
float pitch = pWorld.getPlayer().getLocation().getPitch();
switch (pWorld.getWorldtype()) { //Get a Y position and check for bad blocks
case NETHER:
tpLoc = getLocAtNether(loc.getBlockX(), loc.getBlockZ(), pWorld.getWorld(), yaw, pitch, pWorld); break;
case NORMAL:
default:
tpLoc = getLocAtNormal(loc.getBlockX(), loc.getBlockZ(), pWorld.getWorld(), yaw, pitch, pWorld);
}
if (tpLoc != null && checkDepends(tpLoc))
teleport.sendPlayer(sendi, pWorld.getPlayer(), tpLoc, pWorld.getPrice(), pWorld.getAttempts());
else else
metMax(sendi, pWorld.getPlayer(), pWorld.getPrice()); findSafeLocation(sendi, pWorld);
} });
}.runTaskAsynchronously(getPl()); }
} }
// Compressed code for MaxAttempts being met // Compressed code for MaxAttempts being met
@ -193,82 +221,69 @@ public class RTP {
} }
//Get a random location depending the world type //Get a random location depending the world type
private Location randomLoc(PlayerWorld pWorld) { // private Location randomLoc(PlayerWorld pWorld) {
int borderRad = pWorld.getMaxRad(); // int borderRad = pWorld.getMaxRad();
int minVal = pWorld.getMinRad(); // int minVal = pWorld.getMinRad();
int CenterX = pWorld.getCenterX(); // int CenterX = pWorld.getCenterX();
int CenterZ = pWorld.getCenterZ(); // int CenterZ = pWorld.getCenterZ();
int quadrant = rn.nextInt(4); // int quadrant = rn.nextInt(4);
Player p = pWorld.getPlayer(); // Player p = pWorld.getPlayer();
World world = Bukkit.getWorld(pWorld.getWorld()); // World world = pWorld.getWorld();
if (pWorld.getUseWorldborder()) { // if (pWorld.getUseWorldborder()) {
WorldBorder border = world.getWorldBorder(); // WorldBorder border = world.getWorldBorder();
borderRad = (int) border.getSize() / 2; // borderRad = (int) border.getSize() / 2;
CenterX = border.getCenter().getBlockX(); // CenterX = border.getCenter().getBlockX();
CenterZ = border.getCenter().getBlockZ(); // CenterZ = border.getCenter().getBlockZ();
} // }
float yaw = p.getLocation().getYaw(), pitch = p.getLocation().getPitch(); // float yaw = p.getLocation().getYaw(), pitch = p.getLocation().getPitch();
RTP_WORLD_TYPE world_type = RTP_WORLD_TYPE.NORMAL; //World rtp type // RTP_WORLD_TYPE world_type = pWorld.getWorldtype();
/*try { // //for (int i = 0; i <= maxAttempts; i++) {
//1.13+ // // Get the y-coords from up top, then check if it's SAFE!
normal = !world.getBiome(0, 0).equals(Biome.valueOf("NETHER"))); // Location loc = null;
} catch (Exception e) { // if (borderRad <= minVal) {
//1.8-1.12 // minVal = defaultWorld.getMinRad();
try { // if (borderRad <= minVal)
normal = !world.getBiome(0, 0).equals(Biome.valueOf("HELL")); // minVal = 0;
} catch (Exception e1) { // }
normal = true; // switch (world_type) {
} // case NETHER:
}*/ // loc = nether(borderRad, minVal, CenterX, CenterZ, quadrant, world, pWorld, yaw, pitch); break;
if (this.world_type.containsKey(world.getName())) // default:
world_type = this.world_type.get(world.getName()); // loc = normal(borderRad, minVal, CenterX, CenterZ, quadrant, world, pWorld, yaw, pitch);
for (int i = 0; i <= maxAttempts; i++) { // }
// Get the y-coords from up top, then check if it's SAFE! // pWorld.addAttempt();
Location loc = null; // //if (loc != null && checkDepends(loc))
if (borderRad <= minVal) { // return loc;
minVal = Default.getMinRad(); // // quadrant = rn.nextInt(4);
if (borderRad <= minVal) // //}
minVal = 0; // //return null;
} // }
switch (world_type) { //
case NETHER: // //NORMAL
loc = nether(borderRad, minVal, CenterX, CenterZ, quadrant, world, pWorld, yaw, pitch); break; // private Location normal(int borderRad, int minVal, int CenterX, int CenterZ, int quadrant, World world,
default: // PlayerWorld pWorld, Float yaw, Float pitch) {
loc = normal(borderRad, minVal, CenterX, CenterZ, quadrant, world, pWorld, yaw, pitch); // int x, x2, z, z2;
} // Location loc;
pWorld.addAttempt(); // // Will Check is CenterZ is negative or positive, then set 2 x's
if (loc != null && checkDepends(loc)) // // up for choosing up next
return loc; // z = rn.nextInt(borderRad - minVal) + CenterZ + minVal;
quadrant = rn.nextInt(4); // z2 = -(rn.nextInt(borderRad - minVal) - CenterZ - minVal);
} // // Will Check is CenterZ is negative or positive, then set 2 z's
return null; // // up for choosing up next
} // x = rn.nextInt(borderRad - minVal) + CenterX + minVal;
// x2 = -rn.nextInt(borderRad - minVal) + CenterX - minVal;
//NORMAL // switch (quadrant) {
private Location normal(int borderRad, int minVal, int CenterX, int CenterZ, int quadrant, World world, // case 0: // Positive X and Z
PlayerWorld pWorld, Float yaw, Float pitch) { // loc = getLocAtNormal(x, z, world, yaw, pitch, pWorld); break;
int x, x2, z, z2; // case 1: // Negative X and Z
Location loc; // loc = getLocAtNormal(x2, z2, world, yaw, pitch, pWorld); break;
// Will Check is CenterZ is negative or positive, then set 2 x's // case 2: // Negative X and Positive Z
// up for choosing up next // loc = getLocAtNormal(x2, z, world, yaw, pitch, pWorld); break;
z = rn.nextInt(borderRad - minVal) + CenterZ + minVal; // default: // Positive X and Negative Z
z2 = -(rn.nextInt(borderRad - minVal) - CenterZ - minVal); // loc = getLocAtNormal(x, z2, world, yaw, pitch, pWorld);
// Will Check is CenterZ is negative or positive, then set 2 z's // }
// up for choosing up next // return loc;
x = rn.nextInt(borderRad - minVal) + CenterX + minVal; // }
x2 = -rn.nextInt(borderRad - minVal) + CenterX - minVal;
switch (quadrant) {
case 0: // Positive X and Z
loc = getLocAtNormal(x, z, world, yaw, pitch, pWorld); break;
case 1: // Negative X and Z
loc = getLocAtNormal(x2, z2, world, yaw, pitch, pWorld); break;
case 2: // Negative X and Positive Z
loc = getLocAtNormal(x2, z, world, yaw, pitch, pWorld); break;
default: // Positive X and Negative Z
loc = getLocAtNormal(x, z2, world, yaw, pitch, pWorld);
}
return loc;
}
private Location getLocAtNormal(int x, int z, World world, Float yaw, Float pitch, PlayerWorld pWorld) { private Location getLocAtNormal(int x, int z, World world, Float yaw, Float pitch, PlayerWorld pWorld) {
Block b = world.getHighestBlockAt(x, z); Block b = world.getHighestBlockAt(x, z);
@ -287,31 +302,31 @@ public class RTP {
return null; return null;
} }
//NETHER // //NETHER
private Location nether(int borderRad, int minVal, int CenterX, int CenterZ, int quadrant, World world, // private Location nether(int borderRad, int minVal, int CenterX, int CenterZ, int quadrant, World world,
PlayerWorld pWorld, Float yaw, Float pitch) { // PlayerWorld pWorld, Float yaw, Float pitch) {
int x, x2, z, z2; // int x, x2, z, z2;
Location loc; // Location loc;
// Will Check is CenterZ is negative or positive, then set 2 x's // // Will Check is CenterZ is negative or positive, then set 2 x's
// up for choosing up next // // up for choosing up next
z = rn.nextInt((borderRad) - minVal) + CenterZ + minVal; // z = rn.nextInt((borderRad) - minVal) + CenterZ + minVal;
z2 = -(rn.nextInt(borderRad - minVal) - CenterZ - minVal); // z2 = -(rn.nextInt(borderRad - minVal) - CenterZ - minVal);
// Will Check is CenterZ is negative or positive, then set 2 z's // // Will Check is CenterZ is negative or positive, then set 2 z's
// up for choosing up next // // up for choosing up next
x = rn.nextInt(borderRad - minVal) + CenterX + minVal; // x = rn.nextInt(borderRad - minVal) + CenterX + minVal;
x2 = -rn.nextInt(borderRad - minVal) + CenterX - minVal; // x2 = -rn.nextInt(borderRad - minVal) + CenterX - minVal;
switch (quadrant) { // switch (quadrant) {
case 0: // Positive X and Z // case 0: // Positive X and Z
loc = getLocAtNether(x, z, world, yaw, pitch, pWorld); break; // loc = getLocAtNether(x, z, world, yaw, pitch, pWorld); break;
case 1: // Negative X and Z // case 1: // Negative X and Z
loc = getLocAtNether(x2, z2, world, yaw, pitch, pWorld); break; // loc = getLocAtNether(x2, z2, world, yaw, pitch, pWorld); break;
case 2: // Negative X and Positive Z // case 2: // Negative X and Positive Z
loc = getLocAtNether(x2, z, world, yaw, pitch, pWorld); break; // loc = getLocAtNether(x2, z, world, yaw, pitch, pWorld); break;
default: // Positive X and Negative Z // default: // Positive X and Negative Z
loc = getLocAtNether(x, z2, world, yaw, pitch, pWorld); // loc = getLocAtNether(x, z2, world, yaw, pitch, pWorld);
} // }
return loc; // return loc;
} // }
private Location getLocAtNether(int x, int z, World world, Float yaw, Float pitch, PlayerWorld pWorld) { private Location getLocAtNether(int x, int z, World world, Float yaw, Float pitch, PlayerWorld pWorld) {
//System.out.println("-----------"); //System.out.println("-----------");
@ -356,14 +371,14 @@ public class RTP {
} }
// Bad blocks, or bad biome // Bad blocks, or bad biome
private boolean badBlock(String block, int x, int z, String world, List<String> biomes) { private boolean badBlock(String block, int x, int z, World world, List<String> biomes) {
for (String currentBlock : blockList) //Check Block for (String currentBlock : blockList) //Check Block
if (currentBlock.toUpperCase().equals(block)) if (currentBlock.toUpperCase().equals(block))
return true; return true;
//Check Biomes //Check Biomes
if (biomes == null || biomes.isEmpty()) if (biomes == null || biomes.isEmpty())
return false; return false;
String biomeCurrent = Bukkit.getWorld(world).getBiome(x, z).name(); String biomeCurrent = world.getBiome(x, z).name();
for (String biome : biomes) for (String biome : biomes)
if (biomeCurrent.toUpperCase().contains(biome.toUpperCase())) if (biomeCurrent.toUpperCase().contains(biome.toUpperCase()))
return false; return false;

View File

@ -3,7 +3,6 @@ package me.SuperRonanCraft.BetterRTP.player.rtp;
import me.SuperRonanCraft.BetterRTP.references.worlds.PlayerWorld; import me.SuperRonanCraft.BetterRTP.references.worlds.PlayerWorld;
import me.SuperRonanCraft.BetterRTP.Main; import me.SuperRonanCraft.BetterRTP.Main;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -92,7 +91,7 @@ class RTPDelay implements Listener {
HandlerList.unregisterAll(cls); HandlerList.unregisterAll(cls);
if (getPl().getCmd().rtping.containsKey(pWorld.getPlayer().getUniqueId())) { if (getPl().getCmd().rtping.containsKey(pWorld.getPlayer().getUniqueId())) {
try { try {
getPl().getRTP().tp(sendi, pWorld); getPl().getRTP().findSafeLocation(sendi, pWorld);
} catch (NullPointerException e) { } catch (NullPointerException e) {
if (pWorld.getPrice() > 0) if (pWorld.getPrice() > 0)
getPl().getEco().unCharge(pWorld.getPlayer(), pWorld.getPrice()); getPl().getEco().unCharge(pWorld.getPlayer(), pWorld.getPrice());

View File

@ -3,6 +3,7 @@ package me.SuperRonanCraft.BetterRTP.references.worlds;
import me.SuperRonanCraft.BetterRTP.Main; import me.SuperRonanCraft.BetterRTP.Main;
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics; import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -31,34 +32,34 @@ public class Custom implements RTPWorld {
continue; continue;
if (test.get("UseWorldBorder") != null) { if (test.get("UseWorldBorder") != null) {
if (test.get("UseWorldBorder").getClass() == Boolean.class) if (test.get("UseWorldBorder").getClass() == Boolean.class)
useWorldborder = Boolean.valueOf(test.get("UseWorldBorder").toString()); useWorldborder = Boolean.parseBoolean(test.get("UseWorldBorder").toString());
} }
if (test.get("CenterX") != null) { if (test.get("CenterX") != null) {
if (test.get("CenterX").getClass() == Integer.class) if (test.get("CenterX").getClass() == Integer.class)
CenterX = Integer.valueOf((test.get("CenterX")).toString()); CenterX = Integer.parseInt((test.get("CenterX")).toString());
} }
if (test.get("CenterZ") != null) { if (test.get("CenterZ") != null) {
if (test.get("CenterZ").getClass() == Integer.class) if (test.get("CenterZ").getClass() == Integer.class)
CenterZ = Integer.valueOf((test.get("CenterZ")).toString()); CenterZ = Integer.parseInt((test.get("CenterZ")).toString());
} }
if (test.get("MaxRadius") != null) { if (test.get("MaxRadius") != null) {
if (test.get("MaxRadius").getClass() == Integer.class) if (test.get("MaxRadius").getClass() == Integer.class)
maxBorderRad = Integer.valueOf((test.get("MaxRadius")).toString()); maxBorderRad = Integer.parseInt((test.get("MaxRadius")).toString());
if (maxBorderRad <= 0) { if (maxBorderRad <= 0) {
Main.getInstance().getText().sms(Bukkit.getConsoleSender(), Main.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Custom world '" + world + "' Maximum radius of '" + maxBorderRad + "' is not allowed! Set to default value!"); "WARNING! Custom world '" + world + "' Maximum radius of '" + maxBorderRad + "' is not allowed! Set to default value!");
maxBorderRad = Main.getInstance().getRTP().Default.getMaxRad(); maxBorderRad = Main.getInstance().getRTP().defaultWorld.getMaxRad();
} }
} }
if (test.get("MinRadius") != null) { if (test.get("MinRadius") != null) {
if (test.get("MinRadius").getClass() == Integer.class) if (test.get("MinRadius").getClass() == Integer.class)
minBorderRad = Integer.valueOf((test.get("MinRadius")).toString()); minBorderRad = Integer.parseInt((test.get("MinRadius")).toString());
if (minBorderRad < 0 || minBorderRad >= maxBorderRad) { if (minBorderRad < 0 || minBorderRad >= maxBorderRad) {
Main.getInstance().getText().sms(Bukkit.getConsoleSender(), Main.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Custom world '" + world + "' Minimum radius of '" + minBorderRad + "' is not allowed! Set to default value!"); "WARNING! Custom world '" + world + "' Minimum radius of '" + minBorderRad + "' is not allowed! Set to default value!");
minBorderRad = Main.getInstance().getRTP().Default.getMinRad(); minBorderRad = Main.getInstance().getRTP().defaultWorld.getMinRad();
if (minBorderRad >= maxBorderRad) if (minBorderRad >= maxBorderRad)
maxBorderRad = Main.getInstance().getRTP().Default.getMaxRad(); maxBorderRad = Main.getInstance().getRTP().defaultWorld.getMaxRad();
} }
} }
if (test.get("Biomes") != null) { if (test.get("Biomes") != null) {
@ -100,7 +101,7 @@ public class Custom implements RTPWorld {
price = Integer.valueOf((test.get("Price")).toString()); price = Integer.valueOf((test.get("Price")).toString());
} }
} else } else
price = Main.getInstance().getRTP().Default.getPrice(); price = Main.getInstance().getRTP().defaultWorld.getPrice();
//Other //Other
this.Biomes = config.getStringList(pre + world + ".Biomes"); this.Biomes = config.getStringList(pre + world + ".Biomes");
} }
@ -141,7 +142,7 @@ public class Custom implements RTPWorld {
} }
@Override @Override
public String getWorld() { public World getWorld() {
return world; return Bukkit.getWorld(world);
} }
} }

View File

@ -4,6 +4,7 @@ package me.SuperRonanCraft.BetterRTP.references.worlds;
import me.SuperRonanCraft.BetterRTP.Main; import me.SuperRonanCraft.BetterRTP.Main;
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics; import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -78,7 +79,7 @@ public class Default implements RTPWorld {
} }
@Override @Override
public String getWorld() { public World getWorld() {
return null; return null;
} }
} }

View File

@ -1,18 +1,23 @@
package me.SuperRonanCraft.BetterRTP.references.worlds; package me.SuperRonanCraft.BetterRTP.references.worlds;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
public class PlayerWorld implements RTPWorld { public class PlayerWorld implements RTPWorld {
private boolean useWorldborder; private boolean useWorldborder;
private int CenterX, CenterZ, maxBorderRad, minBorderRad, price, attempts; private int CenterX, CenterZ, maxBorderRad, minBorderRad, price, attempts;
private List<String> Biomes; private List<String> Biomes;
private Player p; private Player p;
private String world; private World world;
private RTP_WORLD_TYPE world_type;
public PlayerWorld(Player p, String world) { public PlayerWorld(Player p, World world) {
this.p = p; this.p = p;
this.world = world; this.world = world;
} }
@ -34,7 +39,59 @@ public class PlayerWorld implements RTPWorld {
return p; return p;
} }
public String getWorld() { public Location generateRandomXZ(Default defaultWorld, int quadrant) {
int borderRad = getMaxRad();
int minVal = getMinRad();
int CenterX = getCenterX();
int CenterZ = getCenterZ();
//int quadrant = rn.nextInt(4);
Player p = getPlayer();
World world = getWorld();
if (getUseWorldborder()) {
WorldBorder border = world.getWorldBorder();
borderRad = (int) border.getSize() / 2;
CenterX = border.getCenter().getBlockX();
CenterZ = border.getCenter().getBlockZ();
}
float yaw = p.getLocation().getYaw(), pitch = p.getLocation().getPitch();
RTP_WORLD_TYPE world_type = this.world_type; //World rtp type
//for (int i = 0; i <= maxAttempts; i++) {
// Get the y-coords from up top, then check if it's SAFE!
if (borderRad <= minVal) {
minVal = defaultWorld.getMinRad();
if (borderRad <= minVal)
minVal = 0;
}
// Will Check is CenterZ is negative or positive, then set 2 x's
// up for choosing up next
////z = rn.nextInt(borderRad - minVal) + CenterZ + minVal;
////z2 = -(rn.nextInt(borderRad - minVal) - CenterZ - minVal);
// Will Check is CenterZ is negative or positive, then set 2 z's
// up for choosing up next
////x = rn.nextInt(borderRad - minVal) + CenterX + minVal;
////x2 = -rn.nextInt(borderRad - minVal) + CenterX - minVal;
int x = borderRad - minVal;
int z = borderRad - minVal;
switch (quadrant) {
case 0: // Positive X and Z
x = new Random().nextInt(x) + CenterX + minVal;
z = new Random().nextInt(z) + CenterZ + minVal; break;
case 1: // Negative X and Z
x = -new Random().nextInt(x) + CenterX - minVal;
z = -(new Random().nextInt(z) + CenterZ + minVal); break;
case 2: // Negative X and Positive Z
x = -new Random().nextInt(x) + CenterX - minVal;
z = new Random().nextInt(z) + CenterZ + minVal; break;
default: // Positive X and Negative Z
x = new Random().nextInt(x) + CenterX + minVal;
z = -(new Random().nextInt(z) + CenterZ + minVal); break;
}
addAttempt();
return new Location(world, x, 0, z);
}
@Override
public World getWorld() {
return world; return world;
} }
@ -104,6 +161,15 @@ public class PlayerWorld implements RTPWorld {
} }
private void setBiomes(List<String> biomes) { private void setBiomes(List<String> biomes) {
Biomes = biomes; this.Biomes = biomes;
}
//Custom World type
public void setWorldtype(RTP_WORLD_TYPE type) {
this.world_type = type;
}
public RTP_WORLD_TYPE getWorldtype() {
return this.world_type;
} }
} }

View File

@ -1,5 +1,7 @@
package me.SuperRonanCraft.BetterRTP.references.worlds; package me.SuperRonanCraft.BetterRTP.references.worlds;
import org.bukkit.World;
import java.util.List; import java.util.List;
public interface RTPWorld { public interface RTPWorld {
@ -18,5 +20,5 @@ public interface RTPWorld {
List<String> getBiomes(); List<String> getBiomes();
String getWorld(); World getWorld();
} }

View File

@ -1,5 +1,5 @@
main: me.SuperRonanCraft.BetterRTP.Main main: me.SuperRonanCraft.BetterRTP.Main
version: '2.12.0' version: '2.12.1'
name: BetterRTP name: BetterRTP
author: SuperRonanCraft author: SuperRonanCraft
softdepend: [Vault, WorldGuard, GriefPrevention, Factions] softdepend: [Vault, WorldGuard, GriefPrevention, Factions]