Skip to content

Commit b440802

Browse files
authored
Merge pull request CommandAPI#580 from Mrredstone5230/fix/nullcommandsender-exception
Made NullCommandSender not throw an exception on Paper
2 parents 81da286 + b521185 commit b440802

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
@@ -409,6 +409,13 @@ public BukkitCommandSender<? extends CommandSender> wrapCommandSender(CommandSen
409409
// We literally cannot type this at compile-time, so let's use a placeholder CommandSender instance
410410
return new BukkitFeedbackForwardingCommandSender<CommandSender>(FeedbackForwardingSender.cast(sender));
411411
}
412+
413+
final Class<? extends CommandSender> NullCommandSender = paper.getNullCommandSender();
414+
if (NullCommandSender != null && NullCommandSender.isInstance(sender)) {
415+
// Since this should only be during a function load, this is just a placeholder to evade the exception.
416+
return null;
417+
}
418+
412419
}
413420
throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender");
414421
}

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)