mirror of
https://github.com/jpenilla/MiniMOTD.git
synced 2026-11-07 01:42:36 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
No files matched your search
@@ -0,0 +1,6 @@
|
||||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# These are explicitly windows files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: Bug Report
|
||||
about: Report a bug
|
||||
title: "[Bug Report] This happens when another thing should have"
|
||||
labels: bug
|
||||
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, Spigot, Tuinity, Velocity, BungeeCord, Waterfall]
|
||||
- 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,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.
|
||||
@@ -17,10 +17,10 @@ jobs:
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- name: Build with Maven
|
||||
run: mvn clean package
|
||||
- run: mkdir staging && cp MiniMOTD-universal/target/MiniMOTD*.jar staging && cp MiniMOTD-spigot/target/MiniMOTD*.jar staging && cp MiniMOTD-bungeecord/target/MiniMOTD*.jar staging && cp MiniMOTD-velocity/target/MiniMOTD*.jar staging
|
||||
- uses: actions/upload-artifact@v1
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew clean build
|
||||
- run: mkdir staging && cp universal/build/libs/minimotd*.jar staging && cp spigot/build/libs/minimotd*.jar staging && cp bungee/build/libs/minimotd*.jar staging && cp velocity/build/libs/minimotd*.jar staging
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Package
|
||||
path: staging
|
||||
+6
-1
@@ -18,7 +18,6 @@ out/
|
||||
*.ctxt
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
@@ -111,3 +110,9 @@ buildNumber.properties
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
|
||||
# Ignore Gradle project-specific cache directory
|
||||
.gradle
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
||||
@@ -1,124 +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>
|
||||
<description>desc</description>
|
||||
|
||||
<parent>
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>MiniMOTD-bungeecord</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MiniMOTD BungeeCord</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<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>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.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.12</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.16-R0.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</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>org.bstats</groupId>
|
||||
<artifactId>bstats-bungeecord</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,91 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
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 javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class BungeeConfig extends MiniMOTDConfig {
|
||||
private final MiniMOTD miniMOTD;
|
||||
private final List<Favicon> icons = new ArrayList<>();
|
||||
|
||||
public BungeeConfig(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
reload();
|
||||
}
|
||||
|
||||
public Favicon getRandomIcon() {
|
||||
if (icons.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return icons.get(ThreadLocalRandom.current().nextInt(icons.size()));
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
final Configuration config = loadFromDisk();
|
||||
|
||||
getMotds().clear();
|
||||
getMotds().addAll(config.getStringList(MOTDS));
|
||||
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));
|
||||
setUpdateChecker(config.getBoolean(UPDATE_CHECKER));
|
||||
|
||||
final File iconFolder = new File(miniMOTD.getDataFolder() + File.separator + "icons");
|
||||
if (!iconFolder.exists()) {
|
||||
iconFolder.mkdir();
|
||||
}
|
||||
this.icons.clear();
|
||||
final File[] icons = iconFolder.listFiles(i -> i.getName().endsWith(".png"));
|
||||
if (icons != null) {
|
||||
for (File icon : icons) {
|
||||
try {
|
||||
BufferedImage bufferedImage = ImageIO.read(icon);
|
||||
if (bufferedImage.getHeight() == 64 && bufferedImage.getWidth() == 64) {
|
||||
this.icons.add(Favicon.create(bufferedImage));
|
||||
} else {
|
||||
miniMOTD.getLogger().info("Could not load " + icon.getName() + ": image must be 64x64px");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
miniMOTD.getLogger().info("Could not load " + icon.getName() + ": invalid image file");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,5 +0,0 @@
|
||||
name: MiniMOTD
|
||||
version: ${project.version}
|
||||
main: xyz.jpenilla.minimotd.bungee.MiniMOTD
|
||||
author: jmp
|
||||
description: Set the server list MOTD using MiniMessage!
|
||||
@@ -1,73 +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>
|
||||
|
||||
<parent>
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>MiniMOTD-common</artifactId>
|
||||
<name>MiniMOTD Common</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<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>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.12</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.jmanpenilla</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>test-MiniMessage-2.1.0-g341ae62-35</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>21.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,53 +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;
|
||||
public final String UPDATE_CHECKER = Fields.updateChecker;
|
||||
@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;
|
||||
@Getter @Setter private boolean updateChecker;
|
||||
|
||||
public abstract void reload();
|
||||
|
||||
public String getMOTD(int onlinePlayers, int maxPlayers) {
|
||||
String motd;
|
||||
if (motds.size() == 1) {
|
||||
motd = motds.get(0);
|
||||
} else {
|
||||
motd = motds.get(new Random().nextInt(motds.size()));
|
||||
}
|
||||
return motd
|
||||
.replace("{onlinePlayers}", String.valueOf(onlinePlayers))
|
||||
.replace("{maxPlayers}", String.valueOf(maxPlayers))
|
||||
.replace("{br}", "\n");
|
||||
}
|
||||
|
||||
public int getAdjustedMaxPlayers(int onlinePlayers, int actualMaxPlayers) {
|
||||
if (maxPlayersEnabled) {
|
||||
return justXMoreEnabled ? onlinePlayers + xValue : maxPlayers;
|
||||
} else {
|
||||
return actualMaxPlayers;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class UpdateChecker {
|
||||
private final JsonParser parser = new JsonParser();
|
||||
private final String currentVersion;
|
||||
|
||||
public UpdateChecker(String currentVersion) {
|
||||
this.currentVersion = currentVersion;
|
||||
}
|
||||
|
||||
public CompletableFuture<List<String>> checkVersion() {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
final List<String> messages = new ArrayList<>();
|
||||
final JsonArray result;
|
||||
try {
|
||||
result = parser.parse(new InputStreamReader(new URL("https://api.github.com/repos/jmanpenilla/MiniMOTD/releases").openStream(), Charsets.UTF_8)).getAsJsonArray();
|
||||
} catch (IOException exception) {
|
||||
messages.add("Cannot look for updates: " + exception.getMessage());
|
||||
return messages;
|
||||
}
|
||||
|
||||
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" + this.currentVersion;
|
||||
if (versionList.get(0).equals(currentVersion)) {
|
||||
messages.add("You are running the latest version of MiniMOTD! :)");
|
||||
return messages;
|
||||
}
|
||||
if (currentVersion.contains("SNAPSHOT")) {
|
||||
messages.add("You are running a development build of MiniMOTD! (" + currentVersion + ")");
|
||||
messages.add("The latest official release is " + versionList.get(0));
|
||||
return messages;
|
||||
}
|
||||
final int versionsBehind = versionList.indexOf(currentVersion);
|
||||
messages.add("There is an update available for MiniMOTD!");
|
||||
messages.add("You are running version " + currentVersion + ", which is " + (versionsBehind == -1 ? "many" : versionsBehind) + " versions outdated.");
|
||||
messages.add("Download the latest version, " + versionList.get(0) + " from GitHub at the link below:");
|
||||
messages.add(versionMap.get(versionList.get(0)));
|
||||
return messages;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,130 +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>
|
||||
<description>desc</description>
|
||||
<url>website</url>
|
||||
|
||||
<parent>
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>MiniMOTD-spigot</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MiniMOTD Spigot</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<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>papermc-repo</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</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.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.12</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.destroystokyo.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.DiamondDagger590</groupId>
|
||||
<artifactId>Prisma</artifactId>
|
||||
<version>a622d01b80</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,77 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class SpigotConfig extends MiniMOTDConfig {
|
||||
private final MiniMOTD miniMOTD;
|
||||
private final List<CachedServerIcon> icons = new ArrayList<>();
|
||||
|
||||
public SpigotConfig(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
miniMOTD.saveDefaultConfig();
|
||||
reload();
|
||||
}
|
||||
|
||||
public CachedServerIcon getRandomIcon() {
|
||||
if (icons.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return icons.get(ThreadLocalRandom.current().nextInt(icons.size()));
|
||||
}
|
||||
|
||||
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(temp);
|
||||
}
|
||||
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));
|
||||
setUpdateChecker(config.getBoolean(UPDATE_CHECKER));
|
||||
|
||||
final File iconFolder = new File(miniMOTD.getDataFolder() + File.separator + "icons");
|
||||
if (!iconFolder.exists()) {
|
||||
iconFolder.mkdir();
|
||||
}
|
||||
this.icons.clear();
|
||||
final File[] icons = iconFolder.listFiles(i -> i.getName().endsWith(".png"));
|
||||
if (icons != null) {
|
||||
for (File icon : icons) {
|
||||
try {
|
||||
BufferedImage bufferedImage = ImageIO.read(icon);
|
||||
if (bufferedImage.getHeight() == 64 && bufferedImage.getWidth() == 64) {
|
||||
this.icons.add(Bukkit.loadServerIcon(bufferedImage));
|
||||
} else {
|
||||
miniMOTD.getLogger().info("Could not load " + icon.getName() + ": image must be 64x64px");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
miniMOTD.getLogger().info("Could not load " + icon.getName() + ": invalid image file");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
name: MiniMOTD
|
||||
version: ${project.version}
|
||||
main: xyz.jpenilla.minimotd.spigot.MiniMOTD
|
||||
softdepend: [Prisma]
|
||||
authors: [jmp]
|
||||
api-version: 1.13
|
||||
description: Set the server list MOTD using MiniMessage!
|
||||
website: https://github.com/jmanpenilla/MiniMOTD/
|
||||
commands:
|
||||
minimotd:
|
||||
description: MiniMOTD command
|
||||
permission-message: No permission
|
||||
usage: /minimotd help
|
||||
@@ -1,68 +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">
|
||||
<parent>
|
||||
<artifactId>MiniMOTD</artifactId>
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<version>1.2.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>MiniMOTD-universal</artifactId>
|
||||
<name>MiniMOTD Universal</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD-spigot</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD-bungeecord</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD-velocity</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<configuration>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>org/**</exclude>
|
||||
<exclude>net/**</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,225 +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>
|
||||
|
||||
<parent>
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>MiniMOTD-velocity</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MiniMOTD Velocity</name>
|
||||
|
||||
<description>desc</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<url>website</url>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}/src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>templating-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>filter-src</id>
|
||||
<goals>
|
||||
<goal>filter-sources</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.9.1</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.trajano.wagon</groupId>
|
||||
<artifactId>wagon-git</artifactId>
|
||||
<version>2.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.doxia</groupId>
|
||||
<artifactId>doxia-module-markdown</artifactId>
|
||||
<version>1.9.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>3.0.0-M1</version>
|
||||
<configuration>
|
||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
<tagNameFormat>@{project.version}</tagNameFormat>
|
||||
<scmCommentPrefix xml:space="preserve">[RELEASE] </scmCommentPrefix>
|
||||
<goals>install deploy site-deploy
|
||||
</goals> <!-- install is here to fix javadoc generation in multi-module projects -->
|
||||
<releaseProfiles>release</releaseProfiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>net.kyori.adventure.text.minimessage</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.kyori.adventure.text.minimessage-unshaded</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>velocitypowered-repo</id>
|
||||
<url>https://repo.velocitypowered.com/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>minecraft-libraries</id>
|
||||
<url>https://libraries.minecraft.net/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spongepowered-repo</id>
|
||||
<url>https://repo.spongepowered.org/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.12</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>examination-api</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>examination-string</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,104 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.velocity;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.velocitypowered.api.util.Favicon;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class VelocityConfig extends MiniMOTDConfig {
|
||||
private final MiniMOTD miniMOTD;
|
||||
private final List<Favicon> icons = new ArrayList<>();
|
||||
|
||||
public VelocityConfig(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
try {
|
||||
Files.createDirectories(miniMOTD.getDataDirectory());
|
||||
} catch (IOException e) {
|
||||
miniMOTD.getLogger().warn("unable to create config directory");
|
||||
}
|
||||
|
||||
final File file = new File(miniMOTD.getDataDirectory().toFile().getPath() + File.separator + "config.yml");
|
||||
if (!file.exists()) {
|
||||
try (InputStream in = miniMOTD.getClass().getClassLoader().getResourceAsStream("config.yml")) {
|
||||
Files.copy(in, file.toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
final YAMLConfigurationLoader loader = YAMLConfigurationLoader.builder().setFile(file).build();
|
||||
|
||||
final ConfigurationNode node;
|
||||
try {
|
||||
node = loader.load();
|
||||
} catch (IOException e) {
|
||||
miniMOTD.getLogger().warn("unable to load config file.");
|
||||
return;
|
||||
}
|
||||
|
||||
final ConfigurationNode motd = node.getNode("motd");
|
||||
final ConfigurationNode maxPlayers = node.getNode("maxPlayers");
|
||||
final ConfigurationNode bungeeOnly = node.getNode("bungeeOnly");
|
||||
final ConfigurationNode updateChecker = node.getNode(UPDATE_CHECKER);
|
||||
|
||||
try {
|
||||
getMotds().clear();
|
||||
getMotds().addAll(motd.getNode("motds").getList(TypeToken.of(String.class)));
|
||||
setMotdEnabled(motd.getNode("motdEnabled").getBoolean());
|
||||
setMaxPlayersEnabled(maxPlayers.getNode("maxPlayersEnabled").getBoolean());
|
||||
setJustXMoreEnabled(maxPlayers.getNode("justXMoreEnabled").getBoolean());
|
||||
setMaxPlayers(maxPlayers.getNode("maxPlayers").getInt());
|
||||
setXValue(maxPlayers.getNode("xValue").getInt());
|
||||
setFakePlayersEnabled(bungeeOnly.getNode("fakePlayersEnabled").getBoolean());
|
||||
setFakePlayers(bungeeOnly.getNode("fakePlayers").getString());
|
||||
setUpdateChecker(updateChecker.getBoolean());
|
||||
} catch (ObjectMappingException e) {
|
||||
miniMOTD.getLogger().warn("unable to load config.");
|
||||
}
|
||||
|
||||
final File iconFolder = new File(miniMOTD.getDataDirectory().toFile().getPath() + File.separator + "icons");
|
||||
if (!iconFolder.exists()) {
|
||||
iconFolder.mkdir();
|
||||
}
|
||||
this.icons.clear();
|
||||
final File[] icons = iconFolder.listFiles(i -> i.getName().endsWith(".png"));
|
||||
if (icons != null) {
|
||||
for (File icon : icons) {
|
||||
try {
|
||||
BufferedImage bufferedImage = ImageIO.read(icon);
|
||||
if (bufferedImage.getHeight() == 64 && bufferedImage.getWidth() == 64) {
|
||||
this.icons.add(Favicon.create(bufferedImage));
|
||||
} else {
|
||||
miniMOTD.getLogger().info("Could not load " + icon.getName() + ": image must be 64x64px");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
miniMOTD.getLogger().info("Could not load " + icon.getName() + ": invalid image file");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Favicon getRandomIcon() {
|
||||
if (icons.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return icons.get(ThreadLocalRandom.current().nextInt(icons.size()));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||

|
||||

|
||||
|
||||
|
||||
> 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 for Paper (and Spigot) based servers, as well as Bungee and Velocity based
|
||||
> proxies. MiniMOTD is compatible with servers running versions 1.8 up through 1.16 and newer, although RGB colors
|
||||
> are only able to be sent from 1.16+ servers, and can only be seen by 1.16+ clients. (RGB colors will be automatically
|
||||
> downsampled for outdated clients)
|
||||
> 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).
|
||||
|
||||
|
||||

|
||||
@@ -0,0 +1,83 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
id("com.github.johnrengelman.shadow") version "6.1.0"
|
||||
}
|
||||
|
||||
allprojects {
|
||||
group = "xyz.jpenilla"
|
||||
version = "1.2.4+${latestCommitHash()}-SNAPSHOT"
|
||||
description = "Use MiniMessage text formatting in your servers MOTD."
|
||||
}
|
||||
|
||||
ext["url"] = "https://github.com/jmanpenilla/MiniMOTD/"
|
||||
|
||||
subprojects {
|
||||
apply<JavaLibraryPlugin>()
|
||||
apply<ShadowPlugin>()
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://papermc.io/repo/repository/maven-public/")
|
||||
maven("https://nexus.velocitypowered.com/repository/maven-public/")
|
||||
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
|
||||
maven("https://oss.sonatype.org/content/groups/public/")
|
||||
maven("https://repo.jpenilla.xyz/snapshots/")
|
||||
maven("https://repo.codemc.org/repository/maven-public")
|
||||
maven("https://jitpack.io")
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
annotationProcessor("org.projectlombok", "lombok", "1.18.16")
|
||||
compileOnly("org.projectlombok", "lombok", "1.18.16")
|
||||
}
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
minimize()
|
||||
archiveClassifier.set("")
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
configurations.archives {
|
||||
artifacts.removeAll { true }
|
||||
}
|
||||
|
||||
tasks {
|
||||
val aggregate = create("aggregateJars") {
|
||||
val artifacts = arrayListOf<File>()
|
||||
dependsOn(project(":minimotd-universal").tasks.getByName("build"))
|
||||
arrayOf("spigot", "bungeecord", "velocity").forEach {
|
||||
val subProject = project(":minimotd-$it")
|
||||
val shadow = subProject.tasks.getByName("shadowJar")
|
||||
artifacts.add(shadow.outputs.files.singleFile)
|
||||
}
|
||||
doLast {
|
||||
artifacts.add(project(":minimotd-universal").project.tasks.getByName("universal").outputs.files.singleFile)
|
||||
val libs = rootProject.buildDir.resolve("libs")
|
||||
libs.listFiles()?.forEach { it.delete() }
|
||||
artifacts.forEach { it.copyTo(libs.resolve(it.name)) }
|
||||
}
|
||||
}
|
||||
build {
|
||||
dependsOn(aggregate)
|
||||
}
|
||||
}
|
||||
|
||||
fun latestCommitHash(): String {
|
||||
val byteOut = ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine = listOf("git", "rev-parse", "--short", "HEAD")
|
||||
standardOutput = byteOut
|
||||
}
|
||||
return byteOut.toString(Charsets.UTF_8.name()).trim()
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
plugins {
|
||||
id("kr.entree.spigradle.bungee") version "2.2.3"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":minimotd-common"))
|
||||
implementation("net.kyori", "adventure-platform-bungeecord", "4.0.0-SNAPSHOT")
|
||||
implementation("org.bstats", "bstats-bungeecord", "1.8")
|
||||
compileOnly("io.github.waterfallmc", "waterfall-api", "1.16-R0.4-SNAPSHOT")
|
||||
}
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
relocate("net.kyori", "xyz.jpenilla.minimotd.lib.kyori")
|
||||
relocate("org.checkerframework", "xyz.jpenilla.minimotd.lib.checkerframework")
|
||||
relocate("org.bstats", "xyz.jpenilla.minimotd.lib.bstats")
|
||||
}
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
}
|
||||
|
||||
bungee {
|
||||
name = rootProject.name
|
||||
author = "jmp"
|
||||
}
|
||||
+2
-9
@@ -1,9 +1,8 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
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;
|
||||
@@ -79,13 +78,7 @@ public class BungeeCommand extends Command {
|
||||
}
|
||||
|
||||
private void send(CommandSender sender, String message) {
|
||||
final String finalMessage;
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
finalMessage = message;
|
||||
} else {
|
||||
finalMessage = miniMessage.stripTokens(message);
|
||||
}
|
||||
sender.sendMessage(BungeeCordComponentSerializer.get().serialize(miniMessage.parse(finalMessage)));
|
||||
miniMOTD.getAudiences().sender(sender).sendMessage(Identity.nil(), miniMessage.parse(message));
|
||||
}
|
||||
|
||||
private void send(CommandSender sender, List<String> messages) {
|
||||
@@ -0,0 +1,69 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class BungeeConfig extends MiniMOTDConfig<Favicon> {
|
||||
private final MiniMOTD miniMOTD;
|
||||
|
||||
public BungeeConfig(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
final Configuration config = Objects.requireNonNull(this.loadFromDisk());
|
||||
|
||||
motds.clear();
|
||||
motds.addAll(config.getStringList(MOTDS));
|
||||
motdEnabled = config.getBoolean(MOTD_ENABLED) && !motds.isEmpty();
|
||||
maxPlayersEnabled = config.getBoolean(MAX_PLAYERS_ENABLED);
|
||||
justXMoreEnabled = config.getBoolean(JUST_X_MORE_ENABLED);
|
||||
maxPlayers = config.getInt(MAX_PLAYERS);
|
||||
xValue = config.getInt(X_VALUE);
|
||||
fakePlayersEnabled = config.getBoolean(FAKE_PLAYERS_ENABLED);
|
||||
fakePlayers = config.getString(FAKE_PLAYERS);
|
||||
updateChecker = config.getBoolean(UPDATE_CHECKER);
|
||||
disablePlayerListHover = config.getBoolean(DISABLE_PLAYER_LIST_HOVER);
|
||||
|
||||
final File iconFolder = new File(miniMOTD.getDataFolder() + File.separator + "icons");
|
||||
this.loadIcons(iconFolder).forEach(miniMOTD.getLogger()::info);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull Favicon createIcon(final @NonNull BufferedImage bufferedImage) {
|
||||
return Favicon.create(bufferedImage);
|
||||
}
|
||||
|
||||
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) {
|
||||
miniMOTD.getLogger().log(Level.WARNING, "Failed to copy default config", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(miniMOTD.getDataFolder(), "config.yml"));
|
||||
} catch (IOException e) {
|
||||
miniMOTD.getLogger().log(Level.WARNING, "Failed to read config", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-6
@@ -6,8 +6,6 @@ import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
import xyz.jpenilla.minimotd.common.UpdateChecker;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class MiniMOTD extends Plugin {
|
||||
@Getter private BungeeConfig cfg;
|
||||
@Getter private BungeeAudiences audiences;
|
||||
@@ -20,10 +18,9 @@ public class MiniMOTD extends Plugin {
|
||||
getProxy().getPluginManager().registerCommand(this, new BungeeCommand(this));
|
||||
Metrics metrics = new Metrics(this, 8137);
|
||||
|
||||
try {
|
||||
new UpdateChecker(this.getDescription().getVersion()).checkVersion().get().forEach(message -> getLogger().info(message));
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
getLogger().info("failed to check for update: " + e.getMessage());
|
||||
if (cfg.isUpdateChecker()) {
|
||||
getProxy().getScheduler().runAsync(this, () ->
|
||||
new UpdateChecker(this.getDescription().getVersion()).checkVersion().forEach(getLogger()::info));
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-8
@@ -2,8 +2,7 @@ package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeCordComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
@@ -11,15 +10,18 @@ import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class PingListener implements Listener {
|
||||
private final BungeeConfig cfg;
|
||||
private final MiniMessage miniMessage = MiniMessage.get();
|
||||
private final MiniMOTD miniMOTD;
|
||||
private final LegacyComponentSerializer legacySerializer = LegacyComponentSerializer.builder().build();
|
||||
|
||||
public PingListener(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
this.cfg = miniMOTD.getCfg();
|
||||
}
|
||||
|
||||
@@ -45,7 +47,7 @@ public class PingListener implements Listener {
|
||||
onlinePlayers = onlinePlayers + addedPlayers;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
System.out.println("[MiniMOTD] fakePlayers config incorrect");
|
||||
miniMOTD.getLogger().warning("fakePlayers config invalid");
|
||||
}
|
||||
}
|
||||
players.setOnline(onlinePlayers);
|
||||
@@ -53,16 +55,22 @@ public class PingListener implements Listener {
|
||||
final int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, players.getMax());
|
||||
players.setMax(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
Component motd = miniMessage.parse(cfg.getMOTD(onlinePlayers, maxPlayers));
|
||||
if (cfg.isDisablePlayerListHover()) {
|
||||
players.setSample(new ServerPing.PlayerInfo[]{});
|
||||
}
|
||||
|
||||
final MiniMOTDConfig<Favicon>.MOTD motd = cfg.getMOTD(onlinePlayers, maxPlayers);
|
||||
final String motdString = motd.motd();
|
||||
if (motdString != null) {
|
||||
Component motdComponent = miniMessage.parse(motdString);
|
||||
if (e.getConnection().getVersion() < 735) {
|
||||
motd = legacySerializer.deserialize(legacySerializer.serialize(motd));
|
||||
motdComponent = legacySerializer.deserialize(legacySerializer.serialize(motdComponent));
|
||||
}
|
||||
response.setDescriptionComponent(BungeeCordComponentSerializer.get().serialize(motd)[0]);
|
||||
response.setDescriptionComponent(BungeeComponentSerializer.get().serialize(motdComponent)[0]);
|
||||
}
|
||||
|
||||
response.setPlayers(players);
|
||||
final Favicon favicon = cfg.getRandomIcon();
|
||||
final Favicon favicon = motd.icon();
|
||||
if (favicon != null) {
|
||||
response.setFavicon(favicon);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
dependencies {
|
||||
api("net.kyori", "adventure-api", "4.3.0")
|
||||
api("net.kyori", "adventure-text-minimessage", "4.1.0-SNAPSHOT")
|
||||
compileOnlyApi("com.google.code.gson", "gson", "2.8.0")
|
||||
compileOnlyApi("com.google.guava", "guava", "21.0")
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@FieldNameConstants
|
||||
public abstract class MiniMOTDConfig<I> {
|
||||
public static final String MOTDS = "motd." + Fields.motds;
|
||||
public static final String MOTD_ENABLED = "motd." + Fields.motdEnabled;
|
||||
public static final String MAX_PLAYERS_ENABLED = Fields.maxPlayers + "." + Fields.maxPlayersEnabled;
|
||||
public static final String JUST_X_MORE_ENABLED = Fields.maxPlayers + "." + Fields.justXMoreEnabled;
|
||||
public static final String MAX_PLAYERS = Fields.maxPlayers + "." + Fields.maxPlayers;
|
||||
public static final String X_VALUE = Fields.maxPlayers + "." + Fields.xValue;
|
||||
public static final String FAKE_PLAYERS_ENABLED = "bungeeOnly." + Fields.fakePlayersEnabled;
|
||||
public static final String FAKE_PLAYERS = "bungeeOnly." + Fields.fakePlayers;
|
||||
public static final String UPDATE_CHECKER = Fields.updateChecker;
|
||||
public static final String DISABLE_PLAYER_LIST_HOVER = "bungeeOnly." + Fields.disablePlayerListHover;
|
||||
protected final List<String> motds = new ArrayList<>();
|
||||
protected final Map<String, I> icons = new HashMap<>();
|
||||
protected boolean motdEnabled;
|
||||
@Getter protected boolean maxPlayersEnabled;
|
||||
@Getter protected boolean justXMoreEnabled;
|
||||
@Getter protected boolean fakePlayersEnabled;
|
||||
@Getter protected int xValue;
|
||||
@Getter protected int maxPlayers;
|
||||
@Getter protected String fakePlayers;
|
||||
@Getter protected boolean updateChecker;
|
||||
@Getter protected boolean disablePlayerListHover;
|
||||
|
||||
public abstract void reload();
|
||||
|
||||
public final class MOTD {
|
||||
private final I icon;
|
||||
private final String motd;
|
||||
|
||||
private MOTD(final @Nullable I icon, final @Nullable String motd) {
|
||||
this.icon = icon;
|
||||
this.motd = motd;
|
||||
}
|
||||
|
||||
public @Nullable String motd() {
|
||||
return motd;
|
||||
}
|
||||
|
||||
public @Nullable I icon() {
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
|
||||
protected List<String> loadIcons(File iconFolder) {
|
||||
final List<String> logOutput = new ArrayList<>();
|
||||
if (!iconFolder.exists()) {
|
||||
iconFolder.mkdir();
|
||||
}
|
||||
this.icons.clear();
|
||||
final File[] icons = iconFolder.listFiles(i -> i.getName().endsWith(".png"));
|
||||
if (icons != null) {
|
||||
for (File icon : icons) {
|
||||
try {
|
||||
BufferedImage bufferedImage = ImageIO.read(icon);
|
||||
if (bufferedImage.getHeight() == 64 && bufferedImage.getWidth() == 64) {
|
||||
final I newIcon = createIcon(bufferedImage);
|
||||
this.icons.put(icon.getName().split("\\.")[0], newIcon);
|
||||
} else {
|
||||
logOutput.add("Could not load " + icon.getName() + ": image must be 64x64px");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logOutput.add("Could not load " + icon.getName() + ": invalid image file");
|
||||
}
|
||||
}
|
||||
}
|
||||
return logOutput;
|
||||
}
|
||||
|
||||
protected abstract @NonNull I createIcon(final @NonNull BufferedImage bufferedImage) throws Exception;
|
||||
|
||||
private @Nullable I icon(final int index) {
|
||||
if (icons.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (icons.containsKey(String.valueOf(index))) {
|
||||
return icons.get(String.valueOf(index));
|
||||
}
|
||||
final int randomIndex = ThreadLocalRandom.current().nextInt(icons.size());
|
||||
final Iterator<I> iterator = icons.values().iterator();
|
||||
for (int i = 0; i < randomIndex; i++) {
|
||||
iterator.next();
|
||||
}
|
||||
return iterator.next();
|
||||
}
|
||||
|
||||
public @NonNull MOTD getMOTD(final int onlinePlayers, final int maxPlayers) {
|
||||
final int index;
|
||||
final String motd;
|
||||
if (motdEnabled) {
|
||||
index = motds.size() == 1 ? 0 : ThreadLocalRandom.current().nextInt(motds.size());
|
||||
motd = motds.get(index).replace("{onlinePlayers}", String.valueOf(onlinePlayers))
|
||||
.replace("{maxPlayers}", String.valueOf(maxPlayers))
|
||||
.replace("{br}", "\n");
|
||||
} else {
|
||||
motd = null;
|
||||
index = 0;
|
||||
}
|
||||
return new MOTD(icon(index), motd);
|
||||
}
|
||||
|
||||
public int getAdjustedMaxPlayers(final int onlinePlayers, final int actualMaxPlayers) {
|
||||
if (maxPlayersEnabled) {
|
||||
return justXMoreEnabled ? onlinePlayers + xValue : maxPlayers;
|
||||
} else {
|
||||
return actualMaxPlayers;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class UpdateChecker {
|
||||
private final JsonParser parser = new JsonParser();
|
||||
private final String currentVersion;
|
||||
|
||||
public UpdateChecker(String currentVersion) {
|
||||
this.currentVersion = currentVersion;
|
||||
}
|
||||
|
||||
public List<String> checkVersion() {
|
||||
final List<String> messages = new ArrayList<>();
|
||||
final JsonArray result;
|
||||
try {
|
||||
result = parser.parse(new InputStreamReader(new URL("https://api.github.com/repos/jmanpenilla/MiniMOTD/releases").openStream(), Charsets.UTF_8)).getAsJsonArray();
|
||||
} catch (IOException exception) {
|
||||
messages.add("Cannot look for updates: " + exception.getMessage());
|
||||
return messages;
|
||||
}
|
||||
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" + this.currentVersion;
|
||||
if (versionList.get(0).equals(currentVersion)) {
|
||||
messages.add("You are running the latest version of MiniMOTD! :)");
|
||||
return messages;
|
||||
}
|
||||
if (currentVersion.contains("SNAPSHOT")) {
|
||||
messages.add("You are running a development build of MiniMOTD! (" + currentVersion + ")");
|
||||
messages.add("The latest official release is " + versionList.get(0));
|
||||
return messages;
|
||||
}
|
||||
final int versionsBehind = versionList.indexOf(currentVersion);
|
||||
messages.add("There is an update available for MiniMOTD!");
|
||||
messages.add("You are running version " + currentVersion + ", which is " + (versionsBehind == -1 ? "many" : versionsBehind) + " versions outdated.");
|
||||
messages.add("Download the latest version, " + versionList.get(0) + " from GitHub at the link below:");
|
||||
messages.add(versionMap.get(versionList.get(0)));
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -1,4 +1,4 @@
|
||||
# Do you want the plugin to check for updated on GitHub on launch?
|
||||
# Do you want the plugin to check for updates on GitHub at launch?
|
||||
# https://github.com/jmanpenilla/MiniMOTD
|
||||
updateChecker: true
|
||||
|
||||
@@ -9,6 +9,8 @@ motd:
|
||||
# Placeholders: {onlinePlayers} {maxPlayers}
|
||||
# Use {br} to separate lines.
|
||||
# Putting more than one will cause one to be randomly chosen each refresh
|
||||
#
|
||||
# Tip: If you want to set a certain icon for each MOTD, check out this page: https://github.com/jmanpenilla/MiniMOTD/wiki/Assigning-specific-icons-per-MOTD
|
||||
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"
|
||||
@@ -40,4 +42,7 @@ bungeeOnly:
|
||||
# ex: fakePlayers: "3:6"
|
||||
# percent: The player count will be inflated by this much, rounding up
|
||||
# ex: fakePlayers: "25%"
|
||||
fakePlayers: "25%"
|
||||
fakePlayers: "25%"
|
||||
|
||||
# Setting this to true will disable the hover text showing online player usernames
|
||||
disablePlayerListHover: false
|
||||
Vendored
BIN
Binary file not shown.
+5
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,185 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or 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 UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# 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"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 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
|
||||
;;
|
||||
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"
|
||||
which java >/dev/null 2>&1 || 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
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+89
@@ -0,0 +1,89 @@
|
||||
@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=.
|
||||
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%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
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%"=="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!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -1,40 +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.2.1</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>MiniMOTD Parent</name>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<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>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<modules>
|
||||
<module>MiniMOTD-common</module>
|
||||
<module>MiniMOTD-spigot</module>
|
||||
<module>MiniMOTD-bungeecord</module>
|
||||
<module>MiniMOTD-velocity</module>
|
||||
<module>MiniMOTD-universal</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -0,0 +1,22 @@
|
||||
rootProject.name = "MiniMOTD"
|
||||
|
||||
setupSubproject("minimotd-common") {
|
||||
projectDir = file("common")
|
||||
}
|
||||
setupSubproject("minimotd-spigot") {
|
||||
projectDir = file("spigot")
|
||||
}
|
||||
setupSubproject("minimotd-bungeecord") {
|
||||
projectDir = file("bungee")
|
||||
}
|
||||
setupSubproject("minimotd-velocity") {
|
||||
projectDir = file("velocity")
|
||||
}
|
||||
setupSubproject("minimotd-universal") {
|
||||
projectDir = file("universal")
|
||||
}
|
||||
|
||||
inline fun setupSubproject(name: String, block: ProjectDescriptor.() -> Unit) {
|
||||
include(name)
|
||||
project(":$name").apply(block)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
plugins {
|
||||
id("kr.entree.spigradle") version "2.2.3"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":minimotd-common"))
|
||||
implementation("net.kyori", "adventure-platform-bukkit", "4.0.0-SNAPSHOT")
|
||||
implementation("org.bstats", "bstats-bukkit", "1.8")
|
||||
compileOnly("com.destroystokyo.paper", "paper-api", "1.16.4-R0.1-SNAPSHOT")
|
||||
compileOnly("com.github.DiamondDagger590", "Prisma", "a622d01b80")
|
||||
}
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
relocate("net.kyori", "xyz.jpenilla.minimotd.lib.kyori")
|
||||
relocate("org.checkerframework", "xyz.jpenilla.minimotd.lib.checkerframework")
|
||||
relocate("org.bstats", "xyz.jpenilla.minimotd.lib.bstats")
|
||||
}
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
}
|
||||
|
||||
spigot {
|
||||
name = rootProject.name
|
||||
apiVersion = "1.13"
|
||||
website = rootProject.ext["url"].toString()
|
||||
authors("jmp")
|
||||
softDepends("Prisma", "ViaVersion")
|
||||
commands {
|
||||
create("minimotd") {
|
||||
description = "MiniMOTD Command"
|
||||
permissionMessage = "No permission"
|
||||
usage = "/minimotd help"
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-6
@@ -8,8 +8,6 @@ import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import xyz.jpenilla.minimotd.common.UpdateChecker;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public final class MiniMOTD extends JavaPlugin {
|
||||
@Getter private static MiniMOTD instance;
|
||||
@Getter private SpigotConfig cfg;
|
||||
@@ -55,10 +53,9 @@ public final class MiniMOTD extends JavaPlugin {
|
||||
|
||||
Metrics metrics = new Metrics(this, 8132);
|
||||
|
||||
try {
|
||||
new UpdateChecker(this.getDescription().getVersion()).checkVersion().get().forEach(message -> getLogger().info(message));
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
getLogger().info("failed to check for update: " + e.getMessage());
|
||||
if (cfg.isUpdateChecker()) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, () ->
|
||||
new UpdateChecker(this.getDescription().getVersion()).checkVersion().forEach(getLogger()::info));
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-6
@@ -7,6 +7,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@@ -40,7 +41,7 @@ public class PaperPingListener implements Listener {
|
||||
onlinePlayers = onlinePlayers + addedPlayers;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
System.out.println("[MiniMOTD] fakePlayers config incorrect");
|
||||
miniMOTD.getLogger().warning("fakePlayers config invalid");
|
||||
}
|
||||
}
|
||||
e.setNumPlayers(onlinePlayers);
|
||||
@@ -48,17 +49,22 @@ public class PaperPingListener implements Listener {
|
||||
final int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, e.getMaxPlayers());
|
||||
e.setMaxPlayers(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
final Component motd = miniMessage.parse(cfg.getMOTD(onlinePlayers, maxPlayers));
|
||||
final MiniMOTDConfig<CachedServerIcon>.MOTD motd = cfg.getMOTD(onlinePlayers, maxPlayers);
|
||||
final String motdString = motd.motd();
|
||||
if (motdString != null) {
|
||||
final Component motdComponent = miniMessage.parse(motdString);
|
||||
if (e.getClient().getProtocolVersion() < 735 || miniMOTD.getMajorMinecraftVersion() < 16) {
|
||||
e.setMotd(legacySerializer.serialize(motd));
|
||||
e.setMotd(legacySerializer.serialize(motdComponent));
|
||||
} else {
|
||||
e.setMotd(serializer.serialize(motd));
|
||||
e.setMotd(serializer.serialize(motdComponent));
|
||||
}
|
||||
}
|
||||
final CachedServerIcon favicon = cfg.getRandomIcon();
|
||||
final CachedServerIcon favicon = motd.icon();
|
||||
if (favicon != null) {
|
||||
e.setServerIcon(favicon);
|
||||
}
|
||||
if (cfg.isDisablePlayerListHover()) {
|
||||
e.getPlayerSample().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-4
@@ -6,6 +6,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
public class PingListener implements Listener {
|
||||
private final SpigotConfig cfg;
|
||||
@@ -27,14 +28,16 @@ public class PingListener implements Listener {
|
||||
final int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, actualMaxPlayers);
|
||||
e.setMaxPlayers(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
final MiniMOTDConfig<CachedServerIcon>.MOTD motd = cfg.getMOTD(onlinePlayers, maxPlayers);
|
||||
final String motdString = motd.motd();
|
||||
if (motdString != null) {
|
||||
if (miniMOTD.getMajorMinecraftVersion() > 15) {
|
||||
e.setMotd(serializer.serialize(miniMessage.parse(cfg.getMOTD(onlinePlayers, maxPlayers))));
|
||||
e.setMotd(serializer.serialize(miniMessage.parse(motdString)));
|
||||
} else {
|
||||
e.setMotd(legacySerializer.serialize(miniMessage.parse(cfg.getMOTD(onlinePlayers, maxPlayers))));
|
||||
e.setMotd(legacySerializer.serialize(miniMessage.parse(motdString)));
|
||||
}
|
||||
}
|
||||
final CachedServerIcon favicon = cfg.getRandomIcon();
|
||||
final CachedServerIcon favicon = motd.icon();
|
||||
if (favicon != null) {
|
||||
e.setServerIcon(favicon);
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import us.eunoians.prisma.ColorProvider;
|
||||
|
||||
public class PrismaHook {
|
||||
+13
-11
@@ -1,16 +1,15 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import lombok.NonNull;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
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.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -24,7 +23,10 @@ public class SpigotCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean onCommand(@NonNull CommandSender sender,
|
||||
@NonNull Command command,
|
||||
@NonNull String label,
|
||||
@NonNull String[] args) {
|
||||
if (!sender.hasPermission("minimotd.admin")) {
|
||||
onNoPermission(sender, args);
|
||||
return true;
|
||||
@@ -85,9 +87,9 @@ public class SpigotCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
private void send(@NonNull CommandSender sender, @NonNull String message) {
|
||||
if (sender instanceof Player) {
|
||||
miniMOTD.getAudiences().player((Player) sender).sendMessage(miniMessage.parse(message));
|
||||
miniMOTD.getAudiences().player((Player) sender).sendMessage(Identity.nil(), miniMessage.parse(message));
|
||||
} else {
|
||||
miniMOTD.getAudiences().console().sendMessage(miniMessage.parse(miniMessage.stripTokens(message)));
|
||||
miniMOTD.getAudiences().console().sendMessage(Identity.nil(), miniMessage.parse(message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,12 +102,12 @@ public class SpigotCommand implements CommandExecutor, TabCompleter {
|
||||
private static final List<String> COMMANDS = ImmutableList.of("about", "reload", "help");
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
final List<String> completions = new ArrayList<>();
|
||||
public List<String> onTabComplete(final @NonNull CommandSender sender,
|
||||
final @NonNull Command command,
|
||||
final @NonNull String alias, String[] args) {
|
||||
if (args.length < 2 && sender.hasPermission("minimotd.admin")) {
|
||||
StringUtil.copyPartialMatches(args[0], COMMANDS, completions);
|
||||
Collections.sort(completions);
|
||||
return COMMANDS;
|
||||
}
|
||||
return completions;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
|
||||
public class SpigotConfig extends MiniMOTDConfig<CachedServerIcon> {
|
||||
private final MiniMOTD miniMOTD;
|
||||
|
||||
public SpigotConfig(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
miniMOTD.saveDefaultConfig();
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
miniMOTD.reloadConfig();
|
||||
final FileConfiguration config = miniMOTD.getConfig();
|
||||
|
||||
motds.clear();
|
||||
for (String motd : config.getStringList(MOTDS)) {
|
||||
final String temp;
|
||||
if (miniMOTD.getPrisma() != null) {
|
||||
temp = miniMOTD.getPrisma().translate(motd);
|
||||
} else {
|
||||
temp = motd;
|
||||
}
|
||||
motds.add(temp);
|
||||
}
|
||||
motdEnabled = config.getBoolean(MOTD_ENABLED) && !motds.isEmpty();
|
||||
maxPlayersEnabled = config.getBoolean(MAX_PLAYERS_ENABLED);
|
||||
justXMoreEnabled = config.getBoolean(JUST_X_MORE_ENABLED);
|
||||
maxPlayers = config.getInt(MAX_PLAYERS);
|
||||
xValue = config.getInt(X_VALUE);
|
||||
fakePlayersEnabled = config.getBoolean(FAKE_PLAYERS_ENABLED);
|
||||
fakePlayers = config.getString(FAKE_PLAYERS);
|
||||
updateChecker = config.getBoolean(UPDATE_CHECKER);
|
||||
disablePlayerListHover = config.getBoolean(DISABLE_PLAYER_LIST_HOVER);
|
||||
|
||||
final File iconFolder = new File(miniMOTD.getDataFolder() + File.separator + "icons");
|
||||
this.loadIcons(iconFolder).forEach(miniMOTD.getLogger()::info);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CachedServerIcon createIcon(final @NonNull BufferedImage bufferedImage) throws Exception {
|
||||
return Bukkit.loadServerIcon(bufferedImage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
tasks {
|
||||
val universal = register<Jar>("universal") {
|
||||
artifacts.add("archives", this)
|
||||
archiveClassifier.set("")
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
arrayOf("spigot", "bungeecord", "velocity").forEach {
|
||||
val shadowJar = rootProject.project(":minimotd-$it").tasks.getByName("shadowJar")
|
||||
from(zipTree(shadowJar.outputs.files.singleFile))
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
}
|
||||
build {
|
||||
dependsOn(universal)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import net.kyori.blossom.BlossomExtension
|
||||
|
||||
plugins {
|
||||
id("net.kyori.blossom") version "1.1.0"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":minimotd-common"))
|
||||
compileOnly("com.velocitypowered", "velocity-api", "1.1.2")
|
||||
annotationProcessor("com.velocitypowered", "velocity-api", "1.1.2")
|
||||
}
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
relocate("net.kyori.adventure.text.minimessage", "xyz.jpenilla.minimotd.velocity.lib.minimessage")
|
||||
relocate("xyz.jpenilla.minimotd.common", "xyz.jpenilla.minimotd.velocity.lib.minimotd.common")
|
||||
relocate("org.checkerframework", "xyz.jpenilla.minimotd.lib.checkerframework")
|
||||
dependencies {
|
||||
exclude { dep -> dep.moduleGroup == "net.kyori" && !dep.name.contains("minimessage") }
|
||||
}
|
||||
}
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
}
|
||||
|
||||
blossom {
|
||||
replaceTokens(
|
||||
"src/main/java/xyz/jpenilla/minimotd/velocity/MiniMOTD.java",
|
||||
"{project.name}" to project.name,
|
||||
"{rootProject.name}" to rootProject.name,
|
||||
"{version}" to version.toString(),
|
||||
"{description}" to description!!,
|
||||
"{url}" to rootProject.ext["url"].toString()
|
||||
)
|
||||
}
|
||||
|
||||
fun BlossomExtension.replaceTokens(
|
||||
filePath: String,
|
||||
vararg replacements: Pair<String, String>
|
||||
) {
|
||||
for ((token, replacement) in replacements) replaceToken(token, replacement, filePath)
|
||||
}
|
||||
+21
-15
@@ -16,18 +16,18 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.slf4j.Logger;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
import xyz.jpenilla.minimotd.common.UpdateChecker;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@Plugin(
|
||||
id = "minimotd-velocity",
|
||||
name = "MiniMOTD",
|
||||
version = "1.2.1",
|
||||
description = "Set the server list MOTD using MiniMessage!",
|
||||
url = "https://github.com/jmanpenilla/MiniMOTD/",
|
||||
id = "{project.name}",
|
||||
name = "{rootProject.name}",
|
||||
version = "{version}",
|
||||
description = "{description}",
|
||||
url = "{url}",
|
||||
authors = {"jmp"}
|
||||
)
|
||||
public class MiniMOTD {
|
||||
@@ -58,10 +58,10 @@ public class MiniMOTD {
|
||||
this.commandManager.register(this.commandManager.metaBuilder("minimotdvelocity").build(), new VelocityCommand(this));
|
||||
this.cfg.reload();
|
||||
|
||||
try {
|
||||
new UpdateChecker(this.getPluginDescription().getVersion().orElse("")).checkVersion().get().forEach(this.logger::info);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
this.logger.info("failed to check for update: " + e.getMessage());
|
||||
if (cfg.isUpdateChecker()) {
|
||||
this.server.getScheduler().buildTask(this, () ->
|
||||
new UpdateChecker(this.getPluginDescription().getVersion().orElse("")).checkVersion().forEach(this.logger::info))
|
||||
.schedule();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,19 +94,25 @@ public class MiniMOTD {
|
||||
int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, pong.getMaximumPlayers());
|
||||
pong.maximumPlayers(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
Component motd = miniMessage.parse(cfg.getMOTD(onlinePlayers, maxPlayers));
|
||||
final MiniMOTDConfig<Favicon>.MOTD motd = cfg.getMOTD(onlinePlayers, maxPlayers);
|
||||
final String motdString = motd.motd();
|
||||
if (motdString != null) {
|
||||
Component motdComponent = miniMessage.parse(motdString);
|
||||
if (pong.getVersion().getProtocol() < 735) {
|
||||
motd = legacySerializer.deserialize(legacySerializer.serialize(motd));
|
||||
motdComponent = legacySerializer.deserialize(legacySerializer.serialize(motdComponent));
|
||||
}
|
||||
pong.description(motd);
|
||||
pong.description(motdComponent);
|
||||
}
|
||||
|
||||
final Favicon favicon = cfg.getRandomIcon();
|
||||
final Favicon favicon = motd.icon();
|
||||
if (favicon != null) {
|
||||
pong.favicon(favicon);
|
||||
}
|
||||
|
||||
if (cfg.isDisablePlayerListHover()) {
|
||||
pong.clearSamplePlayers();
|
||||
}
|
||||
|
||||
ping.setPing(pong.build());
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -2,6 +2,7 @@ package xyz.jpenilla.minimotd.velocity;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -65,7 +66,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
}
|
||||
|
||||
private void sendMessages(Invocation invocation, List<String> messages) {
|
||||
messages.forEach(message -> invocation.source().sendMessage(miniMOTD.getMiniMessage().parse(message)));
|
||||
messages.forEach(message -> invocation.source().sendMessage(Identity.nil(), miniMOTD.getMiniMessage().parse(message)));
|
||||
}
|
||||
|
||||
private static final List<String> COMMANDS = ImmutableList.of("about", "reload", "help");
|
||||
@@ -0,0 +1,79 @@
|
||||
package xyz.jpenilla.minimotd.velocity;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.velocitypowered.api.util.Favicon;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class VelocityConfig extends MiniMOTDConfig<Favicon> {
|
||||
private final MiniMOTD miniMOTD;
|
||||
|
||||
public VelocityConfig(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
try {
|
||||
Files.createDirectories(miniMOTD.getDataDirectory());
|
||||
} catch (IOException e) {
|
||||
miniMOTD.getLogger().warn("unable to create config directory", e);
|
||||
}
|
||||
|
||||
final File file = new File(miniMOTD.getDataDirectory().toFile().getPath() + File.separator + "config.yml");
|
||||
if (!file.exists()) {
|
||||
try (InputStream in = miniMOTD.getClass().getClassLoader().getResourceAsStream("config.yml")) {
|
||||
Files.copy(in, file.toPath());
|
||||
} catch (IOException e) {
|
||||
miniMOTD.getLogger().warn("unable to copy default config file.", e);
|
||||
}
|
||||
}
|
||||
|
||||
final YAMLConfigurationLoader loader = YAMLConfigurationLoader.builder().setFile(file).build();
|
||||
|
||||
final ConfigurationNode node;
|
||||
try {
|
||||
node = loader.load();
|
||||
} catch (IOException e) {
|
||||
miniMOTD.getLogger().warn("unable to load config file.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
final ConfigurationNode motd = node.getNode("motd");
|
||||
final ConfigurationNode maxPlayersNode = node.getNode("maxPlayers");
|
||||
final ConfigurationNode bungeeOnly = node.getNode("bungeeOnly");
|
||||
|
||||
try {
|
||||
motds.clear();
|
||||
motds.addAll(motd.getNode("motds").getList(TypeToken.of(String.class)));
|
||||
motdEnabled = motd.getNode("motdEnabled").getBoolean() && !motds.isEmpty();
|
||||
maxPlayersEnabled = maxPlayersNode.getNode("maxPlayersEnabled").getBoolean();
|
||||
justXMoreEnabled = maxPlayersNode.getNode("justXMoreEnabled").getBoolean();
|
||||
maxPlayers = maxPlayersNode.getNode("maxPlayers").getInt();
|
||||
xValue = maxPlayersNode.getNode("xValue").getInt();
|
||||
fakePlayersEnabled = bungeeOnly.getNode("fakePlayersEnabled").getBoolean();
|
||||
fakePlayers = bungeeOnly.getNode("fakePlayers").getString();
|
||||
updateChecker = node.getNode(UPDATE_CHECKER).getBoolean();
|
||||
disablePlayerListHover = bungeeOnly.getNode("disablePlayerListHover").getBoolean();
|
||||
} catch (ObjectMappingException e) {
|
||||
miniMOTD.getLogger().warn("unable to load config.", e);
|
||||
}
|
||||
|
||||
final File iconFolder = new File(miniMOTD.getDataDirectory().toFile().getPath() + File.separator + "icons");
|
||||
this.loadIcons(iconFolder).forEach(miniMOTD.getLogger()::info);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull Favicon createIcon(final @NonNull BufferedImage bufferedImage) {
|
||||
return Favicon.create(bufferedImage);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user