Queue memory leak Fix

This commit is contained in:
RonanCraft
2022-10-25 16:29:19 -04:00
parent e22924be1f
commit ba5c0a4717
29 changed files with 428 additions and 403 deletions

View File

@@ -109,7 +109,7 @@
<dependency>
<groupId>me.SuperRonanCraft</groupId>
<artifactId>BetterRTP</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
<!-- ProtocolLib -->

View File

@@ -7,7 +7,7 @@
<groupId>me.SuperRonanCraft</groupId>
<artifactId>BetterRTP</artifactId>
<packaging>jar</packaging>
<version>3.5.1</version>
<version>3.6.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>

View File

@@ -8,11 +8,11 @@ public enum RTPCommandType {
HELP(new CmdHelp()),
INFO(new CmdInfo()),
PLAYER(new CmdPlayer()),
QUEUE(new CmdQueue(), true),
RELOAD(new CmdReload()),
LOCATION(new CmdLocation()),
//SETTINGS(new CmdSettings(), true),
TEST(new CmdTest(), true),
Queue(new CmdQueue(), true),
VERSION(new CmdVersion()),
WORLD(new CmdWorld());

View File

@@ -3,12 +3,11 @@ package me.SuperRonanCraft.BetterRTP.player.commands.types;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
import me.SuperRonanCraft.BetterRTP.player.commands.RTP_SETUP_TYPE;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPParticles;
import me.SuperRonanCraft.BetterRTP.player.rtp.effects.RTPEffect_Particles;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPSetupInformation;
import me.SuperRonanCraft.BetterRTP.references.PermissionNode;
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP;
import me.SuperRonanCraft.BetterRTP.references.messages.Message;
import me.SuperRonanCraft.BetterRTP.references.messages.Message_RTP;
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesCore;
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesHelp;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.QueueHandler;
@@ -98,7 +97,7 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
private void infoShapes(CommandSender sendi) {
List<String> info = new ArrayList<>();
for (String shape : RTPParticles.shapeTypes) {
for (String shape : RTPEffect_Particles.shapeTypes) {
if (info.isEmpty() || info.size() % 2 == 0) {
info.add("&7" + shape + "&r");
} else
@@ -158,7 +157,7 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
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- &6Permission Group&7: " + (_rtpworld.getConfig() != null ? "&a" + _rtpworld.getConfig().getGroupName() : "&cN/A"));
info.add("&7- &eQueue Available&7: " + QueueHandler.getApplicable(_rtpworld).size());
info.add("&7- &eQueue Available&7: " + QueueHandler.getApplicableAsync(null, _rtpworld).size());
}
return info;
}

View File

@@ -2,25 +2,20 @@ package me.SuperRonanCraft.BetterRTP.player.commands.types;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
import me.SuperRonanCraft.BetterRTP.player.commands.RTP_SETUP_TYPE;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPParticles;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPSetupInformation;
import me.SuperRonanCraft.BetterRTP.references.PermissionNode;
import me.SuperRonanCraft.BetterRTP.references.database.DatabaseHandler;
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP;
import me.SuperRonanCraft.BetterRTP.references.messages.Message;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.QueueData;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.QueueHandler;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldDefault;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPlayer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import xyz.xenondevs.particle.ParticleEffect;
import java.sql.Time;
import java.util.ArrayList;
import java.util.List;
@@ -31,10 +26,15 @@ public class CmdQueue implements RTPCommand {
}
public void execute(CommandSender sendi, String label, String[] args) {
if (args.length > 1 && Bukkit.getWorld(args[1]) != null) {
sendInfo(sendi, queueGetWorld(Bukkit.getWorld(args[1])));
} else
queueWorlds(sendi);
Player p = (Player) sendi;
//sendi.sendMessage("Loading...");
World world = args.length > 1 ? Bukkit.getWorld(args[1]) : null;
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
if (world != null) {
sendInfo(sendi, queueGetWorld(p, world));
} else
queueWorlds(p);
});
}
//World
@@ -45,18 +45,20 @@ public class CmdQueue implements RTPCommand {
sendi.sendMessage(list.toArray(new String[0]));
}
private void queueWorlds(CommandSender sendi) { //All worlds
private void queueWorlds(Player p) { //All worlds
List<String> info = new ArrayList<>();
for (World w : Bukkit.getWorlds())
info.addAll(queueGetWorld(w));
info.add("&eTotal of &a%amount% &egenerated locations".replace("%amount%", String.valueOf(QueueHandler.getCount())));
sendInfo(sendi, info);
info.addAll(queueGetWorld(p, w));
info.add("&eTotal of &a%amount% &egenerated locations".replace("%amount%", String.valueOf(DatabaseHandler.getQueue().getCount())));
sendInfo(p, info);
}
public static List<String> queueGetWorld(World world) { //Specific world
private static List<String> queueGetWorld(Player player, World world) { //Specific world
List<String> info = new ArrayList<>();
info.add("&eWorld: &6" + world.getName());
for (QueueData queue : QueueHandler.getApplicable(world)) {
RTPSetupInformation setup_info = new RTPSetupInformation(HelperRTP.getActualWorld(player, world), player, player, true);
WorldPlayer pWorld = HelperRTP.getPlayerWorld(setup_info);
for (QueueData queue : QueueHandler.getApplicableAsync(null, pWorld)) {
String str = "&8- &7x= &b%x, &7z= &b%z";
Location loc = queue.getLocation();
str = str.replace("%x", String.valueOf(loc.getBlockX())).replace("%z", String.valueOf(loc.getBlockZ()));

View File

@@ -1,6 +1,7 @@
package me.SuperRonanCraft.BetterRTP.player.rtp;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_FindLocationEvent;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.QueueData;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.QueueHandler;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WORLD_TYPE;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPlayer;
@@ -39,34 +40,43 @@ public class RTPPlayer {
if (attempts >= settings.maxAttempts) //Cancel out, too many tries
metMax(sendi, p);
else { //Try again to find a safe location
//Find a queue'd location
RTP_FindLocationEvent event = new RTP_FindLocationEvent(p, pWorld); //Find a queue'd location
//Find a location from another Plugin
RTP_FindLocationEvent event = new RTP_FindLocationEvent(p, pWorld); //Find an external plugin location
Bukkit.getServer().getPluginManager().callEvent(event);
Location loc;
if (event.getLocation() != null) // && WorldPlayer.checkIsValid(event.getLocation(), pWorld))
loc = event.getLocation();
else
loc = WorldPlayer.generateLocation(pWorld);
attempts++; //Add an attempt
//Load chunk and find out if safe location (asynchronously)
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(loc);
chunk.thenAccept(result -> {
//BetterRTP.debug("Checking location for " + p.getName());
Location tpLoc;
tpLoc = getSafeLocation(pWorld.getWorldtype(), pWorld.getWorld(), loc, pWorld.getMinY(), pWorld.getMaxY(), pWorld.getBiomes());
attemptedLocations.add(loc);
//Valid location?
if (tpLoc != null && checkDepends(tpLoc)) {
tpLoc.add(0.5, 0, 0.5); //Center location
if (getPl().getEco().charge(p, pWorld)) {
tpLoc.setYaw(p.getLocation().getYaw());
tpLoc.setPitch(p.getLocation().getPitch());
settings.teleport.sendPlayer(sendi, p, tpLoc, pWorld.getPrice(), attempts, type, pWorld.getWorldtype());
}
} else {
randomlyTeleport(sendi);
QueueHandler.remove(loc);
//Async Location finder
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
Location loc;
if (event.getLocation() != null) // && WorldPlayer.checkIsValid(event.getLocation(), pWorld))
loc = event.getLocation();
else {
QueueData queueData = QueueHandler.getRandomAsync(pWorld);
if (queueData != null)
loc = queueData.getLocation();
else
loc = WorldPlayer.generateLocation(pWorld);
}
attempts++; //Add an attempt
//Load chunk and find out if safe location (asynchronously)
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(loc);
chunk.thenAccept(result -> {
//BetterRTP.debug("Checking location for " + p.getName());
Location tpLoc;
tpLoc = getSafeLocation(pWorld.getWorldtype(), pWorld.getWorld(), loc, pWorld.getMinY(), pWorld.getMaxY(), pWorld.getBiomes());
attemptedLocations.add(loc);
//Valid location?
if (tpLoc != null && checkDepends(tpLoc)) {
tpLoc.add(0.5, 0, 0.5); //Center location
if (getPl().getEco().charge(p, pWorld)) {
tpLoc.setYaw(p.getLocation().getYaw());
tpLoc.setPitch(p.getLocation().getPitch());
Bukkit.getScheduler().runTask(BetterRTP.getInstance(), () ->
settings.teleport.sendPlayer(sendi, p, tpLoc, pWorld.getPrice(), attempts, type, pWorld.getWorldtype()));
}
} else {
randomlyTeleport(sendi);
QueueHandler.remove(loc);
}
});
});
}
}
@@ -82,12 +92,7 @@ public class RTPPlayer {
// Compressed code for MaxAttempts being met
private void metMax(CommandSender sendi, Player p) {
settings.teleport.failedTeleport(p, sendi);
/*if (p == sendi)
getPl().getText().getFailedNotSafe(sendi, settings.maxAttempts);
else
getPl().getText().getOtherNotSafe(sendi, settings.maxAttempts, p.getName());*/
getPl().getCooldowns().removeCooldown(p, pWorld.getWorld());
//getPl().getEco().unCharge(p, pWorld);
getPl().getpInfo().getRtping().put(p, false);
}

View File

@@ -2,21 +2,18 @@ package me.SuperRonanCraft.BetterRTP.player.rtp;
import io.papermc.lib.PaperLib;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.rtp.effects.*;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_TeleportEvent;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_TeleportPostEvent;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_TeleportPreEvent;
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesCore;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WORLD_TYPE;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
//---
//Credit to @PaperMC for PaperLib - https://github.com/PaperMC/PaperLib
@@ -26,18 +23,12 @@ import java.util.concurrent.CompletableFuture;
public class RTPTeleport {
private final RTPParticles eParticles = new RTPParticles();
private final RTPPotions ePotions = new RTPPotions();
private final RTPSounds eSounds = new RTPSounds();
private final RTPTitles eTitles = new RTPTitles();
private final RTPEffects effects = new RTPEffects();
//public HashMap<Player, List<CompletableFuture<Chunk>>> playerLoads = new HashMap<>();
void load() {
eParticles.load();
ePotions.load();
eSounds.load();
eTitles.load();
effects.load();
}
// void cancel(Player p) { //Cancel loading chunks/teleporting
@@ -85,45 +76,45 @@ public class RTPTeleport {
//Effects
public void afterTeleport(Player p, Location loc, int price, int attempts, Location oldLoc, RTP_TYPE type) { //Only a successful rtp should run this OR '/rtp test'
eSounds.playTeleport(p);
eParticles.display(p);
ePotions.giveEffects(p);
eTitles.showTitle(RTPTitles.RTP_TITLE_TYPE.TELEPORT, p, loc, attempts, 0);
if (eTitles.sendMsg(RTPTitles.RTP_TITLE_TYPE.TELEPORT))
effects.getSounds().playTeleport(p);
effects.getParticles().display(p);
effects.getPotions().giveEffects(p);
effects.getTitles().showTitle(RTPEffect_Titles.RTP_TITLE_TYPE.TELEPORT, p, loc, attempts, 0);
if (effects.getTitles().sendMsg(RTPEffect_Titles.RTP_TITLE_TYPE.TELEPORT))
sendSuccessMsg(p, p.getName(), loc, price, true, attempts);
getPl().getServer().getPluginManager().callEvent(new RTP_TeleportPostEvent(p, loc, oldLoc, type));
}
public void beforeTeleportInstant(CommandSender sendi, Player p) {
eSounds.playDelay(p);
eTitles.showTitle(RTPTitles.RTP_TITLE_TYPE.NODELAY, p, p.getLocation(), 0, 0);
if (eTitles.sendMsg(RTPTitles.RTP_TITLE_TYPE.NODELAY))
effects.getSounds().playDelay(p);
effects.getTitles().showTitle(RTPEffect_Titles.RTP_TITLE_TYPE.NODELAY, p, p.getLocation(), 0, 0);
if (effects.getTitles().sendMsg(RTPEffect_Titles.RTP_TITLE_TYPE.NODELAY))
MessagesCore.SUCCESS_TELEPORT.send(sendi);
getPl().getServer().getPluginManager().callEvent(new RTP_TeleportPreEvent(p));
}
public void beforeTeleportDelay(Player p, int delay) { //Only Delays should call this
eSounds.playDelay(p);
eTitles.showTitle(RTPTitles.RTP_TITLE_TYPE.DELAY, p, p.getLocation(), 0, delay);
if (eTitles.sendMsg(RTPTitles.RTP_TITLE_TYPE.DELAY))
effects.getSounds().playDelay(p);
effects.getTitles().showTitle(RTPEffect_Titles.RTP_TITLE_TYPE.DELAY, p, p.getLocation(), 0, delay);
if (effects.getTitles().sendMsg(RTPEffect_Titles.RTP_TITLE_TYPE.DELAY))
MessagesCore.DELAY.send(p, delay);
}
public void cancelledTeleport(Player p) { //Only Delays should call this
eTitles.showTitle(RTPTitles.RTP_TITLE_TYPE.CANCEL, p, p.getLocation(), 0, 0);
if (eTitles.sendMsg(RTPTitles.RTP_TITLE_TYPE.CANCEL))
effects.getTitles().showTitle(RTPEffect_Titles.RTP_TITLE_TYPE.CANCEL, p, p.getLocation(), 0, 0);
if (effects.getTitles().sendMsg(RTPEffect_Titles.RTP_TITLE_TYPE.CANCEL))
MessagesCore.MOVED.send(p);
}
private void loadingTeleport(Player p, CommandSender sendi) {
eTitles.showTitle(RTPTitles.RTP_TITLE_TYPE.LOADING, p, p.getLocation(), 0, 0);
if ((eTitles.sendMsg(RTPTitles.RTP_TITLE_TYPE.LOADING) && sendStatusMessage()) || sendi != p) //Show msg if enabled or if not same player
effects.getTitles().showTitle(RTPEffect_Titles.RTP_TITLE_TYPE.LOADING, p, p.getLocation(), 0, 0);
if ((effects.getTitles().sendMsg(RTPEffect_Titles.RTP_TITLE_TYPE.LOADING) && sendStatusMessage()) || sendi != p) //Show msg if enabled or if not same player
MessagesCore.SUCCESS_LOADING.send(sendi);
}
public void failedTeleport(Player p, CommandSender sendi) {
eTitles.showTitle(RTPTitles.RTP_TITLE_TYPE.FAILED, p, p.getLocation(), 0, 0);
if (eTitles.sendMsg(RTPTitles.RTP_TITLE_TYPE.FAILED))
effects.getTitles().showTitle(RTPEffect_Titles.RTP_TITLE_TYPE.FAILED, p, p.getLocation(), 0, 0);
if (effects.getTitles().sendMsg(RTPEffect_Titles.RTP_TITLE_TYPE.FAILED))
if (p == sendi)
MessagesCore.FAILED_NOTSAFE.send(sendi, BetterRTP.getInstance().getRTP().maxAttempts);
else

View File

@@ -1,4 +1,4 @@
package me.SuperRonanCraft.BetterRTP.player.rtp;
package me.SuperRonanCraft.BetterRTP.player.rtp.effects;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.file.FileOther;
@@ -11,7 +11,6 @@ import xyz.xenondevs.particle.ParticleEffect;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
//---
//Credit to @ByteZ1337 for ParticleLib - https://github.com/ByteZ1337/ParticleLib
@@ -19,7 +18,7 @@ import java.util.Random;
//Use of particle creation
//---
public class RTPParticles {
public class RTPEffect_Particles {
private boolean enabled;
private final List<ParticleEffect> effects = new ArrayList<>();
@@ -69,7 +68,7 @@ public class RTPParticles {
}
}
void display(Player p) {
public void display(Player p) {
if (!enabled) return;
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
try { //Incase the library errors out

View File

@@ -1,4 +1,4 @@
package me.SuperRonanCraft.BetterRTP.player.rtp;
package me.SuperRonanCraft.BetterRTP.player.rtp.effects;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.file.FileOther;
@@ -10,7 +10,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class RTPPotions { //Potions AND Invincibility
public class RTPEffect_Potions { //Potions AND Invincibility
private boolean potionEnabled;
private final HashMap<PotionEffectType, Integer[]> potionEffects = new HashMap<>();
@@ -48,7 +48,7 @@ public class RTPPotions { //Potions AND Invincibility
}
}
void giveEffects(Player p) {
public void giveEffects(Player p) {
if (invincibleEnabled)
p.setNoDamageTicks(invincibleTime * 20);
if (potionEnabled) {

View File

@@ -1,4 +1,4 @@
package me.SuperRonanCraft.BetterRTP.player.rtp;
package me.SuperRonanCraft.BetterRTP.player.rtp.effects;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
@@ -10,7 +10,7 @@ import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
public class RTPSounds {
public class RTPEffect_Sounds {
private boolean enabled;
private String soundTeleport, soundDelay;
@@ -24,7 +24,7 @@ public class RTPSounds {
}
}
void playTeleport(Player p) {
public void playTeleport(Player p) {
if (!enabled)
return;
if (soundTeleport != null) {
@@ -33,7 +33,7 @@ public class RTPSounds {
}
}
void playDelay(Player p) {
public void playDelay(Player p) {
if (!enabled) return;
if (soundDelay != null) {
playSound(p.getLocation(), p, soundDelay);

View File

@@ -1,15 +1,13 @@
package me.SuperRonanCraft.BetterRTP.player.rtp;
package me.SuperRonanCraft.BetterRTP.player.rtp.effects;
import me.SuperRonanCraft.BetterRTP.references.file.FileOther;
import me.SuperRonanCraft.BetterRTP.references.messages.Message;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.HashMap;
public class RTPTitles {
public class RTPEffect_Titles {
boolean enabled = false;
private final HashMap<RTP_TITLE_TYPE, RTP_TITLE> titles = new HashMap<>();
@@ -23,7 +21,7 @@ public class RTPTitles {
titles.put(type, new RTP_TITLE(type.path));
}
void showTitle(RTP_TITLE_TYPE type, Player p, Location loc, int attempts, int delay) {
public void showTitle(RTP_TITLE_TYPE type, Player p, Location loc, int attempts, int delay) {
if (titles.containsKey(type)) {
String title = getPlaceholders(titles.get(type).title, p, loc, attempts, delay);
String sub = getPlaceholders(titles.get(type).subTitle, p, loc, attempts, delay);
@@ -31,7 +29,7 @@ public class RTPTitles {
}
}
boolean sendMsg(RTP_TITLE_TYPE type) {
public boolean sendMsg(RTP_TITLE_TYPE type) {
return titles.containsKey(type) && titles.get(type).send_message || !enabled;
}
@@ -55,7 +53,7 @@ public class RTPTitles {
// player.sendTitle(title, subTitle, fadeIn, stay, fadeOut);
}
enum RTP_TITLE_TYPE {
public enum RTP_TITLE_TYPE {
NODELAY("NoDelay"), TELEPORT("Teleport"), DELAY("Delay"), CANCEL("Cancelled"), LOADING("Loading"), FAILED("Failed");
final String path;
RTP_TITLE_TYPE(String path) {

View File

@@ -0,0 +1,21 @@
package me.SuperRonanCraft.BetterRTP.player.rtp.effects;
import lombok.Getter;
public class RTPEffects {
@Getter final RTPEffect_Particles particles = new RTPEffect_Particles();
@Getter final RTPEffect_Potions potions = new RTPEffect_Potions();
@Getter final RTPEffect_Sounds sounds = new RTPEffect_Sounds();
@Getter final RTPEffect_Titles titles = new RTPEffect_Titles();
//public HashMap<Player, List<CompletableFuture<Chunk>>> playerLoads = new HashMap<>();
public void load() {
particles.load();
potions.load();
sounds.load();
titles.load();
}
}

View File

@@ -1,8 +1,11 @@
package me.SuperRonanCraft.BetterRTP.references.database;
import lombok.Getter;
import lombok.NonNull;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.QueueData;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.QueueGenerator;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.RTPWorld;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@@ -11,7 +14,6 @@ import java.sql.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
public class DatabaseQueue extends SQLite {
@@ -45,7 +47,7 @@ public class DatabaseQueue extends SQLite {
}
}
public List<QueueData> getQueues() {
public List<QueueData> getAll() {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
@@ -54,6 +56,47 @@ public class DatabaseQueue extends SQLite {
conn = getSQLConnection();
ps = conn.prepareStatement("SELECT * FROM " + tables.get(0));
rs = ps.executeQuery();
while (rs.next()) {
long x = rs.getLong(COLUMNS.X.name);
long z = rs.getLong(COLUMNS.Z.name);
String worldName = rs.getString(COLUMNS.WORLD.name);
int id = rs.getInt(COLUMNS.ID.name);
long generated = rs.getLong(COLUMNS.GENERATED.name);
World world = Bukkit.getWorld(worldName);
if (world != null) {
queueDataList.add(new QueueData(new Location(world, x, 69 /*giggity*/, z), generated, id));
}
}
} catch (SQLException ex) {
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
} finally {
close(ps, rs, conn);
}
return queueDataList;
}
public List<QueueData> getInRange(QueueRangeData range) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
List<QueueData> queueDataList = new ArrayList<>();
try {
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 "
+ COLUMNS.X.name + " BETWEEN " + range.getXLow() + " AND " + range.getXHigh()
+ " AND " + COLUMNS.Z.name + " BETWEEN " + range.getZLow() + " AND " + range.getZHigh()
+ " ORDER BY " + COLUMNS.ID.name + " DESC LIMIT " + (QueueGenerator.queueMax + 1)
);
/*ps.setString(1, COLUMNS.X.name);
ps.setInt(2, range.getXLow());
ps.setInt(3, range.getXHigh());
ps.setString(4, COLUMNS.Z.name);
ps.setInt(5, range.getZLow());
ps.setInt(6, range.getZHigh());*/
//BetterRTP.getInstance().getLogger().info(ps.toString());
rs = ps.executeQuery();
while (rs.next()) {
long x = rs.getLong(COLUMNS.X.name);
@@ -144,13 +187,12 @@ public class DatabaseQueue extends SQLite {
return id;
}
public boolean removeQueue(QueueData data) {
public boolean removeLocation(Location loc) {
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());
@@ -158,4 +200,18 @@ public class DatabaseQueue extends SQLite {
}};
return sqlUpdate(sql, params);
}
public static class QueueRangeData {
@Getter int xLow, xHigh;
@Getter int zLow, zHigh;
public QueueRangeData(RTPWorld rtpWorld) {
this.xLow = rtpWorld.getCenterX() - rtpWorld.getMaxRadius();
this.xHigh = rtpWorld.getCenterX() + rtpWorld.getMaxRadius();
this.zLow = rtpWorld.getCenterZ() - rtpWorld.getMaxRadius();
this.zHigh = rtpWorld.getCenterZ() + rtpWorld.getMaxRadius();
}
}
}

View File

@@ -15,10 +15,7 @@ import java.util.logging.Level;
public abstract class SQLite {
private static final String db_file_name = "database";
@Getter List<String> tables;
//private String host, database, username, password;
//private int port;
//boolean sqlEnabled;
List<String> tables;
private boolean loaded;
public String addMissingColumns = "ALTER TABLE %table% ADD COLUMN %column% %type%";
@@ -33,26 +30,9 @@ public abstract class SQLite {
// SQL creation stuff
public Connection getSQLConnection() {
/*if (sqlEnabled) {
try {
return getOnline();
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
BetterRTP.getInstance().getLogger().info("MySQL setup is incorrect! Grabbing data from local database!");
sqlEnabled = false;
}
}*/
return getLocal();
}
/*private Connection getOnline() throws SQLException, ClassNotFoundException {
synchronized (this) {
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database +
"?autoReconnect=true&useSSL=false", this.username, this.password);
}
}*/
private Connection getLocal() {
File dataFolder = new File(BetterRTP.getInstance().getDataFolder().getPath() + File.separator + "data", db_file_name + ".db");
if (!dataFolder.exists()){
@@ -78,14 +58,6 @@ public abstract class SQLite {
public void load() {
loaded = false;
tables = getTables();
/*switch (type) {
case COOLDOWN: table = "BetterRTP_Cooldown"; break;
}
if (table == null) {
BetterRTP.getInstance().getLogger().severe("The table for `" + type.name() + "` is invalid. Disabling the plugin!");
Bukkit.getPluginManager().disablePlugin(BetterRTP.getInstance());
return;
}*/
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
Connection connection = getSQLConnection();
try {

View File

@@ -24,7 +24,7 @@ import java.util.*;
public class HelperRTP {
//Teleporter and sender are the same
//Teleported and Sender are the same
public static void tp(Player player, World world, List<String> biomes, RTP_TYPE rtpType) {
tp(player, player, world, biomes, rtpType, false, false);
}

View File

@@ -0,0 +1,193 @@
package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
import io.papermc.lib.PaperLib;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.commands.RTP_SETUP_TYPE;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPPlayer;
import me.SuperRonanCraft.BetterRTP.references.database.DatabaseHandler;
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP;
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;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class QueueGenerator {
boolean loaded = false;
public static final int queueMax = 32, queueMin = 2; //Amount to ready up for each rtp world
private final int queueMaxAttempts = 50;
boolean generating;
private BukkitTask task;
public void unload() {
if (task != null)
Bukkit.getScheduler().cancelTask(task.getTaskId());
}
public void load() {
loaded = false;
if (task != null)
Bukkit.getScheduler().cancelTask(task.getTaskId());
generate(null);
}
public void generate(@Nullable RTPWorld rtpWorld) {
Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
if (!DatabaseHandler.getQueue().isLoaded()) {
generate(rtpWorld);
return;
}
loaded = true;
//BetterRTP.debug("Loaded " + queueList.size() + " previously generated safe locations!");
//Queue after everything was loaded
BetterRTP.debug("Attempting to queue up some more safe locations...");
queueGenerator(new ReQueueData(DatabaseHandler.getQueue().getAll(), rtpWorld, queueMax, queueMin, 0, "noone", 0));
}, 10L);
}
private void queueGenerator(ReQueueData data) {
generating = true;
task = Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
//BetterRTP.debug("Generating a new position... attemp # " + data.attempts);
//Generate more locations
//Rare cases where a rtp world didn't have a location generated (Permission Groups?)
if (data.rtpWorld != null) {
List<QueueData> applicable = QueueHandler.getApplicableAsync(data.queue, data.rtpWorld);
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 attempt = data.lastType.equalsIgnoreCase(type) ? data.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;
}
addQueue(data.rtpWorld, type, new ReQueueData(data.queue, data.rtpWorld, queueMax, queueMin, newCount, type, attempt)); //Generate another later
return;
}
if (data.lastType.equalsIgnoreCase(type))
BetterRTP.debug("Queue max reached for " + type + " (amount: " + applicable.size() + ") lastCount: " + data.lastCount);
}
//Queue up all setup types
for (RTP_SETUP_TYPE setup : RTP_SETUP_TYPE.values()) {
HashMap<String, RTPWorld> map = getFromSetup(setup);
if (map == null) continue;
for (Map.Entry<String, RTPWorld> rtpWorldEntry : map.entrySet()) {
RTPWorld world = rtpWorldEntry.getValue();
String type = getId(setup, rtpWorldEntry.getKey());
List<QueueData> applicable = QueueHandler.getApplicableAsync(data.queue, world);
int newCount = data.lastType.equalsIgnoreCase(type) ? data.lastCount : applicable.size();
int attempt = data.lastType.equalsIgnoreCase(type) ? data.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() + ")");
continue;
}
//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
return;
}
if (data.lastType.equalsIgnoreCase(type))
BetterRTP.debug("Max queue reached for " + type + " (amount: " + applicable.size() + ") lastCount: " + data.lastCount);
}
}
generating = false;
BetterRTP.debug("Queueing paused, max queue limit reached!");
}, 20L /*delay before starting queue generator*/);
}
static class ReQueueData {
List<QueueData> queue;
RTPWorld rtpWorld;
int queueMax, queueMin, lastCount, attempts;
String lastType;
ReQueueData(List<QueueData> queue, RTPWorld rtpWorld, int queueMax, int queueMin, int lastCount, String lastType, int attempts) {
this.queue = queue;
this.rtpWorld = rtpWorld;
this.queueMax = queueMax;
this.queueMin = queueMin;
this.lastCount = lastCount;
this.lastType = lastType;
this.attempts = attempts;
}
}
private static HashMap<String, RTPWorld> getFromSetup(RTP_SETUP_TYPE type) {
switch (type) {
case LOCATION: return BetterRTP.getInstance().getRTP().getRTPworldLocations();
case CUSTOM_WORLD: return BetterRTP.getInstance().getRTP().getRTPcustomWorld();
case DEFAULT:
HashMap<String, RTPWorld> list = new HashMap<>();
RTP rtp = BetterRTP.getInstance().getRTP();
for (World world : Bukkit.getWorlds())
if (!rtp.getDisabledWorlds().contains(world.getName()) && !rtp.getRTPcustomWorld().containsKey(world.getName()))
list.put(world.getName(), new WorldCustom(world, rtp.getRTPdefaultWorld()));
return list;
}
return null;
}
private static String getId(RTP_SETUP_TYPE type, String id) {
switch (type) {
case CUSTOM_WORLD: return "custom_" + id;
case LOCATION: return "location_" + id;
case DEFAULT: return "default_" + id;
}
return "unknown_" + id;
}
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(loc)
.thenAccept(v -> {
Location safeLoc = RTPPlayer.getSafeLocation(
HelperRTP.getWorldType(rtpWorld.getWorld()),
loc.getWorld(),
loc,
rtpWorld.getMinY(),
rtpWorld.getMaxY(),
rtpWorld.getBiomes());
//data.setLocation(safeLoc);
if (safeLoc != null) {
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
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"
+ ": 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 when trying to save: " + safeLoc);
queueGenerator(reQueueData);
});
} else
queueGenerator(reQueueData);
});
});
} else {
BetterRTP.debug("Queue position wasn't able to generate a location!");
queueGenerator(reQueueData);
}
}
}

View File

@@ -1,35 +1,25 @@
package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
import io.papermc.lib.PaperLib;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.commands.RTP_SETUP_TYPE;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPPlayer;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_FindLocationEvent;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_TeleportPostEvent;
import me.SuperRonanCraft.BetterRTP.references.database.DatabaseHandler;
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP;
import me.SuperRonanCraft.BetterRTP.references.database.DatabaseQueue;
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;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.Nullable;
import java.util.*;
public class QueueHandler implements Listener { //Randomly queues up some safe locations
boolean loaded = false;
List<QueueData> queueList = new ArrayList<>();
private final int queueMax = 32, queueMin = 2; //Amount to ready up for each rtp world
private final int queueMaxAttempts = 50;
private boolean generating;
private BukkitTask task;
private final QueueGenerator generator = new QueueGenerator();
public void registerEvents(BetterRTP pl) {
PluginManager pm = pl.getServer().getPluginManager();
@@ -37,204 +27,32 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
}
public void unload() {
if (task != null)
Bukkit.getScheduler().cancelTask(task.getTaskId());
generator.unload();
}
public void load() {
loaded = false;
if (task != null)
Bukkit.getScheduler().cancelTask(task.getTaskId());
if (!BetterRTP.getInstance().getSettings().isQueueEnabled())
return;
queueDownload();
}
private void queueDownload() {
queueList.clear();
//LOAD FROM DATABASE
Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
if (!DatabaseHandler.getQueue().isLoaded()) {
queueDownload();
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
BetterRTP.debug("Attempting to queue up some more safe locations...");
queueGenerator(new ReQueueData(null, queueMax, queueMin, 0, "noone", 0));
}, 10L);
}
//Inject queue to find event
@EventHandler
public void onRtpFindLoc(RTP_FindLocationEvent e) {
List<QueueData> queueData = getApplicable(e.getWorld());
if (!queueData.isEmpty()) {
QueueData data = queueData.get(new Random().nextInt(queueData.size()));
e.setLocation(data.location);
}
if (!generating)
queueGenerator(new ReQueueData(e.getWorld(), queueMax, queueMin, 0, "noone", 0));
generator.load();
}
@EventHandler
public void onRTP(RTP_TeleportPostEvent e) {
//Delete previously used location
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
Location location = e.getLocation();
QueueHandler.remove(location);
});
Location location = e.getLocation();
remove(location);
}
private void queueGenerator(ReQueueData data) {
generating = true;
task = Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
//BetterRTP.debug("Generating a new position... attemp # " + data.attempts);
//Generate more locations
//Rare cases where a rtp world didnt have a location generated (Permission Groups?)
if (data.rtpWorld != null) {
List<QueueData> applicable = getApplicable(data.rtpWorld);
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 attempt = data.lastType.equalsIgnoreCase(type) ? data.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;
}
generateFromWorld(data.rtpWorld, type, new ReQueueData(data.rtpWorld, queueMax, queueMin, newCount, type, attempt)); //Generate another later
return;
}
if (data.lastType.equalsIgnoreCase(type))
BetterRTP.debug("Queue max reached for " + type + " (amount: " + applicable.size() + ") lastCount: " + data.lastCount);
}
//Queue up all setup types
for (RTP_SETUP_TYPE setup : RTP_SETUP_TYPE.values()) {
HashMap<String, RTPWorld> map = getFromSetup(setup);
if (map == null) continue;
for (Map.Entry<String, RTPWorld> rtpWorldEntry : map.entrySet()) {
RTPWorld world = rtpWorldEntry.getValue();
String type = getId(setup, rtpWorldEntry.getKey());
List<QueueData> applicable = getApplicable(world);
int newCount = data.lastType.equalsIgnoreCase(type) ? data.lastCount : applicable.size();
int attempt = data.lastType.equalsIgnoreCase(type) ? data.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() + ")");
continue;
}
//Generate a location sync to bukkit api
generateFromWorld(world, type, new ReQueueData(null, queueMax, queueMin, newCount, type, attempt)); //Generate another when done later
return;
}
if (data.lastType.equalsIgnoreCase(type))
BetterRTP.debug("Max queue reached for " + type + " (amount: " + applicable.size() + ") lastCount: " + data.lastCount);
}
}
generating = false;
BetterRTP.debug("Queueing paused, max queue limit reached!");
}, 20L /*delay before starting queue generator*/);
}
static class ReQueueData {
RTPWorld rtpWorld;
int queueMax, queueMin, lastCount, attempts;
String lastType;
ReQueueData(RTPWorld rtpWorld, int queueMax, int queueMin, int lastCount, String lastType, int attempts) {
this.rtpWorld = rtpWorld;
this.queueMax = queueMax;
this.queueMin = queueMin;
this.lastCount = lastCount;
this.lastType = lastType;
this.attempts = attempts;
}
}
private static HashMap<String, RTPWorld> getFromSetup(RTP_SETUP_TYPE type) {
switch (type) {
case LOCATION: return BetterRTP.getInstance().getRTP().getRTPworldLocations();
case CUSTOM_WORLD: return BetterRTP.getInstance().getRTP().getRTPcustomWorld();
case DEFAULT:
HashMap<String, RTPWorld> list = new HashMap<>();
RTP rtp = BetterRTP.getInstance().getRTP();
for (World world : Bukkit.getWorlds())
if (!rtp.getDisabledWorlds().contains(world.getName()) && !rtp.getRTPcustomWorld().containsKey(world.getName()))
list.put(world.getName(), new WorldCustom(world, rtp.getRTPdefaultWorld()));
return list;
}
public static QueueData getRandomAsync(RTPWorld rtpWorld) {
List<QueueData> queueData = getApplicableAsync(null, rtpWorld);
if (queueData.size() <= QueueGenerator.queueMin && !BetterRTP.getInstance().getQueue().generator.generating)
BetterRTP.getInstance().getQueue().generator.generate(rtpWorld);
if (!queueData.isEmpty())
return queueData.get(new Random().nextInt(queueData.size()));
return null;
}
private static String getId(RTP_SETUP_TYPE type, String id) {
switch (type) {
case CUSTOM_WORLD: return "custom_" + id;
case LOCATION: return "location_" + id;
case DEFAULT: return "default_" + id;
}
return "unknown_" + id;
}
//Generate a safe location
private void generateFromWorld(RTPWorld world, String id, ReQueueData reQueueData) {
addQueue(world, id, reQueueData);
}
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(loc)
.thenAccept(v -> {
Location safeLoc = RTPPlayer.getSafeLocation(
HelperRTP.getWorldType(rtpWorld.getWorld()),
loc.getWorld(),
loc,
rtpWorld.getMinY(),
rtpWorld.getMaxY(),
rtpWorld.getBiomes());
//data.setLocation(safeLoc);
if (safeLoc != null) {
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
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 + ", database_ID" + data.database_id
+ ", location= x:" + _x + ", y:" + _y + ", z:" + _z + ", world:" + _world);
} else
BetterRTP.debug("Database error occurred for a queue when trying to save: " + safeLoc);
queueGenerator(reQueueData);
});
} else
queueGenerator(reQueueData);
});
});
} else {
BetterRTP.debug("Queue position wasn't able to generate a location!");
queueGenerator(reQueueData);
}
}
public static List<QueueData> getApplicable(RTPWorld rtpWorld) {
List<QueueData> queueData = BetterRTP.getInstance().getQueue().queueList;
public static List<QueueData> getApplicableAsync(@Nullable List<QueueData> queueCache, RTPWorld rtpWorld) {
List<QueueData> queueData = queueCache == null ? DatabaseHandler.getQueue().getInRange(new DatabaseQueue.QueueRangeData(rtpWorld)) : queueCache;
List<QueueData> available = new ArrayList<>();
for (QueueData data : queueData) {
if (!Objects.equals(data.getLocation().getWorld().getName(), rtpWorld.getWorld().getName()))
@@ -250,45 +68,21 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
available.add(data);
}
}
BetterRTP.getInstance().getLogger().info("Available: " + available.size());
return available;
}
public static List<QueueData> getApplicable(World world) {
List<QueueData> available = new ArrayList<>();
List<QueueData> queueData = BetterRTP.getInstance().getQueue().queueList;
for (QueueData queue : queueData)
if (Objects.equals(queue.location.getWorld().getName(), world.getName()))
available.add(queue);
return available;
}
public static int getCount() {
return BetterRTP.getInstance().getQueue().queueList.size();
}
public static void remove(Location loc) {
List<QueueData> deleteList = new ArrayList<>();
for (QueueData data : BetterRTP.getInstance().getQueue().queueList) {
Location dataLoc = data.getLocation();
if (loc.getBlockX() == dataLoc.getBlockX()
&& loc.getBlockZ() == dataLoc.getBlockZ()
&& loc.getWorld().getName().equals(dataLoc.getWorld().getName())) {
deleteList.add(data);
}
}
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
deleteList.forEach(data -> {
//Delete all queue data async
if (DatabaseHandler.getQueue().removeQueue(data)) {
BetterRTP.getInstance().getQueue().queueList.remove(data);
BetterRTP.debug("-Removed a queue " + data.getLocation().toString());
}
});
//Delete all queue data async
if (DatabaseHandler.getQueue().removeLocation(loc)) {
//BetterRTP.getInstance().getQueue().queueList.remove(data);
BetterRTP.debug("-Removed a queue " + loc);
}
});
}
private static boolean isInCircle(Location loc, RTPWorld rtpWorld) {
public static boolean isInCircle(Location loc, RTPWorld rtpWorld) {
int center_x = rtpWorld.getCenterX();
int center_z = rtpWorld.getCenterZ();
int radius = rtpWorld.getMaxRadius();
@@ -299,7 +93,7 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
return square_dist <= radius * 2 && square_dist >= radius_min * 2;
}
private static boolean isInSquare(Location loc, RTPWorld rtpWorld) {
public static boolean isInSquare(Location loc, RTPWorld rtpWorld) {
int center_x = rtpWorld.getCenterX();
int center_z = rtpWorld.getCenterZ();
int radius = rtpWorld.getMaxRadius();

View File

@@ -13,7 +13,7 @@ Titles:
SendMessage: true
Teleport:
Title: '&6Teleported!'
Subtitle: '&fx=%x% y=%y% z=%z% in %attempts% attempts'
Subtitle: '&fx=%x% y=%y% z=%z%'
SendMessage: true # Allow the teleport success message in chat
Delay:
Title: ''

View File

@@ -2,23 +2,18 @@
Messages:
Prefix: '&7[&6BetterRTP&7] '
Success: # # Placeholders! %x% %y% and %z% are the x, y, and z coordinates that the player is being teleported to! #
Paid: '&aVocê foi enviado para&7 x=%x% y=%y% z=%z% por &c$%price%&7 em &f%attempts%
&7tentativas!'
Bypass: '&aVocê foi teleportado para&7 x=%x% y=%y% z=%z% em &f%attempts% &7tentativas'
Paid: '&aVocê foi enviado para&7 x=%x% y=%y% z=%z% por &c$%price%&7!'
Bypass: '&aVocê foi teleportado para&7 x=%x% y=%y% z=%z%'
Loading: '&aLocal seguro localizado! &7Carregando pedaços...'
Teleport: '&aTeleportando... &fpor favor, espere enquanto encontramos um local seguro!'
Failed:
Price: '&cRTP falhou devido a fundos insuficientes! &7Você deve ter pelo menos
$%price% &7para o rtp!'
NotSafe: '&cNão foi possível encontrar local seguro em %attempts% tentativas! &7Você não foi
teleportado!'
Price: '&cRTP falhou devido a fundos insuficientes! &7Você deve ter pelo menos $%price% &7para o rtp!'
NotSafe: '&cNão foi possível encontrar local seguro em %attempts% tentativas! &7Você não foi teleportado!'
Hunger: '&cRTP falhou porque você está... &7com muita fome&c, coma alguma coisa, cara!'
Other:
Success: '&a%player% foi enviado para&7 x=%x% y=%y% z=%z% em &f%attempts% &7tentativas!'
NotSafe: '&cNão foi possível encontrar local seguro em %attempts% tentativas! &7%player% não
foi teleportado!'
Biome: '&cParece que o bioma&7 %bioma%&c não existe! &7Tente usar a
lista de guias!'
Success: '&a%player% foi enviado para&7 x=%x% y=%y% z=%z%&a!'
NotSafe: '&cNão foi possível encontrar local seguro em %attempts% tentativas! &7%player% não foi teleportado!'
Biome: '&cParece que o bioma&7 %bioma%&c não existe! &7Tente usar a lista de guias!'
Reload: '&eConfig recarregado com sucesso!'
NoPermission:
Basic: '&cDesculpe! &7Você não tem permissão para usar este comando!'

View File

@@ -2,7 +2,7 @@
Messages:
Prefix: '&7[&6BetterRTP&7] '
Success:
Paid: '&aByl/a jsi teleportován/a na&7 x=%x% y=%y% z=%z% za &c$%price%&7 po &f%attempts% &7pokusech!'
Paid: '&aByl/a jsi teleportován/a na&7 x=%x% y=%y% z=%z% za &c$%price%&7!'
Bypass: '&aByl/a jsi teleportován/a na&7 x=%x% y=%y% z=%z% po &f%attempts% &7pokusech!'
Loading: '&aNalezeno bezpečné místo! &7Načítám chunky...'
Teleport: '&aTeleportuji... &fProsím, počkejte, než nalezneme bezpečné místo!'
@@ -11,7 +11,7 @@ Messages:
NotSafe: '&cNepodařilo se najít bezpečné místo po %attempts% pokusech! &7Nebyl/a jsi teleportován/a!'
Hunger: '&cNebyl/a jsi teleportován, protože jsi... &7příliš hladový/á.&c Sněz něco, kámo!'
Other:
Success: '&a%player% byl/a teleportován/a na&7 x=%x% y=%y% z=%z% po &f%attempts% &7pokusech!'
Success: '&a%player% byl/a teleportován/a na&7 x=%x% y=%y% z=%z%!'
NotSafe: '&cNepodařilo se najít bezpečné místo po %attempts% pokusech! &7%player% nebyl/a teleportován/a!'
Biome: '&cVypadá to, že biom&7 %biome%&c neexistuje! &7Zkus použít tabulátor!'
Reload: '&eConfig úspěšně načten!'

View File

@@ -2,7 +2,7 @@
Messages:
Prefix: '&7[&6BetterRTP&7] '
Success: ## Placeholders! %x% %y% and %z% are the x, y, and z coordinates that the player is being teleported to! #
Paid: '&aDu er blevet tp''et til&7 x=%x% y=%y% z=%z% for &c$%price%&7 i &f%attempts% &7forsøg!'
Paid: '&aDu er blevet tp''et til&7 x=%x% y=%y% z=%z% for &c$%price%&7!'
Bypass: '&aDu er blevet tp''et til&7 x=%x% y=%y% z=%z% i &f%attempts% &7forsøg'
Loading: '&aSikkert sted fundet! &7Loader chunks...'
Teleport: '&Teleportering... &fVent venligst, mens vi finde et sikkert sted!'
@@ -11,7 +11,7 @@ Messages:
NotSafe: '&cKunne ikke finde et sikkert sted indenfor %attempts% forsøg! &7Du blev ikke RTP''et!'
Hunger: '&cKunne ikke rtp, fordi du er... &7sulten&c, spis noget, min ven!'
Other:
Success: '&a%player% er blevet tp''d til&7 x=%x% y=%y% z=%z% i &f%attempts% &7forsøg!'
Success: '&a%player% er blevet tp''d til&7 x=%x% y=%y% z=%z%!'
NotSafe: '&cKunne ikke finde et sikkert sted indenfor %attempts% forsøg! &7%player% blev ikke rtp''et!'
Biome: '&cDet ser ud til, at biomet&7 %biome%&c ikke findes! &7Prøv at bruge TAB listen!'
Reload: '&eKonfiguration genindlæst med succes!'

View File

@@ -2,8 +2,8 @@
Messages:
Prefix: '&7[&6BetterRTP&7] '
Success: # # Placeholders! %x% %y% and %z% are the x, y, and z ist du Position wo der Spieler telelportiert würde! ##
Paid: '&aDu wurdest zu &7 x=%x% y=%y% z=%z% für &c$%price%&7 in &f%attempts% Versuchen &7attempts!'
Bypass: '&adu würdest zu &7 x=%x% y=%y% z=%z% in &f%attempts% &7'
Paid: '&aDu wurdest zu &7 x=%x% y=%y% z=%z% für &c$%price%&7!'
Bypass: '&adu würdest zu &7 x=%x% y=%y% z=%z%'
Loading: '&aSicherer Spot gefunden! &7Lade chunks...'
Teleport: '&aTeleportiere... &fbitte Warte bis wir einen Sicheren Spot gefunden haben!'
Failed:

View File

@@ -2,8 +2,8 @@
Messages:
Prefix: '&7[&6BetterRTP&7] '
Success: ## Placeholders! %x% %y% and %z% are the x, y, and z coordinates that the player is being teleported to! #
Paid: '&aYou have been tp''d to&7 x=%x% y=%y% z=%z% for &c$%price%&7 in &f%attempts% &7attempts!'
Bypass: '&aYou have been tp''d to&7 x=%x% y=%y% z=%z% in &f%attempts% &7attempts'
Paid: '&aYou have been tp''d to&7 x=%x% y=%y% z=%z% for &c$%price%&7!'
Bypass: '&aYou have been tp''d to&7 x=%x% y=%y% z=%z%'
Loading: '&aSafe spot located! &7Loading chunks...'
Teleport: '&aTeleporting... &fplease wait while we find a safe location!'
Failed:
@@ -11,7 +11,7 @@ Messages:
NotSafe: '&cCould not find safe spot within %attempts% attempts! &7You were not RTP''d!'
Hunger: '&cCould not rtp because you are... &7too hungry&c, eat something fella!'
Other:
Success: '&a%player% has been tp''d to&7 x=%x% y=%y% z=%z% in &f%attempts% &7attempts!'
Success: '&a%player% has been tp''d to&7 x=%x% y=%y% z=%z%'
NotSafe: '&cCould not find safe spot within %attempts% attempts! &7%player% was not rtp''d!'
Biome: '&cSeems like the biome&7 %biome%&c does not exist! &7Try using the tab list!'
Reload: '&eConfig reloaded successfully!'

View File

@@ -2,8 +2,8 @@
Messages:
Prefix: '&7[&6BetterRTP&7] '
Success: # # ¡Placeholders! ¡%x% %y% y %z% son las coordinadas x, y, y z al que el jugador está siendo teletransportado! #
Paid: '&a¡Has sido teletransportado a&7 x=%x% y=%y% z=%z% por &c$%price%&7 en &f%attempts% &7intentos!'
Bypass: '&aHas sido teletransportado a&7 x=%x% y=%y% z=%z% en &f%attempts% &7intentos'
Paid: '&a¡Has sido teletransportado a&7 x=%x% y=%y% z=%z% por &c$%price%&7!'
Bypass: '&aHas sido teletransportado a&7 x=%x% y=%y% z=%z%'
Loading: '&a¡Lugar seguro localizado! &7Cargando chunks...'
Teleport: '&f¡&aTeletransportandote... &fpor favor, espere mientras encontramos un lugar seguro!'
Failed:
@@ -11,7 +11,7 @@ Messages:
NotSafe: '&c¡No pudimos encontrar un lugar seguro en %attempts% intentos! &7¡No fuiste teletransportado!'
Hunger: '&c¡No pudimos teletransportarte aleatoriamente porque tienes... &7demasiada hambre&c, come algo amigo!'
Other:
Success: '&7¡&a%player% ha sido teletransportado a&7 x=%x% y=%y% z=%z% en &f%attempts% &7intentos!'
Success: '&7¡&a%player% ha sido teletransportado a&7 x=%x% y=%y% z=%z%!'
NotSafe: '&c¡No se pudo encontrar un lugar seguro en %attempts% intentos! &7¡%player% no fue teletransportado aleatoriamente!'
Biome: '&c¡Parece que el bioma&7 %biome%&c no existe! &7¡Intenta usar la lista del tab!'
Reload: '&e¡Configuración recargada exitosamente!'

View File

@@ -3,8 +3,8 @@
Messages:
Prefix: '&7[&6BetterRTP&7] '
Success: # # Placeholders! %x% %y% and %z% are the x, y, and z coordinates that the player is being teleported to! #
Paid: '&aVous avez été téléporté aux coordonnées &7x=%x% y=%y% z=%z% pour un prix de &c$%price%&7 en &f%attempts% &7tentatives !'
Bypass: '&aVous avez été téléporté aux cooordonées &7x=%x% y=%y% z=%z% en &f%attempts% &7tentatives !'
Paid: '&aVous avez été téléporté aux coordonnées &7x=%x% y=%y% z=%z% pour un prix de &c$%price%&7!'
Bypass: '&aVous avez été téléporté aux cooordonées &7x=%x% y=%y% z=%z%!'
Loading: '&aUn endroit sûr a été trouvé ! &7Chargement des chunks...'
Teleport: '&aTéléportation... &fMerci de patienter pendant la recherche d''un endroit sûr !'
Failed:
@@ -12,7 +12,7 @@ Messages:
NotSafe: '&cImpossible de trouver un endroit sûr en %attempts% tentatives ! &7Vous n''avez pas été téléporté !'
Hunger: '&cImpossible de vous téléporter car vous avez trop faim, manger pour remplir votre barre de nourriture !'
Other:
Success: '&a%player% a été téléporté aux coordonées &7x=%x% y=%y% z=%z% em &f%attempts% &7tentatives !'
Success: '&a%player% a été téléporté aux coordonées &7x=%x% y=%y% z=%z%!'
NotSafe: '&cImpossible de trouver un endroit sûr en %attempts% tentatives ! &7%player% n''a pas été téléporté !'
Biome: '&cIl demblerais que le biome &7%biome% &cn''existe pas ! &7Utiliser l''autocomplétion de la Tab list !'
Reload: '&eConfiguration rechargée avec succès !'

View File

@@ -3,7 +3,7 @@ Messages:
Prefix: '&7[&6BetterRTP&7] '
Success:
Paid: '&aSei stato teletrasportato a&7 x=%x% y=%y% z=%z% in &f%attempts% &7tentativi, pagando &c$%price%&7! '
Bypass: '&aSei stato teletrasportato a&7 x=%x% y=%y% z=%z% in &f%attempts% &7tentativi!'
Bypass: '&aSei stato teletrasportato a&7 x=%x% y=%y% z=%z%!'
Loading: '&aLuogo sicuro localizzato! &7Caricamento...'
Teleport: '&aTeletrasporto in corso... ricerca di un luogo sicuro...'
Failed:

View File

@@ -2,8 +2,8 @@
Messages:
Prefix: '&7[&6BetterRTP&7] '
Success: # # Placeholders! %x% %y% and %z% are the x, y, and z coordinates that the player is being teleported to! #
Paid: '&aJe bent random geteleporteerd naar&7 x=%x% y=%y% z=%z% voor &c$%price%&7 in &f%attempts% &7pogingen!'
Bypass: '&aJe bent random geteleporteerd naar&7 x=%x% y=%y% z=%z% in &f%attempts% &7pogingen'
Paid: '&aJe bent random geteleporteerd naar&7 x=%x% y=%y% z=%z% voor &c$%price%&7!'
Bypass: '&aJe bent random geteleporteerd naar&7 x=%x% y=%y% z=%z%'
Loading: '&aVeilige plek gevonden! &7Laden van chunks...'
Teleport: '&aTeleporteren... &7Wacht even terwijl we een veilige plek zoeken!'
Failed:
@@ -11,7 +11,7 @@ Messages:
NotSafe: '&cKon geen veilige plek vinden binnen %attempts% pogingen! &7Je werd niet random geteleporteerd!'
Hunger: '&cKon niet random teleporteren omdat je... &7te hongerig&c bent, eet iets!'
Other:
Success: '&a%player% is geteleporteerd naar&7 x=%x% y=%y% z=%z% in &f%attempts% &7pogingen!'
Success: '&a%player% is geteleporteerd naar&7 x=%x% y=%y% z=%z%!'
NotSafe: '&cKon geen veilige plek vinden binnen %attempts% pogingen! &7%player% is niet random geteleporteerd!'
Biome: '&cHet lijkt erop dat de biome&7 %biome%&c niet bestaat! &7Probeer de tabbladenlijst te gebruiken!'
Reload: '&eConfig herlaadde met succes!'

View File

@@ -2,8 +2,8 @@
Messages:
Prefix: '&7[&6BetterRTP&7] '
Success:
Paid: '&aZostałeś przeniesiony do&7 x=%x% y=%y% z=%z% za &c$%price%&7 po &f%attempts% &7próbach!'
Bypass: '&aZostałeś przeniesiony do&7 x=%x% y=%y% z=%z% po &f%attempts% &7próbach'
Paid: '&aZostałeś przeniesiony do&7 x=%x% y=%y% z=%z% za &c$%price%&7!'
Bypass: '&aZostałeś przeniesiony do&7 x=%x% y=%y% z=%z%'
Loading: '&aZnaleziono bezpieczną strefę! &7Ładowanie chunków...'
Teleport: '&aTeleportuję... &fproszę czekać aż znajdziemy bezpieczną lokację!'
Failed:
@@ -11,7 +11,7 @@ Messages:
NotSafe: '&cNie udało się znaleź bezpiecznego miejsca po %attempts% próbach! &7Nie zostałeś przeniesiony!'
Hunger: '&cNie udało się wykonać losowej teleportacji, ponieważ jesteś &7zbyt głodny&c, zjedz coś!'
Other:
Success: '&a%player% został przeteleportowany do&7 x=%x% y=%y% z=%z% po &f%attempts% &7próbach!'
Success: '&a%player% został przeteleportowany do&7 x=%x% y=%y% z=%z%!'
NotSafe: '&cNie udało się znaleźć bezpiecznego miejsca po %attempts% próbach! &7%player% nie został przeteleportowany!'
Biome: '&cWygląda na to, że biom&7 %biome%&c nie istnieje! &7Spróbuj użyć biomu z listy!'
Reload: '&ePrzeładowano konfigurację!'

View File

@@ -1,8 +1,8 @@
Messages:
Prefix: '&7[&6BetterRTP&7] '
Success: ## PlaceHolder-ele! %x% %y% si %z% sunt x, y, si z coordonatelor ce apare player-ilor! #
Paid: '&aAi fost teleportat la coordonatele &7 x=%x% y=%y% z=%z% pentru &c$%price%&7 in &f%attempts% &7incercari!'
Bypass: '&aAi fost teleportat la coordonatele &7 x=%x% y=%y% z=%z% in &f%attempts% &7incercari'
Paid: '&aAi fost teleportat la coordonatele &7 x=%x% y=%y% z=%z% pentru &c$%price%&7!'
Bypass: '&aAi fost teleportat la coordonatele &7 x=%x% y=%y% z=%z%'
Loading: '&aUn loc sigur a fost gasit! &7Se incarca chunk-urile...'
Teleport: '&aTe teleportezi... &fte rugam sa astepti pana gasim un loc sigur!'
Failed:
@@ -10,7 +10,7 @@ Messages:
NotSafe: '&cNu am putut gasi un loc sigur in %attempts% incercari! &7Nu ai fost teleportat/a!'
Hunger: '&cNu te-am putut teleporta pentru ca esti... &7prea infometat&c, mananca ceva!'
Other:
Success: '&a%player% a fost teleportat la coordonatele &7 x=%x% y=%y% z=%z% in &f%attempts% &7incercari!'
Success: '&a%player% a fost teleportat la coordonatele &7 x=%x% y=%y% z=%z%!'
NotSafe: '&cNu am putut gasi un loc sigur in %attempts% incercari! &7%player% nu a fost teleportat/a!'
Biome: '&cSe pare ca biome-ul &7 %biome%&c nu exista! &7Incerca sa folosesti Tab-ul!'
Reload: '&eConfiguratia a fost reincarcata cu success!'