Skip to content

Commit

Permalink
2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
moom0o committed Jun 7, 2021
1 parent 2b3f148 commit 07ba7ae
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 109 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# RestartPlugin

Restart notifications just like the minecraft server 2b2t

Completely configurable messages

```
# 2b2t restart plugin
# Minecraft restart notifications plugin by moo
# Time to where the server will call a restart
Timezone: "America/New_York"
#Time
# 2:00 AM EST
# THIS IS IN 24 HOUR TIME
Hour: 2
Minute: 0
Seconds: 0
RestartTimes:
- "2:00:00" # 2AM EST
# - "14:00:00" #2PM EST
string: "&e[SERVER] Server restarting in"
# %timeword% is the minute/seconds/second string.
# %time% is the number, ex: 15/10/5/2
string: "&e[SERVER] Server restarting in %time% %timeword%"
finalstring: "&e[SERVER] Server restarting..."
minutestring: " minutes..."
secondsstring: " seconds..."
secondstring: " second..."
minutestring: "minutes..."
secondsstring: "seconds..."
secondstring: "second..."
```
114 changes: 65 additions & 49 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,58 +1,74 @@
<?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"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
<modelVersion>4.0.0</modelVersion>

<groupId>me.moomoo</groupId>
<artifactId>RestartPlugin</artifactId>
<version>1.1</version>
<packaging>jar</packaging>
<groupId>me.moomoo</groupId>
<artifactId>RestartPlugin</artifactId>
<version>2.0</version>
<packaging>jar</packaging>

<name>RestartPlugin</name>
<name>RestartPlugin</name>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<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.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<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.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories><repository><id>papermc-repo</id><url>https://papermc.io/repo/repository/maven-public/</url></repository><repository><id>sonatype</id><url>https://oss.sonatype.org/content/groups/public/</url></repository></repositories>
<repositories>
<repository>
<id>papermc-repo</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>

<dependencies><dependency><groupId>com.destroystokyo.paper</groupId><artifactId>paper-api</artifactId><version>1.12.2-R0.1-SNAPSHOT</version><scope>provided</scope></dependency></dependencies>
<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
81 changes: 43 additions & 38 deletions src/main/java/me/moomoo/restartplugin/RestartPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,80 @@

public class RestartPlugin extends JavaPlugin implements Listener {
FileConfiguration config = getConfig();
boolean playerslow = false;

public void onEnable() {
saveDefaultConfig();
System.out.println("[ENABLED] moomoo's 2b2t restart notifications plugin");
Bukkit.getServer().getPluginManager().registerEvents(this, this);

ZonedDateTime now = ZonedDateTime.now(ZoneId.of(get("Timezone")));
ZonedDateTime nextRun = now.withHour(config.getInt("Hour")).withMinute(config.getInt("Minute")).withSecond(config.getInt("Seconds"));
if (now.compareTo(nextRun) > 0)
nextRun = nextRun.plusDays(1);
config.getStringList("RestartTimes").forEach(b -> {
String[] numbers = b.split(":");
int hour = Integer.parseInt(numbers[0]);
int minute = Integer.parseInt(numbers[1]);
int second = Integer.parseInt(numbers[2]);

Duration duration = Duration.between(now, nextRun);
long initalDelay = duration.getSeconds();
ZonedDateTime nextRun = now.withHour(hour).withMinute(minute).withSecond(second);
if (now.compareTo(nextRun) > 0)
nextRun = nextRun.plusDays(1);

ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(() -> {
Thread t = new Thread(() -> {
try {
restart();
} catch (InterruptedException e) {
e.printStackTrace();
}
Duration duration = Duration.between(now, nextRun);
long initalDelay = duration.getSeconds();

});

t.start();
}, initalDelay, TimeUnit.DAYS.toSeconds(1), TimeUnit.SECONDS);
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(() -> {
Thread t = new Thread(() -> {
try {
restart();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
t.start();
}, initalDelay, TimeUnit.DAYS.toSeconds(1), TimeUnit.SECONDS);
});
}

public void restart() throws InterruptedException {
String s = translate(get("string"));
b(translate(s + " 15" + get("minutestring")));
String s = get("string");
// Pull req. If you find a better way to do this!
b(translate(s.replace("%time%", "15").replace("%timeword%", get("minutestring"))));
sleep(300000);
b(translate(s + " 10" + get("minutestring")));
b(translate(s.replace("%time%", "10").replace("%timeword%", get("minutestring"))));
sleep(300000);
b(translate(s + " 5" + get("minutestring")));
b(translate(s.replace("%time%", "5").replace("%timeword%", get("minutestring"))));
sleep(180000);
b(translate(s + " 2" + get("minutestring")));
b(translate(s.replace("%time%", "2").replace("%timeword%", get("minutestring"))));
sleep(105000);
b(translate(s + " 15" + get("secondsstring")));
b(translate(s.replace("%time%", "15").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 14" + get("secondsstring")));
b(translate(s.replace("%time%", "14").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 13" + get("secondsstring")));
b(translate(s.replace("%time%", "13").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 12" + get("secondsstring")));
b(translate(s.replace("%time%", "12").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 11" + get("secondsstring")));
b(translate(s.replace("%time%", "11").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 10" + get("secondsstring")));
b(translate(s.replace("%time%", "10").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 9" + get("secondsstring")));
b(translate(s.replace("%time%", "9").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 8" + get("secondsstring")));
b(translate(s.replace("%time%", "8").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 7" + get("secondsstring")));
b(translate(s.replace("%time%", "7").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 6" + get("secondsstring")));
b(translate(s.replace("%time%", "6").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 5" + get("secondsstring")));
b(translate(s.replace("%time%", "5").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 4" + get("secondsstring")));
b(translate(s.replace("%time%", "4").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 3" + get("secondsstring")));
b(translate(s.replace("%time%", "3").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 2" + get("secondsstring")));
b(translate(s.replace("%time%", "2").replace("%timeword%", get("secondsstring"))));
sleep(1000);
b(translate(s + " 1" + get("secondstring")));
b(translate(s.replace("%time%", "1").replace("%timeword%", get("secondstring"))));
sleep(1000);
b(translate(get("finalstring")));
Bukkit.shutdown();
Expand Down
21 changes: 10 additions & 11 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# 2b2t restart plugin

# Minecraft restart notifications plugin by moo
# Time to where the server will call a restart
Timezone: "America/New_York"
#Time
# 2:00 AM EST
# THIS IS IN 24 HOUR TIME
Hour: 2
Minute: 0
Seconds: 0
RestartTimes:
- "2:00:00" # 2AM EST
# - "14:00:00" #2PM EST

string: "&e[SERVER] Server restarting in"
# %timeword% is the minute/seconds/second string.
# %time% is the number, ex: 15/10/5/2
string: "&e[SERVER] Server restarting in %time% %timeword%"
finalstring: "&e[SERVER] Server restarting..."
minutestring: " minutes..."
secondsstring: " seconds..."
secondstring: " second..."
minutestring: "minutes..."
secondsstring: "seconds..."
secondstring: "second..."

0 comments on commit 07ba7ae

Please sign in to comment.