AutoRespawnPlus API

Nov 28, 2016
AutoRespawnPlus API
  • Welcome to the AutoRespawnPlus API!

    This API is used at times when players Respawn, to do anything you like! :D

    Old version (Deprecated):
    Usage:

    First, we want our package and to register our event:

    Code (Text):
    package me.ishadey.autorespawn;

    import org.bukkit.Bukkit;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Event extends JavaPlugin implements Listener {
     
        public void onEnable() {
         
            Bukkit.getPluginManager().registerEvents(this, this);
         
        }
    }
    Next, let's make our event and a message!

    Code (Text):
    package me.ishadey.autorespawn;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.ishadey.autorespawn.Events.PlayerAutoRespawnEvent;

    public class Event extends JavaPlugin implements Listener {
     
        public void onEnable() {
         
            Bukkit.getPluginManager().registerEvents(this, this);
         
        }

        @EventHandler
        public void onPlayerAutoRespawn(PlayerAutoRespawnEvent event) {
         
            Player player = event.getPlayer();
         
            Location deathLocation = event.getDeathLocation();
         
            player.sendMessage("You died at (" + deathLocation.getX() + ", " +  deathLocation.getZ() + ")!");
         
        }
    }
    So now our plugin finds when the player dies, now let's get more advanced.

    Code (Text):
    package me.ishadey.autorespawn;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.ishadey.autorespawn.Events.PlayerAutoRespawnEvent;

    public class Event extends JavaPlugin implements Listener {
     
        public void onEnable() {
         
            Bukkit.getPluginManager().registerEvents(this, this);
         
        }

        @EventHandler
        public void onPlayerAutoRespawn(PlayerAutoRespawnEvent event) {
         
            Player player = event.getPlayer();
         
            Location deathLocation = event.getDeathLocation();
         
            player.sendMessage("You died at (" + deathLocation.getX() + ", " +  deathLocation.getZ() + ")!");
         
            Location spawnLocation = event.getRespawnLocation();
         
            double respawnTime = event.getRespawnDelaySeconds();
         
            player.sendMessage("But don't worry! You respawned at (" + spawnLocation.getX() + ", " + spawnLocation.getZ() + ") in " + respawnTime + " seconds!");
         
        }
    }
    This now sends the player who died our first message (You died at (X, Z)!) and also our new message (But don't worry! You respawned at (X, Z) in time seconds!)

    The respawnTime is specified in the plugin config and is how long until the plugin automagically respawns the player.

    Now, let's tell the player how they died!

    Code (Text):

    package me.ishadey.autorespawn;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.ishadey.autorespawn.Events.PlayerAutoRespawnEvent;

    public class Event extends JavaPlugin implements Listener {
     
        public void onEnable() {
         
            Bukkit.getPluginManager().registerEvents(this, this);
         
        }

        @EventHandler
        public void onPlayerAutoRespawn(PlayerAutoRespawnEvent event) {
         
            Player player = event.getPlayer();
         
            Location deathLocation = event.getDeathLocation();
         
            player.sendMessage("You died at (" + deathLocation.getX() + ", " +  deathLocation.getZ() + ")!");
         
            Location spawnLocation = event.getRespawnLocation();
         
            double respawnTime = event.getRespawnDelaySeconds();
         
            player.sendMessage("But don't worry! You respawned at (" + spawnLocation.getX() + ", " + spawnLocation.getZ() + ") in " + respawnTime + " seconds!");
         
            if (event.killedByPlayer()) {
             
                Player killer = event.getKiller();
             
                DamageCause deathCause = event.getDeathCause();
             
                player.sendMessage("Player " + killer.getName() + " killed you, they did this with " +  deathCause.toString().toLowerCase());
             
            }
        }
    }
     

    Note the API below is version 3.0 and above only.

    Usage:

    First, we want our package and to register our event:

    Code (Text):
    package me.ishadey.autorespawn;

    import org.bukkit.Bukkit;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Event extends JavaPlugin implements Listener {
     
        public void onEnable() {
         
            Bukkit.getPluginManager().registerEvents(this, this);
         
        }
    }
    Next, let's make our event and a message!

    Code (Text):
    package me.ishadey.autorespawn;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.ishadey.autorespawn.Events.PlayerPreAutoRespawnEvent;

    public class Event extends JavaPlugin implements Listener {
     
        public void onEnable() {
         
            Bukkit.getPluginManager().registerEvents(this, this);
         
        }

        @EventHandler
        public void onPlayerAutoRespawn(PlayerPreAutoRespawnEvent event) {
         
            Player player = event.getPlayer();
         
            Location deathLocation = event.getDeathLocation();
         
            player.sendMessage("You died at (" + deathLocation.getX() + ", " +  deathLocation.getZ() + ")!");
         
        }
    }
    So now our plugin finds when the player dies, now let's get more advanced.

    Code (Text):

    package me.ishadey.autorespawn;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.ishadey.autorespawn.Events.PlayerPreAutoRespawnEvent;

    public class Event extends JavaPlugin implements Listener {
     
        public void onEnable() {
         
            Bukkit.getPluginManager().registerEvents(this, this);
         
        }

        @EventHandler
        public void onPlayerAutoRespawn(PlayerPreAutoRespawnEvent event) {
         
            Player player = event.getPlayer();
         
            Location deathLocation = event.getDeathLocation();
         
            player.sendMessage("You died at (" + deathLocation.getX() + ", " +  deathLocation.getZ() + ")!");
         
            if (event.killedByPlayer()) {
             
                Player killer = event.getKiller();
             
                DamageCause deathCause = event.getDeathCause();
             
                player.sendMessage("Player " + killer.getName() + " killed you, they did this with " +  deathCause.toString().toLowerCase());
             
            }
        }
    }
     


    Awesome! Our player now knows how they died, who killed them and where they died!

    If you ever want to cancel the AutoRespawn, you can now do this in the New API!

    Code (Text):

    package me.ishadey.autorespawn;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.ishadey.autorespawn.Events.PlayerPreAutoRespawnEvent;

    public class Event extends JavaPlugin implements Listener {
     
        public void onEnable() {
         
            Bukkit.getPluginManager().registerEvents(this, this);
         
        }

        @EventHandler
        public void onPlayerAutoRespawn(PlayerPreAutoRespawnEvent event) {
         
            Player player = event.getPlayer();
         
            Location deathLocation = event.getDeathLocation();
         
            player.sendMessage("You died at (" + deathLocation.getX() + ", " +  deathLocation.getZ() + ")!");
         
            if (event.killedByPlayer()) {
             
                Player killer = event.getKiller();
             
                DamageCause deathCause = event.getDeathCause();
             
                player.sendMessage("Player " + killer.getName() + " killed you, they did this with " +  deathCause.toString().toLowerCase());
             
            } else {
               
                player.sendMessage("You was not killed by a player, so we didn't make you automagically respawn :(");
                e.setCancelled(true);
               
            }
        }
    }
     



    Well, that covers most of the API! If you need help, contact @TrollStar12345 via PM.

    Plugin: https://www.spigotmc.org/resources/14412/
  • Loading...
  • Loading...