Skip to content

Commit 81b1644

Browse files
authored
Replace BukkitRunnable with UniversalRunnable (#2460)
1 parent 12d8141 commit 81b1644

File tree

8 files changed

+86
-20
lines changed

8 files changed

+86
-20
lines changed

gradle/wrapper/gradle-wrapper.jar

1.73 KB
Binary file not shown.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
44
networkTimeout=10000
5+
validateDistributionUrl=true
56
zipStoreBase=GRADLE_USER_HOME
67
zipStorePath=wrapper/dists

gradlew

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ done
8585
APP_BASE_NAME=${0##*/}
8686
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
8787

88-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90-
9188
# Use the maximum available, or set MAX_FD != -1 to use that value.
9289
MAX_FD=maximum
9390

@@ -133,10 +130,13 @@ location of your Java installation."
133130
fi
134131
else
135132
JAVACMD=java
136-
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
133+
if ! command -v java >/dev/null 2>&1
134+
then
135+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137136
138137
Please set the JAVA_HOME variable in your environment to match the
139138
location of your Java installation."
139+
fi
140140
fi
141141

142142
# Increase the maximum file descriptors if we can.
@@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
197197
done
198198
fi
199199

200+
201+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
202+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
203+
200204
# Collect all arguments for the java command;
201205
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
202206
# shell script including quotes and variable substitutions, so put them in

src/main/java/com/comphenix/protocol/PacketType.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.comphenix.protocol.PacketTypeLookup.ClassLookup;
1212
import com.comphenix.protocol.events.ConnectionSide;
1313
import com.comphenix.protocol.injector.packet.PacketRegistry;
14+
import com.comphenix.protocol.scheduler.UniversalRunnable;
1415
import com.comphenix.protocol.utility.MinecraftReflection;
1516
import com.comphenix.protocol.utility.MinecraftVersion;
1617
import com.google.common.base.Preconditions;
@@ -19,8 +20,6 @@
1920

2021
import org.apache.commons.lang.WordUtils;
2122
import org.bukkit.Bukkit;
22-
import org.bukkit.scheduler.BukkitRunnable;
23-
2423
/**
2524
* Represents the type of a packet in a specific protocol.
2625
* <p>
@@ -1022,7 +1021,7 @@ public static boolean hasClass(Class<?> packetClass) {
10221021
* @param name - the name of the packet.
10231022
*/
10241023
public static void scheduleRegister(final PacketType type, final String name) {
1025-
BukkitRunnable runnable = new BukkitRunnable() {
1024+
UniversalRunnable runnable = new UniversalRunnable() {
10261025
@Override
10271026
public void run() {
10281027
PacketTypeEnum objEnum;

src/main/java/com/comphenix/protocol/ProtocolLibrary.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public class ProtocolLibrary {
3737
/**
3838
* The maximum version ProtocolLib has been tested with.
3939
*/
40-
public static final String MAXIMUM_MINECRAFT_VERSION = MinecraftVersion.LATEST.getVersion();
40+
public static final String MAXIMUM_MINECRAFT_VERSION = "1.20.1";
4141

4242
/**
43-
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.19.2) was released.
43+
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.20.1) was released.
4444
*/
45-
public static final String MINECRAFT_LAST_RELEASE_DATE = "2022-08-05";
45+
public static final String MINECRAFT_LAST_RELEASE_DATE = "2023-06-12";
4646

4747
/**
4848
* Plugins that are currently incompatible with ProtocolLib.

src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@ public void sendServerPacket(Player receiver, PacketContainer packet, NetworkMar
166166
// ensure we are on the main thread if any listener requires that
167167
if (this.playerInjectionHandler.hasMainThreadListener(packet.getType()) && !this.server.isPrimaryThread()) {
168168
NetworkMarker copy = marker; // okay fine
169-
this.server.getScheduler().scheduleSyncDelayedTask(
170-
this.plugin,
171-
() -> this.sendServerPacket(receiver, packet, copy, false));
169+
ProtocolLibrary.getScheduler().scheduleSyncDelayedTask(
170+
() -> this.sendServerPacket(receiver, packet, copy, false), 1L);
172171
return;
173172
}
174173

@@ -218,8 +217,7 @@ public void receiveClientPacket(Player sender, PacketContainer packet, NetworkMa
218217
if (!this.closed) {
219218
// make sure we are on the main thread if any listener of the packet needs it
220219
if (this.playerInjectionHandler.hasMainThreadListener(packet.getType()) && !this.server.isPrimaryThread()) {
221-
this.server.getScheduler().scheduleSyncDelayedTask(
222-
this.plugin,
220+
ProtocolLibrary.getScheduler().runTask(
223221
() -> this.receiveClientPacket(sender, packet, marker, filters));
224222
return;
225223
}

src/main/java/com/comphenix/protocol/injector/netty/channel/NettyChannelInjector.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import com.comphenix.protocol.PacketType;
1717
import com.comphenix.protocol.PacketType.Protocol;
18+
import com.comphenix.protocol.ProtocolLibrary;
1819
import com.comphenix.protocol.error.ErrorReporter;
1920
import com.comphenix.protocol.error.Report;
2021
import com.comphenix.protocol.error.ReportType;
@@ -490,8 +491,7 @@ private void ensureInEventLoop(EventLoop eventLoop, Runnable runnable) {
490491
void processInboundPacket(ChannelHandlerContext ctx, Object packet, Class<?> packetClass) {
491492
if (this.channelListener.hasMainThreadListener(packetClass) && !this.server.isPrimaryThread()) {
492493
// not on the main thread but we are required to be - re-schedule the packet on the main thread
493-
this.server.getScheduler().runTask(
494-
this.injectionFactory.getPlugin(),
494+
ProtocolLibrary.getScheduler().runTask(
495495
() -> this.processInboundPacket(ctx, packet, packetClass));
496496
return;
497497
}
@@ -555,8 +555,7 @@ <T> T processOutbound(T action) {
555555
// ensure that we are on the main thread if we need to
556556
if (this.channelListener.hasMainThreadListener(packet.getClass()) && !this.server.isPrimaryThread()) {
557557
// not on the main thread but we are required to be - re-schedule the packet on the main thread
558-
this.server.getScheduler().scheduleSyncDelayedTask(
559-
this.injectionFactory.getPlugin(),
558+
ProtocolLibrary.getScheduler().runTask(
560559
() -> this.sendServerPacket(packet, null, true));
561560
return null;
562561
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.comphenix.protocol.scheduler;
2+
3+
import com.comphenix.protocol.ProtocolLibrary;
4+
import org.bukkit.plugin.Plugin;
5+
6+
/** Just modified BukkitRunnable */
7+
public abstract class UniversalRunnable implements Runnable {
8+
Task task;
9+
10+
public synchronized void cancel() throws IllegalStateException {
11+
checkScheduled();
12+
task.cancel();
13+
}
14+
15+
/**
16+
* Schedules this in the scheduler to run on next tick.
17+
*
18+
* @param plugin the reference to the plugin scheduling task
19+
* @return {@link Task}
20+
* @throws IllegalArgumentException if plugin is null
21+
* @throws IllegalStateException if this was already scheduled
22+
* @see ProtocolScheduler#runTask(Runnable)
23+
*/
24+
25+
public synchronized Task runTask(Plugin plugin) throws IllegalArgumentException, IllegalStateException {
26+
checkNotYetScheduled();
27+
return setupTask(ProtocolLibrary.getScheduler().runTask(this));
28+
}
29+
30+
/**
31+
* Schedules this to run after the specified number of server ticks.
32+
*
33+
* @param plugin the reference to the plugin scheduling task
34+
* @param delay the ticks to wait before running the task
35+
* @return {@link Task}
36+
* @throws IllegalArgumentException if plugin is null
37+
* @throws IllegalStateException if this was already scheduled
38+
* @see ProtocolScheduler#scheduleSyncDelayedTask(Runnable, long)
39+
*/
40+
41+
public synchronized Task runTaskLater(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException {
42+
checkNotYetScheduled();
43+
return setupTask(ProtocolLibrary.getScheduler().scheduleSyncDelayedTask(this, delay));
44+
}
45+
46+
private void checkScheduled() {
47+
if (task == null) {
48+
throw new IllegalStateException("Not scheduled yet");
49+
}
50+
}
51+
52+
private void checkNotYetScheduled() {
53+
if (task != null) {
54+
throw new IllegalStateException("Already scheduled");
55+
}
56+
}
57+
58+
59+
private Task setupTask(final Task task) {
60+
this.task = task;
61+
return task;
62+
}
63+
64+
65+
}

0 commit comments

Comments
 (0)