Essentials /back support + Queue system bug fixes

This commit is contained in:
RonanCraft 2022-04-12 12:58:32 -04:00
parent 7f6afdfd7a
commit db0d64e404
24 changed files with 315 additions and 121 deletions

12
pom.xml
View File

@ -163,6 +163,11 @@
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
</repository>
<!-- EssentialsX Repo -->
<repository>
<id>essentials-releases</id>
<url>https://repo.essentialsx.net/releases/</url>
</repository>
</repositories>
<dependencies>
<!--Spigot API-->
@ -310,5 +315,12 @@
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<!-- EssentialsX -->
<dependency>
<groupId>net.essentialsx</groupId>
<artifactId>EssentialsX</artifactId>
<version>2.19.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -12,6 +12,7 @@ public enum RTPCommandType {
LOCATION(new CmdLocation()),
//SETTINGS(new CmdSettings(), true),
TEST(new CmdTest(), true),
Queue(new CmdQueue(), true),
VERSION(new CmdVersion()),
WORLD(new CmdWorld());

View File

@ -6,6 +6,7 @@ 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.rtpinfo.QueueHandler;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldDefault;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPlayer;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
@ -142,6 +143,7 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
info.add("&7- &eBiomes&7: &f" + _rtpworld.getBiomes().toString());
info.add("&7- &6Shape&7: &f" + _rtpworld.getShape().toString() + getInfo(_rtpworld, worldDefault, "shape"));
info.add("&7- &ePermission Group&7: " + (_rtpworld.getConfig() != null ? "&a" + _rtpworld.getConfig().getGroupName() : "&cN/A"));
info.add("&7- &6Queue Available&7: " + QueueHandler.getApplicable(_rtpworld).size());
}
}
return info;

View File

@ -0,0 +1,85 @@
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.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;
public class CmdQueue implements RTPCommand, RTPCommandHelpable {
public String getName() {
return "queue";
}
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);
}
@Override
public String getHelp() {
return null;
}
//World
public static void sendInfo(CommandSender sendi, List<String> list) { //Send info
list.add(0, "&e&m-----&6 BetterRTP &8| Queue &e&m-----");
list.forEach(str ->
list.set(list.indexOf(str), BetterRTP.getInstance().getText().color(str)));
sendi.sendMessage(list.toArray(new String[0]));
}
private void queueWorlds(CommandSender sendi) { //All worlds
List<String> info = new ArrayList<>();
for (World w : Bukkit.getWorlds())
info.addAll(queueGetWorld(w));
info.add("&eTotal of &a%amount% generated locations".replace("%amount%", String.valueOf(QueueHandler.getCount())));
sendInfo(sendi, info);
}
public static List<String> queueGetWorld(World world) { //Specific world
List<String> info = new ArrayList<>();
info.add("&eWorld: &6" + world.getName());
for (QueueData queue : QueueHandler.getApplicable(world)) {
String str = "&7x= &b%x, &7z= &b%z";
Location loc = queue.getLocation();
str = str.replace("%x", String.valueOf(loc.getBlockX())).replace("%z", String.valueOf(loc.getBlockZ()));
info.add(str);
}
return info;
}
public List<String> tabComplete(CommandSender sendi, String[] args) {
List<String> info = new ArrayList<>();
if (args.length == 2) {
for (World world : Bukkit.getWorlds())
if (world.getName().startsWith(args[1]))
info.add(world.getName());
}
return info;
}
public boolean permission(CommandSender sendi) {
return PermissionNode.ADMIN.check(sendi);
}
}

View File

@ -33,7 +33,7 @@ public class CmdTest implements RTPCommand, RTPCommandHelpable {
@Override
public boolean permission(CommandSender sendi) {
return PermissionNode.TEST.check(sendi);
return PermissionNode.ADMIN.check(sendi);
}
@Override

View File

@ -10,14 +10,14 @@ import org.bukkit.event.inventory.InventoryClickEvent;
public class Click {
public void click(InventoryClickEvent e) {
static void click(InventoryClickEvent e) {
if (!validClick(e))
return;
e.setCancelled(true);
handler(e);
}
private void handler(InventoryClickEvent e) {
static private void handler(InventoryClickEvent e) {
try {
Player p = (Player) e.getWhoClicked();
PlayerData data = HelperPlayer.getData(p);
@ -28,7 +28,7 @@ public class Click {
}
}
private boolean validClick(InventoryClickEvent e) {
static private boolean validClick(InventoryClickEvent e) {
//Not a player, or Not our inventory
if (!(e.getWhoClicked() instanceof Player) || e.isCancelled())
return false;

View File

@ -0,0 +1,12 @@
package me.SuperRonanCraft.BetterRTP.player.events;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_TeleportPostEvent;
import me.SuperRonanCraft.BetterRTP.references.depends.DepEssentials;
public class Custom {
static void postRTP(RTP_TeleportPostEvent e) {
DepEssentials.setBackLocation(e.getPlayer(), e.getOldLocation());
}
}

View File

@ -1,6 +1,7 @@
package me.SuperRonanCraft.BetterRTP.player.events;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_TeleportPostEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
@ -12,11 +13,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.PluginManager;
public class EventListener implements Listener {
private final Join join = new Join();
private final Leave leave = new Leave();
private final Interact interact = new Interact();
private final Click click = new Click();
//private final PluginEnable pEnable = new PluginEnable();
public void registerEvents(BetterRTP pl) {
PluginManager pm = pl.getServer().getPluginManager();
@ -28,33 +25,28 @@ public class EventListener implements Listener {
}
@EventHandler
@SuppressWarnings("unused")
private void onLeave(PlayerQuitEvent e) {
leave.event(e);
Leave.event(e);
}
@EventHandler
@SuppressWarnings("unused")
private void onJoin(PlayerJoinEvent e) {
join.event(e);
Join.event(e);
}
@EventHandler
@SuppressWarnings("unused")
private void onInteract(PlayerInteractEvent e) {
interact.event(e);
}
@EventHandler
@SuppressWarnings("unused")
private void interact(SignChangeEvent e) {
interact.createSign(e);
}
@EventHandler
@SuppressWarnings("unused")
private void click(InventoryClickEvent e) {
click.click(e);
Click.click(e);
}
@EventHandler
@ -62,8 +54,8 @@ public class EventListener implements Listener {
Teleport.tpEvent(e);
}
/*@EventHandler
private void enablePlugin(PluginEnableEvent e) {
pEnable.enabled(e);
}*/
@EventHandler
private void rtpPost(RTP_TeleportPostEvent e) {
Custom.postRTP(e);
}
}

View File

@ -61,7 +61,7 @@ class Interact {
BetterRTP.getInstance().getCmd().commandExecuted(p, "rtp", line);
}
private String cmd(String[] signArray) {
private static String cmd(String[] signArray) {
String actions = "";
for (int i = 1; i < signArray.length; i++) {
String line = signArray[i];
@ -74,7 +74,7 @@ class Interact {
return actions;
}
private boolean isSign(Block block) {
private static boolean isSign(Block block) {
return block.getState() instanceof Sign;
}
}

View File

@ -12,7 +12,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
public class Join {
void event(PlayerJoinEvent e) {
static void event(PlayerJoinEvent e) {
Player p = e.getPlayer();
updater(p);
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
@ -22,7 +22,7 @@ public class Join {
}
//Updater
private void updater(Player p) {
private static void updater(Player p) {
if (!getPl().getFiles().getType(FileBasics.FILETYPE.CONFIG).getBoolean("Settings.DisableUpdater") && PermissionNode.UPDATER.check(p))
if (!getPl().getDescription().getVersion().equals(Updater.updatedVersion))
getPl().getText().sms(p, "&7There is currently an update for &6BetterRTP &7version &e#" +
@ -30,12 +30,12 @@ public class Join {
}
//RTP on first join
private void rtpOnFirstJoin(Player p) {
private static void rtpOnFirstJoin(Player p) {
if (getPl().getSettings().isRtpOnFirstJoin_Enabled() && !p.hasPlayedBefore())
HelperRTP.tp(p, Bukkit.getConsoleSender(), Bukkit.getWorld(getPl().getSettings().getRtpOnFirstJoin_World()), null, RTP_TYPE.JOIN); //Console is sender to override delays
}
private BetterRTP getPl() {
private static BetterRTP getPl() {
return BetterRTP.getInstance();
}
}

View File

@ -6,7 +6,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
class Leave {
void event(PlayerQuitEvent e) {
static void event(PlayerQuitEvent e) {
Player p = e.getPlayer();
HelperPlayer.unload(p);
}

View File

@ -1,19 +0,0 @@
package me.SuperRonanCraft.BetterRTP.player.events;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import org.bukkit.event.server.PluginEnableEvent;
public class PluginEnable {
//In the case SoftDependencies plugins load after us!
void enabled(PluginEnableEvent e) {
String name = e.getPlugin().getName();
//System.out.println(name);
if (name.equalsIgnoreCase("WorldGuard"))
BetterRTP.getInstance().getSettings().getsDepends().registerWorldguard();
else if (name.equalsIgnoreCase("GriefPrevention"))
BetterRTP.getInstance().getSettings().getsDepends().registerGriefPrevention();
}
}

View File

@ -56,6 +56,7 @@ public class RTPPlayer {
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());
@ -101,7 +102,7 @@ public class RTPPlayer {
if ( b.getY() >= minY
&& b.getY() <= maxY
&& !badBlock(b.getType().name(), x, z, world, biomes)) {
return new Location(world, (x + 0.5), b.getY() + 1, (z + 0.5));
return new Location(world, x, b.getY() + 1, z);
}
return null;
}
@ -122,7 +123,7 @@ public class RTPPlayer {
continue;
if (world.getBlockAt(x, y + 1, z).getType().name().endsWith("AIR") //Head space
&& !badBlock(block, x, z, world, biomes)) //Valid block
return new Location(world, (x + 0.5), y, (z + 0.5));
return new Location(world, x, y, 0.5);
}
}
return null;

View File

@ -1,13 +1,13 @@
package me.SuperRonanCraft.BetterRTP.references;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.depends.DepPerms;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
public enum PermissionNode {
ADMIN("admin"),
USE("use"),
BYPASS_ECONOMY("bypass.economy"),
BYPASS_HUNGER("bypass.hunger"),
@ -21,7 +21,6 @@ public enum PermissionNode {
BIOME("biome"),
WORLD("world"),
SIGN_CREATE("sign"),
TEST("test"),
VERSION("version"),
EDIT("edit"),
LOCATION("location"),

View File

@ -87,8 +87,8 @@ public class DatabaseQueue extends SQLite {
//+ COLUMNS.USES.name + " "
+ ") VALUES(?, ?, ?, ?)";
List<Object> params = new ArrayList<Object>() {{
add(data.getLocation().getX());
add(data.getLocation().getZ());
add(data.getLocation().getBlockX());
add(data.getLocation().getBlockX());
add(data.getLocation().getWorld().getName());
add(data.getGenerated());
//add(data.getUses());

View File

@ -0,0 +1,19 @@
package me.SuperRonanCraft.BetterRTP.references.depends;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class DepEssentials {
public static void setBackLocation(Player player, Location location) {
Essentials ess = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
if (ess == null) return;
User user = ess.getUser(player.getUniqueId());
if (user == null) return;
user.setLastLocation(location);
}
}

View File

@ -7,14 +7,16 @@ 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.database.DatabaseQueue;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.*;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.RTPWorld;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldCustom;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldDefault;
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 java.util.*;
@ -22,8 +24,11 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
boolean loaded = false;
List<QueueData> queueList = new ArrayList<>();
private final int queueMax = 8, queueMin = 2; //Amount to ready up for each rtp world
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;
public void registerEvents(BetterRTP pl) {
PluginManager pm = pl.getServer().getPluginManager();
@ -32,8 +37,12 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
public void load() {
loaded = false;
if (task != null && Bukkit.getScheduler().isCurrentlyRunning(task.getTaskId()))
task.cancel();
if (!BetterRTP.getInstance().getSettings().isQueueEnabled())
return;
queueDownload();
queueGenerator(null, queueMax, queueMin, 0, "noone");
}
private void queueDownload() {
@ -48,6 +57,10 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
//Download all queue cached from last session
queueList = DatabaseHandler.getQueue().getQueues();
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(null, queueMax, queueMin, 0, "noone", 0);
}, 10L);
}
@ -60,7 +73,7 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
e.setLocation(data.location);
}
if (!generating)
queueGenerator(e.getWorld(), queueMax, queueMin, 0, "noone");
queueGenerator(e.getWorld(), queueMax, queueMin, 0, "noone", 0);
}
@EventHandler
@ -90,24 +103,27 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
}
private void queueGenerator(RTPWorld rtpWorld, int queueMax, int queueMin, int lastCount, @NonNull String lastType) {
if (queueMax != 10000)
return;
private void queueGenerator(RTPWorld rtpWorld, int queueMax, int queueMin, int lastCount, @NonNull String lastType, int attempts) {
/*if (queueList.size() >= queueSize) {
//Plenty of locations, cancel out
return;
}*/
generating = true;
Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
task = Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
//Generate more locations
//Rare cases where a rtp world didnt have a location generated (Permission Groups?)
if (rtpWorld != null) {
List<QueueData> applicable = getApplicable(rtpWorld);
String type = "superCustom_" + (rtpWorld.getID() != null ? rtpWorld.getID() : rtpWorld.getWorld().getName());
int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size();
int attempt = lastType.equalsIgnoreCase(type) ? 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(rtpWorld);
queueGenerator(rtpWorld, queueMax, queueMin, newCount, type); //Generate another later
queueGenerator(rtpWorld, queueMax, queueMin, newCount, type, attempt); //Generate another later
return;
}
if (lastType.equalsIgnoreCase(type))
@ -123,9 +139,14 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
List<QueueData> applicable = getApplicable(newWorld);
String type = "default_" + world.getName();
int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size();
int attempt = lastType.equalsIgnoreCase(type) ? 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() + ") world: " + world.getName());
continue;
}
generateFromWorld(newWorld);
queueGenerator(null, queueMax, queueMin, newCount, type); //Generate another later
queueGenerator(null, queueMax, queueMin, newCount, type, attempt); //Generate another later
return;
}
if (lastType.equalsIgnoreCase(type))
@ -139,13 +160,18 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
List<QueueData> applicable = getApplicable(world);
String type = "custom_" + customWorld.getKey();
int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size();
int attempt = lastType.equalsIgnoreCase(type) ? 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() + ") " + customWorld.getValue().getWorld().getName());
continue;
}
generateFromWorld(world);
queueGenerator(null, queueMax, queueMin, newCount, type); //Generate another later
queueGenerator(null, queueMax, queueMin, newCount, type, attempt); //Generate another later
return;
}
if (lastType.equalsIgnoreCase(type))
BetterRTP.debug("Queue max reached for " + type + " " + applicable.size() + " " + customWorld.getValue().getWorld().getName() + " lastCount: " + lastCount);
BetterRTP.debug("Queue max reached for " + type + " (amount: " + applicable.size() + ") " + customWorld.getValue().getWorld().getName() + " lastCount: " + lastCount);
}
//Generate Locations
@ -154,15 +180,21 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
List<QueueData> applicable = getApplicable(world);
String type = "location_" + location.getValue().getID();
int newCount = lastType.equalsIgnoreCase(type) ? lastCount : applicable.size();
int attempt = lastType.equalsIgnoreCase(type) ? attempts + 1 : 0;
if (newCount < queueMin && applicable.size() < queueMax) {
if (attempt > queueMaxAttempts) {
BetterRTP.debug("Max attempts to create a Queue reached for " + type + " " + applicable.size() + " " + location.getValue().getID());
continue;
}
generateFromWorld(world);
queueGenerator(null, queueMax, queueMin, newCount, type); //Generate another later
queueGenerator(null, queueMax, queueMin, newCount, type, attempt); //Generate another later
return;
}
if (lastType.equalsIgnoreCase(type))
BetterRTP.debug("Queue max reached for " + type + " " + applicable.size() + " " + location.getValue().getID() + " lastCount: " + lastCount);
}
generating = false;
BetterRTP.debug("Queueing paused, max queue limit reached!");
}, 20L * 5 /*delay before starting queue generator*/);
}
@ -176,7 +208,9 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
}
private void addQueue(RTPWorld rtpWorld, QueueData data) {
Location loc = RTPPlayer.getSafeLocation(
Location loc = null;
if (data.getLocation() != null)
loc = RTPPlayer.getSafeLocation(
RTP.getWorldType(rtpWorld),
data.getLocation().getWorld(),
data.getLocation(),
@ -190,8 +224,19 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
BetterRTP.debug("Queue position added " + data.getLocation().toString());
} else
BetterRTP.debug("Database error occured for a queue! " + data.getLocation().toString());
} else if (data.getLocation() != null) {
/*BetterRTP.debug("Queue position wasn't safe " + data.getLocation().toString());
if (BetterRTP.getInstance().getSettings().isDebug()) {
Logger log = BetterRTP.getInstance().getLogger();
log.info("- CenterX: " + rtpWorld.getCenterX());
log.info("- CenterZ: " + rtpWorld.getCenterZ());
log.info("- MaxRadius: " + rtpWorld.getMaxRadius());
log.info("- MinRadius: " + rtpWorld.getMinRadius());
log.info("- MinY: " + rtpWorld.getMinY());
log.info("- MaxY: " + rtpWorld.getMaxY());
}*/
} else
BetterRTP.debug("Queue position wasn't safe " + data.getLocation().toString());
BetterRTP.debug("Queue position wasn't able to generate a location!");
}
public static List<QueueData> getApplicable(RTPWorld rtpWorld) {
@ -205,6 +250,7 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
if (isInCircle(data.location, rtpWorld))
available.add(data);
break;
case SQUARE:
default:
if (isInSquare(data.location, rtpWorld))
available.add(data);
@ -213,6 +259,19 @@ public class QueueHandler implements Listener { //Randomly queues up some safe l
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();
}
private static boolean isInCircle(Location loc, RTPWorld rtpWorld) {
int center_x = rtpWorld.getCenterX();
int center_z = rtpWorld.getCenterZ();

View File

@ -2,6 +2,7 @@ package me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds;
import lombok.NonNull;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.commands.RTP_SETUP_TYPE;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_SHAPE;
import org.bukkit.World;
import org.jetbrains.annotations.Nullable;

View File

@ -10,11 +10,12 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
public World world;
private boolean useWorldborder;
private int centerX, centerZ, maxBorderRad, minBorderRad, price, miny, maxy;
private int centerX, centerZ, maxRad, minRad, price, miny, maxy;
private List<String> biomes;
private RTP_SHAPE shape;
@ -50,22 +51,22 @@ public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
}
if (test.get("MaxRadius") != null) {
if (test.get("MaxRadius").getClass() == Integer.class)
maxBorderRad = Integer.parseInt((test.get("MaxRadius")).toString());
if (maxBorderRad <= 0) {
maxRad = Integer.parseInt((test.get("MaxRadius")).toString());
if (maxRad <= 0) {
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Custom world '" + world + "' Maximum radius of '" + maxBorderRad + "' is not allowed! Set to default value!");
maxBorderRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMaxRadius();
"WARNING! Custom world '" + world + "' Maximum radius of '" + maxRad + "' is not allowed! Set to default value!");
maxRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMaxRadius();
}
}
if (test.get("MinRadius") != null) {
if (test.get("MinRadius").getClass() == Integer.class)
minBorderRad = Integer.parseInt((test.get("MinRadius")).toString());
if (minBorderRad < 0 || minBorderRad >= maxBorderRad) {
minRad = Integer.parseInt((test.get("MinRadius")).toString());
if (minRad < 0 || minRad >= maxRad) {
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Custom world '" + world + "' Minimum radius of '" + minBorderRad + "' is not allowed! Set to default value!");
minBorderRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMinRadius();
if (minBorderRad >= maxBorderRad)
maxBorderRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMaxRadius();
"WARNING! Custom world '" + world + "' Minimum radius of '" + minRad + "' is not allowed! Set to default value!");
minRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMinRadius();
if (minRad >= maxRad)
maxRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMaxRadius();
}
}
if (test.get("Biomes") != null) {
@ -105,16 +106,16 @@ public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
CenterX = config.getInt(pre + world + ".CenterX");
CenterZ = config.getInt(pre + world + ".CenterZ");
maxBorderRad = config.getInt(pre + world + ".MaxRadius");*/
if (maxBorderRad <= 0) {
if (maxRad <= 0) {
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Custom world '" + world + "' Maximum radius of '" + maxBorderRad + "' is not allowed! Set to default value!");
maxBorderRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMaxRadius();
"WARNING! Custom world '" + world + "' Maximum radius of '" + maxRad + "' is not allowed! Set to default value!");
maxRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMaxRadius();
}
//minBorderRad = config.getInt(pre + world + ".MinRadius");
if (minBorderRad <= 0 || minBorderRad >= maxBorderRad) {
if (minRad < 0 || minRad >= maxRad) {
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Custom world '" + world + "' Minimum radius of '" + minBorderRad + "' is not allowed! Set to default value!");
minBorderRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMinRadius();
"WARNING! Custom world '" + world + "' Minimum radius of '" + minRad + "' is not allowed! Set to default value!");
minRad = BetterRTP.getInstance().getRTP().RTPdefaultWorld.getMinRadius();
}
/*if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled"))
if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("CustomWorlds.Enabled")) {
@ -132,6 +133,19 @@ public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
price = worldDefault.getPrice();*/
//Other
//this.Biomes = config.getStringList("CustomWorlds." + world + ".Biomes");
if (BetterRTP.getInstance().getSettings().isDebug()) {
Logger log = BetterRTP.getInstance().getLogger();
log.info("- -World: " + this.world.getName());
log.info("- UseWorldBorder: " + this.useWorldborder);
log.info("- CenterX: " + this.centerX);
log.info("- CenterZ: " + this.centerZ);
log.info("- MaxRadius: " + this.maxRad);
log.info("- MinRadius: " + this.minRad);
log.info("- Price: " + this.price);
log.info("- MinY: " + this.miny);
log.info("- MaxY: " + this.maxy);
}
}
public WorldCustom(World world, RTPWorld rtpWorld) {
@ -156,12 +170,12 @@ public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
@Override
public int getMaxRadius() {
return maxBorderRad;
return maxRad;
}
@Override
public int getMinRadius() {
return minBorderRad;
return minRad;
}
@Override
@ -213,12 +227,12 @@ public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
@Override
public void setMaxRadius(int value) {
this.maxBorderRad = value;
this.maxRad = value;
}
@Override
public void setMinRadius(int value) {
this.minBorderRad = value;
this.minRad = value;
}
@Override

View File

@ -14,7 +14,7 @@ import java.util.logging.Logger;
public class WorldDefault implements RTPWorld {
private boolean useWorldborder;
private int CenterX, CenterZ, maxBorderRad, minBorderRad, price, miny, maxy;
private int centerX, centerZ, maxRad, minRad, price, miny, maxy;
private List<String> Biomes;
private final HashMap<String, Integer> prices = new HashMap<>();
private RTP_SHAPE shape;
@ -27,22 +27,22 @@ public class WorldDefault implements RTPWorld {
//Booleans
useWorldborder = config.getBoolean(pre + ".UseWorldBorder");
//Integers
CenterX = config.getInt(pre + ".CenterX");
CenterZ = config.getInt(pre + ".CenterZ");
maxBorderRad = config.getInt(pre + ".MaxRadius");
centerX = config.getInt(pre + ".CenterX");
centerZ = config.getInt(pre + ".CenterZ");
maxRad = config.getInt(pre + ".MaxRadius");
try {
shape = RTP_SHAPE.valueOf(config.getString(pre + ".Shape").toUpperCase());
} catch (Exception e) {
shape = RTP_SHAPE.SQUARE;
}
if (maxBorderRad <= 0) {
BetterRTP.getInstance().getLogger().warning("WARNING! Default Maximum radius of '" + maxBorderRad + "' is not allowed! Value set to '1000'");
maxBorderRad = 1000;
if (maxRad <= 0) {
BetterRTP.getInstance().getLogger().warning("WARNING! Default Maximum radius of '" + maxRad + "' is not allowed! Value set to '1000'");
maxRad = 1000;
}
minBorderRad = config.getInt(pre + ".MinRadius");
if (minBorderRad < 0 || minBorderRad >= maxBorderRad) {
BetterRTP.getInstance().getLogger().warning("The Default MinRadius of '" + minBorderRad + "' is not allowed! Value set to '0'");
minBorderRad = 0;
minRad = config.getInt(pre + ".MinRadius");
if (minRad < 0 || minRad >= maxRad) {
BetterRTP.getInstance().getLogger().warning("The Default MinRadius of '" + minRad + "' is not allowed! Value set to '0'");
minRad = 0;
}
prices.clear();
if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled")) {
@ -75,10 +75,10 @@ public class WorldDefault implements RTPWorld {
if (BetterRTP.getInstance().getSettings().isDebug()) {
Logger log = BetterRTP.getInstance().getLogger();
log.info("- UseWorldBorder: " + this.useWorldborder);
log.info("- CenterX: " + this.CenterX);
log.info("- CenterZ: " + this.CenterZ);
log.info("- MaxRadius: " + this.maxBorderRad);
log.info("- MinRadius: " + this.minBorderRad);
log.info("- CenterX: " + this.centerX);
log.info("- CenterZ: " + this.centerZ);
log.info("- MaxRadius: " + this.maxRad);
log.info("- MinRadius: " + this.minRad);
log.info("- Price: " + this.price);
log.info("- MinY: " + this.miny);
log.info("- MaxY: " + this.maxy);
@ -92,22 +92,22 @@ public class WorldDefault implements RTPWorld {
@Override
public int getCenterX() {
return CenterX;
return centerX;
}
@Override
public int getCenterZ() {
return CenterZ;
return centerZ;
}
@Override
public int getMaxRadius() {
return maxBorderRad;
return maxRad;
}
@Override
public int getMinRadius() {
return minBorderRad;
return minRad;
}
public int getPrice(String world) {

View File

@ -112,19 +112,30 @@ public class WorldPlayer implements RTPWorld, RTPWorld_Defaulted {
int max = rtpWorld.getMaxRadius() - min;
int x, z;
int quadrant = new Random().nextInt(4);
switch (quadrant) {
case 0: // Positive X and Z
x = new Random().nextInt(max) + min;
z = new Random().nextInt(max) + min; break;
case 1: // Negative X and Z
x = -new Random().nextInt(max) - min;
z = -(new Random().nextInt(max) + min); break;
case 2: // Negative X and Positive Z
x = -new Random().nextInt(max) - min;
z = new Random().nextInt(max) + min; break;
default: // Positive X and Negative Z
x = new Random().nextInt(max) + min;
z = -(new Random().nextInt(max) + min); break;
try {
switch (quadrant) {
case 0: // Positive X and Z
x = new Random().nextInt(max) + min;
z = new Random().nextInt(max) + min;
break;
case 1: // Negative X and Z
x = -new Random().nextInt(max) - min;
z = -(new Random().nextInt(max) + min);
break;
case 2: // Negative X and Positive Z
x = -new Random().nextInt(max) - min;
z = new Random().nextInt(max) + min;
break;
default: // Positive X and Negative Z
x = new Random().nextInt(max) + min;
z = -(new Random().nextInt(max) + min);
break;
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
BetterRTP.getInstance().getLogger().warning("A bounding location was negative! Please check your config only has positive x/z for max/min radius!");
BetterRTP.getInstance().getLogger().warning("Max: " + rtpWorld.getMaxRadius() + " Min: " + rtpWorld.getMinRadius());
return null;
}
x += rtpWorld.getCenterX();
z += rtpWorld.getCenterZ();

View File

@ -21,6 +21,7 @@ public class Settings {
@Getter private boolean locationNeedPermission;
@Getter private boolean locationOnlyAllowInWorld;
@Getter private boolean permissionGroupEnabled;
@Getter private boolean queueEnabled;
public void load() { //Load Settings
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
@ -33,6 +34,7 @@ public class Settings {
preloadRadius = config.getInt("Settings.PreloadRadius");
statusMessages = config.getBoolean("Settings.StatusMessages");
permissionGroupEnabled = config.getBoolean("PermissionGroup.Enabled");
queueEnabled = config.getBoolean("Settings.Queue.Enabled");
protocolLibSounds = FileBasics.FILETYPE.EFFECTS.getBoolean("Sounds.ProtocolLibSound");
useLocationIfAvailable = FileBasics.FILETYPE.LOCATIONS.getBoolean("UseLocationIfAvailable");
locationNeedPermission = FileBasics.FILETYPE.LOCATIONS.getBoolean("RequirePermission");

View File

@ -47,6 +47,8 @@ Settings:
Enabled: true
Time: 5
CancelOnMove: true
Queue:
Enabled: true #Allows betterrtp to automatically queue up safe rtp locations prior to players executing `/rtp`
DisableUpdater: false
Default:

View File

@ -18,6 +18,7 @@ softdepend:
- UltimateClaims
- Pueblos
- Multiverse-Core #Forcing Multiverse to load BEFORE BetterRTP
- Essentials #adds `/back` support
api-version: '1.13'
commands: