Skip to content

Commit

Permalink
Merge pull request #186 from TerrorByteTW/Honeypot-3.3.2
Browse files Browse the repository at this point in the history
Honeypot-3.3.2
  • Loading branch information
natereprogle authored Jun 24, 2024
2 parents a16f39a + 5ed311d commit 3fc2935
Show file tree
Hide file tree
Showing 16 changed files with 414 additions and 225 deletions.
2 changes: 1 addition & 1 deletion api/build.gradle.kts
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"

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
group = "org.reprogle"
version = "3.3.0"
version = "3.3.2"

java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
java.toolchain.languageVersion.set(JavaLanguageVersion.of(21))

plugins {
java
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ boosted-yaml = "1.3.5"
bstats = "3.0.2"

guice = '7.0.0'
okhttp = '4.12.0'

[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
Expand All @@ -39,4 +40,5 @@ placeholder-api = { module = "me.clip:placeholderapi", version.ref = "placeholde
boosted-yaml = { module = "dev.dejvokep:boosted-yaml", version.ref = "boosted-yaml" }
bstats = { module = "org.bstats:bstats-bukkit", version.ref = "bstats" }

guice = { module = "com.google.inject:guice", version.ref = "guice"}
guice = { module = "com.google.inject:guice", version.ref = "guice" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
3 changes: 2 additions & 1 deletion spigot/build.gradle.kts
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"] = "spigot"

Expand Down Expand Up @@ -39,6 +39,7 @@ dependencies {
compileOnly(libs.lands)

implementation(libs.guice)
implementation(libs.okhttp)
}

// Configure the file output names of most files (Excluding shadow, which needs tweaking itself to avoid a "-all" being tagged onto it)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings.OptionSorting;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.reprogle.honeypot.Honeypot;

import java.io.File;
import java.io.IOException;
Expand All @@ -52,7 +50,7 @@ public class HoneypotConfigManager {
* decoding the jar to get the files that way but that's suuuuper icky.
* (https://www.spigotmc.org/threads/getresources-function.226318/ if anyone wants an example)
*/
private final List<String> languages = Arrays.asList("en_US", "es_MX", "fr_FR", "ja_JP");
private final List<String> languages = Arrays.asList("en_US", "es_MX", "fr_FR", "ja_JP", "zh_CN");

/**
* Sets up the plugin config and saves it to private variables for use later. Will shut down the plugin if there are
Expand Down
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();

}
}
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@
import com.google.inject.Singleton;
import org.bukkit.Server;
import org.reprogle.honeypot.Honeypot;
import org.reprogle.honeypot.common.utils.HoneypotConfigManager;

@Singleton
public class AdapterManager {

private final Honeypot plugin;
private final HoneypotConfigManager configManager;

/**
* Private constructor to hide implicit one
*/
@Inject
public AdapterManager(Honeypot plugin) {
public AdapterManager(Honeypot plugin, HoneypotConfigManager configManager) {
this.configManager = configManager;
this.plugin = plugin;
}

private static WorldGuardAdapter wga = null;
private WorldGuardAdapter wga = null;

private static GriefPreventionAdapter gpa = null;
private GriefPreventionAdapter gpa = null;

private static LandsAdapter la = null;
private LandsAdapter la = null;

public void onLoadAdapters(Server server) {
if (server.getPluginManager().getPlugin("WorldGuard") != null) {
Expand All @@ -32,7 +35,7 @@ public void onLoadAdapters(Server server) {

public void onEnableAdapters(Server server) {
if (server.getPluginManager().getPlugin("GriefPrevention") != null)
gpa = new GriefPreventionAdapter();
gpa = new GriefPreventionAdapter(configManager);

if (server.getPluginManager().getPlugin("Lands") != null) {
la = new LandsAdapter(plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
*/
public class GriefPreventionAdapter {

@Inject
private HoneypotConfigManager configManager;
private final HoneypotConfigManager configManager;

protected GriefPreventionAdapter(HoneypotConfigManager configManager) {
this.configManager = configManager;
}

/**
* Check if the player has permission
Expand Down
15 changes: 12 additions & 3 deletions spigot/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
######################################################################

# File verison (do NOT edit):
file-version: 19
file-version: 20

# How many Honeypots to store in cache at any given time. The maximum size is 50, and anything larger than that is ignored.
# Setting this to <=0 will disable caching
Expand Down Expand Up @@ -60,11 +60,20 @@ ghost-honeypot-checker:
# Enable more detailed logging, stored in a honeypot.log file in the Honeypot folder
enable-logging: true

# Enable Discord Webhooks. This will send messages to Discord via your webhook URL if a Honeypot is broken and/or activated
# Change "send-when" to "onbreak" when you want to be notified of all breaks (Including when action is taken).
# Change it to "action" if you want to be notified of only actions taken
# If none of these match. the default will be "action"
discord:
enable: false
url: "https://www.example.com"
send-when: action

######################################################################
# C H A T S E T T I N G S #
######################################################################

# Select your language. Current supported languages are: [en_US, es_MX, fr_FR, ja_JP]
# Select your language. Current supported languages are: [en_US, es_MX, fr_FR, ja_JP, zh_CN]
# Want to create your own translation? Visit here: https://github.com/TerrorByteTW/Honeypot/wiki/Translating-Honeypot
language: en_US

Expand Down Expand Up @@ -127,7 +136,7 @@ enable-debug-mode: false
# Credit where credit is due! If you contribute to Honeypot in any way, you'll get your name here
# Code Contributions: TerrorByte, SandwichBtw (Build tools modernization)
# Feature Contributions: MattVid#3488, Jammers, melaniebeedot
# Translation Contributions: siyukatu#4489 (ja_JP)
# Translation Contributions: siyukatu#4489 (ja_JP), HaHaWTH (zh_CN)
# Bug Reports: Casper#9647, siyukatu#4489, MattVid#3488
# The next line is ignored, just a dummy value so the credits above get populated within the config!
thank-you: true
32 changes: 32 additions & 0 deletions spigot/src/main/resources/lang/zh_CN.yml
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: "找不到该玩家相关的历史记录!"
1 change: 1 addition & 0 deletions supported-versions/3.3.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.18-1.20.6
1 change: 1 addition & 0 deletions supported-versions/3.3.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.18-1.21
1 change: 1 addition & 0 deletions supported-versions/3.3.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.21-1.21
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.0
3.3.2

0 comments on commit 3fc2935

Please sign in to comment.