mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 03:25:29 +01:00
Folia support
This commit is contained in:
parent
ac6f911f15
commit
ff0f1be20e
@ -22,6 +22,10 @@ repositories {
|
||||
url 'https://hub.spigotmc.org/nexus/content/groups/public/'
|
||||
}
|
||||
|
||||
maven {
|
||||
url 'https://repo.papermc.io/repository/maven-public/'
|
||||
}
|
||||
|
||||
maven {
|
||||
url 'https://libraries.minecraft.net/'
|
||||
metadataSources {
|
||||
@ -34,6 +38,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'net.bytebuddy:byte-buddy:1.14.3'
|
||||
compileOnly 'dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT'
|
||||
compileOnly 'io.netty:netty-all:4.0.23.Final'
|
||||
@ -51,7 +56,7 @@ dependencies {
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
|
@ -490,9 +490,25 @@ public class ProtocolLib extends JavaPlugin {
|
||||
}
|
||||
|
||||
// Attempt to create task
|
||||
this.packetTask = server.getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
||||
AsyncFilterManager manager = (AsyncFilterManager) protocolManager.getAsynchronousManager();
|
||||
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
this.packetTask = 1;
|
||||
server.getGlobalRegionScheduler().runAtFixedRate(this, task -> packetTaskRegistrator(), ASYNC_MANAGER_DELAY, ASYNC_MANAGER_DELAY);
|
||||
} catch (ClassNotFoundException e) {
|
||||
this.packetTask = server.getScheduler().scheduleSyncRepeatingTask(this, this::packetTaskRegistrator, ASYNC_MANAGER_DELAY, ASYNC_MANAGER_DELAY);
|
||||
}
|
||||
} catch (OutOfMemoryError e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
if (this.packetTask == -1) {
|
||||
reporter.reportDetailed(this, Report.newBuilder(REPORT_CANNOT_CREATE_TIMEOUT_TASK).error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void packetTaskRegistrator() {
|
||||
AsyncFilterManager manager = (AsyncFilterManager) protocolManager.getAsynchronousManager();
|
||||
// We KNOW we're on the main thread at the moment
|
||||
manager.sendProcessedPackets(ProtocolLib.this.tickCounter++, true);
|
||||
|
||||
@ -503,14 +519,6 @@ public class ProtocolLib extends JavaPlugin {
|
||||
if (!ProtocolLibrary.updatesDisabled() && (ProtocolLib.this.tickCounter % 20) == 0) {
|
||||
ProtocolLib.this.checkUpdates();
|
||||
}
|
||||
}, ASYNC_MANAGER_DELAY, ASYNC_MANAGER_DELAY);
|
||||
} catch (OutOfMemoryError e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
if (this.packetTask == -1) {
|
||||
reporter.reportDetailed(this, Report.newBuilder(REPORT_CANNOT_CREATE_TIMEOUT_TASK).error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfiguration() {
|
||||
@ -567,7 +575,12 @@ public class ProtocolLib extends JavaPlugin {
|
||||
|
||||
// Clean up
|
||||
if (this.packetTask >= 0) {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
this.getServer().getGlobalRegionScheduler().cancelTasks(this);
|
||||
} catch (ClassNotFoundException e) {
|
||||
this.getServer().getScheduler().cancelTask(this.packetTask);
|
||||
}
|
||||
this.packetTask = -1;
|
||||
}
|
||||
|
||||
|
@ -32,10 +32,10 @@ import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.utility.ByteBuddyFactory;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.profile.PlayerProfile;
|
||||
|
||||
import net.bytebuddy.description.ByteCodeElement;
|
||||
import net.bytebuddy.description.modifier.Visibility;
|
||||
@ -51,6 +51,7 @@ import net.bytebuddy.implementation.bind.annotation.FieldValue;
|
||||
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a player object that can be serialized by Java.
|
||||
@ -76,6 +77,8 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
|
||||
private boolean playedBefore;
|
||||
private boolean online;
|
||||
private boolean whitelisted;
|
||||
long lastLogin;
|
||||
long lastSeen;
|
||||
|
||||
private static final Constructor<?> proxyPlayerConstructor = setupProxyPlayerConstructor();
|
||||
|
||||
@ -88,6 +91,7 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
|
||||
|
||||
/**
|
||||
* Initialize this serializable offline player from another player.
|
||||
*
|
||||
* @param offline - another player.
|
||||
*/
|
||||
public SerializedOfflinePlayer(OfflinePlayer offline) {
|
||||
@ -100,6 +104,11 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
|
||||
this.playedBefore = offline.hasPlayedBefore();
|
||||
this.online = offline.isOnline();
|
||||
this.whitelisted = offline.isWhitelisted();
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
this.lastSeen = offline.getLastSeen();
|
||||
this.lastLogin = offline.getLastLogin();
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -122,49 +131,74 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
|
||||
return bedSpawnLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastLogin() {
|
||||
return lastLogin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastSeen() {
|
||||
return lastSeen;
|
||||
}
|
||||
|
||||
// TODO do we need to implement this?
|
||||
|
||||
public void incrementStatistic(Statistic statistic) throws IllegalArgumentException { }
|
||||
public void incrementStatistic(Statistic statistic) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public void decrementStatistic(Statistic statistic) throws IllegalArgumentException { }
|
||||
public void decrementStatistic(Statistic statistic) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public void incrementStatistic(Statistic statistic, int i) throws IllegalArgumentException { }
|
||||
public void incrementStatistic(Statistic statistic, int i) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public void decrementStatistic(Statistic statistic, int i) throws IllegalArgumentException { }
|
||||
public void decrementStatistic(Statistic statistic, int i) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public void setStatistic(Statistic statistic, int i) throws IllegalArgumentException { }
|
||||
public void setStatistic(Statistic statistic, int i) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public int getStatistic(Statistic statistic) throws IllegalArgumentException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void incrementStatistic(Statistic statistic, Material material) throws IllegalArgumentException { }
|
||||
public void incrementStatistic(Statistic statistic, Material material) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public void decrementStatistic(Statistic statistic, Material material) throws IllegalArgumentException { }
|
||||
public void decrementStatistic(Statistic statistic, Material material) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public int getStatistic(Statistic statistic, Material material) throws IllegalArgumentException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void incrementStatistic(Statistic statistic, Material material, int i) throws IllegalArgumentException { }
|
||||
public void incrementStatistic(Statistic statistic, Material material, int i) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public void decrementStatistic(Statistic statistic, Material material, int i) throws IllegalArgumentException { }
|
||||
public void decrementStatistic(Statistic statistic, Material material, int i) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public void setStatistic(Statistic statistic, Material material, int i) throws IllegalArgumentException { }
|
||||
public void setStatistic(Statistic statistic, Material material, int i) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public void incrementStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException { }
|
||||
public void incrementStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public void decrementStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException { }
|
||||
public void decrementStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public int getStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void incrementStatistic(Statistic statistic, EntityType entityType, int i) throws IllegalArgumentException { }
|
||||
public void incrementStatistic(Statistic statistic, EntityType entityType, int i) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public void decrementStatistic(Statistic statistic, EntityType entityType, int i) { }
|
||||
public void decrementStatistic(Statistic statistic, EntityType entityType, int i) {
|
||||
}
|
||||
|
||||
public void setStatistic(Statistic statistic, EntityType entityType, int i) { }
|
||||
public void setStatistic(Statistic statistic, EntityType entityType, int i) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLastDeathLocation() {
|
||||
@ -187,7 +221,7 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerProfile getPlayerProfile() {
|
||||
public @NotNull PlayerProfile getPlayerProfile() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -271,6 +305,7 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
|
||||
* Retrieve a player object that implements OfflinePlayer by referring to this object.
|
||||
* <p>
|
||||
* All other methods cause an exception.
|
||||
*
|
||||
* @return Proxy object.
|
||||
*/
|
||||
public Player getProxyPlayer() {
|
||||
@ -285,8 +320,7 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
private static Constructor<? extends Player> setupProxyPlayerConstructor()
|
||||
{
|
||||
private static Constructor<? extends Player> setupProxyPlayerConstructor() {
|
||||
final Method[] offlinePlayerMethods = OfflinePlayer.class.getMethods();
|
||||
final String[] methodNames = new String[offlinePlayerMethods.length];
|
||||
for (int idx = 0; idx < offlinePlayerMethods.length; ++idx)
|
||||
@ -354,7 +388,6 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
|
||||
* This interface extends both OfflinePlayer and Player (in that order) so that the class generated by ByteBuddy
|
||||
* looks at OfflinePlayer's methods first while still being a Player.
|
||||
*/
|
||||
private interface PlayerUnion extends OfflinePlayer, Player
|
||||
{
|
||||
private interface PlayerUnion extends OfflinePlayer, Player {
|
||||
}
|
||||
}
|
||||
|
@ -80,11 +80,16 @@ public final class SpigotUpdater extends Updater {
|
||||
} finally {
|
||||
// Invoke the listeners on the main thread
|
||||
for (Runnable listener : listeners) {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
plugin.getServer().getGlobalRegionScheduler().execute(plugin, listener);
|
||||
} catch (ClassNotFoundException e) {
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String RESOURCE_URL = "https://www.spigotmc.org/resources/protocollib.1997/";
|
||||
private static final String UPDATE_URL = "https://api.spigotmc.org/legacy/update.php?resource=1997";
|
||||
|
@ -8,6 +8,8 @@ load: STARTUP
|
||||
database: false
|
||||
api-version: "1.13"
|
||||
|
||||
folia-supported: true
|
||||
|
||||
commands:
|
||||
protocol:
|
||||
description: Performs administrative tasks regarding ProtocolLib.
|
||||
|
@ -17,6 +17,8 @@ public class SerializedOfflinePlayerTest {
|
||||
|
||||
private static final String name = "playerName";
|
||||
private static final long firstPlayed = 1000L;
|
||||
private static final long lastLogin = 1000L;
|
||||
private static final long lastSeen = 1000L;
|
||||
private static final long lastPlayed = firstPlayed + 100L;
|
||||
private static final boolean isOp = false;
|
||||
private static final boolean playedBefore = true;
|
||||
|
Loading…
Reference in New Issue
Block a user