Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enchantment Webhook #27

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.shweit.serverapi.utils.Logger;
import com.shweit.serverapi.webhooks.block.*;
import com.shweit.serverapi.webhooks.enchantment.EnchantItem;
import com.shweit.serverapi.webhooks.server.PluginDisable;
import com.shweit.serverapi.webhooks.server.PluginEnable;
import com.shweit.serverapi.webhooks.server.ServerStart;
Expand Down Expand Up @@ -56,6 +57,9 @@ public void registerWebHooks(final FileConfiguration config) {

new SignChange().register();
Logger.debug("Registered sign_change WebHook");

new EnchantItem().register();
Logger.debug("Registered enchant_item WebHook");
}

public static void sendToAllUrls(final JSONObject jsonObject) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/shweit/serverapi/webhooks/WebHookEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum WebHookEnum {
BLOCK_BURN("block_burn", "Triggered when a block is burned"),
BLOCK_REDSTONE("block_redstone", "Triggered when a block is powered by redstone or a redstone current changes"),
NOTE_PLAY("note_play", "Triggered when a note block plays a note"),
SIGN_CHANGE("sign_change", "Triggered when a sign is changed"),;
SIGN_CHANGE("sign_change", "Triggered when a sign is changed"),
ENCHANT_ITEM("enchant_item", "Triggered when an item is enchanted"),;

public final String label;
public final String description;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.shweit.serverapi.webhooks.enchantment;

import com.shweit.serverapi.MinecraftServerAPI;
import com.shweit.serverapi.webhooks.RegisterWebHooks;
import com.shweit.serverapi.webhooks.WebHook;
import com.shweit.serverapi.webhooks.WebHookEnum;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.json.JSONObject;

public final class EnchantItem implements WebHook, Listener {

private final String eventName = WebHookEnum.ENCHANT_ITEM.label;

@Override
public void register() {
if (RegisterWebHooks.doActivateWebhook(eventName)) {
MinecraftServerAPI plugin = MinecraftServerAPI.getInstance();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}

@EventHandler
public void onEnchantItem(final EnchantItemEvent event) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("event", eventName);
jsonObject.put("item", event.getItem().getType().name());
jsonObject.put("player", event.getEnchanter().getName());
jsonObject.put("enchantments", event.getEnchantsToAdd().toString());
jsonObject.put("location", event.getEnchantBlock().getLocation().toString());
jsonObject.put("expLevelCost", event.getExpLevelCost());
jsonObject.put("levelHint", event.getLevelHint());

RegisterWebHooks.sendToAllUrls(jsonObject);
}
}
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ webhooks:
block_redstone: true
note_play: true
sign_change: true
enchant_item: true

# Here you can list an extra set of Files or Directories which should be saved by the Backup-System.
# Following directories and files are already saved by default: ["world", "world_nether", "world_the_end", "plugins", "config", "server.properties", "banned-ips.json", "banned-players.json", "ops.json", "whitelist.json"]
Expand Down
Loading