mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-02-16 02:21:06 +00:00
QueueHandler recode (non-async bukkit api calls)
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>me.SuperRonanCraft</groupId>
|
||||
<artifactId>BetterRTP</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>3.4.3</version>
|
||||
<version>3.4.4</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
|
||||
@@ -16,21 +16,21 @@ import java.util.UUID;
|
||||
public class PlayerInfo {
|
||||
|
||||
private final HashMap<Player, Inventory> invs = new HashMap<>();
|
||||
private final HashMap<Player, RTP_INV_SETTINGS> invType = new HashMap<>();
|
||||
//private final HashMap<Player, RTP_INV_SETTINGS> invType = new HashMap<>();
|
||||
@Getter private final HashMap<Player, World> invWorld = new HashMap<>();
|
||||
@Getter private final HashMap<Player, RTP_INV_SETTINGS> invNextInv = new HashMap<>();
|
||||
private final HashMap<Player, CooldownData> cooldown = new HashMap<>();
|
||||
//private final HashMap<Player, CooldownData> cooldown = new HashMap<>();
|
||||
@Getter private final HashMap<Player, Boolean> rtping = new HashMap<>();
|
||||
private final HashMap<Player, List<Location>> previousLocations = new HashMap<>();
|
||||
//private final HashMap<Player, List<Location>> previousLocations = new HashMap<>();
|
||||
//private final HashMap<Player, RTP_TYPE> rtpType = new HashMap<>();
|
||||
|
||||
private void setInv(Player p, Inventory inv) {
|
||||
/*private void setInv(Player p, Inventory inv) {
|
||||
invs.put(p, inv);
|
||||
}
|
||||
}*/
|
||||
|
||||
private void setInvType(Player p, RTP_INV_SETTINGS type) {
|
||||
/*private void setInvType(Player p, RTP_INV_SETTINGS type) {
|
||||
invType.put(p, type);
|
||||
}
|
||||
}*/
|
||||
|
||||
public void setInvWorld(Player p, World type) {
|
||||
invWorld.put(p, type);
|
||||
@@ -48,24 +48,24 @@ public class PlayerInfo {
|
||||
|
||||
private void unloadAll() {
|
||||
invs.clear();
|
||||
invType.clear();
|
||||
//invType.clear();
|
||||
invWorld.clear();
|
||||
invNextInv.clear();
|
||||
cooldown.clear();
|
||||
//cooldown.clear();
|
||||
rtping.clear();
|
||||
previousLocations.clear();
|
||||
//previousLocations.clear();
|
||||
}
|
||||
|
||||
private void unload(Player p) {
|
||||
clearInvs(p);
|
||||
cooldown.remove(p);
|
||||
//cooldown.remove(p);
|
||||
rtping.remove(p);
|
||||
previousLocations.remove(p);
|
||||
//previousLocations.remove(p);
|
||||
}
|
||||
|
||||
public void clearInvs(Player p) {
|
||||
invs.remove(p);
|
||||
invType.remove(p);
|
||||
//invType.remove(p);
|
||||
invWorld.remove(p);
|
||||
invNextInv.remove(p);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class RTP {
|
||||
//Random Location
|
||||
if (setup_info.getLocation() == null && BetterRTP.getInstance().getSettings().isUseLocationIfAvailable()) {
|
||||
setup_info.setLocation(HelperRTP.getRandomLocation(setup_info.getSender(), setup_info.getWorld()));
|
||||
if (setup_info.getLocation() == null)
|
||||
if (setup_info.getLocation() == null && BetterRTP.getInstance().getSettings().isDebug())
|
||||
WarningHandler.warn(WarningHandler.WARNING.USELOCATION_ENABLED_NO_LOCATION_AVAILABLE,
|
||||
"This is not an error! UseLocationIfAvailable is set to `true`, but no location was found for "
|
||||
+ setup_info.getSender().getName() + "! Using world defaults! (Maybe they dont have permission?)");
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.HashMap;
|
||||
|
||||
public class RTPInventories {
|
||||
|
||||
private HashMap<RTP_INV_SETTINGS, RTPInventory_Defaults> invs = new HashMap<>();
|
||||
private final HashMap<RTP_INV_SETTINGS, RTPInventory_Defaults> invs = new HashMap<>();
|
||||
|
||||
public void load() {
|
||||
invs.clear();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import lombok.NonNull;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.player.commands.RTP_SETUP_TYPE;
|
||||
@@ -10,7 +11,6 @@ import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_TeleportPostEven
|
||||
import me.SuperRonanCraft.BetterRTP.references.database.DatabaseHandler;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.RTPWorld;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldCustom;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldDefault;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -20,6 +20,7 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class QueueHandler implements Listener { //Randomly queues up some safe locations
|
||||
|
||||
@@ -98,15 +99,16 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
||||
List<QueueData> applicable = getApplicable(rtpWorld);
|
||||
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;
|
||||
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() + ")");
|
||||
return;
|
||||
}
|
||||
if (!generateFromWorld(rtpWorld, type)) //If fails to generate position, add an attempt (max amount of times to generate are: queueMaxAttempts + queueMax)
|
||||
attempt ++;
|
||||
|
||||
generateFromWorld(rtpWorld, type); //Generate a location sync to bukkit api
|
||||
queueGenerator(rtpWorld, queueMax, queueMin, newCount, type, attempt); //Generate another later
|
||||
|
||||
return;
|
||||
}
|
||||
if (lastType.equalsIgnoreCase(type))
|
||||
@@ -128,8 +130,9 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
||||
BetterRTP.debug("Max attempts to create a Queue reached for " + type + " (amount: " + applicable.size() + ")");
|
||||
continue;
|
||||
}
|
||||
generateFromWorld(world, type);
|
||||
queueGenerator(null, queueMax, queueMin, newCount, type, attempt); //Generate another later
|
||||
generateFromWorld(world, type); //Generate a location sync to bukkit api
|
||||
queueGenerator(null, queueMax, queueMin, newCount, type, attempt); //Generate another when done later
|
||||
|
||||
return;
|
||||
}
|
||||
if (lastType.equalsIgnoreCase(type))
|
||||
@@ -166,35 +169,35 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
||||
}
|
||||
|
||||
//Generate a safe location
|
||||
private boolean generateFromWorld(RTPWorld world, String id) {
|
||||
private void generateFromWorld(RTPWorld world, String id) {
|
||||
QueueData data = new QueueData(world);
|
||||
return addQueue(world, data, id);
|
||||
addQueue(world, data, id);
|
||||
}
|
||||
|
||||
private boolean addQueue(RTPWorld rtpWorld, QueueData data, String id) {
|
||||
Location loc = null;
|
||||
if (data.getLocation() != null)
|
||||
loc = RTPPlayer.getSafeLocation(
|
||||
RTP.getWorldType(rtpWorld),
|
||||
data.getLocation().getWorld(),
|
||||
data.getLocation(),
|
||||
rtpWorld.getMinY(),
|
||||
rtpWorld.getMaxY(),
|
||||
rtpWorld.getBiomes());
|
||||
if (loc != null) {
|
||||
data.setLocation(loc);
|
||||
if (DatabaseHandler.getQueue().addQueue(data)) {
|
||||
queueList.add(data);
|
||||
String _x = String.valueOf(data.getLocation().getBlockX());
|
||||
String _z = String.valueOf(data.getLocation().getBlockZ());
|
||||
String _world = data.getLocation().getWorld().getName();
|
||||
BetterRTP.debug("Queue position generated id= " + id +", location= x:" + _x + ", z:" + _z + ", world:" + _world);
|
||||
return true;
|
||||
} else
|
||||
BetterRTP.debug("Database error occured for a queue! " + data.getLocation().toString());
|
||||
} else if (data.getLocation() == null)
|
||||
private void addQueue(RTPWorld rtpWorld, QueueData data, String id) {
|
||||
if (data.getLocation() != null) {
|
||||
Bukkit.getScheduler().runTask(BetterRTP.getInstance(), () -> {
|
||||
PaperLib.getChunkAtAsync(data.getLocation()).thenAccept(result -> {
|
||||
Location loc = RTPPlayer.getSafeLocation(
|
||||
RTP.getWorldType(rtpWorld),
|
||||
data.getLocation().getWorld(),
|
||||
data.getLocation(),
|
||||
rtpWorld.getMinY(),
|
||||
rtpWorld.getMaxY(),
|
||||
rtpWorld.getBiomes());
|
||||
data.setLocation(loc);
|
||||
if (DatabaseHandler.getQueue().addQueue(data)) {
|
||||
queueList.add(data);
|
||||
String _x = String.valueOf(data.getLocation().getBlockX());
|
||||
String _z = String.valueOf(data.getLocation().getBlockZ());
|
||||
String _world = data.getLocation().getWorld().getName();
|
||||
BetterRTP.debug("Queue position generated id= " + id + ", location= x:" + _x + ", z:" + _z + ", world:" + _world);
|
||||
} else
|
||||
BetterRTP.debug("Database error occured for a queue! " + data.getLocation().toString());
|
||||
});
|
||||
});
|
||||
} else
|
||||
BetterRTP.debug("Queue position wasn't able to generate a location!");
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<QueueData> getApplicable(RTPWorld rtpWorld) {
|
||||
|
||||
Reference in New Issue
Block a user