Skip to content

Commit

Permalink
wh files
Browse files Browse the repository at this point in the history
  • Loading branch information
asmahdi08 committed Nov 14, 2024
1 parent abb7fdd commit 17fc2c6
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 17 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,11 @@
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
package me.ashfaq.commandReporterPlugin;

import me.ashfaq.commandReporterPlugin.Webhooks.Discord_WH;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class CommandReporterPlugin extends JavaPlugin {
public final class CommandReporterPlugin extends JavaPlugin implements Listener {

static String webhookUrl = "https://discord.com/api/webhooks/1296440357722001419/5R7Mji5GtfzeerHAjeQoS6o2zXs0qrkqTp-ekBDi6j-72075BCO2penB3UolHPXDsWEJ";

@Override
public void onEnable() {
// Plugin startup logic
System.out.println("CommandReporter plugin started");
System.out.println("CommandReporter plugin started boiiii");;

getServer().getPluginManager().registerEvents(this, this);
}

@Override
public void onDisable() {
// Plugin shutdown logic
System.out.println("CommandReporter plugin stopped");
}

@EventHandler
public void onCommandSend(PlayerCommandPreprocessEvent event){
String Player = String.valueOf(event.getPlayer().getName());
String command = event.getMessage();
Boolean Suspicion = false;
new Discord_WH().sendRequest(webhookUrl, Player, command, Suspicion);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package me.ashfaq.commandReporterPlugin;

public class CommandReporterSettings {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,69 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import org.jetbrains.annotations.NotNull;

public class Discord_WH {

public void sendRequest(String webhookUrl) {
static String webhookurl = "https://discord.com/api/webhooks/1296440357722001419/5R7Mji5GtfzeerHAjeQoS6o2zXs0qrkqTp-ekBDi6j-72075BCO2penB3UolHPXDsWEJ";

public void sendRequest(@NotNull String webhookUrl, @NotNull String playerName, @NotNull String commandText, @NotNull Boolean suspicion) {

String titleText = "Command Executed";
String msgText = "";
String adminRole = "everyone";
String embedColor = "65280";
String webhookAvatarURL = "https://i.imgur.com/wSeLqyM.jpeg";
String embedIconURL = "https://i.imgur.com/ZTuP6fGb.jpg";
String footerText = "";
String footerIconURL = "";

if(suspicion) {
msgText = "@" + adminRole;
}

URI requestUri = null;
try {
requestUri = new URI(webhookUrl);
} catch (URISyntaxException e) {
e.printStackTrace();
}

if(suspicion) {
titleText = "Suspicious Command Executed";
}


HttpRequest postRequest = HttpRequest.newBuilder()
.uri(requestUri)
.header("Content-Type", "application/json")
.header("User-Agent", "CommandReporterPlugin-Minecraft")
.POST(HttpRequest.BodyPublishers.ofString("{\n" +
" \"content\": \"Hello from your Discord webhook!\",\n" +
" \"username\": \"Webhook Bot\",\n" +
" \"embeds\": [\n" +
" {\n" +
" \"title\": \"Webhook Example\",\n" +
" \"description\": \"This is an example of a Discord webhook message.\",\n" +
" \"color\": 65280\n" +
" }\n" +
" ]\n" +
" }"))
"\t\"username\": \"Command Reporter Minecraft\",\n" +
"\t\"avatar_url\": \""+webhookAvatarURL+"\",\n" +
"\t\"content\": \""+msgText+"\",\n" +
"\t\"embeds\": [\n" +
"\t\t{\n" +
"\t\t\t\"author\": {\n" +
"\t\t\t\t\"name\": \""+ playerName + "\",\n" +
"\t\t\t\t\"icon_url\": \""+embedIconURL+"\"\n" +
"\t\t\t},\n" +
"\t\t\t\"title\": \""+titleText+"\",\n" +
"\t\t\t\"description\": \"Player executed the following command **"+commandText+"**.\",\n" +
"\t\t\t\"color\": "+embedColor+"\n" +
"\t\t\t\"footer\": {\n" +
"\t\t\t\t\"text\": \""+ footerText + "\",\n" +
"\t\t\t\t\"icon_url\": \""+ footerIconURL + "\",\n" +
"\t\t}\n" +
"\t]\n" +
"}"))
.build();


HttpClient httpClient = HttpClient.newHttpClient();

try {
HttpResponse<String> postResponse = httpClient.send(postRequest, HttpResponse.BodyHandlers.ofString());
System.out.println("Status: " + postResponse.statusCode());
//System.out.println("Status: " + postResponse.statusCode());
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
Expand All @@ -53,8 +81,10 @@ public void sendRequest(String webhookUrl) {

}

/*
public static void main(String[] args) {
new Discord_WH().sendRequest("https://discord.com/api/webhooks/1296440357722001419/5R7Mji5GtfzeerHAjeQoS6o2zXs0qrkqTp-ekBDi6j-72075BCO2penB3UolHPXDsWEJ");
new Discord_WH().sendRequest(webhookurl, "Bara","/fill", true);
}
*/

}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CommandReporterPlugin
version: '1.0-SNAPSHOT'
main: me.ashfaq.commandReporterPlugin.CommandReporterPlugin
api-version: '1.21.1'
api-version: '1.21'
description: "A spigot plugin that reports commands executed by players."
16 changes: 16 additions & 0 deletions src/main/resources/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file contains the settings for the Command Reporter Plugin. For setting suspicious commands, head over to the "suspicious commands.yml" file.

discord:
webhook-url: ""
webhook-username: "Command Reporter"
webhook-avatar-url: ""
embed-color: "65280"
embed-icon-url: "https://i.imgur.com/ZTuP6fGb.jpg"

# Leave both of these empty if you don't want a footer.
embed-footer-text: "Command Reporter Plugin"
embed-footer-icon-url: ""

# Specify the discord role that will be mentioned if a suspicious command is executed.
# DO NOT INCLUDE THE @ SYMBOL
admin-role: "everyone"
Empty file.

0 comments on commit 17fc2c6

Please sign in to comment.