Added support for Folia

This commit is contained in:
Intelli 2023-03-23 19:45:44 -06:00
parent 29345e2fb1
commit 7170e29452
20 changed files with 1095 additions and 942 deletions

View file

@ -1,6 +1,5 @@
package net.coreprotect.utility;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
@ -9,6 +8,7 @@ import org.bukkit.block.data.type.Chest;
import org.bukkit.block.data.type.Chest.Type;
import net.coreprotect.CoreProtect;
import net.coreprotect.thread.Scheduler;
public class ChestTool {
@ -75,7 +75,7 @@ public class ChestTool {
}
private static void validateContainer(BlockData blockData, Type newType, Block block, Block relativeBlock) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
Scheduler.scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
try {
BlockData relativeBlockData = relativeBlock.getBlockData();
if (!blockData.getAsString().equals(block.getBlockData().getAsString()) || !(relativeBlockData instanceof Chest) || ((Chest) relativeBlockData).getType() == newType) {
@ -89,7 +89,7 @@ public class ChestTool {
catch (Exception e) {
e.printStackTrace();
}
}, 2);
}, relativeBlock.getLocation(), 2);
}
}

View file

@ -59,6 +59,7 @@ import net.coreprotect.database.Rollback;
import net.coreprotect.language.Phrase;
import net.coreprotect.model.BlockGroup;
import net.coreprotect.thread.CacheHandler;
import net.coreprotect.thread.Scheduler;
import net.coreprotect.utility.serialize.ItemMetaHandler;
import net.coreprotect.worldedit.CoreProtectEditSessionEvent;
@ -1281,6 +1282,17 @@ public class Util extends Queue {
return true;
}
public static boolean isFolia() {
try {
Class.forName("io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler");
}
catch (Exception e) {
return false;
}
return true;
}
public static String getBranch() {
String branch = "";
try {
@ -1521,7 +1533,7 @@ public class Util extends Queue {
}
public static void updateBlock(final BlockState block) {
Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
Scheduler.runTask(CoreProtect.getInstance(), () -> {
try {
if (block.getBlockData() instanceof Waterlogged) {
Block currentBlock = block.getBlock();
@ -1534,7 +1546,7 @@ public class Util extends Queue {
catch (Exception e) {
e.printStackTrace();
}
});
}, block.getLocation());
}
public static void updateInventory(Player player) {

View file

@ -59,6 +59,7 @@ import net.coreprotect.CoreProtect;
import net.coreprotect.bukkit.BukkitAdapter;
import net.coreprotect.database.Rollback;
import net.coreprotect.thread.CacheHandler;
import net.coreprotect.thread.Scheduler;
import net.coreprotect.utility.Util;
public class EntityUtil {
@ -71,7 +72,7 @@ public class EntityUtil {
if (type == null) {
return;
}
Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
Scheduler.runTask(CoreProtect.getInstance(), () -> {
try {
Location location = block.getLocation();
location.setX(location.getX() + 0.50);
@ -557,7 +558,7 @@ public class EntityUtil {
catch (Exception e) {
e.printStackTrace();
}
});
}, block.getLocation());
}
}