-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from TerrorByteTW/Honeypot-3.3.2
Honeypot-3.3.2
- Loading branch information
Showing
16 changed files
with
414 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
group = "org.reprogle" | ||
version = "3.3.0" | ||
version = "3.3.2" | ||
|
||
extra["platform"] = "api" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
436 changes: 230 additions & 206 deletions
436
spigot/src/main/java/org/reprogle/honeypot/common/events/BlockBreakEventListener.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
spigot/src/main/java/org/reprogle/honeypot/common/utils/discord/DiscordWebhookNotifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package org.reprogle.honeypot.common.utils.discord; | ||
|
||
import okhttp3.*; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.reprogle.honeypot.common.utils.HoneypotLogger; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class DiscordWebhookNotifier { | ||
|
||
private final WebhookActionType webhookType; | ||
private final String webhookUrl; | ||
private final Block block; | ||
private final Player player; | ||
private final HoneypotLogger logger; | ||
|
||
private String jsonTemplate = """ | ||
{ | ||
"content": "", | ||
"tts": false, | ||
"embeds": [ | ||
{ | ||
"id": 595876530, | ||
"description": "The honeypot located at %coordinates% in world %world% was triggered by %player%!", | ||
"fields": [], | ||
"title": "Honeypot Discord Alert - %webhookType%", | ||
"timestamp": "2024-06-24T00:32:00.000Z", | ||
"color": 11636736, | ||
"thumbnail": { | ||
"url": "https://mc-heads.net/avatar/%UUID%" | ||
} | ||
} | ||
], | ||
"components": [], | ||
"actions": {}, | ||
"username": "Honeypot" | ||
} | ||
"""; | ||
|
||
/** | ||
* Create a Discord webhook to send. This method does not automatically send the webhook, giving the developer more control over when it is actually sent. | ||
* | ||
* @param webhookType The type of webhook. See {@link WebhookActionType} | ||
* @param webhookUrl The url of the Discord webhook to send it to | ||
* @param block The block that triggered the webhook | ||
* @param player The player that triggered the webhook | ||
* @param logger The HoneypotLogger to log to in case something goes wrong | ||
*/ | ||
public DiscordWebhookNotifier(WebhookActionType webhookType, String webhookUrl, Block block, Player player, HoneypotLogger logger) { | ||
this.webhookType = webhookType; | ||
this.webhookUrl = webhookUrl; | ||
this.block = block; | ||
this.player = player; | ||
this.logger = logger; | ||
} | ||
|
||
/** | ||
* Send the webhook that was created. This will send asynchronously, so no success or failure result can be obtained from it. | ||
* In the future this may be changed to a Future to allow receiving of a result. | ||
*/ | ||
public void send() { | ||
String tempBody; | ||
|
||
switch (webhookType) { | ||
case ACTION: | ||
tempBody = jsonTemplate.replace("%webhookType%", "Action Taken"); | ||
break; | ||
case BREAK: | ||
tempBody = jsonTemplate.replace("%webhookType%", "Block Broken"); | ||
break; | ||
default: | ||
tempBody = jsonTemplate.replace("%webhookType%", "Unknown"); | ||
break; | ||
} | ||
|
||
final String finalBody = tempBody.replace("%coordinates%", block.getX() + ", " + block.getY() + ", " + block.getZ()) | ||
.replace("%world%", "\\\"" + block.getWorld().getName() + "\\\"") | ||
.replace("%player%", player.getName()) | ||
.replace("%UUID%", player.getUniqueId().toString()); | ||
|
||
new Thread(() -> { | ||
RequestBody body = RequestBody.create(finalBody, MediaType.get("application/json")); | ||
|
||
Request request = new Request.Builder() | ||
.url(webhookUrl) | ||
.post(body) | ||
.build(); | ||
|
||
new OkHttpClient().newCall(request).enqueue(new Callback() { | ||
@Override | ||
public void onFailure(@NotNull Call call, @NotNull IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
@Override | ||
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { | ||
response.close(); | ||
return; | ||
} | ||
}); | ||
}).start(); | ||
|
||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
spigot/src/main/java/org/reprogle/honeypot/common/utils/discord/WebhookActionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.reprogle.honeypot.common.utils.discord; | ||
|
||
public enum WebhookActionType { | ||
ACTION, | ||
BREAK | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
language-version: 4 | ||
prefix: "&6[Honeypot]&r" | ||
kick-reason: "你因破坏蜜罐方块被踢出, 请勿破坏!" | ||
ban-reason: "你因破坏蜜罐方块被封禁!" | ||
warn-message: "请勿破坏建筑!" | ||
already-exists: "目标方块已经是一个蜜罐方块了, 如果你想修改惩罚方式, 请删除后重新创建." | ||
success: | ||
created: "成功创建 Honeypot!" | ||
removed: "成功移除 Honeypot!" | ||
default: "操作成功完成!" | ||
not-a-honeypot: "&c目标方块不是蜜罐方块" | ||
no-permission: "&c你没有权限执行该命令" | ||
reload: "配置文件重载中, 如果你修改了语言配置, 请重启服务器以应用更改." | ||
found-pots: "正在高亮附近的蜜罐方块" | ||
no-pots-found: "范围内没有找到任何蜜罐方块" | ||
update-available: "Honeypot 有更新可用. 更新以享受最新功能和安全补丁! 下载链接: &6https://github.com/TerrorByteTW/Honeypot" | ||
against-filter: "你无法这样做, 该方块不在过滤列表中!" | ||
not-looking-at-block: "你需要看向一个方块才能执行此命令!" | ||
no-exist: "配置文件中找不到选定的Honeypot类型!" | ||
deleted: | ||
all: "已删除所有蜜罐方块" | ||
near: "已删除附近的蜜罐方块" | ||
worldguard: "Honeypot 在这片区域已被WorldGuard禁用" | ||
griefprevention: "这片区域由GriefPrevention保护, 你无权在受保护的区域中放置" | ||
lands: "这片区域由Lands保护, 你不能在Lands领地中放置蜜罐方块" | ||
unknown-error: "未知错误, 请联系服务器管理员" | ||
staff-broke: "提醒: 你破坏的是一个蜜罐方块. 已将其自动移除." | ||
exempt-no-break: "你不受破坏惩罚影响, 但是你没有权限破坏蜜罐方块!" | ||
searching: "搜索中..." | ||
truncating: "正在过滤结果..." | ||
not-online: "&c该玩家不在线!" | ||
no-history: "找不到该玩家相关的历史记录!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.18-1.20.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.18-1.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.21-1.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.3.0 | ||
3.3.2 |