From 23343a01d0b24e642bb435cd258c11eaee3f1433 Mon Sep 17 00:00:00 2001 From: SuperRonanCraft Date: Wed, 8 Jun 2022 23:41:15 -0400 Subject: [PATCH] cooldown fix + chunk loading performance --- pom.xml | 2 +- .../SuperRonanCraft/BetterRTP/BetterRTP.java | 1 + .../BetterRTP/player/rtp/RTP.java | 6 +- .../BetterRTP/player/rtp/RTPLoader.java | 2 +- .../BetterRTP/player/rtp/RTPTeleport.java | 54 ++++++------ .../references/rtpinfo/QueueHandler.java | 2 +- .../rtpinfo/worlds/WorldCustom.java | 87 ++++++++----------- .../rtpinfo/worlds/WorldDefault.java | 1 + .../rtpinfo/worlds/WorldLocations.java | 2 +- .../rtpinfo/worlds/WorldPermissionGroup.java | 4 +- 10 files changed, 73 insertions(+), 88 deletions(-) diff --git a/pom.xml b/pom.xml index 8dcb185..2c64fe7 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ me.SuperRonanCraft BetterRTP jar - 3.4.2-2 + 3.4.3 1.8 diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/BetterRTP.java b/src/main/java/me/SuperRonanCraft/BetterRTP/BetterRTP.java index ff2466d..d8f2827 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/BetterRTP.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/BetterRTP.java @@ -42,6 +42,7 @@ public class BetterRTP extends JavaPlugin { @Getter private final DatabaseHandler databaseHandler = new DatabaseHandler(); @Getter private final WarningHandler warningHandler = new WarningHandler(); + @Override public void onEnable() { instance = this; new Updater(this); diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java index 8b933f5..03d74b6 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java @@ -49,11 +49,11 @@ public class RTP { //WorldType RTPLoader.loadWorldTypes(world_type); //Worlds & CustomWorlds - RTPLoader.loadWorlds(RTPdefaultWorld, RTPcustomWorld); + loadWorlds(); //Locations - RTPLoader.loadLocations(RTPworldLocations); + loadLocations(); //Permissions - RTPLoader.loadPermissionGroups(permissionGroups); + loadPermissionGroups(); teleport.load(); //Load teleporting stuff //permConfig.load(); //Load permission configs } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPLoader.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPLoader.java index 24e9264..7abb133 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPLoader.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPLoader.java @@ -31,7 +31,7 @@ public class RTPLoader { exists.set(true); }); if (exists.get()) { - BetterRTP.debug("- Custom World '" + world + "' registered:"); + BetterRTP.debug("Custom World '" + world + "' registered:"); customWorlds.put(world, new WorldCustom(Bukkit.getWorld(world))); } else BetterRTP.debug("[WARN] - Custom World '" + world + "' was not registered because world does NOT exist"); diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPTeleport.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPTeleport.java index a21eda7..3e8c832 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPTeleport.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPTeleport.java @@ -48,36 +48,36 @@ public class RTPTeleport { final int attempts, RTP_TYPE type, WORLD_TYPE worldType) throws NullPointerException { Location oldLoc = p.getLocation(); loadingTeleport(p, sendi); //Send loading message to player who requested - List> asyncChunks = getChunks(location); //Get a list of chunks + //List> asyncChunks = getChunks(location); //Get a list of chunks //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 + @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 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 - public void run() { - afterTeleport(p, loc, price, attempts, oldLoc, type); - 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(); - } + afterTeleport(p, loc, price, attempts, oldLoc, type); + 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 } - }.runTask(getPl()); - }); + }); + } catch (Exception e) { + getPl().getpInfo().getRtping().remove(p); //No longer rtp'ing (errored) + e.printStackTrace(); + } + // } + // }.runTask(getPl()); + //}); } //Effects @@ -130,7 +130,7 @@ public class RTPTeleport { //Processing - private List> getChunks(Location loc) { //List all chunks in range to load + /*private List> getChunks(Location loc) { //List all chunks in range to load List> asyncChunks = new ArrayList<>(); int range = Math.round(Math.max(0, Math.min(16, getPl().getSettings().getPreloadRadius()))); for (int x = -range; x <= range; x++) @@ -140,7 +140,7 @@ public class RTPTeleport { asyncChunks.add(chunk); } return asyncChunks; - } + }*/ private void sendSuccessMsg(CommandSender sendi, String player, Location loc, int price, boolean sameAsPlayer, int attempts) { diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/QueueHandler.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/QueueHandler.java index 67f22e1..3241109 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/QueueHandler.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/QueueHandler.java @@ -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?) if (rtpWorld != null) { List 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 attempt = lastType.equalsIgnoreCase(type) ? attempts : 0; if (newCount < queueMin && applicable.size() < queueMax) { diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldCustom.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldCustom.java index d393232..64affc7 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldCustom.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldCustom.java @@ -39,20 +39,28 @@ public class WorldCustom implements RTPWorld, RTPWorld_Defaulted { if (test == null) continue; 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()); + BetterRTP.debug("- UseWorldBorder: " + this.useWorldborder); + } } 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()); + BetterRTP.debug("- CenterX: " + this.centerX); + } } 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()); + BetterRTP.debug("- CenterZ: " + this.centerZ); + } } 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()); + BetterRTP.debug("- MaxRadius: " + this.maxRad); + } if (maxRad <= 0) { BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(), "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").getClass() == Integer.class) + if (test.get("MinRadius").getClass() == Integer.class) { minRad = Integer.parseInt((test.get("MinRadius")).toString()); + BetterRTP.debug("- MinRadius: " + this.minRad); + } if (minRad < 0 || minRad >= maxRad) { BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(), "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").getClass() == ArrayList.class) + if (test.get("Biomes").getClass() == ArrayList.class) { this.biomes = new ArrayList((ArrayList) test.get("Biomes")); + BetterRTP.debug("- Biomes: " + this.biomes); + } } if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled")) if (test.get("Price") != null) { if (test.get("Price").getClass() == Integer.class) this.price = Integer.parseInt(test.get("Price").toString()); - //else - //price = worldDefault.getPrice(world); - } //else - //price = worldDefault.getPrice(world); + BetterRTP.debug("- Price: " + this.price); + } if (test.get("Shape") != null) { if (test.get("Shape").getClass() == String.class) { try { this.shape = RTP_SHAPE.valueOf(test.get("Shape").toString().toUpperCase()); + BetterRTP.debug("- Shape: " + this.shape); } catch (Exception e) { //Invalid shape } } } if (test.get("MinY") != null) { - if (test.get("MinY").getClass() == Integer.class) - this.miny = Integer.parseInt((test.get("MinY")).toString()); + if (test.get("MinY").getClass() == Integer.class) { + this.miny = Integer.parseInt((test.get("MinY")).toString()); + BetterRTP.debug("- MinY: " + this.miny); + } } if (test.get("MaxY") != null) { - if (test.get("MaxY").getClass() == Integer.class) - this.maxy = Integer.parseInt((test.get("MaxY")).toString()); + if (test.get("MaxY").getClass() == Integer.class) { + this.maxy = Integer.parseInt((test.get("MaxY")).toString()); + BetterRTP.debug("- MaxY: " + this.maxy); + } } if (test.get("Cooldown") != null) { - if (test.get("Cooldown").getClass() == Long.class) - this.cooldown = Long.parseLong((test.get("Cooldown")).toString()); + if (test.get("Cooldown").getClass() == Integer.class || test.get("Cooldown").getClass() == Long.class) { + 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) { BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(), "WARNING! Custom world '" + world + "' Maximum radius of '" + maxRad + "' is not allowed! Set to default value!"); maxRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMaxRadius(); } - //minBorderRad = config.getInt(pre + world + ".MinRadius"); + if (minRad < 0 || minRad >= maxRad) { BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(), "WARNING! Custom world '" + world + "' Minimum radius of '" + minRad + "' is not allowed! Set to default value!"); 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> 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) { diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldDefault.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldDefault.java index 5ede39f..e3b8c46 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldDefault.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldDefault.java @@ -82,6 +82,7 @@ public class WorldDefault implements RTPWorld { log.info("- Price: " + this.price); log.info("- MinY: " + this.miny); log.info("- MaxY: " + this.maxy); + log.info("- Cooldown (default): " + getCooldown()); } } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldLocations.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldLocations.java index a26bac0..67b5202 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldLocations.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldLocations.java @@ -116,7 +116,7 @@ public class WorldLocations implements RTPWorld, RTPWorld_Defaulted { if (test.get("MaxY").getClass() == Integer.class) this.maxy = Integer.parseInt(test.get("MaxY").toString()); 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()); } } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldPermissionGroup.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldPermissionGroup.java index 69a36e8..a472bc7 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldPermissionGroup.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/worlds/WorldPermissionGroup.java @@ -118,9 +118,9 @@ public class WorldPermissionGroup implements RTPWorld, RTPWorld_Defaulted { BetterRTP.debug("- - MaxY: " + maxy); } 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()); - BetterRTP.debug("- - Custom Cooldown: " + cooldown); + BetterRTP.debug("- - Cooldown: " + cooldown); } } }