mirror of
https://github.com/IdalecioSch/TKNLogs.git
synced 2026-07-28 00:30:08 -03:00
primeirinho
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package org.itakinn.tknlogs;
|
||||
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class DiscordNotifier {
|
||||
private static JDA api;
|
||||
private final static JavaPlugin plugin = TKNLogs.getPlugin();
|
||||
private final static FileConfiguration config = plugin.getConfig();
|
||||
private static TextChannel channel;
|
||||
public DiscordNotifier(){
|
||||
api = JDABuilder.createDefault(config.getString("discord.token")).build();
|
||||
|
||||
/* .addEventListeners(new SlashListener()).build();
|
||||
api.upsertCommand("genimg", "gera uma img")
|
||||
.addOption(OptionType.STRING, "resolução", "resolução da imagem", true, true)
|
||||
.addOption(OptionType.STRING, "prompt", "prompt pra gerar a imagem", true)
|
||||
.queue();*/
|
||||
|
||||
channel = api.getTextChannelById(Objects.requireNonNull(config.getString("discord.channel-id")));
|
||||
}
|
||||
public void sendMessage(String message){
|
||||
channel.sendMessage(message).queue();
|
||||
|
||||
|
||||
}
|
||||
public void sendShutdown(){
|
||||
api.shutdown();
|
||||
}
|
||||
|
||||
public static JDA getJDA() {return api;}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.itakinn.tknlogs;
|
||||
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
|
||||
public class ErrorCatcher extends Handler {
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if (record.getLevel() == Level.SEVERE|| record.getLevel() == Level.WARNING) {
|
||||
String mensagem = record.getMessage();
|
||||
Throwable excecao = record.getThrown();
|
||||
TKNLogs.getDiscord().sendMessage(mensagem);
|
||||
TKNLogs.getDiscord().sendMessage(excecao.toString());
|
||||
//Bukkit.getConsoleSender().sendMessage("§c[ERROR] " + mensagem);
|
||||
|
||||
if (excecao != null) {
|
||||
excecao.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.itakinn.tknlogs;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class TKNLogs extends JavaPlugin {
|
||||
private static DiscordNotifier discord;
|
||||
private static JavaPlugin plugin;
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
saveDefaultConfig();
|
||||
reloadConfig();
|
||||
|
||||
discord = new DiscordNotifier();
|
||||
Logger logger = Bukkit.getLogger();
|
||||
logger.addHandler(new ErrorCatcher());
|
||||
|
||||
}
|
||||
public static JavaPlugin getPlugin(){
|
||||
return plugin;
|
||||
}
|
||||
public static DiscordNotifier getDiscord(){
|
||||
return discord;
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
discord.sendMessage("Desligando o plugin");
|
||||
discord.sendShutdown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
discord:
|
||||
token: ""
|
||||
channel-id: ""
|
||||
@@ -0,0 +1,5 @@
|
||||
name: TKNLogs
|
||||
version: '1.0-SNAPSHOT'
|
||||
main: org.itakinn.tknlogs.TKNLogs
|
||||
api-version: '1.20'
|
||||
authors: [iTakinn]
|
||||
Reference in New Issue
Block a user