Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23e94d4824 | ||
|
|
ba6f4c2ff1 | ||
|
|
85db4d623b | ||
|
|
a3974d309f | ||
|
|
6a79ea0c11 | ||
|
|
ed68b936cb | ||
|
|
e168e25d91 | ||
|
|
61a3c2592c | ||
|
|
f7d7cfb202 | ||
|
|
e5a62be219 | ||
|
|
a3d2288269 | ||
|
|
f179a61cfd | ||
|
|
fdff9c4899 | ||
|
|
985c8f5fe6 | ||
|
|
facb4cf718 | ||
|
|
f7694d7c8c |
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="ms-21" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1 +1,78 @@
|
|||||||
# RestartCountdownPlugin
|
 
|
||||||
|
# EN
|
||||||
|
|
||||||
|
# RestartCountdownPlugin
|
||||||
|
|
||||||
|
A simple Minecraft plugin that restarts the server after a countdown to warn all players.
|
||||||
|
Made for Paper Server.
|
||||||
|
|
||||||
|
Plugin can be downloaded from Modrinth:
|
||||||
|
https://modrinth.com/plugin/restartcountdown
|
||||||
|
|
||||||
|
## How to use it
|
||||||
|
|
||||||
|
For example, with “/restartserver 20s” you start a countdown with 20 seconds. Minutes are also possible with “/restartserver 10m”.
|
||||||
|
With “/restartserver stop” you stop the current countdown.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
All messages can be customized in config.yml!
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
messages:
|
||||||
|
start: "§aAttention! The Server is restarting in %time%"
|
||||||
|
stop: "§cCountdown stopped"
|
||||||
|
restart: "§cServer is restarting now!"
|
||||||
|
invalid_time: "§cInvalid time!"
|
||||||
|
usage: "§cUsage: /restartserver <time> or /restartserver stop"
|
||||||
|
|
||||||
|
# dynamic alerts
|
||||||
|
half: "§eRestart in %time%!"
|
||||||
|
minute: "§eRestart in %time%!"
|
||||||
|
seconds_20: "§eRestart in 20s!"
|
||||||
|
seconds_final: "§cThe Server is restarting in %time% seconds!"
|
||||||
|
|
||||||
|
# fixed alerts
|
||||||
|
fixed_1200: "§eRestart in 20m!"
|
||||||
|
fixed_600: "§eRestart in 10m!"
|
||||||
|
fixed_300: "§eRestart in 5m!"
|
||||||
|
```
|
||||||
|
|
||||||
|
# DE
|
||||||
|
|
||||||
|
# RestartCountdownPlugin
|
||||||
|
|
||||||
|
Ein simples Minecraft Plugin welches den Server nach einem Countdown neustartet um alle Spieler zu warnen.
|
||||||
|
Gemacht für Paper Server
|
||||||
|
|
||||||
|
Download auf Modrinth:
|
||||||
|
https://modrinth.com/plugin/restartcountdown
|
||||||
|
|
||||||
|
## Verwendung
|
||||||
|
|
||||||
|
Mit "/restartserver 20s" startest du z.B. ein Countdown mit 20 Sekunden. Minuten mit "/restartserver 10m" gehen auch.
|
||||||
|
Mit "/restartserver stop", stoppst du den aktuellen Countdown.
|
||||||
|
|
||||||
|
# Konfiguration
|
||||||
|
|
||||||
|
Alle Nachrichten sind in der config.yml anpassbar!
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
messages:
|
||||||
|
start: "§aAttention! The Server is restarting in %time%"
|
||||||
|
stop: "§cCountdown stopped"
|
||||||
|
restart: "§cServer is restarting now!"
|
||||||
|
invalid_time: "§cInvalid time!"
|
||||||
|
usage: "§cUsage: /restartserver <time> or /restartserver stop"
|
||||||
|
|
||||||
|
# dynamic alerts
|
||||||
|
half: "§eRestart in %time%!"
|
||||||
|
minute: "§eRestart in %time%!"
|
||||||
|
seconds_20: "§eRestart in 20s!"
|
||||||
|
seconds_final: "§cThe Server is restarting in %time% seconds!"
|
||||||
|
|
||||||
|
# fixed alerts
|
||||||
|
fixed_1200: "§eRestart in 20m!"
|
||||||
|
fixed_600: "§eRestart in 10m!"
|
||||||
|
fixed_300: "§eRestart in 5m!"
|
||||||
|
```
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<groupId>de.jakob48</groupId>
|
<groupId>de.jakob48</groupId>
|
||||||
<artifactId>restartcountdown</artifactId>
|
<artifactId>restartcountdown</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.1.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- Compiler Plugin -->
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
@@ -48,8 +47,6 @@
|
|||||||
<target>${java.version}</target>
|
<target>${java.version}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- Shade Plugin, optional für fertiges JAR -->
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
|||||||
@@ -6,12 +6,16 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class restartcountdown extends JavaPlugin {
|
public class restartcountdown extends JavaPlugin {
|
||||||
|
|
||||||
private BukkitRunnable countdownTask = null; // Referenz auf aktuellen Countdown
|
private BukkitRunnable countdownTask = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
saveDefaultConfig();
|
||||||
getLogger().info("RestartCountdown Plugin aktiviert!");
|
getLogger().info("RestartCountdown Plugin aktiviert!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,28 +30,30 @@ public class restartcountdown extends JavaPlugin {
|
|||||||
if (!command.getName().equalsIgnoreCase("restartserver")) return false;
|
if (!command.getName().equalsIgnoreCase("restartserver")) return false;
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.sendMessage("§cVerwendung: /restartserver <Zeit> oder /restartserver stop");
|
sender.sendMessage(getConfig().getString("messages.usage", "§cVerwendung: /restartserver <Zeit> oder /restartserver stop"));
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Countdown stoppen
|
||||||
if (args[0].equalsIgnoreCase("stop")) {
|
if (args[0].equalsIgnoreCase("stop")) {
|
||||||
if (countdownTask != null) {
|
if (countdownTask != null) {
|
||||||
countdownTask.cancel();
|
countdownTask.cancel();
|
||||||
countdownTask = null;
|
countdownTask = null;
|
||||||
Bukkit.broadcastMessage("§cCountdown wurde gestoppt!");
|
Bukkit.broadcastMessage(getConfig().getString("messages.stop", "§cCountdown wurde gestoppt!"));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§cEs läuft kein Countdown!");
|
sender.sendMessage("§cEs läuft kein Countdown!");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zeit parsen
|
||||||
long seconds = parseTime(args[0]);
|
long seconds = parseTime(args[0]);
|
||||||
if (seconds <= 0) {
|
if (seconds <= 0) {
|
||||||
sender.sendMessage("§cUngültige Zeitangabe!");
|
sender.sendMessage(getConfig().getString("messages.invalid_time", "§cUngültige Zeitangabe!"));
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage("§aServerneustart in " + formatTime(seconds) + " gestartet!");
|
// Countdown starten
|
||||||
startCountdown(seconds);
|
startCountdown(seconds);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -63,53 +69,99 @@ public class restartcountdown extends JavaPlugin {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startCountdown(long seconds) {
|
private void startCountdown(long totalSeconds) {
|
||||||
if (countdownTask != null) countdownTask.cancel();
|
if (countdownTask != null) countdownTask.cancel();
|
||||||
|
|
||||||
|
// Halbzeit-/Viertel-/Achtel-Marken vorberechnen
|
||||||
|
// Halbzeit-/Viertel-/Achtel-Marken vorberechnen
|
||||||
|
Set<Long> halbzeitMarken = new HashSet<>();
|
||||||
|
long check = totalSeconds / 2;
|
||||||
|
while (check >= 60) { // nur solange >= 1 Minute
|
||||||
|
halbzeitMarken.add(check);
|
||||||
|
check /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Feste Meldungen (z.B. 20, 10, 5 Minuten)
|
||||||
|
Set<Long> festeMarken = new HashSet<>();
|
||||||
|
festeMarken.add(1200L); // 20 Minuten
|
||||||
|
festeMarken.add(600L); // 10 Minuten
|
||||||
|
festeMarken.add(300L); // 5 Minuten
|
||||||
|
|
||||||
|
// Bereits angekündigte Zeiten merken, um Doppelmeldungen zu verhindern
|
||||||
|
Set<Long> announced = new HashSet<>();
|
||||||
|
|
||||||
countdownTask = new BukkitRunnable() {
|
countdownTask = new BukkitRunnable() {
|
||||||
long timeLeft = seconds;
|
long timeLeft = totalSeconds;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (timeLeft <= 0) {
|
if (timeLeft <= 0) {
|
||||||
Bukkit.broadcastMessage("§cServer wird jetzt neu gestartet!");
|
Bukkit.broadcastMessage(getConfig().getString("messages.restart", "§cServer wird jetzt neu gestartet!"));
|
||||||
Bukkit.shutdown();
|
Bukkit.shutdown();
|
||||||
cancel();
|
cancel();
|
||||||
countdownTask = null;
|
countdownTask = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeLeft == seconds) {
|
String msg = null;
|
||||||
Bukkit.broadcastMessage("§eServerneustart in " + formatTime(timeLeft) + "!");
|
|
||||||
|
// Startmeldung
|
||||||
|
if (timeLeft == totalSeconds && !announced.contains(timeLeft)) {
|
||||||
|
msg = getConfig().getString("messages.start", "§eServerneustart in %time% gestartet!");
|
||||||
|
announced.add(timeLeft);
|
||||||
}
|
}
|
||||||
else if (timeLeft > 600 && timeLeft % 600 == 0) {
|
// Feste Meldungen
|
||||||
Bukkit.broadcastMessage("§eServerneustart in " + formatTime(timeLeft) + "!");
|
else if (festeMarken.contains(timeLeft) && !announced.contains(timeLeft)) {
|
||||||
|
msg = getConfig().getString("messages.fixed_" + timeLeft, "§eServerneustart in %time%!");
|
||||||
|
announced.add(timeLeft);
|
||||||
}
|
}
|
||||||
else if (timeLeft <= 600 && timeLeft >= 60 && timeLeft % 60 == 0) {
|
// Halbzeit-/Viertel-/Achtel-Meldungen
|
||||||
Bukkit.broadcastMessage("§eServerneustart in " + formatTime(timeLeft) + "!");
|
else if (halbzeitMarken.contains(timeLeft) && !announced.contains(timeLeft)) {
|
||||||
|
msg = getConfig().getString("messages.half", "§6Serverneustart in %time%! (Halbzeit)");
|
||||||
|
announced.add(timeLeft);
|
||||||
}
|
}
|
||||||
else if (timeLeft == 20) {
|
// Ab 10 Minuten jede volle Minute
|
||||||
Bukkit.broadcastMessage("§cServerneustart in 20 Sekunden!");
|
else if (timeLeft > 60 && timeLeft <= 600 && timeLeft % 60 == 0 && !announced.contains(timeLeft)) {
|
||||||
|
msg = getConfig().getString("messages.minute", "§eServerneustart in %time%!");
|
||||||
|
announced.add(timeLeft);
|
||||||
}
|
}
|
||||||
else if (timeLeft <= 10) {
|
// Ab 1 Minute jede volle Minute
|
||||||
Bukkit.broadcastMessage("§cServerneustart in " + timeLeft + " Sekunden!");
|
else if (timeLeft > 20 && timeLeft <= 60 && timeLeft % 60 == 0 && !announced.contains(timeLeft)) {
|
||||||
|
msg = getConfig().getString("messages.minute", "§eServerneustart in %time%!");
|
||||||
|
announced.add(timeLeft);
|
||||||
|
}
|
||||||
|
// Bei genau 20 Sekunden
|
||||||
|
else if (timeLeft == 20 && !announced.contains(timeLeft)) {
|
||||||
|
msg = getConfig().getString("messages.seconds_20", "§cAchtung! Der Server wird in 20 Sekunden neu gestartet!");
|
||||||
|
announced.add(timeLeft);
|
||||||
|
}
|
||||||
|
// Letzte 10 Sekunden, jede Sekunde
|
||||||
|
else if (timeLeft <= 10 && !announced.contains(timeLeft)) {
|
||||||
|
msg = getConfig().getString("messages.seconds_final", "§4Serverneustart in %time% Sekunden!");
|
||||||
|
announced.add(timeLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg != null) {
|
||||||
|
Bukkit.broadcastMessage(msg.replace("%time%", formatTime(timeLeft)));
|
||||||
}
|
}
|
||||||
|
|
||||||
timeLeft--;
|
timeLeft--;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
countdownTask.runTaskTimer(this, 0, 20); // 20 Ticks = 1 Sekunde
|
countdownTask.runTaskTimer(this, 0, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatTime(long seconds) {
|
private String formatTime(long seconds) {
|
||||||
long hours = seconds / 3600;
|
long hours = seconds / 3600;
|
||||||
long minutes = (seconds % 3600) / 60;
|
long minutes = (seconds % 3600) / 60;
|
||||||
long secs = seconds % 60;
|
long secs = seconds % 60;
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
if (hours > 0) sb.append(hours).append("h ");
|
if (hours > 0) sb.append(hours).append("h ");
|
||||||
if (minutes > 0) sb.append(minutes).append("m ");
|
if (minutes > 0) sb.append(minutes).append("m ");
|
||||||
if (secs > 0) sb.append(secs).append("s");
|
if (secs > 0 || sb.length() == 0) sb.append(secs).append("s");
|
||||||
return sb.toString().trim();
|
return sb.toString().trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
messages:
|
||||||
|
start: "§aAttention! The Server is restarting in %time%"
|
||||||
|
stop: "§cCountdown stopped"
|
||||||
|
restart: "§cServer is restarting now!"
|
||||||
|
invalid_time: "§cInvalid time!"
|
||||||
|
usage: "§cUsage: /restartserver <time> or /restartserver stop"
|
||||||
|
|
||||||
|
# dynamic alerts
|
||||||
|
half: "§eRestart in %time%!"
|
||||||
|
minute: "§eRestart in %time%!"
|
||||||
|
seconds_20: "§eRestart in 20s!"
|
||||||
|
seconds_final: "§cThe Server is restarting in %time% seconds!"
|
||||||
|
|
||||||
|
# fixed alerts
|
||||||
|
fixed_1200: "§eRestart in 20m!"
|
||||||
|
fixed_600: "§eRestart in 10m!"
|
||||||
|
fixed_300: "§eRestart in 5m!"
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
name: RestartCountdown
|
name: RestartCountdown
|
||||||
version: 1.0
|
version: 1.1.1
|
||||||
main: de.jakob48.restartcountdown
|
main: de.jakob48.restartcountdown
|
||||||
api-version: 1.20
|
api-version: 1.20
|
||||||
commands:
|
commands:
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
name: RestartCountdown
|
||||||
|
version: 1.1
|
||||||
|
main: de.jakob48.restartcountdown
|
||||||
|
api-version: 1.20
|
||||||
|
commands:
|
||||||
|
restartserver:
|
||||||
|
description: Startet einen Server-Neustart nach Countdown
|
||||||
|
usage: /restartserver <Zeit>
|
||||||
|
permission: restartserver.use
|
||||||
|
permissions:
|
||||||
|
restartserver.use:
|
||||||
|
default: op
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
artifactId=restartcountdown
|
||||||
|
groupId=de.jakob48
|
||||||
|
version=1.1
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
de/jakob48/restartcountdown$1.class
|
||||||
|
de/jakob48/restartcountdown.class
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/Users/jakob/IdeaProjects/RestartCountdownPlugin/src/main/java/de/jakob48/restartcountdown.java
|
||||||
Reference in New Issue
Block a user