update 1.1
This commit is contained in:
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>
|
||||||
@@ -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</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -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,97 @@ 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
|
||||||
|
Set<Long> halbzeitMarken = new HashSet<>();
|
||||||
|
long check = totalSeconds / 2;
|
||||||
|
while (check >= 10) {
|
||||||
|
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: "§aAchtung! Der Server wird in %time% neu gestartet!"
|
||||||
|
stop: "§cCountdown wurde gestoppt!"
|
||||||
|
restart: "§cServer wird jetzt neu gestartet!"
|
||||||
|
invalid_time: "§cUngültige Zeitangabe!"
|
||||||
|
usage: "§cVerwendung: /restartserver <Zeit> oder /restartserver stop"
|
||||||
|
|
||||||
|
# Dynamische Meldungen
|
||||||
|
half: "§eServerneustart in %time%!"
|
||||||
|
minute: "§eServerneustart in %time%!"
|
||||||
|
seconds_20: "§eServerneustart in 20s!"
|
||||||
|
seconds_final: "§cServerneustart in %time% Sekunden!"
|
||||||
|
|
||||||
|
# Feste Meldungen
|
||||||
|
fixed_1200: "§eServerneustart in 20m!"
|
||||||
|
fixed_600: "§eServerneustart in 10m!"
|
||||||
|
fixed_300: "§eServerneustart in 5m!"
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
name: RestartCountdown
|
name: RestartCountdown
|
||||||
version: 1.0
|
version: 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