refactor
This commit is contained in:
parent
e697b1a0f5
commit
b1d94aff3a
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>serverLog</groupId>
|
||||
<artifactId>serverStatusLogger</artifactId>
|
||||
<version>1.1</version>
|
||||
<version>2.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Server status logger</name>
|
||||
|
@ -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
|
||||
|
@ -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<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();
|
||||
|
||||
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);
|
||||
|
||||
plugin.saveConfig();
|
||||
|
@ -1,4 +1,4 @@
|
||||
package testplugin.plugin;
|
||||
package testplugin.plugin.Events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user