Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- options:
- token: <BOT_TOKEN>
- channelId: <CHANNEL_ID>
- import:
- com.btk5h.skriptmirror.JavaType
- org.apache.logging.log4j.LogManager
- javassist.ClassPool
- javassist.CtField
- javassist.CtMethod
- javassist.CtNewConstructor
- org.bukkit.Bukkit
- on load:
- set {_enabledvixio} to Bukkit.getPluginManager().isPluginEnabled("Vixio")
- set {_enableddiscordsrv} to Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")
- {_enabledvixio} or {_enableddiscordsrv}
- set {_cp} to ClassPool.getDefault()
- try {_cp}.get("com.akon.discordlogger.DiscordLogger") is not set
- if {_enabledvixio}:
- {_cp}.insertClassPath(Bukkit.getPluginManager().getPlugin("Vixio").[org.bukkit.plugin.java.JavaPlugin]getFile().toString())
- else if {_enableddiscordsrv}:
- {_cp}.insertClassPath(Bukkit.getPluginManager().getPlugin("DiscordSRV").[org.bukkit.plugin.java.JavaPlugin]getFile().toString())
- {_cp}.importPackage("net.dv8tion.jda.core")
- {_cp}.importPackage("net.dv8tion.jda.core.entities")
- {_cp}.importPackage("org.apache.logging.log4j")
- {_cp}.importPackage("org.apache.logging.log4j.core")
- set {_ctclass} to {_cp}.makeClass("com.akon.discordlogger.DiscordLogger")
- {_ctclass}.setSuperclass({_cp}.get("org.apache.logging.log4j.core.filter.AbstractFilter"))
- {_ctclass}.addField(CtField.make("private JDA bot = null;", {_ctclass}))
- {_ctclass}.addField(CtField.make("private TextChannel channel = null;", {_ctclass}))
- {_ctclass}.addConstructor(CtNewConstructor.make("public DiscordLogger(String token, long channelId) {super(org.apache.logging.log4j.core.Filter.Result.NEUTRAL, org.apache.logging.log4j.core.Filter.Result.NEUTRAL); try {this.bot = new JDABuilder(AccountType.BOT).setToken(token).build().awaitReady(); this.channel = this.bot.getTextChannelById(channelId);} catch (Exception ex) {ex.printStackTrace();}}", {_ctclass}))
- {_ctclass}.addMethod(CtMethod.make("public void sendMessageToDiscord(String message) {this.channel.sendMessage(new MessageBuilder(message).build()).queue();}", {_ctclass}))
- {_ctclass}.addMethod(CtMethod.make("private org.apache.logging.log4j.core.Filter.Result log(Level level, String message, Throwable throwable) {if (this.bot != null && this.channel != null) {message = message.replaceAll((char)27 + ""\\[(\\d{1,2}(;\\d{1,2})*)?m"", """"); java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(""HH:mm:ss""); java.util.Date date = new java.util.Date(System.currentTimeMillis()); this.sendMessageToDiscord(""["" + format.format(date) + "" "" + level.name() + ""]: "" + message);} return org.apache.logging.log4j.core.Filter.Result.NEUTRAL;}", {_ctclass}))
- {_ctclass}.addMethod(CtMethod.make("public org.apache.logging.log4j.core.Filter.Result filter(Logger logger, Level level, Marker marker, String s, Object[] object) {return this.log(level, s, null);}", {_ctclass}))
- {_ctclass}.addMethod(CtMethod.make("public org.apache.logging.log4j.core.Filter.Result filter(Logger logger, Level level, Marker marker, Object o, Throwable throwable) {return this.log(level, o.toString(), throwable);}", {_ctclass}))
- {_ctclass}.addMethod(CtMethod.make("public org.apache.logging.log4j.core.Filter.Result filter(Logger logger, Level level, Marker marker, org.apache.logging.log4j.message.Message message, Throwable throwable) {return this.log(level, message.getFormattedMessage(), throwable);}", {_ctclass}))
- {_ctclass}.addMethod(CtMethod.make("public org.apache.logging.log4j.core.Filter.Result filter(LogEvent logEvent) {return this.log(logEvent.getLevel(), logEvent.getMessage().getFormattedMessage(), logEvent.getThrown());}", {_ctclass}))
- set {_javatype} to new JavaType({_ctclass}.toClass(Bukkit.getPluginManager().getPlugin("Skript").[org.bukkit.plugin.java.JavaPlugin]getClassLoader()))
- set {discordlogger} to new {_javatype}("{@token}", {@channelId})
- LogManager.getRootLogger().addFilter({discordlogger})
Advertisement
Add Comment
Please, Sign In to add comment