mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-12-28 17:47:41 +01:00
Added support for Folia
This commit is contained in:
parent
29345e2fb1
commit
7170e29452
8
pom.xml
8
pom.xml
@ -82,7 +82,7 @@
|
|||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>paper-repo</id>
|
<id>paper-repo</id>
|
||||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>codemc-repo</id>
|
<id>codemc-repo</id>
|
||||||
@ -100,9 +100,9 @@
|
|||||||
bukkit: org.bukkit
|
bukkit: org.bukkit
|
||||||
-->
|
-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc.paper</groupId>
|
<groupId>dev.folia</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>folia-api</artifactId>
|
||||||
<version>1.19-R0.1-SNAPSHOT</version>
|
<version>1.19.4-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -21,6 +21,7 @@ import net.coreprotect.listener.player.PlayerQuitListener;
|
|||||||
import net.coreprotect.paper.PaperAdapter;
|
import net.coreprotect.paper.PaperAdapter;
|
||||||
import net.coreprotect.thread.CacheHandler;
|
import net.coreprotect.thread.CacheHandler;
|
||||||
import net.coreprotect.thread.NetworkHandler;
|
import net.coreprotect.thread.NetworkHandler;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Chat;
|
import net.coreprotect.utility.Chat;
|
||||||
import net.coreprotect.utility.Color;
|
import net.coreprotect.utility.Color;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
@ -94,7 +95,7 @@ public final class CoreProtect extends JavaPlugin {
|
|||||||
Chat.console(Phrase.build(Phrase.LINK_DISCORD, "www.coreprotect.net/discord/"));
|
Chat.console(Phrase.build(Phrase.LINK_DISCORD, "www.coreprotect.net/discord/"));
|
||||||
Chat.console("--------------------");
|
Chat.console("--------------------");
|
||||||
|
|
||||||
getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
|
Scheduler.scheduleSyncDelayedTask(this, () -> {
|
||||||
try {
|
try {
|
||||||
Thread networkHandler = new Thread(new NetworkHandler(true, true));
|
Thread networkHandler = new Thread(new NetworkHandler(true, true));
|
||||||
networkHandler.start();
|
networkHandler.start();
|
||||||
|
@ -20,6 +20,7 @@ import org.bukkit.World;
|
|||||||
|
|
||||||
import net.coreprotect.CoreProtect;
|
import net.coreprotect.CoreProtect;
|
||||||
import net.coreprotect.language.Language;
|
import net.coreprotect.language.Language;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
|
|
||||||
public class Config extends Language {
|
public class Config extends Language {
|
||||||
|
|
||||||
@ -383,7 +384,7 @@ public class Config extends Language {
|
|||||||
// for now this solution is good enough to ensure we only modify on the main thread
|
// for now this solution is good enough to ensure we only modify on the main thread
|
||||||
final CompletableFuture<Void> complete = new CompletableFuture<>();
|
final CompletableFuture<Void> complete = new CompletableFuture<>();
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(CoreProtect.getInstance(), () -> {
|
Scheduler.runTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
parseConfig(data);
|
parseConfig(data);
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ public class ConfigHandler extends Queue {
|
|||||||
public static HikariDataSource hikariDataSource = null;
|
public static HikariDataSource hikariDataSource = null;
|
||||||
public static final boolean isSpigot = Util.isSpigot();
|
public static final boolean isSpigot = Util.isSpigot();
|
||||||
public static final boolean isPaper = Util.isPaper();
|
public static final boolean isPaper = Util.isPaper();
|
||||||
|
public static final boolean isFolia = Util.isFolia();
|
||||||
public static volatile boolean serverRunning = false;
|
public static volatile boolean serverRunning = false;
|
||||||
public static volatile boolean converterRunning = false;
|
public static volatile boolean converterRunning = false;
|
||||||
public static volatile boolean purgeRunning = false;
|
public static volatile boolean purgeRunning = false;
|
||||||
|
@ -24,6 +24,7 @@ import net.coreprotect.config.ConfigHandler;
|
|||||||
import net.coreprotect.consumer.process.Process;
|
import net.coreprotect.consumer.process.Process;
|
||||||
import net.coreprotect.listener.block.BlockUtil;
|
import net.coreprotect.listener.block.BlockUtil;
|
||||||
import net.coreprotect.model.BlockGroup;
|
import net.coreprotect.model.BlockGroup;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
|
|
||||||
public class Queue {
|
public class Queue {
|
||||||
@ -85,7 +86,7 @@ public class Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static void queueBlockBreakValidate(final String user, final Block block, final BlockState blockState, final Material type, final String blockData, final int extraData, int ticks) {
|
protected static void queueBlockBreakValidate(final String user, final Block block, final BlockState blockState, final Material type, final String blockData, final int extraData, int ticks) {
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
Scheduler.scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
if (!block.getType().equals(type)) {
|
if (!block.getType().equals(type)) {
|
||||||
queueBlockBreak(user, blockState, type, blockData, null, extraData, 0);
|
queueBlockBreak(user, blockState, type, blockData, null, extraData, 0);
|
||||||
@ -94,7 +95,7 @@ public class Queue {
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}, ticks);
|
}, block.getLocation(), ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void queueBlockBreak(String user, BlockState block, Material type, String blockData, Material breakType, int extraData, int blockNumber) {
|
protected static void queueBlockBreak(String user, BlockState block, Material type, String blockData, Material breakType, int extraData, int blockNumber) {
|
||||||
@ -178,18 +179,18 @@ public class Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static void queueBlockPlaceDelayed(final String user, final Location placed, final Material type, final String blockData, final BlockState replaced, int ticks) {
|
protected static void queueBlockPlaceDelayed(final String user, final Location placed, final Material type, final String blockData, final BlockState replaced, int ticks) {
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
Scheduler.scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
queueBlockPlace(user, placed.getBlock().getState(), type, replaced, null, -1, 0, blockData);
|
queueBlockPlace(user, placed.getBlock().getState(), type, replaced, null, -1, 0, blockData);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}, ticks);
|
}, placed, ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void queueBlockPlaceValidate(final String user, final BlockState blockLocation, final Block block, final BlockState blockReplaced, final Material forceT, final int forceD, final int forceData, final String blockData, int ticks) {
|
protected static void queueBlockPlaceValidate(final String user, final BlockState blockLocation, final Block block, final BlockState blockReplaced, final Material forceT, final int forceD, final int forceData, final String blockData, int ticks) {
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
Scheduler.scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
Material blockType = block.getType();
|
Material blockType = block.getType();
|
||||||
if (blockType.equals(forceT)) {
|
if (blockType.equals(forceT)) {
|
||||||
@ -204,11 +205,11 @@ public class Queue {
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}, ticks);
|
}, blockLocation.getLocation(), ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void queueBlockGravityValidate(final String user, final Location location, final Block block, final Material blockType, int ticks) {
|
protected static void queueBlockGravityValidate(final String user, final Location location, final Block block, final Material blockType, int ticks) {
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
Scheduler.scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
Block placementBlock = BlockUtil.gravityScan(location, blockType, user);
|
Block placementBlock = BlockUtil.gravityScan(location, blockType, user);
|
||||||
if (!block.equals(placementBlock)) {
|
if (!block.equals(placementBlock)) {
|
||||||
@ -218,7 +219,7 @@ public class Queue {
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}, ticks);
|
}, location, ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void queueContainerBreak(String user, Location location, Material type, ItemStack[] oldInventory) {
|
protected static void queueContainerBreak(String user, Location location, Material type, ItemStack[] oldInventory) {
|
||||||
|
@ -6,7 +6,6 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -24,6 +23,7 @@ import net.coreprotect.consumer.Queue;
|
|||||||
import net.coreprotect.consumer.process.Process;
|
import net.coreprotect.consumer.process.Process;
|
||||||
import net.coreprotect.language.Phrase;
|
import net.coreprotect.language.Phrase;
|
||||||
import net.coreprotect.model.BlockGroup;
|
import net.coreprotect.model.BlockGroup;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Chat;
|
import net.coreprotect.utility.Chat;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
|
|
||||||
@ -46,9 +46,9 @@ public class ContainerRollback extends Queue {
|
|||||||
Queue.queueRollbackUpdate(userString, location, lookupList, Process.CONTAINER_ROLLBACK_UPDATE, rollbackType); // Perform update transaction in consumer
|
Queue.queueRollbackUpdate(userString, location, lookupList, Process.CONTAINER_ROLLBACK_UPDATE, rollbackType); // Perform update transaction in consumer
|
||||||
|
|
||||||
final String finalUserString = userString;
|
final String finalUserString = userString;
|
||||||
ConfigHandler.rollbackHash.put(userString, new int[] { 0, 0, 0, 0 });
|
ConfigHandler.rollbackHash.put(userString, new int[] { 0, 0, 0, 0, 0 });
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), new Runnable() {
|
Scheduler.scheduleSyncDelayedTask(CoreProtect.getInstance(), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@ -140,13 +140,13 @@ public class ContainerRollback extends Queue {
|
|||||||
}
|
}
|
||||||
matchingFrames.clear();
|
matchingFrames.clear();
|
||||||
|
|
||||||
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount, modifyCount, entityCount, 1 });
|
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount, modifyCount, entityCount, 1, 1 });
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0);
|
}, location, 0);
|
||||||
|
|
||||||
int[] rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
int[] rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
||||||
int next = rollbackHashData[3];
|
int next = rollbackHashData[3];
|
||||||
|
@ -10,6 +10,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -90,6 +91,7 @@ import net.coreprotect.language.Phrase;
|
|||||||
import net.coreprotect.language.Selector;
|
import net.coreprotect.language.Selector;
|
||||||
import net.coreprotect.model.BlockGroup;
|
import net.coreprotect.model.BlockGroup;
|
||||||
import net.coreprotect.thread.CacheHandler;
|
import net.coreprotect.thread.CacheHandler;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Chat;
|
import net.coreprotect.utility.Chat;
|
||||||
import net.coreprotect.utility.ChestTool;
|
import net.coreprotect.utility.ChestTool;
|
||||||
import net.coreprotect.utility.Color;
|
import net.coreprotect.utility.Color;
|
||||||
@ -145,9 +147,10 @@ public class Rollback extends Queue {
|
|||||||
itemList = Lookup.performLookupRaw(statement, user, checkUuids, checkUsers, itemRestrictList, itemExcludeList, excludeUserList, itemActionList, location, radius, null, startTime, endTime, -1, -1, restrictWorld, lookup);
|
itemList = Lookup.performLookupRaw(statement, user, checkUuids, checkUsers, itemRestrictList, itemExcludeList, excludeUserList, itemActionList, location, radius, null, startTime, endTime, -1, -1, restrictWorld, lookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LinkedHashSet<Integer> worldList = new LinkedHashSet<>();
|
||||||
TreeMap<Long, Integer> chunkList = new TreeMap<>();
|
TreeMap<Long, Integer> chunkList = new TreeMap<>();
|
||||||
HashMap<Long, ArrayList<Object[]>> dataList = new HashMap<>();
|
HashMap<Integer, HashMap<Long, ArrayList<Object[]>>> dataList = new HashMap<>();
|
||||||
HashMap<Long, ArrayList<Object[]>> itemDataList = new HashMap<>();
|
HashMap<Integer, HashMap<Long, ArrayList<Object[]>>> itemDataList = new HashMap<>();
|
||||||
boolean inventoryRollback = actionList.contains(11);
|
boolean inventoryRollback = actionList.contains(11);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -216,33 +219,43 @@ public class Rollback extends Queue {
|
|||||||
UserStatement.loadName(statement.getConnection(), userId);
|
UserStatement.loadName(statement.getConnection(), userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<Long, ArrayList<Object[]>> modifyList = dataList;
|
HashMap<Integer, HashMap<Long, ArrayList<Object[]>>> modifyList = dataList;
|
||||||
if (listC == 1) {
|
if (listC == 1) {
|
||||||
modifyList = itemDataList;
|
modifyList = itemDataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modifyList.get(chunkKey) == null) {
|
if (modifyList.get(rowWorldId) == null) {
|
||||||
// Integer[][] chunkSections = new Integer[((worldMax - worldMin) >> 4)][];
|
dataList.put(rowWorldId, new HashMap<>());
|
||||||
// adjacentDataList.put(chunkKey, chunkSections);
|
itemDataList.put(rowWorldId, new HashMap<>());
|
||||||
dataList.put(chunkKey, new ArrayList<>());
|
worldList.add(rowWorldId);
|
||||||
itemDataList.put(chunkKey, new ArrayList<>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
modifyList.get(chunkKey).add(result);
|
if (modifyList.get(rowWorldId).get(chunkKey) == null) {
|
||||||
|
// Integer[][] chunkSections = new Integer[((worldMax - worldMin) >> 4)][];
|
||||||
|
// adjacentDataList.put(chunkKey, chunkSections);
|
||||||
|
dataList.get(rowWorldId).put(chunkKey, new ArrayList<>());
|
||||||
|
itemDataList.get(rowWorldId).put(chunkKey, new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
modifyList.get(rowWorldId).get(chunkKey).add(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
listC++;
|
listC++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rollbackType == 1) { // Restore
|
if (rollbackType == 1) { // Restore
|
||||||
Iterator<Map.Entry<Long, ArrayList<Object[]>>> dlIterator = dataList.entrySet().iterator();
|
Iterator<Map.Entry<Integer, HashMap<Long, ArrayList<Object[]>>>> dlIterator = dataList.entrySet().iterator();
|
||||||
while (dlIterator.hasNext()) {
|
while (dlIterator.hasNext()) {
|
||||||
Collections.reverse(dlIterator.next().getValue());
|
for (ArrayList<Object[]> map : dlIterator.next().getValue().values()) {
|
||||||
|
Collections.reverse(map);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dlIterator = itemDataList.entrySet().iterator();
|
dlIterator = itemDataList.entrySet().iterator();
|
||||||
while (dlIterator.hasNext()) {
|
while (dlIterator.hasNext()) {
|
||||||
Collections.reverse(dlIterator.next().getValue());
|
for (ArrayList<Object[]> map : dlIterator.next().getValue().values()) {
|
||||||
|
Collections.reverse(map);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +297,7 @@ public class Rollback extends Queue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigHandler.rollbackHash.put(userString, new int[] { 0, 0, 0, 0 });
|
ConfigHandler.rollbackHash.put(userString, new int[] { 0, 0, 0, 0, 0 });
|
||||||
|
|
||||||
final String finalUserString = userString;
|
final String finalUserString = userString;
|
||||||
for (Entry<Long, Integer> entry : Util.entriesSortedByValues(chunkList)) {
|
for (Entry<Long, Integer> entry : Util.entriesSortedByValues(chunkList)) {
|
||||||
@ -293,18 +306,42 @@ public class Rollback extends Queue {
|
|||||||
int itemCount = 0;
|
int itemCount = 0;
|
||||||
int blockCount = 0;
|
int blockCount = 0;
|
||||||
int entityCount = 0;
|
int entityCount = 0;
|
||||||
|
int scannedWorldData = 0;
|
||||||
int[] rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
int[] rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
||||||
itemCount = rollbackHashData[0];
|
itemCount = rollbackHashData[0];
|
||||||
blockCount = rollbackHashData[1];
|
blockCount = rollbackHashData[1];
|
||||||
entityCount = rollbackHashData[2];
|
entityCount = rollbackHashData[2];
|
||||||
|
scannedWorldData = rollbackHashData[4];
|
||||||
|
|
||||||
final long chunkKey = entry.getKey();
|
long chunkKey = entry.getKey();
|
||||||
|
final int finalChunkX = (int) chunkKey;
|
||||||
|
final int finalChunkZ = (int) (chunkKey >> 32);
|
||||||
final CommandSender finalUser = user;
|
final CommandSender finalUser = user;
|
||||||
final HashMap<Long, ArrayList<Object[]>> finalBlockList = dataList;
|
|
||||||
final HashMap<Long, ArrayList<Object[]>> finalItemList = itemDataList;
|
|
||||||
|
|
||||||
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount, blockCount, entityCount, 0 });
|
HashMap<Integer, World> worldMap = new HashMap<>();
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
for (int rollbackWorldId : worldList) {
|
||||||
|
String rollbackWorld = Util.getWorldName(rollbackWorldId);
|
||||||
|
if (rollbackWorld.length() == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
World bukkitRollbackWorld = Bukkit.getServer().getWorld(rollbackWorld);
|
||||||
|
if (bukkitRollbackWorld == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
worldMap.put(rollbackWorldId, bukkitRollbackWorld);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount, blockCount, entityCount, 0, scannedWorldData });
|
||||||
|
for (Entry<Integer, World> rollbackWorlds : worldMap.entrySet()) {
|
||||||
|
Integer rollbackWorldId = rollbackWorlds.getKey();
|
||||||
|
World bukkitRollbackWorld = rollbackWorlds.getValue();
|
||||||
|
Location chunkLocation = new Location(bukkitRollbackWorld, (finalChunkX << 4), 0, (finalChunkZ << 4));
|
||||||
|
final HashMap<Long, ArrayList<Object[]>> finalBlockList = dataList.get(rollbackWorldId);
|
||||||
|
final HashMap<Long, ArrayList<Object[]>> finalItemList = itemDataList.get(rollbackWorldId);
|
||||||
|
|
||||||
|
Scheduler.scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
boolean clearInventories = false;
|
boolean clearInventories = false;
|
||||||
if (Config.getGlobal().ROLLBACK_ITEMS) {
|
if (Config.getGlobal().ROLLBACK_ITEMS) {
|
||||||
@ -315,14 +352,13 @@ public class Rollback extends Queue {
|
|||||||
ArrayList<Object[]> itemData = finalItemList.get(chunkKey);
|
ArrayList<Object[]> itemData = finalItemList.get(chunkKey);
|
||||||
Map<Block, BlockData> chunkChanges = new LinkedHashMap<>();
|
Map<Block, BlockData> chunkChanges = new LinkedHashMap<>();
|
||||||
|
|
||||||
int finalChunkX = (int) chunkKey;
|
|
||||||
int finalChunkZ = (int) (chunkKey >> 32);
|
|
||||||
for (Object[] row : data) {
|
for (Object[] row : data) {
|
||||||
int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
|
int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
|
||||||
int[] rollbackHashData1 = ConfigHandler.rollbackHash.get(finalUserString);
|
int[] rollbackHashData1 = ConfigHandler.rollbackHash.get(finalUserString);
|
||||||
int itemCount1 = rollbackHashData1[0];
|
int itemCount1 = rollbackHashData1[0];
|
||||||
int blockCount1 = rollbackHashData1[1];
|
int blockCount1 = rollbackHashData1[1];
|
||||||
int entityCount1 = rollbackHashData1[2];
|
int entityCount1 = rollbackHashData1[2];
|
||||||
|
int scannedWorlds = rollbackHashData1[4];
|
||||||
// int rowId = row[0];
|
// int rowId = row[0];
|
||||||
int rowTime = (Integer) row[1];
|
int rowTime = (Integer) row[1];
|
||||||
int rowUserId = (Integer) row[2];
|
int rowUserId = (Integer) row[2];
|
||||||
@ -1024,7 +1060,7 @@ public class Rollback extends Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// count++;
|
// count++;
|
||||||
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount1, blockCount1, entityCount1, 0 });
|
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount1, blockCount1, entityCount1, 0, scannedWorlds });
|
||||||
}
|
}
|
||||||
data.clear();
|
data.clear();
|
||||||
|
|
||||||
@ -1056,6 +1092,7 @@ public class Rollback extends Queue {
|
|||||||
int itemCount1 = rollbackHashData1[0];
|
int itemCount1 = rollbackHashData1[0];
|
||||||
int blockCount1 = rollbackHashData1[1];
|
int blockCount1 = rollbackHashData1[1];
|
||||||
int entityCount1 = rollbackHashData1[2];
|
int entityCount1 = rollbackHashData1[2];
|
||||||
|
int scannedWorlds = rollbackHashData1[4];
|
||||||
int rowX = (Integer) row[3];
|
int rowX = (Integer) row[3];
|
||||||
int rowY = (Integer) row[4];
|
int rowY = (Integer) row[4];
|
||||||
int rowZ = (Integer) row[5];
|
int rowZ = (Integer) row[5];
|
||||||
@ -1115,7 +1152,7 @@ public class Rollback extends Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
itemCount1 = itemCount1 + rowAmount;
|
itemCount1 = itemCount1 + rowAmount;
|
||||||
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount1, blockCount1, entityCount1, 0 });
|
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount1, blockCount1, entityCount1, 0, scannedWorlds });
|
||||||
continue; // remove this for merged rollbacks in future? (be sure to re-enable chunk sorting)
|
continue; // remove this for merged rollbacks in future? (be sure to re-enable chunk sorting)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1200,7 +1237,7 @@ public class Rollback extends Queue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount1, blockCount1, entityCount1, 0 });
|
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount1, blockCount1, entityCount1, 0, scannedWorlds });
|
||||||
}
|
}
|
||||||
itemData.clear();
|
itemData.clear();
|
||||||
|
|
||||||
@ -1213,7 +1250,8 @@ public class Rollback extends Queue {
|
|||||||
int itemCount1 = rollbackHashData1[0];
|
int itemCount1 = rollbackHashData1[0];
|
||||||
int blockCount1 = rollbackHashData1[1];
|
int blockCount1 = rollbackHashData1[1];
|
||||||
int entityCount1 = rollbackHashData1[2];
|
int entityCount1 = rollbackHashData1[2];
|
||||||
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount1, blockCount1, entityCount1, 1 });
|
int scannedWorlds = rollbackHashData1[4];
|
||||||
|
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount1, blockCount1, entityCount1, 1, (scannedWorlds + 1) });
|
||||||
|
|
||||||
// Teleport players out of danger if they're within this chunk
|
// Teleport players out of danger if they're within this chunk
|
||||||
if (preview == 0) {
|
if (preview == 0) {
|
||||||
@ -1234,17 +1272,20 @@ public class Rollback extends Queue {
|
|||||||
int itemCount1 = rollbackHashData1[0];
|
int itemCount1 = rollbackHashData1[0];
|
||||||
int blockCount1 = rollbackHashData1[1];
|
int blockCount1 = rollbackHashData1[1];
|
||||||
int entityCount1 = rollbackHashData1[2];
|
int entityCount1 = rollbackHashData1[2];
|
||||||
|
int scannedWorlds = rollbackHashData1[4];
|
||||||
|
|
||||||
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount1, blockCount1, entityCount1, 2 });
|
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount1, blockCount1, entityCount1, 2, (scannedWorlds + 1) });
|
||||||
|
}
|
||||||
|
}, chunkLocation, 0);
|
||||||
}
|
}
|
||||||
}, 0);
|
|
||||||
|
|
||||||
rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
||||||
int next = rollbackHashData[3];
|
int next = rollbackHashData[3];
|
||||||
|
int scannedWorlds = rollbackHashData[4];
|
||||||
int sleepTime = 0;
|
int sleepTime = 0;
|
||||||
int abort = 0;
|
int abort = 0;
|
||||||
|
|
||||||
while (next == 0) {
|
while (next == 0 || scannedWorlds < worldMap.size()) {
|
||||||
if (preview == 1) {
|
if (preview == 1) {
|
||||||
// Not actually changing blocks, so less intensive.
|
// Not actually changing blocks, so less intensive.
|
||||||
sleepTime = sleepTime + 1;
|
sleepTime = sleepTime + 1;
|
||||||
@ -1257,6 +1298,7 @@ public class Rollback extends Queue {
|
|||||||
|
|
||||||
rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
||||||
next = rollbackHashData[3];
|
next = rollbackHashData[3];
|
||||||
|
scannedWorlds = rollbackHashData[4];
|
||||||
|
|
||||||
if (sleepTime > 300000) {
|
if (sleepTime > 300000) {
|
||||||
abort = 1;
|
abort = 1;
|
||||||
@ -1273,7 +1315,7 @@ public class Rollback extends Queue {
|
|||||||
itemCount = rollbackHashData[0];
|
itemCount = rollbackHashData[0];
|
||||||
blockCount = rollbackHashData[1];
|
blockCount = rollbackHashData[1];
|
||||||
entityCount = rollbackHashData[2];
|
entityCount = rollbackHashData[2];
|
||||||
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount, blockCount, entityCount, 0 });
|
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount, blockCount, entityCount, 0, 0 });
|
||||||
|
|
||||||
if (verbose && user != null && preview == 0 && !actionList.contains(11)) {
|
if (verbose && user != null && preview == 0 && !actionList.contains(11)) {
|
||||||
Integer chunks = chunkList.size();
|
Integer chunks = chunkList.size();
|
||||||
|
@ -2,7 +2,6 @@ package net.coreprotect.listener.entity;
|
|||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -35,6 +34,7 @@ import net.coreprotect.config.ConfigHandler;
|
|||||||
import net.coreprotect.consumer.Queue;
|
import net.coreprotect.consumer.Queue;
|
||||||
import net.coreprotect.database.Database;
|
import net.coreprotect.database.Database;
|
||||||
import net.coreprotect.listener.player.PlayerInteractEntityListener;
|
import net.coreprotect.listener.player.PlayerInteractEntityListener;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
|
|
||||||
public final class EntityDamageByEntityListener extends Queue implements Listener {
|
public final class EntityDamageByEntityListener extends Queue implements Listener {
|
||||||
@ -125,13 +125,13 @@ public final class EntityDamageByEntityListener extends Queue implements Listene
|
|||||||
if (Config.getConfig(entityLocation.getWorld()).ITEM_TRANSACTIONS) {
|
if (Config.getConfig(entityLocation.getWorld()).ITEM_TRANSACTIONS) {
|
||||||
String killer = user;
|
String killer = user;
|
||||||
ItemStack[] contents = Util.getContainerContents(Material.ARMOR_STAND, entity, block.getLocation());
|
ItemStack[] contents = Util.getContainerContents(Material.ARMOR_STAND, entity, block.getLocation());
|
||||||
Bukkit.getScheduler().runTask(CoreProtect.getInstance(), () -> {
|
Scheduler.runTask(CoreProtect.getInstance(), () -> {
|
||||||
if (entity != null && entity.isDead()) {
|
if (entity != null && entity.isDead()) {
|
||||||
entityLocation.setY(entityLocation.getY() + 0.99);
|
entityLocation.setY(entityLocation.getY() + 0.99);
|
||||||
Database.containerBreakCheck(killer, Material.ARMOR_STAND, entity, contents, block.getLocation());
|
Database.containerBreakCheck(killer, Material.ARMOR_STAND, entity, contents, block.getLocation());
|
||||||
Queue.queueBlockBreak(killer, block.getState(), Material.ARMOR_STAND, null, (int) entityLocation.getYaw());
|
Queue.queueBlockBreak(killer, block.getState(), Material.ARMOR_STAND, null, (int) entityLocation.getYaw());
|
||||||
}
|
}
|
||||||
});
|
}, entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ import net.coreprotect.CoreProtect;
|
|||||||
import net.coreprotect.bukkit.BukkitAdapter;
|
import net.coreprotect.bukkit.BukkitAdapter;
|
||||||
import net.coreprotect.config.Config;
|
import net.coreprotect.config.Config;
|
||||||
import net.coreprotect.consumer.Queue;
|
import net.coreprotect.consumer.Queue;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.serialize.ItemMetaHandler;
|
import net.coreprotect.utility.serialize.ItemMetaHandler;
|
||||||
|
|
||||||
public final class EntityDeathListener extends Queue implements Listener {
|
public final class EntityDeathListener extends Queue implements Listener {
|
||||||
@ -96,13 +97,13 @@ public final class EntityDeathListener extends Queue implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(CoreProtect.getInstance(), () -> {
|
|
||||||
for (LivingEntity entity : entityList) {
|
for (LivingEntity entity : entityList) {
|
||||||
|
Scheduler.runTask(CoreProtect.getInstance(), () -> {
|
||||||
if (entity != null && entity.isDead()) {
|
if (entity != null && entity.isDead()) {
|
||||||
logEntityDeath(entity, "#command");
|
logEntityDeath(entity, "#command");
|
||||||
}
|
}
|
||||||
|
}, entity);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void logEntityDeath(LivingEntity entity, String e) {
|
protected static void logEntityDeath(LivingEntity entity, String e) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.coreprotect.listener.player;
|
package net.coreprotect.listener.player;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -15,6 +14,7 @@ import org.bukkit.event.entity.FoodLevelChangeEvent;
|
|||||||
import net.coreprotect.CoreProtect;
|
import net.coreprotect.CoreProtect;
|
||||||
import net.coreprotect.consumer.Queue;
|
import net.coreprotect.consumer.Queue;
|
||||||
import net.coreprotect.thread.CacheHandler;
|
import net.coreprotect.thread.CacheHandler;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
|
|
||||||
public final class FoodLevelChangeListener extends Queue implements Listener {
|
public final class FoodLevelChangeListener extends Queue implements Listener {
|
||||||
@ -50,7 +50,7 @@ public final class FoodLevelChangeListener extends Queue implements Listener {
|
|||||||
}
|
}
|
||||||
final Material oldBlockType = oldType;
|
final Material oldBlockType = oldType;
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
|
Scheduler.runTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
Block newBlock = oldBlockState.getBlock();
|
Block newBlock = oldBlockState.getBlock();
|
||||||
BlockState newBlockState = newBlock.getState();
|
BlockState newBlockState = newBlock.getState();
|
||||||
@ -66,7 +66,7 @@ public final class FoodLevelChangeListener extends Queue implements Listener {
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
}, oldBlockState.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheHandler.interactCache.remove(coordinates);
|
CacheHandler.interactCache.remove(coordinates);
|
||||||
|
@ -5,7 +5,6 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.inventory.BrewerInventory;
|
import org.bukkit.inventory.BrewerInventory;
|
||||||
import org.bukkit.inventory.FurnaceInventory;
|
import org.bukkit.inventory.FurnaceInventory;
|
||||||
@ -16,6 +15,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import net.coreprotect.CoreProtect;
|
import net.coreprotect.CoreProtect;
|
||||||
import net.coreprotect.config.Config;
|
import net.coreprotect.config.Config;
|
||||||
import net.coreprotect.config.ConfigHandler;
|
import net.coreprotect.config.ConfigHandler;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
|
|
||||||
public final class HopperPullListener {
|
public final class HopperPullListener {
|
||||||
@ -38,7 +38,7 @@ public final class HopperPullListener {
|
|||||||
ItemStack movedItem = item.clone();
|
ItemStack movedItem = item.clone();
|
||||||
|
|
||||||
final long taskStarted = InventoryChangeListener.tasksStarted.incrementAndGet();
|
final long taskStarted = InventoryChangeListener.tasksStarted.incrementAndGet();
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(CoreProtect.getInstance(), () -> {
|
Scheduler.runTaskAsynchronously(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
if (sourceHolder == null || destinationHolder == null) {
|
if (sourceHolder == null || destinationHolder == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -5,7 +5,6 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.inventory.BrewerInventory;
|
import org.bukkit.inventory.BrewerInventory;
|
||||||
import org.bukkit.inventory.FurnaceInventory;
|
import org.bukkit.inventory.FurnaceInventory;
|
||||||
@ -16,6 +15,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import net.coreprotect.CoreProtect;
|
import net.coreprotect.CoreProtect;
|
||||||
import net.coreprotect.config.Config;
|
import net.coreprotect.config.Config;
|
||||||
import net.coreprotect.config.ConfigHandler;
|
import net.coreprotect.config.ConfigHandler;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
|
|
||||||
public final class HopperPushListener {
|
public final class HopperPushListener {
|
||||||
@ -38,7 +38,7 @@ public final class HopperPushListener {
|
|||||||
ItemStack movedItem = item.clone();
|
ItemStack movedItem = item.clone();
|
||||||
|
|
||||||
final long taskStarted = InventoryChangeListener.tasksStarted.incrementAndGet();
|
final long taskStarted = InventoryChangeListener.tasksStarted.incrementAndGet();
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(CoreProtect.getInstance(), () -> {
|
Scheduler.runTaskAsynchronously(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
if (sourceHolder == null || destinationHolder == null) {
|
if (sourceHolder == null || destinationHolder == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -6,7 +6,6 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -32,6 +31,7 @@ import net.coreprotect.config.ConfigHandler;
|
|||||||
import net.coreprotect.consumer.Queue;
|
import net.coreprotect.consumer.Queue;
|
||||||
import net.coreprotect.model.BlockGroup;
|
import net.coreprotect.model.BlockGroup;
|
||||||
import net.coreprotect.paper.PaperAdapter;
|
import net.coreprotect.paper.PaperAdapter;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
import net.coreprotect.utility.Validate;
|
import net.coreprotect.utility.Validate;
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ public final class InventoryChangeListener extends Queue implements Listener {
|
|||||||
ItemStack[] containerState = Util.getContainerState(inventory.getContents());
|
ItemStack[] containerState = Util.getContainerState(inventory.getContents());
|
||||||
|
|
||||||
final long taskStarted = InventoryChangeListener.tasksStarted.incrementAndGet();
|
final long taskStarted = InventoryChangeListener.tasksStarted.incrementAndGet();
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(CoreProtect.getInstance(), () -> {
|
Scheduler.runTaskAsynchronously(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
Material containerType = (enderChest != true ? null : Material.ENDER_CHEST);
|
Material containerType = (enderChest != true ? null : Material.ENDER_CHEST);
|
||||||
InventoryChangeListener.checkTasks(taskStarted);
|
InventoryChangeListener.checkTasks(taskStarted);
|
||||||
|
@ -8,7 +8,6 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -55,6 +54,7 @@ import net.coreprotect.database.lookup.SignMessageLookup;
|
|||||||
import net.coreprotect.language.Phrase;
|
import net.coreprotect.language.Phrase;
|
||||||
import net.coreprotect.model.BlockGroup;
|
import net.coreprotect.model.BlockGroup;
|
||||||
import net.coreprotect.thread.CacheHandler;
|
import net.coreprotect.thread.CacheHandler;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Chat;
|
import net.coreprotect.utility.Chat;
|
||||||
import net.coreprotect.utility.Color;
|
import net.coreprotect.utility.Color;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
@ -735,7 +735,7 @@ public final class PlayerInteractListener extends Queue implements Listener {
|
|||||||
if (!exists) {
|
if (!exists) {
|
||||||
final Player playerFinal = player;
|
final Player playerFinal = player;
|
||||||
final Location locationFinal = crystalLocation;
|
final Location locationFinal = crystalLocation;
|
||||||
Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
|
Scheduler.runTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
boolean blockExists = false;
|
boolean blockExists = false;
|
||||||
int showingBottom = 0;
|
int showingBottom = 0;
|
||||||
@ -755,7 +755,7 @@ public final class PlayerInteractListener extends Queue implements Listener {
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
}, locationFinal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
91
src/main/java/net/coreprotect/thread/Scheduler.java
Normal file
91
src/main/java/net/coreprotect/thread/Scheduler.java
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
package net.coreprotect.thread;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
|
import net.coreprotect.CoreProtect;
|
||||||
|
import net.coreprotect.config.ConfigHandler;
|
||||||
|
|
||||||
|
public class Scheduler {
|
||||||
|
|
||||||
|
private Scheduler() {
|
||||||
|
throw new IllegalStateException("Scheduler class");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void scheduleSyncDelayedTask(CoreProtect plugin, Runnable task, Object regionData, int delay) {
|
||||||
|
if (ConfigHandler.isFolia) {
|
||||||
|
if (regionData instanceof Location) { // REGION
|
||||||
|
Location location = (Location) regionData;
|
||||||
|
if (delay == 0) {
|
||||||
|
Bukkit.getServer().getRegionScheduler().run(plugin, location, value -> task.run());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Bukkit.getServer().getRegionScheduler().runDelayed(plugin, location, value -> task.run(), delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (regionData instanceof Entity) { // ENTITY
|
||||||
|
Entity entity = (Entity) regionData;
|
||||||
|
if (delay == 0) {
|
||||||
|
entity.getScheduler().run(plugin, value -> task.run(), null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
entity.getScheduler().runDelayed(plugin, value -> task.run(), null, delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { // GLOBAL
|
||||||
|
if (delay == 0) {
|
||||||
|
Bukkit.getServer().getGlobalRegionScheduler().run(plugin, value -> task.run());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Bukkit.getServer().getGlobalRegionScheduler().runDelayed(plugin, value -> task.run(), delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { // BUKKIT
|
||||||
|
if (delay == 0) {
|
||||||
|
Bukkit.getServer().getScheduler().runTask(plugin, task);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, task, delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void scheduleAsyncDelayedTask(CoreProtect plugin, Runnable task, int delay) {
|
||||||
|
if (ConfigHandler.isFolia) {
|
||||||
|
if (delay == 0) {
|
||||||
|
Bukkit.getServer().getAsyncScheduler().runNow(plugin, value -> task.run());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Bukkit.getServer().getAsyncScheduler().runDelayed(plugin, value -> task.run(), (delay * 50L), TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { // BUKKIT
|
||||||
|
if (delay == 0) {
|
||||||
|
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, task);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, task, delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void scheduleSyncDelayedTask(CoreProtect plugin, Runnable task, int delay) {
|
||||||
|
scheduleSyncDelayedTask(plugin, task, null, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void runTask(CoreProtect plugin, Runnable task) {
|
||||||
|
scheduleSyncDelayedTask(plugin, task, null, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void runTask(CoreProtect plugin, Runnable task, Object regionData) {
|
||||||
|
scheduleSyncDelayedTask(plugin, task, regionData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void runTaskAsynchronously(CoreProtect plugin, Runnable task) {
|
||||||
|
scheduleAsyncDelayedTask(plugin, task, 0);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package net.coreprotect.utility;
|
package net.coreprotect.utility;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.BlockData;
|
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 org.bukkit.block.data.type.Chest.Type;
|
||||||
|
|
||||||
import net.coreprotect.CoreProtect;
|
import net.coreprotect.CoreProtect;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
|
|
||||||
public class ChestTool {
|
public class ChestTool {
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ public class ChestTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void validateContainer(BlockData blockData, Type newType, Block block, Block relativeBlock) {
|
private static void validateContainer(BlockData blockData, Type newType, Block block, Block relativeBlock) {
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
Scheduler.scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
BlockData relativeBlockData = relativeBlock.getBlockData();
|
BlockData relativeBlockData = relativeBlock.getBlockData();
|
||||||
if (!blockData.getAsString().equals(block.getBlockData().getAsString()) || !(relativeBlockData instanceof Chest) || ((Chest) relativeBlockData).getType() == newType) {
|
if (!blockData.getAsString().equals(block.getBlockData().getAsString()) || !(relativeBlockData instanceof Chest) || ((Chest) relativeBlockData).getType() == newType) {
|
||||||
@ -89,7 +89,7 @@ public class ChestTool {
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}, 2);
|
}, relativeBlock.getLocation(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,7 @@ import net.coreprotect.database.Rollback;
|
|||||||
import net.coreprotect.language.Phrase;
|
import net.coreprotect.language.Phrase;
|
||||||
import net.coreprotect.model.BlockGroup;
|
import net.coreprotect.model.BlockGroup;
|
||||||
import net.coreprotect.thread.CacheHandler;
|
import net.coreprotect.thread.CacheHandler;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.serialize.ItemMetaHandler;
|
import net.coreprotect.utility.serialize.ItemMetaHandler;
|
||||||
import net.coreprotect.worldedit.CoreProtectEditSessionEvent;
|
import net.coreprotect.worldedit.CoreProtectEditSessionEvent;
|
||||||
|
|
||||||
@ -1281,6 +1282,17 @@ public class Util extends Queue {
|
|||||||
return true;
|
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() {
|
public static String getBranch() {
|
||||||
String branch = "";
|
String branch = "";
|
||||||
try {
|
try {
|
||||||
@ -1521,7 +1533,7 @@ public class Util extends Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void updateBlock(final BlockState block) {
|
public static void updateBlock(final BlockState block) {
|
||||||
Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
|
Scheduler.runTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
if (block.getBlockData() instanceof Waterlogged) {
|
if (block.getBlockData() instanceof Waterlogged) {
|
||||||
Block currentBlock = block.getBlock();
|
Block currentBlock = block.getBlock();
|
||||||
@ -1534,7 +1546,7 @@ public class Util extends Queue {
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
}, block.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateInventory(Player player) {
|
public static void updateInventory(Player player) {
|
||||||
|
@ -59,6 +59,7 @@ import net.coreprotect.CoreProtect;
|
|||||||
import net.coreprotect.bukkit.BukkitAdapter;
|
import net.coreprotect.bukkit.BukkitAdapter;
|
||||||
import net.coreprotect.database.Rollback;
|
import net.coreprotect.database.Rollback;
|
||||||
import net.coreprotect.thread.CacheHandler;
|
import net.coreprotect.thread.CacheHandler;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
|
|
||||||
public class EntityUtil {
|
public class EntityUtil {
|
||||||
@ -71,7 +72,7 @@ public class EntityUtil {
|
|||||||
if (type == null) {
|
if (type == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
|
Scheduler.runTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
Location location = block.getLocation();
|
Location location = block.getLocation();
|
||||||
location.setX(location.getX() + 0.50);
|
location.setX(location.getX() + 0.50);
|
||||||
@ -557,7 +558,7 @@ public class EntityUtil {
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
}, block.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import net.coreprotect.config.Config;
|
|||||||
import net.coreprotect.config.ConfigHandler;
|
import net.coreprotect.config.ConfigHandler;
|
||||||
import net.coreprotect.language.Phrase;
|
import net.coreprotect.language.Phrase;
|
||||||
import net.coreprotect.language.Selector;
|
import net.coreprotect.language.Selector;
|
||||||
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Chat;
|
import net.coreprotect.utility.Chat;
|
||||||
|
|
||||||
public class CoreProtectEditSessionEvent {
|
public class CoreProtectEditSessionEvent {
|
||||||
@ -47,7 +48,7 @@ public class CoreProtectEditSessionEvent {
|
|||||||
// Failed to initialize WorldEdit logging
|
// Failed to initialize WorldEdit logging
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
|
Scheduler.runTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
if (isInitialized()) {
|
if (isInitialized()) {
|
||||||
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.FIRST));
|
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.FIRST));
|
||||||
|
@ -3,6 +3,7 @@ main: net.coreprotect.CoreProtect
|
|||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
branch: ${project.branch}
|
branch: ${project.branch}
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
|
folia-supported: true
|
||||||
website: http://coreprotect.net
|
website: http://coreprotect.net
|
||||||
author: Intelli
|
author: Intelli
|
||||||
softdepend: [WorldEdit]
|
softdepend: [WorldEdit]
|
||||||
|
Loading…
Reference in New Issue
Block a user