possible workaround for folia compatibility

This commit is contained in:
2024-04-16 16:29:26 +02:00
parent 375ef3de4e
commit c369c110e5
@@ -6,14 +6,11 @@ import me.youhavetrouble.preventstabby.api.event.PlayerLeaveCombatEvent;
import me.youhavetrouble.preventstabby.util.PluginMessages; import me.youhavetrouble.preventstabby.util.PluginMessages;
import me.youhavetrouble.preventstabby.util.PvpState; import me.youhavetrouble.preventstabby.util.PvpState;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@@ -32,16 +29,17 @@ public class PlayerManager {
playerList.values().removeIf(PlayerData::isCacheExpired); playerList.values().removeIf(PlayerData::isCacheExpired);
}, 250, 250, TimeUnit.MILLISECONDS); }, 250, 250, TimeUnit.MILLISECONDS);
Bukkit.getScheduler().runTaskTimer(plugin, (task -> { Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, (task) -> Bukkit.getWorlds().forEach((world -> {
List<LivingEntity> entities = new ArrayList<>(); for (Chunk chunk : world.getLoadedChunks()) {
Bukkit.getWorlds().forEach((world -> entities.addAll(world.getLivingEntities()))); if (!chunk.isEntitiesLoaded()) continue;
Bukkit.getAsyncScheduler().runNow(plugin, (asyncTask) -> entities.forEach(livingEntity -> { for (Entity entity : chunk.getEntities()) {
if (!(livingEntity instanceof Tameable tameable)) return; if (!(entity instanceof Tameable tameable)) continue;
UUID ownerId = tameable.getOwnerUniqueId(); UUID ownerId = tameable.getOwnerUniqueId();
if (ownerId == null) return; if (ownerId == null) continue;
getPlayerData(ownerId); getPlayerData(ownerId);
})); }
}), 5, 20 * 15); }
})), 5, 20 * 15);
Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, (task) -> { Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, (task) -> {
for (PlayerData playerData : playerList.values()) { for (PlayerData playerData : playerList.values()) {