Patched discord nullpointer

This commit is contained in:
TheTelly1
2024-02-20 08:12:55 -06:00
parent f6dc9e3629
commit c9ffde93ab
11 changed files with 282 additions and 52 deletions

View File

@@ -82,7 +82,7 @@ public final class Sentinel extends JavaPlugin {
log.info("Pre-load finished!\n]====---- Requesting Authentication ----====[ \n- License Key: %s\n- Server ID: %s".formatted(license,serverID));
String authStatus = "ERROR";
String authstatus = "ERROR";
/*try {
try {
authStatus = Authenticator.authorize(license, serverID);
authstatus = Auth.authorize(license, serverID);
IP = Authenticator.getPublicIPAddress();
@@ -91,9 +91,7 @@ public final class Sentinel extends JavaPlugin {
e.printStackTrace();
log.info("WTFFFF ARE YOU DOING MAN??????");
manager.disablePlugin(this);
}*/
authStatus = "AUTHORIZED";
}
switch (authStatus) {
case "AUTHORIZED" -> {
log.info("\n]======----- Auth Success! -----======[");

View File

@@ -1,6 +1,7 @@
package io.github.thetrouper.sentinel.server;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import io.github.itzispyder.pdk.utils.discord.DiscordEmbed;
import io.github.itzispyder.pdk.utils.discord.DiscordWebhook;
import io.github.thetrouper.sentinel.Sentinel;
@@ -18,6 +19,7 @@ import org.bukkit.event.Cancellable;
import org.bukkit.inventory.ItemStack;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class Action {
@@ -170,18 +172,22 @@ public class Action {
actions += Emojis.rightSort + " **Logged:** " + Emojis.success;
try {
ServerUtils.sendDebugMessage("Executing webhook...");
DiscordWebhook.create()
.username("Sentinel Anti-Nuke | Logs")
.avatar("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png")
.addEmbed(DiscordEmbed.create()
.author(new DiscordEmbed.Author(actionTop,"https://builtbybit.com/resources/sentinel-anti-nuke.30130/",null))
.title(actionTitle)
.desc(description)
.addField(new DiscordEmbed.Field("Actions:", actions,false))
.thumbnail("https://crafatar.com/avatars/" + player.getUniqueId() + "?size=64&&overlay")
.color(action.getEmbedColor())
.build()).send(Sentinel.mainConfig.plugin.webhook);
String finalDescription = description;
String finalActions = actions;
CompletableFuture.runAsync(()->{
ServerUtils.sendDebugMessage("Executing webhook...");
DiscordWebhook.create()
.username("Sentinel Anti-Nuke | Logs")
.avatar("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png")
.addEmbed(DiscordEmbed.create()
.author(new DiscordEmbed.Author(actionTop,"https://builtbybit.com/resources/sentinel-anti-nuke.30130/",null))
.title(actionTitle)
.desc(finalDescription)
.addField(new DiscordEmbed.Field("Actions:", finalActions,false))
.thumbnail("https://crafatar.com/avatars/" + (player == null ? "049460f7-21cb-42f5-8059-d42752bf406f" : player.getUniqueId()) + "?size=64&&overlay")
.color(action.getEmbedColor())
.build()).send(Sentinel.mainConfig.plugin.webhook);
});
} catch (Exception e) {
ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!"));
Sentinel.log.info(e.toString());

View File

@@ -18,6 +18,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.concurrent.CompletableFuture;
import static io.github.thetrouper.sentinel.server.functions.AntiSpam.heatMap;
import static io.github.thetrouper.sentinel.server.functions.AntiSpam.lastMessageMap;
@@ -200,21 +201,26 @@ public class FilterAction {
}
try {
ServerUtils.sendDebugMessage("Executing webhook...");
DiscordWebhook.create()
.username("Sentinel Anti-Nuke | Logs")
.avatar("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png")
.addEmbed(DiscordEmbed.create()
.author(new DiscordEmbed.Author(supertitle,"https://builtbybit.com/resources/sentinel-anti-nuke.30130/",null))
.title(title)
.desc(String.valueOf(description))
.addField(new DiscordEmbed.Field(historyTitle,historyValue,true))
.addField(new DiscordEmbed.Field(currentTitle,currentValue,true))
.addField(new DiscordEmbed.Field("Executed: ", executed.replaceAll("%player%",offender.getName()),false))
.thumbnail("https://crafatar.com/avatars/" + offender.getUniqueId() + "?size=64&&overlay")
.color(type.getColor())
.build()).send(Sentinel.mainConfig.plugin.webhook);
String finalHistoryTitle = historyTitle;
String finalHistoryValue = historyValue;
String finalCurrentTitle = currentTitle;
String finalCurrentValue = currentValue;
CompletableFuture.runAsync(()->{
ServerUtils.sendDebugMessage("Executing webhook...");
DiscordWebhook.create()
.username("Sentinel Anti-Nuke | Logs")
.avatar("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png")
.addEmbed(DiscordEmbed.create()
.author(new DiscordEmbed.Author(supertitle,"https://builtbybit.com/resources/sentinel-anti-nuke.30130/",null))
.title(title)
.desc(String.valueOf(description))
.addField(new DiscordEmbed.Field(finalHistoryTitle, finalHistoryValue,true))
.addField(new DiscordEmbed.Field(finalCurrentTitle, finalCurrentValue,true))
.addField(new DiscordEmbed.Field("Executed: ", executed.replaceAll("%player%",offender.getName()),false))
.thumbnail("https://crafatar.com/avatars/" + offender.getUniqueId() + "?size=64&&overlay")
.color(type.getColor())
.build()).send(Sentinel.mainConfig.plugin.webhook);
});
} catch (Exception ex) {
ServerUtils.sendDebugMessage("Filter Actions: Epic webhook failure!!!");
Sentinel.log.info(ex.toString());

View File

@@ -24,7 +24,6 @@ public class CMDBlockWhitelist {
Location wll = WhitelistedBlock.fromSerialized(wl.loc());
if (wll.distance(wbl) < 0.5) {
Sentinel.whitelist.whitelistedCMDBlocks.remove(wb);
break;
}
}

View File

@@ -1,20 +0,0 @@
package io.github.thetrouper.sentinel.server.util;
import java.io.File;
public final class FileValidationUtils {
public static boolean validate(File file) {
try {
if (!file.getParentFile().exists())
if (!file.getParentFile().mkdirs())
return false;
if (!file.exists())
return file.createNewFile();
return true;
}
catch (Exception ex) {
return false;
}
}
}