-
-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace BukkitRunnable with UniversalRunnable (#2460)
- Loading branch information
Showing
8 changed files
with
86 additions
and
20 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
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 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/com/comphenix/protocol/scheduler/UniversalRunnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
|
||
} |