update checkstyle and bump carbon to 2.0.0-SNAPSHOT

This commit is contained in:
Draycia committed 2021-05-12 20:47:48 -07:00
1 parent 7abfbe2090
commit f3a734601e
15 files changed
+462 -154

No files matched your search

+241 -136
View File
@@ -1,56 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- MIT License-->
<!-- Copyright (c) 2017-2020 KyoriPowered-->
<!-- Permission is hereby granted, free of charge, to any person obtaining a copy-->
<!-- of this software and associated documentation files (the "Software"), to deal-->
<!-- in the Software without restriction, including without limitation the rights-->
<!-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell-->
<!-- copies of the Software, and to permit persons to whom the Software is-->
<!-- furnished to do so, subject to the following conditions:-->
<!-- The above copyright notice and this permission notice shall be included in all-->
<!-- copies or substantial portions of the Software.-->
<!-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR-->
<!-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,-->
<!-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE-->
<!-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER-->
<!-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,-->
<!-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE-->
<!-- SOFTWARE.-->
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="error"/>
<property name="fileExtensions" value="java, properties, xml"/>
<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<property name="severity" value="error"/>
<!-- https://checkstyle.org/config_filefilters.html#BeforeExecutionExclusionFileFilter -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter">
<property name="file" value="${basedir}/suppressions.xml"
default=".checkstyle/suppressions.xml" />
<property name="optional" value="true"/>
</module>
<!-- allow // CHECKSTYLE:OFF and // CHECKSTYLE:ON comments -->
<module name="SuppressWithPlainTextCommentFilter"/>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.org/config_whitespace.html -->
<!-- https://checkstyle.org/config_whitespace.html#FileTabCharacter -->
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<!-- https://checkstyle.org/config_misc.html#NewlineAtEndOfFile -->
<module name="NewlineAtEndOfFile"/>
<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter">
<property name="file" value="${configDirectory}/suppressions.xml"/>
</module>
<!-- https://checkstyle.org/config_filters.html#SuppressWarningsFilter -->
<module name="SuppressWarningsFilter"/>
<!-- carbon -->
<!-- empty line at beginning after class/interface/enum definition -->
<!-- Temporary until https://github.com/checkstyle/checkstyle/issues/5313 -->
<module name="RegexpMultiline">
@@ -59,122 +35,251 @@
<property name="fileExtensions" value="groovy,java"/>
</module>
<module name="SuppressWarningsFilter" />
<!-- https://checkstyle.org/config_filters.html#SuppressWithPlainTextCommentFilter -->
<module name="SuppressWithPlainTextCommentFilter"/>
<module name="TreeWalker">
<!-- Make the @SuppressWarnings annotations available to Checkstyle -->
<module name="SuppressWarningsHolder" />
<!-- https://checkstyle.org/config_misc.html#ArrayTypeStyle -->
<module name="ArrayTypeStyle"/>
<!-- no space between parameters and parenthesis -->
<module name="EmptyForInitializerPad"/>
<module name="EmptyForIteratorPad"/>
<!-- one empty line between each class element -->
<module name="EmptyLineSeparator">
<!-- No new line after the license header -->
<property name="tokens"
value="IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
<property name="allowNoEmptyLineBetweenFields" value="true"/>
<property name="allowMultipleEmptyLines" value="false"/>
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>
</module>
<module name="GenericWhitespace"/>
<!-- packages and imports must be on one line each -->
<module name="NoLineWrap"/>
<module name="SingleSpaceSeparator">
<property name="validateComments" value="true"/>
</module>
<module name="TypecastParenPad"/>
<module name="UnnecessaryParentheses"/>
<!-- field and method access qualified with `this` -->
<module name="FinalLocalVariable">
<property name="validateEnhancedForLoopVariable" value="true"/>
<property name="tokens" value="VARIABLE_DEF, PARAMETER_DEF"/>
</module>
<module name="RequireThis">
<property name="validateOnlyOverlapping" value="false"/>
<!-- https://checkstyle.org/config_javadoc.html#AtclauseOrder -->
<module name="AtclauseOrder">
<property name="violateExecutionOnNonTightHtml" value="true"/>
<property name="tagOrder" value="@author, @deprecated, @exception, @param, @return, @serial, @serialData, @serialField, @throws, @see, @since, @sinceMinecraft, @version"/>
</module>
<!-- coding practices -->
<module name="RedundantImport"/>
<module name="RedundantModifier">
<!-- Take out METHOD_DEF and RESOURCE so we can have finals -->
<property name="tokens"
value="VARIABLE_DEF, ANNOTATION_FIELD_DEF, INTERFACE_DEF, CTOR_DEF, CLASS_DEF, ENUM_DEF"/>
</module>
<module name="UnusedImports"/>
<module name="HideUtilityClassConstructor"/>
<module name="FinalClass"/>
<!-- https://checkstyle.org/config_imports.html#AvoidStarImport -->
<module name="AvoidStarImport"/>
<!-- no local variable type annotations -->
<module name="NoLvTypeAnnotations"/>
<!-- braces and parentheses on block statements on same line -->
<module name="LeftCurly"/>
<module name="RightCurly">
<property name="id" value="RightCurlySame"/>
<property name="tokens"
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE,
LITERAL_DO"/>
</module>
<module name="RightCurly">
<property name="id" value="RightCurlyAlone"/>
<property name="option" value="alone"/>
<property name="tokens"
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF"/>
<!-- https://checkstyle.org/config_misc.html#AvoidEscapedUnicodeCharacters -->
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowByTailComment" value="true"/>
<property name="allowEscapesForControlCharacters" value="true"/>
<property name="allowNonPrintableEscapes" value="true"/>
</module>
<!-- 2 space indentation -->
<module name="Indentation">
<property name="basicOffset" value="2"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="2"/>
<property name="throwsIndent" value="2"/>
<property name="lineWrappingIndentation" value="0"/>
<property name="arrayInitIndent" value="2"/>
</module>
<!-- https://checkstyle.org/config_misc.html#CommentsIndentation -->
<module name="CommentsIndentation"/>
<!-- some generally unwanted imports -->
<!-- https://checkstyle.org/config_whitespace.html#EmptyForInitializerPad -->
<module name="EmptyForInitializerPad"/>
<!-- https://checkstyle.org/config_whitespace.html#EmptyForIteratorPad -->
<module name="EmptyForIteratorPad"/>
<!-- https://checkstyle.org/config_whitespace.html#EmptyLineSeparator -->
<module name="EmptyLineSeparator">
<property name="allowMultipleEmptyLines" value="false"/>
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>
<property name="allowNoEmptyLineBetweenFields" value="true"/>
<property name="tokens" value="CLASS_DEF, CTOR_DEF, ENUM_DEF, IMPORT, INSTANCE_INIT, INTERFACE_DEF, METHOD_DEF, STATIC_IMPORT, STATIC_INIT, VARIABLE_DEF"/> <!-- remove PACKAGE_DEF, temporarily remove COMPACT_CTOR_DEF, RECORD_DEF -->
</module>
<!-- https://checkstyle.org/config_coding.html#FallThrough -->
<module name="FallThrough">
<property name="checkLastCaseGroup" value="true"/>
</module>
<!-- https://checkstyle.org/config_design.html#FinalClass -->
<module name="FinalClass"/>
<!-- https://checkstyle.org/config_coding.html#FinalLocalVariable -->
<module name="FinalLocalVariable">
<property name="tokens" value="PARAMETER_DEF, VARIABLE_DEF"/> <!-- add PARAMETER_DEF -->
<property name="validateEnhancedForLoopVariable" value="true"/>
</module>
<!-- https://checkstyle.org/config_whitespace.html#GenericWhitespace -->
<module name="GenericWhitespace"/>
<!-- https://checkstyle.org/config_design.html#HideUtilityClassConstructor -->
<module name="HideUtilityClassConstructor"/>
<!-- https://checkstyle.org/config_imports.html#IllegalImport -->
<module name="IllegalImport">
<property name="illegalPkgs" value="sun, jdk, com.sun"/>
</module>
<!-- no get* or set* method names -->
<!-- https://checkstyle.org/config_coding.html#IllegalTokenText -->
<module name="IllegalTokenText">
<property name="format" value="($|[^\\])\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message" value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
<property name="tokens" value="CHAR_LITERAL, STRING_LITERAL"/>
</module>
<!-- https://checkstyle.org/config_misc.html#Indentation -->
<module name="Indentation">
<property name="arrayInitIndent" value="2"/>
<property name="basicOffset" value="2"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="2"/>
<property name="lineWrappingIndentation" value="0"/>
<property name="throwsIndent" value="2"/>
</module>
<!-- https://checkstyle.org/config_javadoc.html#InvalidJavadocPosition -->
<module name="InvalidJavadocPosition"/>
<!-- https://checkstyle.org/config_javadoc.html#JavadocContentLocation -->
<module name="JavadocContentLocation"/>
<!-- https://checkstyle.org/config_javadoc.html#JavadocMissingWhitespaceAfterAsterisk -->
<module name="JavadocMissingWhitespaceAfterAsterisk"/>
<!-- https://checkstyle.org/config_javadoc.html#JavadocParagraph -->
<module name="JavadocParagraph"/>
<!-- https://checkstyle.org/config_javadoc.html#JavadocMissingWhitespaceAfterAsterisk -->
<module name="JavadocTagContinuationIndentation"/>
<!-- https://checkstyle.org/config_blocks.html#LeftCurly -->
<module name="LeftCurly"/>
<!-- https://checkstyle.org/config_naming.html#MethodName -->
<module name="MethodName">
<property name="format" value="^(?:(?:.{1,3})|(?:[gs]et[^A-Z].*)|(?:(?:[^gsA-Z]..|.[^e].|..[^t]).+))$"/>
</module>
<!-- misc formatting based on Google style -->
<!-- match filenames, don't use unicode escapes, no star imports -->
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format"
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message"
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
</module>
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowEscapesForControlCharacters" value="true"/>
<property name="allowByTailComment" value="true"/>
<property name="allowNonPrintableEscapes" value="true"/>
</module>
<module name="AvoidStarImport"/>
<module name="OneStatementPerLine"/>
<!-- https://checkstyle.org/config_whitespace.html#MethodParamPad -->
<module name="MethodParamPad"/>
<!-- https://checkstyle.org/config_javadoc.html#MissingJavadocMethod -->
<module name="MissingJavadocMethod"/>
<!-- https://checkstyle.org/config_javadoc.html#MissingJavadocPackage -->
<module name="MissingJavadocPackage"/>
<!-- https://checkstyle.org/config_javadoc.html#MissingJavadocType -->
<module name="MissingJavadocType"/>
<!-- https://checkstyle.org/config_coding.html#MultipleVariableDeclarations -->
<module name="MultipleVariableDeclarations"/>
<module name="ArrayTypeStyle"/>
<module name="FallThrough"/>
<!-- https://checkstyle.org/config_coding.html#NoFinalizer -->
<module name="NoFinalizer"/>
<module name="MethodParamPad">
<property name="tokens"
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF"/>
<!-- https://checkstyle.org/config_whitespace.html#NoLineWrap -->
<module name="NoLineWrap"/>
<!-- https://checkstyle.org/config_javadoc.html#NonEmptyAtclauseDescription -->
<module name="NonEmptyAtclauseDescription"/>
<!-- https://checkstyle.org/config_whitespace.html#NoWhitespaceAfter -->
<module name="NoWhitespaceAfter">
<property name="allowLineBreaks" value="false"/>
</module>
<module name="WhitespaceAfter"/>
<!-- https://checkstyle.org/config_whitespace.html#NoWhitespaceBefore -->
<module name="NoWhitespaceBefore">
<property name="allowLineBreaks" value="true"/>
<property name="tokens" value="COMMA, DOT, LABELED_STAT, METHOD_REF, POST_DEC, POST_INC, SEMI"/> <!-- remove ELLIPSIS -->
</module>
<!-- https://checkstyle.org/config_coding.html#OneStatementPerLine -->
<module name="OneStatementPerLine"/>
<!-- https://checkstyle.org/config_misc.html#OuterTypeFilename -->
<module name="OuterTypeFilename"/>
<!-- https://checkstyle.org/config_imports.html#RedundantImport -->
<module name="RedundantImport"/>
<!-- https://checkstyle.org/config_modifier.html#RedundantModifier -->
<module name="RedundantModifier">
<property name="tokens" value="ANNOTATION_FIELD_DEF, CLASS_DEF, CTOR_DEF, ENUM_DEF, INTERFACE_DEF, VARIABLE_DEF"/> <!-- remove METHOD_DEF and RESOURCE -->
</module>
<!-- https://checkstyle.org/config_javadoc.html#RequireEmptyLineBeforeBlockTagGroup -->
<module name="RequireEmptyLineBeforeBlockTagGroup"/>
<!-- https://checkstyle.org/config_coding.html#RequireThis -->
<module name="RequireThis">
<property name="validateOnlyOverlapping" value="false"/>
</module>
<!-- https://checkstyle.org/config_blocks.html#RightCurly -->
<module name="RightCurly">
<property name="id" value="RightCurlyAlone"/>
<property name="option" value="alone"/>
<property name="tokens" value="ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_DEF, INSTANCE_INIT, LITERAL_FOR, LITERAL_WHILE, METHOD_DEF, STATIC_INIT"/>
</module>
<module name="RightCurly">
<property name="id" value="RightCurlySame"/>
<property name="option" value="same"/>
<property name="tokens" value="LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF, LITERAL_TRY"/> <!-- add LITERAL_DO -->
</module>
<!-- https://checkstyle.org/config_whitespace.html#SeparatorWrap -->
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapEol"/>
<property name="option" value="eol"/>
<property name="tokens" value="COMMA, SEMI, ELLIPSIS, RBRACK, ARRAY_DECLARATOR, METHOD_REF"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapNl"/>
<property name="option" value="nl"/>
<property name="tokens" value="DOT, AT"/>
</module>
<!-- https://checkstyle.org/config_coding.html#SimplifyBooleanExpression -->
<module name="SimplifyBooleanExpression"/>
<!-- https://checkstyle.org/config_coding.html#SimplifyBooleanReturn -->
<module name="SimplifyBooleanReturn"/>
<!-- https://checkstyle.org/config_whitespace.html#SingleSpaceSeparator -->
<module name="SingleSpaceSeparator">
<property name="validateComments" value="true"/>
</module>
<!-- https://checkstyle.org/config_javadoc.html#SummaryJavadoc -->
<module name="SummaryJavadoc"/>
<!-- https://checkstyle.org/config_annotation.html#SuppressWarningsHolder -->
<module name="SuppressWarningsHolder"/>
<!-- https://checkstyle.org/config_whitespace.html#TypecastParenPad -->
<module name="TypecastParenPad"/>
<!-- https://checkstyle.org/config_coding.html#UnnecessaryParentheses -->
<module name="UnnecessaryParentheses"/>
<!-- https://checkstyle.org/config_imports.html#UnusedImports -->
<module name="UnusedImports"/>
<!-- https://checkstyle.org/config_whitespace.html#WhitespaceAfter -->
<module name="WhitespaceAfter">
<property name="tokens" value="COMMA, SEMI, TYPECAST"/>
</module>
<!-- https://checkstyle.org/config_whitespace.html#WhitespaceAround -->
<module name="WhitespaceAround">
<property name="ignoreEnhancedForColon" value="false"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLambdas" value="true"/>
<property name="tokens" value="ASSIGN, COLON, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LCURLY, LE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
</module>
<!--
#####################
#### third-party ####
#####################
-->
<!-- https://checkstyle.org/config_javadoc.html#WriteTag -->
<!-- https://gitlab.com/stellardrift/stylecheck/-/blob/dev/src/main/java/ca/stellardrift/stylecheck/FilteringWriteTag.java -->
<module name="FilteringWriteTag">
<property name="tag" value="@since\s"/>
<property name="tagFormat" value="\d\.\d+\.\d+"/>
<property name="tagSeverity" value="ignore"/>
<property name="minimumScope" value="public"/>
<property name="tokens" value="INTERFACE_DEF, CLASS_DEF, ENUM_DEF, ANNOTATION_DEF, RECORD_DEF, METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, RECORD_DEF, COMPACT_CTOR_DEF"/>
</module>
<!-- what insane person willingly uses this rule? I'll never know. -->
<!-- &lt;!&ndash; https://gitlab.com/stellardrift/stylecheck/-/blob/dev/src/main/java/ca/stellardrift/stylecheck/StatementNoWhitespaceAfter.java &ndash;&gt;-->
<!-- <module name="StatementNoWhitespaceAfter">-->
<!-- <property name="tokens" value="LITERAL_CATCH, LITERAL_FOR, LITERAL_IF, LITERAL_TRY, LITERAL_WHILE"/>-->
<!-- </module>-->
</module>
</module>
+5 -2
View File
@@ -2,7 +2,7 @@
<!-- MIT License-->
<!-- Copyright (c) 2017-2020 KyoriPowered-->
<!-- Copyright (c) 2017-2021 KyoriPowered-->
<!-- Permission is hereby granted, free of charge, to any person obtaining a copy-->
<!-- of this software and associated documentation files (the "Software"), to deal-->
@@ -27,5 +27,8 @@
"http://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<!-- add any necessary suppressions here -->
<suppress files="src[\\/]test[\\/]java[\\/].*" checks="RequireExplicitVisibilityModifier"/>
<suppress files="src[\\/]main[\\/]java[\\/]net[\\/]draycia[\\/]carbon[\\/](bukkit|sponge|common)[\\/].*" checks="FilteringWriteTag" />
<suppress files="src[\\/]main[\\/]java[\\/]net[\\/]draycia[\\/]carbon[\\/](bukkit|sponge|common)[\\/].*" checks="MissingJavadocMethod" />
<suppress files="src[\\/]main[\\/]java[\\/]net[\\/]draycia[\\/]carbon[\\/](bukkit|sponge|common)[\\/].*" checks="MissingJavadocPackage" />
<suppress files="src[\\/]main[\\/]java[\\/]net[\\/]draycia[\\/]carbon[\\/](bukkit|sponge|common)[\\/].*" checks="MissingJavadocType" />
</suppressions>
@@ -1,16 +1,45 @@
package net.draycia.carbon.api;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* The main plugin interface.<br>
* Instances may be obtained through {@link CarbonChatProvider#carbonChat()}.
*
* @since 1.0.0
*/
public interface CarbonChat {
/**
* The plugin's logger.<br>
* All messages will be logged through this.
*
* @return the plugin's logger
*
* @since 2.0.0
*/
@NonNull Logger logger();
/**
* The event handler, used for listening to and emitting events.
*
* @return the event handler
*
* @since 2.0.0
*/
@NonNull CarbonEventHandler eventHandler();
/**
* The user manager, used for loading and obtaining {@link CarbonPlayer CarbonPlayers}.
*
* @return the user manager
*
* @since 2.0.0
*/
@NonNull UserManager userManager();
}
@@ -3,6 +3,11 @@ package net.draycia.carbon.api;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Static accessor for the {@link CarbonChat} class.
*
* @since 1.0.0
*/
public final class CarbonChatProvider {
private CarbonChatProvider() {
@@ -11,10 +16,24 @@ public final class CarbonChatProvider {
private static @Nullable CarbonChat instance;
/**
* Registers the {@link CarbonChat} implementation.
*
* @param carbonChat the carbon implementation
*
* @since 1.0.0
*/
public static void register(final @NonNull CarbonChat carbonChat) {
CarbonChatProvider.instance = carbonChat;
}
/**
* Gets the currently registered {@link CarbonChat} implementation.
*
* @return the registered carbon implementation
*
* @since 1.0.0
*/
public static @NonNull CarbonChat carbonChat() {
if (CarbonChatProvider.instance == null) {
throw new IllegalStateException("CarbonChat not initialized!"); // LuckPerms design go brrrr
@@ -4,6 +4,8 @@ import net.kyori.event.Cancellable;
/**
* Represents a {@link CarbonEvent} that's cancellable.
*
* @since 2.0.0
*/
public abstract class CancellableCarbonEvent extends Cancellable.Impl implements CarbonEvent {
@@ -11,6 +11,8 @@ import static net.kyori.adventure.text.Component.translatable;
/**
* {@link CancellableCarbonEvent} that's called when chat components are rendered for online players.
*
* @since 2.0.0
*/
public class CarbonChatEvent extends CancellableCarbonEvent {
@@ -25,6 +27,15 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
private final @NonNull List<@NonNull CarbonPlayer> recipients;
/**
* {@link CancellableCarbonEvent} that's called when chat components are rendered for online players.
*
* @param sender the sender of the message
* @param originalMessage the original message that was sent
* @param recipients the recipients of the message
*
* @since 2.0.0
*/
public CarbonChatEvent(
final @NonNull CarbonPlayer sender,
final @NonNull Component originalMessage,
@@ -39,7 +50,9 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
/**
* Set the {@link PlayerComponentRenderer} for the event.
*
* @param renderer new {@link PlayerComponentRenderer}
* @param renderer the renderer
*
* @since 2.0.0
*/
public void renderer(final @NonNull PlayerComponentRenderer renderer) {
this.renderer = renderer;
@@ -49,6 +62,8 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
* Get the renderer used to construct components for each player in recipients.
*
* @return The per-player component renderer.
*
* @since 2.0.0
*/
public @NonNull PlayerComponentRenderer renderer() {
return this.renderer;
@@ -58,6 +73,8 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
* Get the sender of the message.
*
* @return The message sender.
*
* @since 2.0.0
*/
public CarbonPlayer sender() {
return this.sender;
@@ -67,6 +84,8 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
* Get the original message that was sent.
*
* @return The original message.
*
* @since 2.0.0
*/
public Component originalMessage() {
return this.originalMessage;
@@ -76,6 +95,8 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
* Get the chat message that will be sent.
*
* @return The chat message.
*
* @since 2.0.0
*/
public Component message() {
return this.message;
@@ -85,6 +106,8 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
* Set the chat message that will be sent.
*
* @param message new message
*
* @since 2.0.0
*/
public void message(final @NonNull Component message) {
this.message = message;
@@ -95,6 +118,8 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
* List is mutable and players may be added/removed.
*
* @return The players that will receive this message.
*
* @since 2.0.0
*/
public @NonNull List<@NonNull CarbonPlayer> recipients() {
return this.recipients;
@@ -1,5 +1,10 @@
package net.draycia.carbon.api.events;
/**
* Interface to represent that an event belongs to carbon.
*
* @since 1.0.0
*/
public interface CarbonEvent {
}
@@ -7,16 +7,44 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.function.Consumer;
/**
* Event handler for listening to and emitting carbon events.
*
* @since 1.0.0
*/
public final class CarbonEventHandler {
private final SimpleEventBus<CarbonEvent> eventBus = new SimpleEventBus<>(CarbonEvent.class);
public <T extends CarbonEvent> void register(final @NonNull Class<T> clazz, final @NonNull EventSubscriber<T> subscriber) {
this.eventBus.register(clazz, subscriber);
/**
* Registers a subscriber for the given event class.
*
* @param eventClass the class to listen for
* @param subscriber the subscriber that's executed when the event is emitted
* @param <T> the class to listen for
*
* @since 1.0.0
*/
public <T extends CarbonEvent> void register(final @NonNull Class<T> eventClass, final @NonNull EventSubscriber<T> subscriber) {
this.eventBus.register(eventClass, subscriber);
}
public <T extends CarbonEvent> void register(final @NonNull Class<T> clazz, final int priority, final boolean consumeCancelled, final @NonNull Consumer<T> consumer) {
this.eventBus.register(clazz, new EventSubscriber<>() {
/**
* Registers a subscriber for the given event class.<br>
* Includes extra values to control when the consumer is executed.
*
* @param eventClass the class to listen for
* @param priority the priority of the consumer
* @param consumeCancelled if the consumer should be executed if the event is cancelled early
* @param consumer the consumer that's executed when the event is emitted
* @param <T> the class to listen for
*
* @return the subscriber, so that it may be unregistered
*
* @since 2.0.0
*/
public <T extends CarbonEvent> EventSubscriber<T> register(final @NonNull Class<T> eventClass, final int priority, final boolean consumeCancelled, final @NonNull Consumer<T> consumer) {
final var subscriber = new EventSubscriber<T>() {
@Override
public int postOrder() {
return priority;
@@ -31,14 +59,36 @@ public final class CarbonEventHandler {
public void invoke(final @NonNull T event) {
consumer.accept(event);
}
});
};
this.eventBus.register(eventClass, subscriber);
return subscriber;
}
/**
* Unregisters the subscriber and prevents it from being executed.
*
* @param subscriber the subscriber
*
* @since 1.0.0
*/
public void unregister(final @NonNull EventSubscriber<? super CarbonEvent> subscriber) {
this.eventBus.unregister(subscriber);
}
public PostResult post(final @NonNull CarbonEvent event) {
/**
* Emits the supplied event and returns its result.<br>
* Events are modified in place, so care should be taken to keep a reference to
* the event while it's being emitted.
*
* @param event the event to be emitted
*
* @return the result
*
* @since 2.0.0
*/
public PostResult emit(final @NonNull CarbonEvent event) {
return this.eventBus.post(event);
}
@@ -8,31 +8,57 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.UUID;
/**
* Generic abstraction for players.
*
* @since 2.0.0
*/
public interface CarbonPlayer extends Audience, Identified {
/**
* Gets the player's username.
*
* @return The player's username.
* @return the player's username
*
* @since 2.0.0
*/
@NonNull String username();
/**
* Gets the player's display name, shown in places like chat and tab menu.
*
* @return The player's display name.
* @return the player's display name
*
* @since 2.0.0
*/
@NonNull Component displayName();
/**
* Sets the player's display name.<br>
* Setting null is equivalent to setting the display name to the username.
*
* @param displayName the new display name
*
* @since 2.0.0
*/
void displayName(final @Nullable Component displayName);
/**
* Gets the player's UUID.
* The player's UUID, often used for identification purposes.
*
* @return The player's UUID.
* @return the player's UUID
*
* @since 2.0.0
*/
@NonNull UUID uuid();
/**
* Creates a {@link Component} with a content and item hover given the player's actively held item.
*
* @return the player's held item as an item hover component
*
* @since 2.0.0
*/
@NonNull Component createItemHoverComponent();
}
@@ -5,6 +5,11 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.UUID;
/**
* Manager used to load and obtain {@link CarbonPlayer CarbonPlayers}.
*
* @since 2.0.0
*/
public interface UserManager {
/**
@@ -13,6 +18,8 @@ public interface UserManager {
* @param uuid The player's UUID.
*
* @return The {@link CarbonPlayer}, or null if the player doesn't exist.
*
* @since 2.0.0
*/
@Nullable CarbonPlayer carbonPlayer(final @NonNull UUID uuid);
@@ -22,6 +29,8 @@ public interface UserManager {
* @param username The player's username.
*
* @return The {@link CarbonPlayer}, or null if the player doesn't exist.
*
* @since 2.0.0
*/
@Nullable CarbonPlayer carbonPlayer(final @NonNull String username);
@@ -10,12 +10,27 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.regex.Pattern;
/**
* Basic color related utilities.
*
* @since 1.0.0
*/
public final class ColorUtils {
private ColorUtils() {
}
/**
* Parses the input into a color.<br>
* Supports named colors, legacy, and hex inputs.
*
* @param input the color input
*
* @return the color
*
* @since 1.0.0
*/
public static @Nullable TextColor parseColor(@NonNull String input) {
if (input.isEmpty()) {
return NamedTextColor.WHITE;
@@ -44,7 +59,16 @@ public final class ColorUtils {
private static final @NonNull String hexReplacement = "<#$1$2$3$4$5$6>";
public static @NonNull String translateAlternateColors(final @NonNull String input) {
/**
* Converts the input legacy, legacy rgb, and alternate color formats to MiniMessage color tags.
*
* @param input the message to convert
*
* @return the converted message
*
* @since 1.0.0
*/
public static @NonNull String legacyToMiniMessage(final @NonNull String input) {
String output = input;
// Legacy RGB
@@ -4,10 +4,12 @@ import net.kyori.registry.DefaultedRegistryGetter;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* An extension of the DefaultedRegistryGetter that declares a defaultValue method
* An extension of the DefaultedRegistryGetter that declares a defaultValue method.
*
* @param <K> the key type
* @param <V> the value type
*
* @since 1.0.0
*/
public interface DefaultedKeyValueRegistry<K, V> extends DefaultedRegistryGetter<K, V> {
@@ -15,6 +17,8 @@ public interface DefaultedKeyValueRegistry<K, V> extends DefaultedRegistryGetter
* Gets the default value.
*
* @return the default value
*
* @since 1.0.0
*/
@NonNull V defaultValue();
@@ -5,6 +5,11 @@ import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Renderer used to construct chat components on a per-player basis.
*
* @since 2.0.0
*/
@FunctionalInterface
public interface PlayerComponentRenderer {
@@ -16,7 +21,9 @@ public interface PlayerComponentRenderer {
* @param message The message being sent.
*
* @return The component to be shown to the recipient,
* or null if the recipient should not receive the message.
* or null if the recipient should not receive the message.
*
* @since 2.0.0
*/
@Nullable
Component render(final @NonNull CarbonPlayer sender,
@@ -45,7 +45,7 @@ public final class BukkitChatListener implements Listener {
}
final var chatEvent = new CarbonChatEvent(player, event.message(), recipients);
final var result = this.carbonChat.eventHandler().post(chatEvent);
final var result = this.carbonChat.eventHandler().emit(chatEvent);
if (result.wasSuccessful()) {
// TODO: send to channels
+1 -1
View File
@@ -1,5 +1,5 @@
# Project Properties
projectVersion=1.0.0-SNAPSHOT
projectVersion=2.0.0-SNAPSHOT
# Gradle Properties
org.gradle.caching=true