mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-09-28 22:57:29 +02:00
Updated FoliaLib dependency. Added new Folia task methods to SchedulerReport.java. Re-added Bukkit task reports in SchedulerReport.java.
This commit is contained in:
parent
6edbb60e00
commit
13682383c8
@ -30,7 +30,7 @@
|
|||||||
}
|
}
|
||||||
"api"("com.sk89q.worldedit:worldedit-bukkit:${Versions.WORLDEDIT}") { isTransitive = false }
|
"api"("com.sk89q.worldedit:worldedit-bukkit:${Versions.WORLDEDIT}") { isTransitive = false }
|
||||||
"implementation"("com.google.guava:guava:${Versions.GUAVA}")
|
"implementation"("com.google.guava:guava:${Versions.GUAVA}")
|
||||||
"implementation"("com.tcoded:FoliaLib:0.3.1")
|
"implementation"("com.tcoded:FoliaLib:0.3.2")
|
||||||
"compileOnly"("com.sk89q:commandbook:2.3") { isTransitive = false }
|
"compileOnly"("com.sk89q:commandbook:2.3") { isTransitive = false }
|
||||||
"shadeOnly"("io.papermc:paperlib:1.0.8")
|
"shadeOnly"("io.papermc:paperlib:1.0.8")
|
||||||
"shadeOnly"("org.bstats:bstats-bukkit:3.0.1")
|
"shadeOnly"("org.bstats:bstats-bukkit:3.0.1")
|
||||||
|
@ -25,9 +25,8 @@
|
|||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.sk89q.worldedit.util.report.DataReport;
|
import com.sk89q.worldedit.util.report.DataReport;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import com.tcoded.folialib.FoliaLib;
|
||||||
import com.tcoded.folialib.wrapper.task.WrappedTask;
|
import com.tcoded.folialib.wrapper.task.WrappedTask;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -37,6 +36,8 @@
|
|||||||
|
|
||||||
public class SchedulerReport extends DataReport {
|
public class SchedulerReport extends DataReport {
|
||||||
|
|
||||||
|
private FoliaLib foliaLib = WorldGuardPlugin.inst().getFoliaLib();
|
||||||
|
|
||||||
private LoadingCache<Class<?>, Optional<Field>> taskFieldCache = CacheBuilder.newBuilder()
|
private LoadingCache<Class<?>, Optional<Field>> taskFieldCache = CacheBuilder.newBuilder()
|
||||||
.build(new CacheLoader<Class<?>, Optional<Field>>() {
|
.build(new CacheLoader<Class<?>, Optional<Field>>() {
|
||||||
@Override
|
@Override
|
||||||
@ -51,30 +52,78 @@ public Optional<Field> load(Class<?> clazz) throws Exception {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
private LoadingCache<Class<?>, Optional<Field>> foliaTaskFieldCache = CacheBuilder.newBuilder()
|
||||||
|
.build(new CacheLoader<Class<?>, Optional<Field>>() {
|
||||||
|
@Override
|
||||||
|
public Optional<Field> load(Class<?> clazz) throws Exception {
|
||||||
|
try {
|
||||||
|
Field field = clazz.getDeclaredField("run");
|
||||||
|
field.setAccessible(true);
|
||||||
|
return Optional.ofNullable(field);
|
||||||
|
} catch (NoSuchFieldException ignored) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
public SchedulerReport() {
|
public SchedulerReport() {
|
||||||
super("Scheduler");
|
super("Scheduler");
|
||||||
|
|
||||||
append("Error", "FOLIA VERSION - PLEASE REPORT TO WORLDGUARD");
|
List<WrappedTask> tasks = foliaLib.getImpl().getAllTasks();
|
||||||
|
|
||||||
// List<BukkitTask> tasks = Bukkit.getServer().getScheduler().getPendingTasks();
|
append("Pending Task Count", tasks.size());
|
||||||
//// WorldGuardPlugin.inst().foliaLib.getImpl().
|
|
||||||
//
|
for (WrappedTask task : tasks) {
|
||||||
// append("Pending Task Count", tasks.size());
|
Object handle = getTaskHandle(task);
|
||||||
//
|
Class<?> taskClass;
|
||||||
// for (BukkitTask task : tasks) {
|
if (foliaLib.isFolia()) {
|
||||||
// Class<?> taskClass = getTaskClass(task);
|
taskClass = getFoliaTaskClass(handle);
|
||||||
//
|
} else {
|
||||||
// DataReport report = new DataReport("Task: #" + task.getTaskId());
|
taskClass = getBukkitTaskClass(handle);
|
||||||
// report.append("Owner", task.getOwner().getName());
|
}
|
||||||
// report.append("Runnable", taskClass != null ? taskClass.getName() : "<Unknown>");
|
|
||||||
// report.append("Synchronous?", task.isSync());
|
DataReport report = new DataReport("Task: #" + handle.hashCode());
|
||||||
// append(report.getTitle(), report);
|
report.append("Owner", task.getOwningPlugin().getName());
|
||||||
// }
|
report.append("Runnable", taskClass != null ? taskClass.getName() : "<Unknown>");
|
||||||
|
report.append("Synchronous?", !task.isAsync());
|
||||||
|
append(report.getTitle(), report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getTaskHandle(WrappedTask task) {
|
||||||
|
try {
|
||||||
|
Field field = task.getClass().getDeclaredField("task");
|
||||||
|
field.setAccessible(true);
|
||||||
|
return field.get(task);
|
||||||
|
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Nullable
|
@Nullable
|
||||||
private Class<?> getTaskClass(BukkitTask task) {
|
private Class<?> getFoliaTaskClass(Object task) {
|
||||||
|
try {
|
||||||
|
Class<?> clazz = task.getClass();
|
||||||
|
Set<Class<?>> classes = (Set) TypeToken.of(clazz).getTypes().rawTypes();
|
||||||
|
|
||||||
|
for (Class<?> type : classes) {
|
||||||
|
Optional<Field> field = foliaTaskFieldCache.getUnchecked(type);
|
||||||
|
if (field.isPresent()) {
|
||||||
|
Object res = field.get().get(task);
|
||||||
|
return res == null ? null : res.getClass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException | NoClassDefFoundError ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Nullable
|
||||||
|
private Class<?> getBukkitTaskClass(Object task) {
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = task.getClass();
|
Class<?> clazz = task.getClass();
|
||||||
Set<Class<?>> classes = (Set) TypeToken.of(clazz).getTypes().rawTypes();
|
Set<Class<?>> classes = (Set) TypeToken.of(clazz).getTypes().rawTypes();
|
||||||
|
Loading…
Reference in New Issue
Block a user