mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-02-16 02:21:06 +00:00
Unsafe Queues auto removed + Global Cooldown bug
This commit is contained in:
10
pom.xml
10
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>me.SuperRonanCraft</groupId>
|
||||
<artifactId>BetterRTP</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>3.4.1</version>
|
||||
<version>3.4.2</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
@@ -264,7 +264,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.cryptomorin</groupId>
|
||||
<artifactId>kingdoms</artifactId>
|
||||
<version>1.12.3</version>
|
||||
<version>1.12.6.1</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
@@ -321,6 +321,12 @@
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.19.0</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<QueueData> 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<String, RTPWorld> 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<QueueData> 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<String, RTPWorld> customWorld : BetterRTP.getInstance().getRTP().RTPcustomWorld.entrySet()) {
|
||||
RTPWorld world = customWorld.getValue();
|
||||
List<QueueData> 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<String, RTPWorld> location : BetterRTP.getInstance().getRTP().RTPworldLocations.entrySet()) {
|
||||
RTPWorld world = location.getValue();
|
||||
List<QueueData> 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> queueData = BetterRTP.getInstance().getQueue().queueList;
|
||||
List<QueueData> 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<QueueData> 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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user