Question on PlayerDeathEvent

Discussion in 'Spigot Plugin Development' started by Sirenum, May 16, 2016.

  1. I have a plugin that has a custom spawn for a game. I have set the spawn using a command and saved it with a file system correctly.

    The objective is to send the killed player to the set spawn once they die, however, I feel as if I am missing something. There are no errors and everything checks out.

    Console output.

    [​IMG]

    Code (Text):
     @EventHandler
        public void onDeath(PlayerDeathEvent event)
        {


            Debug.log(Debug.pluginLog() + "" + getGamePrefix() + " &6Calling Death Event.");
            Player p =  event.getEntity().getPlayer();

            UUID uuid = p.getUniqueId();
            String name = p.getName();

            if(main.getKitInstance().isUserArcher().contains(uuid))
            {
                Debug.log(Debug.pluginLog() + "" + getGamePrefix() + " &6Check worked! Hopefully keeping Inventory and preventing Item pickup");
                event.setKeepInventory(true);
                setArmor(p,main);
                Debug.log(Debug.pluginLog() + getGamePrefix() + "&6Calling the goToSpawn method...");
                goToSpawn(main,p);

            }
        }

    Code (Text):
    public void goToSpawn(Core plugin, Player p)
        {
           Debug.log(Debug.pluginLog() + getGamePrefix() + "&6GoToSpawn Method...");
            if(plugin.getGameSettings().getGameConfig().getConfigurationSection("Game.Settings.setting.spawn") == null)
            {
                p.sendMessage(color("%prefix% &cError: &6The spawn has not been set for this world..."));
            }else
            {
                World world = Bukkit.getServer().getWorld(plugin.getGameSettings().getGameConfig().getString("Game.Settings.setting.spawn.world"));
                double x = plugin.getGameSettings().getGameConfig().getDouble("Game.Settings.setting.spawn.x");
                double y = plugin.getGameSettings().getGameConfig().getDouble("Game.Settings.setting.spawn.y");
                double z = plugin.getGameSettings().getGameConfig().getDouble("Game.Settings.setting.spawn.z");
                p.teleport(new Location(world,x,y,z));
                p.sendMessage(color(""));
            }
        }
     

    Code (Text):
    Game:
      Settings:
        setting:
          spawn:
            world: world
            x: 29.323108410118603
            y: 72.0
            z: -33.0328907891172

    Nothing happens, and when the player is killed they are teleported directly to the default world spawn.

    I have debugged this using command, and I am able to teleport to the configured spawn point.
     
  2. You could try setting the spawn location of the player instead of teleporting him on death
     
  3. ohh. This sounds good. I can't remember off hand.. Is there a specific method for this?
     
    • Agree Agree x 1
    • Agree Agree x 2