mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-02-16 02:21:06 +00:00
Queue loading improvements
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -118,7 +118,7 @@
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<!-- Github based Repos -->
|
||||
<!-- GitHub based Repos -->
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
@@ -264,7 +264,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.cryptomorin</groupId>
|
||||
<artifactId>kingdoms</artifactId>
|
||||
<version>1.12.6.1</version>
|
||||
<version>1.13.9</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
@@ -312,7 +312,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
<version>1.18.24</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- EssentialsX -->
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references.database;
|
||||
|
||||
import lombok.NonNull;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.QueueData;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -11,6 +12,7 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
@@ -60,12 +62,12 @@ public class DatabaseQueue extends SQLite {
|
||||
long x = rs.getLong(COLUMNS.X.name);
|
||||
long z = rs.getLong(COLUMNS.Z.name);
|
||||
String worldName = rs.getString(COLUMNS.WORLD.name);
|
||||
//String id = rs.getString(COLUMNS.IDENTIFIER.name);
|
||||
int id = rs.getInt(COLUMNS.ID.name);
|
||||
long generated = rs.getLong(COLUMNS.GENERATED.name);
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world != null) {
|
||||
QueueData data = new QueueData(new Location(world, x, 69 /*giggity*/, z), generated);
|
||||
queueDataList.add(data);
|
||||
queueDataList.add(new QueueData(new Location(world, x, 69 /*giggity*/, z), generated, id));
|
||||
//queueDataList.add(data);
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
@@ -77,7 +79,7 @@ public class DatabaseQueue extends SQLite {
|
||||
}
|
||||
|
||||
//Set a queue to save
|
||||
public boolean addQueue(QueueData data) {
|
||||
public QueueData addQueue(Location loc) {
|
||||
String pre = "INSERT INTO ";
|
||||
String sql = pre + tables.get(0) + " ("
|
||||
+ COLUMNS.X.name + ", "
|
||||
@@ -87,13 +89,62 @@ public class DatabaseQueue extends SQLite {
|
||||
//+ COLUMNS.USES.name + " "
|
||||
+ ") VALUES(?, ?, ?, ?)";
|
||||
List<Object> params = new ArrayList<Object>() {{
|
||||
add(data.getLocation().getBlockX());
|
||||
add(data.getLocation().getBlockZ());
|
||||
add(data.getLocation().getWorld().getName());
|
||||
add(data.getGenerated());
|
||||
add(loc.getBlockX());
|
||||
add(loc.getBlockZ());
|
||||
add(loc.getWorld().getName());
|
||||
add(System.currentTimeMillis());
|
||||
//add(data.getUses());
|
||||
}};
|
||||
return sqlUpdate(sql, params);
|
||||
//return sqlUpdate(sql, params);
|
||||
int database_id = createQueue(sql, params);
|
||||
if (database_id >= 0)
|
||||
return new QueueData(loc, System.currentTimeMillis(), database_id);
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
int count = 0;
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + tables.get(0));
|
||||
|
||||
rs = ps.executeQuery();
|
||||
count = rs.getFetchSize();
|
||||
} catch (SQLException ex) {
|
||||
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
close(ps, rs, conn);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private int createQueue(String statement, @NonNull List<Object> params) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
int id = -1;
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement(statement);
|
||||
Iterator<Object> it = params.iterator();
|
||||
int paramIndex = 1;
|
||||
while (it.hasNext()) {
|
||||
ps.setObject(paramIndex, it.next());
|
||||
paramIndex++;
|
||||
}
|
||||
ps.executeUpdate();
|
||||
ResultSet rs = ps.getGeneratedKeys();
|
||||
if (rs.next()) {
|
||||
id = rs.getInt(COLUMNS.ID.name);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
close(ps, null, conn);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean removeQueue(QueueData data) {
|
||||
|
||||
@@ -8,20 +8,14 @@ import org.bukkit.Location;
|
||||
|
||||
public class QueueData {
|
||||
|
||||
//@Getter final String identifier;
|
||||
@Getter final int database_id;
|
||||
@Getter @Setter Location location;
|
||||
@Getter final long generated;
|
||||
|
||||
public QueueData(Location location, long generated/*, String identifier*/) {
|
||||
public QueueData(Location location, long generated, int database_id) {
|
||||
this.location = location;
|
||||
this.generated = generated;
|
||||
//this.identifier = identifier;
|
||||
}
|
||||
|
||||
public QueueData(RTPWorld rtpWorld) {
|
||||
this.location = WorldPlayer.generateLocation(rtpWorld);
|
||||
this.generated = System.currentTimeMillis();
|
||||
//this.identifier = rtpWorld.getID();
|
||||
this.database_id = database_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.WorldPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -58,7 +59,11 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
||||
return;
|
||||
}
|
||||
//Download all queue cached from last session
|
||||
//long usedmemory = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
|
||||
//BetterRTP.debug("Memory used " + usedmemory);
|
||||
queueList = DatabaseHandler.getQueue().getQueues();
|
||||
//usedmemory = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) - usedmemory;
|
||||
//BetterRTP.debug("Memory used after load " + usedmemory);
|
||||
loaded = true;
|
||||
BetterRTP.debug("Loaded " + queueList.size() + " previously generated safe locations!");
|
||||
//Queue after everything was loaded
|
||||
@@ -183,34 +188,38 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
||||
|
||||
//Generate a safe location
|
||||
private void generateFromWorld(RTPWorld world, String id, ReQueueData reQueueData) {
|
||||
addQueue(world, new QueueData(world), id, reQueueData);
|
||||
addQueue(world, id, reQueueData);
|
||||
}
|
||||
|
||||
private void addQueue(RTPWorld rtpWorld, QueueData data, String id, ReQueueData reQueueData) {
|
||||
if (data.getLocation() != null) {
|
||||
private void addQueue(RTPWorld rtpWorld, String id, ReQueueData reQueueData) {
|
||||
Location loc = WorldPlayer.generateLocation(rtpWorld);
|
||||
if (loc != null) {
|
||||
Bukkit.getScheduler().runTask(BetterRTP.getInstance(), () -> {
|
||||
//BetterRTP.debug("Queued up a new position, attempts " + reQueueData.attempts);
|
||||
PaperLib.getChunkAtAsync(data.getLocation())
|
||||
PaperLib.getChunkAtAsync(loc)
|
||||
.thenAccept(v -> {
|
||||
Location loc = RTPPlayer.getSafeLocation(
|
||||
Location safeLoc = RTPPlayer.getSafeLocation(
|
||||
RTP.getWorldType(rtpWorld),
|
||||
data.getLocation().getWorld(),
|
||||
data.getLocation(),
|
||||
loc.getWorld(),
|
||||
loc,
|
||||
rtpWorld.getMinY(),
|
||||
rtpWorld.getMaxY(),
|
||||
rtpWorld.getBiomes());
|
||||
data.setLocation(loc);
|
||||
if (loc != null) {
|
||||
//data.setLocation(safeLoc);
|
||||
if (safeLoc != null) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||
if (DatabaseHandler.getQueue().addQueue(data)) {
|
||||
QueueData data = DatabaseHandler.getQueue().addQueue(safeLoc);
|
||||
if (data != null) {
|
||||
queueList.add(data);
|
||||
String _x = String.valueOf(data.getLocation().getBlockX());
|
||||
String _y = String.valueOf(data.getLocation().getBlockY());
|
||||
String _z = String.valueOf(data.getLocation().getBlockZ());
|
||||
String _world = data.getLocation().getWorld().getName();
|
||||
BetterRTP.debug("Queue position generated #" + queueList.size() + ": id= " + id + ", location= x:" + _x + ", y:" + _y + ", z:" + _z + ", world:" + _world);
|
||||
BetterRTP.debug("Queue position generated #" + queueList.size()
|
||||
+ ": id= " + id + ", database_ID" + data.database_id
|
||||
+ ", location= x:" + _x + ", y:" + _y + ", z:" + _z + ", world:" + _world);
|
||||
} else
|
||||
BetterRTP.debug("Database error occurred for a queue! " + data.getLocation().toString());
|
||||
BetterRTP.debug("Database error occurred for a queue when trying to save: " + safeLoc);
|
||||
queueGenerator(reQueueData);
|
||||
});
|
||||
} else
|
||||
|
||||
Reference in New Issue
Block a user