Skip to content

Commit dd25001

Browse files
committed
Merge branch 'api-8' into api-9
2 parents de0ec98 + a572f60 commit dd25001

File tree

5 files changed

+46
-89
lines changed

5 files changed

+46
-89
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ projectDescription=A plugin API for Minecraft: Java Edition
66

77
org.gradle.parallel=true
88

9-
adventureVersion=4.9.0
9+
adventureVersion=4.9.2
1010
caffeineVersion=3.0.2
1111
configurateVersion=4.1.2
1212
errorproneVersion=2.8.1

src/main/java/org/spongepowered/api/scheduler/ScheduledTask.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,24 @@
2525
package org.spongepowered.api.scheduler;
2626

2727
import org.spongepowered.api.util.Identifiable;
28-
import org.spongepowered.plugin.PluginContainer;
28+
import org.spongepowered.api.util.Nameable;
2929

3030
/**
31-
* Represents a {@link Task} that was scheduled through a
32-
* {@link Scheduler} using {@link Scheduler#submit(Task)}.
31+
* Represents a {@link Task task} that was scheduled through a
32+
* {@link Scheduler scheduler} using {@link Scheduler#submit(Task)}.
3333
*/
34-
public interface ScheduledTask extends Identifiable {
34+
public interface ScheduledTask extends Nameable, Identifiable {
3535

3636
/**
37-
* Gets the name of this scheduled task.
38-
*
39-
* @return The name
37+
* @return The {@link Scheduler scheduler}
4038
*/
41-
String name();
39+
Scheduler scheduler();
4240

4341
/**
44-
* Gets the {@link Task} that was scheduled.
45-
*
46-
* @return The task
42+
* @return The {@link Task}
4743
*/
4844
Task task();
4945

50-
/**
51-
* Returns the plugin that scheduled this task.
52-
*
53-
* @return The plugin that scheduled the task
54-
*/
55-
default PluginContainer owner() {
56-
return this.task().owner();
57-
}
58-
5946
/**
6047
* Cancels this scheduled task. Cancelling a repeating task
6148
* will prevent any further repetitions of the task.

src/main/java/org/spongepowered/api/scheduler/Scheduler.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import java.util.concurrent.ExecutorService;
3333

3434
/**
35-
* Represents a scheduler for running {@link Task}s.
35+
* Represents a scheduler for running {@link Task tasks}.
3636
*/
3737
public interface Scheduler {
3838

@@ -47,43 +47,62 @@ public interface Scheduler {
4747
/**
4848
* Returns a set of {@link Task}s that match the Regular Expression pattern.
4949
*
50-
* @param pattern The regular expression pattern applied to the name of
51-
* tasks
52-
* @return A set of {@link Task}s that have names that match the pattern,
53-
* the set will be empty if no names match
50+
* @param pattern The regular expression pattern applied to the name of tasks
51+
* @return A set of {@link Task}s that have names that match the pattern, the
52+
* set will be empty if no names match
5453
*/
5554
Set<ScheduledTask> findTasks(String pattern);
5655

5756
/**
58-
* Returns a set of all currently scheduled tasks.
57+
* Returns a set of all currently scheduled tasks owned by the given plugin.
5958
*
59+
* @param plugin The plugin that created the tasks
6060
* @return A set of scheduled tasks
6161
*/
62-
Set<ScheduledTask> tasks();
62+
Set<ScheduledTask> tasks(PluginContainer plugin);
6363

6464
/**
65-
* Returns a set of all currently scheduled tasks owned by the given plugin.
65+
* Returns a set of all currently scheduled tasks.
6666
*
67-
* @param plugin The plugin that created the tasks
6867
* @return A set of scheduled tasks
6968
*/
70-
Set<ScheduledTask> tasks(PluginContainer plugin);
69+
Set<ScheduledTask> tasks();
7170

7271
/**
73-
* Creates a new {@link ExecutorService} that can be used to schedule
72+
* Gets an {@link ExecutorService executor} that can be used to schedule
7473
* tasks through the standard Java concurrency interfaces.
7574
*
7675
* @param plugin The plugin that will own the created tasks
77-
* @return A new executor service that can be used to execute tasks
76+
* @return An executor that can be used to execute tasks
7877
*/
79-
TaskExecutorService createExecutor(PluginContainer plugin);
78+
TaskExecutorService executor(PluginContainer plugin);
8079

8180
/**
8281
* Submit a {@link Task} to this scheduler and returns the task
8382
* as a {@link ScheduledTask}.
83+
* <p>
84+
* The name of the task will be the form:<br> {@code PLUGIN_ID "-" ( "A-" | "S-" ) SERIAL_ID}
85+
* <p>
86+
* Examples of default Task names:<br>
8487
*
88+
* {@code "FooPlugin-A-12"}<br>{@code "BarPlugin-S-4322"}
89+
* <p>
90+
* No two active tasks will have the same serial ID for the same
91+
* synchronisation type.<br>i.e {@code APlugin-A-15} and
92+
* {@code BPlugin-A-15} is not possible but {@code BPlugin-S-15}
93+
* is.
8594
* @param task The task
8695
* @return The scheduled task
8796
*/
8897
ScheduledTask submit(Task task);
98+
99+
/**
100+
* Submit a {@link Task} with a specified {@link String name} to this scheduler and returns the task
101+
* as a {@link ScheduledTask}.
102+
*
103+
* @param task The task
104+
* @param name The name
105+
* @return The scheduled task
106+
*/
107+
ScheduledTask submit(Task task, String name);
89108
}

src/main/java/org/spongepowered/api/scheduler/Task.java

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
package org.spongepowered.api.scheduler;
2626

2727
import org.spongepowered.api.Sponge;
28-
import org.spongepowered.api.event.CauseStackManager;
2928
import org.spongepowered.api.util.CopyableBuilder;
3029
import org.spongepowered.api.util.Ticks;
3130
import org.spongepowered.plugin.PluginContainer;
@@ -51,18 +50,9 @@ static Builder builder() {
5150
}
5251

5352
/**
54-
* Gets the name of this task.
55-
*
56-
* @return The name of the task
57-
*/
58-
String name();
59-
60-
/**
61-
* Returns the plugin that constructed this task.
62-
*
63-
* @return The plugin that constructed the task
53+
* @return The {@link PluginContainer plugin}
6454
*/
65-
PluginContainer owner();
55+
PluginContainer plugin();
6656

6757
/**
6858
* Gets the delay that the task was scheduled to run after. A delay of 0
@@ -80,13 +70,6 @@ static Builder builder() {
8070
*/
8171
Duration interval();
8272

83-
/**
84-
* Gets the {@link Consumer}&gt;{@link Task}&lt; that this task is running.
85-
*
86-
* @return The consumer
87-
*/
88-
Consumer<ScheduledTask> consumer();
89-
9073
/**
9174
* Represents a builder to create a {@link Task}.
9275
*/
@@ -224,37 +207,9 @@ default Builder interval(final long interval, final TimeUnit unit) {
224207
*/
225208
Builder interval(final Ticks ticks);
226209

227-
/**
228-
* Sets the name of the task, the name cannot be blank.
229-
*
230-
* <p>If the name is not set in the builder, the name of the task
231-
* will be the form:<br> {@code PLUGIN_ID "-" ( "A-" | "S-" ) SERIAL_ID}
232-
* </p>
233-
*
234-
* <p>Examples of default Task names:<br>
235-
*
236-
* {@code "FooPlugin-A-12"}<br>{@code "BarPlugin-S-4322"}</p>
237-
*
238-
* <p>No two active tasks will have the same serial ID for the same
239-
* synchronisation type.<br>i.e {@code APlugin-A-15} and
240-
* {@code BPlugin-A-15} is not possible but {@code BPlugin-S-15}
241-
* is.</p>
242-
*
243-
* @param name The task name
244-
* @return This builder, for chaining
245-
* @throws IllegalArgumentException If the name is blank
246-
*/
247-
Builder name(String name);
248-
249210
/**
250211
* Sets the plugin of the task.
251212
*
252-
* <p>If no plugin is set, one will be extracted from the
253-
* {@link CauseStackManager} when the {@link #build()} method
254-
* is called from a main thread. If it's not called called
255-
* from a main thread, a {@link IllegalStateException} will
256-
* be thrown.</p>
257-
*
258213
* @param plugin The plugin instance
259214
* @return This builder, for chaining
260215
* @throws IllegalArgumentException If the given object isn't a valid plugin
@@ -265,10 +220,8 @@ default Builder interval(final long interval, final TimeUnit unit) {
265220
* Builds the task.
266221
*
267222
* @return A new instance of a {@link Task}
268-
* @throws IllegalStateException If the {@link #execute(Runnable)} isn't set. Or
269-
* in case that {@link #plugin(PluginContainer)} isn't set and
270-
* no {@link PluginContainer} could be extracted
271-
* from the {@link CauseStackManager}.
223+
* @throws IllegalStateException If the {@link #execute(Runnable)} isn't set or in the
224+
* case that {@link #plugin(PluginContainer)} isn't set.
272225
*/
273226
@Override
274227
Task build();

src/main/java/org/spongepowered/api/util/Nameable.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525
package org.spongepowered.api.util;
2626

2727
/**
28-
* An identifiable object that uses a {@link String} as an identifier.
28+
* An object that can be described by a {@link String name}.
2929
*/
3030
public interface Nameable {
3131

3232
/**
33-
* The name that represents this object.
34-
*
35-
* @return The name.
33+
* @return The {@link String name}
3634
*/
3735
String name();
3836

0 commit comments

Comments
 (0)