Solved Land Mines doesnt cause player damage!

Discussion in 'Plugin Development' started by HeavyMine13, Dec 20, 2013.

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

    HeavyMine13

    Hello! I am trying to make my landmines damage the player, and I used: event.getPlayer().setHealth(10.0) The Problem is, if a player with only one heart runs over a land mine, the player will have his hearts back to 5 hearts! So please help me add damage to a player, like he will lose 5 hearts with each land mine he ran over!

    My code:
    Code:java
    1. package me.HeavyMine13.jm;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Location;
    9. import org.bukkit.Material;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.block.BlockPlaceEvent;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15. import org.bukkit.plugin.Plugin;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17. import org.bukkit.potion.PotionEffect;
    18. import org.bukkit.potion.PotionEffectType;
    19.  
    20. public class Jm extends JavaPlugin implements Listener {
    21. private List<Location> mines = new ArrayList<Location>();
    22.  
    23. public void onEnable() {
    24. Bukkit.getServer().getPluginManager().registerEvents(this, (Plugin) this);
    25. }
    26.  
    27. public void onDisable() {
    28. }
    29.  
    30. public List<Location> getMines() {
    31. return mines;
    32. }
    33.  
    34. public void setMines(List<Location> mines) {
    35. this.mines = mines;
    36. }
    37.  
    38. @EventHandler
    39. public void onActivate(PlayerInteractEvent event) {
    40. if(event.getAction().equals(Action.PHYSICAL)) {
    41. if(event.getClickedBlock().getType().equals(Material.STONE_PLATE)) {
    42. if(mines.contains(event.getClickedBlock().getLocation())) {
    43. event.getClickedBlock().setType(Material.AIR);
    44. mines.remove(event.getClickedBlock().getLocation());
    45. event.getClickedBlock().getWorld().createExplosion(event.getClickedBlock().getLocation(), 0, false);
    46. event.getPlayer().setHealth(10.0);
    47. event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 1));
    48.  
    49. }
    50. }
    51. }
    52. }
    53. @EventHandler
    54. public void onPlace(BlockPlaceEvent event) {
    55. if(event.getBlock().getType().equals(Material.STONE_PLATE)) {
    56. mines.add(event.getBlock().getLocation());
    57. event.getPlayer().sendMessage(ChatColor.GOLD + "You created a " + ChatColor.DARK_RED + " land mine! Owwww Fancy!");
    58. }
    59.  
    60. }
    61. }
    62.  
    63.  
    64.  
    65.  
    66.  
     
  2. Offline

    Zarko

    Does the player still get the speed effect?
     
  3. Offline

    HeavyMine13

    Yes he does get it :)
     
  4. Offline

    Zarko

    Try to use player.damage(Double)
     
  5. Offline

    Assist

    HeavyMine13 Zarko
    Set the health to their current health - 10.0.
    Code:
    event.getPlayer().setHealth(event.getPlayer().getHealth() - 10.0);
    Alternatively, just make the explosion cause damage by increasing the power of it.

    Edit: Or use what Zarko said.
     
  6. Offline

    HeavyMine13

    When I hover over the second getHealth() it says: The method getHealth() is ambiguous for the type Player
     
  7. Offline

    Assist

  8. Offline

    HeavyMine13

    Ik the second one, but not the first thanks!

    I have both now, but it still shows the error :I

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

    Garris0n

    Use .damage()...
     
    HeavyMine13 likes this.
  10. Offline

    HeavyMine13

    Thanks, did not see it in JavaDoc!
     
  11. Offline

    Garris0n

    If you would've just searched "damage player bukkit" you would've gotten plenty of results.
     
Thread Status:
Not open for further replies.

Share This Page