Sueta

Gravestones

1.8

Custom gravestones to save your items on death.

·Plugin

Gravestones

Gravestones is a plugin designed for Survival/Factions servers looking to offer the ability to re-obtain one's items without the chance of them de-spawning. When the Gravestone is right-clicked it displays information about the Gravestone such as the Player, the death message (based off of your death message system), and the date/time they died.

It will also let them know on death that a Gravestone has been created at their previous death location, and send them the coordinates.

If a player dies while seeking their gravestone, their previous gravestone will be destroyed and their items will be dropped.

If the server closes while players have active gravestones, they will be serialized into a YML and re-created when the player rejoins.

Servers Using Gravestones:
NoNonsense (1.16.1)


API:
The plugin does have an API for developers to use, in order to access it you must access the GravestoneManager, an instance of it can be found in my Main class unless you need a new instance.

Example Usage
package com.prophaze.gravestones.storage;

import com.prophaze.gravestones.Main;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class GravestoneCommand implements CommandExecutor {

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if(sender instanceof Player) {
            Player player = (Player)sender;
            Main.getGravestoneManager().createGravestone(player.getLocation(), player, "N/A", new List<ItemStack>);
        }
        return false;
    }

}
GravestoneManager Class
package com.prophaze.gravestones.storage;

import com.prophaze.gravestones.Main;
import com.prophaze.gravestones.utilities.ChatUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class GravestoneManager {

    private final Set<Gravestone> gravestones;

    public GravestoneManager() {
        this.gravestones = new HashSet<>();
    }

    public boolean hasGraveStone(Player player) {
        for(Gravestone gravestone : gravestones) {
            return gravestone.getPlayer().equals(player);
        }
        return false;
    }

    public Gravestone getGraveStone(Player player) {
        return gravestones.stream().filter(gravestone -> gravestone.getPlayer().equals(player)).findFirst().orElse(null);
    }

    public Gravestone getGraveStone(Location loc) {
        return gravestones.stream().filter(gravestone -> gravestone.getLocation().equals(loc)).findFirst().orElse(null);
    }

    public int graveStoneCount() {
        return gravestones.size();
    }

    public Set<Gravestone> getGravestones() {
        return Collections.unmodifiableSet(gravestones);
    }

    public void addGravestone(Gravestone gravestone) {
        this.gravestones.add(gravestone);
    }

    public void removeGravestone(Gravestone gravestone) {
        this.gravestones.remove(gravestone);
    }

    public Gravestone createGravestone(Location loc, Player player, String deathMessage, List<ItemStack> contents) {
        if(hasGraveStone(player)) deleteGravestone(getGraveStone(player));
        Gravestone stone = new Gravestone(loc, player, deathMessage);
        stone.addItems(contents);
        return stone;
    }

    public void deleteGravestone(Gravestone gravestone) {
        if(gravestone != null) {
            if(gravestone.getPlayer().isOnline()) gravestone.getPlayer().sendMessage(ChatUtils
                    .replaceVariables(Main.getInstance().getConfig().getString("broke-old"), gravestone));
            gravestone.dropItems();
            removeGravestone(gravestone);
            gravestone.getLocation().getBlock().setType(gravestone.getPreviousBlock());
        }
    }

}

Similar projects

Plugin →