Stomper Code Help

Discussion in 'Plugin Development' started by mrgreen33gamer, Apr 16, 2014.

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

    mrgreen33gamer

    Hello, i have having some problems and i need some help!

    2 Things i need help on:

    1. I need help on he Shifting event which will be in the code below!
    2. I need help whenever a player is stomped, the stomper gets a kill, for instance, I stomp a player and it says something like this, WITHOUT SOME MESSAGE: "SoandSo was slain by SoandSo"

    Here is the code:

    Code:java
    1.  
    2.  
    3. @SuppressWarnings("deprecation")
    4. @EventHandler
    5. public void StomperKit(EntityDamageEvent event) {
    6. Entity ent = event.getEntity();
    7. if ((ent instanceof Player)) {
    8. Player player = (Player) ent;
    9. if (Main.stomper.contains(player.getName())) {
    10. if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
    11. if (event.getDamage() > 5)
    12. event.setCancelled(true);
    13. if (5 > 0) {
    14. player.damage(5);
    15. }
    16. {
    17. }
    18. for (Entity nearby : player.getNearbyEntities(4.0D, 4.0D,
    19. 4.0D)) {
    20. if (!(nearby instanceof Player))
    21. continue;
    22. Player targetplayer = (Player) nearby;
    23. if (!(targetplayer.isSneaking())) {
    24. int Damage = (int) (event.getDamage() - 2);
    25. targetplayer.damage(Damage);
    26. } else {
    27. targetplayer.damage(event.getDamage());
    28. }
    29. event.setCancelled(true);
    30. if (targetplayer.isDead()) {
    31. player.getServer().broadcastMessage(
    32. ChatColor.GREEN + player.getName() + ""
    33. + ChatColor.GOLD + " Stomped "
    34. + ChatColor.RED
    35. + targetplayer.getName() + "");
    36. }
    37. }
    38. }
    39. }
    40. }
    41. }
    42.  


    Public code for all!

    Any help?!
     
  2. Offline

    agent6262

    For future reference if you are posting Java code please switch the code type to Java and format it. It really helps everyone debug/ help you with your code. And when you have done that then i might be able to help.
     
  3. Offline

    mrgreen33gamer

    Happy?
     
  4. Offline

    DrEinsteinium

    It's still not formatted lol. Paste it into eclipse and press CTRL + SHIFT + F
     
  5. Offline

    mrgreen33gamer

    Yeah it doesn't want to set it that way, sooooo, yeah.
     
  6. Offline

    agent6262

    mrgreen33gamer
    Could you elaborate a little more on what you need help with and what exactly do you need help with on the event
     
  7. Offline

    mrgreen33gamer

  8. Offline

    agent6262

    Change == to .equals(). == only compares object refrences
     
  9. Offline

    mrgreen33gamer

  10. Nope.

    mrgreen33gamer As said, you're not being very clear. I don't understand what your code currently does, and what you want it to do differently.
     
  11. Offline

    mrgreen33gamer


    Well, specifically. I am trying to make it were whenever I stomp and player, it counts as a kill. For instance, if i was to kill someone it says player was slain by player. Well i am trying to make it were it displays that message when you kill someone.

    Another thing I am trying to do is make it were when the targeted player is shifting, then they only take a certain amount of damage.

    Sorry, i was really lazy that day and I wasn't thinking very straight.
     
  12. Offline

    agent6262

    If you are trying to change the "death" message then wouldn't you want to use a EntityDeathEvent?

    Just Formatted Code. (Sorry just a little OCD)
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void StomperKit(EntityDamageEvent event) {
    4. Entity ent = event.getEntity();
    5. if ((ent instanceof Player)) {
    6. Player player = (Player) ent;
    7. if (Main.stomper.contains(player.getName())) {
    8. if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
    9. if (event.getDamage() > 5) {
    10. event.setCancelled(true);
    11. }
    12. if (5 > 0) {
    13. player.damage(5);
    14. }
    15. for (Entity nearby : player.getNearbyEntities(4.0D, 4.0D, 4.0D)) {
    16. if (!(nearby instanceof Player))
    17. continue;
    18. Player targetplayer = (Player) nearby;
    19. if (!(targetplayer.isSneaking())) {
    20. int Damage = (int) (event.getDamage() - 2);
    21. targetplayer.damage(Damage);
    22. } else {
    23. targetplayer.damage(event.getDamage());
    24. }
    25. event.setCancelled(true);
    26. if (targetplayer.isDead()) {
    27. player.getServer().broadcastMessage(
    28. ChatColor.GREEN + player.getName() + ""
    29. + ChatColor.GOLD + " Stomped "
    30. + ChatColor.RED
    31. + targetplayer.getName() + "");
    32. }
    33. }
    34. }
    35. }
    36. }
    37. }
     
  13. Offline

    mrgreen33gamer


    Nice code, but when i stomp and player that is shifting they are stomped... Any help with that?
     
  14. Offline

    Bobit

    Formatting code is a lot easier if you paste it into pastebin, then press submit, then copy and paste into bukkit.
    Or you could set up github, but that's a lot more work to get started on.
     
  15. lol
    Code:java
    1. if (5 > 0) {
    2. player.damage(5);
    3. }
     
  16. Offline

    mrgreen33gamer

    Not related to the topic....

    Still not related to the topic.

    Come on guys, i really need help on this, my server really needs it :(
     
  17. Offline

    agent6262

    Does this help?
    Code:java
    1. @EventHandler
    2. public void stomperKit(EntityDamageEvent evt){
    3. if(evt.getEntity() instanceof Player){
    4. Player player = (Player)evt.getEntity();
    5. if(evt.getCause().equals(EntityDamageEvent.DamageCause.FALL)){
    6. if(Main.stomper.contians(player.getName())){
    7. for (Entity nearby : player.getNearbyEntities(4.0D, 4.0D, 4.0D)){
    8. if (!(nearby instanceof Player)){
    9. continue;
    10. }
    11. Player targetplayer = (Player) nearby;
    12. if (!(targetplayer.isSneaking())) {
    13. targetplayer.damage(evt.getDamage() - 2);
    14. } else {
    15. targetplayer.damage(evt.getDamage());
    16. }
    17. evt.setCancelled(true);
    18. if (targetplayer.isDead()) {
    19. player.getServer().broadcastMessage(
    20. ChatColor.GREEN + player.getName() + ""
    21. + ChatColor.GOLD + " Stomped "
    22. + ChatColor.RED
    23. + targetplayer.getName() + "");
    24. }
    25. }
    26. }
    27. }
    28. }
    29. }
     
Thread Status:
Not open for further replies.

Share This Page