Developer API

Integrate ReanimateMC into your plugins

API Overview

ReanimateMC provides a comprehensive API for developers to integrate the KO system into their plugins. You can listen to events, access the KO manager, and programmatically control the KO state of players.

Getting Started

Adding ReanimateMC as a Dependency

plugin.yml

name: YourPlugin
version: 1.0.0
depend: [ReanimateMC]
# or for optional dependency
# softdepend: [ReanimateMC]

Maven (pom.xml)

<dependencies>
    <dependency>
        <groupId>fr.jachou</groupId>
        <artifactId>ReanimateMC</artifactId>
        <version>1.2.02</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

Gradle (build.gradle)

dependencies {
    compileOnly 'fr.jachou:ReanimateMC:1.2.02'
}

Basic Plugin Setup

import fr.jachou.reanimatemc.ReanimateMC;
import fr.jachou.reanimatemc.managers.KOManager;

public class YourPlugin extends JavaPlugin {
    private ReanimateMC reanimateMC;
    private KOManager koManager;
    
    @Override
    public void onEnable() {
        // Get ReanimateMC instance
        reanimateMC = (ReanimateMC) getServer()
            .getPluginManager().getPlugin("ReanimateMC");
        
        if (reanimateMC == null) {
            getLogger().warning("ReanimateMC not found!");
            return;
        }
        
        // Get KO Manager
        koManager = reanimateMC.getKoManager();
        
        // Register event listeners
        getServer().getPluginManager()
            .registerEvents(new YourEventListener(), this);
    }
}

Events API

PlayerKOEvent

Fired when a player enters the KO state.

Methods:

Method Return Type Description
getPlayer() Player The player entering KO state
getDuration() int KO duration in seconds
isCancelled() boolean Check if event is cancelled
setCancelled(boolean) void Cancel the KO event

Example Usage:

@EventHandler
public void onPlayerKO(PlayerKOEvent event) {
    Player player = event.getPlayer();
    int duration = event.getDuration();
    
    // Custom logic when player enters KO
    if (player.hasPermission("server.vip")) {
        // VIP players get longer KO duration
        // Note: Cannot modify duration directly
        getLogger().info(player.getName() + " is VIP, extending KO");
    }
    
    // Cancel KO for staff members
    if (player.hasPermission("server.staff")) {
        event.setCancelled(true);
        player.sendMessage("Staff bypass: KO cancelled");
    }
    
    // Notify team members
    notifyTeam(player, duration);
}

PlayerReanimatedEvent

Fired when a player is revived from KO state.

Methods:

Method Return Type Description
getPlayer() Player The player being revived
getReanimator() Player Player performing revival (can be null)
isSuccessful() boolean Whether revival was successful
getTimestamp() long Timestamp of revival attempt
getPlayerName() String Name of revived player
getReanimatorName() String Name of reanimator (or "Unknown")

Example Usage:

@EventHandler
public void onPlayerRevived(PlayerReanimatedEvent event) {
    Player patient = event.getPlayer();
    Player medic = event.getReanimator();
    boolean successful = event.isSuccessful();
    
    if (!successful) return;
    
    // Reward the medic
    if (medic != null) {
        // Give XP
        medic.giveExp(50);
        
        // Economy reward (if you have Vault)
        economy.depositPlayer(medic, 100.0);
        
        // Send message
        medic.sendMessage(ChatColor.GREEN + 
            "You saved " + patient.getName() + "!");
        
        // Add to statistics
        addToStats(medic, "revivals_performed");
    }
    
    // Log the revival
    logRevival(patient, medic, event.getTimestamp());
}

KOManager API

Manager Methods

The KOManager provides methods to interact with the KO system programmatically.

Method Description
isKO(Player player) Check if player is currently in KO state
getKOData(Player player) Get KOData object for player (can be null)
setKO(Player player) Set player to KO state (default duration)
setKO(Player player, int seconds) Set player to KO for specific duration
revive(Player target, Player reviver) Revive a KO'd player
execute(Player player) Execute a KO'd player (permanent death)
toggleCrawl(Player player) Toggle crawling mode for KO'd player
sendDistress(Player player) Send distress signal for KO'd player
handleLogout(Player player) Handle player logout while KO'd
pullOfflineKO(UUID uuid) Get remaining KO time for offline player

Example Usage:

// Check if player is KO'd
if (koManager.isKO(player)) {
    player.sendMessage("You are currently KO'd!");
}

// Force KO a player
koManager.setKO(player, 30); // 30 seconds

// Revive a player
if (koManager.isKO(target)) {
    koManager.revive(target, reviverPlayer);
}

// Execute a KO'd player
if (koManager.isKO(target)) {
    koManager.execute(target);
}

// Get KO data
KOData koData = koManager.getKOData(player);
if (koData != null && koData.isKo()) {
    // Player is KO'd, access KO-specific data
    long endTime = koData.getEndTimestamp();
    boolean crawling = koData.isCrawling();
}

Integration Examples

Economy Integration

@EventHandler
public void onRevive(PlayerReanimatedEvent e) {
    if (e.isSuccessful() && e.getReanimator() != null) {
        Player medic = e.getReanimator();
        economy.depositPlayer(medic, 100.0);
        medic.sendMessage("§a+$100 for revival!");
    }
}

Team System

@EventHandler
public void onRevive(PlayerReanimatedEvent e) {
    Player patient = e.getPlayer();
    Player medic = e.getReanimator();
    
    if (medic == null) return;
    
    String patientTeam = getTeam(patient);
    String medicTeam = getTeam(medic);
    
    if (!patientTeam.equals(medicTeam)) {
        medic.sendMessage("§cNot your team!");
        // Note: Event isn't cancellable
    }
}

Achievement System

@EventHandler
public void onRevive(PlayerReanimatedEvent e) {
    if (e.isSuccessful() && e.getReanimator() != null) {
        Player medic = e.getReanimator();
        int revivals = incrementStat(medic, "revivals");
        
        if (revivals == 10) {
            giveAchievement(medic, "First Aid");
        } else if (revivals == 100) {
            giveAchievement(medic, "Guardian Angel");
        }
    }
}

Best Practices

Recommended Practices

  • Null checks: Always check if getReanimator() returns null
  • KO verification: Use isKO() before KO operations
  • Event priorities: Use appropriate priorities for event handlers
  • Cache managers: Store manager references instead of fetching repeatedly
  • Soft dependencies: Use softdepend if ReanimateMC is optional

Common Pitfalls

  • Missing null check: getReanimator() can return null (command usage, NPC revival)
  • Wrong event priority: Use HIGH/HIGHEST if you need to cancel before other plugins
  • Direct field access: Always use getter methods, don't access fields directly
  • Forgetting soft dependency: Declare in plugin.yml to avoid load order issues
NPC System Back to Home