mirror of
https://github.com/jpenilla/MiniMOTD.git
synced 2026-11-07 01:42:36 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7741523e56 | ||
|
|
f858f29d67 |
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD</artifactId>
|
||||
<version>1.1.7</version>
|
||||
<version>1.2.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MiniMOTD</name>
|
||||
@@ -133,9 +133,9 @@
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<groupId>com.github.jmanpenilla</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<version>2cb5077c9d</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.DiamondDagger590</groupId>
|
||||
|
||||
@@ -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,28 @@ public class BungeeConfig extends MiniMOTDConfig {
|
||||
setXValue(config.getInt(X_VALUE));
|
||||
setFakePlayersEnabled(config.getBoolean(FAKE_PLAYERS_ENABLED));
|
||||
setFakePlayers(config.getString(FAKE_PLAYERS));
|
||||
|
||||
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() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
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;
|
||||
@@ -64,6 +65,10 @@ public class PingListener implements Listener {
|
||||
}
|
||||
|
||||
response.setPlayers(players);
|
||||
final Favicon favicon = cfg.getRandomIcon();
|
||||
if (favicon != null) {
|
||||
response.setFavicon(favicon);
|
||||
}
|
||||
e.setResponse(response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ 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;
|
||||
|
||||
@@ -55,5 +56,9 @@ public class PaperPingListener implements Listener {
|
||||
e.setMotd(serializer.serialize(motd));
|
||||
}
|
||||
}
|
||||
final CachedServerIcon favicon = cfg.getRandomIcon();
|
||||
if (favicon != null) {
|
||||
e.setServerIcon(favicon);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ 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;
|
||||
@@ -33,5 +34,9 @@ public class PingListener implements Listener {
|
||||
e.setMotd(legacySerializer.serialize(miniMessage.parse(cfg.getMOTD(onlinePlayers, maxPlayers))));
|
||||
}
|
||||
}
|
||||
final CachedServerIcon favicon = cfg.getRandomIcon();
|
||||
if (favicon != null) {
|
||||
e.setServerIcon(favicon);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,20 @@
|
||||
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;
|
||||
@@ -12,6 +22,13 @@ public class SpigotConfig extends MiniMOTDConfig {
|
||||
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();
|
||||
@@ -33,5 +50,27 @@ public class SpigotConfig extends MiniMOTDConfig {
|
||||
setXValue(config.getInt(X_VALUE));
|
||||
setFakePlayersEnabled(config.getBoolean(FAKE_PLAYERS_ENABLED));
|
||||
setFakePlayers(config.getString(FAKE_PLAYERS));
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user