1
0

add version check and notify user

This commit is contained in:
Lee
2024-03-30 12:24:12 +00:00
parent e3bd0b7c15
commit 7c5557abd2
7 changed files with 47 additions and 2 deletions

11
pom.xml
View File

@ -112,6 +112,10 @@
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>viaversion-repo</id>
<url>https://repo.viaversion.com</url>
</repository>
</repositories>
<dependencies>
@ -160,6 +164,13 @@
<version>7.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.viaversion</groupId>
<artifactId>viaversion-api</artifactId>
<version>4.9.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -4,6 +4,7 @@ import cc.fascinated.account.AccountManager;
import cc.fascinated.chat.ChatManager;
import cc.fascinated.command.CommandManager;
import cc.fascinated.metrics.MetricManager;
import cc.fascinated.misc.PlayerVersionWarning;
import cc.fascinated.motd.MotdManager;
import cc.fascinated.placeholder.PlaceholderManager;
import cc.fascinated.playercolor.PlayerColorManager;
@ -44,5 +45,6 @@ public class Aetheria extends JavaPlugin {
new PlayerColorManager();
new ChatManager();
new MotdManager();
new PlayerVersionWarning();
}
}

View File

@ -31,7 +31,7 @@ public class ChatManager extends Manager {
private final HashMap<Account, String> lastMessage = new HashMap<>();
private final Pattern domainPattern = Pattern.compile("^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,8}$");
private final Pattern ipPattern = Pattern.compile("\\b(?:\\d{1,3}\\.){1,3}\\d{1,3}\\b");
private final Pattern ipPattern = Pattern.compile("\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b");
@EventHandler
public void onChat(AsyncChatEvent event) {

View File

@ -17,7 +17,9 @@ public enum Config {
DISCORD_LOG_WEBHOOK("discord.log-webhook"),
MOTD_HEADER("motd.header"),
MOTD_FORMAT("motd.format"),
MOTD_LIST("motd.motds");
MOTD_LIST("motd.motds"),
VERSION_WARNING_VERSION("version-warning.min-version"),
VERSION_WARNING_MESSAGE("version-warning.message");
/**
* The path of the lang in the lang.yml file.
@ -70,4 +72,8 @@ public enum Config {
public List<String> getAsStringList() {
return (List<String>) get();
}
public int getAsInt() {
return (int) get();
}
}

View File

@ -0,0 +1,21 @@
package cc.fascinated.misc;
import cc.fascinated.config.Config;
import cc.fascinated.utils.Manager;
import cc.fascinated.utils.Style;
import com.viaversion.viaversion.api.Via;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
public class PlayerVersionWarning extends Manager {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
int version = Via.getAPI().getPlayerVersion(player.getUniqueId());
if (version < Config.VERSION_WARNING_VERSION.getAsInt()) {
player.sendMessage(Style.getMiniMessage().deserialize(Config.VERSION_WARNING_MESSAGE.getAsString()));
}
}
}

View File

@ -7,6 +7,10 @@ influxdb:
discord:
log-webhook: "https://discord.com/api/webhooks/1223162714822807572/jkqXHdcf4ov7MTC4fxx8MI2rSCoQTHONua8VOJa3ie5OtHBthqd5MGM7WGd7oHF52OOm"
version-warning:
min-version: 763 # 1.20
message: "<red><bold>WARNING!</bold></red> <white>You are using an outdated version of Minecraft. Please update to the latest version to avoid any issues."
motd:
header: "<yellow>Aetheria</yellow>"
format: "<gray>%motd%</gray>"

View File

@ -5,6 +5,7 @@ api-version: 1.20
author: Fascinated
depend:
- PlaceholderAPI
- ViaVersion
commands:
totaljoins:
description: "Shows the total amount of joins"