Skip to content
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
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Corpse

[![](https://jitpack.io/v/unldenis/Corpse.svg)](https://jitpack.io/#unldenis/Corpse)
[![](https://jitpack.io/v/denmeh/Corpse.svg)](https://jitpack.io/#denmeh/Corpse)

Dead bodies in minecraft for 1.8-1.21.11 servers.

Expand All @@ -27,24 +27,23 @@ Dead bodies in minecraft for 1.8-1.21.11 servers.

## API

Add the dependency (e.g. JitPack) and use `CorpseAPI.getInstance()`:
Add the dependency (e.g. JitPack) and use the **builder API** via `Corpse.fromPlayer()` or `Corpse.fromLocation()`:

```java
CorpseAPI api = CorpseAPI.getInstance();

// At player location, with their skin and inventory
Corpse corpse = api.spawnCorpse(player);
// At player location, with their skin and armor
Corpse corpse = Corpse.fromPlayer(player).spawn();

// At a specific location
Corpse corpse = api.spawnCorpse(player, location);
Corpse corpse = api.spawnCorpse(offlinePlayer, location);
Corpse corpse = Corpse.fromPlayer(player).location(location).spawn();
Corpse corpse = Corpse.fromLocation(location).name(offlinePlayer.getName()).spawn();

// Custom armor (player/offline + location + helmet, chestplate, leggings, boots)
Corpse corpse = api.spawnCorpse(player, location, helmet, chestPlate, leggings, boots);
Corpse corpse = api.spawnCorpse(offlinePlayer, location, helmet, chestPlate, leggings, boots);
// Custom armor (array order: boots, leggings, chestplate, helmet)
ItemStack[] armor = new ItemStack[]{boots, leggings, chestPlate, helmet};
Corpse corpse = Corpse.fromPlayer(player).location(location).armorContents(armor).spawn();
Corpse corpse = Corpse.fromLocation(location).name(name).armorContents(armor).spawn();

// Remove a corpse
api.removeCorpse(corpse);
corpse.destroy();
```

Listen for right‑clicks (and attack) on corpses via `AsyncCorpseInteractEvent`; use `getAction()` to tell interact vs attack.
The builder also supports `.textures(List<TextureProperty>)` for custom skins. Listen for right‑clicks and attacks on corpses via `AsyncCorpseInteractEvent`; use `getAction()` to distinguish interact vs attack.
149 changes: 0 additions & 149 deletions src/main/java/com/github/unldenis/corpse/api/CorpseAPI.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.bukkit.entity.*;
import org.jetbrains.annotations.*;

import java.util.concurrent.atomic.*;

public class RemoveCorpseCommand implements CommandExecutor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.github.unldenis.corpse.command;


import com.github.unldenis.corpse.api.*;
import com.github.unldenis.corpse.corpse.*;
import org.bukkit.*;
import org.bukkit.command.*;
Expand All @@ -35,15 +34,15 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd,
Player player = (Player) sender;
if (player.hasPermission("corpses.spawn")) {
if (args.length == 0) {
new Corpse(player);
Corpse.fromPlayer(player).spawn();
player.sendMessage(ChatColor.GREEN + "Corpse created");
return true;
} else if (args.length == 1) {
OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
if (target.isOnline()) {
CorpseAPI.getInstance().spawnCorpse((Player) target, player.getLocation());
Corpse.fromPlayer((Player) target).location(player.getLocation()).spawn();
} else {
new Corpse(player.getLocation(), target, null);
Corpse.fromLocation(player.getLocation()).name(target.getName()).spawn();
}
player.sendMessage(ChatColor.GREEN + "Corpse created");
return true;
Expand Down
48 changes: 31 additions & 17 deletions src/main/java/com/github/unldenis/corpse/corpse/Corpse.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@
import com.github.unldenis.corpse.util.BedUtil;
import com.github.unldenis.corpse.util.ProfileUtils;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import io.github.retrooper.packetevents.util.SpigotReflectionUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
Expand All @@ -48,8 +46,31 @@
import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;

/**
* Corpse class that represents a dead body.
* To create a Corpse, use fromPlayer, fromLocation methods.
*/
public class Corpse {


/**
* Create a CorpseBuilder from a player.
* @param player The player to create the CorpseBuilder for.
* @return A CorpseBuilder object.
*/
public static CorpseBuilder fromPlayer(@NotNull Player player) {
return new CorpseBuilder(player);
}

/**
* Create a CorpseBuilder from a location.
* @param location The location to create the CorpseBuilder for.
* @return A CorpseBuilder object.
*/
public static CorpseBuilder fromLocation(@NotNull Location location) {
return new CorpseBuilder(location);
}

protected final int id;
protected final Location location;
protected final UserProfile profile;
Expand All @@ -59,8 +80,7 @@ public class Corpse {
private final CorpseNPC internalNPC;
private final boolean hasArmor;

@ApiStatus.Internal
public Corpse(
Corpse(
@NotNull Location location,
@NotNull List<TextureProperty> textures,
@Nullable ItemStack[] armorContents,
Expand Down Expand Up @@ -104,18 +124,6 @@ public Corpse(

}

public Corpse(@NotNull Player player) {
this(player.getLocation(), SpigotReflectionUtil.getUserProfile(player), player.getInventory().getArmorContents(), player.getName());
}

public Corpse(
@NotNull Location location,
@NotNull OfflinePlayer offlinePlayer,
@Nullable ItemStack[] armorContents
) {
this(location, new ArrayList<>(), armorContents, offlinePlayer.getName());
}

@ApiStatus.Internal
public void show(@NotNull Player player) {
this.seeingPlayers.add(player);
Expand Down Expand Up @@ -148,7 +156,6 @@ public void show(@NotNull Player player) {
// show armor
if (hasArmor) {
internalNPC.updateEquipment(channel);
CorpsePlugin.getInstance().getLogger().info("Sent updateEquipment packet with helmet " + internalNPC.getHelmet());
}

}
Expand All @@ -167,6 +174,13 @@ public boolean isShownFor(@NotNull Player player) {
return this.seeingPlayers.contains(player);
}

/**
* Removes this corpse from the world.
*/
public void destroy() {
CorpsePool.getInstance().remove(this.id);
}

public int getId() {
return id;
}
Expand Down
Loading