Merge 17a0d9dc1d
into aa254c80e0
This commit is contained in:
commit
8e7a34c8f8
|
@ -37,6 +37,14 @@ Please read CONTRIBUTING.md for important guidelines to follow.
|
|||
|
||||
Submissions must be licensed under the GNU Lesser General Public License v3.
|
||||
|
||||
# Folia Inquisitors
|
||||
This Folia support is maintained by the following organizations and people:
|
||||
|
||||
[<img src="https://github.com/Folia-Inquisitors.png" width=80 alt="Folia-Inquisitors">](https://github.com/orgs/Folia-Inquisitors/repositories)
|
||||
[<img src="https://github.com/TechnicallyCoded.png" width=80 alt="TechnicallyCoded">](https://github.com/TechnicallyCoded)
|
||||
[<img src="https://github.com/Yomamaeatstoes.png" width=80 alt="Yomamaeatstoes">](https://github.com/Yomamaeatstoes)
|
||||
[<img src="https://github.com/Loving11ish.png" width=80 alt="Loving11ish">](https://github.com/Loving11ish)
|
||||
|
||||
Links
|
||||
-----
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
<allow pkg="junit.framework"/>
|
||||
<allow pkg="com.sk89q"/>
|
||||
<allow pkg="com.google.common"/>
|
||||
<allow pkg="com.tcoded.folialib"/>
|
||||
|
||||
<subpackage name="worldguard">
|
||||
<allow pkg="org.khelekore"/>
|
||||
|
|
|
@ -31,6 +31,7 @@ dependencies {
|
|||
}
|
||||
"api"("com.sk89q.worldedit:worldedit-bukkit:${Versions.WORLDEDIT}") { isTransitive = false }
|
||||
"implementation"("com.google.guava:guava:${Versions.GUAVA}")
|
||||
"implementation"("com.tcoded:FoliaLib:0.3.2")
|
||||
"compileOnly"("com.sk89q:commandbook:2.3") { isTransitive = false }
|
||||
"shadeOnly"("io.papermc:paperlib:1.0.8")
|
||||
"shadeOnly"("org.bstats:bstats-bukkit:3.0.1")
|
||||
|
@ -66,6 +67,9 @@ tasks.named<ShadowJar>("shadowJar") {
|
|||
relocate ("co.aikar.timings.lib", "com.sk89q.worldguard.bukkit.timingslib") {
|
||||
include(dependency("co.aikar:minecraft-timings"))
|
||||
}
|
||||
relocate ("com.tcoded.folialib", "com.sk89q.worldguard.bukkit.folialib") {
|
||||
include(dependency("com.tcoded:FoliaLib"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.bukkit.event.world.WorldUnloadEvent;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -94,7 +95,10 @@ public class BukkitRegionContainer extends RegionContainer {
|
|||
}
|
||||
}, plugin);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, cache::invalidateAll, CACHE_INVALIDATION_INTERVAL, CACHE_INVALIDATION_INTERVAL);
|
||||
int interval = CACHE_INVALIDATION_INTERVAL * 50;
|
||||
plugin.getFoliaLib().getImpl().runTimerAsync(cache::invalidateAll, interval, interval, TimeUnit.MILLISECONDS);
|
||||
|
||||
// Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, cache::invalidateAll, CACHE_INVALIDATION_INTERVAL, CACHE_INVALIDATION_INTERVAL);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
|
|
|
@ -75,6 +75,7 @@ import com.sk89q.worldguard.protection.managers.storage.file.DirectoryYamlDriver
|
|||
import com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.util.logging.RecordMessagePrefixer;
|
||||
import com.tcoded.folialib.FoliaLib;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.DrilldownPie;
|
||||
import org.bstats.charts.SimplePie;
|
||||
|
@ -96,6 +97,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -111,6 +113,9 @@ public class WorldGuardPlugin extends JavaPlugin {
|
|||
|
||||
private static final int BSTATS_PLUGIN_ID = 3283;
|
||||
|
||||
|
||||
private FoliaLib foliaLib;
|
||||
|
||||
/**
|
||||
* Construct objects. Actual loading occurs when the plugin is enabled, so
|
||||
* this merely instantiates the objects.
|
||||
|
@ -138,6 +143,10 @@ public class WorldGuardPlugin extends JavaPlugin {
|
|||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
// FoliaLib Util
|
||||
foliaLib = new FoliaLib(this);
|
||||
|
||||
// Catch bad things being done by naughty plugins that include WorldGuard's classes
|
||||
ClassSourceValidator verifier = new ClassSourceValidator(this);
|
||||
verifier.reportMismatches(ImmutableList.of(WorldGuard.class, ProtectedRegion.class, Flag.class));
|
||||
|
@ -164,7 +173,9 @@ public class WorldGuardPlugin extends JavaPlugin {
|
|||
reg.register(GeneralCommands.class);
|
||||
}
|
||||
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, sessionManager, BukkitSessionManager.RUN_DELAY, BukkitSessionManager.RUN_DELAY);
|
||||
int runDelayMs = BukkitSessionManager.RUN_DELAY * 50;
|
||||
foliaLib.getImpl().runTimerAsync(sessionManager, runDelayMs, runDelayMs, TimeUnit.MILLISECONDS);
|
||||
// getServer().getScheduler().scheduleSyncRepeatingTask(this, sessionManager, BukkitSessionManager.RUN_DELAY, BukkitSessionManager.RUN_DELAY);
|
||||
|
||||
// Register events
|
||||
getServer().getPluginManager().registerEvents(sessionManager, this);
|
||||
|
@ -205,12 +216,28 @@ public class WorldGuardPlugin extends JavaPlugin {
|
|||
}
|
||||
worldListener.registerEvents();
|
||||
|
||||
Bukkit.getScheduler().runTask(this, () -> {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
foliaLib.getImpl().runAtEntity(player, (task) -> {
|
||||
ProcessPlayerEvent event = new ProcessPlayerEvent(player);
|
||||
Events.fire(event);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// if (foliaLib.isFolia()) {
|
||||
// for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
// foliaLib.getImpl().runAtEntity(player, (task) -> {
|
||||
// ProcessPlayerEvent event = new ProcessPlayerEvent(player);
|
||||
// Events.fire(event);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// Bukkit.getScheduler().runTask(this, () -> {
|
||||
// for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
// ProcessPlayerEvent event = new ProcessPlayerEvent(player);
|
||||
// Events.fire(event);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).setInitialized(true);
|
||||
((SimpleDomainRegistry) WorldGuard.getInstance().getDomainRegistry()).setInitialized(true);
|
||||
|
@ -266,7 +293,10 @@ public class WorldGuardPlugin extends JavaPlugin {
|
|||
@Override
|
||||
public void onDisable() {
|
||||
WorldGuard.getInstance().disable();
|
||||
this.getServer().getScheduler().cancelTasks(this);
|
||||
if (!foliaLib.isFolia()) {
|
||||
this.getServer().getScheduler().cancelTasks(this);
|
||||
}
|
||||
foliaLib.getImpl().cancelAllTasks();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -526,4 +556,7 @@ public class WorldGuardPlugin extends JavaPlugin {
|
|||
return playerMoveListener;
|
||||
}
|
||||
|
||||
public FoliaLib getFoliaLib() {
|
||||
return foliaLib;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,6 +152,7 @@ import org.bukkit.util.Vector;
|
|||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EventAbstractionListener extends AbstractListener {
|
||||
|
@ -990,8 +991,16 @@ public class EventAbstractionListener extends AbstractListener {
|
|||
handleInventoryHolderUse(event, cause, targetHolder);
|
||||
|
||||
if (event.isCancelled() && causeHolder instanceof Hopper && wcfg.breakDeniedHoppers) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(),
|
||||
() -> ((Hopper) causeHolder).getBlock().breakNaturally());
|
||||
Hopper hopperCauseHolder = (Hopper) causeHolder;
|
||||
Location location = hopperCauseHolder.getLocation();
|
||||
|
||||
getPlugin().getFoliaLib().getImpl().runAtLocationLater(location, () -> {
|
||||
Block block = location.getBlock();
|
||||
if (block.getType() == Material.HOPPER) {
|
||||
block.breakNaturally();
|
||||
}
|
||||
}, 50, TimeUnit.MILLISECONDS);
|
||||
|
||||
} else {
|
||||
entry.setCancelled(event.isCancelled());
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
|||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.spigotmc.event.entity.EntityMountEvent;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PlayerMoveListener extends AbstractListener {
|
||||
|
||||
|
@ -127,7 +129,10 @@ public class PlayerMoveListener extends AbstractListener {
|
|||
|
||||
player.teleport(override.clone().add(0, 1, 0));
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(getPlugin(), () -> player.teleport(override.clone().add(0, 1, 0)), 1);
|
||||
getPlugin().getFoliaLib().getImpl().runAtEntityLater(player, () -> {
|
||||
player.teleport(override.clone().add(0, 1, 0));
|
||||
}, 50, TimeUnit.MILLISECONDS);
|
||||
// Bukkit.getScheduler().runTaskLater(getPlugin(), () -> player.teleport(override.clone().add(0, 1, 0)), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ import com.sk89q.worldguard.bukkit.event.player.ProcessPlayerEvent;
|
|||
import com.sk89q.worldguard.bukkit.util.Entities;
|
||||
import com.sk89q.worldguard.session.AbstractSessionManager;
|
||||
import com.sk89q.worldguard.session.Session;
|
||||
import com.tcoded.folialib.FoliaLib;
|
||||
import com.tcoded.folialib.impl.ServerImplementation;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -68,7 +70,13 @@ public class BukkitSessionManager extends AbstractSessionManager implements Runn
|
|||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
get(localPlayer).tick(localPlayer);
|
||||
Session session = get(localPlayer);
|
||||
|
||||
FoliaLib foliaLib = WorldGuardPlugin.inst().getFoliaLib();
|
||||
ServerImplementation impl = foliaLib.getImpl();
|
||||
|
||||
if (foliaLib.isFolia()) impl.runAtEntity(player, (task) -> session.tick(localPlayer));
|
||||
else session.tick(localPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,9 @@ import com.google.common.cache.CacheBuilder;
|
|||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.sk89q.worldedit.util.report.DataReport;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.tcoded.folialib.FoliaLib;
|
||||
import com.tcoded.folialib.wrapper.task.WrappedTask;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
|
@ -35,6 +36,8 @@ import java.util.Set;
|
|||
|
||||
public class SchedulerReport extends DataReport {
|
||||
|
||||
private FoliaLib foliaLib = WorldGuardPlugin.inst().getFoliaLib();
|
||||
|
||||
private LoadingCache<Class<?>, Optional<Field>> taskFieldCache = CacheBuilder.newBuilder()
|
||||
.build(new CacheLoader<Class<?>, Optional<Field>>() {
|
||||
@Override
|
||||
|
@ -49,27 +52,78 @@ public class SchedulerReport extends DataReport {
|
|||
}
|
||||
});
|
||||
|
||||
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() {
|
||||
super("Scheduler");
|
||||
|
||||
List<BukkitTask> tasks = Bukkit.getServer().getScheduler().getPendingTasks();
|
||||
List<WrappedTask> tasks = foliaLib.getImpl().getAllTasks();
|
||||
|
||||
append("Pending Task Count", tasks.size());
|
||||
|
||||
for (BukkitTask task : tasks) {
|
||||
Class<?> taskClass = getTaskClass(task);
|
||||
for (WrappedTask task : tasks) {
|
||||
Object handle = getTaskHandle(task);
|
||||
Class<?> taskClass;
|
||||
if (foliaLib.isFolia()) {
|
||||
taskClass = getFoliaTaskClass(handle);
|
||||
} else {
|
||||
taskClass = getBukkitTaskClass(handle);
|
||||
}
|
||||
|
||||
DataReport report = new DataReport("Task: #" + task.getTaskId());
|
||||
report.append("Owner", task.getOwner().getName());
|
||||
DataReport report = new DataReport("Task: #" + handle.hashCode());
|
||||
report.append("Owner", task.getOwningPlugin().getName());
|
||||
report.append("Runnable", taskClass != null ? taskClass.getName() : "<Unknown>");
|
||||
report.append("Synchronous?", task.isSync());
|
||||
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")
|
||||
@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 {
|
||||
Class<?> clazz = task.getClass();
|
||||
Set<Class<?>> classes = (Set) TypeToken.of(clazz).getTypes().rawTypes();
|
||||
|
|
|
@ -4,3 +4,4 @@ version: "${internalVersion}"
|
|||
depend: [WorldEdit]
|
||||
softdepend: [CommandBook]
|
||||
api-version: "1.20"
|
||||
folia-supported: true
|
||||
|
|
Loading…
Reference in New Issue