diff --git a/src/main/java/com/shweit/serverapi/webhooks/RegisterWebHooks.java b/src/main/java/com/shweit/serverapi/webhooks/RegisterWebHooks.java index 7a484f1..23c161e 100644 --- a/src/main/java/com/shweit/serverapi/webhooks/RegisterWebHooks.java +++ b/src/main/java/com/shweit/serverapi/webhooks/RegisterWebHooks.java @@ -4,6 +4,10 @@ import com.shweit.serverapi.webhooks.block.*; import com.shweit.serverapi.webhooks.enchantment.EnchantItem; import com.shweit.serverapi.webhooks.entity.*; +import com.shweit.serverapi.webhooks.inventory.Brew; +import com.shweit.serverapi.webhooks.inventory.CraftItem; +import com.shweit.serverapi.webhooks.inventory.FurnaceBurn; +import com.shweit.serverapi.webhooks.inventory.FurnaceSmelt; import com.shweit.serverapi.webhooks.server.PluginDisable; import com.shweit.serverapi.webhooks.server.PluginEnable; import com.shweit.serverapi.webhooks.server.ServerStart; @@ -82,6 +86,21 @@ public void registerWebHooks(final FileConfiguration config) { new ExplosionPrime().register(); Logger.debug("Registered explosion_prime WebHook"); + + new PlayerDeath().register(); + Logger.debug("Registered player_death WebHook"); + + new Brew().register(); + Logger.debug("Registered brew WebHook"); + + new CraftItem().register(); + Logger.debug("Registered craft_item WebHook"); + + new FurnaceBurn().register(); + Logger.debug("Registered furnace_burn WebHook"); + + new FurnaceSmelt().register(); + Logger.debug("Registered furnace_smelt WebHook"); } public static void sendToAllUrls(final JSONObject jsonObject) { diff --git a/src/main/java/com/shweit/serverapi/webhooks/WebHookEnum.java b/src/main/java/com/shweit/serverapi/webhooks/WebHookEnum.java index d81274d..126e672 100644 --- a/src/main/java/com/shweit/serverapi/webhooks/WebHookEnum.java +++ b/src/main/java/com/shweit/serverapi/webhooks/WebHookEnum.java @@ -22,7 +22,11 @@ public enum WebHookEnum { ENTITY_SHOOT_BOW("entity_shoot_bow", "Triggered when an entity shoots a bow"), ENTITY_TAME("entity_tame", "Triggered when an entity is tamed"), EXPLOSION_PRIME("explosion_prime", "Triggered when an explosion is primed"), - PLAYER_DEATH("player_death", "Triggered when a player dies"),; + PLAYER_DEATH("player_death", "Triggered when a player dies"), + BREW("brew", "Triggered when a potion is brewed"), + CRAFT_ITEM("craft_item", "Triggered when an item is crafted"), + FURNACE_BURN("furnace_burn", "Triggered when a furnace burns an item as fuel"), + FURNACE_SMELT("furnace_smelt", "Triggered when a furnace smelts an item"),; public final String label; public final String description; diff --git a/src/main/java/com/shweit/serverapi/webhooks/inventory/Brew.java b/src/main/java/com/shweit/serverapi/webhooks/inventory/Brew.java new file mode 100644 index 0000000..b1899cd --- /dev/null +++ b/src/main/java/com/shweit/serverapi/webhooks/inventory/Brew.java @@ -0,0 +1,36 @@ +package com.shweit.serverapi.webhooks.inventory; + +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.inventory.BrewEvent; +import org.json.JSONObject; + +public final class Brew implements WebHook, Listener { + + private final String eventName = WebHookEnum.BREW.label; + + @Override + public void register() { + if (RegisterWebHooks.doActivateWebhook(eventName)) { + MinecraftServerAPI plugin = MinecraftServerAPI.getInstance(); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + } + + @EventHandler + public void onBrew(final BrewEvent event) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("event", eventName); + jsonObject.put("fuelLevel", event.getFuelLevel()); + jsonObject.put("location", event.getBlock().getLocation().toString()); + + if (event.getContents().getIngredient() != null) { + jsonObject.put("ingredient", event.getContents().getIngredient().getType().name()); + } + RegisterWebHooks.sendToAllUrls(jsonObject); + } +} diff --git a/src/main/java/com/shweit/serverapi/webhooks/inventory/CraftItem.java b/src/main/java/com/shweit/serverapi/webhooks/inventory/CraftItem.java new file mode 100644 index 0000000..6c5a8e1 --- /dev/null +++ b/src/main/java/com/shweit/serverapi/webhooks/inventory/CraftItem.java @@ -0,0 +1,38 @@ +package com.shweit.serverapi.webhooks.inventory; + +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.inventory.CraftItemEvent; +import org.json.JSONObject; + +public final class CraftItem implements WebHook, Listener { + + private final String eventName = WebHookEnum.CRAFT_ITEM.label; + + @Override + public void register() { + if (RegisterWebHooks.doActivateWebhook(eventName)) { + MinecraftServerAPI plugin = MinecraftServerAPI.getInstance(); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + } + + @EventHandler + public void onCraftItem(final CraftItemEvent event) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("event", eventName); + jsonObject.put("item", event.getRecipe().getResult().getType().name()); + jsonObject.put("location", event.getWhoClicked().getLocation().toString()); + jsonObject.put("recipe", event.getRecipe().toString()); + + if (event.getInventory().getResult() != null) { + jsonObject.put("result", event.getInventory().getResult().getType().name()); + } + + RegisterWebHooks.sendToAllUrls(jsonObject); + } +} diff --git a/src/main/java/com/shweit/serverapi/webhooks/inventory/FurnaceBurn.java b/src/main/java/com/shweit/serverapi/webhooks/inventory/FurnaceBurn.java new file mode 100644 index 0000000..90cad40 --- /dev/null +++ b/src/main/java/com/shweit/serverapi/webhooks/inventory/FurnaceBurn.java @@ -0,0 +1,34 @@ +package com.shweit.serverapi.webhooks.inventory; + +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.inventory.FurnaceBurnEvent; +import org.json.JSONObject; + +public final class FurnaceBurn implements WebHook, Listener { + + private final String eventName = WebHookEnum.FURNACE_BURN.label; + + @Override + public void register() { + if (RegisterWebHooks.doActivateWebhook(eventName)) { + MinecraftServerAPI plugin = MinecraftServerAPI.getInstance(); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + } + + @EventHandler + public void onFurnaceBurn(final FurnaceBurnEvent event) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("event", eventName); + jsonObject.put("location", event.getBlock().getLocation().toString()); + jsonObject.put("burnTime", event.getBurnTime()); + jsonObject.put("fuel", event.getFuel().getType().name()); + + RegisterWebHooks.sendToAllUrls(jsonObject); + } +} diff --git a/src/main/java/com/shweit/serverapi/webhooks/inventory/FurnaceSmelt.java b/src/main/java/com/shweit/serverapi/webhooks/inventory/FurnaceSmelt.java new file mode 100644 index 0000000..0fb5afb --- /dev/null +++ b/src/main/java/com/shweit/serverapi/webhooks/inventory/FurnaceSmelt.java @@ -0,0 +1,34 @@ +package com.shweit.serverapi.webhooks.inventory; + +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.inventory.FurnaceSmeltEvent; +import org.json.JSONObject; + +public final class FurnaceSmelt implements WebHook, Listener { + + private final String eventName = WebHookEnum.FURNACE_SMELT.label; + + @Override + public void register() { + if (RegisterWebHooks.doActivateWebhook(eventName)) { + MinecraftServerAPI plugin = MinecraftServerAPI.getInstance(); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + } + + @EventHandler + public void onFurnaceSmelt(final FurnaceSmeltEvent event) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("event", eventName); + jsonObject.put("location", event.getBlock().getLocation().toString()); + jsonObject.put("result", event.getResult().getType().name()); + jsonObject.put("source", event.getSource().getType().name()); + + RegisterWebHooks.sendToAllUrls(jsonObject); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c46f19c..9fbdf05 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -45,6 +45,10 @@ webhooks: entity_tame: true explosion_prime: true player_death: true + brew: true + craft_item: false # This is disabled by default, because it can spam your Webhook-URLs. + furnace_burn: true + furnace_smelt: 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"]