Replace BukkitRunnable with UniversalRunnable (#2460)
This commit is contained in:
parent
12d814182d
commit
81b16448f8
Binary file not shown.
|
@ -1,6 +1,7 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
@ -85,9 +85,6 @@ done
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
@ -133,10 +130,13 @@ location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
|
@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
# Collect all arguments for the java command;
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
# shell script including quotes and variable substitutions, so put them in
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.function.Consumer;
|
||||||
import com.comphenix.protocol.PacketTypeLookup.ClassLookup;
|
import com.comphenix.protocol.PacketTypeLookup.ClassLookup;
|
||||||
import com.comphenix.protocol.events.ConnectionSide;
|
import com.comphenix.protocol.events.ConnectionSide;
|
||||||
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
||||||
|
import com.comphenix.protocol.scheduler.UniversalRunnable;
|
||||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
@ -19,8 +20,6 @@ import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang.WordUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the type of a packet in a specific protocol.
|
* Represents the type of a packet in a specific protocol.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -1022,7 +1021,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||||
* @param name - the name of the packet.
|
* @param name - the name of the packet.
|
||||||
*/
|
*/
|
||||||
public static void scheduleRegister(final PacketType type, final String name) {
|
public static void scheduleRegister(final PacketType type, final String name) {
|
||||||
BukkitRunnable runnable = new BukkitRunnable() {
|
UniversalRunnable runnable = new UniversalRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PacketTypeEnum objEnum;
|
PacketTypeEnum objEnum;
|
||||||
|
|
|
@ -37,12 +37,12 @@ public class ProtocolLibrary {
|
||||||
/**
|
/**
|
||||||
* The maximum version ProtocolLib has been tested with.
|
* The maximum version ProtocolLib has been tested with.
|
||||||
*/
|
*/
|
||||||
public static final String MAXIMUM_MINECRAFT_VERSION = MinecraftVersion.LATEST.getVersion();
|
public static final String MAXIMUM_MINECRAFT_VERSION = "1.20.1";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.19.2) was released.
|
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.20.1) was released.
|
||||||
*/
|
*/
|
||||||
public static final String MINECRAFT_LAST_RELEASE_DATE = "2022-08-05";
|
public static final String MINECRAFT_LAST_RELEASE_DATE = "2023-06-12";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugins that are currently incompatible with ProtocolLib.
|
* Plugins that are currently incompatible with ProtocolLib.
|
||||||
|
|
|
@ -166,9 +166,8 @@ public class PacketFilterManager implements ListenerInvoker, InternalManager {
|
||||||
// ensure we are on the main thread if any listener requires that
|
// ensure we are on the main thread if any listener requires that
|
||||||
if (this.playerInjectionHandler.hasMainThreadListener(packet.getType()) && !this.server.isPrimaryThread()) {
|
if (this.playerInjectionHandler.hasMainThreadListener(packet.getType()) && !this.server.isPrimaryThread()) {
|
||||||
NetworkMarker copy = marker; // okay fine
|
NetworkMarker copy = marker; // okay fine
|
||||||
this.server.getScheduler().scheduleSyncDelayedTask(
|
ProtocolLibrary.getScheduler().scheduleSyncDelayedTask(
|
||||||
this.plugin,
|
() -> this.sendServerPacket(receiver, packet, copy, false), 1L);
|
||||||
() -> this.sendServerPacket(receiver, packet, copy, false));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,8 +217,7 @@ public class PacketFilterManager implements ListenerInvoker, InternalManager {
|
||||||
if (!this.closed) {
|
if (!this.closed) {
|
||||||
// make sure we are on the main thread if any listener of the packet needs it
|
// make sure we are on the main thread if any listener of the packet needs it
|
||||||
if (this.playerInjectionHandler.hasMainThreadListener(packet.getType()) && !this.server.isPrimaryThread()) {
|
if (this.playerInjectionHandler.hasMainThreadListener(packet.getType()) && !this.server.isPrimaryThread()) {
|
||||||
this.server.getScheduler().scheduleSyncDelayedTask(
|
ProtocolLibrary.getScheduler().runTask(
|
||||||
this.plugin,
|
|
||||||
() -> this.receiveClientPacket(sender, packet, marker, filters));
|
() -> this.receiveClientPacket(sender, packet, marker, filters));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.PacketType.Protocol;
|
import com.comphenix.protocol.PacketType.Protocol;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.error.ErrorReporter;
|
import com.comphenix.protocol.error.ErrorReporter;
|
||||||
import com.comphenix.protocol.error.Report;
|
import com.comphenix.protocol.error.Report;
|
||||||
import com.comphenix.protocol.error.ReportType;
|
import com.comphenix.protocol.error.ReportType;
|
||||||
|
@ -490,8 +491,7 @@ public class NettyChannelInjector implements Injector {
|
||||||
void processInboundPacket(ChannelHandlerContext ctx, Object packet, Class<?> packetClass) {
|
void processInboundPacket(ChannelHandlerContext ctx, Object packet, Class<?> packetClass) {
|
||||||
if (this.channelListener.hasMainThreadListener(packetClass) && !this.server.isPrimaryThread()) {
|
if (this.channelListener.hasMainThreadListener(packetClass) && !this.server.isPrimaryThread()) {
|
||||||
// not on the main thread but we are required to be - re-schedule the packet on the main thread
|
// not on the main thread but we are required to be - re-schedule the packet on the main thread
|
||||||
this.server.getScheduler().runTask(
|
ProtocolLibrary.getScheduler().runTask(
|
||||||
this.injectionFactory.getPlugin(),
|
|
||||||
() -> this.processInboundPacket(ctx, packet, packetClass));
|
() -> this.processInboundPacket(ctx, packet, packetClass));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -555,8 +555,7 @@ public class NettyChannelInjector implements Injector {
|
||||||
// ensure that we are on the main thread if we need to
|
// ensure that we are on the main thread if we need to
|
||||||
if (this.channelListener.hasMainThreadListener(packet.getClass()) && !this.server.isPrimaryThread()) {
|
if (this.channelListener.hasMainThreadListener(packet.getClass()) && !this.server.isPrimaryThread()) {
|
||||||
// not on the main thread but we are required to be - re-schedule the packet on the main thread
|
// not on the main thread but we are required to be - re-schedule the packet on the main thread
|
||||||
this.server.getScheduler().scheduleSyncDelayedTask(
|
ProtocolLibrary.getScheduler().runTask(
|
||||||
this.injectionFactory.getPlugin(),
|
|
||||||
() -> this.sendServerPacket(packet, null, true));
|
() -> this.sendServerPacket(packet, null, true));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.comphenix.protocol.scheduler;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
/** Just modified BukkitRunnable */
|
||||||
|
public abstract class UniversalRunnable implements Runnable {
|
||||||
|
Task task;
|
||||||
|
|
||||||
|
public synchronized void cancel() throws IllegalStateException {
|
||||||
|
checkScheduled();
|
||||||
|
task.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedules this in the scheduler to run on next tick.
|
||||||
|
*
|
||||||
|
* @param plugin the reference to the plugin scheduling task
|
||||||
|
* @return {@link Task}
|
||||||
|
* @throws IllegalArgumentException if plugin is null
|
||||||
|
* @throws IllegalStateException if this was already scheduled
|
||||||
|
* @see ProtocolScheduler#runTask(Runnable)
|
||||||
|
*/
|
||||||
|
|
||||||
|
public synchronized Task runTask(Plugin plugin) throws IllegalArgumentException, IllegalStateException {
|
||||||
|
checkNotYetScheduled();
|
||||||
|
return setupTask(ProtocolLibrary.getScheduler().runTask(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedules this to run after the specified number of server ticks.
|
||||||
|
*
|
||||||
|
* @param plugin the reference to the plugin scheduling task
|
||||||
|
* @param delay the ticks to wait before running the task
|
||||||
|
* @return {@link Task}
|
||||||
|
* @throws IllegalArgumentException if plugin is null
|
||||||
|
* @throws IllegalStateException if this was already scheduled
|
||||||
|
* @see ProtocolScheduler#scheduleSyncDelayedTask(Runnable, long)
|
||||||
|
*/
|
||||||
|
|
||||||
|
public synchronized Task runTaskLater(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException {
|
||||||
|
checkNotYetScheduled();
|
||||||
|
return setupTask(ProtocolLibrary.getScheduler().scheduleSyncDelayedTask(this, delay));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkScheduled() {
|
||||||
|
if (task == null) {
|
||||||
|
throw new IllegalStateException("Not scheduled yet");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkNotYetScheduled() {
|
||||||
|
if (task != null) {
|
||||||
|
throw new IllegalStateException("Already scheduled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Task setupTask(final Task task) {
|
||||||
|
this.task = task;
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue