mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-04-22 16:17:23 +00:00
Removed the requirement of loading all QueueData
This commit is contained in:
@@ -157,7 +157,7 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
|
|||||||
info.add("&7- &6Biomes&7: &f" + _rtpworld.getBiomes().toString());
|
info.add("&7- &6Biomes&7: &f" + _rtpworld.getBiomes().toString());
|
||||||
info.add("&7- &eShape&7: &f" + _rtpworld.getShape().toString() + getInfo(_rtpworld, worldDefault, "shape"));
|
info.add("&7- &eShape&7: &f" + _rtpworld.getShape().toString() + getInfo(_rtpworld, worldDefault, "shape"));
|
||||||
info.add("&7- &6Permission Group&7: " + (_rtpworld.getConfig() != null ? "&a" + _rtpworld.getConfig().getGroupName() : "&cN/A"));
|
info.add("&7- &6Permission Group&7: " + (_rtpworld.getConfig() != null ? "&a" + _rtpworld.getConfig().getGroupName() : "&cN/A"));
|
||||||
info.add("&7- &eQueue Available&7: " + QueueHandler.getApplicableAsync(null, _rtpworld).size());
|
info.add("&7- &eQueue Available&7: " + QueueHandler.getApplicableAsync(_rtpworld).size());
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class CmdQueue implements RTPCommand {
|
|||||||
info.add("&eWorld: &6" + world.getName());
|
info.add("&eWorld: &6" + world.getName());
|
||||||
RTPSetupInformation setup_info = new RTPSetupInformation(HelperRTP.getActualWorld(player, world), player, player, true);
|
RTPSetupInformation setup_info = new RTPSetupInformation(HelperRTP.getActualWorld(player, world), player, player, true);
|
||||||
WorldPlayer pWorld = HelperRTP.getPlayerWorld(setup_info);
|
WorldPlayer pWorld = HelperRTP.getPlayerWorld(setup_info);
|
||||||
for (QueueData queue : QueueHandler.getApplicableAsync(null, pWorld)) {
|
for (QueueData queue : QueueHandler.getApplicableAsync(pWorld)) {
|
||||||
String str = "&8- &7x= &b%x, &7z= &b%z";
|
String str = "&8- &7x= &b%x, &7z= &b%z";
|
||||||
Location loc = queue.getLocation();
|
Location loc = queue.getLocation();
|
||||||
str = str.replace("%x", String.valueOf(loc.getBlockX())).replace("%z", String.valueOf(loc.getBlockZ()));
|
str = str.replace("%x", String.valueOf(loc.getBlockX())).replace("%z", String.valueOf(loc.getBlockZ()));
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class DatabaseQueue extends SQLite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<QueueData> getAll() {
|
/*public List<QueueData> getAll() {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@@ -65,7 +65,7 @@ public class DatabaseQueue extends SQLite {
|
|||||||
long generated = rs.getLong(COLUMNS.GENERATED.name);
|
long generated = rs.getLong(COLUMNS.GENERATED.name);
|
||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
queueDataList.add(new QueueData(new Location(world, x, 69 /*giggity*/, z), generated, id));
|
queueDataList.add(new QueueData(new Location(world, x, 69, z), generated, id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
@@ -74,7 +74,7 @@ public class DatabaseQueue extends SQLite {
|
|||||||
close(ps, rs, conn);
|
close(ps, rs, conn);
|
||||||
}
|
}
|
||||||
return queueDataList;
|
return queueDataList;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public List<QueueData> getInRange(QueueRangeData range) {
|
public List<QueueData> getInRange(QueueRangeData range) {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@@ -85,9 +85,10 @@ public class DatabaseQueue extends SQLite {
|
|||||||
conn = getSQLConnection();
|
conn = getSQLConnection();
|
||||||
//ps = conn.prepareStatement("SELECT * FROM " + tables.get(0) + " WHERE ? BETWEEN ? AND ? AND ? BETWEEN ? AND ?");
|
//ps = conn.prepareStatement("SELECT * FROM " + tables.get(0) + " WHERE ? BETWEEN ? AND ? AND ? BETWEEN ? AND ?");
|
||||||
ps = conn.prepareStatement("SELECT * FROM " + tables.get(0) + " WHERE "
|
ps = conn.prepareStatement("SELECT * FROM " + tables.get(0) + " WHERE "
|
||||||
|
+ COLUMNS.WORLD.name + " = '" + range.getWorld().getName() + "' AND "
|
||||||
+ COLUMNS.X.name + " BETWEEN " + range.getXLow() + " AND " + range.getXHigh()
|
+ COLUMNS.X.name + " BETWEEN " + range.getXLow() + " AND " + range.getXHigh()
|
||||||
+ " AND " + COLUMNS.Z.name + " BETWEEN " + range.getZLow() + " AND " + range.getZHigh()
|
+ " AND " + COLUMNS.Z.name + " BETWEEN " + range.getZLow() + " AND " + range.getZHigh()
|
||||||
+ " ORDER BY " + COLUMNS.ID.name + " DESC LIMIT " + (QueueGenerator.queueMax + 1)
|
+ " ORDER BY RANDOM() LIMIT " + (QueueGenerator.queueMax + 1)
|
||||||
);
|
);
|
||||||
/*ps.setString(1, COLUMNS.X.name);
|
/*ps.setString(1, COLUMNS.X.name);
|
||||||
ps.setInt(2, range.getXLow());
|
ps.setInt(2, range.getXLow());
|
||||||
@@ -205,12 +206,14 @@ public class DatabaseQueue extends SQLite {
|
|||||||
|
|
||||||
@Getter int xLow, xHigh;
|
@Getter int xLow, xHigh;
|
||||||
@Getter int zLow, zHigh;
|
@Getter int zLow, zHigh;
|
||||||
|
@Getter World world;
|
||||||
|
|
||||||
public QueueRangeData(RTPWorld rtpWorld) {
|
public QueueRangeData(RTPWorld rtpWorld) {
|
||||||
this.xLow = rtpWorld.getCenterX() - rtpWorld.getMaxRadius();
|
this.xLow = rtpWorld.getCenterX() - rtpWorld.getMaxRadius();
|
||||||
this.xHigh = rtpWorld.getCenterX() + rtpWorld.getMaxRadius();
|
this.xHigh = rtpWorld.getCenterX() + rtpWorld.getMaxRadius();
|
||||||
this.zLow = rtpWorld.getCenterZ() - rtpWorld.getMaxRadius();
|
this.zLow = rtpWorld.getCenterZ() - rtpWorld.getMaxRadius();
|
||||||
this.zHigh = rtpWorld.getCenterZ() + rtpWorld.getMaxRadius();
|
this.zHigh = rtpWorld.getCenterZ() + rtpWorld.getMaxRadius();
|
||||||
|
this.world = rtpWorld.getWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,18 +51,18 @@ public class QueueGenerator {
|
|||||||
//BetterRTP.debug("Loaded " + queueList.size() + " previously generated safe locations!");
|
//BetterRTP.debug("Loaded " + queueList.size() + " previously generated safe locations!");
|
||||||
//Queue after everything was loaded
|
//Queue after everything was loaded
|
||||||
BetterRTP.debug("Attempting to queue up some more safe locations...");
|
BetterRTP.debug("Attempting to queue up some more safe locations...");
|
||||||
queueGenerator(new ReQueueData(DatabaseHandler.getQueue().getAll(), rtpWorld, queueMax, queueMin, 0, "noone", 0));
|
queueGenerator(new ReQueueData(rtpWorld, queueMax, queueMin, 0, "noone", 0));
|
||||||
}, 10L);
|
}, 10L);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queueGenerator(ReQueueData data) {
|
private void queueGenerator(ReQueueData data) {
|
||||||
generating = true;
|
generating = true;
|
||||||
task = Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
|
task = Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
//BetterRTP.debug("Generating a new position... attemp # " + data.attempts);
|
//BetterRTP.debug("Generating a new position... attempt # " + data.attempts);
|
||||||
//Generate more locations
|
//Generate more locations
|
||||||
//Rare cases where a rtp world didn't have a location generated (Permission Groups?)
|
//Rare cases where a rtp world didn't have a location generated (Permission Groups?)
|
||||||
if (data.rtpWorld != null) {
|
if (data.rtpWorld != null) {
|
||||||
List<QueueData> applicable = QueueHandler.getApplicableAsync(data.queue, data.rtpWorld);
|
List<QueueData> applicable = QueueHandler.getApplicableAsync(data.rtpWorld);
|
||||||
String type = "rtp_" + (data.rtpWorld.getID() != null ? data.rtpWorld.getID() : data.rtpWorld.getWorld().getName());
|
String type = "rtp_" + (data.rtpWorld.getID() != null ? data.rtpWorld.getID() : data.rtpWorld.getWorld().getName());
|
||||||
int newCount = data.lastType.equalsIgnoreCase(type) ? data.lastCount : applicable.size();
|
int newCount = data.lastType.equalsIgnoreCase(type) ? data.lastCount : applicable.size();
|
||||||
int attempt = data.lastType.equalsIgnoreCase(type) ? data.attempts + 1: 0;
|
int attempt = data.lastType.equalsIgnoreCase(type) ? data.attempts + 1: 0;
|
||||||
@@ -72,7 +72,7 @@ public class QueueGenerator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addQueue(data.rtpWorld, type, new ReQueueData(data.queue, data.rtpWorld, queueMax, queueMin, newCount, type, attempt)); //Generate another later
|
addQueue(data.rtpWorld, type, new ReQueueData(data.rtpWorld, queueMax, queueMin, newCount, type, attempt)); //Generate another later
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ public class QueueGenerator {
|
|||||||
for (Map.Entry<String, RTPWorld> rtpWorldEntry : map.entrySet()) {
|
for (Map.Entry<String, RTPWorld> rtpWorldEntry : map.entrySet()) {
|
||||||
RTPWorld world = rtpWorldEntry.getValue();
|
RTPWorld world = rtpWorldEntry.getValue();
|
||||||
String type = getId(setup, rtpWorldEntry.getKey());
|
String type = getId(setup, rtpWorldEntry.getKey());
|
||||||
List<QueueData> applicable = QueueHandler.getApplicableAsync(data.queue, world);
|
List<QueueData> applicable = QueueHandler.getApplicableAsync(world);
|
||||||
int newCount = data.lastType.equalsIgnoreCase(type) ? data.lastCount : applicable.size();
|
int newCount = data.lastType.equalsIgnoreCase(type) ? data.lastCount : applicable.size();
|
||||||
int attempt = data.lastType.equalsIgnoreCase(type) ? data.attempts + 1 : 0;
|
int attempt = data.lastType.equalsIgnoreCase(type) ? data.attempts + 1 : 0;
|
||||||
if (newCount < queueMin && applicable.size() < queueMax) {
|
if (newCount < queueMin && applicable.size() < queueMax) {
|
||||||
@@ -96,7 +96,7 @@ public class QueueGenerator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//Generate a location sync to bukkit api
|
//Generate a location sync to bukkit api
|
||||||
addQueue(world, type, new ReQueueData(data.queue, null, queueMax, queueMin, newCount, type, attempt)); //Generate another when done later
|
addQueue(world, type, new ReQueueData(null, queueMax, queueMin, newCount, type, attempt)); //Generate another when done later
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -111,12 +111,10 @@ public class QueueGenerator {
|
|||||||
|
|
||||||
static class ReQueueData {
|
static class ReQueueData {
|
||||||
|
|
||||||
List<QueueData> queue;
|
|
||||||
RTPWorld rtpWorld;
|
RTPWorld rtpWorld;
|
||||||
int queueMax, queueMin, lastCount, attempts;
|
int queueMax, queueMin, lastCount, attempts;
|
||||||
String lastType;
|
String lastType;
|
||||||
ReQueueData(List<QueueData> queue, RTPWorld rtpWorld, int queueMax, int queueMin, int lastCount, String lastType, int attempts) {
|
ReQueueData(RTPWorld rtpWorld, int queueMax, int queueMin, int lastCount, String lastType, int attempts) {
|
||||||
this.queue = queue;
|
|
||||||
this.rtpWorld = rtpWorld;
|
this.rtpWorld = rtpWorld;
|
||||||
this.queueMax = queueMax;
|
this.queueMax = queueMax;
|
||||||
this.queueMin = queueMin;
|
this.queueMin = queueMin;
|
||||||
|
|||||||
@@ -38,21 +38,23 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onRTP(RTP_TeleportPostEvent e) {
|
public void onRTP(RTP_TeleportPostEvent e) {
|
||||||
//Delete previously used location
|
//Delete previously used location
|
||||||
Location location = e.getLocation();
|
remove(e.getLocation());
|
||||||
remove(location);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static QueueData getRandomAsync(RTPWorld rtpWorld) {
|
public static QueueData getRandomAsync(RTPWorld rtpWorld) {
|
||||||
List<QueueData> queueData = getApplicableAsync(null, rtpWorld);
|
List<QueueData> queueData = getApplicableAsync(rtpWorld);
|
||||||
if (queueData.size() <= QueueGenerator.queueMin && !BetterRTP.getInstance().getQueue().generator.generating)
|
if (queueData.size() <= QueueGenerator.queueMin && !BetterRTP.getInstance().getQueue().generator.generating)
|
||||||
BetterRTP.getInstance().getQueue().generator.generate(rtpWorld);
|
BetterRTP.getInstance().getQueue().generator.generate(rtpWorld);
|
||||||
if (!queueData.isEmpty())
|
if (!queueData.isEmpty()) {
|
||||||
return queueData.get(new Random().nextInt(queueData.size()));
|
QueueData randomQueue = queueData.get(new Random().nextInt(queueData.size()));
|
||||||
|
queueData.clear();
|
||||||
|
return randomQueue;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<QueueData> getApplicableAsync(@Nullable List<QueueData> queueCache, RTPWorld rtpWorld) {
|
public static List<QueueData> getApplicableAsync(RTPWorld rtpWorld) {
|
||||||
List<QueueData> queueData = queueCache == null ? DatabaseHandler.getQueue().getInRange(new DatabaseQueue.QueueRangeData(rtpWorld)) : queueCache;
|
List<QueueData> queueData = DatabaseHandler.getQueue().getInRange(new DatabaseQueue.QueueRangeData(rtpWorld));
|
||||||
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()))
|
||||||
@@ -68,7 +70,7 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
|||||||
available.add(data);
|
available.add(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BetterRTP.getInstance().getLogger().info("Available: " + available.size());
|
//BetterRTP.getInstance().getLogger().info("Available: " + available.size());
|
||||||
return available;
|
return available;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user