mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-10-12 03:24:12 +00:00
Unsafe Queues auto removed + Global Cooldown bug
This commit is contained in:
@@ -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.1</version>
|
<version>3.4.2</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
@@ -264,7 +264,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.cryptomorin</groupId>
|
<groupId>com.github.cryptomorin</groupId>
|
||||||
<artifactId>kingdoms</artifactId>
|
<artifactId>kingdoms</artifactId>
|
||||||
<version>1.12.3</version>
|
<version>1.12.6.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
@@ -321,6 +321,12 @@
|
|||||||
<artifactId>EssentialsX</artifactId>
|
<artifactId>EssentialsX</artifactId>
|
||||||
<version>2.19.0</version>
|
<version>2.19.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
||||||
|
|
||||||
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_FindLocationEvent;
|
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.WORLD_TYPE;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPlayer;
|
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPlayer;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
@@ -62,8 +63,10 @@ public class RTPPlayer {
|
|||||||
tpLoc.setPitch(p.getLocation().getPitch());
|
tpLoc.setPitch(p.getLocation().getPitch());
|
||||||
settings.teleport.sendPlayer(sendi, p, tpLoc, pWorld.getPrice(), attempts, type, pWorld.getWorldtype());
|
settings.teleport.sendPlayer(sendi, p, tpLoc, pWorld.getPrice(), attempts, type, pWorld.getWorldtype());
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
randomlyTeleport(sendi);
|
randomlyTeleport(sendi);
|
||||||
|
QueueHandler.remove(loc);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,9 @@ public class HelperRTP {
|
|||||||
//Cooldown Data
|
//Cooldown Data
|
||||||
CooldownData cooldownData = getPl().getCooldowns().get(player, setupInfo.getWorld());
|
CooldownData cooldownData = getPl().getCooldowns().get(player, setupInfo.getWorld());
|
||||||
if (cooldownData != null) {
|
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);
|
getPl().getText().getNoPermission(sendi);
|
||||||
return false;
|
return false;
|
||||||
} else { //Normal cooldown
|
} else { //Normal cooldown
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public class CooldownHandler {
|
|||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
PlayerData playerData = getData(player);
|
PlayerData playerData = getData(player);
|
||||||
CooldownData cooldownData = playerData.getCooldowns().getOrDefault(world, null);
|
CooldownData cooldownData = playerData.getCooldowns().getOrDefault(world, null);
|
||||||
if (cooldownData != null)
|
if (cooldownData != null) {
|
||||||
if (lockedAfter > 0) {
|
if (lockedAfter > 0) {
|
||||||
//uses.put(id, uses.getOrDefault(id, 1) - 1);
|
//uses.put(id, uses.getOrDefault(id, 1) - 1);
|
||||||
if (playerData.getRtpCount() <= 0) { //Remove from file as well
|
if (playerData.getRtpCount() <= 0) { //Remove from file as well
|
||||||
@@ -124,6 +124,10 @@ public class CooldownHandler {
|
|||||||
getData(player).getCooldowns().remove(world);
|
getData(player).getCooldowns().remove(world);
|
||||||
savePlayer(player, world, cooldownData, true);
|
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) {
|
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 boolean generating;
|
||||||
private BukkitTask task;
|
private BukkitTask task;
|
||||||
|
|
||||||
|
|
||||||
public void registerEvents(BetterRTP pl) {
|
public void registerEvents(BetterRTP pl) {
|
||||||
PluginManager pm = pl.getServer().getPluginManager();
|
PluginManager pm = pl.getServer().getPluginManager();
|
||||||
pm.registerEvents(this, pl);
|
pm.registerEvents(this, pl);
|
||||||
@@ -55,7 +54,6 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
|||||||
queueList.clear();
|
queueList.clear();
|
||||||
//LOAD FROM DATABASE
|
//LOAD FROM DATABASE
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
|
|
||||||
if (!DatabaseHandler.getQueue().isLoaded()) {
|
if (!DatabaseHandler.getQueue().isLoaded()) {
|
||||||
queueDownload();
|
queueDownload();
|
||||||
return;
|
return;
|
||||||
@@ -87,33 +85,11 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
|||||||
//Delete previously used location
|
//Delete previously used location
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
Location location = e.getLocation();
|
Location location = e.getLocation();
|
||||||
List<QueueData> deleteList = new ArrayList<>();
|
QueueHandler.remove(location);
|
||||||
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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void queueGenerator(RTPWorld rtpWorld, int queueMax, int queueMin, int lastCount, @NonNull String lastType, int attempts) {
|
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;
|
generating = true;
|
||||||
task = Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
|
task = Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
//Generate more locations
|
//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);
|
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()) {
|
for (RTP_SETUP_TYPE setup : RTP_SETUP_TYPE.values()) {
|
||||||
HashMap<String, RTPWorld> map = getFromSetup(setup);
|
HashMap<String, RTPWorld> map = getFromSetup(setup);
|
||||||
if (map == null) continue;
|
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);
|
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;
|
generating = false;
|
||||||
BetterRTP.debug("Queueing paused, max queue limit reached!");
|
BetterRTP.debug("Queueing paused, max queue limit reached!");
|
||||||
}, 20L * 5 /*delay before starting queue generator*/);
|
}, 20L * 5 /*delay before starting queue generator*/);
|
||||||
@@ -279,18 +192,7 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
|||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
BetterRTP.debug("Database error occured for a queue! " + data.getLocation().toString());
|
BetterRTP.debug("Database error occured for a queue! " + data.getLocation().toString());
|
||||||
} else if (data.getLocation() != null) {
|
} 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
|
|
||||||
BetterRTP.debug("Queue position wasn't able to generate a location!");
|
BetterRTP.debug("Queue position wasn't able to generate a location!");
|
||||||
return false;
|
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> queueData = BetterRTP.getInstance().getQueue().queueList;
|
||||||
List<QueueData> available = new ArrayList<>();
|
List<QueueData> available = new ArrayList<>();
|
||||||
for (QueueData data : queueData) {
|
for (QueueData data : queueData) {
|
||||||
if (!Objects.equals(data.getLocation().getWorld().getName(), rtpWorld.getWorld().getName())) {
|
if (!Objects.equals(data.getLocation().getWorld().getName(), rtpWorld.getWorld().getName()))
|
||||||
//BetterRTP.getInstance().getLogger().info(data.getLocation().getWorld().getName() + " != " + rtpWorld.getWorld().getName());
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
switch (rtpWorld.getShape()) {
|
switch (rtpWorld.getShape()) {
|
||||||
case CIRCLE:
|
case CIRCLE:
|
||||||
if (isInCircle(data.location, rtpWorld))
|
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();
|
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) {
|
private static boolean isInCircle(Location loc, RTPWorld rtpWorld) {
|
||||||
int center_x = rtpWorld.getCenterX();
|
int center_x = rtpWorld.getCenterX();
|
||||||
int center_z = rtpWorld.getCenterZ();
|
int center_z = rtpWorld.getCenterZ();
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ Settings:
|
|||||||
Enabled: true # Enabled or disabled cooldown timer
|
Enabled: true # Enabled or disabled cooldown timer
|
||||||
LockAfter: 0 # Lock the player in an infinite cooldown after # rtp's (0 to disable)
|
LockAfter: 0 # Lock the player in an infinite cooldown after # rtp's (0 to disable)
|
||||||
Time: 600 # in SECONDS
|
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 #
|
## Time between command and actually rtp'ing, time is in SECONDS. Set to "0" to disable delay timer #
|
||||||
Delay:
|
Delay:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|||||||
Reference in New Issue
Block a user