queue system implementation, still working on

This commit is contained in:
SuperRonanCraft 2020-12-18 13:56:23 -05:00
parent 253fa73100
commit 538bfa95ce
5 changed files with 98 additions and 26 deletions

View File

@ -179,34 +179,13 @@ public class RTP {
getPl().getCmd().cooldowns.add(p.getUniqueId());
getPl().getCmd().rtping.put(p.getUniqueId(), true); //Cache player so they cant run '/rtp' again while rtp'ing
//Setup player rtp methods
RTPPlayer rtp = new RTPPlayer(p, this, pWorld, type);
RTPPlayer rtpPlayer = new RTPPlayer(p, this, pWorld, type);
// Delaying? Else, just go
if (getPl().getSettings().delayEnabled && delay) {
new RTPDelay(sendi, rtp, delayTime, cancelOnMove, cancelOnDamage);
new RTPDelay(sendi, rtpPlayer, delayTime, cancelOnMove, cancelOnDamage);
} else {
teleport.beforeTeleportInstant(sendi, p);
rtp.randomlyTeleport(sendi);
}
}
private static class Queue {
private int queueAmount;
private final List<Location> locationList = new ArrayList<>();
Location getQueue() {
Location loc = null;
if (!locationList.isEmpty())
loc = locationList.get(0);
return loc;
}
void removeFromQueue(Location loc) {
locationList.remove(loc);
}
void startQueue() {
rtpPlayer.randomlyTeleport(sendi);
}
}
}

View File

@ -1,5 +1,6 @@
package me.SuperRonanCraft.BetterRTP.player.rtp;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_FindLocationEvent;
import me.SuperRonanCraft.BetterRTP.references.worlds.WorldPlayer;
import io.papermc.lib.PaperLib;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
@ -35,7 +36,14 @@ public class RTPPlayer {
if (pWorld.getAttempts() >= settings.maxAttempts) //Cancel out, too many tries
metMax(sendi, p);
else { //Try again to find a safe location
Location loc = pWorld.generateRandomXZ(settings.defaultWorld); //randomLoc(pWorld);
//Find a queue'd location
RTP_FindLocationEvent event = new RTP_FindLocationEvent(p, pWorld); //Find a queue'd location
Location loc;
if (event.getLocation() != null && pWorld.checkIsValid(event.getLocation()))
loc = event.getLocation();
else
loc = pWorld.generateRandomXZ();
//Load chunk and find out if safe location
CompletableFuture<Chunk> chunk = PaperLib.getChunkAtAsync(pWorld.getWorld(), loc.getBlockX(), loc.getBlockZ());
chunk.thenAccept(result -> {
//BetterRTP.debug("Checking location for " + p.getName());

View File

@ -0,0 +1,32 @@
package me.SuperRonanCraft.BetterRTP.player.rtp.queue;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_FindLocationEvent;
import me.SuperRonanCraft.BetterRTP.references.worlds.RTPWorld;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import java.util.HashMap;
import java.util.List;
public class RTPQueue implements Listener { //Randomly queues up some randomly safe locations
HashMap<RTPWorld, List<Location>> queue = new HashMap<>();
public void load() {
Bukkit.getPluginManager().registerEvents(this, BetterRTP.getInstance());
//queue();
}
@EventHandler
public void onRtpFindLoc(RTP_FindLocationEvent e) {
RTPWorld world = e.getWorld();
}
private void queue(RTPWorld world) {
}
}

View File

@ -0,0 +1,33 @@
package me.SuperRonanCraft.BetterRTP.references.customEvents;
import me.SuperRonanCraft.BetterRTP.references.worlds.RTPWorld;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class RTP_FindLocationEvent {
Player p;
RTPWorld world;
Location loc = null;
public RTP_FindLocationEvent(Player p, RTPWorld world) {
this.p = p;
this.world = world;
}
public void setLocation(Location loc) {
this.loc = loc;
}
public Location getLocation() {
return loc;
}
public RTPWorld getWorld() {
return world;
}
public Player getPlayer() {
return p;
}
}

View File

@ -91,7 +91,27 @@ public class WorldPlayer implements RTPWorld {
return (Player) p;
}
public Location generateRandomXZ(WorldDefault defaultWorld) {
public boolean checkIsValid(Location loc) { //Will check if a previously given location is valid
if (loc.getWorld() != getWorld())
return false;
int _xLMax = getCenterX() - getMaxRad(); //I|-||
int _xLMin = getCenterX() - getMinRad(); //|I-||
int _xRMax = getCenterX() + getMaxRad(); //||-|I
int _xRMin = getCenterX() + getMinRad(); //||-I|
int _xLoc = loc.getBlockX();
if (_xLoc < _xLMax || (_xLoc > _xLMin && _xLoc < _xRMin) || _xLoc > _xRMax)
return false;
int _zLMax = getCenterZ() - getMaxRad(); //I|-||
int _zLMin = getCenterZ() - getMinRad(); //|I-||
int _zRMax = getCenterZ() + getMaxRad(); //||-|I
int _zRMin = getCenterZ() + getMinRad(); //||-I|
int _zLoc = loc.getBlockX();
if (_zLoc < _zLMax || (_zLoc > _zLMin && _zLoc < _zRMin) || _zLoc > _zRMax)
return false;
return true;
}
public Location generateRandomXZ() {
int borderRad = getMaxRad();
int minVal = getMinRad();