A Few Bugs In My Plugin

Discussion in 'Plugin Development' started by CBUJoshua345, Nov 20, 2014.

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

    CBUJoshua345

    Hello! I have some errors i need to fix. First thing first, here is the link to my plugin. In Eclipse, you can open it.
    Download Link: https://dl-web.dropbox.com/get/MCJK...J_c5SmoJCwcTBuuA1TsVHQhyLN4cTtPeS2tLQKmA&dl=1
    How to see the code:
    Extract the files, and find the either
    Java Files:
    If they are .java files, you can just open them in Notepad, Notepad++, etc.
    Class Files:
    If they are .class files,
    you can download a .class to .java converter like this one:
    http://jd.benow.ca/
    And then see the code in the GUI Program.
    Here's the problemos. (problems xD)
    When someone is killed, the message turns up as:
    CraftPlayer{name=MCJoshua345} was killed by null (null is gold)

    When it's supposed to be:
    MCJoshua345 was killed by null (null is gold)
    Where it says null, I'm pretty sure it's supposed to be null, because I died of fall damage and potions.
    Also, where it's supposed to say "You were killed by {player name}" It doesn't show up at all, because there's some error. By the way, here's the log with that error.
    Log: http://pastebin.com/hn8eEpru
    Thanks for your help!
     
  2. Offline

    ColonelHedgehog

    Or you could post your code here...

    I guarantee you'll get 50% more help if you post code with something like hastebin or with the code tags here.
     
    TGRHavoc likes this.
  3. Offline

    TGRHavoc

    CBUJoshua345
    I haven't bothered to download your file (Just can't be bothered to be honest) however, I think I understand what your problem is..
    I think you're assuming some things in your "Death" class. One of these things you're assuming is that the player is being killed by another player. This is giving you an error when you die by _natural_ causes (such as fall damage) because fall damage isn't a player and, as a result, doesn't contain the information you're assuming it has.

    Like ColonelHedgehog said, posting your code on here (or github) will allow people to help you out much more efficiently.
     
  4. Offline

    xTrollxDudex

    You need to use Player#getName() instead of Object#toString() or implicit conversion.
     
  5. Offline

    MCJoshua345

    Finally just got it working, here's the code:
    http://pastebin.com/NShRBtem
    Thought I would paste the whole file.
    Please post the edited .java file on Pastebin, because since I'm a noob coder, and made the plugin from a tutorial, I don't understand xTrollxDudex's advice. Thank you for the advice anyways xTrollxDudex ;)

    Sorry 'bout that. CBJoshua345 is my other account.

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

    Skionz

    MCJoshua345 Ill explain what xTrollxDudex means. He said to use Player#getName() instead of Object#toString(). This is a way programmers represent classes and methods. The world before the '#' is a class such as Object, or Player, while the word after is a method in that class. Every class extends the Object class so you can use toString() with any class which turns the Object into a String. toString() will not return the players name, but the method "getName()" in the bukkit class "Player" will.
     
  7. Skionz
    You probably meant to say "word", not "world"? Would make a bit more sense that way :p
     
    Skionz likes this.
  8. Offline

    MCJoshua345

    Skionz I use p.getName(). I am like really dumb when It comes to coding. Can you please see my code on Pastebin: http://pastebin.com/NShRBtem And then post the edited code on Pastebin? I'm sorry I'm not very good at coding. It would help very much.
     
  9. Offline

    Skionz

    MCJoshua345 First off I am not going to rewrite your code for you as it won't help you at all. Second of all whats the issue?
     
  10. Offline

    MCJoshua345

    From the orig thread:
    Here's the problemos. (problems xD)
    When someone is killed, the message turns up as:
    CraftPlayer{name=MCJoshua345} was killed by null (null is gold)

    When it's supposed to be:
    MCJoshua345 was killed by null (null is gold)
    Where it says null, I'm pretty sure it's supposed to be null, because I died of fall damage and potions.
    Also, where it's supposed to say "You were killed by {player name}" It doesn't show up at all, because there's some error. By the way, here's the log with that error.
    Log: http://pastebin.com/hn8eEpru

    Code:

    1. @EventHandler
    2. public void Death(PlayerDeathEvent e) {
    3. Player p = e.getEntity();
    4. Player k = p.getKiller();
    5. e.getDrops().clear();
    6. e.setDeathMessage("" + ChatColor.RED + ChatColor.BOLD + p.getName() + " was killed by " + ChatColor.RESET + ChatColor.GOLD + k.getName());
    7. p.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "You were killed by " + k.getName());
    8. k.sendMessage("" + ChatColor.GREEN + "You killed " + p.getName());
    9. }
    It should be working!
     
  11. Offline

    Support

    Have you tried using Player p = (Player) e.getEntity()?
    Also, I'm pretty sure you could use e.getPlayer() instead of getEntity().
     
  12. Offline

    Skionz

    MCJoshua345 I thought you fixed the problem? It looks fine to me. Are you sure you exported correctly?
    Support PlayerDeathEvent#getEntity() returns a player as the event wouldn't be called if it was a normal LivingEntity dying.
     
  13. Offline

    MCJoshua345

    Take a look at this log. This is what happens when my death message is supposed to come into play. (At the almost very bottom.)

    Log: http://pastebin.com/a2dTYZYd

    Thanks for the help!

    The Gaming Grunts Nope, it's a class handler. All my imports get errors when I remove it.
    What the heck is CamelCase? If your trying to make my code look better, I really don't care. As long as it works. But yeah, If you were going to comment, then you could've helped me with my current problem. -_-

    New death code:
    Player p = e.getEntity();
    Player k = p.getKiller();
    e.getDrops().clear();
    e.setDeathMessage("" + ChatColor.RED + ChatColor.BOLD + e.getEntity() + " was killed by " + ChatColor.RESET + ChatColor.GOLD + p.getKiller());
    p.sendMessage("" + ChatColor.RED + ChatColor.BOLD + "You were killed by " + k.getName());
    k.sendMessage("" + ChatColor.GREEN + "You killed " + e.getEntity());

    <Edit by mrCookieSlime: Merged Posts. Please dont double post. There is an Edit-Button right next to the Date.>

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 27, 2017
  14. MCJoshua345
    Just wondering why you have this? It serves no use at all.

    Code:java
    1. public class PlayerFighters implements Listener
    2. {
    3. Main plugin;
    4. public PlayerFighters(Main instance)
    5.  
    6. {
    7.  
    8. this.plugin = instance;
    9.  
    10. }


    Also, your naming conventions are off. Methods should be written in lower CamelCase .
     
  15. Offline

    fireblast709

    MCJoshua345
    • Check if the killer isn't null.
    • Instead of concatenating the Player instance, use their name (invoke getName()).
     
  16. Offline

    Skionz

    MCJoshua345 Your casting PlayerDeathEvent to OfflinePlayer which throws an exception.
     
  17. Offline

    MCJoshua345

    fireblast709
    If killed by another player, It says:
    CraftPlayer{name=MCJoshua345} was killed by CraftPlayer{name=myllifesurfs}

    Skionz
    What does that mean & what should I replace, etc. ?

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

    Skionz

    MCJoshua345 It means that you are casting PlayerDeathEvent to OfflinePlayer which makes no sense. I suggest learning to read stack-traces. There is actually a sticky post in this forum that teaches you how.
     
  19. Offline

    MCJoshua345

    fireblast709
    I tried changing e.getEntity to ((OfflinePlayer) e).getPlayer(); but that just jacked up the whole system.
    Then I tried that invoke thing you were saying, and either I did it wrong or something, because it jacked up the whole system.

    Skionz
    Stack-Traces are really beyond my league. What does that mean, just like delete the EventHandler?!?! I just started coding like 1 week ago, so I really don't know what you're talking about. So If you could just tell me what to do, that would be very nice.

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

    Skionz

    MCJoshua345 Why would you cast it to OfflinePlayer? Stack-traces are in plain english. They give you each class and line where an issue is occurring and you look for your class. I suggest learning basic Java before jumping into a complex API that is written in Java.
     
  21. Offline

    Gater12

  22. Offline

    MCJoshua345

    How did I cast it to an OfflinePlayer? Do you mean I casted it to a dead player? In the tutorial video comments section there were people who had the same error as me, but how they fixed it doesn't even seem to match up with my code! Here's the video: www.youtube.com/watch?v=34rlkkW7EuQ . I know they're easily understandable (If you know how to fix the errors they're pointing to.) What I'm seeing in the stack-trace is SimplePluginManager, JavaPlugin, SimpleCommandMap, KillCommand, CraftServer, Dedicated Server, PacketPlayInChat, ServerConnection, etc. And of course a whole lot of my Spigot jar. I do know basic Java, just not in the Bukkit area.

    Gater12
    Already did.

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

    Gater12

    MCJoshua345
    I doubt it.

    I don't know how the discussion of casting an OfflinePlayer (Player extends OfflinePlayer) came up but this is the right answer:
     

  24. I just wanted to point that out for the future so you can improve ;) You don't need to attack me for doing so.
     
  25. Offline

    MCJoshua345

  26. Offline

    xTrollxDudex

    So you have solved this, no? Post your new code/problem please.
     
  27. Offline

    MCJoshua345

    xTrollxDudex Nope. Gater12 told me to invoke it, so I need to do that. Looking up how as we speak.

    NEVERMIND! Just fixed it by tweaking a bit of code and variables. Thanks for all your help guys! There is a few more bugs, but those are bugs that are within my knowledge. Thank you so much Skionz Sorry for being so dumb:p LOL sorry bout' that. <3

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

Share This Page