Skip to content

Commit 47aa428

Browse files
committed
Made NullCommandSender not throw an exception on Paper
1 parent d130bde commit 47aa428

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@ public BukkitCommandSender<? extends CommandSender> wrapCommandSender(CommandSen
407407
// We literally cannot type this at compile-time, so let's use a placeholder CommandSender instance
408408
return new BukkitFeedbackForwardingCommandSender<CommandSender>(FeedbackForwardingSender.cast(sender));
409409
}
410+
411+
final Class<? extends CommandSender> NullCommandSender = paper.getNullCommandSender();
412+
if (NullCommandSender.isInstance(sender)) {
413+
// Since this should only be during a function load, this is just a placeholder to evade the exception.
414+
return null;
415+
}
416+
410417
}
411418
throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender");
412419
}

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperImplementations.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class PaperImplementations {
2222
private final boolean isFoliaPresent;
2323
private final NMS<?> nmsInstance;
2424
private final Class<? extends CommandSender> feedbackForwardingCommandSender;
25+
private final Class<? extends CommandSender> nullCommandSender;
2526

2627
/**
2728
* Constructs a PaperImplementations object
@@ -44,6 +45,15 @@ public PaperImplementations(boolean isPaperPresent, boolean isFoliaPresent, NMS<
4445
}
4546

4647
this.feedbackForwardingCommandSender = tempFeedbackForwardingCommandSender;
48+
49+
Class<? extends CommandSender> tempNullCommandSender = null;
50+
try {
51+
tempNullCommandSender = (Class<? extends CommandSender>) Class.forName("io.papermc.paper.brigadier.NullCommandSender");
52+
} catch (ClassNotFoundException e) {
53+
// uhh...
54+
}
55+
56+
this.nullCommandSender = tempNullCommandSender;
4757
}
4858

4959
/**
@@ -115,6 +125,13 @@ public Class<? extends CommandSender> getFeedbackForwardingCommandSender() {
115125
return this.feedbackForwardingCommandSender;
116126
}
117127

128+
/**
129+
* @return a class reference pointing to {@code io.papermc.paper.brigadier.NullCommandSender}
130+
*/
131+
public Class<? extends CommandSender> getNullCommandSender() {
132+
return this.nullCommandSender;
133+
}
134+
118135
/**
119136
* Builds a {@link WrapperCommandSyntaxException} from a message with colour codes like {@link ChatColor} or using the § symbol.
120137
*

0 commit comments

Comments
 (0)