Compare commits

...
50 Commits
Author SHA1 Message Date
jmp 541b6bb623 Improve universal jar 2020-12-26 15:13:51 -08:00
jmp 454827731f Allow pairing specific icons and motds 2020-12-20 21:48:28 -08:00
jmp bbb65c2638 Update readme 2020-12-20 19:35:00 -08:00
jmp a7f4161551 Fix gitignore 2020-12-20 19:01:34 -08:00
jmp e08ffee2f9 Build with gradle 2020-12-20 19:00:01 -08:00
jmp 93ae27770e Implement player list hover option on bungee 2020-11-30 22:27:00 -08:00
jmp b6c39163b7 Add option to disable player list hover (closes #30) 2020-11-30 22:19:28 -08:00
Renovate Bot 8f9697c0a7 Update dependency net.kyori:adventure-api to v4.2.0 2020-11-30 21:44:58 -08:00
Renovate Bot 81adaf4e1a Update dependency com.velocitypowered:velocity-api to v1.1.2 2020-11-30 21:44:51 -08:00
jmp 9093ebfecd Use native schedulers instead of CompletableFuture for update checker 2020-10-28 12:25:08 -07:00
jmp 76552f52a7 Use System.lineSeparator() instead of \n for newlines 2020-10-28 12:14:41 -07:00
jmp d17a1f7948 Update velocity-api from 1.1.0-SNAPSHOT to 1.1.0 2020-10-28 11:44:51 -07:00
Renovate Bot 4c6ad898a1 Update dependency org.projectlombok:lombok to v1.18.16 2020-10-27 16:08:23 -07:00
Renovate Bot e5c3a723a2 Update dependency org.apache.maven.plugins:maven-source-plugin to v3.2.1 2020-10-27 16:07:13 -07:00
Renovate Bot 314d7b15b4 Update actions/upload-artifact action to v2 2020-10-24 11:14:23 -07:00
jmp a66faf7251 Update adventure-api 2020-10-18 17:19:04 -07:00
jmp 0b948367e2 Update adventure-api 2020-10-15 23:53:57 -07:00
jmp c2ee7e8f4b Update for adventure-api changes 2020-10-14 12:08:19 -07:00
jmp df665e5810 Update dependencies 2020-10-10 23:04:15 -07:00
jmp 382229cbbf revert listener priority change 2020-09-23 12:04:48 -07:00
jmp 5257fa9e3b adjust spigot listener priority 2020-09-23 11:37:42 -07:00
jmp 21b991b313 bump to 1.2.2 2020-09-14 11:39:38 -07:00
jmp 3720fec2f5 add issue templates 2020-09-13 09:32:52 -07:00
jmp 6fe11c729a respect update checker toggle 2020-09-12 22:40:46 -07:00
jmp c1e40216d4 bump MiniMessage 2020-09-12 10:44:59 -07:00
jmp b04de1b951 the update checker shouldn't be blocking :P 2020-09-12 01:54:54 -07:00
jmp 5673730693 don't strip colors from console; spigot (and soon paper) support rgb in console now 2020-09-12 01:40:20 -07:00
jmp 60b83031ab update GH actions 2020-09-12 00:19:06 -07:00
jmp 2a750c289b update VelocityCommand 2020-09-12 00:18:07 -07:00
jmp 0092a2b6b7 add Velocity command, add update checker, bump version 2020-09-12 00:15:18 -07:00
Jason 0847d15eef Merge pull request #9 from jmanpenilla/renovate/configure
Configure Renovate
2020-09-10 18:10:03 -07:00
jmp c9d2f3fdb7 Set up multi-module, add Velocity support 2020-09-10 17:51:15 -07:00
Renovate Bot db0ea2e656 Add renovate.json 2020-08-28 02:52:04 +00:00
jmp 7741523e56 use fixed MiniMessage build 2020-08-25 18:33:09 -07:00
jmp f858f29d67 added random server icon feature. place 64x64 pngs in the plugins/MiniMOTD/icons/ folder 2020-08-25 18:29:44 -07:00
jmp 725855124c - add tab completor on spigot.
- always downsample colors on old version servers which don't support sending rgb colors.
2020-08-15 14:39:49 -07:00
jmp 84f6f2b5d5 add comment to config.yml 2020-08-01 23:37:54 -07:00
jmp 2e2fe64923 1.1.6 2020-08-01 23:33:26 -07:00
jmp 574eca67e2 1.1.5 2020-07-29 12:41:19 -07:00
jmp 6556e92e5e 1.1.4 2020-07-16 16:41:56 -07:00
Jason 91a6973288 Merge pull request #6 from jmanpenilla/dependabot/maven/net.md-5-bungeecord-api-1.16-R0.2
Bump bungeecord-api from 1.16-R0.1 to 1.16-R0.2
2020-07-14 08:15:14 -07:00
dependabot[bot] afd3de54ed Bump bungeecord-api from 1.16-R0.1 to 1.16-R0.2
Bumps [bungeecord-api](https://github.com/SpigotMC/BungeeCord) from 1.16-R0.1 to 1.16-R0.2.
- [Release notes](https://github.com/SpigotMC/BungeeCord/releases)
- [Commits](https://github.com/SpigotMC/BungeeCord/commits)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-14 06:22:05 +00:00
jmp b9c3f505eb minor clean up 2020-07-13 12:17:58 -07:00
Jason bcc15def17 Merge pull request #5 from wkonowrocki/master
Adds a second list of MOTDs to be used for pre-1.16 clients. Currently bungee only.
2020-07-13 11:37:07 -07:00
Jason ef1b13d08f GitHub Actions 2020-07-13 11:34:15 -07:00
wkonowrocki 7edccb6ea4 added different motd for older versions 2020-07-13 20:15:43 +02:00
Jason c87f3c4321 Merge pull request #2 from jmanpenilla/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.2.4
Bump maven-shade-plugin from 3.2.2 to 3.2.4
2020-07-10 15:18:39 -07:00
dependabot[bot] 4aff316770 Bump maven-shade-plugin from 3.2.2 to 3.2.4
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.2 to 3.2.4.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.2...maven-shade-plugin-3.2.4)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-10 22:17:19 +00:00
Jason 702a6a7d66 Create dependabot.yml 2020-07-10 15:16:36 -07:00
jmp 6ffce0713f 1.1.2 2020-07-10 00:36:41 -07:00
42 changed files with 1468 additions and 434 deletions

No files matched your search

+6
View File
@@ -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
+32
View File
@@ -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.
+20
View File
@@ -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.
+26
View File
@@ -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
View File
@@ -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
+7 -2
View File
@@ -1,7 +1,12 @@
![MiniMOTD logo](https://i.imgur.com/kzapjUA.png)
![MiniMOTD logo](https://i.imgur.com/CXWwjOJ.png)
> 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).
![demo motd image](https://i.imgur.com/5yqJx8t.png)
+83
View File
@@ -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.3+${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()
}
+26
View File
@@ -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"
}
@@ -1,9 +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.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import java.util.ArrayList;
@@ -11,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
@@ -47,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);
}
@@ -64,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) {
@@ -79,13 +78,7 @@ public class BungeeCommand extends Command {
}
private void send(CommandSender sender, String message) {
final String finalMessage;
if (sender instanceof ProxiedPlayer) {
finalMessage = message;
} else {
finalMessage = MiniMessage.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;
}
}
}
@@ -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));
}
}
}
@@ -2,21 +2,26 @@ 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.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.chat.BaseComponent;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.chat.ComponentSerializer;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
import 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();
}
@@ -42,22 +47,33 @@ public class PingListener implements Listener {
onlinePlayers = onlinePlayers + addedPlayers;
}
} catch (NumberFormatException ex) {
System.out.println("[MiniMOTD] fakePlayers config incorrect");
miniMOTD.getLogger().warning("fakePlayers config invalid");
}
}
players.setOnline(onlinePlayers);
int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, players.getMax());
final 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]);
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);
}
}
+6
View File
@@ -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}", System.lineSeparator());
} 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;
}
}
@@ -1,3 +1,7 @@
# 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
@@ -5,6 +9,8 @@ motd:
# Placeholders: {onlinePlayers} {maxPlayers}
# Use {br} to separate lines.
# Putting more than one will cause one to be randomly chosen each refresh
#
# Tip: If you want to set a certain icon for each MOTD, check out this page: https://github.com/jmanpenilla/MiniMOTD/wiki/Assigning-specific-icons-per-MOTD
motds:
- "<bold><gradient:black:white>----====[</gradient> <gradient:green:blue>UltraCraft <gradient:red:yellow></bold><italic>Official</gradient></italic><bold> <gradient:white:black>]=====----</gradient></bold>{br}<bold> <gradient:#EEFF4A:#F7FFAE>Custom <italic>Survival</italic></gradient> <color:#0092FF>Discord</bold><gray>:</gray> <gradient:#5FDAFF:#B8A6FF><italic>Ab3d5f"
- "<rainbow>|||||||||||||||||||||||||||||||||||||||||||||||||||||||||</rainbow>{br}<white>Hello <blue>{onlinePlayers} <gray>/</gray> {maxPlayers}</blue> Players Online"
@@ -21,6 +27,10 @@ maxPlayers:
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
@@ -32,4 +42,7 @@ bungeeOnly:
# ex: fakePlayers: "3:6"
# percent: The player count will be inflated by this much, rounding up
# ex: fakePlayers: "25%"
fakePlayers: "25%"
fakePlayers: "25%"
# Setting this to true will disable the hover text showing online player usernames
disablePlayerListHover: false
Binary file not shown.
+5
View File
@@ -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
Vendored Executable
+185
View File
@@ -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
View File
@@ -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
-166
View File
@@ -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.1</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>
+5
View File
@@ -0,0 +1,5 @@
{
"extends": [
"config:base"
]
}
+22
View File
@@ -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)
}
+37
View File
@@ -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,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 {
@@ -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,56 +0,0 @@
package xyz.jpenilla.minimotd.bungee;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
public class BungeeConfig extends MiniMOTDConfig {
private final MiniMOTD miniMOTD;
public BungeeConfig(MiniMOTD miniMOTD) {
this.miniMOTD = miniMOTD;
reload();
}
public void reload() {
final Configuration config = loadFromDisk();
getMotds().clear();
for (String motd : config.getStringList(MOTDS)) {
getMotds().add(motd.replace("{br}", "\n"));
}
setMotdEnabled(config.getBoolean(MOTD_ENABLED));
setMaxPlayersEnabled(config.getBoolean(MAX_PLAYERS_ENABLED));
setJustXMoreEnabled(config.getBoolean(JUST_X_MORE_ENABLED));
setMaxPlayers(config.getInt(MAX_PLAYERS));
setXValue(config.getInt(X_VALUE));
setFakePlayersEnabled(config.getBoolean(FAKE_PLAYERS_ENABLED));
setFakePlayers(config.getString(FAKE_PLAYERS));
}
private Configuration loadFromDisk() {
if (!miniMOTD.getDataFolder().exists()) {
miniMOTD.getDataFolder().mkdir();
}
File file = new File(miniMOTD.getDataFolder(), "config.yml");
if (!file.exists()) {
try (InputStream in = miniMOTD.getResourceAsStream("config.yml")) {
Files.copy(in, file.toPath());
} catch (IOException e) {
e.printStackTrace();
}
}
try {
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(miniMOTD.getDataFolder(), "config.yml"));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
@@ -1,49 +0,0 @@
package xyz.jpenilla.minimotd.common;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.FieldNameConstants;
import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;
@FieldNameConstants
public abstract class MiniMOTDConfig {
@Getter private final ArrayList<String> motds = new ArrayList<>();
@Getter @Setter private boolean motdEnabled;
@Getter @Setter private boolean maxPlayersEnabled;
@Getter @Setter private boolean justXMoreEnabled;
@Getter @Setter private boolean fakePlayersEnabled;
@Getter @Setter private int xValue;
@Getter @Setter private int maxPlayers;
@Getter @Setter private String fakePlayers;
public final String MOTDS = "motd." + Fields.motds;
public final String MOTD_ENABLED = "motd." + Fields.motdEnabled;
public final String MAX_PLAYERS_ENABLED = Fields.maxPlayers + "." + Fields.maxPlayersEnabled;
public final String JUST_X_MORE_ENABLED = Fields.maxPlayers + "." + Fields.justXMoreEnabled;
public final String MAX_PLAYERS = Fields.maxPlayers + "." + Fields.maxPlayers;
public final String X_VALUE = Fields.maxPlayers + "." + Fields.xValue;
public final String FAKE_PLAYERS_ENABLED = "bungeeOnly." + Fields.fakePlayersEnabled;
public final String FAKE_PLAYERS = "bungeeOnly." + Fields.fakePlayers;
public abstract void reload();
public String getMOTD(int onlinePlayers, int maxPlayers) {
if (motds.size() == 1) {
return motds.get(0);
} else {
return motds.get(ThreadLocalRandom.current().nextInt(motds.size()))
.replace("{onlinePlayers}", String.valueOf(onlinePlayers))
.replace("{maxPlayers}", String.valueOf(maxPlayers));
}
}
public int getAdjustedMaxPlayers(int onlinePlayers, int actualMaxPlayers) {
if (maxPlayersEnabled) {
return justXMoreEnabled ? onlinePlayers + xValue : maxPlayers;
} else {
return actualMaxPlayers;
}
}
}
@@ -1,24 +0,0 @@
package xyz.jpenilla.minimotd.spigot;
import lombok.Getter;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public final class MiniMOTD extends JavaPlugin {
@Getter private SpigotConfig cfg;
@Getter private PrismaHook prisma;
@Getter private static MiniMOTD instance;
@Override
public void onEnable() {
instance = this;
if (Bukkit.getPluginManager().isPluginEnabled("Prisma")) {
prisma = new PrismaHook();
}
this.cfg = new SpigotConfig(this);
getServer().getPluginManager().registerEvents(new PingListener(this), this);
getCommand("minimotd").setExecutor(new SpigotCommand(this));
Metrics metrics = new Metrics(this, 8132);
}
}
@@ -1,26 +0,0 @@
package xyz.jpenilla.minimotd.spigot;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerListPingEvent;
public class PingListener implements Listener {
private final SpigotConfig cfg;
public PingListener(MiniMOTD miniMOTD) {
this.cfg = miniMOTD.getCfg();
}
@EventHandler
public void onPing(ServerListPingEvent e) {
final int onlinePlayers = e.getNumPlayers();
final int actualMaxPlayers = e.getMaxPlayers();
final int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, actualMaxPlayers);
e.setMaxPlayers(maxPlayers);
if (cfg.isMotdEnabled()) {
e.setMotd(cfg.getMOTD(onlinePlayers, maxPlayers));
}
}
}
@@ -1,41 +0,0 @@
package xyz.jpenilla.minimotd.spigot;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.configuration.file.FileConfiguration;
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
public class SpigotConfig extends MiniMOTDConfig {
private final MiniMOTD miniMOTD;
public SpigotConfig(MiniMOTD miniMOTD) {
this.miniMOTD = miniMOTD;
miniMOTD.saveDefaultConfig();
reload();
}
public void reload() {
miniMOTD.reloadConfig();
final FileConfiguration config = miniMOTD.getConfig();
getMotds().clear();
for (String motd : config.getStringList(MOTDS)) {
final String temp;
if (miniMOTD.getPrisma() != null) {
temp = miniMOTD.getPrisma().translate(motd);
} else {
temp = motd;
}
getMotds().add(miniMessageToLegacy(temp.replace("{br}", "\n")));
}
setMotdEnabled(config.getBoolean(MOTD_ENABLED));
setMaxPlayersEnabled(config.getBoolean(MAX_PLAYERS_ENABLED));
setJustXMoreEnabled(config.getBoolean(JUST_X_MORE_ENABLED));
setMaxPlayers(config.getInt(MAX_PLAYERS));
setXValue(config.getInt(X_VALUE));
}
private String miniMessageToLegacy(String message) {
return LegacyComponentSerializer.builder().hexColors().useUnusualXRepeatedCharacterHexFormat().build().serialize(MiniMessage.get().parse(message));
}
}
-5
View File
@@ -1,5 +0,0 @@
name: MiniMOTD
version: ${project.version}
main: xyz.jpenilla.minimotd.bungee.MiniMOTD
author: jmp
description: Set the MOTD using MiniMessage!
-13
View File
@@ -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
+15
View File
@@ -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)
}
}
+43
View File
@@ -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);
}
}