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 | ||
|
|
60b83031ab | ||
|
|
2a750c289b | ||
|
|
0092a2b6b7 | ||
|
|
0847d15eef | ||
|
|
c9d2f3fdb7 | ||
|
|
db0ea2e656 | ||
|
|
7741523e56 | ||
|
|
f858f29d67 | ||
|
|
725855124c | ||
|
|
84f6f2b5d5 | ||
|
|
2e2fe64923 | ||
|
|
574eca67e2 | ||
|
|
6556e92e5e | ||
|
|
91a6973288 | ||
|
|
afd3de54ed | ||
|
|
b9c3f505eb | ||
|
|
bcc15def17 | ||
|
|
ef1b13d08f | ||
|
|
7edccb6ea4 | ||
|
|
c87f3c4321 | ||
|
|
4aff316770 | ||
|
|
702a6a7d66 | ||
|
|
6ffce0713f | ||
|
|
ac1dea2867 |
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.
|
||||
@@ -0,0 +1,26 @@
|
||||
name: MiniMOTD
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- 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,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"
|
||||
}
|
||||
+11
-19
@@ -1,10 +1,8 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ConnectedPlayer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -12,12 +10,12 @@ import java.util.List;
|
||||
|
||||
public class BungeeCommand extends Command {
|
||||
private final MiniMOTD miniMOTD;
|
||||
private final BungeeAudiences audience;
|
||||
private final MiniMessage miniMessage;
|
||||
|
||||
public BungeeCommand(MiniMOTD miniMOTD) {
|
||||
super("minimotd");
|
||||
super("minimotdbungee");
|
||||
this.miniMOTD = miniMOTD;
|
||||
this.audience = BungeeAudiences.create(miniMOTD);
|
||||
this.miniMessage = MiniMessage.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,11 +46,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);
|
||||
}
|
||||
|
||||
@@ -65,14 +63,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) {
|
||||
@@ -80,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.get().stripTokens(message);
|
||||
}
|
||||
audience.audience(sender).sendMessage(MiniMessage.get().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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -1,17 +1,26 @@
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
if (cfg.isUpdateChecker()) {
|
||||
getProxy().getScheduler().runAsync(this, () ->
|
||||
new UpdateChecker(this.getDescription().getVersion()).checkVersion().forEach(getLogger()::info));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
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.BungeeComponentSerializer;
|
||||
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.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();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPing(ProxyPingEvent e) {
|
||||
final ServerPing response = e.getResponse();
|
||||
|
||||
if (response != null) {
|
||||
final ServerPing.Players players = response.getPlayers();
|
||||
int onlinePlayers = players.getOnline();
|
||||
if (cfg.isFakePlayersEnabled()) {
|
||||
try {
|
||||
if (cfg.getFakePlayers().contains(":")) {
|
||||
final String[] fakePlayers = cfg.getFakePlayers().split(":");
|
||||
final int start = Integer.parseInt(fakePlayers[0]);
|
||||
final int end = Integer.parseInt(fakePlayers[1]);
|
||||
onlinePlayers = onlinePlayers + ThreadLocalRandom.current().nextInt(start, end);
|
||||
} else if (cfg.getFakePlayers().contains("%")) {
|
||||
final double factor = 1 + (Double.parseDouble(cfg.getFakePlayers().replace("%", "")) / 100);
|
||||
onlinePlayers = (int) Math.ceil(factor * onlinePlayers);
|
||||
} else {
|
||||
final int addedPlayers = Integer.parseInt(cfg.getFakePlayers());
|
||||
onlinePlayers = onlinePlayers + addedPlayers;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
miniMOTD.getLogger().warning("fakePlayers config invalid");
|
||||
}
|
||||
}
|
||||
players.setOnline(onlinePlayers);
|
||||
|
||||
final int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, players.getMax());
|
||||
players.setMax(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) {
|
||||
motdComponent = legacySerializer.deserialize(legacySerializer.serialize(motdComponent));
|
||||
}
|
||||
response.setDescriptionComponent(BungeeComponentSerializer.get().serialize(motdComponent)[0]);
|
||||
}
|
||||
|
||||
response.setPlayers(players);
|
||||
final Favicon favicon = motd.icon();
|
||||
if (favicon != null) {
|
||||
response.setFavicon(favicon);
|
||||
}
|
||||
e.setResponse(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
# Do you want the plugin to check for updates on GitHub at launch?
|
||||
# https://github.com/jmanpenilla/MiniMOTD
|
||||
updateChecker: true
|
||||
|
||||
motd:
|
||||
# Do you want to enable this feature?
|
||||
motdEnabled: true
|
||||
|
||||
# Placeholders: {onlinePlayers} {maxPlayers}
|
||||
# Use {br} to separate lines.
|
||||
# Putting more than one will cause one to be randomly chosen each refresh
|
||||
#
|
||||
# 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"
|
||||
|
||||
maxPlayers:
|
||||
# Do you want to enable this feature?
|
||||
maxPlayersEnabled: true
|
||||
|
||||
# Changes the Max Players value.
|
||||
maxPlayers: 69
|
||||
|
||||
# Changes the Max Players to X more than the online players
|
||||
# Example: 16/19 players online.
|
||||
justXMoreEnabled: false
|
||||
xValue: 3
|
||||
|
||||
# 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:
|
||||
# Do you want to enable this feature?
|
||||
fakePlayersEnabled: false
|
||||
|
||||
# Modes: static, random, percent
|
||||
# static: This many fake players will be added
|
||||
# ex: fakePlayers: "3"
|
||||
# random: A random number of fake players in this range will be added
|
||||
# ex: fakePlayers: "3:6"
|
||||
# percent: The player count will be inflated by this much, rounding up
|
||||
# ex: fakePlayers: "25%"
|
||||
fakePlayers: "25%"
|
||||
|
||||
# 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,166 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>xyz.jpenilla</groupId>
|
||||
<artifactId>MiniMOTD</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MiniMOTD</name>
|
||||
|
||||
<description>Set the server MOTD using MiniMessage!</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<url>https://spigotmc.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.apache.commons.io</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.apachecommonsio</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>xyz.jpenilla.jmplib</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.jmplib</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.kyori.examination</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.kyori.examination</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.kyori.adventure</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.kyori.adventure</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.checkerframework</pattern>
|
||||
<shadedPattern>xyz.jpenilla.minimotd.lib.checkerframework</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>CodeMC</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.16-R0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-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.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bungeecord</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
]
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
if (cfg.isUpdateChecker()) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, () ->
|
||||
new UpdateChecker(this.getDescription().getVersion()).checkVersion().forEach(getLogger()::info));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
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 xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
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
|
||||
public void onPing(PaperServerListPingEvent e) {
|
||||
int onlinePlayers = e.getNumPlayers();
|
||||
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) {
|
||||
miniMOTD.getLogger().warning("fakePlayers config invalid");
|
||||
}
|
||||
}
|
||||
e.setNumPlayers(onlinePlayers);
|
||||
|
||||
final int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, e.getMaxPlayers());
|
||||
e.setMaxPlayers(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(motdComponent));
|
||||
} else {
|
||||
e.setMotd(serializer.serialize(motdComponent));
|
||||
}
|
||||
}
|
||||
final CachedServerIcon favicon = motd.icon();
|
||||
if (favicon != null) {
|
||||
e.setServerIcon(favicon);
|
||||
}
|
||||
if (cfg.isDisablePlayerListHover()) {
|
||||
e.getPlayerSample().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
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.event.server.ServerListPingEvent;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
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
|
||||
public void onPing(ServerListPingEvent e) {
|
||||
final int onlinePlayers = e.getNumPlayers();
|
||||
final int actualMaxPlayers = e.getMaxPlayers();
|
||||
|
||||
final int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, actualMaxPlayers);
|
||||
e.setMaxPlayers(maxPlayers);
|
||||
|
||||
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(motdString)));
|
||||
} else {
|
||||
e.setMotd(legacySerializer.serialize(miniMessage.parse(motdString)));
|
||||
}
|
||||
}
|
||||
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 {
|
||||
+36
-21
@@ -1,29 +1,32 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import lombok.NonNull;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@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;
|
||||
@@ -51,12 +54,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 +68,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 +87,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(Identity.nil(), miniMessage.parse(message));
|
||||
} else {
|
||||
audience.console().sendMessage(miniMessage.parse(miniMessage.stripTokens(message)));
|
||||
miniMOTD.getAudiences().console().sendMessage(Identity.nil(), miniMessage.parse(message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,4 +98,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(final @NonNull CommandSender sender,
|
||||
final @NonNull Command command,
|
||||
final @NonNull String alias, String[] args) {
|
||||
if (args.length < 2 && sender.hasPermission("minimotd.admin")) {
|
||||
return COMMANDS;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class BungeeConfig extends MiniMOTDConfig {
|
||||
private final MiniMOTD miniMOTD;
|
||||
|
||||
public BungeeConfig(MiniMOTD miniMOTD) {
|
||||
this.miniMOTD = miniMOTD;
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
final Configuration config = loadFromDisk();
|
||||
|
||||
getMotds().clear();
|
||||
for (String motd : config.getStringList(MOTDS)) {
|
||||
getMotds().add(motd.replace("{br}", "\n"));
|
||||
}
|
||||
setMotdEnabled(config.getBoolean(MOTD_ENABLED));
|
||||
setMaxPlayersEnabled(config.getBoolean(MAX_PLAYERS_ENABLED));
|
||||
setJustXMoreEnabled(config.getBoolean(JUST_X_MORE_ENABLED));
|
||||
setMaxPlayers(config.getInt(MAX_PLAYERS));
|
||||
setXValue(config.getInt(X_VALUE));
|
||||
}
|
||||
|
||||
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,47 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.bungee;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
public class PingListener implements Listener {
|
||||
private final BungeeConfig cfg;
|
||||
|
||||
public PingListener(MiniMOTD miniMOTD) {
|
||||
this.cfg = miniMOTD.getCfg();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPing(ProxyPingEvent e) {
|
||||
final ServerPing response = e.getResponse();
|
||||
|
||||
if (response != null) {
|
||||
final ServerPing.Players players = response.getPlayers();
|
||||
int onlinePlayers = players.getOnline();
|
||||
/*if (cfg.isFakePlayersEnabled()) {
|
||||
onlinePlayers = onlinePlayers + cfg.getFakePlayersAmount(onlinePlayers);
|
||||
}*/
|
||||
players.setOnline(onlinePlayers);
|
||||
|
||||
int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, players.getMax());
|
||||
players.setMax(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
Component motd = MiniMessage.get().parse(cfg.getMOTD(onlinePlayers, maxPlayers));
|
||||
BaseComponent component = ComponentSerializer.parse(GsonComponentSerializer.builder().build().serialize(motd))[0];
|
||||
response.setDescriptionComponent(component);
|
||||
//response.setDescriptionComponent(BungeeCordComponentSerializer.get().serialize(motd)[0]);
|
||||
}
|
||||
|
||||
response.setPlayers(players);
|
||||
e.setResponse(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +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 {
|
||||
private final Random r = new Random();
|
||||
|
||||
@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 int xValue;
|
||||
@Getter @Setter private int maxPlayers;
|
||||
|
||||
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 abstract void reload();
|
||||
|
||||
public String getMOTD(int onlinePlayers, int maxPlayers) {
|
||||
if (motds.size() == 1) {
|
||||
return motds.get(0);
|
||||
} else {
|
||||
return motds.get(r.nextInt(motds.size()))
|
||||
.replace("{onlinePlayers}", String.valueOf(onlinePlayers))
|
||||
.replace("{maxPlayers}", String.valueOf(maxPlayers));
|
||||
}
|
||||
}
|
||||
|
||||
public int getAdjustedMaxPlayers(int onlinePlayers, int actualMaxPlayers) {
|
||||
if (maxPlayersEnabled) {
|
||||
return justXMoreEnabled ? onlinePlayers + xValue : maxPlayers;
|
||||
} else {
|
||||
return actualMaxPlayers;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.common;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MiniMessageUtil {
|
||||
public static String miniMessageToLegacy(String message) {
|
||||
return LegacyComponentSerializer.builder().hexColors().useUnusualXRepeatedCharacterHexFormat().build().serialize(MiniMessage.get().parse(message));
|
||||
}
|
||||
|
||||
public static List<String> miniMessageToLegacy(List<String> messages) {
|
||||
final List<String> l = new ArrayList<>();
|
||||
for (String message : messages) {
|
||||
l.add(miniMessageToLegacy(message));
|
||||
}
|
||||
return l;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class MiniMOTD extends JavaPlugin {
|
||||
@Getter private SpigotConfig cfg;
|
||||
@Getter private PrismaHook prisma;
|
||||
@Getter private static MiniMOTD instance;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Prisma")) {
|
||||
prisma = new PrismaHook();
|
||||
}
|
||||
this.cfg = new SpigotConfig(this);
|
||||
getServer().getPluginManager().registerEvents(new PingListener(this), this);
|
||||
getCommand("minimotd").setExecutor(new SpigotCommand(this));
|
||||
Metrics metrics = new Metrics(this, 8132);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
|
||||
public class PingListener implements Listener {
|
||||
private final SpigotConfig cfg;
|
||||
|
||||
public PingListener(MiniMOTD miniMOTD) {
|
||||
this.cfg = miniMOTD.getCfg();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPing(ServerListPingEvent e) {
|
||||
final int onlinePlayers = e.getNumPlayers();
|
||||
final int actualMaxPlayers = e.getMaxPlayers();
|
||||
|
||||
final int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, actualMaxPlayers);
|
||||
e.setMaxPlayers(maxPlayers);
|
||||
|
||||
if (cfg.isMotdEnabled()) {
|
||||
e.setMotd(cfg.getMOTD(onlinePlayers, maxPlayers));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package xyz.jpenilla.minimotd.spigot;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
|
||||
import xyz.jpenilla.minimotd.common.MiniMessageUtil;
|
||||
|
||||
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(MiniMessageUtil.miniMessageToLegacy(temp.replace("{br}", "\n")));
|
||||
}
|
||||
setMotdEnabled(config.getBoolean(MOTD_ENABLED));
|
||||
setMaxPlayersEnabled(config.getBoolean(MAX_PLAYERS_ENABLED));
|
||||
setJustXMoreEnabled(config.getBoolean(JUST_X_MORE_ENABLED));
|
||||
setMaxPlayers(config.getInt(MAX_PLAYERS));
|
||||
setXValue(config.getInt(X_VALUE));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
name: MiniMOTD
|
||||
version: ${project.version}
|
||||
main: xyz.jpenilla.minimotd.bungee.MiniMOTD
|
||||
author: jmp
|
||||
description: Set the MOTD using MiniMessage!
|
||||
@@ -1,22 +0,0 @@
|
||||
motd:
|
||||
# Do you want to enable this feature?
|
||||
motdEnabled: true
|
||||
|
||||
# Placeholders: {onlinePlayers} {maxPlayers}
|
||||
# Use {br} to separate lines.
|
||||
# Putting more than one will cause one to be randomly chosen each refresh
|
||||
motds:
|
||||
- "<bold><gradient:black:white>----====[</gradient> <gradient:green:blue>UltraCraft <gradient:red:yellow></bold><italic>Official</gradient></italic><bold> <gradient:white:black>]=====----</gradient></bold>{br}<bold> <gradient:#EEFF4A:#F7FFAE>Custom <italic>Survival</italic></gradient> <color:#0092FF>Discord</bold><gray>:</gray> <gradient:#5FDAFF:#B8A6FF><italic>Ab3d5f"
|
||||
- "<rainbow>|||||||||||||||||||||||||||||||||||||||||||||||||||||||||</rainbow>{br}<white>Hello <blue>{onlinePlayers} <gray>/</gray> {maxPlayers}</blue> Players Online"
|
||||
|
||||
maxPlayers:
|
||||
# Do you want to enable this feature?
|
||||
maxPlayersEnabled: true
|
||||
|
||||
# Changes the Max Players value.
|
||||
maxPlayers: 69
|
||||
|
||||
# Changes the Max Players to X more than the online players
|
||||
# Example: 16/19 players online.
|
||||
justXMoreEnabled: false
|
||||
xValue: 3
|
||||
@@ -1,13 +0,0 @@
|
||||
name: MiniMOTD
|
||||
version: ${project.version}
|
||||
main: xyz.jpenilla.minimotd.spigot.MiniMOTD
|
||||
load: STARTUP
|
||||
softdepend: [Prisma]
|
||||
authors: [jmp]
|
||||
description: Set the server MOTD using MiniMessage!
|
||||
website: https://www.spigotmc.org/resources/minimotd.81254/
|
||||
commands:
|
||||
minimotd:
|
||||
description: MiniMOTD command
|
||||
permission-message:
|
||||
usage: /minimotd help
|
||||
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
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.MiniMOTDConfig;
|
||||
import xyz.jpenilla.minimotd.common.UpdateChecker;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@Plugin(
|
||||
id = "{project.name}",
|
||||
name = "{rootProject.name}",
|
||||
version = "{version}",
|
||||
description = "{description}",
|
||||
url = "{url}",
|
||||
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();
|
||||
|
||||
if (cfg.isUpdateChecker()) {
|
||||
this.server.getScheduler().buildTask(this, () ->
|
||||
new UpdateChecker(this.getPluginDescription().getVersion().orElse("")).checkVersion().forEach(this.logger::info))
|
||||
.schedule();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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);
|
||||
|
||||
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) {
|
||||
motdComponent = legacySerializer.deserialize(legacySerializer.serialize(motdComponent));
|
||||
}
|
||||
pong.description(motdComponent);
|
||||
}
|
||||
|
||||
final Favicon favicon = motd.icon();
|
||||
if (favicon != null) {
|
||||
pong.favicon(favicon);
|
||||
}
|
||||
|
||||
if (cfg.isDisablePlayerListHover()) {
|
||||
pong.clearSamplePlayers();
|
||||
}
|
||||
|
||||
ping.setPing(pong.build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
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;
|
||||
|
||||
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(Identity.nil(), 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,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