Solved Check if a player dies but not killed by player?

Discussion in 'Spigot Plugin Development' started by OopsyPoopsy, May 4, 2017.

Thread Status:
Not open for further replies.
  1. Hello Spigot.

    In my practice plugin, only when a player gets killed, the killer and player are teleported back to spawn. How do I detect when the player dies but also get the killer back to spawn?
  2. Listen to the death event, use Player#getKiller().

    Also if this is a 1v1 type plugin, you should probably have somewhere where both players are registered as currently fighting. In that case, just teleport both registered fighters back to spawn...
  3. Add me on skype: Diyar.sav (I have a couple of questions)
  4. Yeah. Both players are added to an ArrayList.
  5. Then just teleport them back?

    Side note, why an arraylist?
  6. ArrayList are easy to use in my opinion.
  7. I dont know why you would need an array list would just be bad coding since you wouldent need it..

    If you have alredy have a location to teleport them both you can use a method that goes something like this..

    Remember that his isnt coding since i am doing this on my laptop but well well

    If you want to hardcode the location you do not need to add the location into the method

    Void Teleportplayers(Player p, Player T){

    Location spawn = new location(World, Cordx, CordY, Cordz);



    Then in the event do this

    public void playerkillplayer(PlayerDeathEvent e){
    if(!(e.getkiller instanceof Player)){
    Player p = e.getkiller;
    Player t = e.Player;

    And your done.

    You can ofc do this with out a method where you put the code inse the event but i just like to orginze things
  8. Okay so I added this and still nothing.

    Code (Java):



    new BukkitRunnable() {

    public void run() {

    if (!Queues.inmatch.contains(p)) {


    } else

    if (!Queues.inmatch.contains(target)) {





    Heres my DeathEvent

    Code (Java):


    public void onDeath(PlayerDeathEvent e) {

    if (e.getEntity() instanceof Player) {

    Player p = (Player)e.getEntity();




  9. Ah alright i miss understood so you do have an arraylist for the players?...

    Then you can just do
    Location spawn = spawns cordinations;
    For (Player p : List){
    p.teleport (spawn);

    I hope you are using a map to seperate all the current pvps
  10. There's multiple maps but there's also mutliarena. I don't see how this code will get to the opponent.
  11. Why do you run this asynchronously?
  12. Why is that bad?
  13. Do you mind posting all pertinent classes? In a pastebin pls?
  14. Why'd you tag me??
    • Using a task where you do not need one will perform worse than using no task.
    • You cannot use many Bukkit API methods asynchronously.
    • Doing something async doesn't increase performance. It will relieve the main task, which is not in general necessary. The best example where it makes sense is when you need to load bunches of data from a database. It also theoretically makes sense to load worlds (e.g. DungeonsXL) and to place blocks (e.g. FastAsyncWorldEdit) aynchronously to prevent that your server freezes, but as I said, it's not easily possible with Bukkit.
Thread Status:
Not open for further replies.