Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b034e2ec64
|
||
|
|
a6652f6b83
|
||
|
|
8c66bcd408 | ||
|
|
2d47e73d3b | ||
|
|
f500c9fb8f | ||
|
|
922079cc7d | ||
|
|
798946390b | ||
|
|
743a149f3b | ||
|
|
316945b30f | ||
|
|
c8bf42463c | ||
|
|
a9bf505028 | ||
|
|
60bfb21444 | ||
|
|
fb13022642 | ||
|
|
1bbf3abd9a | ||
|
|
1967d9802f | ||
|
|
6b3d7aeab6 | ||
|
|
267c0426fe | ||
|
|
c3d5afa680 | ||
|
|
2009684fb5 | ||
|
|
56202f3f26 | ||
|
|
f2be2062e5 | ||
|
|
4cbe7d4bf9 | ||
|
|
fd20b5e583 | ||
|
|
e495e76a2d | ||
|
|
a37e7d8b7c | ||
|
|
b97ebcbbd6 | ||
|
|
2abf0c1eba | ||
|
|
80df7d0500 | ||
|
|
b7318a1ac8 | ||
|
|
b5e5848bd9 | ||
|
|
22064b8576 | ||
|
|
aac6cab5f6 | ||
|
|
7197cf9100 | ||
|
|
b3c448136d | ||
|
|
25ad706ebf | ||
|
|
3c04370488 | ||
|
|
5a3c52481a | ||
|
|
2eb0ba1e98 | ||
|
|
b38e08daa0 | ||
|
|
3c61a2d24b | ||
|
|
611772f4bb | ||
|
|
118cef163a | ||
|
|
d17e4af825 | ||
|
|
19a21d988f | ||
|
|
0cd04574f9 | ||
|
|
5acc5d285d | ||
|
|
3d9e90d7bf | ||
|
|
c39cad4017 | ||
|
|
9c9c67776b | ||
|
|
2858de84ae | ||
|
|
64b023fad7 | ||
|
|
f59de86c5e | ||
|
|
0f1c69f8b2 | ||
|
|
f8deb9b7fb | ||
|
|
8428e2b124 | ||
|
|
8f91a1b445 | ||
|
|
0ca1f8f19d | ||
|
|
2fd3d41cbd | ||
|
|
ce201ba89e | ||
|
|
e33135d3c6 | ||
|
|
5f6e2789e2 | ||
|
|
add32b31e7 | ||
|
|
b2b2801907 | ||
|
|
c919c40a59 | ||
|
|
b3cc4bce5c | ||
|
|
6fdf75dd3d | ||
|
|
a8c2b0f23e | ||
|
|
0ee99d90f2 | ||
|
|
6623a5928e | ||
|
|
6532c03706 | ||
|
|
0bf3bfba7f | ||
|
|
f7094e0a77 | ||
|
|
563da7f255 | ||
|
|
51e599838d | ||
|
|
e4970016e4 | ||
|
|
2a04d0b2c8 | ||
|
|
f8c6c2db6f | ||
|
|
9e25b68d00 | ||
|
|
96b7d12743 | ||
|
|
328ad6cd39 | ||
|
|
c0ee968e5b | ||
|
|
bc4d1e3cdd | ||
|
|
2626ed4551 | ||
|
|
a1f51db093 | ||
|
|
59ab61825b | ||
|
|
5d7f79ce8a | ||
|
|
a5145384f6 | ||
|
|
fba4066522 | ||
|
|
3c9261a92d | ||
|
|
ab409537ac | ||
|
|
98a5bba407 | ||
|
|
87bec5315b | ||
|
|
bf9d92150c | ||
|
|
4cad4d461b | ||
|
|
fc7b78f7a8 | ||
|
|
15cffc2d71 | ||
|
|
28cb91a40c | ||
|
|
4ab6567fd2 | ||
|
|
bdac395c2d | ||
|
|
ffb475f529 | ||
|
|
d690104a9e | ||
|
|
efa0c69840 | ||
|
|
369e387a39 | ||
|
|
2f98e67a93 | ||
|
|
e2894e211c | ||
|
|
58ff03aa95 | ||
|
|
4155249878 | ||
|
|
de0936c5d2 | ||
|
|
a8e5e910ee | ||
|
|
0d48b46621 | ||
|
|
2a18bc156d | ||
|
|
0dd650dacb | ||
|
|
624a97346d | ||
|
|
3d4fdc1f53 | ||
|
|
286f72f746 | ||
|
|
0cc8d9a98d | ||
|
|
80ae413c9d | ||
|
|
1a2ba16194 | ||
|
|
8c0a9b6811 | ||
|
|
310e8e7e7a | ||
|
|
45604e6bb3 | ||
|
|
ec8d81144b | ||
|
|
48c1c09d79 | ||
|
|
df89471fdd | ||
|
|
d2e0bba539 | ||
|
|
e715f3bb57 | ||
|
|
bd774480b3 | ||
|
|
d91ea43aa8 | ||
|
|
3bf3796ce2 | ||
|
|
34e819abf4 | ||
|
|
799dd82b4f | ||
|
|
67d4a12546 | ||
|
|
06543a2c45 | ||
|
|
acf9056f5b | ||
|
|
ae3fefb54d | ||
|
|
bcfe67fc6f | ||
|
|
10775836cb | ||
|
|
3a07128bd0 | ||
|
|
336d613274 | ||
|
|
a742fd9b62 | ||
|
|
577a77951a | ||
|
|
f8456bec5c | ||
|
|
b086550eae | ||
|
|
f512ca6174 | ||
|
|
82b3a35a9e | ||
|
|
5f4e8efa45 | ||
|
|
22a47511a2 | ||
|
|
972ac8fcc5 | ||
|
|
c7f2d5f33b | ||
|
|
2bc4a4caac | ||
|
|
3577d67820 | ||
|
|
9392601232 | ||
|
|
e4071d390c | ||
|
|
c4ca735e8b | ||
|
|
42ccd182b0 | ||
|
|
99e7954612 | ||
|
|
bcf2589eb0 | ||
|
|
fe41b21d9b | ||
|
|
cbbe201710 | ||
|
|
30d58fc0f9 | ||
|
|
067ec4ea65 | ||
|
|
22f805f4ab | ||
|
|
ed21f45573 | ||
|
|
41b1fdffe3 | ||
|
|
142f7a34f7 | ||
|
|
ed7fe3591b | ||
|
|
fa67cd3538 | ||
|
|
615fce3cd6 | ||
|
|
faccf19535 | ||
|
|
e50953c9fb | ||
|
|
5f2df1debd | ||
|
|
0c90ef0886 | ||
|
|
9bfd73e862 | ||
|
|
ec74878a1b | ||
|
|
502a775a41 | ||
|
|
245596426e | ||
|
|
996fd0f7d2 | ||
|
|
4713809a27 | ||
|
|
259a1e784e | ||
|
|
793d3d7736 | ||
|
|
49f86cc4ef | ||
|
|
6d70e82fbe | ||
|
|
ffe1f389e2 | ||
|
|
2c709d3dc7 | ||
|
|
5fe30bf8f9 | ||
|
|
196e6d8f00 | ||
|
|
1465423927 | ||
|
|
4b61e91220 | ||
|
|
09c590c873 | ||
|
|
57f3de39a2 | ||
|
|
f472736b32 | ||
|
|
27fbefdd9c | ||
|
|
454439a10c | ||
|
|
eebe13ae06 | ||
|
|
8b36863244 | ||
|
|
0b89b1fbf3 | ||
|
|
34ece94cbb | ||
|
|
880757cd09 | ||
|
|
dbcbb9e48e | ||
|
|
9f31ba4406 | ||
|
|
9d6d7feae0 | ||
|
|
ed6595ee0d | ||
|
|
a462f0b96e | ||
|
|
af4f0c78f1 | ||
|
|
7ef0ada06a | ||
|
|
fedae0ab23 | ||
|
|
157bc7b767 | ||
|
|
71f653122a | ||
|
|
b44070bdb0 | ||
|
|
ae5ab6a95b | ||
|
|
73ee4f393b | ||
|
|
ff4a1da49c | ||
|
|
725e5c8d2b | ||
|
|
5d644c326a | ||
|
|
09683f06ce | ||
|
|
c92c718ced | ||
|
|
e468600d83 | ||
|
|
101915290e | ||
|
|
b0c8c7a11d | ||
|
|
5bac39d149 | ||
|
|
37dd141af4 | ||
|
|
d348ee6b1d | ||
|
|
b1336df817 | ||
|
|
8e9c8aac5f | ||
|
|
fdfe651c02 | ||
|
|
c133e0452b | ||
|
|
93effdf83a | ||
|
|
186f174572 | ||
|
|
2b20b4b786 | ||
|
|
966943c161 | ||
|
|
04346d582d | ||
|
|
d00825bed9 | ||
|
|
2fbbc9c0e3 | ||
|
|
a1f01f959b | ||
|
|
c97d8ecea6 | ||
|
|
43b01fe833 | ||
|
|
b5667f75e5 | ||
|
|
f695835748 | ||
|
|
807fac6e71 | ||
|
|
31179943f7 | ||
|
|
a847dc5dd8 | ||
|
|
77f3ccf734 | ||
|
|
541b6bb623 | ||
|
|
454827731f | ||
|
|
bbb65c2638 | ||
|
|
a7f4161551 | ||
|
|
e08ffee2f9 | ||
|
|
93ae27770e | ||
|
|
b6c39163b7 | ||
|
|
8f9697c0a7 | ||
|
|
81adaf4e1a | ||
|
|
9093ebfecd | ||
|
|
76552f52a7 | ||
|
|
d17a1f7948 | ||
|
|
4c6ad898a1 | ||
|
|
e5c3a723a2 | ||
|
|
314d7b15b4 | ||
|
|
a66faf7251 | ||
|
|
0b948367e2 | ||
|
|
c2ee7e8f4b | ||
|
|
df665e5810 | ||
|
|
382229cbbf | ||
|
|
5257fa9e3b | ||
|
|
21b991b313 | ||
|
|
3720fec2f5 | ||
|
|
6fe11c729a | ||
|
|
c1e40216d4 | ||
|
|
b04de1b951 | ||
|
|
5673730693 | ||
|
|
60b83031ab | ||
|
|
2a750c289b | ||
|
|
0092a2b6b7 | ||
|
|
0847d15eef | ||
|
|
c9d2f3fdb7 | ||
|
|
db0ea2e656 | ||
|
|
7741523e56 | ||
|
|
f858f29d67 | ||
|
|
725855124c | ||
|
|
84f6f2b5d5 | ||
|
|
2e2fe64923 | ||
|
|
574eca67e2 | ||
|
|
6556e92e5e | ||
|
|
91a6973288 | ||
|
|
afd3de54ed | ||
|
|
b9c3f505eb | ||
|
|
bcc15def17 | ||
|
|
ef1b13d08f | ||
|
|
7edccb6ea4 | ||
|
|
c87f3c4321 | ||
|
|
4aff316770 | ||
|
|
702a6a7d66 |
No files matched your search
@@ -0,0 +1,287 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!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="fileExtensions" value="java, properties, xml"/>
|
||||
<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_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"/>
|
||||
|
||||
<!-- https://checkstyle.org/config_filters.html#SuppressWithPlainTextCommentFilter -->
|
||||
<module name="SuppressWithPlainTextCommentFilter"/>
|
||||
|
||||
<module name="TreeWalker">
|
||||
<!-- https://checkstyle.org/config_misc.html#ArrayTypeStyle -->
|
||||
<module name="ArrayTypeStyle"/>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- https://checkstyle.org/config_imports.html#AvoidStarImport -->
|
||||
<module name="AvoidStarImport"/>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- https://checkstyle.org/config_misc.html#CommentsIndentation -->
|
||||
<module name="CommentsIndentation"/>
|
||||
|
||||
<!-- https://checkstyle.org/config_imports.html#CustomImportOrder -->
|
||||
<module name="CustomImportOrder">
|
||||
<property name="customImportOrderRules" value="THIRD_PARTY_PACKAGE###STATIC"/>
|
||||
<property name="standardPackageRegExp" value="^$"/>
|
||||
<property name="sortImportsInGroupAlphabetically" value="true"/>
|
||||
</module>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- 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"/>
|
||||
|
||||
<!-- https://checkstyle.org/config_coding.html#NoFinalizer -->
|
||||
<module name="NoFinalizer"/>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- 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, LITERAL_IF, LITERAL_ELSE, LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, DO_WHILE"/>
|
||||
</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>
|
||||
-->
|
||||
|
||||
<!-- https://gitlab.com/stellardrift/stylecheck/-/blob/dev/src/main/java/ca/stellardrift/stylecheck/StatementNoWhitespaceAfter.java -->
|
||||
<!--
|
||||
<module name="StatementNoWhitespaceAfter">
|
||||
<property name="tokens" value="LITERAL_CATCH, LITERAL_FOR, LITERAL_IF, LITERAL_TRY, LITERAL_WHILE"/>
|
||||
</module>
|
||||
-->
|
||||
|
||||
</module>
|
||||
</module>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" "http://checkstyle.org/dtds/suppressions_1_2.dtd">
|
||||
<suppressions>
|
||||
<!-- This file is modified from KyoriPowered/adventure's suppressions.xml -->
|
||||
<!-- no javadoc on test classes -->
|
||||
<suppress files="src[\\/]test[\\/]java[\\/].*" checks="FilteringWriteTag"/>
|
||||
<suppress files="src[\\/]test[\\/]java[\\/].*" checks="MissingJavadoc.*"/>
|
||||
</suppressions>
|
||||
@@ -0,0 +1,8 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
max_line_length = off
|
||||
@@ -0,0 +1,7 @@
|
||||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# These are explicitly windows files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
||||
.gitea/CODEOWNERS linguist-detectable=false
|
||||
@@ -0,0 +1,3 @@
|
||||
# Pull requests request review from the eligible staff team(s).
|
||||
# One approval from either an Admin or Developer satisfies branch protection.
|
||||
* @trueog/Admins @trueog/Developers
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: Bug Report
|
||||
about: Report a bug
|
||||
title: "[Bug Report] This happens when another thing should have"
|
||||
labels: bug, unconfirmed
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Dig straight down
|
||||
2. Right click 5 times
|
||||
3. Craft a Netherite Hoe
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Server Software and Version:**
|
||||
- Vendor: [e.g. Paper, Tuinity, Velocity, BungeeCord, Waterfall, Fabric, Sponge]
|
||||
- Minecraft Version: [e.g. 1.15.2, 1.16.3]
|
||||
- Output of /version command: [e.g. This server is running Paper version git-Paper-53 (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT)]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1 @@
|
||||
blank_issues_enabled: false
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature Request
|
||||
about: Suggest a feature
|
||||
title: "[Feature Request] My Feature"
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -0,0 +1,20 @@
|
||||
name: "build"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "**" ]
|
||||
tags-ignore: [ "**" ]
|
||||
pull_request:
|
||||
release:
|
||||
types: [ released ]
|
||||
|
||||
jobs:
|
||||
call-build:
|
||||
uses: "jpenilla/actions/.github/workflows/shared-ci.yml@master"
|
||||
secrets: inherit
|
||||
with:
|
||||
artifacts-path: 'build/libs/*.jar'
|
||||
modrinth-publish: true
|
||||
hangar-publish: true
|
||||
loom: true
|
||||
jdk-version: 21
|
||||
+7
-1
@@ -18,7 +18,6 @@ out/
|
||||
*.ctxt
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
@@ -78,6 +77,7 @@ ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
*.hprof
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
@@ -111,3 +111,9 @@ buildNumber.properties
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
|
||||
# Ignore Gradle project-specific cache directory
|
||||
.gradle
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build/
|
||||
@@ -1,7 +1,30 @@
|
||||

|
||||

|
||||
|
||||
[](https://github.com/jpenilla/MiniMOTD/actions) [](https://github.com/jpenilla/MiniMOTD/releases)
|
||||
|
||||
> MiniMOTD is a basic MOTD Spigot plugin that is compatible with legacy Minecraft versions up through 1.16+ (Also supports BungeeCord). MiniMOTD gets it's name from [MiniMessage](https://github.com/KyoriPowered/adventure-text-minimessage), the library used to parse text in MiniMOTD.
|
||||
### MiniMOTD is a basic server list MOTD plugin/mod for Minecraft servers and proxies
|
||||
|
||||
- MiniMOTD supports RGB colors and gradients through [MiniMessage](https://github.com/KyoriPowered/adventure-text-minimessage), which is also where MiniMOTD gets it's name.
|
||||
- For more detailed info on formatting text, refer to the [MiniMessage docs](https://docs.adventure.kyori.net/minimessage.html).
|
||||
- RGB colors are automatically downsampled for outdated clients.
|
||||
- RGB colors are only able to be sent by proxies and 1.16+ servers, and can only be seen by 1.16+ clients.
|
||||
|
||||

|
||||
#### Server Platforms
|
||||
- [Paper](https://papermc.io/) / Spigot
|
||||
- MiniMOTD is compatible with Spigot, however many features will not work. It is recommended to use Paper for full compatibility.
|
||||
- [Sponge API 8](https://www.spongepowered.org/)
|
||||
- [Sponge API 7](https://www.spongepowered.org/)
|
||||
- [Fabric](https://fabricmc.net/) (requires [Fabric API](https://www.curseforge.com/minecraft/mc-mods/fabric-api))
|
||||
|
||||
#### Proxy Platforms
|
||||
- [Velocity](https://velocitypowered.com/)
|
||||
- [Waterfall](https://papermc.io/downloads#Waterfall) / Bungeecord
|
||||
|
||||
#### Downloads
|
||||
Downloads can be obtained from [GitHub releases](https://github.com/jpenilla/MiniMOTD/releases). There is a separate jar for each platform, as well as a universal jar for all platforms. Paper and Spigot share the same jar, as do Waterfall and Bungeecord.
|
||||
|
||||
#### Configuration
|
||||
See the [wiki](https://github.com/jpenilla/MiniMOTD/wiki) for configuration details
|
||||
|
||||
#### Screenshots
|
||||

|
||||
@@ -1,24 +0,0 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
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 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.
|
||||
|
||||
For more information, please refer to <https://unlicense.org>
|
||||
@@ -0,0 +1,3 @@
|
||||
plugins {
|
||||
id("minimotd.build-logic")
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
plugins {
|
||||
alias(libs.plugins.blossom)
|
||||
id("minimotd.base-conventions")
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
from(rootProject.file("license.txt")) {
|
||||
rename { "license_${rootProject.name.lowercase()}.txt" }
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(libs.configurateHocon)
|
||||
api(platform(libs.adventureBom))
|
||||
api(libs.adventureApi)
|
||||
api(libs.adventureTextSerializerPlain)
|
||||
api(libs.adventureTextSerializerGson) {
|
||||
exclude("com.google.code.gson", "gson")
|
||||
}
|
||||
api(libs.minimessage)
|
||||
compileOnlyApi(libs.slf4jApi)
|
||||
compileOnlyApi(libs.checkerQual)
|
||||
compileOnlyApi(libs.gson)
|
||||
testImplementation(libs.gson)
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
blossom {
|
||||
javaSources {
|
||||
property("PLUGIN_NAME", rootProject.name)
|
||||
property("PLUGIN_VERSION", project.version.toString())
|
||||
property("PLUGIN_WEBSITE", Constants.GITHUB_URL)
|
||||
property("GITHUB_USER", Constants.GITHUB_USER)
|
||||
property("GITHUB_REPO", Constants.GITHUB_REPO)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
public final class Constants {
|
||||
private Constants() {
|
||||
}
|
||||
|
||||
public static final class PluginMetadata {
|
||||
private PluginMetadata() {
|
||||
}
|
||||
|
||||
public static final String NAME = "{{ PLUGIN_NAME }}";
|
||||
public static final String VERSION = "{{ PLUGIN_VERSION }}";
|
||||
public static final String WEBSITE = "{{ PLUGIN_WEBSITE }}";
|
||||
public static final String GITHUB_USER = "{{ GITHUB_USER }}";
|
||||
public static final String GITHUB_REPO = "{{ GITHUB_REPO }}";
|
||||
public static final String GITHUB_REPO_URL = "https://github.com/" + GITHUB_USER + "/" + GITHUB_REPO;
|
||||
}
|
||||
|
||||
public static final int MINECRAFT_1_16_PROTOCOL_VERSION = 735;
|
||||
|
||||
public static final Component COMMAND_PREFIX = MiniMessage.miniMessage().deserialize("<white>[</white><gradient:#0047AB:#ADD8E6>" + PluginMetadata.NAME + "</gradient><white>]</white>");
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
import static net.kyori.adventure.text.Component.space;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.LinearComponents.linear;
|
||||
import static net.kyori.adventure.text.event.ClickEvent.openUrl;
|
||||
import static net.kyori.adventure.text.event.ClickEvent.runCommand;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GREEN;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.RED;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
import static net.kyori.adventure.text.format.TextColor.color;
|
||||
import static net.kyori.adventure.text.format.TextDecoration.STRIKETHROUGH;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CommandHandler {
|
||||
private final MiniMOTD<?> miniMOTD;
|
||||
|
||||
public CommandHandler(final MiniMOTD<?> miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
public void about(final Audience audience) {
|
||||
final Component header = miniMessage("<gradient:white:#007FFF:white> ").decorate(STRIKETHROUGH);
|
||||
Stream.of(
|
||||
header,
|
||||
text()
|
||||
.hoverEvent(miniMessage("<rainbow>click me!"))
|
||||
.clickEvent(openUrl(Constants.PluginMetadata.WEBSITE))
|
||||
.content(Constants.PluginMetadata.NAME)
|
||||
.color(WHITE)
|
||||
.append(space())
|
||||
.append(miniMessage("<gradient:#0047AB:#007FFF>" + Constants.PluginMetadata.VERSION))
|
||||
.build(),
|
||||
text()
|
||||
.content("By ")
|
||||
.color(GRAY)
|
||||
.append(text("jmp", WHITE))
|
||||
.build(),
|
||||
header
|
||||
).forEach(audience::sendMessage);
|
||||
}
|
||||
|
||||
public void reload(final Audience audience) {
|
||||
try {
|
||||
this.miniMOTD.reload();
|
||||
} catch (final Exception ex) {
|
||||
this.miniMOTD.logger().warn("Failed to reload MiniMOTD. Ensure there are no errors in your config files.", ex);
|
||||
audience.sendMessage(Component.textOfChildren(
|
||||
Constants.COMMAND_PREFIX,
|
||||
space(),
|
||||
text("Failed to reload MiniMOTD. Ensure there are no errors in your config files. See console for more details.", RED)
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
audience.sendMessage(Component.textOfChildren(
|
||||
Constants.COMMAND_PREFIX,
|
||||
space(),
|
||||
text("Done reloading configuration.", GREEN)
|
||||
));
|
||||
}
|
||||
|
||||
public void help(final Audience audience) {
|
||||
Stream.of(
|
||||
linear(Constants.COMMAND_PREFIX, space(), text(Constants.PluginMetadata.NAME + " command help", WHITE)),
|
||||
commandInfo("minimotd about", "Show information about MiniMOTD"),
|
||||
commandInfo("minimotd reload", "Reload MiniMOTD configuration files"),
|
||||
commandInfo("minimotd help", "Show this help menu")
|
||||
).forEach(audience::sendMessage);
|
||||
}
|
||||
|
||||
private static Component commandInfo(final String command, final String description) {
|
||||
return text()
|
||||
.content(" - ")
|
||||
.color(GRAY)
|
||||
.append(text('/', WHITE))
|
||||
.append(text(command, color(0x007FFF)))
|
||||
.append(text(':'))
|
||||
.append(space())
|
||||
.append(text(description, WHITE))
|
||||
.hoverEvent(text()
|
||||
.content("Click to execute '")
|
||||
.color(GRAY)
|
||||
.append(text("/" + command, WHITE))
|
||||
.append(text("'"))
|
||||
.build())
|
||||
.clickEvent(runCommand("/" + command))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Component miniMessage(final String message) {
|
||||
return MiniMessage.miniMessage().deserialize(message);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Executor {
|
||||
void execute(Audience audience);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Stream;
|
||||
import javax.imageio.ImageIO;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class IconManager<I> {
|
||||
private final Map<String, I> icons = new ConcurrentHashMap<>();
|
||||
private final MiniMOTD<I> miniMOTD;
|
||||
private final Path iconsDirectory;
|
||||
|
||||
public IconManager(final @NonNull MiniMOTD<I> miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
this.iconsDirectory = miniMOTD.dataDirectory().resolve("icons");
|
||||
this.loadIcons();
|
||||
}
|
||||
|
||||
public void loadIcons() {
|
||||
this.icons.clear();
|
||||
try {
|
||||
if (!Files.exists(this.iconsDirectory)) {
|
||||
Files.createDirectories(this.iconsDirectory);
|
||||
}
|
||||
try (final Stream<Path> stream = Files.list(this.iconsDirectory)) {
|
||||
stream.filter(Files::isRegularFile)
|
||||
.filter(file -> file.getFileName().toString().endsWith(".png"))
|
||||
.forEach(this::loadIcon);
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
throw new RuntimeException("Exception loading server icons", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadIcon(final @NonNull Path iconFile) {
|
||||
try (final InputStream inputStream = Files.newInputStream(iconFile)) {
|
||||
final BufferedImage bufferedImage = ImageIO.read(inputStream);
|
||||
if (bufferedImage.getHeight() == 64 && bufferedImage.getWidth() == 64) {
|
||||
final I newIcon = this.miniMOTD.platform().loadIcon(bufferedImage);
|
||||
this.icons.put(iconFile.getFileName().toString().split("\\.")[0], newIcon);
|
||||
} else {
|
||||
this.miniMOTD.logger().warn("Could not load {}: image must be 64x64px", iconFile.getFileName());
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
this.miniMOTD.logger().warn("Could not load {}: invalid image file", iconFile.getFileName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable I icon(final @Nullable String iconString) {
|
||||
if (this.icons.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (iconString == null || "random".equals(iconString)) {
|
||||
final int randomIndex = ThreadLocalRandom.current().nextInt(this.icons.size());
|
||||
final Iterator<I> iterator = this.icons.values().iterator();
|
||||
for (int i = 0; i < randomIndex; i++) {
|
||||
iterator.next();
|
||||
}
|
||||
return iterator.next();
|
||||
}
|
||||
|
||||
return this.icons.get(iconString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.slf4j.Logger;
|
||||
import xyz.jpenilla.minimotd.common.config.ConfigManager;
|
||||
import xyz.jpenilla.minimotd.common.config.MOTDConfig;
|
||||
|
||||
import static net.kyori.adventure.text.Component.newline;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class MiniMOTD<I> {
|
||||
private final ConfigManager configManager;
|
||||
private final IconManager<I> iconManager;
|
||||
private final MiniMOTDPlatform<I> platform;
|
||||
|
||||
public MiniMOTD(final MiniMOTDPlatform<I> platform) {
|
||||
this.platform = platform;
|
||||
|
||||
try {
|
||||
this.iconManager = new IconManager<>(this);
|
||||
this.configManager = new ConfigManager(this);
|
||||
this.configManager.loadConfigs();
|
||||
} catch (final Exception ex) {
|
||||
throw new IllegalStateException("Failed to load MiniMOTD. Ensure your config files are without errors.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public MiniMOTDPlatform<I> platform() {
|
||||
return this.platform;
|
||||
}
|
||||
|
||||
public Path dataDirectory() {
|
||||
return this.platform.dataDirectory();
|
||||
}
|
||||
|
||||
public IconManager<I> iconManager() {
|
||||
return this.iconManager;
|
||||
}
|
||||
|
||||
public Logger logger() {
|
||||
return this.platform.logger();
|
||||
}
|
||||
|
||||
public ConfigManager configManager() {
|
||||
return this.configManager;
|
||||
}
|
||||
|
||||
public PingResponse<I> createMOTD(final MOTDConfig config, final int onlinePlayers, final int maxPlayers) {
|
||||
final PingResponse.PlayerCount count = config.modifyPlayerCount(onlinePlayers, maxPlayers);
|
||||
final PingResponse.Builder<I> response = PingResponse.<I>builder()
|
||||
.playerCount(count)
|
||||
.disablePlayerListHover(config.disablePlayerListHover())
|
||||
.hidePlayerCount(config.hidePlayerCount());
|
||||
|
||||
@Nullable String iconString = null;
|
||||
if (config.motdEnabled()) {
|
||||
if (config.motds().isEmpty()) {
|
||||
throw new IllegalStateException("MOTD is enabled, but there are no MOTDs in the config file?");
|
||||
}
|
||||
final int index = config.motds().size() == 1 ? 0 : ThreadLocalRandom.current().nextInt(config.motds().size());
|
||||
final MOTDConfig.MOTD motdConfig = config.motds().get(index);
|
||||
final Component motd = Component.textOfChildren(
|
||||
parse(motdConfig.line1(), count),
|
||||
newline(),
|
||||
parse(motdConfig.line2(), count)
|
||||
);
|
||||
response.motd(motd);
|
||||
iconString = motdConfig.icon();
|
||||
}
|
||||
|
||||
if (config.iconEnabled()) {
|
||||
response.icon(this.iconManager().icon(iconString));
|
||||
}
|
||||
|
||||
return response.build();
|
||||
}
|
||||
|
||||
private static Component parse(final String input, final PingResponse.PlayerCount count) {
|
||||
final String online = Integer.toString(count.onlinePlayers());
|
||||
final String max = Integer.toString(count.maxPlayers());
|
||||
return MiniMessage.miniMessage().deserialize(
|
||||
replacePlayerCount(input, online, max),
|
||||
TagResolver.resolver(Placeholder.unparsed("online_players", online), Placeholder.unparsed("max_players", max))
|
||||
);
|
||||
}
|
||||
|
||||
private static String replacePlayerCount(final String input, final String online, final String max) {
|
||||
return input.replace("{onlinePlayers}", online).replace("{maxPlayers}", max);
|
||||
}
|
||||
|
||||
public synchronized void reload() {
|
||||
this.iconManager.loadIcons();
|
||||
this.configManager.loadConfigs();
|
||||
this.platform.onReload();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.file.Path;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public interface MiniMOTDPlatform<I> {
|
||||
@NonNull Path dataDirectory();
|
||||
|
||||
@NonNull Logger logger();
|
||||
|
||||
@NonNull I loadIcon(@NonNull BufferedImage image) throws Exception;
|
||||
|
||||
default void onReload() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntConsumer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class PingResponse<I> {
|
||||
private final @Nullable I icon;
|
||||
private final @Nullable Component motd;
|
||||
private final PlayerCount playerCount;
|
||||
private final boolean hidePlayerCount;
|
||||
private final boolean disablePlayerListHover;
|
||||
|
||||
private PingResponse(
|
||||
final @Nullable I icon,
|
||||
final @Nullable Component motd,
|
||||
final PlayerCount playerCount,
|
||||
final boolean hidePlayerCount,
|
||||
final boolean disablePlayerListHover
|
||||
) {
|
||||
this.icon = icon;
|
||||
this.motd = motd;
|
||||
this.playerCount = playerCount;
|
||||
this.hidePlayerCount = hidePlayerCount;
|
||||
this.disablePlayerListHover = disablePlayerListHover;
|
||||
}
|
||||
|
||||
public @Nullable I icon() {
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* If {@link #icon()} is non-null, the provided {@link Consumer} will be called using
|
||||
* its return value. If {@link #icon()} is {@code null}, do nothing.
|
||||
*
|
||||
* @param iconConsumer icon consumer
|
||||
*/
|
||||
public void icon(final Consumer<I> iconConsumer) {
|
||||
if (this.icon != null) {
|
||||
iconConsumer.accept(this.icon);
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable Component motd() {
|
||||
return this.motd;
|
||||
}
|
||||
|
||||
/**
|
||||
* If {@link #motd()} is non-null, the provided {@link Consumer} will be called using
|
||||
* its return value. If {@link #motd()} is {@code null}, do nothing.
|
||||
*
|
||||
* @param motdConsumer motd consumer
|
||||
*/
|
||||
public void motd(final Consumer<Component> motdConsumer) {
|
||||
if (this.motd != null) {
|
||||
motdConsumer.accept(this.motd);
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerCount playerCount() {
|
||||
return this.playerCount;
|
||||
}
|
||||
|
||||
public boolean hidePlayerCount() {
|
||||
return this.hidePlayerCount;
|
||||
}
|
||||
|
||||
public boolean disablePlayerListHover() {
|
||||
return this.disablePlayerListHover;
|
||||
}
|
||||
|
||||
public Builder<I> toBuilder() {
|
||||
return new BuilderImpl<>(
|
||||
this.motd,
|
||||
this.icon,
|
||||
this.playerCount,
|
||||
this.hidePlayerCount,
|
||||
this.disablePlayerListHover
|
||||
);
|
||||
}
|
||||
|
||||
public static <I> Builder<I> builder() {
|
||||
return new BuilderImpl<>();
|
||||
}
|
||||
|
||||
public static final class PlayerCount {
|
||||
private final int onlinePlayers;
|
||||
private final int maxPlayers;
|
||||
|
||||
private PlayerCount(final int onlinePlayers, final int maxPlayers) {
|
||||
this.onlinePlayers = onlinePlayers;
|
||||
this.maxPlayers = maxPlayers;
|
||||
}
|
||||
|
||||
public int onlinePlayers() {
|
||||
return this.onlinePlayers;
|
||||
}
|
||||
|
||||
public int maxPlayers() {
|
||||
return this.maxPlayers;
|
||||
}
|
||||
|
||||
public void applyCount(final IntConsumer onlinePlayersSetter, final IntConsumer maxPlayersSetter) {
|
||||
onlinePlayersSetter.accept(this.onlinePlayers);
|
||||
maxPlayersSetter.accept(this.maxPlayers);
|
||||
}
|
||||
|
||||
public static PlayerCount playerCount(final int onlinePlayers, final int maxPlayers) {
|
||||
return new PlayerCount(onlinePlayers, maxPlayers);
|
||||
}
|
||||
}
|
||||
|
||||
public interface Builder<I> {
|
||||
Builder<I> motd(@Nullable Component motd);
|
||||
|
||||
Builder<I> icon(@Nullable I icon);
|
||||
|
||||
Builder<I> playerCount(PlayerCount playerCount);
|
||||
|
||||
Builder<I> hidePlayerCount(boolean hidePlayerCount);
|
||||
|
||||
Builder<I> disablePlayerListHover(boolean disablePlayerListHover);
|
||||
|
||||
PingResponse<I> build();
|
||||
}
|
||||
|
||||
private static final class BuilderImpl<I> implements Builder<I> {
|
||||
private @Nullable Component motd;
|
||||
private @Nullable I icon;
|
||||
private @Nullable PlayerCount playerCount;
|
||||
private boolean hidePlayerCount = false;
|
||||
private boolean disablePlayerListHover = false;
|
||||
|
||||
private BuilderImpl() {
|
||||
}
|
||||
|
||||
private BuilderImpl(
|
||||
final @Nullable Component motd,
|
||||
final @Nullable I icon,
|
||||
final @Nullable PlayerCount playerCount,
|
||||
final boolean hidePlayerCount,
|
||||
final boolean disablePlayerListHover
|
||||
) {
|
||||
this.motd = motd;
|
||||
this.icon = icon;
|
||||
this.playerCount = playerCount;
|
||||
this.hidePlayerCount = hidePlayerCount;
|
||||
this.disablePlayerListHover = disablePlayerListHover;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder<I> motd(final @Nullable Component motd) {
|
||||
this.motd = motd;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder<I> icon(final @Nullable I icon) {
|
||||
this.icon = icon;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder<I> playerCount(final PlayerCount playerCount) {
|
||||
this.playerCount = playerCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder<I> hidePlayerCount(final boolean hidePlayerCount) {
|
||||
this.hidePlayerCount = hidePlayerCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder<I> disablePlayerListHover(final boolean disablePlayerListHover) {
|
||||
this.disablePlayerListHover = disablePlayerListHover;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PingResponse<I> build() {
|
||||
requireNonNull(this.playerCount, "playerCount");
|
||||
return new PingResponse<>(
|
||||
this.icon,
|
||||
this.motd,
|
||||
this.playerCount,
|
||||
this.hidePlayerCount,
|
||||
this.disablePlayerListHover
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common.config;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.UnaryOperator;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationOptions;
|
||||
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMapper;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializerCollection;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class ConfigLoader<C> {
|
||||
private static final TypeSerializerCollection SERIALIZERS;
|
||||
|
||||
static {
|
||||
SERIALIZERS = TypeSerializerCollection.builder()
|
||||
.register(PlayerCountModifier.serializer())
|
||||
.build();
|
||||
}
|
||||
|
||||
private final HoconConfigurationLoader loader;
|
||||
private final ObjectMapper<C> mapper;
|
||||
private final List<Consumer<C>> postProcess;
|
||||
|
||||
public ConfigLoader(
|
||||
final Class<C> configClass,
|
||||
final Path configPath,
|
||||
final UnaryOperator<ConfigurationOptions> optionsModifier
|
||||
) {
|
||||
this.postProcess = this.findPostProcessors(configClass);
|
||||
this.loader = HoconConfigurationLoader.builder()
|
||||
.path(configPath)
|
||||
.defaultOptions(options ->
|
||||
optionsModifier.apply(options)
|
||||
.serializers(builder -> builder.registerAll(SERIALIZERS)))
|
||||
.build();
|
||||
try {
|
||||
this.mapper = ObjectMapper.factory().get(configClass);
|
||||
} catch (final SerializationException ex) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to initialize an object mapper for type: " + configClass.getSimpleName(),
|
||||
ex
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Consumer<C>> findPostProcessors(final Class<C> configClass) {
|
||||
final List<Consumer<C>> ret = new ArrayList<>();
|
||||
for (final Method method : configClass.getDeclaredMethods()) {
|
||||
if (method.getAnnotation(PostProcessor.class) == null) {
|
||||
continue;
|
||||
}
|
||||
ret.add(config -> {
|
||||
try {
|
||||
method.setAccessible(true);
|
||||
method.invoke(config);
|
||||
} catch (final ReflectiveOperationException ex) {
|
||||
throw new RuntimeException("Failed to invoke post processor method", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public ConfigLoader(
|
||||
final @NonNull Class<C> configClass,
|
||||
final @NonNull Path configPath
|
||||
) {
|
||||
this(configClass, configPath, options -> options);
|
||||
}
|
||||
|
||||
public @NonNull C load() throws ConfigurateException {
|
||||
final CommentedConfigurationNode node = this.loader.load();
|
||||
final C config = this.mapper.load(node);
|
||||
for (final Consumer<C> processor : this.postProcess) {
|
||||
processor.accept(config);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
public void save(final @NonNull C config) throws ConfigurateException {
|
||||
final CommentedConfigurationNode node = this.loader.createNode();
|
||||
this.mapper.save(config, node);
|
||||
this.loader.save(node);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.util.Pair;
|
||||
|
||||
import static xyz.jpenilla.minimotd.common.util.Pair.pair;
|
||||
|
||||
public final class ConfigManager {
|
||||
|
||||
private final MiniMOTD<?> miniMOTD;
|
||||
|
||||
private final ConfigLoader<MOTDConfig> mainConfigLoader;
|
||||
private MOTDConfig mainConfig;
|
||||
|
||||
private final ConfigLoader<PluginSettings> pluginSettingsLoader;
|
||||
private PluginSettings pluginSettings;
|
||||
|
||||
private final Map<String, MOTDConfig> extraConfigs = new HashMap<>();
|
||||
|
||||
public ConfigManager(final @NonNull MiniMOTD<?> miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
this.mainConfigLoader = new ConfigLoader<>(
|
||||
MOTDConfig.class,
|
||||
this.miniMOTD.dataDirectory().resolve("main.conf"),
|
||||
options -> options.header("MiniMOTD Main Configuration")
|
||||
);
|
||||
this.pluginSettingsLoader = new ConfigLoader<>(
|
||||
PluginSettings.class,
|
||||
this.miniMOTD.dataDirectory().resolve("plugin_settings.conf"),
|
||||
options -> options.header("MiniMOTD Plugin Configuration")
|
||||
);
|
||||
}
|
||||
|
||||
public void loadConfigs() {
|
||||
try {
|
||||
this.mainConfig = this.mainConfigLoader.load();
|
||||
this.mainConfigLoader.save(this.mainConfig);
|
||||
|
||||
this.pluginSettings = this.pluginSettingsLoader.load();
|
||||
this.pluginSettingsLoader.save(this.pluginSettings);
|
||||
} catch (final ConfigurateException e) {
|
||||
throw new IllegalStateException("Failed to load config", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadExtraConfigs() {
|
||||
this.extraConfigs.clear();
|
||||
final Path extraConfigsDir = this.miniMOTD.dataDirectory().resolve("extra-configs");
|
||||
try {
|
||||
if (!Files.exists(extraConfigsDir)) {
|
||||
Files.createDirectories(extraConfigsDir);
|
||||
this.createDefaultExtraConfigs(extraConfigsDir);
|
||||
}
|
||||
try (final Stream<Path> stream = Files.list(extraConfigsDir)) {
|
||||
for (final Path path : stream.collect(Collectors.toList())) {
|
||||
if (!path.toString().endsWith(".conf")) {
|
||||
continue;
|
||||
}
|
||||
final String name = path.getFileName().toString().replace(".conf", "");
|
||||
final ConfigLoader<MOTDConfig> loader = new ConfigLoader<>(
|
||||
MOTDConfig.class,
|
||||
path,
|
||||
options -> options.header(String.format("Extra MiniMOTD config '%s'", name))
|
||||
);
|
||||
final MOTDConfig config = loader.load();
|
||||
loader.save(config);
|
||||
this.extraConfigs.put(name, config);
|
||||
}
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
throw new IllegalStateException("Failed to load virtual host configs", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void createDefaultExtraConfigs(final @NonNull Path extraConfigsDir) throws ConfigurateException {
|
||||
final List<Pair<Path, MOTDConfig.MOTD>> defaults = Collections.unmodifiableList(Arrays.asList(
|
||||
pair(extraConfigsDir.resolve("skyblock.conf"), new MOTDConfig.MOTD("<green><italic>Skyblock</green>", "<bold><rainbow>MiniMOTD Skyblock Server")),
|
||||
pair(extraConfigsDir.resolve("survival.conf"), new MOTDConfig.MOTD("<gradient:blue:red>Survival Mode Hardcore", "<green><bold>MiniMOTD Survival Server"))
|
||||
));
|
||||
for (final Pair<Path, MOTDConfig.MOTD> pair : defaults) {
|
||||
final ConfigLoader<MOTDConfig> loader = new ConfigLoader<>(
|
||||
MOTDConfig.class,
|
||||
pair.left()
|
||||
);
|
||||
loader.save(new MOTDConfig(pair.right()));
|
||||
}
|
||||
}
|
||||
|
||||
public @NonNull MOTDConfig mainConfig() {
|
||||
if (this.mainConfig == null) {
|
||||
throw new IllegalStateException("Config has not yet been loaded");
|
||||
}
|
||||
return this.mainConfig;
|
||||
}
|
||||
|
||||
public @NonNull PluginSettings pluginSettings() {
|
||||
if (this.pluginSettings == null) {
|
||||
throw new IllegalStateException("Config has not yet been loaded");
|
||||
}
|
||||
return this.pluginSettings;
|
||||
}
|
||||
|
||||
public @NonNull MOTDConfig resolveConfig(final @Nullable InetSocketAddress address) {
|
||||
if (address == null) {
|
||||
return this.mainConfig();
|
||||
}
|
||||
final String configString = this.pluginSettings().proxySettings().findConfigStringForHost(address.getHostString(), address.getPort());
|
||||
|
||||
if (this.pluginSettings().proxySettings().virtualHostTestMode()) {
|
||||
this.miniMOTD.platform().logger().info("[virtual-host-debug] Virtual Host: '{}:{}', Selected Config: '{}'", address.getHostString(), address.getPort(), configString == null ? "default" : configString);
|
||||
}
|
||||
|
||||
if (configString == null) {
|
||||
return this.mainConfig();
|
||||
}
|
||||
return this.resolveConfig(configString);
|
||||
}
|
||||
|
||||
public @NonNull MOTDConfig resolveConfig(final @NonNull String name) {
|
||||
if ("default".equals(name)) {
|
||||
return this.mainConfig();
|
||||
}
|
||||
final MOTDConfig cfg = this.extraConfigs.get(name);
|
||||
if (cfg != null) {
|
||||
return cfg;
|
||||
}
|
||||
this.miniMOTD.logger().warn("Invalid extra-config name: '{}', falling back to main.conf", name);
|
||||
return this.mainConfig();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
import xyz.jpenilla.minimotd.common.PingResponse;
|
||||
|
||||
import static xyz.jpenilla.minimotd.common.PingResponse.PlayerCount.playerCount;
|
||||
|
||||
@ConfigSerializable
|
||||
public final class MOTDConfig {
|
||||
|
||||
public MOTDConfig() {
|
||||
this(
|
||||
new MOTD(),
|
||||
new MOTD("<blue>Another <bold><red>MOTD", "<italic><underlined><gradient:red:green>much wow")
|
||||
);
|
||||
}
|
||||
|
||||
public MOTDConfig(final @NonNull MOTD @NonNull ... defaults) {
|
||||
this.motds.addAll(Arrays.asList(defaults));
|
||||
}
|
||||
|
||||
@Comment("The list of MOTDs to display\n"
|
||||
+ "\n"
|
||||
+ " - Supported placeholders: <online_players>, <max_players>\n"
|
||||
+ " - Putting more than one will cause one to be randomly chosen each refresh")
|
||||
private final List<MOTD> motds = new ArrayList<>();
|
||||
|
||||
@Comment("Enable MOTD-related features")
|
||||
private boolean motdEnabled = true;
|
||||
|
||||
@Comment("Enable server list icon related features")
|
||||
private boolean iconEnabled = true;
|
||||
|
||||
private PlayerCountSettings playerCountSettings = new PlayerCountSettings();
|
||||
|
||||
@ConfigSerializable
|
||||
public static final class MOTD {
|
||||
|
||||
public MOTD() {
|
||||
}
|
||||
|
||||
public MOTD(final @NonNull String line1, final @NonNull String line2) {
|
||||
this.line1 = line1;
|
||||
this.line2 = line2;
|
||||
}
|
||||
|
||||
private String line1 = "<rainbow>MiniMOTD Default";
|
||||
|
||||
private String line2 = "MiniMessage <gradient:blue:red>Gradients";
|
||||
|
||||
@Comment("Set the icon to use with this MOTD\n"
|
||||
+ " Either use 'random' to randomly choose an icon, or use the name\n"
|
||||
+ " of a file in the icons folder (excluding the '.png' extension)\n"
|
||||
+ " ex: icon=\"myIconFile\"")
|
||||
private String icon = "random";
|
||||
|
||||
public @NonNull String line1() {
|
||||
return this.line1;
|
||||
}
|
||||
|
||||
public @NonNull String line2() {
|
||||
return this.line2;
|
||||
}
|
||||
|
||||
public @NonNull String icon() {
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public static final class PlayerCountSettings {
|
||||
|
||||
@Comment("Enable modification of the max player count")
|
||||
private boolean maxPlayersEnabled = true;
|
||||
|
||||
@Comment("Changes the Max Players value")
|
||||
private int maxPlayers = 69;
|
||||
|
||||
@Comment("Setting this to true will disable the hover text showing online player usernames")
|
||||
private boolean disablePlayerListHover = false;
|
||||
|
||||
@Comment("Setting this to true will disable the player list hover (same as 'disable-player-list-hover'),\n"
|
||||
+ "but will also cause the player count to appear as '???'")
|
||||
private boolean hidePlayerCount = false;
|
||||
|
||||
@Comment("Settings for the fake player count feature")
|
||||
private FakePlayers fakePlayers = new FakePlayers();
|
||||
|
||||
@Comment("Changes the Max Players to be X more than the online players\n"
|
||||
+ "ex: x=3 -> 16/19 players online.")
|
||||
private JustXMore justXMoreSettings = new JustXMore();
|
||||
|
||||
@Comment("Should the displayed online player count be allowed to exceed the displayed maximum player count?\n"
|
||||
+ "If false, the online player count will be capped at the maximum player count")
|
||||
private boolean allowExceedingMaximum = false;
|
||||
|
||||
@Comment("The list of server names that affect player counts/listing.\n"
|
||||
+ "Only applicable when running the plugin on a proxy (Velocity or Waterfall/Bungeecord).\n"
|
||||
+ "When set to an empty list, the default count & list as determined by the proxy will be used.")
|
||||
private final List<String> servers = new ArrayList<>();
|
||||
|
||||
@ConfigSerializable
|
||||
public static final class JustXMore {
|
||||
|
||||
@Comment("Enable this feature")
|
||||
private boolean justXMoreEnabled = false;
|
||||
|
||||
private int xValue = 3;
|
||||
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public static final class FakePlayers {
|
||||
|
||||
@Comment("Enable fake player count feature")
|
||||
private boolean fakePlayersEnabled = false;
|
||||
|
||||
@Comment("Modes: add, constant, minimum, random, percent\n"
|
||||
+ "\n"
|
||||
+ " - add: This many fake players will be added\n"
|
||||
+ " ex: fake-players=\"3\"\n"
|
||||
+ " - constant: A constant value for the player count\n"
|
||||
+ " ex: fake-players=\"=42\"\n"
|
||||
+ " - minimum: The minimum bound of the player count\n"
|
||||
+ " ex: fake-players=\"7+\"\n"
|
||||
+ " - random: A random number of fake players in this range will be added\n"
|
||||
+ " ex: fake-players=\"3:6\"\n"
|
||||
+ " - percent: The player count will be inflated by this much, rounding up\n"
|
||||
+ " ex: fake-players=\"25%\"")
|
||||
private PlayerCountModifier fakePlayers = PlayerCountModifier.parse("25%");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<String> targetServers() {
|
||||
return this.playerCountSettings.servers;
|
||||
}
|
||||
|
||||
public boolean iconEnabled() {
|
||||
return this.iconEnabled;
|
||||
}
|
||||
|
||||
public @NonNull List<MOTD> motds() {
|
||||
return this.motds;
|
||||
}
|
||||
|
||||
public boolean motdEnabled() {
|
||||
return this.motdEnabled;
|
||||
}
|
||||
|
||||
public boolean disablePlayerListHover() {
|
||||
return this.playerCountSettings.disablePlayerListHover;
|
||||
}
|
||||
|
||||
public boolean hidePlayerCount() {
|
||||
return this.playerCountSettings.hidePlayerCount;
|
||||
}
|
||||
|
||||
private @NonNull PlayerCountModifier playerCountModifier() {
|
||||
return this.playerCountSettings.fakePlayers.fakePlayers;
|
||||
}
|
||||
|
||||
private int calculateOnlinePlayers(final int onlinePlayers) {
|
||||
if (this.playerCountSettings.fakePlayers.fakePlayersEnabled) {
|
||||
return this.playerCountModifier().apply(onlinePlayers);
|
||||
}
|
||||
return onlinePlayers;
|
||||
}
|
||||
|
||||
private int calculateMaxPlayers(final int onlinePlayers, final int maxPlayers) {
|
||||
if (this.playerCountSettings.maxPlayersEnabled) {
|
||||
if (this.playerCountSettings.justXMoreSettings.justXMoreEnabled) {
|
||||
return onlinePlayers + this.playerCountSettings.justXMoreSettings.xValue;
|
||||
}
|
||||
return this.playerCountSettings.maxPlayers;
|
||||
}
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
public PingResponse.@NonNull PlayerCount modifyPlayerCount(final int onlinePlayers, final int maxPlayers) {
|
||||
final int online = this.calculateOnlinePlayers(onlinePlayers);
|
||||
final int max = this.calculateMaxPlayers(online, maxPlayers);
|
||||
if (!this.playerCountSettings.allowExceedingMaximum) {
|
||||
return playerCount(Math.min(online, max), max);
|
||||
}
|
||||
return playerCount(online, max);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common.config;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.function.Predicate;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.serialize.ScalarSerializer;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import xyz.jpenilla.minimotd.common.util.Int2IntFunction;
|
||||
|
||||
public final class PlayerCountModifier implements Int2IntFunction {
|
||||
private final String input;
|
||||
private final Int2IntFunction function;
|
||||
|
||||
private PlayerCountModifier(final @NonNull String input, final @NonNull Int2IntFunction function) {
|
||||
this.input = input;
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int apply(final int actualPlayers) {
|
||||
return this.function.apply(actualPlayers);
|
||||
}
|
||||
|
||||
public @NonNull String input() {
|
||||
return this.input;
|
||||
}
|
||||
|
||||
public static @NonNull PlayerCountModifier parse(final @NonNull String input) {
|
||||
try {
|
||||
if (input.contains(":")) {
|
||||
return parseRandomModifier(input);
|
||||
} else if (input.contains("%")) {
|
||||
return parsePercentModifier(input);
|
||||
} else if (input.contains("=")) {
|
||||
return parseConstantModifier(input);
|
||||
} else if (input.contains("+")) {
|
||||
return parseMinimumModifier(input);
|
||||
} else {
|
||||
return parseAddModifier(input);
|
||||
}
|
||||
} catch (final NumberFormatException ex) {
|
||||
throw cannotParse(input, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static @NonNull PlayerCountModifier parseRandomModifier(final @NonNull String input) {
|
||||
final String[] fakePlayers = input.split(":");
|
||||
if (fakePlayers.length != 2) {
|
||||
throw cannotParse(input, null);
|
||||
}
|
||||
final int start = Integer.parseInt(fakePlayers[0]);
|
||||
final int end = Integer.parseInt(fakePlayers[1]);
|
||||
return new PlayerCountModifier(input, actual -> actual + ThreadLocalRandom.current().nextInt(start, end));
|
||||
}
|
||||
|
||||
private static @NonNull PlayerCountModifier parsePercentModifier(final @NonNull String input) {
|
||||
final double factor = 1.00D + Double.parseDouble(input.replace("%", "")) / 100.00D;
|
||||
return new PlayerCountModifier(input, actual -> (int) Math.ceil(factor * actual));
|
||||
}
|
||||
|
||||
private static @NonNull PlayerCountModifier parseConstantModifier(final @NonNull String input) {
|
||||
final int value = Integer.parseInt(input.replace("=", ""));
|
||||
return new PlayerCountModifier(input, actual -> value);
|
||||
}
|
||||
|
||||
private static @NonNull PlayerCountModifier parseMinimumModifier(final @NonNull String input) {
|
||||
final int minPlayers = Integer.parseInt(input.replace("+", ""));
|
||||
return new PlayerCountModifier(input, actual -> Math.max(minPlayers, actual));
|
||||
}
|
||||
|
||||
private static @NonNull PlayerCountModifier parseAddModifier(final @NonNull String input) {
|
||||
final int addedPlayers = Integer.parseInt(input);
|
||||
return new PlayerCountModifier(input, actual -> actual + addedPlayers);
|
||||
}
|
||||
|
||||
private static @NonNull IllegalArgumentException cannotParse(final @NonNull String input, final @Nullable Throwable cause) {
|
||||
return new IllegalArgumentException(String.format("Unable to parse a player count modifier from input string '%s'.", input), cause);
|
||||
}
|
||||
|
||||
public static @NonNull Serializer serializer() {
|
||||
return Serializer.INSTANCE;
|
||||
}
|
||||
|
||||
public static final class Serializer extends ScalarSerializer<PlayerCountModifier> {
|
||||
private static final Serializer INSTANCE = new Serializer();
|
||||
|
||||
private Serializer() {
|
||||
super(PlayerCountModifier.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerCountModifier deserialize(final @NonNull Type type, final @NonNull Object obj) throws SerializationException {
|
||||
try {
|
||||
return PlayerCountModifier.parse(obj.toString());
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
throw new SerializationException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object serialize(final @NonNull PlayerCountModifier item, final @NonNull Predicate<Class<?>> typeSupported) {
|
||||
return item.input();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common.config;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
|
||||
@ConfigSerializable
|
||||
public final class PluginSettings {
|
||||
|
||||
@Comment("Do you want the plugin to check for updates on GitHub at launch?\n"
|
||||
+ "https://github.com/jpenilla/MiniMOTD")
|
||||
private boolean updateChecker = true;
|
||||
|
||||
@Comment("Settings only applicable when running the plugin on a proxy (Velocity or Waterfall/Bungeecord)")
|
||||
private ProxySettings proxySettings = new ProxySettings();
|
||||
|
||||
@ConfigSerializable
|
||||
public static final class ProxySettings {
|
||||
|
||||
public ProxySettings() {
|
||||
this.virtualHostConfigs.put("minigames.example.com:25565", "default");
|
||||
this.virtualHostConfigs.put("survival.example.com:25565", "survival");
|
||||
this.virtualHostConfigs.put("skyblock.example.com:25565", "skyblock");
|
||||
}
|
||||
|
||||
public ProxySettings(final Map<String, String> virtualHostConfigs) {
|
||||
this.virtualHostConfigs.putAll(virtualHostConfigs);
|
||||
}
|
||||
|
||||
@Comment("Here you can assign configs in the 'extra-configs' folder to specific virtual hosts\n"
|
||||
+ "Either use the name of the config in 'extra-configs', or use \"default\" to use the configuration in main.conf\n"
|
||||
+ "\n"
|
||||
+ "Format is \"hostname:port\"=\"configName|default\"\n"
|
||||
+ "Parts of domains can be substituted for wildcards, i.e. \"*.mydomain.com:25565\". Wildcard-containing configs are\n"
|
||||
+ "checked in the order they are declared if there are no exact matches.")
|
||||
private final Map<String, String> virtualHostConfigs = new LinkedHashMap<>();
|
||||
|
||||
private transient @MonotonicNonNull Map<String[], String> splitVirtualHostConfigs;
|
||||
|
||||
@Comment("Set whether to enable virtual host testing mode.\n"
|
||||
+ "When enabled, MiniMOTD will print virtual host debug info to the console on each server ping.")
|
||||
private boolean virtualHostTestMode = false;
|
||||
|
||||
public boolean virtualHostTestMode() {
|
||||
return this.virtualHostTestMode;
|
||||
}
|
||||
|
||||
public @Nullable String findConfigStringForHost(@NonNull String host, final int port) {
|
||||
host = processTcpShieldHostname(host).toLowerCase(Locale.ENGLISH) + ':' + port;
|
||||
|
||||
final @Nullable String exactMatch = this.virtualHostConfigs.get(host);
|
||||
if (exactMatch != null) {
|
||||
return exactMatch;
|
||||
}
|
||||
|
||||
if (this.splitVirtualHostConfigs.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String[] splitHost = host.split("\\.");
|
||||
|
||||
configs:
|
||||
for (final Map.Entry<String[], String> e : this.splitVirtualHostConfigs.entrySet()) {
|
||||
final String[] splitKey = e.getKey();
|
||||
if (splitKey.length != splitHost.length) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < splitHost.length; i++) {
|
||||
final String keyPart = splitKey[i];
|
||||
if (!keyPart.equals(splitHost[i]) && !keyPart.equals("*")) {
|
||||
continue configs;
|
||||
}
|
||||
}
|
||||
return e.getValue();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String processTcpShieldHostname(final String hostname) {
|
||||
if (hostname.contains("///")) {
|
||||
final String[] split = hostname.split("///");
|
||||
if (split.length == 4) {
|
||||
// <actual hostname>///<user-ip>:<user-port>///<unix timestamp>///<signature>
|
||||
return split[0];
|
||||
}
|
||||
}
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void processVirtualHosts() {
|
||||
final Map<String, String> virtualHosts = new LinkedHashMap<>(this.virtualHostConfigs);
|
||||
this.virtualHostConfigs.clear();
|
||||
virtualHosts.forEach((host, config) -> this.virtualHostConfigs.put(host.toLowerCase(Locale.ENGLISH), config));
|
||||
|
||||
this.splitVirtualHostConfigs = new LinkedHashMap<>();
|
||||
this.virtualHostConfigs.forEach((host, config) -> {
|
||||
if (!host.contains("*")) {
|
||||
return;
|
||||
}
|
||||
this.splitVirtualHostConfigs.put(host.split("\\."), config);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public @NonNull ProxySettings proxySettings() {
|
||||
return this.proxySettings;
|
||||
}
|
||||
|
||||
public boolean updateChecker() {
|
||||
return this.updateChecker;
|
||||
}
|
||||
|
||||
@PostProcessor
|
||||
private void processVirtualHosts() {
|
||||
this.proxySettings.processVirtualHosts();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common.config;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface PostProcessor {
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common.util;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public interface ComponentColorDownsampler {
|
||||
static @NonNull ComponentColorDownsampler downsampler() {
|
||||
return ComponentColorDownsamplerImpl.INSTANCE;
|
||||
}
|
||||
|
||||
@NonNull Component downsample(@NonNull Component component);
|
||||
|
||||
final class ComponentColorDownsamplerImpl implements ComponentColorDownsampler {
|
||||
private static final ComponentColorDownsampler INSTANCE = new ComponentColorDownsamplerImpl();
|
||||
|
||||
private ComponentColorDownsamplerImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Component downsample(final @NonNull Component component) {
|
||||
return GsonComponentSerializer.gson().deserializeFromTree(
|
||||
GsonComponentSerializer.colorDownsamplingGson().serializeToTree(component)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common.util;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Int2IntFunction {
|
||||
int apply(int value);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common.util;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class Pair<L, R> {
|
||||
private final L left;
|
||||
private final R right;
|
||||
|
||||
private Pair(final @NonNull L left, final @NonNull R right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public @NonNull L left() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
public @NonNull R right() {
|
||||
return this.right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final @Nullable Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || this.getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Pair<?, ?> pair = (Pair<?, ?>) o;
|
||||
return this.left.equals(pair.left)
|
||||
&& this.right.equals(pair.right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.left, this.right);
|
||||
}
|
||||
|
||||
public static <L, R> @NonNull Pair<L, R> pair(final @NonNull L left, final @NonNull R right) {
|
||||
return new Pair<>(left, right);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common.util;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonParser;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import xyz.jpenilla.minimotd.common.Constants;
|
||||
|
||||
public final class UpdateChecker {
|
||||
private final JsonParser parser = new JsonParser();
|
||||
|
||||
public @NonNull List<String> checkVersion() {
|
||||
final JsonArray result;
|
||||
final String url = String.format("https://api.github.com/repos/%s/%s/releases", Constants.PluginMetadata.GITHUB_USER, Constants.PluginMetadata.GITHUB_REPO);
|
||||
try (final InputStream is = new URL(url).openStream(); InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
|
||||
result = this.parser.parse(reader).getAsJsonArray();
|
||||
} catch (final IOException ex) {
|
||||
return Collections.singletonList("Cannot look for updates: " + ex.getMessage());
|
||||
}
|
||||
final Map<String, String> versionMap = new LinkedHashMap<>();
|
||||
result.forEach(element -> versionMap.put(element.getAsJsonObject().get("tag_name").getAsString(), element.getAsJsonObject().get("html_url").getAsString()));
|
||||
final List<String> versionList = new LinkedList<>(versionMap.keySet());
|
||||
final String currentVersion = "v" + Constants.PluginMetadata.VERSION;
|
||||
if (versionList.get(0).equals(currentVersion)) {
|
||||
return Collections.emptyList(); // Up to date, do nothing
|
||||
}
|
||||
if (currentVersion.contains("SNAPSHOT")) {
|
||||
return Arrays.asList(
|
||||
"This server is running a development build of " + Constants.PluginMetadata.NAME + "! (" + currentVersion + ")",
|
||||
"The latest official release is " + versionList.get(0)
|
||||
);
|
||||
}
|
||||
final int versionsBehind = versionList.indexOf(currentVersion);
|
||||
return Arrays.asList(
|
||||
"There is an update available for " + Constants.PluginMetadata.NAME + "!",
|
||||
"This server is running version " + currentVersion + ", which is " + (versionsBehind == -1 ? "UNKNOWN" : versionsBehind) + " versions outdated.",
|
||||
"Download the latest version, " + versionList.get(0) + " from GitHub at the link below:",
|
||||
versionMap.get(versionList.get(0))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.jpenilla.minimotd.common.config.PluginSettings;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
class VirtualHostMatchingTest {
|
||||
@Test
|
||||
void testMatching() {
|
||||
final Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("abc.xyz:25565", "1");
|
||||
map.put("subdomain.abc.xyz:25565", "2");
|
||||
map.put("*.abc.xyz:25565", "3");
|
||||
map.put("abc.*.*.domain.com:25565", "4");
|
||||
map.put("*.*.*.domain.com:25565", "5");
|
||||
final PluginSettings.ProxySettings proxySettings = new PluginSettings.ProxySettings(map);
|
||||
proxySettings.processVirtualHosts();
|
||||
|
||||
assertEquals("1", proxySettings.findConfigStringForHost("abc.xyz", 25565));
|
||||
assertEquals("2", proxySettings.findConfigStringForHost("subdomain.abc.xyz", 25565));
|
||||
assertEquals("3", proxySettings.findConfigStringForHost("other_subdomain.abc.xyz", 25565));
|
||||
assertEquals("4", proxySettings.findConfigStringForHost("abc.2.3.domain.com", 25565));
|
||||
assertEquals("5", proxySettings.findConfigStringForHost("1.2.3.domain.com", 25565));
|
||||
// TCPShield-mangled hostname
|
||||
assertEquals("5", proxySettings.findConfigStringForHost("1.2.3.domain.com///127.0.0.1:25565///1681016669///MGQCMAW5X13a9cF5ysnWdrBLovH4wfVu60l7eBUwWsCI8vw0cuZ9aj+UM7+y1wC//qGHngIwRsCke7eCpO99HTHOVdvZKjx9G0E51ALqRFGWH7kxMhVKYNF2IfMaT1FfbS0/D0du", 25565));
|
||||
assertNull(proxySettings.findConfigStringForHost("subdomain.subdomain.abc.xyz", 25565));
|
||||
assertNull(proxySettings.findConfigStringForHost("google.com", 25565));
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.common.util;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.nearestTo;
|
||||
import static net.kyori.adventure.text.format.TextColor.color;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ComponentColorDownsamplerTest {
|
||||
private static final TextColor GREEN = color(0x04E762);
|
||||
private static final TextColor ORANGE_YELLOW = color(0xF5B700);
|
||||
private static final TextColor PINK = color(0xDC0073);
|
||||
private static final TextColor BLUE = color(0x008BF8);
|
||||
private static final TextColor LIME_GREEN = color(0x89FC00);
|
||||
|
||||
@Test
|
||||
void testColorDownsampling() {
|
||||
final Component fullColor = Component.textOfChildren(
|
||||
text("Green ", GREEN),
|
||||
text("Orange Yellow ", ORANGE_YELLOW),
|
||||
text("Pink ", PINK),
|
||||
text("Blue ", BLUE),
|
||||
text("Lime Green", LIME_GREEN)
|
||||
);
|
||||
final Component expectedDownsample = Component.textOfChildren(
|
||||
text("Green ", nearestTo(GREEN)),
|
||||
text("Orange Yellow ", nearestTo(ORANGE_YELLOW)),
|
||||
text("Pink ", nearestTo(PINK)),
|
||||
text("Blue ", nearestTo(BLUE)),
|
||||
text("Lime Green", nearestTo(LIME_GREEN))
|
||||
);
|
||||
final Component actualDownsample = ComponentColorDownsampler.downsampler().downsample(fullColor);
|
||||
|
||||
assertEquals(expectedDownsample, actualDownsample);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
plugins {
|
||||
id("minimotd.platform-conventions")
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
archiveClassifier.set("empty")
|
||||
}
|
||||
|
||||
val platforms = setOf(
|
||||
projects.minimotdBukkit,
|
||||
projects.minimotdBungeecord,
|
||||
).map { it.dependencyProject }
|
||||
|
||||
val dist = tasks.register<Jar>("bukkitAndBungeeJar") {
|
||||
artifacts.add("archives", this)
|
||||
archiveClassifier.set(null as String?)
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
|
||||
for (platform in platforms) {
|
||||
val jarTask = platform.miniMOTDPlatform.jarTask
|
||||
from(zipTree(jarTask.flatMap { it.archiveFile }))
|
||||
}
|
||||
}
|
||||
|
||||
miniMOTDPlatform {
|
||||
jarTask.set(dist)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
group=xyz.jpenilla
|
||||
version=2.1.2-SNAPSHOT
|
||||
description=Use MiniMessage text formatting in the server list MOTD.
|
||||
|
||||
org.gradle.caching=true
|
||||
org.gradle.configureondemand=true
|
||||
org.gradle.jvmargs=-Xmx2G
|
||||
org.gradle.parallel=true
|
||||
@@ -0,0 +1,18 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.indraCommon)
|
||||
implementation(libs.indraLicenser)
|
||||
implementation(libs.shadow)
|
||||
implementation(libs.mod.publish.plugin)
|
||||
implementation(libs.hangarPublishPlugin)
|
||||
|
||||
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
|
||||
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
rootProject.name = "build-logic"
|
||||
|
||||
dependencyResolutionManagement {
|
||||
versionCatalogs {
|
||||
create("libs") {
|
||||
from(files("../libs.versions.toml"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
object Constants {
|
||||
const val GITHUB_USER = "jpenilla"
|
||||
const val GITHUB_REPO = "MiniMOTD"
|
||||
const val GITHUB_URL = "https://github.com/$GITHUB_USER/$GITHUB_REPO"
|
||||
const val RELOCATION_BASE_PACKAGE = "xyz.jpenilla.minimotd.lib"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
abstract class FileCopyTask : DefaultTask() {
|
||||
@get:InputFile
|
||||
abstract val fileToCopy: RegularFileProperty
|
||||
|
||||
@get:OutputFile
|
||||
abstract val destination: RegularFileProperty
|
||||
|
||||
@TaskAction
|
||||
fun copyFile() {
|
||||
destination.get().asFile.parentFile.mkdirs()
|
||||
fileToCopy.get().asFile.copyTo(destination.get().asFile, overwrite = true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask
|
||||
|
||||
interface MiniMOTDPlatformExtension {
|
||||
val jarTask: Property<AbstractArchiveTask>
|
||||
val hangar: Property<Boolean>
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import net.kyori.indra.git.IndraGitExtension
|
||||
import org.gradle.accessors.dm.LibrariesForLibs
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
|
||||
fun Project.lastCommitHash(): String =
|
||||
extensions.getByType<IndraGitExtension>().commit()?.name?.substring(0, 7) ?: "unknown"
|
||||
|
||||
val Project.libs: LibrariesForLibs
|
||||
get() = extensions.getByType()
|
||||
|
||||
val Project.releaseNotes: Provider<String>
|
||||
get() = providers.environmentVariable("RELEASE_NOTES")
|
||||
|
||||
val Project.minecraftVersion: String
|
||||
get() = libs.versions.minecraft.get()
|
||||
|
||||
val bukkitVersions = listOf(
|
||||
"1.8.8",
|
||||
"1.8.9",
|
||||
"1.9.4",
|
||||
"1.10.2",
|
||||
"1.11.2",
|
||||
"1.12.2",
|
||||
"1.13.2",
|
||||
"1.14.4",
|
||||
"1.15.2",
|
||||
"1.16.5",
|
||||
"1.17.1",
|
||||
"1.18.2",
|
||||
"1.19.4",
|
||||
"1.20.6",
|
||||
"1.21",
|
||||
)
|
||||
@@ -0,0 +1,40 @@
|
||||
plugins {
|
||||
id("java-library")
|
||||
id("net.kyori.indra")
|
||||
id("net.kyori.indra.git")
|
||||
id("net.kyori.indra.checkstyle")
|
||||
id("net.kyori.indra.licenser.spotless")
|
||||
}
|
||||
|
||||
version = (version as String)
|
||||
.run { if (this.endsWith("-SNAPSHOT")) "$this+${lastCommitHash()}" else this }
|
||||
|
||||
indra {
|
||||
javaVersions {
|
||||
minimumToolchain(17)
|
||||
target(8)
|
||||
}
|
||||
github(Constants.GITHUB_USER, Constants.GITHUB_REPO)
|
||||
mitLicense()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(libs.jupiterEngine)
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
tasks {
|
||||
withType<JavaCompile> {
|
||||
options.compilerArgs.add("-Xlint:-processing")
|
||||
}
|
||||
listOf(javadocJar, javadoc).forEach {
|
||||
it.configure {
|
||||
onlyIf { false }
|
||||
}
|
||||
}
|
||||
test {
|
||||
testLogging {
|
||||
events("passed")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
plugins {
|
||||
base
|
||||
id("io.papermc.hangar-publish-plugin")
|
||||
}
|
||||
|
||||
fun jar(platform: String) = project(":minimotd-$platform")
|
||||
.extensions.getByType<MiniMOTDPlatformExtension>().jarTask.flatMap { it.archiveFile }
|
||||
|
||||
hangarPublish.publications.register("plugin") {
|
||||
version.set(project.version as String)
|
||||
id.set("MiniMOTD")
|
||||
channel.set("Release")
|
||||
changelog.set(releaseNotes)
|
||||
apiKey.set(providers.environmentVariable("HANGAR_UPLOAD_KEY"))
|
||||
platforms {
|
||||
paper {
|
||||
jar.set(jar("bukkit"))
|
||||
val vers = bukkitVersions.toMutableList()
|
||||
vers -= "1.8.8"
|
||||
vers -= "1.8.9"
|
||||
vers += "1.8"
|
||||
platformVersions.addAll(vers)
|
||||
}
|
||||
velocity {
|
||||
jar.set(jar("velocity"))
|
||||
platformVersions.addAll("3.2")
|
||||
}
|
||||
waterfall {
|
||||
jar.set(jar("bungeecord"))
|
||||
platformVersions.addAll("1.20")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import me.modmuss50.mpp.ModPublishExtension
|
||||
|
||||
plugins {
|
||||
id("minimotd.base-conventions")
|
||||
id("net.kyori.indra.git")
|
||||
}
|
||||
|
||||
val platformExtension = extensions.create<MiniMOTDPlatformExtension>("miniMOTDPlatform")
|
||||
|
||||
tasks {
|
||||
val copyJar = register<FileCopyTask>("copyJar") {
|
||||
fileToCopy.set(platformExtension.jarTask.flatMap { it.archiveFile })
|
||||
destination.set(rootProject.layout.buildDirectory.dir("libs").flatMap {
|
||||
it.file(fileToCopy.map { file -> file.asFile.name })
|
||||
})
|
||||
}
|
||||
build {
|
||||
dependsOn(copyJar)
|
||||
}
|
||||
}
|
||||
|
||||
if (name != "minimotd-bukkit-bungeecord") {
|
||||
plugins.apply("me.modmuss50.mod-publish-plugin")
|
||||
|
||||
extensions.configure(ModPublishExtension::class) {
|
||||
modrinth {
|
||||
projectId.set("16vhQOQN")
|
||||
type = STABLE
|
||||
file.set(platformExtension.jarTask.flatMap { it.archiveFile })
|
||||
changelog.set(releaseNotes)
|
||||
accessToken.set(providers.environmentVariable("MODRINTH_TOKEN"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
plugins {
|
||||
id("minimotd.platform-conventions")
|
||||
id("io.github.goooler.shadow")
|
||||
}
|
||||
|
||||
tasks {
|
||||
jar {
|
||||
archiveClassifier.set("unshaded")
|
||||
}
|
||||
shadowJar {
|
||||
archiveClassifier.set(null as String?)
|
||||
commonConfiguration()
|
||||
}
|
||||
}
|
||||
|
||||
extensions.configure<MiniMOTDPlatformExtension> {
|
||||
jarTask.set(tasks.shadowJar)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
fun ShadowJar.commonRelocation(pkg: String) {
|
||||
relocate(pkg, "${Constants.RELOCATION_BASE_PACKAGE}.$pkg")
|
||||
}
|
||||
|
||||
fun ShadowJar.platformRelocation(platform: String, pkg: String) {
|
||||
relocate(pkg, "${Constants.RELOCATION_BASE_PACKAGE}.platform_$platform.$pkg")
|
||||
}
|
||||
|
||||
fun ShadowJar.commonConfiguration() {
|
||||
commonRelocation("org.spongepowered.configurate")
|
||||
commonRelocation("com.typesafe.config")
|
||||
dependencies {
|
||||
exclude(dependency("org.checkerframework:checker-qual"))
|
||||
exclude(dependency("org.jetbrains:annotations")) // transitive dep from adventure
|
||||
}
|
||||
}
|
||||
|
||||
fun ShadowJar.configureForNativeAdventurePlatform() {
|
||||
dependencies {
|
||||
exclude { dependency -> dependency.moduleGroup == "net.kyori" }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
[plugins]
|
||||
blossom = { id = "net.kyori.blossom", version = "2.1.0" }
|
||||
sponge-gradle-plugin = { id = "org.spongepowered.gradle.plugin", version = "2.2.0" }
|
||||
run-paper = { id = "xyz.jpenilla.run-paper", version.ref = "run-task" }
|
||||
run-velocity = { id = "xyz.jpenilla.run-velocity", version.ref = "run-task" }
|
||||
run-waterfall = { id = "xyz.jpenilla.run-waterfall", version.ref = "run-task" }
|
||||
|
||||
[versions]
|
||||
run-task = "2.3.0"
|
||||
mod-publish-plugin = "0.5.1"
|
||||
hangarPublishPlugin = "0.1.2"
|
||||
indra = "3.1.3"
|
||||
shadow = "8.1.7"
|
||||
adventure = "4.17.0"
|
||||
adventurePlatform = "4.3.3"
|
||||
adventurePlatformFabric = "5.14.0-SNAPSHOT"
|
||||
configurate = "4.1.2"
|
||||
checkerQual = "3.43.0"
|
||||
slf4j = "1.7.32"
|
||||
gson = "2.8.0"
|
||||
bstats = "3.0.2"
|
||||
paperApi = "1.16.5-R0.1-SNAPSHOT"
|
||||
paperlib = "1.0.8"
|
||||
waterfallApi = "1.16-R0.5-SNAPSHOT"
|
||||
fabricApi = "0.100.3+1.21"
|
||||
fabricLoader = "0.15.11"
|
||||
minecraft = "1.21"
|
||||
spongeApi7 = "7.2.0"
|
||||
velocityApi = "3.3.0-SNAPSHOT"
|
||||
jupiterEngine = "5.10.2"
|
||||
|
||||
[libraries]
|
||||
adventureBom = { group = "net.kyori", name = "adventure-bom", version.ref = "adventure" }
|
||||
adventureApi = { group = "net.kyori", name = "adventure-api" }
|
||||
adventureTextSerializerPlain = { group = "net.kyori", name = "adventure-text-serializer-plain" }
|
||||
adventureTextSerializerGson = { group = "net.kyori", name = "adventure-text-serializer-gson" }
|
||||
adventurePlatformBungeecord = { group = "net.kyori", name = "adventure-platform-bungeecord", version.ref = "adventurePlatform" }
|
||||
adventurePlatformBukkit = { group = "net.kyori", name = "adventure-platform-bukkit", version.ref = "adventurePlatform" }
|
||||
adventurePlatformFabric = { group = "net.kyori", name = "adventure-platform-fabric", version.ref = "adventurePlatformFabric" }
|
||||
adventurePlatformSpongeApi = { group = "net.kyori", name = "adventure-platform-spongeapi", version.ref = "adventurePlatform" }
|
||||
minimessage = { group = "net.kyori", name = "adventure-text-minimessage" }
|
||||
|
||||
configurateHocon = { group = "org.spongepowered", name = "configurate-hocon", version.ref = "configurate" }
|
||||
|
||||
checkerQual = { group = "org.checkerframework", name = "checker-qual", version.ref = "checkerQual" }
|
||||
|
||||
slf4jApi = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" }
|
||||
slf4jJdk14 = { group = "org.slf4j", name = "slf4j-jdk14", version.ref = "slf4j" }
|
||||
|
||||
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
|
||||
|
||||
bstatsBukkit = { group = "org.bstats", name = "bstats-bukkit", version.ref = "bstats" }
|
||||
bstatsBungeecord = { group = "org.bstats", name = "bstats-bungeecord", version.ref = "bstats" }
|
||||
bstatsVelocity = { group = "org.bstats", name = "bstats-velocity", version.ref = "bstats" }
|
||||
bstatsSponge = { group = "org.bstats", name = "bstats-sponge", version.ref = "bstats" }
|
||||
|
||||
paperApi = { group = "com.destroystokyo.paper", name = "paper-api", version.ref = "paperApi" }
|
||||
paperlib = { group = "io.papermc", name = "paperlib", version.ref = "paperlib" }
|
||||
|
||||
waterfallApi = { group = "io.github.waterfallmc", name = "waterfall-api", version.ref = "waterfallApi" }
|
||||
|
||||
fabricApi = { group = "net.fabricmc.fabric-api", name = "fabric-api", version.ref = "fabricApi" }
|
||||
fabricLoader = { group = "net.fabricmc", name = "fabric-loader", version.ref = "fabricLoader" }
|
||||
minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft" }
|
||||
|
||||
spongeApi7 = { group = "org.spongepowered", name = "spongeapi", version.ref = "spongeApi7" }
|
||||
|
||||
velocityApi = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocityApi" }
|
||||
|
||||
jupiterEngine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "jupiterEngine" }
|
||||
|
||||
# build-logic
|
||||
indraCommon = { group = "net.kyori", name = "indra-common", version.ref = "indra" }
|
||||
indraLicenser = { group = "net.kyori", name = "indra-licenser-spotless", version.ref = "indra" }
|
||||
shadow = { group = "io.github.goooler.shadow", name = "shadow-gradle-plugin", version.ref = "shadow" }
|
||||
mod-publish-plugin = { module = "me.modmuss50:mod-publish-plugin", version.ref = "mod-publish-plugin" }
|
||||
hangarPublishPlugin = { group = "io.papermc", name = "hangar-publish-plugin", version.ref = "hangarPublishPlugin" }
|
||||
|
||||
[bundles]
|
||||
Vendored
BIN
Binary file not shown.
+7
@@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,249 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+92
@@ -0,0 +1,92 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020-2024 Jason Penilla
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,21 @@
|
||||
This file is part of MiniMOTD, licensed under the MIT License.
|
||||
|
||||
Copyright (c) 2020-2024 Jason Penilla
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,48 @@
|
||||
plugins {
|
||||
id("minimotd.shadow-platform")
|
||||
alias(libs.plugins.run.paper)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.minimotdCommon)
|
||||
implementation(libs.slf4jJdk14)
|
||||
implementation(libs.adventurePlatformBukkit)
|
||||
implementation(libs.bstatsBukkit)
|
||||
implementation(libs.paperlib)
|
||||
compileOnly(libs.paperApi)
|
||||
}
|
||||
|
||||
tasks {
|
||||
runServer {
|
||||
minecraftVersion(minecraftVersion)
|
||||
}
|
||||
shadowJar {
|
||||
platformRelocation("bukkit", "xyz.jpenilla.minimotd.common")
|
||||
commonRelocation("org.slf4j")
|
||||
commonRelocation("io.leangen.geantyref")
|
||||
commonRelocation("net.kyori")
|
||||
commonRelocation("org.bstats")
|
||||
commonRelocation("io.papermc.lib")
|
||||
manifest {
|
||||
attributes("paperweight-mappings-namespace" to "mojang")
|
||||
}
|
||||
}
|
||||
processResources {
|
||||
val props = mapOf(
|
||||
"version" to project.version,
|
||||
"website" to Constants.GITHUB_URL,
|
||||
"description" to project.description
|
||||
)
|
||||
inputs.properties(props)
|
||||
filesMatching("plugin.yml") {
|
||||
expand(props)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runPaper.folia.registerTask()
|
||||
|
||||
publishMods.modrinth {
|
||||
modLoaders.addAll("paper", "folia")
|
||||
minecraftVersions.addAll(bukkitVersions)
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.bukkit;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import xyz.jpenilla.minimotd.common.CommandHandler;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.event.ClickEvent.runCommand;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.RED;
|
||||
|
||||
final class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
private final MiniMOTDPlugin plugin;
|
||||
private final CommandHandler handler;
|
||||
|
||||
BukkitCommand(final @NonNull MiniMOTDPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.handler = new CommandHandler(plugin.miniMOTD());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final @NonNull CommandSender sender, final @NonNull Command command, final @NonNull String label, final @NonNull String[] args) {
|
||||
final Audience audience = this.plugin.audiences().sender(sender);
|
||||
if (!sender.hasPermission("minimotd.admin")) {
|
||||
audience.sendMessage(text("No permission.", RED));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
this.onInvalidUse(audience);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
case "about":
|
||||
this.handler.about(audience);
|
||||
return true;
|
||||
case "help":
|
||||
this.handler.help(audience);
|
||||
return true;
|
||||
case "reload":
|
||||
this.handler.reload(audience);
|
||||
return true;
|
||||
}
|
||||
|
||||
this.onInvalidUse(audience);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void onInvalidUse(final @NonNull Audience audience) {
|
||||
audience.sendMessage(text("Invalid command usage. Use '/minimotd help' for a list of command provided by MiniMOTD.", RED)
|
||||
.hoverEvent(text("Click to execute '/minimotd help'"))
|
||||
.clickEvent(runCommand("/minimotd help")));
|
||||
}
|
||||
|
||||
private static final List<String> COMMANDS = ImmutableList.of("about", "reload", "help");
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(final @NonNull CommandSender sender, final @NonNull Command command, final @NonNull String alias, final @NonNull String[] args) {
|
||||
if (args.length < 2 && sender.hasPermission("minimotd.admin")) {
|
||||
return COMMANDS;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.bukkit;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDPlatform;
|
||||
import xyz.jpenilla.minimotd.common.util.UpdateChecker;
|
||||
|
||||
public final class MiniMOTDPlugin extends JavaPlugin implements MiniMOTDPlatform<CachedServerIcon> {
|
||||
private static final boolean PAPER_PING_EVENT_EXISTS = findClass("com.destroystokyo.paper.event.server.PaperServerListPingEvent") != null;
|
||||
|
||||
private Logger logger;
|
||||
private MiniMOTD<CachedServerIcon> miniMOTD;
|
||||
private BukkitAudiences audiences;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.logger = LoggerFactory.getLogger(this.getName());
|
||||
this.miniMOTD = new MiniMOTD<>(this);
|
||||
this.audiences = BukkitAudiences.create(this);
|
||||
|
||||
if (PAPER_PING_EVENT_EXISTS) {
|
||||
this.getServer().getPluginManager().registerEvents(new PaperPingListener(this.miniMOTD), this);
|
||||
} else {
|
||||
this.getServer().getPluginManager().registerEvents(new PingListener(this.miniMOTD), this);
|
||||
if (PaperLib.getMinecraftVersion() >= 12) { // PaperServerListPingEvent was added in 1.12
|
||||
this.suggestPaper();
|
||||
}
|
||||
}
|
||||
|
||||
final PluginCommand command = this.getCommand("minimotd");
|
||||
if (command != null) {
|
||||
final BukkitCommand bukkitCommand = new BukkitCommand(this);
|
||||
command.setExecutor(bukkitCommand);
|
||||
command.setTabCompleter(bukkitCommand);
|
||||
}
|
||||
|
||||
final Metrics metrics = new Metrics(this, 8132);
|
||||
|
||||
if (this.miniMOTD.configManager().pluginSettings().updateChecker()) {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
CompletableFuture.runAsync(() -> new UpdateChecker().checkVersion().forEach(this.logger::info)).whenComplete(($, thr) -> {
|
||||
if (thr != null) {
|
||||
this.logger.warn("Exception checking for updates", thr);
|
||||
}
|
||||
});
|
||||
} catch (final ReflectiveOperationException ex) {
|
||||
this.getServer().getScheduler().runTaskAsynchronously(this, () ->
|
||||
new UpdateChecker().checkVersion().forEach(this.logger::info));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public @NonNull MiniMOTD<CachedServerIcon> miniMOTD() {
|
||||
return this.miniMOTD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Path dataDirectory() {
|
||||
return this.getDataFolder().toPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Logger logger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CachedServerIcon loadIcon(final @NonNull BufferedImage image) throws Exception {
|
||||
return this.getServer().loadServerIcon(image);
|
||||
}
|
||||
|
||||
public @NonNull BukkitAudiences audiences() {
|
||||
return this.audiences;
|
||||
}
|
||||
|
||||
private void suggestPaper() {
|
||||
this.logger.warn("======================================================");
|
||||
this.logger.warn(" MiniMOTD works better if you use Paper as your server");
|
||||
this.logger.warn(" software.");
|
||||
this.logger.warn(" ");
|
||||
this.logger.warn(" Spigot does not include the necessary APIs for all");
|
||||
this.logger.warn(" of MiniMOTD's features to operate. MiniMOTD was");
|
||||
this.logger.warn(" designed to work with Paper and it's expanded API");
|
||||
this.logger.warn(" for full compatibility.");
|
||||
this.logger.warn(" ");
|
||||
this.logger.warn(" Get Paper from https://papermc.io/downloads");
|
||||
this.logger.warn("======================================================");
|
||||
}
|
||||
|
||||
private static @Nullable Class<?> findClass(final @NonNull String className) {
|
||||
try {
|
||||
return Class.forName(className);
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.bukkit;
|
||||
|
||||
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import xyz.jpenilla.minimotd.common.Constants;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.PingResponse;
|
||||
import xyz.jpenilla.minimotd.common.config.MOTDConfig;
|
||||
|
||||
public final class PaperPingListener implements Listener {
|
||||
private final LegacyComponentSerializer unusualHexSerializer = LegacyComponentSerializer.builder().hexColors().useUnusualXRepeatedCharacterHexFormat().build();
|
||||
private final MiniMOTD<CachedServerIcon> miniMOTD;
|
||||
|
||||
PaperPingListener(final @NonNull MiniMOTD<CachedServerIcon> miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handlePing(final @NonNull PaperServerListPingEvent event) {
|
||||
final MOTDConfig cfg = this.miniMOTD.configManager().mainConfig();
|
||||
|
||||
final PingResponse<CachedServerIcon> response = this.miniMOTD.createMOTD(cfg, event.getNumPlayers(), event.getMaxPlayers());
|
||||
|
||||
response.playerCount().applyCount(event::setNumPlayers, event::setMaxPlayers);
|
||||
response.motd(motd -> {
|
||||
if (event.getClient().getProtocolVersion() < Constants.MINECRAFT_1_16_PROTOCOL_VERSION || PaperLib.getMinecraftVersion() < 16) {
|
||||
event.setMotd(LegacyComponentSerializer.legacySection().serialize(motd));
|
||||
} else {
|
||||
event.setMotd(this.unusualHexSerializer.serialize(motd));
|
||||
}
|
||||
});
|
||||
response.icon(event::setServerIcon);
|
||||
|
||||
if (response.disablePlayerListHover()) {
|
||||
event.getPlayerSample().clear();
|
||||
}
|
||||
if (response.hidePlayerCount()) {
|
||||
event.setHidePlayers(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.bukkit;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.PingResponse;
|
||||
import xyz.jpenilla.minimotd.common.config.MOTDConfig;
|
||||
|
||||
public final class PingListener implements Listener {
|
||||
private final MiniMOTD<CachedServerIcon> miniMOTD;
|
||||
private final LegacyComponentSerializer unusualHexSerializer = LegacyComponentSerializer.builder().hexColors().useUnusualXRepeatedCharacterHexFormat().build();
|
||||
|
||||
PingListener(final @NonNull MiniMOTD<CachedServerIcon> miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handlePing(final @NonNull ServerListPingEvent event) {
|
||||
final MOTDConfig cfg = this.miniMOTD.configManager().mainConfig();
|
||||
|
||||
final PingResponse<CachedServerIcon> response = this.miniMOTD.createMOTD(cfg, event.getNumPlayers(), event.getMaxPlayers());
|
||||
|
||||
event.setMaxPlayers(response.playerCount().maxPlayers());
|
||||
response.motd(motd -> {
|
||||
if (PaperLib.getMinecraftVersion() > 15) {
|
||||
event.setMotd(this.unusualHexSerializer.serialize(motd));
|
||||
} else {
|
||||
event.setMotd(LegacyComponentSerializer.legacySection().serialize(motd));
|
||||
}
|
||||
});
|
||||
response.icon(icon -> {
|
||||
try {
|
||||
event.setServerIcon(icon);
|
||||
} catch (final UnsupportedOperationException ignore) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
name: MiniMOTD
|
||||
version: $version
|
||||
main: xyz.jpenilla.minimotd.bukkit.MiniMOTDPlugin
|
||||
folia-supported: true
|
||||
description: $description
|
||||
authors:
|
||||
- jmp
|
||||
website: $website
|
||||
commands:
|
||||
minimotd:
|
||||
description: MiniMOTD Command
|
||||
permission: minimotd.admin
|
||||
usage: /minimotd help
|
||||
api-version: 1.13
|
||||
softdepend:
|
||||
- ViaVersion
|
||||
@@ -0,0 +1,38 @@
|
||||
plugins {
|
||||
id("minimotd.shadow-platform")
|
||||
alias(libs.plugins.run.waterfall)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.minimotdCommon)
|
||||
implementation(libs.adventurePlatformBungeecord)
|
||||
implementation(libs.bstatsBungeecord)
|
||||
compileOnly(libs.waterfallApi)
|
||||
}
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
platformRelocation("bungee", "xyz.jpenilla.minimotd.common")
|
||||
commonRelocation("io.leangen.geantyref")
|
||||
commonRelocation("net.kyori")
|
||||
commonRelocation("org.bstats")
|
||||
}
|
||||
runWaterfall {
|
||||
waterfallVersion("1.20")
|
||||
}
|
||||
processResources {
|
||||
val props = mapOf(
|
||||
"version" to project.version,
|
||||
"description" to project.description
|
||||
)
|
||||
inputs.properties(props)
|
||||
filesMatching("bungee.yml") {
|
||||
expand(props)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishMods.modrinth {
|
||||
modLoaders.add("waterfall")
|
||||
minecraftVersions.addAll(minecraftVersion)
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import xyz.jpenilla.minimotd.common.CommandHandler;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.event.ClickEvent.runCommand;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.RED;
|
||||
|
||||
final class BungeeCommand extends Command {
|
||||
private final MiniMOTDPlugin plugin;
|
||||
private final CommandHandler handler;
|
||||
|
||||
BungeeCommand(final @NonNull MiniMOTDPlugin plugin) {
|
||||
super("minimotd");
|
||||
this.plugin = plugin;
|
||||
this.handler = new CommandHandler(plugin.miniMOTD());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final @NonNull CommandSender sender, final @NonNull String @NonNull [] args) {
|
||||
final Audience audience = this.plugin.audiences().sender(sender);
|
||||
if (!sender.hasPermission("minimotd.admin")) {
|
||||
audience.sendMessage(text("No permission.", RED));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
this.onInvalidUse(audience);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
case "about":
|
||||
this.handler.about(audience);
|
||||
return;
|
||||
case "help":
|
||||
this.handler.help(audience);
|
||||
return;
|
||||
case "reload":
|
||||
this.handler.reload(audience);
|
||||
return;
|
||||
}
|
||||
|
||||
this.onInvalidUse(audience);
|
||||
}
|
||||
|
||||
private void onInvalidUse(final @NonNull Audience audience) {
|
||||
audience.sendMessage(text("Invalid command usage. Use '/minimotd help' for a list of command provided by MiniMOTD.", RED)
|
||||
.hoverEvent(text("Click to execute '/minimotd help'"))
|
||||
.clickEvent(runCommand("/minimotd help")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Path;
|
||||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDPlatform;
|
||||
import xyz.jpenilla.minimotd.common.PingResponse;
|
||||
import xyz.jpenilla.minimotd.common.config.MOTDConfig;
|
||||
import xyz.jpenilla.minimotd.common.util.UpdateChecker;
|
||||
|
||||
public final class MiniMOTDPlugin extends Plugin implements MiniMOTDPlatform<Favicon> {
|
||||
private Logger logger;
|
||||
private BungeeAudiences audiences;
|
||||
private MiniMOTD<Favicon> miniMOTD;
|
||||
|
||||
public @NonNull MiniMOTD<Favicon> miniMOTD() {
|
||||
return this.miniMOTD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.logger = LoggerFactory.getLogger(this.getDescription().getName());
|
||||
this.miniMOTD = new MiniMOTD<>(this);
|
||||
this.miniMOTD.configManager().loadExtraConfigs();
|
||||
this.audiences = BungeeAudiences.create(this);
|
||||
this.injectTravertineGson();
|
||||
this.getProxy().getPluginManager().registerListener(this, new PingListener(this.miniMOTD));
|
||||
this.getProxy().getPluginManager().registerCommand(this, new BungeeCommand(this));
|
||||
final Metrics metrics = new Metrics(this, 8137);
|
||||
|
||||
if (this.miniMOTD.configManager().pluginSettings().updateChecker()) {
|
||||
this.getProxy().getScheduler().runAsync(this, () ->
|
||||
new UpdateChecker().checkVersion().forEach(this.logger::info));
|
||||
}
|
||||
|
||||
// preload some stuff, so the first ping is as fast as the rest
|
||||
this.preload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Path dataDirectory() {
|
||||
return this.getDataFolder().toPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Logger logger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Favicon loadIcon(final @NonNull BufferedImage image) {
|
||||
return Favicon.create(image);
|
||||
}
|
||||
|
||||
public @NonNull BungeeAudiences audiences() {
|
||||
return this.audiences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
this.miniMOTD.configManager().loadExtraConfigs();
|
||||
}
|
||||
|
||||
private void injectTravertineGson() {
|
||||
final Field gsonLegacyField = findDeclaredField(ProxyServer.getInstance().getClass(), "gsonLegacy");
|
||||
if (gsonLegacyField != null) {
|
||||
try {
|
||||
BungeeComponentSerializer.inject((Gson) gsonLegacyField.get(ProxyServer.getInstance()));
|
||||
} catch (final IllegalAccessException ex) {
|
||||
this.miniMOTD.logger().warn("Failed to inject into Travertine's gsonLegacy gson instance. There will likely be issues with 1.7.x clients.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static @Nullable Field findDeclaredField(final @NonNull Class<?> holder, final @NonNull String name) {
|
||||
try {
|
||||
return holder.getDeclaredField(name);
|
||||
} catch (final NoSuchFieldException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void preload() {
|
||||
final MOTDConfig cfg = this.miniMOTD.configManager().mainConfig();
|
||||
final PingResponse<Favicon> mini = this.miniMOTD.createMOTD(cfg, 0, 0);
|
||||
mini.motd(motd -> BungeeComponentSerializer.get().serialize(motd));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import xyz.jpenilla.minimotd.common.Constants;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.PingResponse;
|
||||
import xyz.jpenilla.minimotd.common.config.MOTDConfig;
|
||||
|
||||
public final class PingListener implements Listener {
|
||||
private final MiniMOTD<Favicon> miniMOTD;
|
||||
|
||||
PingListener(final @NonNull MiniMOTD<Favicon> miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPing(final @NonNull ProxyPingEvent e) {
|
||||
final ServerPing response = e.getResponse();
|
||||
if (response == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ServerPing.Players players = response.getPlayers();
|
||||
final MOTDConfig cfg = this.miniMOTD.configManager().resolveConfig(e.getConnection().getVirtualHost());
|
||||
final PingResponse<Favicon> mini = this.miniMOTD.createMOTD(cfg, players.getOnline(), players.getMax());
|
||||
|
||||
if (mini.hidePlayerCount()) {
|
||||
response.setPlayers(null);
|
||||
} else {
|
||||
mini.playerCount().applyCount(players::setOnline, players::setMax);
|
||||
if (mini.disablePlayerListHover()) {
|
||||
players.setSample(new ServerPing.PlayerInfo[]{});
|
||||
}
|
||||
}
|
||||
|
||||
mini.motd(motd -> {
|
||||
final BaseComponent[] bungee;
|
||||
if (e.getConnection().getVersion() < Constants.MINECRAFT_1_16_PROTOCOL_VERSION) {
|
||||
bungee = BungeeComponentSerializer.legacy().serialize(motd);
|
||||
} else {
|
||||
bungee = BungeeComponentSerializer.get().serialize(motd);
|
||||
}
|
||||
if (BungeeComponentSerializer.isNative()) {
|
||||
response.setDescriptionComponent(bungee[0]);
|
||||
} else {
|
||||
response.setDescriptionComponent(new TextComponent(bungee));
|
||||
}
|
||||
});
|
||||
mini.icon(response::setFavicon);
|
||||
|
||||
e.setResponse(response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
name: MiniMOTD
|
||||
main: xyz.jpenilla.minimotd.bungee.MiniMOTDPlugin
|
||||
version: $version
|
||||
author: jmp
|
||||
description: $description
|
||||
@@ -0,0 +1,60 @@
|
||||
plugins {
|
||||
id("quiet-fabric-loom")
|
||||
id("minimotd.platform-conventions")
|
||||
id("io.github.goooler.shadow")
|
||||
}
|
||||
|
||||
val shade: Configuration by configurations.creating
|
||||
|
||||
dependencies {
|
||||
minecraft(libs.minecraft)
|
||||
mappings(loom.officialMojangMappings())
|
||||
modImplementation(libs.fabricLoader)
|
||||
modImplementation(libs.fabricApi)
|
||||
|
||||
shade(implementation(projects.minimotdCommon) {
|
||||
exclude("net.kyori")
|
||||
})
|
||||
|
||||
modImplementation(libs.adventurePlatformFabric)
|
||||
include(libs.adventurePlatformFabric)
|
||||
}
|
||||
|
||||
miniMOTDPlatform {
|
||||
jarTask.set(tasks.remapJar)
|
||||
}
|
||||
|
||||
indra {
|
||||
javaVersions {
|
||||
target(21)
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
configurations = listOf(shade)
|
||||
commonConfiguration()
|
||||
commonRelocation("io.leangen.geantyref")
|
||||
}
|
||||
remapJar {
|
||||
archiveFileName.set("${project.name}-mc$minecraftVersion-${project.version}.jar")
|
||||
}
|
||||
processResources {
|
||||
val replacements = mapOf(
|
||||
"modid" to project.name,
|
||||
"name" to rootProject.name,
|
||||
"version" to project.version.toString(),
|
||||
"description" to project.description.toString(),
|
||||
"github_url" to Constants.GITHUB_URL
|
||||
)
|
||||
inputs.properties(replacements)
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand(replacements)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishMods.modrinth {
|
||||
modLoaders.add("fabric")
|
||||
minecraftVersions.addAll(minecraftVersion)
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.fabric;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import javax.imageio.ImageIO;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import xyz.jpenilla.minimotd.common.CommandHandler;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDPlatform;
|
||||
import xyz.jpenilla.minimotd.common.util.UpdateChecker;
|
||||
import xyz.jpenilla.minimotd.fabric.access.ServerStatusFaviconAccess;
|
||||
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
public final class MiniMOTDFabric implements ModInitializer, MiniMOTDPlatform<ServerStatus.Favicon> {
|
||||
private static MiniMOTDFabric instance = null;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(MiniMOTD.class);
|
||||
private final Path dataDirectory = FabricLoader.getInstance().getConfigDir().resolve("MiniMOTD");
|
||||
private final MiniMOTD<ServerStatus.Favicon> miniMOTD = new MiniMOTD<>(this);
|
||||
|
||||
private MinecraftServer server;
|
||||
private FabricServerAudiences audiences;
|
||||
|
||||
public MiniMOTDFabric() {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("Cannot create a second instance of " + this.getClass().getName());
|
||||
}
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public @NonNull MiniMOTD<ServerStatus.Favicon> miniMOTD() {
|
||||
return this.miniMOTD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
this.registerCommand();
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(minecraftServer -> {
|
||||
this.server = minecraftServer;
|
||||
this.audiences = FabricServerAudiences.of(minecraftServer);
|
||||
});
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(minecraftServer -> {
|
||||
if (this.miniMOTD.configManager().pluginSettings().updateChecker()) {
|
||||
CompletableFuture.runAsync(() -> new UpdateChecker().checkVersion().forEach(this.logger()::info));
|
||||
}
|
||||
});
|
||||
ServerLifecycleEvents.SERVER_STOPPED.register($ -> {
|
||||
this.server = null;
|
||||
this.audiences = null;
|
||||
});
|
||||
this.miniMOTD.logger().info("Done initializing MiniMOTD");
|
||||
}
|
||||
|
||||
private void registerCommand() {
|
||||
final class WrappingExecutor implements Command<CommandSourceStack> {
|
||||
private final CommandHandler.Executor handler;
|
||||
|
||||
WrappingExecutor(final CommandHandler.@NonNull Executor handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int run(final @NonNull CommandContext<CommandSourceStack> context) {
|
||||
this.handler.execute(context.getSource());
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
final CommandHandler handler = new CommandHandler(this.miniMOTD);
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, commandBuildContext, commandSelection) -> dispatcher.register(
|
||||
literal("minimotd")
|
||||
.requires(source -> source.hasPermission(4))
|
||||
.then(literal("reload").executes(new WrappingExecutor(handler::reload)))
|
||||
.then(literal("about").executes(new WrappingExecutor(handler::about)))
|
||||
.then(literal("help").executes(new WrappingExecutor(handler::help)))
|
||||
));
|
||||
}
|
||||
|
||||
public @NonNull FabricServerAudiences audiences() {
|
||||
return this.audiences;
|
||||
}
|
||||
|
||||
public static @NonNull MiniMOTDFabric get() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public @NonNull MinecraftServer requireServer() {
|
||||
if (this.server == null) {
|
||||
throw new IllegalStateException("Server requested before started");
|
||||
}
|
||||
return this.server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Path dataDirectory() {
|
||||
return this.dataDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Logger logger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerStatus.@NonNull Favicon loadIcon(final @NonNull BufferedImage bufferedImage) throws Exception {
|
||||
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ImageIO.write(bufferedImage, "PNG", out);
|
||||
final ServerStatus.Favicon favicon = new ServerStatus.Favicon(out.toByteArray());
|
||||
((ServerStatusFaviconAccess) (Object) favicon).cacheEncodedIcon();
|
||||
return favicon;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.fabric.access;
|
||||
|
||||
public interface ConnectionAccess {
|
||||
void protocolVersion(int protocolVersion);
|
||||
|
||||
int protocolVersion();
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.fabric.access;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface ServerStatusFaviconAccess {
|
||||
@Nullable String cachedEncodedIcon();
|
||||
|
||||
void cacheEncodedIcon();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.fabric.mixin;
|
||||
|
||||
import net.minecraft.network.Connection;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import xyz.jpenilla.minimotd.fabric.access.ConnectionAccess;
|
||||
|
||||
@Unique
|
||||
@Mixin(Connection.class)
|
||||
@Implements({@Interface(iface = ConnectionAccess.class, prefix = "miniMOTD$")})
|
||||
abstract class ConnectionMixin {
|
||||
private int miniMOTD$protocolVersion = -1;
|
||||
|
||||
public void miniMOTD$protocolVersion(final int protocolVersion) {
|
||||
this.miniMOTD$protocolVersion = protocolVersion;
|
||||
}
|
||||
|
||||
public int miniMOTD$protocolVersion() {
|
||||
return this.miniMOTD$protocolVersion;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.fabric.mixin;
|
||||
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
|
||||
import net.minecraft.server.network.ServerHandshakePacketListenerImpl;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import xyz.jpenilla.minimotd.fabric.access.ConnectionAccess;
|
||||
|
||||
@Mixin(ServerHandshakePacketListenerImpl.class)
|
||||
abstract class ServerHandshakePacketListenerImplMixin {
|
||||
@Shadow @Final private Connection connection;
|
||||
|
||||
@Inject(method = "handleIntention", at = @At("HEAD"))
|
||||
public void injectHandleIntention(final ClientIntentionPacket packet, final CallbackInfo ci) {
|
||||
((ConnectionAccess) this.connection).protocolVersion(packet.protocolVersion());
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.fabric.mixin;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.DataResult;
|
||||
import com.mojang.serialization.codecs.PrimitiveCodec;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import xyz.jpenilla.minimotd.fabric.access.ServerStatusFaviconAccess;
|
||||
|
||||
@Mixin(ServerStatus.Favicon.class)
|
||||
abstract class ServerStatusFaviconMixin implements ServerStatusFaviconAccess {
|
||||
@Unique
|
||||
private static Function<ServerStatus.Favicon, String> VANILLA_ENCODE_TO_STRING;
|
||||
|
||||
@Redirect(
|
||||
method = "<clinit>",
|
||||
at = @At(
|
||||
target = "Lcom/mojang/serialization/codecs/PrimitiveCodec;comapFlatMap(Ljava/util/function/Function;Ljava/util/function/Function;)Lcom/mojang/serialization/Codec;",
|
||||
value = "INVOKE"
|
||||
),
|
||||
remap = false
|
||||
)
|
||||
private static Codec<ServerStatus.Favicon> makeCodec(
|
||||
final PrimitiveCodec<String> stringCodec,
|
||||
final Function<String, DataResult<ServerStatus.Favicon>> decode,
|
||||
final Function<ServerStatus.Favicon, String> encode
|
||||
) {
|
||||
VANILLA_ENCODE_TO_STRING = encode;
|
||||
return stringCodec.comapFlatMap(decode, favicon -> {
|
||||
final @Nullable String encodedIcon = ((ServerStatusFaviconAccess) (Object) favicon).cachedEncodedIcon();
|
||||
if (encodedIcon != null) {
|
||||
return encodedIcon;
|
||||
}
|
||||
return encode.apply(favicon);
|
||||
});
|
||||
}
|
||||
|
||||
@Unique
|
||||
private String encodedIcon;
|
||||
|
||||
@Override
|
||||
public @Nullable String cachedEncodedIcon() {
|
||||
return this.encodedIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cacheEncodedIcon() {
|
||||
this.encodedIcon = VANILLA_ENCODE_TO_STRING.apply((ServerStatus.Favicon) (Object) this);
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.fabric.mixin;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerStatusPacketListenerImpl;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import xyz.jpenilla.minimotd.common.Constants;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.PingResponse;
|
||||
import xyz.jpenilla.minimotd.common.config.MOTDConfig;
|
||||
import xyz.jpenilla.minimotd.common.util.ComponentColorDownsampler;
|
||||
import xyz.jpenilla.minimotd.fabric.MiniMOTDFabric;
|
||||
import xyz.jpenilla.minimotd.fabric.access.ConnectionAccess;
|
||||
import xyz.jpenilla.minimotd.fabric.util.MutableServerStatus;
|
||||
|
||||
@Mixin(ServerStatusPacketListenerImpl.class)
|
||||
abstract class ServerStatusPacketListenerImplMixin {
|
||||
@Shadow @Final private Connection connection;
|
||||
|
||||
@Redirect(
|
||||
method = "handleStatusRequest",
|
||||
at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerStatusPacketListenerImpl;status:Lnet/minecraft/network/protocol/status/ServerStatus;")
|
||||
)
|
||||
public ServerStatus injectHandleStatusRequest(final ServerStatusPacketListenerImpl instance) {
|
||||
final MiniMOTDFabric miniMOTDFabric = MiniMOTDFabric.get();
|
||||
final MinecraftServer minecraftServer = miniMOTDFabric.requireServer();
|
||||
final ServerStatus vanillaStatus = Objects.requireNonNull(minecraftServer.getStatus(), "vanillaStatus");
|
||||
|
||||
final MiniMOTD<ServerStatus.Favicon> miniMOTD = miniMOTDFabric.miniMOTD();
|
||||
final MOTDConfig config = miniMOTD.configManager().mainConfig();
|
||||
|
||||
final PingResponse<ServerStatus.Favicon> response = miniMOTD.createMOTD(
|
||||
config,
|
||||
minecraftServer.getPlayerCount(),
|
||||
vanillaStatus.players().map(ServerStatus.Players::max).orElseGet(minecraftServer::getMaxPlayers)
|
||||
);
|
||||
|
||||
final MutableServerStatus modifiedStatus = new MutableServerStatus(vanillaStatus);
|
||||
response.motd(motd -> {
|
||||
if (((ConnectionAccess) this.connection).protocolVersion() >= Constants.MINECRAFT_1_16_PROTOCOL_VERSION) {
|
||||
modifiedStatus.description(miniMOTDFabric.audiences().toNative(motd));
|
||||
} else {
|
||||
modifiedStatus.description(miniMOTDFabric.audiences().toNative(ComponentColorDownsampler.downsampler().downsample(motd)));
|
||||
}
|
||||
});
|
||||
response.icon(favicon -> modifiedStatus.favicon(Optional.of(favicon)));
|
||||
|
||||
if (response.hidePlayerCount()) {
|
||||
modifiedStatus.players(Optional.empty());
|
||||
} else {
|
||||
final ServerStatus.Players newPlayers = new ServerStatus.Players(
|
||||
response.playerCount().maxPlayers(),
|
||||
response.playerCount().onlinePlayers(),
|
||||
response.disablePlayerListHover()
|
||||
? Collections.emptyList()
|
||||
: vanillaStatus.players().map(ServerStatus.Players::sample).orElse(Collections.emptyList())
|
||||
);
|
||||
modifiedStatus.players(Optional.of(newPlayers));
|
||||
}
|
||||
|
||||
return modifiedStatus.toServerStatus();
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.fabric.util;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@SuppressWarnings({"OptionalUsedAsFieldOrParameterType", "unused"})
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class MutableServerStatus {
|
||||
private Component description;
|
||||
private Optional<ServerStatus.Players> players;
|
||||
private Optional<ServerStatus.Version> version;
|
||||
private Optional<ServerStatus.Favicon> favicon;
|
||||
private boolean enforcesSecureChat;
|
||||
|
||||
public MutableServerStatus(final ServerStatus status) {
|
||||
this.description = status.description();
|
||||
this.players = status.players();
|
||||
this.version = status.version();
|
||||
this.favicon = status.favicon();
|
||||
this.enforcesSecureChat = status.enforcesSecureChat();
|
||||
}
|
||||
|
||||
public ServerStatus toServerStatus() {
|
||||
return new ServerStatus(this.description, this.players, this.version, this.favicon, this.enforcesSecureChat);
|
||||
}
|
||||
|
||||
public Component description() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void description(final Component description) {
|
||||
Objects.requireNonNull(description, "description");
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Optional<ServerStatus.Players> players() {
|
||||
return this.players;
|
||||
}
|
||||
|
||||
public void players(final Optional<ServerStatus.Players> players) {
|
||||
Objects.requireNonNull(players, "players");
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
public Optional<ServerStatus.Version> version() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public void version(final Optional<ServerStatus.Version> version) {
|
||||
Objects.requireNonNull(version, "version");
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Optional<ServerStatus.Favicon> favicon() {
|
||||
return this.favicon;
|
||||
}
|
||||
|
||||
public void favicon(final Optional<ServerStatus.Favicon> favicon) {
|
||||
Objects.requireNonNull(favicon, "favicon");
|
||||
this.favicon = favicon;
|
||||
}
|
||||
|
||||
public boolean enforcesSecureChat() {
|
||||
return this.enforcesSecureChat;
|
||||
}
|
||||
|
||||
public void enforcesSecureChat(final boolean enforcesSecureChat) {
|
||||
this.enforcesSecureChat = enforcesSecureChat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "${modid}",
|
||||
"version": "${version}",
|
||||
"name": "${name}",
|
||||
"description": "${description}",
|
||||
"authors": [
|
||||
"jmp"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "${github_url}",
|
||||
"sources": "${github_url}",
|
||||
"issues": "${github_url}/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"environment": "server",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"xyz.jpenilla.minimotd.fabric.MiniMOTDFabric"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"minimotd-fabric.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.15.11",
|
||||
"fabric": "*",
|
||||
"minecraft": "~1.21"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8.4",
|
||||
"package": "xyz.jpenilla.minimotd.fabric.mixin",
|
||||
"compatibilityLevel": "JAVA_16",
|
||||
"mixins": [
|
||||
"ConnectionMixin",
|
||||
"ServerHandshakePacketListenerImplMixin",
|
||||
"ServerStatusFaviconMixin",
|
||||
"ServerStatusPacketListenerImplMixin"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
plugins {
|
||||
id("minimotd.shadow-platform")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.minimotdCommon)
|
||||
implementation(libs.adventurePlatformSpongeApi)
|
||||
compileOnly(libs.spongeApi7)
|
||||
implementation(libs.bstatsSponge)
|
||||
}
|
||||
|
||||
tasks {
|
||||
processResources {
|
||||
val replacements = mapOf(
|
||||
"modid" to rootProject.name.lowercase(),
|
||||
"name" to rootProject.name,
|
||||
"version" to project.version.toString(),
|
||||
"description" to project.description.toString(),
|
||||
"url" to Constants.GITHUB_URL
|
||||
)
|
||||
inputs.properties(replacements)
|
||||
filesMatching("mcmod.info") {
|
||||
expand(replacements)
|
||||
}
|
||||
}
|
||||
shadowJar {
|
||||
commonRelocation("io.leangen.geantyref")
|
||||
commonRelocation("net.kyori")
|
||||
commonRelocation("org.bstats")
|
||||
}
|
||||
}
|
||||
|
||||
publishMods.modrinth {
|
||||
modLoaders.add("sponge")
|
||||
minecraftVersions.add("1.12.2")
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.sponge7;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import net.kyori.adventure.text.serializer.spongeapi.SpongeComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.event.EventListener;
|
||||
import org.spongepowered.api.event.server.ClientPingServerEvent;
|
||||
import org.spongepowered.api.network.status.Favicon;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.PingResponse;
|
||||
import xyz.jpenilla.minimotd.common.config.MOTDConfig;
|
||||
|
||||
final class ClientPingServerEventListener implements EventListener<ClientPingServerEvent> {
|
||||
private final MiniMOTD<Favicon> miniMOTD;
|
||||
|
||||
@Inject
|
||||
private ClientPingServerEventListener(final @NonNull MiniMOTD<Favicon> miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(final @NonNull ClientPingServerEvent event) {
|
||||
final ClientPingServerEvent.Response response = event.getResponse();
|
||||
|
||||
final ClientPingServerEvent.Response.Players players;
|
||||
final ClientPingServerEvent.Response.Players players0 = response.getPlayers().orElse(null);
|
||||
if (players0 != null) {
|
||||
players = players0;
|
||||
} else {
|
||||
response.setHidePlayers(false);
|
||||
players = response.getPlayers().orElse(null);
|
||||
if (players == null) {
|
||||
this.miniMOTD.logger().warn(String.format("Failed to handle ClientPingServerEvent: '%s', response.getPlayers() was null.", event));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final MOTDConfig config = this.miniMOTD.configManager().mainConfig();
|
||||
|
||||
final PingResponse<Favicon> mini = this.miniMOTD.createMOTD(config, players.getOnline(), players.getMax());
|
||||
mini.playerCount().applyCount(players::setOnline, players::setMax);
|
||||
mini.motd(motd -> response.setDescription(SpongeComponentSerializer.get().serialize(motd)));
|
||||
mini.icon(response::setFavicon);
|
||||
|
||||
if (mini.disablePlayerListHover()) {
|
||||
players.getProfiles().clear();
|
||||
}
|
||||
if (mini.hidePlayerCount()) {
|
||||
response.setHidePlayers(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.sponge7;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import net.kyori.adventure.platform.spongeapi.SpongeAudiences;
|
||||
import org.bstats.sponge.Metrics;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.command.CommandResult;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.command.args.CommandContext;
|
||||
import org.spongepowered.api.command.spec.CommandExecutor;
|
||||
import org.spongepowered.api.command.spec.CommandSpec;
|
||||
import org.spongepowered.api.config.ConfigDir;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.game.GameReloadEvent;
|
||||
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
||||
import org.spongepowered.api.event.server.ClientPingServerEvent;
|
||||
import org.spongepowered.api.network.status.Favicon;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
import xyz.jpenilla.minimotd.common.CommandHandler;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDPlatform;
|
||||
import xyz.jpenilla.minimotd.common.util.UpdateChecker;
|
||||
|
||||
@Plugin(id = "minimotd-sponge7")
|
||||
public final class MiniMOTDPlugin implements MiniMOTDPlatform<Favicon> {
|
||||
private final Logger logger;
|
||||
private final Path dataDirectory;
|
||||
private final MiniMOTD<Favicon> miniMOTD;
|
||||
private final SpongeAudiences audiences;
|
||||
private final Game game;
|
||||
private final Injector injector;
|
||||
|
||||
@Inject
|
||||
public MiniMOTDPlugin(
|
||||
final @NonNull Logger logger,
|
||||
@ConfigDir(sharedRoot = false) final @NonNull Path dataDirectory,
|
||||
final @NonNull SpongeAudiences audiences,
|
||||
final Metrics.@NonNull Factory metricsFactory,
|
||||
final @NonNull Injector injector,
|
||||
final @NonNull Game game
|
||||
) {
|
||||
this.logger = logger;
|
||||
this.dataDirectory = dataDirectory;
|
||||
this.audiences = audiences;
|
||||
this.game = game;
|
||||
this.miniMOTD = new MiniMOTD<>(this);
|
||||
this.injector = injector.createChildInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
this.bind(new TypeLiteral<MiniMOTD<Favicon>>() {
|
||||
}).toInstance(MiniMOTDPlugin.this.miniMOTD);
|
||||
}
|
||||
});
|
||||
metricsFactory.make(10768);
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void gameStarted(final @NonNull GameStartedServerEvent event) {
|
||||
Sponge.getEventManager().registerListener(this, ClientPingServerEvent.class, this.injector.getInstance(ClientPingServerEventListener.class));
|
||||
this.registerCommands();
|
||||
if (this.miniMOTD.configManager().pluginSettings().updateChecker()) {
|
||||
Task.builder()
|
||||
.async()
|
||||
.execute(() -> new UpdateChecker().checkVersion().forEach(this.logger::info))
|
||||
.submit(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void reloaded(final @NonNull GameReloadEvent event) {
|
||||
try {
|
||||
this.miniMOTD.reload();
|
||||
} catch (final Exception ex) {
|
||||
this.miniMOTD.logger().warn("Failed to reload MiniMOTD.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
final class WrappingExecutor implements CommandExecutor {
|
||||
private final CommandHandler.Executor handler;
|
||||
|
||||
WrappingExecutor(final CommandHandler.@NonNull Executor handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CommandResult execute(final @NonNull CommandSource src, final @NonNull CommandContext args) {
|
||||
this.handler.execute(MiniMOTDPlugin.this.audiences.receiver(src));
|
||||
return CommandResult.success();
|
||||
}
|
||||
}
|
||||
|
||||
final CommandHandler handler = new CommandHandler(this.miniMOTD);
|
||||
final CommandSpec help = CommandSpec.builder()
|
||||
.executor(new WrappingExecutor(handler::help))
|
||||
.build();
|
||||
final CommandSpec about = CommandSpec.builder()
|
||||
.executor(new WrappingExecutor(handler::about))
|
||||
.build();
|
||||
final CommandSpec reload = CommandSpec.builder()
|
||||
.executor(new WrappingExecutor(handler::reload))
|
||||
.build();
|
||||
Sponge.getCommandManager().register(
|
||||
this,
|
||||
CommandSpec.builder()
|
||||
.permission("minimotd.admin")
|
||||
.child(help, "help")
|
||||
.child(about, "about")
|
||||
.child(reload, "reload")
|
||||
.build(),
|
||||
"minimotd"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Path dataDirectory() {
|
||||
return this.dataDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Logger logger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Favicon loadIcon(final @NonNull BufferedImage image) throws IOException {
|
||||
return this.game.getRegistry().loadFavicon(image);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"modid": "${modid}",
|
||||
"name": "${name}",
|
||||
"version": "${version}",
|
||||
"description": "${description}",
|
||||
"url": "${url}",
|
||||
"authorList": [
|
||||
"jmp"
|
||||
],
|
||||
"dependencies": [
|
||||
"spongeapi@7.2.0"
|
||||
],
|
||||
"requiredMods": [
|
||||
"spongeapi@7.2.0"
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,59 @@
|
||||
import org.spongepowered.gradle.plugin.config.PluginLoaders
|
||||
import org.spongepowered.plugin.metadata.model.PluginDependency
|
||||
|
||||
plugins {
|
||||
id("minimotd.shadow-platform")
|
||||
alias(libs.plugins.sponge.gradle.plugin)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.minimotdCommon)
|
||||
}
|
||||
|
||||
sponge {
|
||||
injectRepositories(false)
|
||||
apiVersion("8.1.0-SNAPSHOT")
|
||||
plugin(rootProject.name.lowercase()) {
|
||||
loader {
|
||||
name(PluginLoaders.JAVA_PLAIN)
|
||||
version("1.0")
|
||||
}
|
||||
license("MIT")
|
||||
displayName(rootProject.name)
|
||||
entrypoint("xyz.jpenilla.minimotd.sponge8.MiniMOTDPlugin")
|
||||
description(project.description)
|
||||
links {
|
||||
homepage(Constants.GITHUB_URL)
|
||||
source(Constants.GITHUB_URL)
|
||||
issues("${Constants.GITHUB_URL}/issues")
|
||||
}
|
||||
contributor("jmp") {
|
||||
description("Lead Developer")
|
||||
}
|
||||
dependency("spongeapi") {
|
||||
loadOrder(PluginDependency.LoadOrder.AFTER)
|
||||
optional(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
configureForNativeAdventurePlatform()
|
||||
dependencies {
|
||||
exclude(dependency("io.leangen.geantyref:geantyref"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishMods.modrinth {
|
||||
modLoaders.add("sponge")
|
||||
minecraftVersions.addAll(
|
||||
"1.16.5",
|
||||
"1.17.1",
|
||||
"1.18.2",
|
||||
"1.19.4",
|
||||
"1.20.6",
|
||||
"1.21",
|
||||
)
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.sponge8;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.lang.reflect.Method;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.MinecraftVersion;
|
||||
import org.spongepowered.api.event.EventListener;
|
||||
import org.spongepowered.api.event.server.ClientPingServerEvent;
|
||||
import org.spongepowered.api.network.status.Favicon;
|
||||
import xyz.jpenilla.minimotd.common.Constants;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.PingResponse;
|
||||
import xyz.jpenilla.minimotd.common.config.MOTDConfig;
|
||||
import xyz.jpenilla.minimotd.common.util.ComponentColorDownsampler;
|
||||
|
||||
final class ClientPingServerEventListener implements EventListener<ClientPingServerEvent> {
|
||||
private static final Method GET_PROTOCOL;
|
||||
|
||||
static {
|
||||
try {
|
||||
final Class<?> protocolMinecraftVersion = Class.forName("org.spongepowered.common.ProtocolMinecraftVersion");
|
||||
GET_PROTOCOL = protocolMinecraftVersion.getMethod("getProtocol");
|
||||
} catch (final ReflectiveOperationException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private final MiniMOTD<Favicon> miniMOTD;
|
||||
|
||||
@Inject
|
||||
private ClientPingServerEventListener(final @NonNull MiniMOTD<Favicon> miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(final @NonNull ClientPingServerEvent event) {
|
||||
final ClientPingServerEvent.Response response = event.response();
|
||||
|
||||
final ClientPingServerEvent.Response.Players players;
|
||||
final ClientPingServerEvent.Response.Players players0 = response.players().orElse(null);
|
||||
if (players0 != null) {
|
||||
players = players0;
|
||||
} else {
|
||||
response.setHidePlayers(false);
|
||||
players = response.players().orElse(null);
|
||||
if (players == null) {
|
||||
this.miniMOTD.logger().warn(String.format("Failed to handle ClientPingServerEvent: '%s', response.players() was null.", event));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final MOTDConfig config = this.miniMOTD.configManager().mainConfig();
|
||||
|
||||
final PingResponse<Favicon> mini = this.miniMOTD.createMOTD(config, players.online(), players.max());
|
||||
mini.playerCount().applyCount(players::setOnline, players::setMax);
|
||||
mini.motd(motd -> {
|
||||
if (this.legacy(event.client().version())) {
|
||||
response.setDescription(ComponentColorDownsampler.downsampler().downsample(motd));
|
||||
} else {
|
||||
response.setDescription(motd);
|
||||
}
|
||||
});
|
||||
mini.icon(response::setFavicon);
|
||||
|
||||
if (mini.disablePlayerListHover()) {
|
||||
players.profiles().clear();
|
||||
}
|
||||
if (mini.hidePlayerCount()) {
|
||||
response.setHidePlayers(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean legacy(final @NonNull MinecraftVersion version) {
|
||||
try {
|
||||
return version.isLegacy()
|
||||
|| (int) GET_PROTOCOL.invoke(version) < Constants.MINECRAFT_1_16_PROTOCOL_VERSION;
|
||||
} catch (final ReflectiveOperationException e) {
|
||||
throw new IllegalStateException("Failed to get protocol version", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.sponge8;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.file.Path;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.command.Command;
|
||||
import org.spongepowered.api.command.CommandExecutor;
|
||||
import org.spongepowered.api.command.CommandResult;
|
||||
import org.spongepowered.api.command.parameter.CommandContext;
|
||||
import org.spongepowered.api.config.ConfigDir;
|
||||
import org.spongepowered.api.event.EventListenerRegistration;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.Order;
|
||||
import org.spongepowered.api.event.lifecycle.LoadedGameEvent;
|
||||
import org.spongepowered.api.event.lifecycle.RefreshGameEvent;
|
||||
import org.spongepowered.api.event.lifecycle.RegisterCommandEvent;
|
||||
import org.spongepowered.api.event.server.ClientPingServerEvent;
|
||||
import org.spongepowered.api.network.status.Favicon;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
import org.spongepowered.plugin.PluginContainer;
|
||||
import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||
import org.spongepowered.plugin.metadata.PluginMetadata;
|
||||
import xyz.jpenilla.minimotd.common.CommandHandler;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDPlatform;
|
||||
import xyz.jpenilla.minimotd.common.util.UpdateChecker;
|
||||
|
||||
@Plugin("minimotd-sponge8")
|
||||
public final class MiniMOTDPlugin implements MiniMOTDPlatform<Favicon> {
|
||||
private final Path dataDirectory;
|
||||
private final PluginMetadata pluginMetadata;
|
||||
private final Logger logger;
|
||||
private final PluginContainer pluginContainer;
|
||||
private final MiniMOTD<Favicon> miniMOTD;
|
||||
private final Injector injector;
|
||||
|
||||
@Inject
|
||||
public MiniMOTDPlugin(
|
||||
@ConfigDir(sharedRoot = false) final @NonNull Path dataDirectory,
|
||||
final @NonNull PluginContainer pluginContainer,
|
||||
final @NonNull Injector injector
|
||||
) {
|
||||
this.dataDirectory = dataDirectory;
|
||||
this.pluginContainer = pluginContainer;
|
||||
this.pluginMetadata = pluginContainer.metadata();
|
||||
this.logger = LoggerFactory.getLogger(this.pluginMetadata.id());
|
||||
this.miniMOTD = new MiniMOTD<>(this);
|
||||
this.injector = injector.createChildInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
this.bind(new TypeLiteral<MiniMOTD<Favicon>>() {
|
||||
}).toInstance(MiniMOTDPlugin.this.miniMOTD);
|
||||
}
|
||||
});
|
||||
Sponge.eventManager().registerListener(
|
||||
EventListenerRegistration.builder(ClientPingServerEvent.class)
|
||||
.plugin(pluginContainer)
|
||||
.listener(this.injector.getInstance(ClientPingServerEventListener.class))
|
||||
.order(Order.DEFAULT)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onGameLoaded(final @NonNull LoadedGameEvent event) {
|
||||
if (this.miniMOTD.configManager().pluginSettings().updateChecker()) {
|
||||
Sponge.asyncScheduler().submit(Task.builder()
|
||||
.plugin(this.pluginContainer)
|
||||
.execute(() -> new UpdateChecker().checkVersion().forEach(this.logger::info))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void registerCommands(final @NonNull RegisterCommandEvent<Command.Parameterized> event) {
|
||||
final class WrappingExecutor implements CommandExecutor {
|
||||
private final CommandHandler.Executor handler;
|
||||
|
||||
WrappingExecutor(final CommandHandler.@NonNull Executor handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(final @NonNull CommandContext context) {
|
||||
this.handler.execute(context.cause().audience());
|
||||
return CommandResult.success();
|
||||
}
|
||||
}
|
||||
|
||||
final CommandHandler handler = new CommandHandler(this.miniMOTD);
|
||||
final Command.Parameterized about = Command.builder()
|
||||
.executor(new WrappingExecutor(handler::about))
|
||||
.build();
|
||||
final Command.Parameterized help = Command.builder()
|
||||
.executor(new WrappingExecutor(handler::help))
|
||||
.build();
|
||||
final Command.Parameterized reload = Command.builder()
|
||||
.executor(new WrappingExecutor(handler::reload))
|
||||
.build();
|
||||
event.register(
|
||||
this.pluginContainer,
|
||||
Command.builder()
|
||||
.permission("minimotd.admin")
|
||||
.addChild(about, "about")
|
||||
.addChild(help, "help")
|
||||
.addChild(reload, "reload")
|
||||
.build(),
|
||||
"minimotd"
|
||||
);
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onRefresh(final @NonNull RefreshGameEvent event) {
|
||||
try {
|
||||
this.miniMOTD.reload();
|
||||
} catch (final Exception ex) {
|
||||
this.miniMOTD.logger().warn("Failed to reload MiniMOTD.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Path dataDirectory() {
|
||||
return this.dataDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Logger logger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Favicon loadIcon(final @NonNull BufferedImage image) throws Exception {
|
||||
return Favicon.load(image);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
plugins {
|
||||
id("minimotd.shadow-platform")
|
||||
alias(libs.plugins.run.velocity)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.minimotdCommon)
|
||||
implementation(libs.bstatsVelocity)
|
||||
compileOnly(libs.velocityApi)
|
||||
}
|
||||
|
||||
java.disableAutoTargetJvm()
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
configureForNativeAdventurePlatform()
|
||||
commonRelocation("io.leangen.geantyref")
|
||||
commonRelocation("org.bstats")
|
||||
}
|
||||
runVelocity {
|
||||
velocityVersion(libs.versions.velocityApi.get())
|
||||
}
|
||||
processResources {
|
||||
val props = mapOf(
|
||||
"description" to project.description as String,
|
||||
"url" to Constants.GITHUB_URL,
|
||||
"version" to project.version,
|
||||
)
|
||||
inputs.properties(props)
|
||||
filesMatching("velocity-plugin.json") {
|
||||
expand(props)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishMods.modrinth {
|
||||
modLoaders.add("velocity")
|
||||
minecraftVersions.addAll(minecraftVersion)
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.velocity;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.velocitypowered.api.command.BrigadierCommand;
|
||||
import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.util.Favicon;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
import org.bstats.velocity.Metrics;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
import xyz.jpenilla.minimotd.common.CommandHandler;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDPlatform;
|
||||
import xyz.jpenilla.minimotd.common.util.UpdateChecker;
|
||||
|
||||
public final class MiniMOTDPlugin implements MiniMOTDPlatform<Favicon> {
|
||||
private static final Set<Class<?>> LISTENER_CLASSES = ImmutableSet.of(
|
||||
PingListener.class
|
||||
);
|
||||
|
||||
private final MiniMOTD<Favicon> miniMOTD;
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private final CommandManager commandManager;
|
||||
private final Path dataDirectory;
|
||||
private final Metrics.Factory metricsFactory;
|
||||
private final Injector injector;
|
||||
|
||||
@Inject
|
||||
public MiniMOTDPlugin(
|
||||
final @NonNull ProxyServer server,
|
||||
final @NonNull Logger logger,
|
||||
final @NonNull CommandManager commandManager,
|
||||
@DataDirectory final @NonNull Path dataDirectory,
|
||||
final Metrics.@NonNull Factory metricsFactory,
|
||||
final @NonNull Injector injector
|
||||
) {
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
this.commandManager = commandManager;
|
||||
this.dataDirectory = dataDirectory;
|
||||
this.metricsFactory = metricsFactory;
|
||||
this.miniMOTD = new MiniMOTD<>(this);
|
||||
this.miniMOTD.configManager().loadExtraConfigs();
|
||||
this.injector = injector.createChildInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
this.bind(new TypeLiteral<MiniMOTD<Favicon>>() {
|
||||
}).toInstance(MiniMOTDPlugin.this.miniMOTD);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(final @NonNull ProxyInitializeEvent event) {
|
||||
for (final Class<?> clazz : LISTENER_CLASSES) {
|
||||
this.server.getEventManager().register(this, this.injector.getInstance(clazz));
|
||||
}
|
||||
this.registerCommand();
|
||||
this.metricsFactory.make(this, 10257);
|
||||
if (this.miniMOTD.configManager().pluginSettings().updateChecker()) {
|
||||
this.server.getScheduler().buildTask(
|
||||
this,
|
||||
() -> new UpdateChecker().checkVersion().forEach(this.logger::info)
|
||||
).schedule();
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommand() {
|
||||
final class WrappingExecutor implements Command<CommandSource> {
|
||||
private final CommandHandler.Executor handler;
|
||||
|
||||
WrappingExecutor(final CommandHandler.@NonNull Executor handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int run(final @NonNull CommandContext<CommandSource> context) {
|
||||
this.handler.execute(context.getSource());
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
final CommandHandler handler = new CommandHandler(this.miniMOTD);
|
||||
this.commandManager.register(this.commandManager.metaBuilder("minimotd").build(), new BrigadierCommand(
|
||||
LiteralArgumentBuilder.<CommandSource>literal("minimotd")
|
||||
.requires(source -> source.hasPermission("minimotd.admin"))
|
||||
.then(LiteralArgumentBuilder.<CommandSource>literal("help").executes(new WrappingExecutor(handler::help)))
|
||||
.then(LiteralArgumentBuilder.<CommandSource>literal("about").executes(new WrappingExecutor(handler::about)))
|
||||
.then(LiteralArgumentBuilder.<CommandSource>literal("reload").executes(new WrappingExecutor(handler::reload)))
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Path dataDirectory() {
|
||||
return this.dataDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Logger logger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Favicon loadIcon(final @NonNull BufferedImage image) {
|
||||
return Favicon.create(image);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
this.miniMOTD.configManager().loadExtraConfigs();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* This file is part of MiniMOTD, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2020-2024 Jason Penilla
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package xyz.jpenilla.minimotd.velocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.EventTask;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import com.velocitypowered.api.util.Favicon;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTD;
|
||||
import xyz.jpenilla.minimotd.common.PingResponse;
|
||||
import xyz.jpenilla.minimotd.common.config.MOTDConfig;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class PingListener {
|
||||
private final MiniMOTD<Favicon> miniMOTD;
|
||||
private final ProxyServer proxy;
|
||||
|
||||
@Inject
|
||||
private PingListener(final MiniMOTD<Favicon> miniMOTD, final ProxyServer proxy) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public EventTask onProxyPingEvent(final ProxyPingEvent event) {
|
||||
return EventTask.async(() -> this.handle(event));
|
||||
}
|
||||
|
||||
private void handle(final ProxyPingEvent event) {
|
||||
final MOTDConfig config = this.miniMOTD.configManager().resolveConfig(event.getConnection().getVirtualHost().orElse(null));
|
||||
final ServerPing.Builder pong = event.getPing().asBuilder();
|
||||
|
||||
final List<String> targetServers = config.targetServers();
|
||||
int playersCount = 0;
|
||||
if (targetServers.isEmpty()) {
|
||||
playersCount = pong.getOnlinePlayers();
|
||||
} else {
|
||||
final Set<ServerPing.SamplePlayer> players = new HashSet<>();
|
||||
for (final String serverName : targetServers) {
|
||||
final @Nullable RegisteredServer server = this.proxy.getServer(serverName).orElse(null);
|
||||
if (server != null) {
|
||||
playersCount += server.getPlayersConnected().size();
|
||||
players.addAll(server.getPlayersConnected().stream()
|
||||
.map(p -> new ServerPing.SamplePlayer(p.getGameProfile().getName(), p.getUniqueId()))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
pong.clearSamplePlayers();
|
||||
pong.samplePlayers(players.toArray(new ServerPing.SamplePlayer[0]));
|
||||
}
|
||||
|
||||
final PingResponse<Favicon> response = this.miniMOTD.createMOTD(config, playersCount, pong.getMaximumPlayers());
|
||||
response.icon(pong::favicon);
|
||||
response.motd(pong::description);
|
||||
response.playerCount().applyCount(pong::onlinePlayers, pong::maximumPlayers);
|
||||
|
||||
if (response.disablePlayerListHover()) {
|
||||
pong.clearSamplePlayers();
|
||||
}
|
||||
if (response.hidePlayerCount()) {
|
||||
pong.nullPlayers();
|
||||
}
|
||||
|
||||
event.setPing(pong.build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"id": "minimotd-velocity",
|
||||
"name": "MiniMOTD",
|
||||
"version": "$version",
|
||||
"description": "$description",
|
||||
"url": "$url",
|
||||
"authors": [
|
||||
"jmp"
|
||||
],
|
||||
"dependencies": [],
|
||||
"main": "xyz.jpenilla.minimotd.velocity.MiniMOTDPlugin"
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MiniMOTD</name>
|
||||
|
||||
<description>Set the server MOTD using MiniMessage!</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<url>https://spigotmc.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.apache.commons.io</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.apachecommonsio</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>xyz.jpenilla.jmplib</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.jmplib</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.kyori.examination</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.kyori.examination</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.kyori.adventure</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.kyori.adventure</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.checkerframework</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.checkerframework</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>CodeMC</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.16-R0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-bungeecord</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.DiamondDagger590</groupId>
|
||||
<artifactId>Prisma</artifactId>
|
||||
<version>a622d01b80</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.12</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bungeecord</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:base"
|
||||
],
|
||||
"ignoreDeps": [
|
||||
"quiet-fabric-loom",
|
||||
"com.mojang:minecraft",
|
||||
"com.google.code.gson:gson"
|
||||
],
|
||||
"labels": [
|
||||
"dependencies"
|
||||
],
|
||||
"packageRules": [
|
||||
{
|
||||
"description": "Correct Fabric API version handling",
|
||||
"matchPackageNames": ["net.fabricmc.fabric-api:fabric-api", "net.fabricmc.fabric-api:fabric-api-deprecated"],
|
||||
"versioning": "regex:^(?<major>\\d+)(\\.(?<minor>\\d+))?(\\.(?<patch>\\d+))?(?:\\+(?<compatibility>.*))?$"
|
||||
},
|
||||
{
|
||||
"matchManagers": ["github-actions", "gradle-wrapper"],
|
||||
"groupName": "gradle and github actions"
|
||||
},
|
||||
{
|
||||
"matchDepTypes": ["plugin"],
|
||||
"groupName": "gradle and github actions"
|
||||
},
|
||||
{
|
||||
"matchPaths": ["build-logic/*", "buildSrc/*"],
|
||||
"groupName": "gradle and github actions"
|
||||
}
|
||||
],
|
||||
"semanticCommitType": "build",
|
||||
"commitMessagePrefix": "chore(deps): "
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
mavenCentral {
|
||||
mavenContent { releasesOnly() }
|
||||
}
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots/") {
|
||||
mavenContent { snapshotsOnly() }
|
||||
}
|
||||
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
|
||||
mavenContent { snapshotsOnly() }
|
||||
}
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://repo.spongepowered.org/repository/maven-public/")
|
||||
maven("https://repo.jpenilla.xyz/snapshots/") {
|
||||
mavenContent { snapshotsOnly() }
|
||||
}
|
||||
}
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
}
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://maven.fabricmc.net/")
|
||||
maven("https://repo.jpenilla.xyz/snapshots/")
|
||||
}
|
||||
includeBuild("gradle/build-logic")
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("quiet-fabric-loom") version "1.6-SNAPSHOT"
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
|
||||
}
|
||||
|
||||
rootProject.name = "MiniMOTD"
|
||||
|
||||
fun setup(name: String, dir: String) {
|
||||
include(name)
|
||||
project(":$name").projectDir = file(dir)
|
||||
}
|
||||
|
||||
fun platform(name: String) = setup("minimotd-$name", "platform/$name")
|
||||
fun dist(name: String) = setup("minimotd-$name", "dist/$name")
|
||||
|
||||
setup("minimotd-common", "common")
|
||||
|
||||
sequenceOf(
|
||||
"bukkit",
|
||||
"sponge8",
|
||||
"sponge7",
|
||||
"bungeecord",
|
||||
"velocity",
|
||||
"fabric",
|
||||
).forEach(::platform)
|
||||
|
||||
dist("bukkit-bungeecord")
|
||||
@@ -1,94 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeCordComponentSerializer;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeCommand extends Command {
|
||||
private final MiniMOTD miniMOTD;
|
||||
|
||||
public BungeeCommand(MiniMOTD miniMOTD) {
|
||||
super("minimotdbungee");
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("minimotd.admin")) {
|
||||
onNoPermission(sender, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
onInvalidUse(sender, args);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
case "about":
|
||||
onAbout(sender, args);
|
||||
return;
|
||||
case "help":
|
||||
onHelp(sender, args);
|
||||
return;
|
||||
case "reload":
|
||||
onReload(sender, args);
|
||||
return;
|
||||
}
|
||||
|
||||
onInvalidUse(sender, args);
|
||||
}
|
||||
|
||||
private void onHelp(CommandSender sender, String[] args) {
|
||||
final ArrayList<String> messages = new ArrayList<String>();
|
||||
messages.add("<gradient:blue:green>MiniMOTD Commands:");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd about'><click:run_command:/minimotd about><yellow>/minimotd about");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd reload'><click:run_command:/minimotd reload><yellow>/minimotd reload");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd help'><click:run_command:/minimotd help><yellow>/minimotd help");
|
||||
send(sender, messages);
|
||||
}
|
||||
|
||||
private void onReload(CommandSender sender, String[] args) {
|
||||
miniMOTD.getCfg().reload();
|
||||
send(sender, "<green>Done reloading.");
|
||||
}
|
||||
|
||||
private void onAbout(CommandSender sender, String[] args) {
|
||||
final ArrayList<String> messages = new ArrayList<>();
|
||||
final String header = "<gradient:white:black>=============</gradient><gradient:black:white>=============";
|
||||
messages.add(header);
|
||||
messages.add("<hover:show_text:'<rainbow>click me!'><click:open_url:https://www.spigotmc.org/resources/minimotd.81254/>" + miniMOTD.getDescription().getName() + " <gradient:red:yellow>" + miniMOTD.getDescription().getVersion());
|
||||
messages.add("<yellow>By</yellow><gray>:</gray> <gradient:blue:green>jmp");
|
||||
messages.add(header);
|
||||
send(sender, messages);
|
||||
}
|
||||
|
||||
private void onInvalidUse(CommandSender sender, String[] args) {
|
||||
send(sender, "<hover:show_text:'<green>Click for <yellow>/minimotd help'><click:run_command:/minimotd help><italic><gradient:red:gold>Invalid usage.</gradient> <blue>Try <yellow>/minimotd help</yellow> or click here");
|
||||
}
|
||||
|
||||
private void onNoPermission(CommandSender sender, String[] args) {
|
||||
send(sender, "<gradient:red:yellow>No permission.");
|
||||
}
|
||||
|
||||
private void send(CommandSender sender, String message) {
|
||||
final String finalMessage;
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
finalMessage = message;
|
||||
} else {
|
||||
finalMessage = MiniMessage.get().stripTokens(message);
|
||||
}
|
||||
sender.sendMessage(BungeeCordComponentSerializer.get().serialize(MiniMessage.get().parse(finalMessage)));
|
||||
}
|
||||
|
||||
private void send(CommandSender sender, List<String> messages) {
|
||||
for (String message : messages) {
|
||||
send(sender, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class BungeeConfig extends MiniMOTDConfig {
|
||||
private final MiniMOTD miniMOTD;
|
||||
|
||||
public BungeeConfig(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
final Configuration config = loadFromDisk();
|
||||
|
||||
getMotds().clear();
|
||||
for (String motd : config.getStringList(MOTDS)) {
|
||||
getMotds().add(motd.replace("{br}", "\n"));
|
||||
}
|
||||
setMotdEnabled(config.getBoolean(MOTD_ENABLED));
|
||||
setMaxPlayersEnabled(config.getBoolean(MAX_PLAYERS_ENABLED));
|
||||
setJustXMoreEnabled(config.getBoolean(JUST_X_MORE_ENABLED));
|
||||
setMaxPlayers(config.getInt(MAX_PLAYERS));
|
||||
setXValue(config.getInt(X_VALUE));
|
||||
setFakePlayersEnabled(config.getBoolean(FAKE_PLAYERS_ENABLED));
|
||||
setFakePlayers(config.getString(FAKE_PLAYERS));
|
||||
}
|
||||
|
||||
private Configuration loadFromDisk() {
|
||||
if (!miniMOTD.getDataFolder().exists()) {
|
||||
miniMOTD.getDataFolder().mkdir();
|
||||
}
|
||||
File file = new File(miniMOTD.getDataFolder(), "config.yml");
|
||||
if (!file.exists()) {
|
||||
try (InputStream in = miniMOTD.getResourceAsStream("config.yml")) {
|
||||
Files.copy(in, file.toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(miniMOTD.getDataFolder(), "config.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
|
||||
public class MiniMOTD extends Plugin {
|
||||
@Getter private BungeeConfig cfg;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.cfg = new BungeeConfig(this);
|
||||
getProxy().getPluginManager().registerListener(this, new PingListener(this));
|
||||
getProxy().getPluginManager().registerCommand(this, new BungeeCommand(this));
|
||||
Metrics metrics = new Metrics(this, 8137);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class PingListener implements Listener {
|
||||
private final BungeeConfig cfg;
|
||||
|
||||
public PingListener(MiniMOTD miniMOTD) {
|
||||
this.cfg = miniMOTD.getCfg();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPing(ProxyPingEvent e) {
|
||||
final ServerPing response = e.getResponse();
|
||||
|
||||
if (response != null) {
|
||||
final ServerPing.Players players = response.getPlayers();
|
||||
int onlinePlayers = players.getOnline();
|
||||
if (cfg.isFakePlayersEnabled()) {
|
||||
try {
|
||||
if (cfg.getFakePlayers().contains(":")) {
|
||||
final String[] fakePlayers = cfg.getFakePlayers().split(":");
|
||||
final int start = Integer.parseInt(fakePlayers[0]);
|
||||
final int end = Integer.parseInt(fakePlayers[1]);
|
||||
onlinePlayers = onlinePlayers + ThreadLocalRandom.current().nextInt(start, end);
|
||||
} else if (cfg.getFakePlayers().contains("%")) {
|
||||
final double factor = 1 + (Double.parseDouble(cfg.getFakePlayers().replace("%", "")) / 100);
|
||||
onlinePlayers = (int) Math.ceil(factor * onlinePlayers);
|
||||
} else {
|
||||
final int addedPlayers = Integer.parseInt(cfg.getFakePlayers());
|
||||
onlinePlayers = onlinePlayers + addedPlayers;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
System.out.println("[MiniMOTD] fakePlayers config incorrect");
|
||||
}
|
||||
}
|
||||
players.setOnline(onlinePlayers);
|
||||
|
||||
int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, players.getMax());
|
||||
players.setMax(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
Component motd = MiniMessage.get().parse(cfg.getMOTD(onlinePlayers, maxPlayers));
|
||||
BaseComponent component = ComponentSerializer.parse(GsonComponentSerializer.builder().build().serialize(motd))[0];
|
||||
response.setDescriptionComponent(component);
|
||||
//response.setDescriptionComponent(BungeeCordComponentSerializer.get().serialize(motd)[0]);
|
||||
}
|
||||
|
||||
response.setPlayers(players);
|
||||
e.setResponse(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
@FieldNameConstants
|
||||
public abstract class MiniMOTDConfig {
|
||||
public final String MOTDS = "motd." + Fields.motds;
|
||||
public final String MOTD_ENABLED = "motd." + Fields.motdEnabled;
|
||||
public final String MAX_PLAYERS_ENABLED = Fields.maxPlayers + "." + Fields.maxPlayersEnabled;
|
||||
public final String JUST_X_MORE_ENABLED = Fields.maxPlayers + "." + Fields.justXMoreEnabled;
|
||||
public final String MAX_PLAYERS = Fields.maxPlayers + "." + Fields.maxPlayers;
|
||||
public final String X_VALUE = Fields.maxPlayers + "." + Fields.xValue;
|
||||
public final String FAKE_PLAYERS_ENABLED = "bungeeOnly." + Fields.fakePlayersEnabled;
|
||||
public final String FAKE_PLAYERS = "bungeeOnly." + Fields.fakePlayers;
|
||||
@Getter private final ArrayList<String> motds = new ArrayList<>();
|
||||
@Getter @Setter private boolean motdEnabled;
|
||||
@Getter @Setter private boolean maxPlayersEnabled;
|
||||
@Getter @Setter private boolean justXMoreEnabled;
|
||||
@Getter @Setter private boolean fakePlayersEnabled;
|
||||
@Getter @Setter private int xValue;
|
||||
@Getter @Setter private int maxPlayers;
|
||||
@Getter @Setter private String fakePlayers;
|
||||
|
||||
public abstract void reload();
|
||||
|
||||
public String getMOTD(int onlinePlayers, int maxPlayers) {
|
||||
if (motds.size() == 1) {
|
||||
return motds.get(0);
|
||||
} else {
|
||||
return motds.get(new Random().nextInt(motds.size()))
|
||||
.replace("{onlinePlayers}", String.valueOf(onlinePlayers))
|
||||
.replace("{maxPlayers}", String.valueOf(maxPlayers));
|
||||
}
|
||||
}
|
||||
|
||||
public int getAdjustedMaxPlayers(int onlinePlayers, int actualMaxPlayers) {
|
||||
if (maxPlayersEnabled) {
|
||||
return justXMoreEnabled ? onlinePlayers + xValue : maxPlayers;
|
||||
} else {
|
||||
return actualMaxPlayers;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class MiniMOTD extends JavaPlugin {
|
||||
@Getter private SpigotConfig cfg;
|
||||
@Getter private PrismaHook prisma;
|
||||
@Getter private static MiniMOTD instance;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Prisma")) {
|
||||
prisma = new PrismaHook();
|
||||
}
|
||||
this.cfg = new SpigotConfig(this);
|
||||
getServer().getPluginManager().registerEvents(new PingListener(this), this);
|
||||
getCommand("minimotd").setExecutor(new SpigotCommand(this));
|
||||
Metrics metrics = new Metrics(this, 8132);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
|
||||
public class PingListener implements Listener {
|
||||
private final SpigotConfig cfg;
|
||||
|
||||
public PingListener(MiniMOTD miniMOTD) {
|
||||
this.cfg = miniMOTD.getCfg();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPing(ServerListPingEvent e) {
|
||||
final int onlinePlayers = e.getNumPlayers();
|
||||
final int actualMaxPlayers = e.getMaxPlayers();
|
||||
|
||||
final int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, actualMaxPlayers);
|
||||
e.setMaxPlayers(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
e.setMotd(cfg.getMOTD(onlinePlayers, maxPlayers));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import lombok.NonNull;
|
||||
import us.eunoians.prisma.ColorProvider;
|
||||
|
||||
public class PrismaHook {
|
||||
public String translate(@NonNull String message) {
|
||||
return ColorProvider.translatePrismaToHex(message);
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import lombok.NonNull;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SpigotCommand implements CommandExecutor {
|
||||
private final MiniMOTD miniMOTD;
|
||||
private final BukkitAudiences audience;
|
||||
private final MiniMessage miniMessage;
|
||||
|
||||
public SpigotCommand(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
audience = BukkitAudiences.create(miniMOTD);
|
||||
miniMessage = MiniMessage.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!sender.hasPermission("minimotd.admin")) {
|
||||
onNoPermission(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
onInvalidUse(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
case "about":
|
||||
onAbout(sender, args);
|
||||
return true;
|
||||
case "help":
|
||||
onHelp(sender, args);
|
||||
return true;
|
||||
case "reload":
|
||||
onReload(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
onInvalidUse(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void onHelp(CommandSender sender, String[] args) {
|
||||
final ArrayList<String> messages = new ArrayList<>();
|
||||
messages.add("<gradient:blue:green>MiniMOTD Commands:");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd about'><click:run_command:/minimotd about><yellow>/minimotd about");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd reload'><click:run_command:/minimotd reload><yellow>/minimotd reload");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd help'><click:run_command:/minimotd help><yellow>/minimotd help");
|
||||
send(sender, messages);
|
||||
}
|
||||
|
||||
private void onReload(CommandSender sender, String[] args) {
|
||||
miniMOTD.getCfg().reload();
|
||||
send(sender, "<green>Done reloading.");
|
||||
}
|
||||
|
||||
private void onAbout(CommandSender sender, String[] args) {
|
||||
final ArrayList<String> messages = new ArrayList<>();
|
||||
final String header = "<gradient:white:black>=============</gradient><gradient:black:white>=============";
|
||||
messages.add(header);
|
||||
messages.add("<hover:show_text:'<rainbow>click me!'><click:open_url:" + miniMOTD.getDescription().getWebsite() + ">" + miniMOTD.getName() + " <gradient:red:yellow>" + miniMOTD.getDescription().getVersion());
|
||||
messages.add("<yellow>By</yellow><gray>:</gray> <gradient:blue:green>jmp");
|
||||
messages.add(header);
|
||||
send(sender, messages);
|
||||
}
|
||||
|
||||
private void onInvalidUse(CommandSender sender, String[] args) {
|
||||
send(sender, "<hover:show_text:'<green>Click for <yellow>/minimotd help'><click:run_command:/minimotd help><italic><gradient:red:gold>Invalid usage.</gradient> <blue>Try <yellow>/minimotd help</yellow> or click here");
|
||||
}
|
||||
|
||||
private void onNoPermission(CommandSender sender, String[] args) {
|
||||
send(sender, "<gradient:red:yellow>No permission.");
|
||||
}
|
||||
|
||||
private void send(@NonNull CommandSender sender, @NonNull String message) {
|
||||
if (sender instanceof Player) {
|
||||
audience.player((Player) sender).sendMessage(miniMessage.parse(message));
|
||||
} else {
|
||||
audience.console().sendMessage(miniMessage.parse(miniMessage.stripTokens(message)));
|
||||
}
|
||||
}
|
||||
|
||||
private void send(@NonNull CommandSender sender, @NonNull List<String> messages) {
|
||||
for (String message : messages) {
|
||||
send(sender, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
public class SpigotConfig extends MiniMOTDConfig {
|
||||
private final MiniMOTD miniMOTD;
|
||||
|
||||
public SpigotConfig(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
miniMOTD.saveDefaultConfig();
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
miniMOTD.reloadConfig();
|
||||
final FileConfiguration config = miniMOTD.getConfig();
|
||||
|
||||
getMotds().clear();
|
||||
for (String motd : config.getStringList(MOTDS)) {
|
||||
final String temp;
|
||||
if (miniMOTD.getPrisma() != null) {
|
||||
temp = miniMOTD.getPrisma().translate(motd);
|
||||
} else {
|
||||
temp = motd;
|
||||
}
|
||||
getMotds().add(miniMessageToLegacy(temp.replace("{br}", "\n")));
|
||||
}
|
||||
setMotdEnabled(config.getBoolean(MOTD_ENABLED));
|
||||
setMaxPlayersEnabled(config.getBoolean(MAX_PLAYERS_ENABLED));
|
||||
setJustXMoreEnabled(config.getBoolean(JUST_X_MORE_ENABLED));
|
||||
setMaxPlayers(config.getInt(MAX_PLAYERS));
|
||||
setXValue(config.getInt(X_VALUE));
|
||||
}
|
||||
|
||||
private String miniMessageToLegacy(String message) {
|
||||
return LegacyComponentSerializer.builder().hexColors().useUnusualXRepeatedCharacterHexFormat().build().serialize(MiniMessage.get().parse(message));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
name: MiniMOTD
|
||||
version: ${project.version}
|
||||
main: xyz.jpenilla.minimotd.bungee.MiniMOTD
|
||||
author: jmp
|
||||
description: Set the MOTD using MiniMessage!
|
||||
@@ -1,35 +0,0 @@
|
||||
motd:
|
||||
# Do you want to enable this feature?
|
||||
motdEnabled: true
|
||||
|
||||
# Placeholders: {onlinePlayers} {maxPlayers}
|
||||
# Use {br} to separate lines.
|
||||
# Putting more than one will cause one to be randomly chosen each refresh
|
||||
motds:
|
||||
- "<bold><gradient:black:white>----====[</gradient> <gradient:green:blue>UltraCraft <gradient:red:yellow></bold><italic>Official</gradient></italic><bold> <gradient:white:black>]=====----</gradient></bold>{br}<bold> <gradient:#EEFF4A:#F7FFAE>Custom <italic>Survival</italic></gradient> <color:#0092FF>Discord</bold><gray>:</gray> <gradient:#5FDAFF:#B8A6FF><italic>Ab3d5f"
|
||||
- "<rainbow>|||||||||||||||||||||||||||||||||||||||||||||||||||||||||</rainbow>{br}<white>Hello <blue>{onlinePlayers} <gray>/</gray> {maxPlayers}</blue> Players Online"
|
||||
|
||||
maxPlayers:
|
||||
# Do you want to enable this feature?
|
||||
maxPlayersEnabled: true
|
||||
|
||||
# Changes the Max Players value.
|
||||
maxPlayers: 69
|
||||
|
||||
# Changes the Max Players to X more than the online players
|
||||
# Example: 16/19 players online.
|
||||
justXMoreEnabled: false
|
||||
xValue: 3
|
||||
|
||||
bungeeOnly:
|
||||
# Do you want to enable this feature?
|
||||
fakePlayersEnabled: false
|
||||
|
||||
# Modes: static, random, percent
|
||||
# static: This many fake players will be added
|
||||
# ex: fakePlayers: "3"
|
||||
# random: A random number of fake players in this range will be added
|
||||
# ex: fakePlayers: "3:6"
|
||||
# percent: The player count will be inflated by this much, rounding up
|
||||
# ex: fakePlayers: "25%"
|
||||
fakePlayers: "25%"
|
||||
Loaded 100 of 101 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user