Sending Player To Custom Location On Death

Discussion in 'Plugin Development' started by toxiccoke, May 18, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    toxiccoke

    Hi
    I am working on my plugin and i need to send the player on death and join to the custom location that will be set using a command every thing sets correctly and it Evan works fine on the join event but for some reasy i am having troubles on the death event i have been trying different ways but i cannot work out how to fix it im sure it just a stupid noobie mistake but i cannot see it


    Death Event
    Code:
    package me.toxiccoke.paintball.Events;
    
    import me.toxiccoke.paintball.Teams.Teams;
    import me.toxiccoke.paintball.Utils.SettingsManager;
    import me.toxiccoke.paintball.Utils.Spawns;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    
    public class PlayerDeath implements Listener {
       
        SettingsManager settings = SettingsManager.getInstance();
       
        @EventHandler
        public void onDeath(PlayerDeathEvent e){
            Player p = e.getEntity();
            if (e.getEntity() instanceof Player){
            if(Teams.redTeam.contains(p.getName())){
            Spawns.onRedSpawn(p);   
            }else{
                if(Teams.blueTeam.contains(p.getName())){
                    Spawns.onRedSpawn(p);
                }
            }
        }
    }
    }
    Spawn Methods

    Code:
    package me.toxiccoke.paintball.Utils;
    
    import me.toxiccoke.paintball.Teams.Teams;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    
    public class Spawns {
       
        public static SettingsManager settings = SettingsManager.getInstance();
       
        public static void onRedSpawn(Player p){
                if (settings.getData().getConfigurationSection("redspawn") == null) {
                    ChatUtils.sendMessage(p, "Red Team's Spawn Has Not Yet Been Set");
                    return;
            }
            World w = Bukkit.getServer().getWorld(settings.getData().getString("redspawn.world"));
            double x = settings.getData().getDouble("redspawn.x");
            double y = settings.getData().getDouble("redspawn.y");
            double z = settings.getData().getDouble("redspawn.z");
            p.teleport(new Location(w, x, y, z));
        }
       
        public static void onBlueSpawn(Player p){
                if (settings.getData().getConfigurationSection("bluespawn") == null) {
                    ChatUtils.sendMessage(p, "Blue Team's Spawn Has Not Yet Been Set");
                    return;
            }
            World w = Bukkit.getServer().getWorld(settings.getData().getString("bluespawn.world"));
            double x = settings.getData().getDouble("bluespawn.x");
            double y = settings.getData().getDouble("bluespawn.y");
            double z = settings.getData().getDouble("bluespawn.z");
            p.teleport(new Location(w, x, y, z));
            }
           
        }
    If you need anymore info please ask
    thanks toxiccoke
     
  2. Offline

    caderape

    @toxiccoke Use PlayerRespawnEvent for set the respawn.
    A dead player cannot be teleported
     
  3. Offline

    toxiccoke

    @caderape ok ty i will try this now you have helped me out a lot lately thanks :)

    @caderape that dont seem to work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  4. Offline

    Epicballzy

  5. Offline

    xMrPoi

    What does your code look like?
     
  6. Offline

    toxiccoke

    @xMrPoi This is what i have atm
    Code:
    package me.toxiccoke.paintball.Events;
    
    import me.toxiccoke.paintball.Teams.Teams;
    import me.toxiccoke.paintball.Utils.SettingsManager;
    import me.toxiccoke.paintball.Utils.Spawns;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    
    public class PlayerDeath implements Listener {
       
        SettingsManager settings = SettingsManager.getInstance();
       
        @EventHandler
        public void onDeath(PlayerRespawnEvent e){
            Player p = e.getPlayer();
            if(Teams.redTeam.contains(p.getName())){
                Spawns.onRedSpawn(p);
            }else{
                if(Teams.blueTeam.contains(p.getName())){
                    Spawns.onBlueSpawn(p);
                   
                }
            }
        }
    }
    same methods
     
  7. Offline

    xMrPoi

  8. Offline

    toxiccoke

  9. Offline

    Konato_K

  10. Offline

    toxiccoke

    @Konato_K As far as i know that would not work as i am trying to teleport player to team spawn and correct me if im wrong but you can only set one spawn that way if i am wrong please explain how i could use this
     
  11. Offline

    ImaTimelord7

    @toxiccoke if you still need help, tahg me
    But you could cancel his death, remove his inventory if you want, and then teleport him?
     
  12. Invisible

    Reynergodoy

    Code:
            p.teleport(p.getWorld().getSpawnLocation());
    // thats for the world spawn, you can easily set the X,Y,Z
    :)
     
  13. Offline

    toxiccoke

    @ImaTimelord7 umm but would i be able to keep deaths with that as you would be canceling the death

    @Reynergodoy thats only for one spawn i need to set a spawn for each team

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  14. Offline

    ImaTimelord7

    @toxiccoke Ok, you could try starting a delay after they are killed to teleport them
     
  15. Offline

    Konato_K

    @toxiccoke Run different logic for different teams.
     
  16. Offline

    toxiccoke

    @Konato_K sorry this may sound noobie but i dont understand
     
  17. Offline

    xMrPoi

    @toxiccoke The setRespawnLocation method will set that player's spawn point. Just check which team they're on and set the spawn point accordingly.
     
  18. Offline

    caderape

    @toxiccoke
    Make your method 'public static void onRedSpawn(Player p)' return a location.
    then you can do e.setRespawnLocation(onRedSpawn(p));
    and same for the other team.

    PlayerRespawnEvent is the best way for doing it.

    Note: you might have others plugins who handle the respawn, so play with the priority.
     
  19. Offline

    I Al Istannen

    @toxiccoke OR run an delayed task one tick later in the respawn event. Works for me atleast, and doesn't replace the spawnLocation :)
     
  20. Offline

    Konato_K

  21. Invisible

    Reynergodoy

    Code:
    @EventHandler * your bukkit event or a custom one *
    {      
            Player p = e.getPlayer();
    if (*YOUR ARRAY LIST*.teamblue.contains(p.getName()) &&
         p.teleport(p.getWorld().//X Y Z());
    }
    else
    {
    if (*YOUR ARRAY LIST*.teamred.contains(p.getName()) &&
         p.teleport(p.getWorld().//X Y Z());
     
  22. Offline

    I Al Istannen

    @Konato_K I just realized the setSpawnpoint() isn't permanent. Thats nice then. Forget my method, thanks for that ;)
     
Thread Status:
Not open for further replies.

Share This Page