1
1
package org .skriptlang .skript .log .runtime ;
2
2
3
+ import ch .njol .skript .Skript ;
3
4
import ch .njol .skript .log .SkriptLogger ;
5
+ import org .jetbrains .annotations .Nullable ;
4
6
import org .jetbrains .annotations .UnmodifiableView ;
5
7
import org .skriptlang .skript .log .runtime .Frame .FrameOutput ;
6
8
7
9
import java .util .ArrayList ;
8
10
import java .util .Collections ;
9
11
import java .util .List ;
10
- import java .util .Map .Entry ;
11
12
import java .util .logging .Level ;
12
13
13
14
/**
@@ -20,15 +21,21 @@ public class RuntimeErrorCatcher implements RuntimeErrorConsumer {
20
21
21
22
private final List <RuntimeError > cachedErrors = new ArrayList <>();
22
23
23
- private final List <Entry <FrameOutput , Level >> cachedFrames = new ArrayList <>();
24
+ // hard limit on stored errors to prevent a runaway loop from filling up memory, for example.
25
+ private static final int ERROR_LIMIT = 1000 ;
24
26
25
27
public RuntimeErrorCatcher () {}
26
28
27
29
/**
28
30
* Gets the {@link RuntimeErrorManager}.
29
31
*/
30
32
private RuntimeErrorManager getManager () {
31
- return RuntimeErrorManager .getInstance ();
33
+ return Skript .getRuntimeErrorManager ();
34
+ }
35
+
36
+ @ Override
37
+ public @ Nullable RuntimeErrorFilter getFilter () {
38
+ return RuntimeErrorFilter .NO_FILTER ; // no filter means everything gets printed.
32
39
}
33
40
34
41
/**
@@ -47,7 +54,7 @@ public RuntimeErrorCatcher start() {
47
54
/**
48
55
* Stops this {@link RuntimeErrorCatcher}, removing from {@link RuntimeErrorManager} and restoring the previous
49
56
* {@link RuntimeErrorConsumer}s from {@link #storedConsumers}.
50
- * Prints all cached {@link RuntimeError}s, {@link #cachedErrors}, and cached {@link FrameOutput}s, {@link #cachedFrames} .
57
+ * Prints all cached {@link RuntimeError}s, {@link #cachedErrors}.
51
58
*/
52
59
public void stop () {
53
60
if (!getManager ().removeConsumer (this )) {
@@ -57,8 +64,6 @@ public void stop() {
57
64
getManager ().addConsumers (storedConsumers .toArray (RuntimeErrorConsumer []::new ));
58
65
for (RuntimeError runtimeError : cachedErrors )
59
66
storedConsumers .forEach (consumer -> consumer .printError (runtimeError ));
60
- for (Entry <FrameOutput , Level > entry : cachedFrames )
61
- storedConsumers .forEach (consumer -> consumer .printFrameOutput (entry .getKey (), entry .getValue ()));
62
67
}
63
68
64
69
/**
@@ -68,13 +73,6 @@ public void stop() {
68
73
return Collections .unmodifiableList (cachedErrors );
69
74
}
70
75
71
- /**
72
- * Gets all cached {@link FrameOutput}s stored with its corresponding {@link Level} in an {@link Entry}
73
- */
74
- public @ UnmodifiableView List <Entry <FrameOutput , Level >> getCachedFrames () {
75
- return Collections .unmodifiableList (cachedFrames );
76
- }
77
-
78
76
/**
79
77
* Clear all cached {@link RuntimeError}s.
80
78
*/
@@ -83,37 +81,15 @@ public RuntimeErrorCatcher clearCachedErrors() {
83
81
return this ;
84
82
}
85
83
86
- /**
87
- * Clears all cached {@link FrameOutput}s.
88
- */
89
- public RuntimeErrorCatcher clearCachedFrames () {
90
- cachedFrames .clear ();
91
- return this ;
92
- }
93
-
94
84
@ Override
95
85
public void printError (RuntimeError error ) {
96
- cachedErrors .add (error );
86
+ if (cachedErrors .size () < ERROR_LIMIT )
87
+ cachedErrors .add (error );
97
88
}
98
89
99
90
@ Override
100
91
public void printFrameOutput (FrameOutput output , Level level ) {
101
- cachedFrames .add (new Entry <FrameOutput , Level >() {
102
- @ Override
103
- public FrameOutput getKey () {
104
- return output ;
105
- }
106
-
107
- @ Override
108
- public Level getValue () {
109
- return level ;
110
- }
111
-
112
- @ Override
113
- public Level setValue (Level value ) {
114
- return null ;
115
- }
116
- });
92
+ // do nothing, this won't be called since we have no filter.
117
93
}
118
94
119
95
}
0 commit comments