Send mgs to player after he die with his coordinates.

Discussion in 'Plugin Development' started by BioBG, Aug 11, 2013.

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

    BioBG

    Here is the idea, to send only for the player who Die his coordinates were he Die.

    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent event) {
    3. event.setDeathMessage(ChatColor.RED + " You Die in this Coordis" + event.getLocation());
    4. }


    but ... i get error "The method getLocation() is undefined for the type PlayerDeathEvent"

    How can i fix it ?
    tnx :)
     
  2. Offline

    xxMOxMOxx

    Try this
    Code:java
    1. event.setDeathMessage(ChatColor.RED + " You Die in this Coordis" + event.getEntity().getLocation());

    You can't get the location of the event but you can get the location of the player who just died. However, I'm not sure if this will get the location before or after death,
     
  3. Offline

    ZeusAllMighty11 Retired Staff

    PlayerDeathEvent doesn't have a getLocation() method. Player does, though.

    You can use event.getEntity().getLocation()

    Edit: Ninja'd :p
     
  4. Offline

    xxMOxMOxx

    Like a boss.
     
  5. Offline

    BioBG

    don't work ... don't send any massage. any suggestions ?
     
  6. Offline

    Shinxs

    try this
    isn't it event.getPlayer.getlocation()
     
  7. Offline

    Paper

    Code:
    Location loc = event.getEntity().getLocation;
    event.getEntity().sendMessage(ChatColor.RED + "You died at:" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ".";
    You can't literally send a location in a string parameter. (Well I think you could, but the output would be very weird). You need to separately grab each coordinate.


    EDIT:
    Shinxs Check the "Methods Summary" tab, it's getEntity() xD
    http://jd.bukkit.org/rb/apidocs/org/bukkit/event/entity/PlayerDeathEvent.html
     
  8. Offline

    ZeusAllMighty11 Retired Staff

    If it didn't send any message at all:

    - Does your class implement Listener?
    - Are you registering your events?
    - Do you have the @EventHandler annotation above the method?
     
  9. Offline

    xxMOxMOxx

    And just a heads up, you're currently changing the death message ("x Died because of y"), not sending the player a private message
     
  10. Offline

    Shinxs

    k i didn't looked at all i thought it was Player cuz its a player event
     
  11. Offline

    BioBG

    same think , dont work :)

    maby is my mistake, here is the all code, maby something i miss here.

    Code:java
    1. import java.util.logging.Logger;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Location;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.entity.PlayerDeathEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9.  
    10. public class info extends JavaPlugin {
    11.  
    12. public info plugin;
    13. protected static Logger log;
    14.  
    15. Commands cmd;
    16. public void onEnable() {
    17. info.log = this.getLogger();
    18. plugin = this;
    19. cmd = new Commands(this);
    20. log.info("Info plugin has been Enable! V0.1");
    21. }
    22.  
    23. @EventHandler
    24. public void onPlayerDeath(PlayerDeathEvent event) {
    25. Location loc = event.getEntity().getLocation();
    26. event.getEntity().sendMessage(ChatColor.RED + "You died at:" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ".");
    27. }
    28.  
    29. public void onDisable() {
    30.  
    31. log.info("Info plugin has been Disable!");
    32.  
    33. }
    34. }
    35.  
    36.  
     
  12. Offline

    Paper

    You never registered your listeners..

    Add the following code to your onEnable() method.
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);
     
  13. Offline

    Shinxs

    you need to add implements Listener and need to register the listener like Bukkit.getPluginManager.registerevents(this, this);
     
  14. Offline

    BioBG

    http://puu.sh/3Znn5.png
    The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (info, info)

    this happened.
     
  15. Offline

    Shinxs

    add implements Listener to public class info extends JavaPlugin so it would be:
    Code:
    public class info extends JavaPlugin implements Listener {
     
  16. Offline

    BioBG

    http://puu.sh/3ZnD2
    no still don't work
    i have no other plugins on this test server, its just Spigot only and this plugin.
     
  17. Offline

    xxMOxMOxx

    I don't think Spigot is supported here
     
  18. Offline

    Shinxs

    did it gave an error this time?
    you forgot to register thelistener
     
  19. Offline

    viper_monster

    If that event is in your main class, then try this:
    Code:java
    1. public void onEnable() {
    2. getServer().getPluginManager().registerEvents(this, this);
    3. }


    BioBG

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

    BioBG

    TNX guys :) it is working now :)
    thank you very much for your help! :)


    Solved

    Any suggestions to make this plugin beter/cool ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page