@@ -5,11 +5,21 @@ import net.kyori.adventure.text.Component
5
5
import org.slf4j.LoggerFactory
6
6
7
7
/* * The standard implementation that handles an interfaces exception. */
8
- public object StandardInterfacesExceptionHandler : InterfacesExceptionHandler {
8
+ public class StandardInterfacesExceptionHandler (
9
+ /* * Whether decorations are allowed to fail gracefully. */
10
+ public val allowDecorationFailure : Boolean = true ,
11
+ ) : InterfacesExceptionHandler {
9
12
private val logger = LoggerFactory .getLogger(StandardInterfacesExceptionHandler ::class .java)
10
13
11
- override suspend fun handleException (exception : Exception , context : InterfacesExceptionContext ): InterfacesExceptionResolution =
12
- when (context.operation) {
14
+ override suspend fun handleException (exception : Exception , context : InterfacesExceptionContext ): InterfacesExceptionResolution {
15
+ // Optionally gracefully let decorations fail without issue! This defaults to true because we also
16
+ // allow items to be clicked without their decorations.
17
+ if (allowDecorationFailure && context.operation == InterfacesOperation .DECORATING_ELEMENT ) {
18
+ logger.warn(" Failed to decorate interface elements for ${context.player.name} " )
19
+ return InterfacesExceptionResolution .IGNORE
20
+ }
21
+
22
+ return when (context.operation) {
13
23
InterfacesOperation .BUILDING_PLAYER -> {
14
24
if (context.retries < 3 ) {
15
25
// When building a player menu we absolutely do not want to fail as
@@ -19,7 +29,7 @@ public object StandardInterfacesExceptionHandler : InterfacesExceptionHandler {
19
29
} else {
20
30
// Ignore the drawing but kick the player off the server
21
31
logger.error(
22
- " Failed to build player inventory for ${context.player.name} 3 times, kicking player to prevent invalid state"
32
+ " Failed to build player inventory for ${context.player.name} 3 times, kicking player to prevent invalid state" ,
23
33
)
24
34
InterfacesListeners .INSTANCE .runSync {
25
35
context.player.kick(Component .text(" Unknown exception occurred while rendering GUI menus" ))
@@ -37,4 +47,5 @@ public object StandardInterfacesExceptionHandler : InterfacesExceptionHandler {
37
47
InterfacesExceptionResolution .CLOSE
38
48
}
39
49
}
50
+ }
40
51
}
0 commit comments