8
8
/** Object used to store information about the state of a View's update interval. */
9
9
final class BukkitViewUpdateJobImpl implements ViewUpdateJob , Runnable {
10
10
11
- private final Plugin plugin ;
12
11
private final VirtualView view ;
13
12
14
13
@ Getter private final long delay ;
@@ -18,9 +17,7 @@ final class BukkitViewUpdateJobImpl implements ViewUpdateJob, Runnable {
18
17
private boolean interrupted ;
19
18
private boolean started ;
20
19
21
- public BukkitViewUpdateJobImpl (
22
- @ NotNull Plugin plugin , @ NotNull VirtualView view , long delay , long interval ) {
23
- this .plugin = plugin ;
20
+ public BukkitViewUpdateJobImpl (@ NotNull VirtualView view , long delay , long interval ) {
24
21
this .view = view ;
25
22
this .delay = delay ;
26
23
this .interval = interval ;
@@ -39,7 +36,14 @@ public void start() {
39
36
throw new IllegalStateException ("Cannot start a interrupted view update job" );
40
37
if (task != null ) throw new IllegalStateException ("View update job already started" );
41
38
39
+ final PlatformViewFrame <?, ?, ?> initiator = findViewFrame ();
40
+ if (initiator == null )
41
+ throw new IllegalStateException (
42
+ "Cannot schedule view update because there's no initiator to do this" );
43
+
44
+ final Plugin plugin = (Plugin ) initiator .getOwner ();
42
45
task = plugin .getServer ().getScheduler ().runTaskTimer (plugin , this , delay , interval );
46
+
43
47
started = true ;
44
48
}
45
49
@@ -76,7 +80,11 @@ public void cancel() {
76
80
started = false ;
77
81
}
78
82
79
- void interrupt () {
80
- this .interrupted = !interrupted ;
83
+ private PlatformViewFrame <?, ?, ?> findViewFrame () {
84
+ if (view instanceof AbstractView ) return ((AbstractView ) view ).getViewFrame ();
85
+ if (view instanceof ViewContext ) return ((ViewContext ) view ).getRoot ().getViewFrame ();
86
+
87
+ throw new IllegalArgumentException (
88
+ "Unable to find view frame on: " + view .getClass ().getName ());
81
89
}
82
90
}
0 commit comments