Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
bugfix: non-player entities cannot use commands #42
Browse files Browse the repository at this point in the history
  • Loading branch information
chocorean committed Jul 26, 2021
1 parent f8a0b63 commit 35526f9
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/main/java/io/chocorean/authmod/event/Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,22 @@ public void onPlayerEvent(PlayerEvent event) {

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onCommand(CommandEvent event) throws CommandSyntaxException {
List<? extends String> whitelist = Config.commandWhitelist.get();
String name = event.getParseResults().getContext().getNodes().get(0).getNode().getName();
boolean isCommandAllowed = whitelist.contains(name);
CommandSource source = event.getParseResults().getContext().getSource();
PlayerEntity playerEntity = source.getPlayerOrException();
if (descriptors.containsKey(playerEntity) && !isCommandAllowed && event.isCancelable()) {
event.setCanceled(true);
event
.getParseResults()
.getContext().getSource()
.sendSuccess(new ServerTranslationTextComponent("authmod.welcome"), false);
try {
PlayerEntity playerEntity = source.getPlayerOrException();
List<? extends String> whitelist = Config.commandWhitelist.get();
String name = event.getParseResults().getContext().getNodes().get(0).getNode().getName();
boolean isCommandAllowed = whitelist.contains(name);
if (descriptors.containsKey(playerEntity) && !isCommandAllowed && event.isCancelable()) {
event.setCanceled(true);
event
.getParseResults()
.getContext().getSource()
.sendSuccess(new ServerTranslationTextComponent("authmod.welcome"), false);
}
} catch (CommandSyntaxException e) {
// raised when command comes from non-player entity
return;
}
}

Expand Down

0 comments on commit 35526f9

Please sign in to comment.