cooldown fix + chunk loading performance

This commit is contained in:
SuperRonanCraft
2022-06-08 23:41:15 -04:00
parent 2993b595db
commit 23343a01d0
10 changed files with 73 additions and 88 deletions

View File

@@ -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.4.2-2</version> <version>3.4.3</version>
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>

View File

@@ -42,6 +42,7 @@ public class BetterRTP extends JavaPlugin {
@Getter private final DatabaseHandler databaseHandler = new DatabaseHandler(); @Getter private final DatabaseHandler databaseHandler = new DatabaseHandler();
@Getter private final WarningHandler warningHandler = new WarningHandler(); @Getter private final WarningHandler warningHandler = new WarningHandler();
@Override
public void onEnable() { public void onEnable() {
instance = this; instance = this;
new Updater(this); new Updater(this);

View File

@@ -49,11 +49,11 @@ public class RTP {
//WorldType //WorldType
RTPLoader.loadWorldTypes(world_type); RTPLoader.loadWorldTypes(world_type);
//Worlds & CustomWorlds //Worlds & CustomWorlds
RTPLoader.loadWorlds(RTPdefaultWorld, RTPcustomWorld); loadWorlds();
//Locations //Locations
RTPLoader.loadLocations(RTPworldLocations); loadLocations();
//Permissions //Permissions
RTPLoader.loadPermissionGroups(permissionGroups); loadPermissionGroups();
teleport.load(); //Load teleporting stuff teleport.load(); //Load teleporting stuff
//permConfig.load(); //Load permission configs //permConfig.load(); //Load permission configs
} }

View File

@@ -31,7 +31,7 @@ public class RTPLoader {
exists.set(true); exists.set(true);
}); });
if (exists.get()) { if (exists.get()) {
BetterRTP.debug("- Custom World '" + world + "' registered:"); BetterRTP.debug("Custom World '" + world + "' registered:");
customWorlds.put(world, new WorldCustom(Bukkit.getWorld(world))); customWorlds.put(world, new WorldCustom(Bukkit.getWorld(world)));
} else } else
BetterRTP.debug("[WARN] - Custom World '" + world + "' was not registered because world does NOT exist"); BetterRTP.debug("[WARN] - Custom World '" + world + "' was not registered because world does NOT exist");

View File

@@ -48,36 +48,36 @@ public class RTPTeleport {
final int attempts, RTP_TYPE type, WORLD_TYPE worldType) throws NullPointerException { final int attempts, RTP_TYPE type, WORLD_TYPE worldType) throws NullPointerException {
Location oldLoc = p.getLocation(); Location oldLoc = p.getLocation();
loadingTeleport(p, sendi); //Send loading message to player who requested loadingTeleport(p, sendi); //Send loading message to player who requested
List<CompletableFuture<Chunk>> asyncChunks = getChunks(location); //Get a list of chunks //List<CompletableFuture<Chunk>> asyncChunks = getChunks(location); //Get a list of chunks
//playerLoads.put(p, asyncChunks); //playerLoads.put(p, asyncChunks);
CompletableFuture.allOf(asyncChunks.toArray(new CompletableFuture[] {})).thenRun(() -> { //Async chunk load /*CompletableFuture.allOf(asyncChunks.toArray(new CompletableFuture[] {})).thenRun(() -> { //Async chunk load
new BukkitRunnable() { //Run synchronously new BukkitRunnable() { //Run synchronously
@Override
public void run() {*/
try {
RTP_TeleportEvent event = new RTP_TeleportEvent(p, location, worldType);
getPl().getServer().getPluginManager().callEvent(event);
Location loc = event.getLocation();
PaperLib.teleportAsync(p, loc).thenRun(new BukkitRunnable() { //Async teleport
@Override @Override
public void run() { public void run() {
try { afterTeleport(p, loc, price, attempts, oldLoc, type);
RTP_TeleportEvent event = new RTP_TeleportEvent(p, location, worldType); if (sendi != p) //Tell player who requested that the player rtp'd
getPl().getServer().getPluginManager().callEvent(event); sendSuccessMsg(sendi, p.getName(), loc, price, false, attempts);
Location loc = event.getLocation(); getPl().getpInfo().getRtping().remove(p); //No longer rtp'ing
PaperLib.teleportAsync(p, loc).thenRun(new BukkitRunnable() { //Async teleport //Save respawn location if first join
@Override if (type == RTP_TYPE.JOIN) //RTP Type was Join
public void run() { if (BetterRTP.getInstance().getSettings().isRtpOnFirstJoin_SetAsRespawn()) //Save as respawn is enabled
afterTeleport(p, loc, price, attempts, oldLoc, type); p.setBedSpawnLocation(loc, true); //True means to force a respawn even without a valid bed
if (sendi != p) //Tell player who requested that the player rtp'd
sendSuccessMsg(sendi, p.getName(), loc, price, false, attempts);
getPl().getpInfo().getRtping().remove(p); //No longer rtp'ing
//Save respawn location if first join
if (type == RTP_TYPE.JOIN) //RTP Type was Join
if (BetterRTP.getInstance().getSettings().isRtpOnFirstJoin_SetAsRespawn()) //Save as respawn is enabled
p.setBedSpawnLocation(loc, true); //True means to force a respawn even without a valid bed
}
});
} catch (Exception e) {
getPl().getpInfo().getRtping().remove(p); //No longer rtp'ing (errored)
e.printStackTrace();
}
} }
}.runTask(getPl()); });
}); } catch (Exception e) {
getPl().getpInfo().getRtping().remove(p); //No longer rtp'ing (errored)
e.printStackTrace();
}
// }
// }.runTask(getPl());
//});
} }
//Effects //Effects
@@ -130,7 +130,7 @@ public class RTPTeleport {
//Processing //Processing
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().getPreloadRadius()))); int range = Math.round(Math.max(0, Math.min(16, getPl().getSettings().getPreloadRadius())));
for (int x = -range; x <= range; x++) for (int x = -range; x <= range; x++)
@@ -140,7 +140,7 @@ public class RTPTeleport {
asyncChunks.add(chunk); asyncChunks.add(chunk);
} }
return asyncChunks; return asyncChunks;
} }*/
private void sendSuccessMsg(CommandSender sendi, String player, Location loc, int price, boolean sameAsPlayer, private void sendSuccessMsg(CommandSender sendi, String player, Location loc, int price, boolean sameAsPlayer,
int attempts) { int attempts) {

View File

@@ -96,7 +96,7 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
//Rare cases where a rtp world didnt have a location generated (Permission Groups?) //Rare cases where a rtp world didnt have a location generated (Permission Groups?)
if (rtpWorld != null) { if (rtpWorld != null) {
List<QueueData> applicable = getApplicable(rtpWorld); List<QueueData> applicable = getApplicable(rtpWorld);
String type = "superCustom_" + (rtpWorld.getID() != null ? rtpWorld.getID() : rtpWorld.getWorld().getName()); String type = "rtp_" + (rtpWorld.getID() != null ? rtpWorld.getID() : rtpWorld.getWorld().getName());
int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size(); int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size();
int attempt = lastType.equalsIgnoreCase(type) ? attempts : 0; int attempt = lastType.equalsIgnoreCase(type) ? attempts : 0;
if (newCount < queueMin && applicable.size() < queueMax) { if (newCount < queueMin && applicable.size() < queueMax) {

View File

@@ -39,20 +39,28 @@ public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
if (test == null) if (test == null)
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.parseBoolean(test.get("UseWorldBorder").toString()); useWorldborder = Boolean.parseBoolean(test.get("UseWorldBorder").toString());
BetterRTP.debug("- UseWorldBorder: " + this.useWorldborder);
}
} }
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.parseInt((test.get("CenterX")).toString()); centerX = Integer.parseInt((test.get("CenterX")).toString());
BetterRTP.debug("- CenterX: " + this.centerX);
}
} }
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.parseInt((test.get("CenterZ")).toString()); centerZ = Integer.parseInt((test.get("CenterZ")).toString());
BetterRTP.debug("- CenterZ: " + this.centerZ);
}
} }
if (test.get("MaxRadius") != null) { if (test.get("MaxRadius") != null) {
if (test.get("MaxRadius").getClass() == Integer.class) if (test.get("MaxRadius").getClass() == Integer.class) {
maxRad = Integer.parseInt((test.get("MaxRadius")).toString()); maxRad = Integer.parseInt((test.get("MaxRadius")).toString());
BetterRTP.debug("- MaxRadius: " + this.maxRad);
}
if (maxRad <= 0) { if (maxRad <= 0) {
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(), BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Custom world '" + world + "' Maximum radius of '" + maxRad + "' is not allowed! Set to default value!"); "WARNING! Custom world '" + world + "' Maximum radius of '" + maxRad + "' is not allowed! Set to default value!");
@@ -60,8 +68,10 @@ public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
} }
} }
if (test.get("MinRadius") != null) { if (test.get("MinRadius") != null) {
if (test.get("MinRadius").getClass() == Integer.class) if (test.get("MinRadius").getClass() == Integer.class) {
minRad = Integer.parseInt((test.get("MinRadius")).toString()); minRad = Integer.parseInt((test.get("MinRadius")).toString());
BetterRTP.debug("- MinRadius: " + this.minRad);
}
if (minRad < 0 || minRad >= maxRad) { if (minRad < 0 || minRad >= maxRad) {
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(), BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Custom world '" + world + "' Minimum radius of '" + minRad + "' is not allowed! Set to default value!"); "WARNING! Custom world '" + world + "' Minimum radius of '" + minRad + "' is not allowed! Set to default value!");
@@ -71,86 +81,59 @@ public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
} }
} }
if (test.get("Biomes") != null) { if (test.get("Biomes") != null) {
if (test.get("Biomes").getClass() == ArrayList.class) if (test.get("Biomes").getClass() == ArrayList.class) {
this.biomes = new ArrayList<String>((ArrayList) test.get("Biomes")); this.biomes = new ArrayList<String>((ArrayList) test.get("Biomes"));
BetterRTP.debug("- Biomes: " + this.biomes);
}
} }
if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled")) if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled"))
if (test.get("Price") != null) { if (test.get("Price") != null) {
if (test.get("Price").getClass() == Integer.class) if (test.get("Price").getClass() == Integer.class)
this.price = Integer.parseInt(test.get("Price").toString()); this.price = Integer.parseInt(test.get("Price").toString());
//else BetterRTP.debug("- Price: " + this.price);
//price = worldDefault.getPrice(world); }
} //else
//price = worldDefault.getPrice(world);
if (test.get("Shape") != null) { if (test.get("Shape") != null) {
if (test.get("Shape").getClass() == String.class) { if (test.get("Shape").getClass() == String.class) {
try { try {
this.shape = RTP_SHAPE.valueOf(test.get("Shape").toString().toUpperCase()); this.shape = RTP_SHAPE.valueOf(test.get("Shape").toString().toUpperCase());
BetterRTP.debug("- Shape: " + this.shape);
} catch (Exception e) { } catch (Exception e) {
//Invalid shape //Invalid shape
} }
} }
} }
if (test.get("MinY") != null) { if (test.get("MinY") != null) {
if (test.get("MinY").getClass() == Integer.class) if (test.get("MinY").getClass() == Integer.class) {
this.miny = Integer.parseInt((test.get("MinY")).toString()); this.miny = Integer.parseInt((test.get("MinY")).toString());
BetterRTP.debug("- MinY: " + this.miny);
}
} }
if (test.get("MaxY") != null) { if (test.get("MaxY") != null) {
if (test.get("MaxY").getClass() == Integer.class) if (test.get("MaxY").getClass() == Integer.class) {
this.maxy = Integer.parseInt((test.get("MaxY")).toString()); this.maxy = Integer.parseInt((test.get("MaxY")).toString());
BetterRTP.debug("- MaxY: " + this.maxy);
}
} }
if (test.get("Cooldown") != null) { if (test.get("Cooldown") != null) {
if (test.get("Cooldown").getClass() == Long.class) if (test.get("Cooldown").getClass() == Integer.class || test.get("Cooldown").getClass() == Long.class) {
this.cooldown = Long.parseLong((test.get("Cooldown")).toString()); this.cooldown = Long.parseLong((test.get("Cooldown")).toString());
BetterRTP.debug("- Cooldown: " + this.cooldown);
}
} }
} }
} }
//Booleans
/*useWorldborder = config.getBoolean(pre + world + ".UseWorldBorder");
//Integers
CenterX = config.getInt(pre + world + ".CenterX");
CenterZ = config.getInt(pre + world + ".CenterZ");
maxBorderRad = config.getInt(pre + world + ".MaxRadius");*/
if (maxRad <= 0) { if (maxRad <= 0) {
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(), BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Custom world '" + world + "' Maximum radius of '" + maxRad + "' is not allowed! Set to default value!"); "WARNING! Custom world '" + world + "' Maximum radius of '" + maxRad + "' is not allowed! Set to default value!");
maxRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMaxRadius(); maxRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMaxRadius();
} }
//minBorderRad = config.getInt(pre + world + ".MinRadius");
if (minRad < 0 || minRad >= maxRad) { if (minRad < 0 || minRad >= maxRad) {
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(), BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Custom world '" + world + "' Minimum radius of '" + minRad + "' is not allowed! Set to default value!"); "WARNING! Custom world '" + world + "' Minimum radius of '" + minRad + "' is not allowed! Set to default value!");
minRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMinRadius(); minRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMinRadius();
} }
/*if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled"))
if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("CustomWorlds.Enabled")) {
List<Map<?, ?>> world_map = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getMapList("CustomWorlds.Worlds");
for (Map<?, ?> m : world_map)
for (Map.Entry<?, ?> entry : m.entrySet()) {
String _world = entry.getKey().toString();
//System.out.println("Custom World Price " + _world + ":" + entry.getValue().toString());
if (!_world.equals(world))
continue;
if (entry.getValue().getClass() == Integer.class)
price = Integer.parseInt((entry.getValue().toString()));
}
} else
price = worldDefault.getPrice();*/
//Other
//this.Biomes = config.getStringList("CustomWorlds." + world + ".Biomes");
if (BetterRTP.getInstance().getSettings().isDebug()) {
Logger log = BetterRTP.getInstance().getLogger();
log.info("- -World: " + this.world.getName());
log.info("- UseWorldBorder: " + this.useWorldborder);
log.info("- CenterX: " + this.centerX);
log.info("- CenterZ: " + this.centerZ);
log.info("- MaxRadius: " + this.maxRad);
log.info("- MinRadius: " + this.minRad);
log.info("- Price: " + this.price);
log.info("- MinY: " + this.miny);
log.info("- MaxY: " + this.maxy);
}
} }
public WorldCustom(World world, RTPWorld rtpWorld) { public WorldCustom(World world, RTPWorld rtpWorld) {

View File

@@ -82,6 +82,7 @@ public class WorldDefault implements RTPWorld {
log.info("- Price: " + this.price); log.info("- Price: " + this.price);
log.info("- MinY: " + this.miny); log.info("- MinY: " + this.miny);
log.info("- MaxY: " + this.maxy); log.info("- MaxY: " + this.maxy);
log.info("- Cooldown (default): " + getCooldown());
} }
} }

View File

@@ -116,7 +116,7 @@ public class WorldLocations implements RTPWorld, RTPWorld_Defaulted {
if (test.get("MaxY").getClass() == Integer.class) if (test.get("MaxY").getClass() == Integer.class)
this.maxy = Integer.parseInt(test.get("MaxY").toString()); this.maxy = Integer.parseInt(test.get("MaxY").toString());
if (test.get("Cooldown") != null) if (test.get("Cooldown") != null)
if (test.get("Cooldown").getClass() == Long.class) if (test.get("Cooldown").getClass() == Integer.class || test.get("Cooldown").getClass() == Long.class)
this.cooldown = Long.parseLong(test.get("Cooldown").toString()); this.cooldown = Long.parseLong(test.get("Cooldown").toString());
} }
} }

View File

@@ -118,9 +118,9 @@ public class WorldPermissionGroup implements RTPWorld, RTPWorld_Defaulted {
BetterRTP.debug("- - MaxY: " + maxy); BetterRTP.debug("- - MaxY: " + maxy);
} }
if (field.equalsIgnoreCase("Cooldown")) if (field.equalsIgnoreCase("Cooldown"))
if (hash3.getValue().getClass() == Long.class) { if (hash3.getValue().getClass() == Integer.class || hash3.getValue().getClass() == Long.class) {
this.cooldown = Long.parseLong(hash3.getValue().toString()); this.cooldown = Long.parseLong(hash3.getValue().toString());
BetterRTP.debug("- - Custom Cooldown: " + cooldown); BetterRTP.debug("- - Cooldown: " + cooldown);
} }
} }
} }