mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 09:05:47 +00:00
queue system up and running
This commit is contained in:
parent
4d4f6b2d86
commit
7f6afdfd7a
@ -130,6 +130,7 @@ public class BetterRTP extends JavaPlugin {
|
|||||||
listener.load();
|
listener.load();
|
||||||
eco.load();
|
eco.load();
|
||||||
perms.register();
|
perms.register();
|
||||||
|
queue.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(String str) {
|
public static void debug(String str) {
|
||||||
|
@ -155,7 +155,10 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
|
|||||||
case "centerz":
|
case "centerz":
|
||||||
return worldPlayer.getUseWorldborder() || worldPlayer.getCenterZ() == worldDefault.getCenterZ() ? worldPlayer.getUseWorldborder() ? " &8(worldborder)" : " &8(default)" : "";
|
return worldPlayer.getUseWorldborder() || worldPlayer.getCenterZ() == worldDefault.getCenterZ() ? worldPlayer.getUseWorldborder() ? " &8(worldborder)" : " &8(default)" : "";
|
||||||
case "maxrad":
|
case "maxrad":
|
||||||
return worldPlayer.getUseWorldborder() || worldPlayer.getMaxRadius() == worldDefault.getMaxRadius() ? worldPlayer.getUseWorldborder() ? " &8(worldborder)" : " &8(default)" : "";
|
return worldPlayer.getUseWorldborder() || worldPlayer.getMaxRadius() == worldDefault.getMaxRadius() ?
|
||||||
|
worldPlayer.getUseWorldborder() ?
|
||||||
|
worldPlayer.getMaxRadius() >= worldPlayer.getWorld().getWorldBorder().getSize() ?
|
||||||
|
" &8(worldborder)" : " &8(custom)" : " &8(default)" : "";
|
||||||
case "minrad":
|
case "minrad":
|
||||||
return worldPlayer.getMinRadius() == worldDefault.getMinRadius() ? " &8(default)" : "";
|
return worldPlayer.getMinRadius() == worldDefault.getMinRadius() ? " &8(default)" : "";
|
||||||
case "price":
|
case "price":
|
||||||
|
@ -12,12 +12,13 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class DatabaseQueue extends SQLite {
|
public class DatabaseQueue extends SQLite {
|
||||||
|
|
||||||
public DatabaseQueue() {
|
public DatabaseQueue() {
|
||||||
super(DATABASE_TYPE.PLAYERS);
|
super(DATABASE_TYPE.QUEUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -28,15 +29,12 @@ public class DatabaseQueue extends SQLite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum COLUMNS {
|
public enum COLUMNS {
|
||||||
ID("id", "long PRIMARY KEY AUTOINCREMENT"),
|
ID("id", "integer PRIMARY KEY AUTOINCREMENT"),
|
||||||
//COOLDOWN DATA
|
//Location Data
|
||||||
X("x", "long"),
|
X("x", "long"),
|
||||||
Y("y", "long"),
|
|
||||||
Z("z", "long"),
|
Z("z", "long"),
|
||||||
WORLD("world", "varchar(32)"),
|
WORLD("world", "varchar(32)"),
|
||||||
GENERATED("generated", "long"),
|
GENERATED("generated", "long")
|
||||||
//IDENTIFIER("identifier", "varchar(32)"),
|
|
||||||
//USES("uses", "integer"),
|
|
||||||
;
|
;
|
||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
@ -60,14 +58,13 @@ public class DatabaseQueue extends SQLite {
|
|||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
long x = rs.getLong(COLUMNS.X.name);
|
long x = rs.getLong(COLUMNS.X.name);
|
||||||
long y = rs.getLong(COLUMNS.Y.name);
|
|
||||||
long z = rs.getLong(COLUMNS.Z.name);
|
long z = rs.getLong(COLUMNS.Z.name);
|
||||||
String worldName = rs.getString(COLUMNS.WORLD.name);
|
String worldName = rs.getString(COLUMNS.WORLD.name);
|
||||||
//String id = rs.getString(COLUMNS.IDENTIFIER.name);
|
//String id = rs.getString(COLUMNS.IDENTIFIER.name);
|
||||||
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) {
|
||||||
QueueData data = new QueueData(new Location(world, x, y, z), generated);
|
QueueData data = new QueueData(new Location(world, x, 69 /*giggity*/, z), generated);
|
||||||
queueDataList.add(data);
|
queueDataList.add(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,24 +77,37 @@ public class DatabaseQueue extends SQLite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Set a queue to save
|
//Set a queue to save
|
||||||
public void addQueue(QueueData data) {
|
public boolean addQueue(QueueData data) {
|
||||||
String pre = "INSERT INTO ";
|
String pre = "INSERT INTO ";
|
||||||
String sql = pre + tables.get(0) + " ("
|
String sql = pre + tables.get(0) + " ("
|
||||||
+ COLUMNS.X.name + ", "
|
+ COLUMNS.X.name + ", "
|
||||||
+ COLUMNS.Y.name + ", "
|
|
||||||
+ COLUMNS.Z.name + ", "
|
+ COLUMNS.Z.name + ", "
|
||||||
+ COLUMNS.WORLD.name + ", "
|
+ COLUMNS.WORLD.name + ", "
|
||||||
+ COLUMNS.GENERATED.name + " "
|
+ COLUMNS.GENERATED.name + " "
|
||||||
//+ COLUMNS.USES.name + " "
|
//+ COLUMNS.USES.name + " "
|
||||||
+ ") VALUES(?, ?, ?, ?, ?)";
|
+ ") VALUES(?, ?, ?, ?)";
|
||||||
List<Object> params = new ArrayList<Object>() {{
|
List<Object> params = new ArrayList<Object>() {{
|
||||||
add(data.getLocation().getX());
|
add(data.getLocation().getX());
|
||||||
add(data.getLocation().getY());
|
|
||||||
add(data.getLocation().getZ());
|
add(data.getLocation().getZ());
|
||||||
add(data.getLocation().getWorld().getName());
|
add(data.getLocation().getWorld().getName());
|
||||||
add(data.getGenerated());
|
add(data.getGenerated());
|
||||||
//add(data.getUses());
|
//add(data.getUses());
|
||||||
}};
|
}};
|
||||||
sqlUpdate(sql, params);
|
return sqlUpdate(sql, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeQueue(QueueData data) {
|
||||||
|
String sql = "DELETE FROM " + tables.get(0) + " WHERE "
|
||||||
|
+ COLUMNS.X.name + " = ? AND "
|
||||||
|
+ COLUMNS.Z.name + " = ? AND "
|
||||||
|
+ COLUMNS.WORLD.name + " = ?"
|
||||||
|
;
|
||||||
|
Location loc = data.getLocation();
|
||||||
|
List<Object> params = new ArrayList<Object>() {{
|
||||||
|
add(loc.getBlockX());
|
||||||
|
add(loc.getBlockZ());
|
||||||
|
add(loc.getWorld().getName());
|
||||||
|
}};
|
||||||
|
return sqlUpdate(sql, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -140,6 +140,8 @@ public abstract class SQLite {
|
|||||||
private Enum<?>[] getColumns(DATABASE_TYPE type) {
|
private Enum<?>[] getColumns(DATABASE_TYPE type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PLAYERS: return DatabasePlayers.COLUMNS.values();
|
case PLAYERS: return DatabasePlayers.COLUMNS.values();
|
||||||
|
case QUEUE: return DatabaseQueue.COLUMNS.values();
|
||||||
|
case COOLDOWN:
|
||||||
default: return DatabaseCooldownsWorlds.COLUMNS.values();
|
default: return DatabaseCooldownsWorlds.COLUMNS.values();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,6 +149,8 @@ public abstract class SQLite {
|
|||||||
private String getColumnName(DATABASE_TYPE type, Enum<?> column) {
|
private String getColumnName(DATABASE_TYPE type, Enum<?> column) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PLAYERS: return ((DatabasePlayers.COLUMNS) column).name;
|
case PLAYERS: return ((DatabasePlayers.COLUMNS) column).name;
|
||||||
|
case QUEUE: return ((DatabaseQueue.COLUMNS) column).name;
|
||||||
|
case COOLDOWN:
|
||||||
default: return ((DatabaseCooldownsWorlds.COLUMNS) column).name;
|
default: return ((DatabaseCooldownsWorlds.COLUMNS) column).name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,6 +158,8 @@ public abstract class SQLite {
|
|||||||
private String getColumnType(DATABASE_TYPE type, Enum<?> column) {
|
private String getColumnType(DATABASE_TYPE type, Enum<?> column) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PLAYERS: return ((DatabasePlayers.COLUMNS) column).type;
|
case PLAYERS: return ((DatabasePlayers.COLUMNS) column).type;
|
||||||
|
case QUEUE: return ((DatabaseQueue.COLUMNS) column).type;
|
||||||
|
case COOLDOWN:
|
||||||
default: return ((DatabaseCooldownsWorlds.COLUMNS) column).type;
|
default: return ((DatabaseCooldownsWorlds.COLUMNS) column).type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,6 +256,6 @@ public abstract class SQLite {
|
|||||||
public enum DATABASE_TYPE {
|
public enum DATABASE_TYPE {
|
||||||
PLAYERS,
|
PLAYERS,
|
||||||
COOLDOWN,
|
COOLDOWN,
|
||||||
COOLDOWN_GLOBAL, //Table to know last time in general player has a cooldown for
|
QUEUE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
|
package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP;
|
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPPlayer;
|
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPPlayer;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_FindLocationEvent;
|
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_FindLocationEvent;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_TeleportPostEvent;
|
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_TeleportPostEvent;
|
||||||
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.database.DatabaseQueue;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WORLD_TYPE;
|
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.*;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldDefault;
|
|
||||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPlayer;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -17,34 +16,28 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class QueueHandler implements Listener { //Randomly queues up some safe locations
|
public class QueueHandler implements Listener { //Randomly queues up some safe locations
|
||||||
|
|
||||||
boolean loaded = false;
|
boolean loaded = false;
|
||||||
List<QueueData> queueList = new ArrayList<>();
|
List<QueueData> queueList = new ArrayList<>();
|
||||||
private final int queueSize = 8; //Amount to ready up for each rtp world
|
private final int queueMax = 8, queueMin = 2; //Amount to ready up for each rtp world
|
||||||
|
private boolean generating;
|
||||||
|
|
||||||
public void registerEvents(BetterRTP pl) {
|
public void registerEvents(BetterRTP pl) {
|
||||||
//DEBUG ONLY FOR THE TIME BEING
|
|
||||||
if (!BetterRTP.getInstance().getSettings().isDebug())
|
|
||||||
return;
|
|
||||||
PluginManager pm = pl.getServer().getPluginManager();
|
PluginManager pm = pl.getServer().getPluginManager();
|
||||||
pm.registerEvents(this, pl);
|
pm.registerEvents(this, pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
//DEBUG ONLY FOR THE TIME BEING
|
|
||||||
if (!BetterRTP.getInstance().getSettings().isDebug())
|
|
||||||
return;
|
|
||||||
loaded = false;
|
loaded = false;
|
||||||
queueDownload();
|
queueDownload();
|
||||||
|
queueGenerator(null, queueMax, queueMin, 0, "noone");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queueDownload() {
|
private void queueDownload() {
|
||||||
|
queueList.clear();
|
||||||
//LOAD FROM DATABASE
|
//LOAD FROM DATABASE
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
|
|
||||||
@ -66,7 +59,8 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
|||||||
QueueData data = queueData.get(new Random().nextInt(queueData.size()));
|
QueueData data = queueData.get(new Random().nextInt(queueData.size()));
|
||||||
e.setLocation(data.location);
|
e.setLocation(data.location);
|
||||||
}
|
}
|
||||||
queueGenerator(e.getWorld());
|
if (!generating)
|
||||||
|
queueGenerator(e.getWorld(), queueMax, queueMin, 0, "noone");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -77,31 +71,47 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
|||||||
List<QueueData> deleteList = new ArrayList<>();
|
List<QueueData> deleteList = new ArrayList<>();
|
||||||
for (QueueData data : queueList) {
|
for (QueueData data : queueList) {
|
||||||
Location dataLoc = data.getLocation();
|
Location dataLoc = data.getLocation();
|
||||||
|
//BetterRTP.debug("--");
|
||||||
|
//BetterRTP.debug(location.getBlockX() + " -> " + dataLoc.getBlockX());
|
||||||
|
//BetterRTP.debug(location.getBlockZ() + " -> " + dataLoc.getBlockZ());
|
||||||
if (location.getBlockX() == dataLoc.getBlockX()
|
if (location.getBlockX() == dataLoc.getBlockX()
|
||||||
&& location.getBlockY() == dataLoc.getBlockY()
|
|
||||||
&& location.getBlockZ() == dataLoc.getBlockZ()
|
&& location.getBlockZ() == dataLoc.getBlockZ()
|
||||||
&& location.getWorld().getName().equals(dataLoc.getWorld().getName())) {
|
&& location.getWorld().getName().equals(dataLoc.getWorld().getName())) {
|
||||||
deleteList.add(data);
|
deleteList.add(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deleteList.forEach(data -> queueList.remove(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) {
|
private void queueGenerator(RTPWorld rtpWorld, int queueMax, int queueMin, int lastCount, @NonNull String lastType) {
|
||||||
|
if (queueMax != 10000)
|
||||||
|
return;
|
||||||
/*if (queueList.size() >= queueSize) {
|
/*if (queueList.size() >= queueSize) {
|
||||||
//Plenty of locations, cancel out
|
//Plenty of locations, cancel out
|
||||||
return;
|
return;
|
||||||
}*/
|
}*/
|
||||||
|
generating = true;
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
//Generate more locations
|
//Generate more locations
|
||||||
//Rare cases where a rtp world didnt have a location generated (Permission Groups?)
|
//Rare cases where a rtp world didnt have a location generated (Permission Groups?)
|
||||||
if (getApplicable(rtpWorld).size() < queueSize / 2) {
|
if (rtpWorld != null) {
|
||||||
generateFromWorld(rtpWorld);
|
List<QueueData> applicable = getApplicable(rtpWorld);
|
||||||
queueGenerator(rtpWorld); //Generate another later
|
String type = "superCustom_" + (rtpWorld.getID() != null ? rtpWorld.getID() : rtpWorld.getWorld().getName());
|
||||||
return;
|
int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size();
|
||||||
|
if (newCount < queueMin && applicable.size() < queueMax) {
|
||||||
|
generateFromWorld(rtpWorld);
|
||||||
|
queueGenerator(rtpWorld, queueMax, queueMin, newCount, type); //Generate another later
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (lastType.equalsIgnoreCase(type))
|
||||||
|
BetterRTP.debug("Queue max reached for " + type + " (amount: " + applicable.size() + ") lastCount: " + lastCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Generate Defaults
|
//Generate Defaults
|
||||||
@ -109,39 +119,60 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
|||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
if (!BetterRTP.getInstance().getRTP().getDisabledWorlds().contains(world.getName())
|
if (!BetterRTP.getInstance().getRTP().getDisabledWorlds().contains(world.getName())
|
||||||
&& !BetterRTP.getInstance().getRTP().RTPcustomWorld.containsKey(world.getName())) {
|
&& !BetterRTP.getInstance().getRTP().RTPcustomWorld.containsKey(world.getName())) {
|
||||||
if (getApplicable(worldDefault).size() < queueSize) {
|
RTPWorld newWorld = new WorldCustom(world, worldDefault);
|
||||||
generateFromWorld(worldDefault);
|
List<QueueData> applicable = getApplicable(newWorld);
|
||||||
queueGenerator(null); //Generate another later
|
String type = "default_" + world.getName();
|
||||||
|
int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size();
|
||||||
|
if (newCount < queueMin && applicable.size() < queueMax) {
|
||||||
|
generateFromWorld(newWorld);
|
||||||
|
queueGenerator(null, queueMax, queueMin, newCount, type); //Generate another later
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (lastType.equalsIgnoreCase(type))
|
||||||
|
BetterRTP.debug("Queue max reached for " + type + " (amount: " + applicable.size() + ") world: " + world.getName() + " lastCount: " + lastCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Generate Custom Worlds
|
//Generate Custom Worlds
|
||||||
for (Map.Entry<String, RTPWorld> customWorld : BetterRTP.getInstance().getRTP().RTPcustomWorld.entrySet()) {
|
for (Map.Entry<String, RTPWorld> customWorld : BetterRTP.getInstance().getRTP().RTPcustomWorld.entrySet()) {
|
||||||
RTPWorld world = customWorld.getValue();
|
RTPWorld world = customWorld.getValue();
|
||||||
if (getApplicable(world).size() < queueSize) {
|
List<QueueData> applicable = getApplicable(world);
|
||||||
|
String type = "custom_" + customWorld.getKey();
|
||||||
|
int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size();
|
||||||
|
if (newCount < queueMin && applicable.size() < queueMax) {
|
||||||
generateFromWorld(world);
|
generateFromWorld(world);
|
||||||
queueGenerator(null); //Generate another later
|
queueGenerator(null, queueMax, queueMin, newCount, type); //Generate another later
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (lastType.equalsIgnoreCase(type))
|
||||||
|
BetterRTP.debug("Queue max reached for " + type + " " + applicable.size() + " " + customWorld.getValue().getWorld().getName() + " lastCount: " + lastCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Generate Locations
|
//Generate Locations
|
||||||
for (Map.Entry<String, RTPWorld> location : BetterRTP.getInstance().getRTP().RTPworldLocations.entrySet()) {
|
for (Map.Entry<String, RTPWorld> location : BetterRTP.getInstance().getRTP().RTPworldLocations.entrySet()) {
|
||||||
RTPWorld world = location.getValue();
|
RTPWorld world = location.getValue();
|
||||||
if (getApplicable(world).size() < queueSize) {
|
List<QueueData> applicable = getApplicable(world);
|
||||||
|
String type = "location_" + location.getValue().getID();
|
||||||
|
int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size();
|
||||||
|
if (newCount < queueMin && applicable.size() < queueMax) {
|
||||||
generateFromWorld(world);
|
generateFromWorld(world);
|
||||||
queueGenerator(null); //Generate another later
|
queueGenerator(null, queueMax, queueMin, newCount, type); //Generate another later
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (lastType.equalsIgnoreCase(type))
|
||||||
|
BetterRTP.debug("Queue max reached for " + type + " " + applicable.size() + " " + location.getValue().getID() + " lastCount: " + lastCount);
|
||||||
}
|
}
|
||||||
|
generating = false;
|
||||||
}, 20L * 5 /*delay before starting queue generator*/);
|
}, 20L * 5 /*delay before starting queue generator*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Generate a location on another thread
|
//Generate a location on another thread
|
||||||
private void generateFromWorld(RTPWorld world) {
|
private void generateFromWorld(RTPWorld world) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> addQueue(world, new QueueData(world)));
|
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
|
//BetterRTP.debug("Queue attempt started...");
|
||||||
|
QueueData data = new QueueData(world);
|
||||||
|
addQueue(world, data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addQueue(RTPWorld rtpWorld, QueueData data) {
|
private void addQueue(RTPWorld rtpWorld, QueueData data) {
|
||||||
@ -154,14 +185,21 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
|
|||||||
rtpWorld.getBiomes());
|
rtpWorld.getBiomes());
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
data.setLocation(loc);
|
data.setLocation(loc);
|
||||||
queueList.add(data);
|
if (DatabaseHandler.getQueue().addQueue(data)) {
|
||||||
}
|
queueList.add(data);
|
||||||
|
BetterRTP.debug("Queue position added " + data.getLocation().toString());
|
||||||
|
} else
|
||||||
|
BetterRTP.debug("Database error occured for a queue! " + data.getLocation().toString());
|
||||||
|
} else
|
||||||
|
BetterRTP.debug("Queue position wasn't safe " + data.getLocation().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<QueueData> getApplicable(RTPWorld rtpWorld) {
|
public static List<QueueData> getApplicable(RTPWorld rtpWorld) {
|
||||||
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()))
|
||||||
|
continue;
|
||||||
switch (rtpWorld.getShape()) {
|
switch (rtpWorld.getShape()) {
|
||||||
case CIRCLE:
|
case CIRCLE:
|
||||||
if (isInCircle(data.location, rtpWorld))
|
if (isInCircle(data.location, rtpWorld))
|
||||||
|
@ -134,6 +134,11 @@ public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
|
|||||||
//this.Biomes = config.getStringList("CustomWorlds." + world + ".Biomes");
|
//this.Biomes = config.getStringList("CustomWorlds." + world + ".Biomes");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WorldCustom(World world, RTPWorld rtpWorld) {
|
||||||
|
setAllFrom(rtpWorld);
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getUseWorldborder() {
|
public boolean getUseWorldborder() {
|
||||||
return useWorldborder;
|
return useWorldborder;
|
||||||
|
@ -124,8 +124,7 @@ public class WorldDefault implements RTPWorld {
|
|||||||
return Biomes;
|
return Biomes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull @Override
|
||||||
@Override
|
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public class WorldLocations implements RTPWorld, RTPWorld_Defaulted {
|
|||||||
private List<String> biomes;
|
private List<String> biomes;
|
||||||
private World world;
|
private World world;
|
||||||
private RTP_SHAPE shape;
|
private RTP_SHAPE shape;
|
||||||
private String name;
|
private final String name;
|
||||||
|
|
||||||
public WorldLocations(String location_name) {
|
public WorldLocations(String location_name) {
|
||||||
FileBasics.FILETYPE config = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.LOCATIONS);
|
FileBasics.FILETYPE config = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.LOCATIONS);
|
||||||
|
@ -7,6 +7,7 @@ import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
|||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -159,7 +160,7 @@ public class WorldPermissionGroup implements RTPWorld, RTPWorld_Defaulted {
|
|||||||
return biomes;
|
return biomes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@NotNull @Override
|
||||||
public @NonNull World getWorld() {
|
public @NonNull World getWorld() {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
@ -99,10 +99,9 @@ public class WorldPlayer implements RTPWorld, RTPWorld_Defaulted {
|
|||||||
public static Location generateLocation(RTPWorld rtpWorld) {
|
public static Location generateLocation(RTPWorld rtpWorld) {
|
||||||
Location loc;
|
Location loc;
|
||||||
switch (rtpWorld.getShape()) {
|
switch (rtpWorld.getShape()) {
|
||||||
case CIRCLE:
|
case CIRCLE: loc = generateRound(rtpWorld); break;
|
||||||
loc = generateRound(rtpWorld); break;
|
case SQUARE:
|
||||||
default:
|
default: loc = generateSquare(rtpWorld); break;
|
||||||
loc = generateSquare(rtpWorld); break;
|
|
||||||
}
|
}
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
@ -130,7 +129,7 @@ public class WorldPlayer implements RTPWorld, RTPWorld_Defaulted {
|
|||||||
x += rtpWorld.getCenterX();
|
x += rtpWorld.getCenterX();
|
||||||
z += rtpWorld.getCenterZ();
|
z += rtpWorld.getCenterZ();
|
||||||
//System.out.println(quadrant);
|
//System.out.println(quadrant);
|
||||||
return new Location(rtpWorld.getWorld(), x, 0, z);
|
return new Location(rtpWorld.getWorld(), x, 69, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Location generateRound(RTPWorld rtpWorld) {
|
private static Location generateRound(RTPWorld rtpWorld) {
|
||||||
@ -150,7 +149,7 @@ public class WorldPlayer implements RTPWorld, RTPWorld_Defaulted {
|
|||||||
z = (int) (r * Math.sin(theta));
|
z = (int) (r * Math.sin(theta));
|
||||||
x += rtpWorld.getCenterX();
|
x += rtpWorld.getCenterX();
|
||||||
z += rtpWorld.getCenterZ();
|
z += rtpWorld.getCenterZ();
|
||||||
return new Location(rtpWorld.getWorld(), x, 0, z);
|
return new Location(rtpWorld.getWorld(), x, 69, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
Loading…
x
Reference in New Issue
Block a user