mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-15 23:20:44 +00:00
Merge remote-tracking branch 'husky/restart-alert'
This commit is contained in:
@@ -66,6 +66,7 @@ dependencies {
|
||||
pvpPlugin(project(path = ":plugins:namecolors-paper"))
|
||||
|
||||
proxyPlugin(project(path = ":plugins:civproxy-velocity"))
|
||||
proxyPlugin(project(path = ":plugins:announcements-velocity", configuration = "shadow"))
|
||||
}
|
||||
|
||||
val copyPaperPlugins = tasks.register<Copy>("copyPaperPlugins") {
|
||||
|
||||
@@ -31,5 +31,6 @@ allprojects {
|
||||
maven("https://repo.infernalsuite.com/repository/maven-snapshots/")
|
||||
maven("https://repo.rapture.pw/repository/maven-releases/")
|
||||
maven("https://jitpack.io")
|
||||
maven("https://repo.ajg0702.us/releases")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
paper = "1.21.8-R0.1-SNAPSHOT"
|
||||
junit = "5.8.2"
|
||||
nuotifier = "2.7.2"
|
||||
velocity = "3.4.0-SNAPSHOT"
|
||||
configurate = "4.2.0"
|
||||
|
||||
[plugins]
|
||||
paper-userdev = { id = "io.papermc.paperweight.userdev", version = "2.0.0-beta.17" }
|
||||
@@ -10,6 +12,7 @@ runpaper = { id = "xyz.jpenilla.run-paper", version = "2.3.1" }
|
||||
|
||||
[libraries]
|
||||
paper-api = { group = "io.papermc.paper", name = "paper-api", version.ref = "paper" }
|
||||
velocity-api = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity"}
|
||||
|
||||
aikar-acf = { group = "co.aikar", name = "acf-paper", version = "0.5.1-SNAPSHOT" }
|
||||
aikar-taskchain = { group = "co.aikar", name = "taskchain-bukkit", version = "3.7.2" }
|
||||
@@ -18,6 +21,10 @@ commons-lang3 = { group = "org.apache.commons", name = "commons-lang3", version
|
||||
commons-collections4 = { group = "org.apache.commons", name = "commons-collections4", version = "4.4" }
|
||||
commons-math3 = { group = "org.apache.commons", name = "commons-math3", version = "3.6.1" }
|
||||
|
||||
cron-utils = { group = "com.cronutils", name = "cron-utils", version = "9.2.1" }
|
||||
|
||||
configurate-yaml = { group = "org.spongepowered", name = "configurate-yaml", version.ref = "configurate" }
|
||||
|
||||
rabbitmq-client = { group = "com.rabbitmq", name = "amqp-client", version = "5.17.1" }
|
||||
|
||||
nuvotifier-api = { group = "com.github.NuVotifier.NuVotifier", name = "nuvotifier-api", version.ref = "nuotifier" }
|
||||
|
||||
13
plugins/announcements-velocity/build.gradle.kts
Normal file
13
plugins/announcements-velocity/build.gradle.kts
Normal file
@@ -0,0 +1,13 @@
|
||||
plugins {
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
version = "1.0.0"
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.velocity.api)
|
||||
annotationProcessor(libs.velocity.api)
|
||||
|
||||
implementation(libs.cron.utils)
|
||||
implementation(libs.configurate.yaml)
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package net.civmc.announcements;
|
||||
|
||||
import com.cronutils.model.Cron;
|
||||
import com.cronutils.model.CronType;
|
||||
import com.cronutils.model.definition.CronDefinitionBuilder;
|
||||
import com.cronutils.model.time.ExecutionTime;
|
||||
import com.cronutils.parser.CronParser;
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
@Plugin(id = "civannouncements", name = "Civ Announcements", version = "1.0.0",
|
||||
url = "https://civmc.net", description = "Sends various announcements", authors = {"Huskydog9988"})
|
||||
public class AnnouncementsPlugin {
|
||||
|
||||
private final CronParser cronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX));
|
||||
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private final Path dataDirectory;
|
||||
|
||||
private record Announcement(Component message, Boolean showTitle) {}
|
||||
|
||||
private final Map<Cron, Announcement> scheduledAnnouncements = new ConcurrentHashMap<>();
|
||||
private final Map<Cron, ZonedDateTime> lastExecutionTimes = new ConcurrentHashMap<>();
|
||||
private @Nullable CommentedConfigurationNode config;
|
||||
|
||||
@Inject
|
||||
public AnnouncementsPlugin(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
this.dataDirectory = dataDirectory;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
logger.info("Initializing Announcements plugin");
|
||||
|
||||
loadConfig();
|
||||
scheduleTasks();
|
||||
|
||||
// task to check if a scheduled announcement should be sent
|
||||
server.getScheduler().buildTask(this, this::sendScheduledMessages).repeat(5, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
|
||||
private void scheduleTasks() {
|
||||
var minimessageSerializer = MiniMessage.miniMessage();
|
||||
|
||||
// ensure config exists
|
||||
if (config == null) {
|
||||
logger.info("Config is null");
|
||||
return;
|
||||
}
|
||||
|
||||
// read scheduled announcements from config
|
||||
List<? extends ConfigurationNode> announcements = config.node("scheduledAnnouncements").childrenList();
|
||||
for (ConfigurationNode announcement : announcements) {
|
||||
Cron cron = cronParser.parse(Objects.requireNonNull(announcement.node("cron").getString()));
|
||||
// convert message to Component
|
||||
Component formatedMsg = minimessageSerializer.deserialize(Objects.requireNonNull(announcement.node("message").getString()));
|
||||
Boolean showTitle = announcement.node("showTitle").getBoolean();
|
||||
scheduledAnnouncements.put(cron, new Announcement(formatedMsg, showTitle));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a scheduled message needs to be sent, and sends them if so
|
||||
*/
|
||||
private void sendScheduledMessages() {
|
||||
ZonedDateTime now = ZonedDateTime.now().withNano(0);
|
||||
|
||||
for (Cron cron : scheduledAnnouncements.keySet()) {
|
||||
var executionTime = ExecutionTime.forCron(cron);
|
||||
|
||||
// get last time a cron *should* have run
|
||||
executionTime.lastExecution(now).ifPresent(lastExecution -> {
|
||||
// Check if we should execute, and if con already executed at that time
|
||||
if (executionTime.isMatch(now) && !lastExecution.equals(lastExecutionTimes.get(cron))) {
|
||||
// Execute and update the last execution time
|
||||
var announcement = scheduledAnnouncements.get(cron);
|
||||
server.sendMessage(announcement.message);
|
||||
lastExecutionTimes.put(cron, lastExecution);
|
||||
if (announcement.showTitle) {
|
||||
// send title to all players
|
||||
var title = Title.title(announcement.message, Component.empty());
|
||||
server.getAllPlayers().parallelStream().forEach(player ->
|
||||
player.showTitle(title)
|
||||
);
|
||||
}
|
||||
|
||||
logger.info("Announcement sent: {}", announcement.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the config from disk, and creates it if necessary
|
||||
*/
|
||||
private void loadConfig() {
|
||||
try {
|
||||
// ensure data directory exists
|
||||
if (!Files.exists(dataDirectory)) {
|
||||
Files.createDirectories(dataDirectory);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("Could not create data directory: {}", dataDirectory, e);
|
||||
return;
|
||||
}
|
||||
|
||||
// create config file if it doesn't exist
|
||||
Path configFile = dataDirectory.resolve("config.yml");
|
||||
if (!Files.exists(configFile)) {
|
||||
try (InputStream in = getClass().getResourceAsStream("/config.yml")) {
|
||||
if (in != null) {
|
||||
Files.copy(in, configFile);
|
||||
logger.info("Default configuration file created.");
|
||||
} else {
|
||||
logger.error("Default configuration file is missing in resources!");
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("Could not create default configuration file: {}", configFile, e);
|
||||
}
|
||||
}
|
||||
|
||||
YamlConfigurationLoader loader = YamlConfigurationLoader.builder().path(configFile).build();
|
||||
try {
|
||||
config = loader.load();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not load configuration file: " + configFile, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
plugins/announcements-velocity/src/main/resources/config.yml
Normal file
15
plugins/announcements-velocity/src/main/resources/config.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
# messages must be in minimessage format
|
||||
# https://webui.advntr.dev/
|
||||
scheduledAnnouncements:
|
||||
- cron: "0 1 * * *"
|
||||
message: "<gold>Restart in 1 hour</gold>"
|
||||
- cron: "45 1 * * *"
|
||||
message: "<gold>Restart in 15 minutes</gold>"
|
||||
showTitle: false
|
||||
- cron: "55 1 * * *"
|
||||
message: "<gold>Restart in 5 minutes</gold>"
|
||||
showTitle: true
|
||||
- cron: "59 1 * * *"
|
||||
message: "<gold>Restart in 1 minute</gold>"
|
||||
showTitle: true
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("com.gradleup.shadow")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
version = "2.0.1"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "3.0.1"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "2.0.2"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "5.2.4"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "2.2.2"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "1.5.0-SNAPSHOT"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("com.gradleup.shadow")
|
||||
id("xyz.jpenilla.run-paper")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
alias(libs.plugins.shadow)
|
||||
alias(libs.plugins.runpaper)
|
||||
}
|
||||
|
||||
version = "3.0.6"
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
version = "1.0.0"
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = uri("https://repo.ajg0702.us/releases")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
|
||||
compileOnly("us.ajg0702.queue.api:api:2.8.0")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("xyz.jpenilla.run-paper")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
alias(libs.plugins.runpaper)
|
||||
}
|
||||
|
||||
version = "2.0.1"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "2.0.0-SNAPSHOT"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "2.1.6"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "3.1.0"
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://repo.dmulloy2.net/repository/public")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "2.1.0"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "1.0.0"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "2.0.0-SNAPSHOT"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "2.0.2"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("com.gradleup.shadow")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
version = "3.0.8"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("com.gradleup.shadow")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
version = "2.0.3"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("com.gradleup.shadow")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
version = "1.0.0"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "2.0.0-SNAPSHOT"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "3.0.6"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "2.0.0-SNAPSHOT"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "3.0.4"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("xyz.jpenilla.run-paper")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
alias(libs.plugins.runpaper)
|
||||
}
|
||||
|
||||
version = "3.2.3"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("xyz.jpenilla.run-paper")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
alias(libs.plugins.runpaper)
|
||||
}
|
||||
|
||||
version = "3.2.3"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "2.3.2"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
alias(libs.plugins.paper.userdev)
|
||||
}
|
||||
|
||||
version = "1.0.0"
|
||||
|
||||
@@ -13,6 +13,7 @@ plugins {
|
||||
|
||||
include(":ansible")
|
||||
|
||||
include(":plugins:announcements-velocity")
|
||||
include(":plugins:banstick-paper")
|
||||
include(":plugins:bastion-paper")
|
||||
include(":plugins:castlegates-paper")
|
||||
|
||||
Reference in New Issue
Block a user