Skip to content

Commit

Permalink
Refactor negated pattern variables
Browse files Browse the repository at this point in the history
  • Loading branch information
willkroboth committed Aug 14, 2023
1 parent 5f6ca11 commit 0d08647
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,16 @@ <T, EI> ArgumentType<T> wrapArgumentType(Argument argument, ArgumentType<T> rawT
return wrapArgumentType(((WrapperArgument<Argument>) argument).getBaseArgument(), rawType);
}

if (!(argument instanceof InitialParseExceptionArgument)) return rawType;
if (argument instanceof InitialParseExceptionArgument) {
InitialParseExceptionArgument<T, EI, ?> iPEA = (InitialParseExceptionArgument<T, EI, ?>) argument.instance();
Optional<InitialParseExceptionHandler<T, EI>> handler = iPEA.getInitialParseExceptionHandler();

InitialParseExceptionArgument<T, EI, ?> iPEA = (InitialParseExceptionArgument<T, EI, ?>) argument.instance();
if (handler.isPresent()) {
return new ExceptionHandlingArgumentType<>(rawType, handler.get(), iPEA::parseInitialParseException);
}
}

Optional<InitialParseExceptionHandler<T, EI>> handler = iPEA.getInitialParseExceptionHandler();
if (handler.isEmpty()) return rawType;
return new ExceptionHandlingArgumentType<>(rawType, handler.get(), iPEA::parseInitialParseException);
return rawType;
}

CommandArguments generatePreviousArguments(CommandContext<Source> context, Argument[] args, String nodeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,6 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof ChatMessage chat)) return null;

return chat.getKey();
return (message instanceof ChatMessage chat) ? chat.getKey() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,6 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof ChatMessage chat)) return null;

return chat.getKey();
return (message instanceof ChatMessage chat) ? chat.getKey() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,6 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof ChatMessage chat)) return null;

return chat.getKey();
return (message instanceof ChatMessage chat) ? chat.getKey() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,6 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof ChatMessage chat)) return null;

return chat.getKey();
return (message instanceof ChatMessage chat) ? chat.getKey() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,7 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof TranslatableComponent chat)) return null;

return chat.getKey();
return (message instanceof TranslatableComponent chat) ? chat.getKey() : null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,7 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof TranslatableComponent chat)) return null;

return chat.getKey();
return (message instanceof TranslatableComponent chat) ? chat.getKey() : null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,7 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof TranslatableComponent chat)) return null;

return chat.getKey();
return (message instanceof TranslatableComponent chat) ? chat.getKey() : null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,12 +916,16 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof MutableComponent component)) return null;

ComponentContents contents = component.getContents();
if(!(contents instanceof TranslatableContents translatableContents)) return null;
if (message instanceof MutableComponent component) {
ComponentContents contents = component.getContents();

return translatableContents.getKey();
if (contents instanceof TranslatableContents translatableContents) {
return translatableContents.getKey();
}
}

return null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,16 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof MutableComponent component)) return null;

ComponentContents contents = component.getContents();
if(!(contents instanceof TranslatableContents translatableContents)) return null;
if (message instanceof MutableComponent component) {
ComponentContents contents = component.getContents();

return translatableContents.getKey();
if (contents instanceof TranslatableContents translatableContents) {
return translatableContents.getKey();
}
}

return null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,16 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof MutableComponent component)) return null;

ComponentContents contents = component.getContents();
if(!(contents instanceof TranslatableContents translatableContents)) return null;
if (message instanceof MutableComponent component) {
ComponentContents contents = component.getContents();

return translatableContents.getKey();
if (contents instanceof TranslatableContents translatableContents) {
return translatableContents.getKey();
}
}

return null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,16 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof MutableComponent component)) return null;

ComponentContents contents = component.getContents();
if(!(contents instanceof TranslatableContents translatableContents)) return null;
if (message instanceof MutableComponent component) {
ComponentContents contents = component.getContents();

return translatableContents.getKey();
if (contents instanceof TranslatableContents translatableContents) {
return translatableContents.getKey();
}
}

return null;
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 0d08647

Please sign in to comment.