Skip to content

Commit

Permalink
Add extra options for server start and stop.
Browse files Browse the repository at this point in the history
  • Loading branch information
Raquece committed Aug 10, 2022
1 parent 29fabdc commit c50dfe6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.raquece</groupId>
<artifactId>DSync</artifactId>
<version>1.19.0</version>
<version>1.19.1-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/dev/raquece/dsync/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main extends JavaPlugin {
private WebhookOut stdout;
Expand Down Expand Up @@ -38,13 +40,28 @@ public void onEnable() {
logger.info("Registering event listeners...");
getServer().getPluginManager().registerEvents(new EventListener(this, stdout), this);

stdout.SendEmbed(config.getString("messages.server.started.title"), config.getString("messages.server.started.description"), config.getInt("messages.server.started.color"));
Pattern versionP = Pattern.compile("MC: [^)]*");
Matcher m = versionP.matcher(getServer().getVersion());
String ver = "";
if (m.find()) {
ver = m.group(0);
}

var title = config.getString("messages.server.started.title");
var message = config.getString("messages.server.started.description");
title = title.replaceAll("[$]VERSION", ver);
message = message.replaceAll("[$]VERSION", ver);
stdout.SendEmbed(title, message, config.getInt("messages.server.started.color"));
}

@Override
public void onDisable() {
if (config.getString("webhook_url") != null && config.getString("webhook_url") != "null") {
stdout.SendEmbedSync(config.getString("messages.server.stopped.title"), config.getString("messages.server.stopped.description"), config.getInt("messages.server.stopped.color"));
var title = config.getString("messages.server.stopped.title");
var message = config.getString("messages.server.stopped.description");
title = title.replaceAll("[$]VERSION", getServer().getVersion());
message = message.replaceAll("[$]VERSION", getServer().getVersion());
stdout.SendEmbedSync(title, message, config.getInt("messages.server.stopped.color"));
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/default_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"messages.player.join": ":arrow_right: $PLAYER has connected",
"messages.player_quit": ":arrow_left: $PLAYER has disconnected",
"messages.player.death": ":skull: $MESSAGE",
"messages.player.advancement": ":orange_book: $PLAYER has completed an advancement! **[ $ADVANCEMENT ]**",
"messages.server.started.title": ":green_circle: Server Online",
"messages.server.started.description": "The server is now online.",
"messages.server.started.color": "3066993",
"messages.server.stopped.title": ":red_circle: Server Offline",
"messages.server.stopped.description": "The server is now offline.",
"messages.server.stopped.color": "10038562"
}

0 comments on commit c50dfe6

Please sign in to comment.