Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60b83031ab | ||
|
|
2a750c289b | ||
|
|
0092a2b6b7 | ||
|
|
0847d15eef | ||
|
|
c9d2f3fdb7 | ||
|
|
db0ea2e656 | ||
|
|
7741523e56 | ||
|
|
f858f29d67 | ||
|
|
725855124c |
No files matched your search
@@ -1,6 +0,0 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "maven"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
@@ -13,14 +13,13 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: sed "s/{BUILDID}/$GITHUB_RUN_NUMBER/g" pom.xml > _pom.xml; rm pom.xml; mv _pom.xml pom.xml
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- name: Build with Maven
|
||||
run: mvn clean package
|
||||
- run: mkdir staging && cp target/MiniMOTD*.jar staging
|
||||
- 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
|
||||
with:
|
||||
name: Package
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
<?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>
|
||||
+10
-8
@@ -11,10 +11,12 @@ import java.util.List;
|
||||
|
||||
public class BungeeCommand extends Command {
|
||||
private final MiniMOTD miniMOTD;
|
||||
private final MiniMessage miniMessage;
|
||||
|
||||
public BungeeCommand(MiniMOTD miniMOTD) {
|
||||
super("minimotdbungee");
|
||||
this.miniMOTD = miniMOTD;
|
||||
this.miniMessage = MiniMessage.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,11 +47,11 @@ public class BungeeCommand extends Command {
|
||||
}
|
||||
|
||||
private void onHelp(CommandSender sender, String[] args) {
|
||||
final ArrayList<String> messages = new ArrayList<String>();
|
||||
final List<String> messages = new ArrayList<>();
|
||||
messages.add("<gradient:blue:green>MiniMOTD Commands:");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd about'><click:run_command:/minimotd about><yellow>/minimotd about");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd reload'><click:run_command:/minimotd reload><yellow>/minimotd reload");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd help'><click:run_command:/minimotd help><yellow>/minimotd help");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd about'><click:run_command:/minimotdbungee about><yellow>/minimotdbungee about");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd reload'><click:run_command:/minimotdbungee reload><yellow>/minimotdbungee reload");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd help'><click:run_command:/minimotdbungee help><yellow>/minimotdbungee help");
|
||||
send(sender, messages);
|
||||
}
|
||||
|
||||
@@ -62,14 +64,14 @@ public class BungeeCommand extends Command {
|
||||
final ArrayList<String> messages = new ArrayList<>();
|
||||
final String header = "<gradient:white:black>=============</gradient><gradient:black:white>=============";
|
||||
messages.add(header);
|
||||
messages.add("<hover:show_text:'<rainbow>click me!'><click:open_url:https://www.spigotmc.org/resources/minimotd.81254/>" + miniMOTD.getDescription().getName() + " <gradient:red:yellow>" + miniMOTD.getDescription().getVersion());
|
||||
messages.add("<hover:show_text:'<rainbow>click me!'><click:open_url:https://github.com/jmanpenilla/MiniMOTD/>" + miniMOTD.getDescription().getName() + " <gradient:red:yellow>" + miniMOTD.getDescription().getVersion());
|
||||
messages.add("<yellow>By</yellow><gray>:</gray> <gradient:blue:green>jmp");
|
||||
messages.add(header);
|
||||
send(sender, messages);
|
||||
}
|
||||
|
||||
private void onInvalidUse(CommandSender sender, String[] args) {
|
||||
send(sender, "<hover:show_text:'<green>Click for <yellow>/minimotd help'><click:run_command:/minimotd help><italic><gradient:red:gold>Invalid usage.</gradient> <blue>Try <yellow>/minimotd help</yellow> or click here");
|
||||
send(sender, "<hover:show_text:'<green>Click for <yellow>/minimotdbungee help'><click:run_command:/minimotdbungee help><italic><gradient:red:gold>Invalid usage.</gradient> <blue>Try <yellow>/minimotdbungee help</yellow> or click here");
|
||||
}
|
||||
|
||||
private void onNoPermission(CommandSender sender, String[] args) {
|
||||
@@ -81,9 +83,9 @@ public class BungeeCommand extends Command {
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
finalMessage = message;
|
||||
} else {
|
||||
finalMessage = MiniMessage.get().stripTokens(message);
|
||||
finalMessage = miniMessage.stripTokens(message);
|
||||
}
|
||||
sender.sendMessage(BungeeCordComponentSerializer.get().serialize(MiniMessage.get().parse(finalMessage)));
|
||||
sender.sendMessage(BungeeCordComponentSerializer.get().serialize(miniMessage.parse(finalMessage)));
|
||||
}
|
||||
|
||||
private void send(CommandSender sender, List<String> messages) {
|
||||
+37
@@ -1,23 +1,37 @@
|
||||
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();
|
||||
|
||||
@@ -30,6 +44,29 @@ public class BungeeConfig extends MiniMOTDConfig {
|
||||
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() {
|
||||
@@ -0,0 +1,29 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||
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;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.audiences = BungeeAudiences.create(this);
|
||||
this.cfg = new BungeeConfig(this);
|
||||
getProxy().getPluginManager().registerListener(this, new PingListener(this));
|
||||
getProxy().getPluginManager().registerCommand(this, new BungeeCommand(this));
|
||||
Metrics metrics = new Metrics(this, 8137);
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-6
@@ -2,12 +2,13 @@ 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.legacy.LegacyComponentSerializer;
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
@@ -17,7 +18,6 @@ public class PingListener implements Listener {
|
||||
private final BungeeConfig cfg;
|
||||
private final MiniMessage miniMessage = MiniMessage.get();
|
||||
private final LegacyComponentSerializer legacySerializer = LegacyComponentSerializer.builder().build();
|
||||
private final GsonComponentSerializer gsonSerializer = GsonComponentSerializer.builder().build();
|
||||
|
||||
public PingListener(MiniMOTD miniMOTD) {
|
||||
this.cfg = miniMOTD.getCfg();
|
||||
@@ -50,7 +50,7 @@ public class PingListener implements Listener {
|
||||
}
|
||||
players.setOnline(onlinePlayers);
|
||||
|
||||
int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, players.getMax());
|
||||
final int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, players.getMax());
|
||||
players.setMax(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
@@ -58,12 +58,14 @@ public class PingListener implements Listener {
|
||||
if (e.getConnection().getVersion() < 735) {
|
||||
motd = legacySerializer.deserialize(legacySerializer.serialize(motd));
|
||||
}
|
||||
|
||||
response.setDescriptionComponent(ComponentSerializer.parse(gsonSerializer.serialize(motd))[0]);
|
||||
//response.setDescriptionComponent(BungeeCordComponentSerializer.get().serialize(motd)[0]);
|
||||
response.setDescriptionComponent(BungeeCordComponentSerializer.get().serialize(motd)[0]);
|
||||
}
|
||||
|
||||
response.setPlayers(players);
|
||||
final Favicon favicon = cfg.getRandomIcon();
|
||||
if (favicon != null) {
|
||||
response.setFavicon(favicon);
|
||||
}
|
||||
e.setResponse(response);
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,73 @@
|
||||
<?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>
|
||||
+2
@@ -17,6 +17,7 @@ public abstract class MiniMOTDConfig {
|
||||
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;
|
||||
@@ -25,6 +26,7 @@ public abstract class MiniMOTDConfig {
|
||||
@Getter @Setter private int xValue;
|
||||
@Getter @Setter private int maxPlayers;
|
||||
@Getter @Setter private String fakePlayers;
|
||||
@Getter @Setter private boolean updateChecker;
|
||||
|
||||
public abstract void reload();
|
||||
|
||||
@@ -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.*;
|
||||
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,3 +1,7 @@
|
||||
# Do you want the plugin to check for updated on GitHub on launch?
|
||||
# https://github.com/jmanpenilla/MiniMOTD
|
||||
updateChecker: true
|
||||
|
||||
motd:
|
||||
# Do you want to enable this feature?
|
||||
motdEnabled: true
|
||||
@@ -21,7 +25,8 @@ maxPlayers:
|
||||
justXMoreEnabled: false
|
||||
xValue: 3
|
||||
|
||||
# These options work on Paper Servers as well as BungeeCord or Waterfall based proxies
|
||||
# These options work on Paper Servers, BungeeCord or Waterfall based proxies,
|
||||
# and Velocity proxies.
|
||||
# These options do not work on pure Spigot Servers as the API methods are missing
|
||||
# Get Paper here: https://papermc.io/downloads
|
||||
bungeeOnly:
|
||||
@@ -0,0 +1,130 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,64 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
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;
|
||||
@Getter private PrismaHook prisma;
|
||||
@Getter private boolean isPaperServer;
|
||||
@Getter private String serverPackageName;
|
||||
@Getter private String serverApiVersion;
|
||||
@Getter private int majorMinecraftVersion;
|
||||
@Getter private BukkitAudiences audiences;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
serverPackageName = this.getServer().getClass().getPackage().getName();
|
||||
serverApiVersion = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1);
|
||||
majorMinecraftVersion = Integer.parseInt(serverApiVersion.split("_")[1]);
|
||||
|
||||
try {
|
||||
Class.forName("com.destroystokyo.paper.event.server.PaperServerListPingEvent");
|
||||
isPaperServer = true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
isPaperServer = false;
|
||||
}
|
||||
instance = this;
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Prisma")) {
|
||||
prisma = new PrismaHook();
|
||||
}
|
||||
this.cfg = new SpigotConfig(this);
|
||||
if (isPaperServer) {
|
||||
getServer().getPluginManager().registerEvents(new PaperPingListener(this), this);
|
||||
} else {
|
||||
getServer().getPluginManager().registerEvents(new PingListener(this), this);
|
||||
if (majorMinecraftVersion > 11) {
|
||||
getLogger().info("This server is not using Paper, and therefore some features may be limited or disabled.");
|
||||
getLogger().info("Get Paper from https://papermc.io/downloads");
|
||||
}
|
||||
}
|
||||
this.audiences = BukkitAudiences.create(this);
|
||||
final PluginCommand command = getCommand("minimotd");
|
||||
if (command != null) {
|
||||
command.setExecutor(new SpigotCommand(this));
|
||||
command.setTabCompleter(new SpigotCommand(this));
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-2
@@ -6,17 +6,20 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class PaperPingListener implements Listener {
|
||||
private final SpigotConfig cfg;
|
||||
private final MiniMOTD miniMOTD;
|
||||
private final LegacyComponentSerializer serializer = LegacyComponentSerializer.builder().hexColors().useUnusualXRepeatedCharacterHexFormat().build();
|
||||
private final MiniMessage miniMessage = MiniMessage.get();
|
||||
private final LegacyComponentSerializer legacySerializer = LegacyComponentSerializer.builder().build();
|
||||
|
||||
public PaperPingListener(MiniMOTD miniMOTD) {
|
||||
this.cfg = miniMOTD.getCfg();
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -42,16 +45,20 @@ public class PaperPingListener implements Listener {
|
||||
}
|
||||
e.setNumPlayers(onlinePlayers);
|
||||
|
||||
int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, e.getMaxPlayers());
|
||||
final int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, e.getMaxPlayers());
|
||||
e.setMaxPlayers(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
final Component motd = miniMessage.parse(cfg.getMOTD(onlinePlayers, maxPlayers));
|
||||
if (e.getClient().getProtocolVersion() < 735) {
|
||||
if (e.getClient().getProtocolVersion() < 735 || miniMOTD.getMajorMinecraftVersion() < 16) {
|
||||
e.setMotd(legacySerializer.serialize(motd));
|
||||
} else {
|
||||
e.setMotd(serializer.serialize(motd));
|
||||
}
|
||||
}
|
||||
final CachedServerIcon favicon = cfg.getRandomIcon();
|
||||
if (favicon != null) {
|
||||
e.setServerIcon(favicon);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -5,14 +5,18 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
|
||||
public class PingListener implements Listener {
|
||||
private final SpigotConfig cfg;
|
||||
private final MiniMOTD miniMOTD;
|
||||
private final LegacyComponentSerializer serializer = LegacyComponentSerializer.builder().hexColors().useUnusualXRepeatedCharacterHexFormat().build();
|
||||
private final LegacyComponentSerializer legacySerializer = LegacyComponentSerializer.builder().build();
|
||||
private final MiniMessage miniMessage = MiniMessage.get();
|
||||
|
||||
public PingListener(MiniMOTD miniMOTD) {
|
||||
this.cfg = miniMOTD.getCfg();
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -24,7 +28,15 @@ public class PingListener implements Listener {
|
||||
e.setMaxPlayers(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
e.setMotd(serializer.serialize(miniMessage.parse(cfg.getMOTD(onlinePlayers, maxPlayers))));
|
||||
if (miniMOTD.getMajorMinecraftVersion() > 15) {
|
||||
e.setMotd(serializer.serialize(miniMessage.parse(cfg.getMOTD(onlinePlayers, maxPlayers))));
|
||||
} else {
|
||||
e.setMotd(legacySerializer.serialize(miniMessage.parse(cfg.getMOTD(onlinePlayers, maxPlayers))));
|
||||
}
|
||||
}
|
||||
final CachedServerIcon favicon = cfg.getRandomIcon();
|
||||
if (favicon != null) {
|
||||
e.setServerIcon(favicon);
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+31
-18
@@ -1,24 +1,25 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import lombok.NonNull;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SpigotCommand implements CommandExecutor {
|
||||
public class SpigotCommand implements CommandExecutor, TabCompleter {
|
||||
private final MiniMOTD miniMOTD;
|
||||
private final BukkitAudiences audience;
|
||||
private final MiniMessage miniMessage;
|
||||
|
||||
public SpigotCommand(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
audience = BukkitAudiences.create(miniMOTD);
|
||||
miniMessage = MiniMessage.get();
|
||||
}
|
||||
|
||||
@@ -51,12 +52,12 @@ public class SpigotCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
private void onHelp(CommandSender sender, String[] args) {
|
||||
final ArrayList<String> messages = new ArrayList<>();
|
||||
messages.add("<gradient:blue:green>MiniMOTD Commands:");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd about'><click:run_command:/minimotd about><yellow>/minimotd about");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd reload'><click:run_command:/minimotd reload><yellow>/minimotd reload");
|
||||
messages.add(" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd help'><click:run_command:/minimotd help><yellow>/minimotd help");
|
||||
send(sender, messages);
|
||||
send(sender, ImmutableList.of(
|
||||
"<gradient:blue:green>MiniMOTD Commands:",
|
||||
" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd about'><click:run_command:/minimotd about><yellow>/minimotd about",
|
||||
" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd reload'><click:run_command:/minimotd reload><yellow>/minimotd reload",
|
||||
" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotd help'><click:run_command:/minimotd help><yellow>/minimotd help"
|
||||
));
|
||||
}
|
||||
|
||||
private void onReload(CommandSender sender, String[] args) {
|
||||
@@ -65,13 +66,13 @@ public class SpigotCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
private void onAbout(CommandSender sender, String[] args) {
|
||||
final ArrayList<String> messages = new ArrayList<>();
|
||||
final String header = "<gradient:white:black>=============</gradient><gradient:black:white>=============";
|
||||
messages.add(header);
|
||||
messages.add("<hover:show_text:'<rainbow>click me!'><click:open_url:" + miniMOTD.getDescription().getWebsite() + ">" + miniMOTD.getName() + " <gradient:red:yellow>" + miniMOTD.getDescription().getVersion());
|
||||
messages.add("<yellow>By</yellow><gray>:</gray> <gradient:blue:green>jmp");
|
||||
messages.add(header);
|
||||
send(sender, messages);
|
||||
send(sender, ImmutableList.of(
|
||||
header,
|
||||
"<hover:show_text:'<rainbow>click me!'><click:open_url:" + miniMOTD.getDescription().getWebsite() + ">" + miniMOTD.getName() + " <gradient:red:yellow>" + miniMOTD.getDescription().getVersion(),
|
||||
"<yellow>By</yellow><gray>:</gray> <gradient:blue:green>jmp",
|
||||
header
|
||||
));
|
||||
}
|
||||
|
||||
private void onInvalidUse(CommandSender sender, String[] args) {
|
||||
@@ -84,9 +85,9 @@ public class SpigotCommand implements CommandExecutor {
|
||||
|
||||
private void send(@NonNull CommandSender sender, @NonNull String message) {
|
||||
if (sender instanceof Player) {
|
||||
audience.player((Player) sender).sendMessage(miniMessage.parse(message));
|
||||
miniMOTD.getAudiences().player((Player) sender).sendMessage(miniMessage.parse(message));
|
||||
} else {
|
||||
audience.console().sendMessage(miniMessage.parse(miniMessage.stripTokens(message)));
|
||||
miniMOTD.getAudiences().console().sendMessage(miniMessage.parse(miniMessage.stripTokens(message)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,4 +96,16 @@ public class SpigotCommand implements CommandExecutor {
|
||||
send(sender, message);
|
||||
}
|
||||
}
|
||||
|
||||
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<>();
|
||||
if (args.length < 2 && sender.hasPermission("minimotd.admin")) {
|
||||
StringUtil.copyPartialMatches(args[0], COMMANDS, completions);
|
||||
Collections.sort(completions);
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,11 @@ 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://www.spigotmc.org/resources/minimotd.81254/
|
||||
website: https://github.com/jmanpenilla/MiniMOTD/
|
||||
commands:
|
||||
minimotd:
|
||||
description: MiniMOTD command
|
||||
permission-message:
|
||||
permission-message: No permission
|
||||
usage: /minimotd help
|
||||
@@ -0,0 +1,68 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,225 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,112 @@
|
||||
package xyz.jpenilla.minimotd.velocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.PluginDescription;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import com.velocitypowered.api.util.Favicon;
|
||||
import lombok.Getter;
|
||||
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.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/",
|
||||
authors = {"jmp"}
|
||||
)
|
||||
public class MiniMOTD {
|
||||
@Getter private final ProxyServer server;
|
||||
@Getter private final Logger logger;
|
||||
@Getter private final MiniMessage miniMessage = MiniMessage.get();
|
||||
@Getter private PluginDescription pluginDescription;
|
||||
@Getter private VelocityConfig cfg;
|
||||
private final LegacyComponentSerializer legacySerializer = LegacyComponentSerializer.builder().build();
|
||||
|
||||
@Inject private CommandManager commandManager;
|
||||
|
||||
@Getter
|
||||
@Inject
|
||||
@DataDirectory
|
||||
private Path dataDirectory;
|
||||
|
||||
@Inject
|
||||
public MiniMOTD(ProxyServer server, Logger logger) {
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
this.server.getPluginManager().fromInstance(this).ifPresent(container -> this.pluginDescription = container.getDescription());
|
||||
this.cfg = new VelocityConfig(this);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onServerListPing(ProxyPingEvent ping) {
|
||||
final ServerPing.Builder pong = ping.getPing().asBuilder();
|
||||
|
||||
int onlinePlayers = pong.getOnlinePlayers();
|
||||
if (cfg.isFakePlayersEnabled()) {
|
||||
try {
|
||||
if (cfg.getFakePlayers().contains(":")) {
|
||||
final String[] fakePlayers = cfg.getFakePlayers().split(":");
|
||||
final int start = Integer.parseInt(fakePlayers[0]);
|
||||
final int end = Integer.parseInt(fakePlayers[1]);
|
||||
onlinePlayers = onlinePlayers + ThreadLocalRandom.current().nextInt(start, end);
|
||||
} else if (cfg.getFakePlayers().contains("%")) {
|
||||
final double factor = 1 + (Double.parseDouble(cfg.getFakePlayers().replace("%", "")) / 100);
|
||||
onlinePlayers = (int) Math.ceil(factor * onlinePlayers);
|
||||
} else {
|
||||
final int addedPlayers = Integer.parseInt(cfg.getFakePlayers());
|
||||
onlinePlayers = onlinePlayers + addedPlayers;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
logger.info("fakePlayers config incorrect");
|
||||
}
|
||||
}
|
||||
pong.onlinePlayers(onlinePlayers);
|
||||
|
||||
int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, pong.getMaximumPlayers());
|
||||
pong.maximumPlayers(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
Component motd = miniMessage.parse(cfg.getMOTD(onlinePlayers, maxPlayers));
|
||||
if (pong.getVersion().getProtocol() < 735) {
|
||||
motd = legacySerializer.deserialize(legacySerializer.serialize(motd));
|
||||
}
|
||||
pong.description(motd);
|
||||
}
|
||||
|
||||
final Favicon favicon = cfg.getRandomIcon();
|
||||
if (favicon != null) {
|
||||
pong.favicon(favicon);
|
||||
}
|
||||
|
||||
ping.setPing(pong.build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package xyz.jpenilla.minimotd.velocity;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VelocityCommand implements SimpleCommand {
|
||||
private final MiniMOTD miniMOTD;
|
||||
|
||||
public VelocityCommand(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
final String[] args = invocation.arguments();
|
||||
|
||||
if (args.length == 0) {
|
||||
onInvalidUse(invocation);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
case "about":
|
||||
onAbout(invocation);
|
||||
return;
|
||||
case "help":
|
||||
onHelp(invocation);
|
||||
return;
|
||||
case "reload":
|
||||
onReload(invocation);
|
||||
return;
|
||||
}
|
||||
|
||||
onInvalidUse(invocation);
|
||||
}
|
||||
|
||||
private void onInvalidUse(Invocation invocation) {
|
||||
sendMessages(invocation, ImmutableList.of("<hover:show_text:'<green>Click for <yellow>/minimotdvelocity help'><click:run_command:/minimotdvelocity help><italic><gradient:red:gold>Invalid usage.</gradient> <blue>Try <yellow>/minimotdvelocity help</yellow> or click here"));
|
||||
}
|
||||
|
||||
private void onReload(Invocation invocation) {
|
||||
miniMOTD.getCfg().reload();
|
||||
sendMessages(invocation, ImmutableList.of("<green>Done reloading."));
|
||||
}
|
||||
|
||||
private void onHelp(Invocation invocation) {
|
||||
sendMessages(invocation, ImmutableList.of(
|
||||
"<gradient:blue:green>MiniMOTD Commands:",
|
||||
" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotdvelocity about'><click:run_command:/minimotd about><yellow>/minimotdvelocity about",
|
||||
" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotdvelocity reload'><click:run_command:/minimotd reload><yellow>/minimotdvelocity reload",
|
||||
" <gray>-</gray> <hover:show_text:'<green>Click for <yellow>/minimotdvelocity help'><click:run_command:/minimotd help><yellow>/minimotdvelocity help"
|
||||
));
|
||||
}
|
||||
|
||||
private void onAbout(Invocation invocation) {
|
||||
final String header = "<gradient:white:black>=============</gradient><gradient:black:white>=============";
|
||||
sendMessages(invocation, ImmutableList.of(
|
||||
header,
|
||||
"<hover:show_text:'<rainbow>click me!'><click:open_url:" + miniMOTD.getPluginDescription().getUrl().orElse("") + ">" + miniMOTD.getPluginDescription().getName().orElse("") + " <gradient:red:yellow>" + miniMOTD.getPluginDescription().getVersion().orElse(""),
|
||||
"<yellow>By</yellow><gray>:</gray> <gradient:blue:green>jmp",
|
||||
header
|
||||
));
|
||||
}
|
||||
|
||||
private void sendMessages(Invocation invocation, List<String> messages) {
|
||||
messages.forEach(message -> invocation.source().sendMessage(miniMOTD.getMiniMessage().parse(message)));
|
||||
}
|
||||
|
||||
private static final List<String> COMMANDS = ImmutableList.of("about", "reload", "help");
|
||||
|
||||
@Override
|
||||
public List<String> suggest(Invocation invocation) {
|
||||
return COMMANDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Invocation invocation) {
|
||||
return invocation.source().hasPermission("minimotd.admin");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
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()));
|
||||
}
|
||||
}
|
||||
@@ -6,17 +6,15 @@
|
||||
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD</artifactId>
|
||||
<version>1.1.6</version>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.2.1</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>MiniMOTD</name>
|
||||
<name>MiniMOTD Parent</name>
|
||||
|
||||
<description>Set the server list MOTD using MiniMessage!</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<url>https://spigotmc.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
@@ -29,143 +27,14 @@
|
||||
<target>${java.version}</target>
|
||||
</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>org.apache.commons.io</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.apachecommonsio</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>xyz.jpenilla.jmplib</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.jmplib</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.kyori.examination</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.kyori.examination</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.kyori.adventure</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.kyori.adventure</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.checkerframework</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.checkerframework</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>CodeMC</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.destroystokyo.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.16-R0.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-bungeecord</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.DiamondDagger590</groupId>
|
||||
<artifactId>Prisma</artifactId>
|
||||
<version>a622d01b80</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.12</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bungeecord</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<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,5 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
]
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
|
||||
public class MiniMOTD extends Plugin {
|
||||
@Getter private BungeeConfig cfg;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.cfg = new BungeeConfig(this);
|
||||
getProxy().getPluginManager().registerListener(this, new PingListener(this));
|
||||
getProxy().getPluginManager().registerCommand(this, new BungeeCommand(this));
|
||||
Metrics metrics = new Metrics(this, 8137);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class MiniMOTD extends JavaPlugin {
|
||||
@Getter private static MiniMOTD instance;
|
||||
@Getter private SpigotConfig cfg;
|
||||
@Getter private PrismaHook prisma;
|
||||
@Getter private boolean isPaperServer;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
try {
|
||||
Class.forName("com.destroystokyo.paper.PaperConfig");
|
||||
isPaperServer = true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
isPaperServer = false;
|
||||
}
|
||||
instance = this;
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Prisma")) {
|
||||
prisma = new PrismaHook();
|
||||
}
|
||||
this.cfg = new SpigotConfig(this);
|
||||
if (isPaperServer) {
|
||||
getServer().getPluginManager().registerEvents(new PaperPingListener(this), this);
|
||||
} else {
|
||||
getServer().getPluginManager().registerEvents(new PingListener(this), this);
|
||||
}
|
||||
final PluginCommand command = getCommand("minimotd");
|
||||
if (command != null) {
|
||||
command.setExecutor(new SpigotCommand(this));
|
||||
}
|
||||
|
||||
Metrics metrics = new Metrics(this, 8132);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
public class SpigotConfig extends MiniMOTDConfig {
|
||||
private final MiniMOTD miniMOTD;
|
||||
|
||||
public SpigotConfig(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
miniMOTD.saveDefaultConfig();
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
miniMOTD.reloadConfig();
|
||||
final FileConfiguration config = miniMOTD.getConfig();
|
||||
|
||||
getMotds().clear();
|
||||
for (String motd : config.getStringList(MOTDS)) {
|
||||
final String temp;
|
||||
if (miniMOTD.getPrisma() != null) {
|
||||
temp = miniMOTD.getPrisma().translate(motd);
|
||||
} else {
|
||||
temp = motd;
|
||||
}
|
||||
getMotds().add(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));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user