Cooldown disabled bug fix

framework to cancel teleports while chunks are loading
This commit is contained in:
SuperRonanCraft 2020-08-12 16:41:03 -04:00
parent fd1c7c5c14
commit e720f5e600
4 changed files with 22 additions and 8 deletions

View File

@ -9,11 +9,13 @@ import me.SuperRonanCraft.BetterRTP.Main;
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import me.SuperRonanCraft.BetterRTP.references.worlds.*;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashMap;
import java.util.List;

View File

@ -35,6 +35,7 @@ public class RTPCooldown {
}
public void add(UUID id) {
if (!enabled) return;
cooldowns.put(id, System.currentTimeMillis());
if (lockedAfter > 0) {
if (locked.containsKey(id))
@ -62,6 +63,7 @@ public class RTPCooldown {
}
public void remove(UUID id) {
if (!enabled) return;
if (lockedAfter > 0) {
locked.put(id, locked.getOrDefault(id, 1) - 1);
if (locked.get(id) <= 0) { //Remove from file as well
@ -78,7 +80,7 @@ public class RTPCooldown {
private void savePlayer(UUID id, boolean adding, long time, int attempts) {
YamlConfiguration config = getFile();
assert config != null;
if (config == null) return;
if (adding) { //Add player to file
config.set(id.toString() + ".Time", time);
if (attempts > 0)
@ -123,7 +125,7 @@ public class RTPCooldown {
config = null;
configfile = new File(Main.getInstance().getDataFolder(), "data/cooldowns.yml");
YamlConfiguration config = getFile();
assert config != null;
if (config != null)
for (String id : config.getKeys(false)) {
try {
UUID uuid = UUID.fromString(id);

View File

@ -56,9 +56,9 @@ class RTPDelay implements Listener {
if (cancelOnMove)
if (e.getPlayer().equals(pWorld.getPlayer()) &&
(e.getTo() != null &&
(e.getTo().getX() != e.getFrom().getX() ||
e.getTo().getY() != e.getFrom().getY() ||
e.getTo().getZ() != e.getFrom().getZ()))
(e.getTo().getBlockX() != e.getFrom().getBlockX() ||
e.getTo().getBlockY() != e.getFrom().getBlockY() ||
e.getTo().getBlockZ() != e.getFrom().getBlockZ()))
) {
cancel();
}

View File

@ -10,6 +10,7 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@ -26,6 +27,8 @@ public class RTPTeleport {
private final RTPSounds eSounds = new RTPSounds();
private final RTPTitles eTitles = new RTPTitles();
//public HashMap<Player, List<CompletableFuture<Chunk>>> playerLoads = new HashMap<>();
void load() {
eParticles.load();
ePotions.load();
@ -33,10 +36,17 @@ public class RTPTeleport {
eTitles.load();
}
// void cancel(Player p) { //Cancel loading chunks/teleporting
// if (!playerLoads.containsKey(p)) return;
// List<CompletableFuture<Chunk>> asyncChunks = playerLoads.get(p);
// CompletableFuture.allOf(asyncChunks.toArray(new CompletableFuture[] {})).cancel(true);
// }
void sendPlayer(final CommandSender sendi, final Player p, final Location loc, final int price,
final int attempts) throws NullPointerException {
loadingTeleport(p, sendi); //Send loading message to player who requested
List<CompletableFuture<Chunk>> asyncChunks = getChunks(loc); //Get a list of chunks
//playerLoads.put(p, asyncChunks);
CompletableFuture.allOf(asyncChunks.toArray(new CompletableFuture[] {})).thenRun(() -> { //Async chunk load
new BukkitRunnable() { //Run synchronously
@Override