mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-04-17 22:10:00 +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>
|
<groupId>me.SuperRonanCraft</groupId>
|
||||||
<artifactId>BetterRTP</artifactId>
|
<artifactId>BetterRTP</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>3.4.3</version>
|
<version>3.4.4</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
|||||||
@@ -16,21 +16,21 @@ import java.util.UUID;
|
|||||||
public class PlayerInfo {
|
public class PlayerInfo {
|
||||||
|
|
||||||
private final HashMap<Player, Inventory> invs = new HashMap<>();
|
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, World> invWorld = new HashMap<>();
|
||||||
@Getter private final HashMap<Player, RTP_INV_SETTINGS> invNextInv = 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<>();
|
@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 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);
|
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);
|
invType.put(p, type);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void setInvWorld(Player p, World type) {
|
public void setInvWorld(Player p, World type) {
|
||||||
invWorld.put(p, type);
|
invWorld.put(p, type);
|
||||||
@@ -48,24 +48,24 @@ public class PlayerInfo {
|
|||||||
|
|
||||||
private void unloadAll() {
|
private void unloadAll() {
|
||||||
invs.clear();
|
invs.clear();
|
||||||
invType.clear();
|
//invType.clear();
|
||||||
invWorld.clear();
|
invWorld.clear();
|
||||||
invNextInv.clear();
|
invNextInv.clear();
|
||||||
cooldown.clear();
|
//cooldown.clear();
|
||||||
rtping.clear();
|
rtping.clear();
|
||||||
previousLocations.clear();
|
//previousLocations.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unload(Player p) {
|
private void unload(Player p) {
|
||||||
clearInvs(p);
|
clearInvs(p);
|
||||||
cooldown.remove(p);
|
//cooldown.remove(p);
|
||||||
rtping.remove(p);
|
rtping.remove(p);
|
||||||
previousLocations.remove(p);
|
//previousLocations.remove(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearInvs(Player p) {
|
public void clearInvs(Player p) {
|
||||||
invs.remove(p);
|
invs.remove(p);
|
||||||
invType.remove(p);
|
//invType.remove(p);
|
||||||
invWorld.remove(p);
|
invWorld.remove(p);
|
||||||
invNextInv.remove(p);
|
invNextInv.remove(p);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class RTP {
|
|||||||
//Random Location
|
//Random Location
|
||||||
if (setup_info.getLocation() == null && BetterRTP.getInstance().getSettings().isUseLocationIfAvailable()) {
|
if (setup_info.getLocation() == null && BetterRTP.getInstance().getSettings().isUseLocationIfAvailable()) {
|
||||||
setup_info.setLocation(HelperRTP.getRandomLocation(setup_info.getSender(), setup_info.getWorld()));
|
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,
|
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 "
|
"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?)");
|
+ setup_info.getSender().getName() + "! Using world defaults! (Maybe they dont have permission?)");
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public class RTPInventories {
|
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() {
|
public void load() {
|
||||||
invs.clear();
|
invs.clear();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
|
package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
|
||||||
|
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.commands.RTP_SETUP_TYPE;
|
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.database.DatabaseHandler;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.RTPWorld;
|
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.RTPWorld;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldCustom;
|
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldCustom;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldDefault;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@@ -20,6 +20,7 @@ import org.bukkit.plugin.PluginManager;
|
|||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class QueueHandler implements Listener { //Randomly queues up some safe locations
|
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);
|
List<QueueData> applicable = getApplicable(rtpWorld);
|
||||||
String type = "rtp_" + (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 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 (newCount < queueMin && applicable.size() < queueMax) {
|
||||||
if (attempt > queueMaxAttempts) {
|
if (attempt > queueMaxAttempts) {
|
||||||
BetterRTP.debug("Max attempts to create a Queue reached for " + type + " (amount: " + applicable.size() + ")");
|
BetterRTP.debug("Max attempts to create a Queue reached for " + type + " (amount: " + applicable.size() + ")");
|
||||||
return;
|
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
|
queueGenerator(rtpWorld, queueMax, queueMin, newCount, type, attempt); //Generate another later
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (lastType.equalsIgnoreCase(type))
|
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() + ")");
|
BetterRTP.debug("Max attempts to create a Queue reached for " + type + " (amount: " + applicable.size() + ")");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
generateFromWorld(world, type);
|
generateFromWorld(world, type); //Generate a location sync to bukkit api
|
||||||
queueGenerator(null, queueMax, queueMin, newCount, type, attempt); //Generate another later
|
queueGenerator(null, queueMax, queueMin, newCount, type, attempt); //Generate another when done later
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (lastType.equalsIgnoreCase(type))
|
if (lastType.equalsIgnoreCase(type))
|
||||||
@@ -166,35 +169,35 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Generate a safe location
|
//Generate a safe location
|
||||||
private boolean generateFromWorld(RTPWorld world, String id) {
|
private void generateFromWorld(RTPWorld world, String id) {
|
||||||
QueueData data = new QueueData(world);
|
QueueData data = new QueueData(world);
|
||||||
return addQueue(world, data, id);
|
addQueue(world, data, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean addQueue(RTPWorld rtpWorld, QueueData data, String id) {
|
private void addQueue(RTPWorld rtpWorld, QueueData data, String id) {
|
||||||
Location loc = null;
|
if (data.getLocation() != null) {
|
||||||
if (data.getLocation() != null)
|
Bukkit.getScheduler().runTask(BetterRTP.getInstance(), () -> {
|
||||||
loc = RTPPlayer.getSafeLocation(
|
PaperLib.getChunkAtAsync(data.getLocation()).thenAccept(result -> {
|
||||||
RTP.getWorldType(rtpWorld),
|
Location loc = RTPPlayer.getSafeLocation(
|
||||||
data.getLocation().getWorld(),
|
RTP.getWorldType(rtpWorld),
|
||||||
data.getLocation(),
|
data.getLocation().getWorld(),
|
||||||
rtpWorld.getMinY(),
|
data.getLocation(),
|
||||||
rtpWorld.getMaxY(),
|
rtpWorld.getMinY(),
|
||||||
rtpWorld.getBiomes());
|
rtpWorld.getMaxY(),
|
||||||
if (loc != null) {
|
rtpWorld.getBiomes());
|
||||||
data.setLocation(loc);
|
data.setLocation(loc);
|
||||||
if (DatabaseHandler.getQueue().addQueue(data)) {
|
if (DatabaseHandler.getQueue().addQueue(data)) {
|
||||||
queueList.add(data);
|
queueList.add(data);
|
||||||
String _x = String.valueOf(data.getLocation().getBlockX());
|
String _x = String.valueOf(data.getLocation().getBlockX());
|
||||||
String _z = String.valueOf(data.getLocation().getBlockZ());
|
String _z = String.valueOf(data.getLocation().getBlockZ());
|
||||||
String _world = data.getLocation().getWorld().getName();
|
String _world = data.getLocation().getWorld().getName();
|
||||||
BetterRTP.debug("Queue position generated id= " + id +", location= x:" + _x + ", z:" + _z + ", world:" + _world);
|
BetterRTP.debug("Queue position generated id= " + id + ", location= x:" + _x + ", z:" + _z + ", world:" + _world);
|
||||||
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
|
||||||
BetterRTP.debug("Queue position wasn't able to generate a location!");
|
BetterRTP.debug("Queue position wasn't able to generate a location!");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<QueueData> getApplicable(RTPWorld rtpWorld) {
|
public static List<QueueData> getApplicable(RTPWorld rtpWorld) {
|
||||||
|
|||||||
Reference in New Issue
Block a user