Problem while respawning?

Discussion in 'Plugin Development' started by nastasescu, Sep 7, 2014.

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

    nastasescu

    Ok, so i have a problem with my plugin.
    I want to disable the respawn screen when a player dies and while the player is in-game (kitpvp1) to respawn him to a random location, i've tried:
    Code:java
    1. public void onPlayerDeath(PlayerDeathEvent e) {
    2. Player p = e.getEntity();
    3. if (joc1kitpvp.contains(p)) {
    4. Location[] loc = {
    5. new Location(Bukkit.getWorld("world"), 492.5, 7, -111.5),
    6. new Location(Bukkit.getWorld("world"), 470.5, 7, -116.5),
    7. new Location(Bukkit.getWorld("world"), 456.5, 7, -89.5),
    8. new Location(Bukkit.getWorld("world"), 466.5, 7, -76.5),
    9. new Location(Bukkit.getWorld("world"), 482.5, 7, -70.5),
    10. new Location(Bukkit.getWorld("world"), 487.5, 7, -80.5),
    11. new Location(Bukkit.getWorld("world"), 495.5, 7, -91.5),
    12. new Location(Bukkit.getWorld("world"), 480.5, 7, -88.5) };
    13. Random randomLoc = new Random();
    14. int randomLocNr = randomLoc.nextInt(loc.length);
    15. Location randomLocc = loc[randomLocNr];
    16. p.teleport(randomLocc);
    17. if (getKit(p) == "Warrior") {
    18. p.getInventory().clear();
    19. p.getInventory().setArmorContents(null);
    20. p.getInventory().setHelmet(
    21. new ItemStack(Material.LEATHER_HELMET));
    22. p.getInventory().setChestplate(
    23. new ItemStack(Material.LEATHER_CHESTPLATE));
    24. p.getInventory().setLeggings(
    25. new ItemStack(Material.LEATHER_LEGGINGS));
    26. p.getInventory()
    27. .setBoots(new ItemStack(Material.LEATHER_BOOTS));
    28. p.getInventory().addItem(new ItemStack(Material.IRON_SWORD));
    29. }
    30. }
    31. }
    32.  
    33. public void onPlayerRespawn(PlayerRespawnEvent e) {
    34. Player p = e.getPlayer();
    35. if (joc1kitpvp.contains(p)) {
    36. Location[] loc = {
    37. new Location(Bukkit.getWorld("world"), 492.5, 7, -111.5),
    38. new Location(Bukkit.getWorld("world"), 470.5, 7, -116.5),
    39. new Location(Bukkit.getWorld("world"), 456.5, 7, -89.5),
    40. new Location(Bukkit.getWorld("world"), 466.5, 7, -76.5),
    41. new Location(Bukkit.getWorld("world"), 482.5, 7, -70.5),
    42. new Location(Bukkit.getWorld("world"), 487.5, 7, -80.5),
    43. new Location(Bukkit.getWorld("world"), 495.5, 7, -91.5),
    44. new Location(Bukkit.getWorld("world"), 480.5, 7, -88.5) };
    45. Random randomLoc = new Random();
    46. int randomLocNr = randomLoc.nextInt(loc.length);
    47. Location randomLocc = loc[randomLocNr];
    48. p.teleport(randomLocc);
    49. if (getKit(p) == "Warrior") {
    50. p.getInventory().clear();
    51. p.getInventory().setArmorContents(null);
    52. p.getInventory().setHelmet(
    53. new ItemStack(Material.LEATHER_HELMET));
    54. p.getInventory().setChestplate(
    55. new ItemStack(Material.LEATHER_CHESTPLATE));
    56. p.getInventory().setLeggings(
    57. new ItemStack(Material.LEATHER_LEGGINGS));
    58. p.getInventory()
    59. .setBoots(new ItemStack(Material.LEATHER_BOOTS));
    60. p.getInventory().addItem(new ItemStack(Material.IRON_SWORD));
    61. }
    62. }
    63. }

    The problem is... when a player press respawn, he will be respawned at the server spawn.
     
  2. Offline

    xize

  3. Offline

    nastasescu

  4. Offline

    Techy4198

    nastasescu you haven't registered your events properly.
     
  5. Offline

    nastasescu

    Techy4198 now i've registered them and the same problem, now i'm trying something like that:
    Code:java
    1. @EventHandler
    2. public void onPlayerTakeDamage(EntityDamageByEntityEvent e) {
    3. Player p = (Player) e.getEntity();
    4. Player a = (Player) e.getDamager();
    5. double damage = e.getDamage();
    6. if (joc1kitpvp.contains(p)) {
    7. if (damage >= p.getHealth()) {
    8. Bukkit.broadcastMessage(ChatColor.BLUE + "KitPVP#1> "
    9. + ChatColor.YELLOW + p.getName() + ChatColor.GRAY
    10. + " was killed by " + ChatColor.YELLOW + a.getName()
    11. + ChatColor.GRAY + " with " + ChatColor.AQUA
    12. + a.getItemInHand().getItemMeta().getDisplayName());
    13. Location[] loc = {
    14. new Location(Bukkit.getWorld("world"), 492.5, 7, -111.5),
    15. new Location(Bukkit.getWorld("world"), 470.5, 7, -116.5),
    16. new Location(Bukkit.getWorld("world"), 456.5, 7, -89.5),
    17. new Location(Bukkit.getWorld("world"), 466.5, 7, -76.5),
    18. new Location(Bukkit.getWorld("world"), 482.5, 7, -70.5),
    19. new Location(Bukkit.getWorld("world"), 487.5, 7, -80.5),
    20. new Location(Bukkit.getWorld("world"), 495.5, 7, -91.5),
    21. new Location(Bukkit.getWorld("world"), 480.5, 7, -88.5) };
    22. Random randomLoc = new Random();
    23. int randomLocNr = randomLoc.nextInt(loc.length);
    24. Location randomLocc = loc[randomLocNr];
    25. p.teleport(randomLocc);
    26. if (getKit(p) == "Warrior") {
    27. p.getInventory().clear();
    28. p.getInventory().setArmorContents(null);
    29. p.getInventory().setHelmet(
    30. new ItemStack(Material.LEATHER_HELMET));
    31. p.getInventory().setChestplate(
    32. new ItemStack(Material.LEATHER_CHESTPLATE));
    33. p.getInventory().setLeggings(
    34. new ItemStack(Material.LEATHER_LEGGINGS));
    35. p.getInventory().setBoots(
    36. new ItemStack(Material.LEATHER_BOOTS));
    37. p.getInventory()
    38. .addItem(new ItemStack(Material.IRON_SWORD));
    39. }
    40. }
    41. }
    42. }


    Ok, it's done, but now i have another problem, when i'm killed, i am respawned with the kit (is OK) but i'm not teleported where i want.
    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent e) {
    3. Player p = e.getEntity();
    4. if (joc1kitpvp.contains(p)) {
    5. if (e.getEntity().getKiller() instanceof Player) {
    6. Bukkit.broadcastMessage(ChatColor.BLUE
    7. + "KitPVP#1> "
    8. + ChatColor.YELLOW
    9. + p.getName()
    10. + ChatColor.GRAY
    11. + " was killed by "
    12. + ChatColor.YELLOW
    13. + e.getEntity().getKiller().getName()
    14. + ChatColor.GRAY
    15. + " with "
    16. + ChatColor.AQUA
    17. + e.getEntity().getKiller().getItemInHand()
    18. .getItemMeta().getDisplayName());
    19. }
    20. }
    21. }
    22.  
    23. @EventHandler
    24. public void onPlayerRespawn(PlayerRespawnEvent e) {
    25. if (joc1kitpvp.contains(e.getPlayer())) {
    26. Location[] loc = {
    27. new Location(Bukkit.getWorld("world"), 492.5, 7, -111.5),
    28. new Location(Bukkit.getWorld("world"), 470.5, 7, -116.5),
    29. new Location(Bukkit.getWorld("world"), 456.5, 7, -89.5),
    30. new Location(Bukkit.getWorld("world"), 466.5, 7, -76.5),
    31. new Location(Bukkit.getWorld("world"), 482.5, 7, -70.5),
    32. new Location(Bukkit.getWorld("world"), 487.5, 7, -80.5),
    33. new Location(Bukkit.getWorld("world"), 495.5, 7, -91.5),
    34. new Location(Bukkit.getWorld("world"), 480.5, 7, -88.5) };
    35. Random randomLoc = new Random();
    36. int randomLocNr = randomLoc.nextInt(loc.length);
    37. Location randomLocc = loc[randomLocNr];
    38. e.getPlayer().teleport(randomLocc);
    39. if (getKit(e.getPlayer()) == "Warrior") {
    40. e.getPlayer().getInventory().clear();
    41. e.getPlayer().getInventory().setArmorContents(null);
    42. e.getPlayer().getInventory()
    43. .setHelmet(new ItemStack(Material.LEATHER_HELMET));
    44. e.getPlayer()
    45. .getInventory()
    46. .setChestplate(
    47. new ItemStack(Material.LEATHER_CHESTPLATE));
    48. e.getPlayer().getInventory()
    49. .setLeggings(new ItemStack(Material.LEATHER_LEGGINGS));
    50. e.getPlayer().getInventory()
    51. .setBoots(new ItemStack(Material.LEATHER_BOOTS));
    52. e.getPlayer().getInventory()
    53. .addItem(new ItemStack(Material.IRON_SWORD));
    54. }
    55. }
    56. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  6. It's pretty simple, at the end of your method, enter e.setDamage(0); and you'll be good. I think... Because the player still takes the damage here, which will kill him. Set the damage to 0 and the player shouldn't die!

    EDIT: This was meant for your previous EntityDamageEvent handler
     
  7. Offline

    nastasescu

    jl97 i don't want this. look at this:
    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent e) {
    3. Player p = e.getEntity();
    4. if (joc1kitpvp.contains(p)) {
    5. Location[] loc = {
    6. new Location(Bukkit.getWorld("world"), 492.5, 7, -111.5),
    7. new Location(Bukkit.getWorld("world"), 470.5, 7, -116.5),
    8. new Location(Bukkit.getWorld("world"), 456.5, 7, -89.5),
    9. new Location(Bukkit.getWorld("world"), 466.5, 7, -76.5),
    10. new Location(Bukkit.getWorld("world"), 482.5, 7, -70.5),
    11. new Location(Bukkit.getWorld("world"), 487.5, 7, -80.5),
    12. new Location(Bukkit.getWorld("world"), 495.5, 7, -91.5),
    13. new Location(Bukkit.getWorld("world"), 480.5, 7, -88.5) };
    14. Random randomLoc = new Random();
    15. int randomLocNr = randomLoc.nextInt(loc.length);
    16. Location randomLocc = loc[randomLocNr];
    17. e.getEntity().teleport(randomLocc);
    18. if (e.getEntity().getKiller() instanceof Player) {
    19. Bukkit.broadcastMessage(ChatColor.BLUE
    20. + "KitPVP#1> "
    21. + ChatColor.YELLOW
    22. + p.getName()
    23. + ChatColor.GRAY
    24. + " was killed by "
    25. + ChatColor.YELLOW
    26. + e.getEntity().getKiller().getName()
    27. + ChatColor.GRAY
    28. + " with "
    29. + ChatColor.AQUA
    30. + e.getEntity().getKiller().getItemInHand()
    31. .getItemMeta().getDisplayName());
    32. }
    33. }
    34. }
    35.  
    36. @EventHandler
    37. public void onPlayerRespawn(PlayerRespawnEvent e) {
    38. if (joc1kitpvp.contains(e.getPlayer())) {
    39. Location[] loc = {
    40. new Location(Bukkit.getWorld("world"), 492.5, 7, -111.5),
    41. new Location(Bukkit.getWorld("world"), 470.5, 7, -116.5),
    42. new Location(Bukkit.getWorld("world"), 456.5, 7, -89.5),
    43. new Location(Bukkit.getWorld("world"), 466.5, 7, -76.5),
    44. new Location(Bukkit.getWorld("world"), 482.5, 7, -70.5),
    45. new Location(Bukkit.getWorld("world"), 487.5, 7, -80.5),
    46. new Location(Bukkit.getWorld("world"), 495.5, 7, -91.5),
    47. new Location(Bukkit.getWorld("world"), 480.5, 7, -88.5) };
    48. Random randomLoc = new Random();
    49. int randomLocNr = randomLoc.nextInt(loc.length);
    50. Location randomLocc = loc[randomLocNr];
    51. e.getPlayer().teleport(randomLocc);
    52. if (getKit(e.getPlayer()) == "Warrior") {
    53. e.getPlayer().getInventory().clear();
    54. e.getPlayer().getInventory().setArmorContents(null);
    55. e.getPlayer().getInventory()
    56. .setHelmet(new ItemStack(Material.LEATHER_HELMET));
    57. e.getPlayer()
    58. .getInventory()
    59. .setChestplate(
    60. new ItemStack(Material.LEATHER_CHESTPLATE));
    61. e.getPlayer().getInventory()
    62. .setLeggings(new ItemStack(Material.LEATHER_LEGGINGS));
    63. e.getPlayer().getInventory()
    64. .setBoots(new ItemStack(Material.LEATHER_BOOTS));
    65. e.getPlayer().getInventory()
    66. .addItem(new ItemStack(Material.IRON_SWORD));
    67. }
    68. }
    69. if (!(joc1kitpvp.contains(e.getPlayer()))) {
    70. for (PotionEffect effect : e.getPlayer().getActivePotionEffects()) {
    71. e.getPlayer().removePotionEffect(effect.getType());
    72. }
    73. e.getPlayer().addPotionEffect(
    74. new PotionEffect(PotionEffectType.SPEED, 999999999, 3));
    75. e.getPlayer().teleport(Bukkit.getWorld("world").getSpawnLocation());
    76. }
    77. }

    After he press respawn, the player receives his kit, but is not teleported!
     
  8. Offline

    SmooshCakez

    Could always try just cancelling the damage leading to the death, that way there is no respawn screen.
     
  9. Offline

    nastasescu

Thread Status:
Not open for further replies.

Share This Page