diff --git a/pom.xml b/pom.xml index 3ab3b1b..3dba7b6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ serverLog serverStatusLogger - 1.1 + 2.0 jar Server status logger diff --git a/src/main/java/testplugin/plugin/Commands/setWebhookCommand.java b/src/main/java/testplugin/plugin/Commands/setWebhookCommand.java index 58e5439..9a1bb7f 100644 --- a/src/main/java/testplugin/plugin/Commands/setWebhookCommand.java +++ b/src/main/java/testplugin/plugin/Commands/setWebhookCommand.java @@ -1,4 +1,4 @@ -package testplugin.plugin; +package testplugin.plugin.Commands; import org.bukkit.Bukkit; @@ -7,6 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import testplugin.plugin.Events.WebhookChangedEvent; public class setWebhookCommand implements CommandExecutor { // This method is called, when somebody uses our command diff --git a/src/main/java/testplugin/plugin/Config.java b/src/main/java/testplugin/plugin/Config.java index 022bb51..93e4197 100644 --- a/src/main/java/testplugin/plugin/Config.java +++ b/src/main/java/testplugin/plugin/Config.java @@ -3,6 +3,10 @@ package testplugin.plugin; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.Plugin; +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.Hashtable; + public class Config { private static Plugin plugin; @@ -12,11 +16,24 @@ public class Config { } public void loadConfig() { - String webhookURLPath = "webhookURL"; + Dictionary 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(); - config.addDefault(webhookURLPath,"https://discord.com/api/webhooks/xxx/aaaa-bbbb-ccc"); + + + Enumeration configIterator = configs.keys(); + while (configIterator.hasMoreElements()) { + String configPath = configIterator.nextElement(); + String configDefault = configs.get(configPath); + config.addDefault(configPath,configDefault); + } config.options().copyDefaults(true); plugin.saveConfig(); diff --git a/src/main/java/testplugin/plugin/Events/WebhookChangedEvent.java b/src/main/java/testplugin/plugin/Events/WebhookChangedEvent.java index 05e8974..6c5768c 100644 --- a/src/main/java/testplugin/plugin/Events/WebhookChangedEvent.java +++ b/src/main/java/testplugin/plugin/Events/WebhookChangedEvent.java @@ -1,4 +1,4 @@ -package testplugin.plugin; +package testplugin.plugin.Events; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; diff --git a/src/main/java/testplugin/plugin/LoggedEvents.java b/src/main/java/testplugin/plugin/LoggedEvents.java index 06617f9..5fbca71 100644 --- a/src/main/java/testplugin/plugin/LoggedEvents.java +++ b/src/main/java/testplugin/plugin/LoggedEvents.java @@ -1,5 +1,6 @@ package testplugin.plugin; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -7,20 +8,24 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerAdvancementDoneEvent; import org.bukkit.event.player.PlayerJoinEvent; 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.util.Arrays; import java.util.logging.Logger; -public class Events implements Listener { +public class LoggedEvents implements Listener { private final Logger logger; private final WebhookEventLogger plugin; private String webhookURL; - public Events(Logger logger, WebhookEventLogger plugin, String webhookURL) { + public LoggedEvents(Logger logger, WebhookEventLogger plugin, String webhookURL) { this.logger = logger; this.plugin = plugin; 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) public void onWebhookChanged(WebhookChangedEvent event) { this.webhookURL = event.getMessage(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0782fb1..fd44ee1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: WebhookEventLogger version: '${project.version}' main: testplugin.plugin.WebhookEventLogger -api-version: 1.19 +api-version: 1.20 authors: [ tommy ] description: test