From 9c05a3dbc20a2bc3270c48a224a14bbea3f36faa Mon Sep 17 00:00:00 2001 From: SirBlobman Date: Fri, 24 Jun 2022 15:18:00 -0400 Subject: [PATCH] 11.0.0.0: Add more API README examples --- api/README.MD | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/api/README.MD b/api/README.MD index d42555515..5160682b6 100644 --- a/api/README.MD +++ b/api/README.MD @@ -49,13 +49,42 @@ You can see more information about them below: CombatLogX has many uses, but some common examples are provided below. Good luck with your coding! -**Example 01: Check if a player is in combat.** +**Example 01: Check if CombatLogX is enabled and get an instance of it.** +```java +public boolean isEnabled() { + PluginManager pluginManager = Bukkit.getPluginManager(); + return pluginManager.isPluginEnabled("CombatLogX"); +} + +public ICombatLogX getAPI() { + PluginManager pluginManager = Bukkit.getPluginManager(); + Plugin plugin = pluginManager.getPlugin("CombatLogX"); + return (ICombatLogX) plugin; +} +``` + +**Example 02: Check if a player is in combat.** ```java public boolean isInCombat(Player player) { - // You need to ensure that CombatLogX is enabled before using it for anything. - ICombatLogX plugin = (ICombatLogX) Bukkit.getPluginManager().getPlugin("CombatLogX"); + ICombatLogX plugin = getAPI(); ICombatManager combatManager = plugin.getCombatManager(); return combatManager.isInCombat(player); } ``` + +**Example 03: Check if a player was killed by CombatLogX.** + +```java +@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) +public void onDeath(PlayerDeathEvent e) { + Player player = e.getEntity(); + ICombatLogX plugin = getAPI(); + IDeathManager deathManager = plugin.getDeathManager(); + + if(deathManager.wasPunishKilled(player)) { + // Player was killed by CombatLogX + e.setDeathMessage(player.getName() + " was killed for logging out during combat."); + } +} +```