This commit is contained in:
dowoge 2023-07-01 04:24:12 -04:00
parent e697b1a0f5
commit b1d94aff3a
No known key found for this signature in database
GPG Key ID: A868F67EA0425DD8
6 changed files with 48 additions and 8 deletions

View File

@ -6,7 +6,7 @@
<groupId>serverLog</groupId> <groupId>serverLog</groupId>
<artifactId>serverStatusLogger</artifactId> <artifactId>serverStatusLogger</artifactId>
<version>1.1</version> <version>2.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Server status logger</name> <name>Server status logger</name>

View File

@ -1,4 +1,4 @@
package testplugin.plugin; package testplugin.plugin.Commands;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -7,6 +7,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import testplugin.plugin.Events.WebhookChangedEvent;
public class setWebhookCommand implements CommandExecutor { public class setWebhookCommand implements CommandExecutor {
// This method is called, when somebody uses our command // This method is called, when somebody uses our command

View File

@ -3,6 +3,10 @@ package testplugin.plugin;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
public class Config { public class Config {
private static Plugin plugin; private static Plugin plugin;
@ -12,11 +16,24 @@ public class Config {
} }
public void loadConfig() { public void loadConfig() {
String webhookURLPath = "webhookURL"; Dictionary<String, String> configs = new Hashtable<>();
configs.put("webhookURL","https://discord.com/api/webhooks/xxx/aaaa-bbbb-ccc");
configs.put("discordBotToken","TOKEN");
configs.put("discordRelayChannel","SnowflakeID");
FileConfiguration config = plugin.getConfig(); FileConfiguration config = plugin.getConfig();
config.addDefault(webhookURLPath,"https://discord.com/api/webhooks/xxx/aaaa-bbbb-ccc");
Enumeration<String> configIterator = configs.keys();
while (configIterator.hasMoreElements()) {
String configPath = configIterator.nextElement();
String configDefault = configs.get(configPath);
config.addDefault(configPath,configDefault);
}
config.options().copyDefaults(true); config.options().copyDefaults(true);
plugin.saveConfig(); plugin.saveConfig();

View File

@ -1,4 +1,4 @@
package testplugin.plugin; package testplugin.plugin.Events;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;

View File

@ -1,5 +1,6 @@
package testplugin.plugin; package testplugin.plugin;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -7,20 +8,24 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import testplugin.plugin.Events.DiscordRelayChannelIdChangedEvent;
import testplugin.plugin.Events.DiscordTokenChangedEvent;
import testplugin.plugin.Events.WebhookChangedEvent;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.logging.Logger; import java.util.logging.Logger;
public class Events implements Listener { public class LoggedEvents implements Listener {
private final Logger logger; private final Logger logger;
private final WebhookEventLogger plugin; private final WebhookEventLogger plugin;
private String webhookURL; private String webhookURL;
public Events(Logger logger, WebhookEventLogger plugin, String webhookURL) { public LoggedEvents(Logger logger, WebhookEventLogger plugin, String webhookURL) {
this.logger = logger; this.logger = logger;
this.plugin = plugin; this.plugin = plugin;
this.webhookURL = webhookURL; this.webhookURL = webhookURL;
@ -91,6 +96,23 @@ public class Events implements Listener {
} }
} }
@EventHandler(priority = EventPriority.LOW)
public void onPlayerAdvancement(PlayerAdvancementDoneEvent event) {
DiscordWebhook Webhook = new DiscordWebhook(webhookURL);
String advancementName = PlainTextComponentSerializer.plainText().serialize(event.getAdvancement().getDisplay().displayName());
Player player = event.getPlayer();
Webhook.setContent(player.getName() + " has made the advancement `" + advancementName + "`");
try {
Webhook.execute();
} catch (IOException e) {
logger.severe(Arrays.toString(e.getStackTrace()));
}
}
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onWebhookChanged(WebhookChangedEvent event) { public void onWebhookChanged(WebhookChangedEvent event) {
this.webhookURL = event.getMessage(); this.webhookURL = event.getMessage();

View File

@ -1,7 +1,7 @@
name: WebhookEventLogger name: WebhookEventLogger
version: '${project.version}' version: '${project.version}'
main: testplugin.plugin.WebhookEventLogger main: testplugin.plugin.WebhookEventLogger
api-version: 1.19 api-version: 1.20
authors: [ tommy ] authors: [ tommy ]
description: test description: test