diff --git a/pom.xml b/pom.xml index d835ddc..6a9190e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ me.SuperRonanCraft BetterRTP jar - 3.4.1 + 3.4.2 1.8 @@ -264,7 +264,7 @@ com.github.cryptomorin kingdoms - 1.12.3 + 1.12.6.1 provided @@ -321,6 +321,12 @@ EssentialsX 2.19.0 provided + + + org.bstats + bstats-bukkit + + diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPlayer.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPlayer.java index 59df5c6..2201c85 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPlayer.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPlayer.java @@ -1,6 +1,7 @@ package me.SuperRonanCraft.BetterRTP.player.rtp; import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_FindLocationEvent; +import me.SuperRonanCraft.BetterRTP.references.rtpinfo.QueueHandler; import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WORLD_TYPE; import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPlayer; import io.papermc.lib.PaperLib; @@ -62,8 +63,10 @@ public class RTPPlayer { tpLoc.setPitch(p.getLocation().getPitch()); settings.teleport.sendPlayer(sendi, p, tpLoc, pWorld.getPrice(), attempts, type, pWorld.getWorldtype()); } - } else + } else { randomlyTeleport(sendi); + QueueHandler.remove(loc); + } }); } } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/helpers/HelperRTP.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/helpers/HelperRTP.java index 0d8a164..a240632 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/helpers/HelperRTP.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/helpers/HelperRTP.java @@ -88,7 +88,9 @@ public class HelperRTP { //Cooldown Data CooldownData cooldownData = getPl().getCooldowns().get(player, setupInfo.getWorld()); if (cooldownData != null) { - if (cooldownHandler.locked(player)) { //Infinite cooldown (locked) + if (cooldownData.getTime() == 0) //Global cooldown with nothing + return true; + else if (cooldownHandler.locked(player)) { //Infinite cooldown (locked) getPl().getText().getNoPermission(sendi); return false; } else { //Normal cooldown diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/CooldownHandler.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/CooldownHandler.java index 562ca1d..bc0df21 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/CooldownHandler.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/CooldownHandler.java @@ -111,7 +111,7 @@ public class CooldownHandler { if (!enabled) return; PlayerData playerData = getData(player); CooldownData cooldownData = playerData.getCooldowns().getOrDefault(world, null); - if (cooldownData != null) + if (cooldownData != null) { if (lockedAfter > 0) { //uses.put(id, uses.getOrDefault(id, 1) - 1); if (playerData.getRtpCount() <= 0) { //Remove from file as well @@ -124,6 +124,10 @@ public class CooldownHandler { getData(player).getCooldowns().remove(world); savePlayer(player, world, cooldownData, true); } + } else if (!cooldownByWorld) { + getData(player).setGlobalCooldown(0); + savePlayer(player, null, null, true); + } } private void savePlayer(Player player, @Nullable World world, @Nullable CooldownData data, boolean remove) { 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 efad289..67f22e1 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/QueueHandler.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/rtpinfo/QueueHandler.java @@ -30,7 +30,6 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l private boolean generating; private BukkitTask task; - public void registerEvents(BetterRTP pl) { PluginManager pm = pl.getServer().getPluginManager(); pm.registerEvents(this, pl); @@ -55,7 +54,6 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l queueList.clear(); //LOAD FROM DATABASE Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> { - if (!DatabaseHandler.getQueue().isLoaded()) { queueDownload(); return; @@ -87,33 +85,11 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l //Delete previously used location Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> { Location location = e.getLocation(); - List deleteList = new ArrayList<>(); - for (QueueData data : queueList) { - Location dataLoc = data.getLocation(); - //BetterRTP.debug("--"); - //BetterRTP.debug(location.getBlockX() + " -> " + dataLoc.getBlockX()); - //BetterRTP.debug(location.getBlockZ() + " -> " + dataLoc.getBlockZ()); - if (location.getBlockX() == dataLoc.getBlockX() - && location.getBlockZ() == dataLoc.getBlockZ() - && location.getWorld().getName().equals(dataLoc.getWorld().getName())) { - deleteList.add(data); - } - } - deleteList.forEach(data -> { - if (DatabaseHandler.getQueue().removeQueue(data)) { - queueList.remove(data); - BetterRTP.debug("-Removed a queue " + data.getLocation().toString()); - } - }); + QueueHandler.remove(location); }); } - private void queueGenerator(RTPWorld rtpWorld, int queueMax, int queueMin, int lastCount, @NonNull String lastType, int attempts) { - /*if (queueList.size() >= queueSize) { - //Plenty of locations, cancel out - return; - }*/ generating = true; task = Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> { //Generate more locations @@ -137,6 +113,7 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l BetterRTP.debug("Queue max reached for " + type + " (amount: " + applicable.size() + ") lastCount: " + lastCount); } + //Queue up all setup types for (RTP_SETUP_TYPE setup : RTP_SETUP_TYPE.values()) { HashMap map = getFromSetup(setup); if (map == null) continue; @@ -159,70 +136,6 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l BetterRTP.debug("Max queue reached for " + type + " (amount: " + applicable.size() + ") lastCount: " + lastCount); } } - - //Generate Defaults - /*WorldDefault worldDefault = BetterRTP.getInstance().getRTP().RTPdefaultWorld; - for (World world : Bukkit.getWorlds()) { - if (!BetterRTP.getInstance().getRTP().getDisabledWorlds().contains(world.getName()) - && !BetterRTP.getInstance().getRTP().RTPcustomWorld.containsKey(world.getName())) { - RTPWorld newWorld = new WorldCustom(world, worldDefault); - List applicable = getApplicable(newWorld); - String type = "default_" + world.getName(); - int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size(); - int attempt = lastType.equalsIgnoreCase(type) ? attempts + 1 : 0; - if (newCount < queueMin && applicable.size() < queueMax) { - if (attempt > queueMaxAttempts) { - BetterRTP.debug("Max attempts to create a Queue reached for " + type + " (amount: " + applicable.size() + ") world: " + world.getName()); - continue; - } - generateFromWorld(newWorld); - queueGenerator(null, queueMax, queueMin, newCount, type, attempt); //Generate another later - return; - } - if (lastType.equalsIgnoreCase(type)) - BetterRTP.debug("Queue max reached for " + type + " (amount: " + applicable.size() + ") world: " + world.getName() + " lastCount: " + lastCount); - } - } - - //Generate Custom Worlds - for (Map.Entry customWorld : BetterRTP.getInstance().getRTP().RTPcustomWorld.entrySet()) { - RTPWorld world = customWorld.getValue(); - List applicable = getApplicable(world); - String type = "custom_" + customWorld.getKey(); - int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size(); - int attempt = lastType.equalsIgnoreCase(type) ? attempts + 1 : 0; - if (newCount < queueMin && applicable.size() < queueMax) { - if (attempt > queueMaxAttempts) { - BetterRTP.debug("Max attempts to create a Queue reached for " + type + " (amount:" + applicable.size() + ") " + customWorld.getValue().getWorld().getName()); - continue; - } - generateFromWorld(world); - queueGenerator(null, queueMax, queueMin, newCount, type, attempt); //Generate another later - return; - } - if (lastType.equalsIgnoreCase(type)) - BetterRTP.debug("Queue max reached for " + type + " (amount: " + applicable.size() + ") " + customWorld.getValue().getWorld().getName() + " lastCount: " + lastCount); - } - - //Generate Locations - for (Map.Entry location : BetterRTP.getInstance().getRTP().RTPworldLocations.entrySet()) { - RTPWorld world = location.getValue(); - List applicable = getApplicable(world); - String type = "location_" + location.getValue().getID(); - int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size(); - int attempt = lastType.equalsIgnoreCase(type) ? attempts + 1 : 0; - if (newCount < queueMin && applicable.size() < queueMax) { - if (attempt > queueMaxAttempts) { - BetterRTP.debug("Max attempts to create a Queue reached for " + type + " " + applicable.size() + " " + location.getValue().getID()); - continue; - } - generateFromWorld(world); - queueGenerator(null, queueMax, queueMin, newCount, type, attempt); //Generate another later - return; - } - if (lastType.equalsIgnoreCase(type)) - BetterRTP.debug("Queue max reached for " + type + " " + applicable.size() + " " + location.getValue().getID() + " lastCount: " + lastCount); - }*/ generating = false; BetterRTP.debug("Queueing paused, max queue limit reached!"); }, 20L * 5 /*delay before starting queue generator*/); @@ -279,18 +192,7 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l return true; } else BetterRTP.debug("Database error occured for a queue! " + data.getLocation().toString()); - } else if (data.getLocation() != null) { - /*BetterRTP.debug("Queue position wasn't safe " + data.getLocation().toString()); - if (BetterRTP.getInstance().getSettings().isDebug()) { - Logger log = BetterRTP.getInstance().getLogger(); - log.info("- CenterX: " + rtpWorld.getCenterX()); - log.info("- CenterZ: " + rtpWorld.getCenterZ()); - log.info("- MaxRadius: " + rtpWorld.getMaxRadius()); - log.info("- MinRadius: " + rtpWorld.getMinRadius()); - log.info("- MinY: " + rtpWorld.getMinY()); - log.info("- MaxY: " + rtpWorld.getMaxY()); - }*/ - } else + } else if (data.getLocation() == null) BetterRTP.debug("Queue position wasn't able to generate a location!"); return false; } @@ -299,10 +201,8 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l List queueData = BetterRTP.getInstance().getQueue().queueList; List available = new ArrayList<>(); for (QueueData data : queueData) { - if (!Objects.equals(data.getLocation().getWorld().getName(), rtpWorld.getWorld().getName())) { - //BetterRTP.getInstance().getLogger().info(data.getLocation().getWorld().getName() + " != " + rtpWorld.getWorld().getName()); + if (!Objects.equals(data.getLocation().getWorld().getName(), rtpWorld.getWorld().getName())) continue; - } switch (rtpWorld.getShape()) { case CIRCLE: if (isInCircle(data.location, rtpWorld)) @@ -330,6 +230,28 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l return BetterRTP.getInstance().getQueue().queueList.size(); } + public static void remove(Location loc) { + List deleteList = new ArrayList<>(); + for (QueueData data : BetterRTP.getInstance().getQueue().queueList) { + Location dataLoc = data.getLocation(); + if (loc.getBlockX() == dataLoc.getBlockX() + && loc.getBlockZ() == dataLoc.getBlockZ() + && loc.getWorld().getName().equals(dataLoc.getWorld().getName())) { + deleteList.add(data); + } + } + + Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> { + deleteList.forEach(data -> { + //Delete all queue data async + if (DatabaseHandler.getQueue().removeQueue(data)) { + BetterRTP.getInstance().getQueue().queueList.remove(data); + BetterRTP.debug("-Removed a queue " + data.getLocation().toString()); + } + }); + }); + } + private static boolean isInCircle(Location loc, RTPWorld rtpWorld) { int center_x = rtpWorld.getCenterX(); int center_z = rtpWorld.getCenterZ(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1f19ef6..e818b6e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -42,6 +42,7 @@ Settings: Enabled: true # Enabled or disabled cooldown timer LockAfter: 0 # Lock the player in an infinite cooldown after # rtp's (0 to disable) Time: 600 # in SECONDS + PerWorld: false #Cooldowns handled for each world? If disabled, player cannot rtp in another world until original cooldown has passed ## Time between command and actually rtp'ing, time is in SECONDS. Set to "0" to disable delay timer # Delay: Enabled: true