Death By Void and Kill Streaks Help!

Discussion in 'Plugin Development' started by Chibbey, Nov 10, 2013.

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

    Chibbey

    Hello, I am making a FishSlap plugin and I need help! Ok so when I need it so when a player dies from the void it broadcasts saying "(Person who killed the player) has just killed (Person who died) with a fish!" I know how to do the message Its just it only says it when a person dies from PvP and not the void, So I need the PlayerDeathEvent to know who hit the player last kill the player with the void, So for example someone is by the edge, I hit him off, He dies from the void, It will says "Chibbey has just killed someone with a fish!". So please help. And the Killstreaks I want it to save when someone gets a kill, Im guessing that the PlayerDeathEvent and it just gets the killer and does something with him, But I want it to know and when they die there streak goes away, So I can have it so that have KnockBack I on there fish and they kill 2 people and then it clears there Inventory and gives them a KnockBack II Fish or a potion effect. Please help me.
     
  2. Offline

    TeeePeee

    Remember the use of PlayerDeathEvent.getCause(). You can check to see if the death cause was void and the killer (should) still be the last player to hit them.

    As for killstreaks, just increment the count of the killer until they die, then 0 their kills. After you increment the kills, you can compare how many kills they have and do inventory magic.
     
  3. Offline

    Chibbey

    Ok ty for the Void part but I don't get the increment the count and stuff, Sorry im not that good at coding yet XD

    Actually I Don't know the void either, I tried e.getCause() and it wasn't there, I have it so it is like this
    public void onPlayerDeath(PlayerDeathEvent e) {

    }
    and when I try to do e.getCause() it doesn't work

    Someone help please!

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

    thepaperboy99

  5. Offline

    Chibbey

    I didn't really get it, Could someone post some code or something please?
     
  6. Offline

    xTrollxDudex

    Chibbey
    Spoon feeding isn't threat way for you to learn. thepaperboy99 's post is constructive, I suggest you use it.
     
  7. Offline

    Chibbey

    Ok, But I did I copied the post he gave me a link to and I tried to die from the void my friend hit me off and when I died it didn't say he killed me, and I still need a way for killstreaks
     
  8. Offline

    thepaperboy99


    Storing a player's kill streaks can easily be done with a hashmap.
     
  9. Offline

    Chibbey

  10. Offline

    thepaperboy99

    It's not hard at all, make a hashmap of a string and an integer.

    Example:

    map.put(player.getName(),1);

    That is one point, then to get the score, map.get(player.getName);

    And a side note, try to learn some more java if you are trying to do a minigame plugin.
     
  11. Offline

    Chibbey

    thepaperboy99
    Im not really sure about hashmaps so im thinking of just using arraylists and if there in arraylist kill1 and they get a kill they get put in kill2 and so on. And when there in certain ones they get certain things.
     
  12. Offline

    thepaperboy99

    The ArrayList would be a wast of time. If you did do that, you would need to go through every hashmap and check what one he's in. If you just use a hashmap, you can just do what I said above, then map.put(player.getName(),map.get(player.getName() + 1);
     
  13. Offline

    Chibbey

    thepaperboy99
    Thanks for helping me but I don't really get what you are saying, i'm literally really bad with hashmaps. So if you would like could you post some code showing me, also I tried the thing for death by void and it does work heres my code



    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent e) {
    3. e.getDrops().clear();
    4. Player player = e.getEntity();
    5. EntityDamageEvent ede = player.getLastDamageCause();
    6. DamageCause dc = ede.getCause();
    7. if (player instanceof Player && dc == DamageCause.VOID) {
    8. e.setDeathMessage(ChatColor.DARK_RED + player.getKiller().getName() + " has just killed " + player.getName() + " with a fish!");
     
  14. Offline

    thepaperboy99

    Il give you one last, clear example on how you can do your killstreaks.

    You need to create a new HashMap which should be <String,Integer>. So it will be HashMap<String,Integer> map = new HashMap<String,Integer>();

    At the start of the game, put very one into the hashmap like so:

    for(Player p : Bukkit.getOnlinePlayers()){ // You obviously need to change this

    map.put(p.getName(),0); // This will add the player to the map, and set his "score" to 0. And the "score" is the integer part of the hashmap.

    To add a "point" to the player:

    map.put(p.getName(),map.get(p.getName() + 1); // This will add 1 to the players "points"

    To get a players "points"

    map.get(p.getName); // This will return the number that the player has been set to. So this will be the method that you use to check a players points.

    Then when the player dies, you will want to set back him to 0 again with map.put(p.getName(),0);

    Then when te game is over, you can just remove eveyone in te game with map.remove(p.getName());
     
  15. Offline

    Chibbey

    thepaperboy99
    Ok I sorta think I know what your saying, but the minigame isn't like a whole bunch of games that people join and after a certain amount of people join it starts, I'm having it so it's one big game, so they just join the server and get the fish, and they play, but yea, so heres what I think your saying

    HashMap<String,Integer> map = new Hashmap<String,Integer>();

    Player p = Bukkit.getOnlinePlayer();
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
    Player p = Bukkit.getOnlinePlayers();
    map.put(p.getName(),0);
    }
    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent evt) {
    Player pl = Bukkit.getOnlinePlayers();
    map.put(pl.getKiller().getName(),map.get(p.l.getKiller().getName() + 1);

    }

    And this will add points and stuff?

    and to check I don't really know how

    thepaperboy99
    Ok so I got the thing where it add points and puts them into the HashMap, I just need help with checking so im guessing checking goes in PlayerDeathEvent like this

    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
    Player p = event.getEntity();
    map.get(p.getKiller().getName())
    }

    How do I check if he has 1 or 2 or 3 kills? please help :)

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

    NinjaWAffles

    If you have a hashmap setup like thepaperboy99 mentioned, the method 'Hashmap.get(String)' will return an integer. You would then use this integer to determine how many kills that player has; and then to add to it, just take that integer, increment it by one, and put it back into the hashmap.

    I'm not trying to come across as rude, but you really don't seem like you know Java or the Bukkit API much at all. I'd suggest you learn Java and then the Bukkit API before diving into something like this.
     
  17. Offline

    Chibbey

    NinjaWAffles
    I can say i dont know much. But could you please show me, so i have it so the killer gets a point i just need to know how it checks if a player has a certain amount of points and if they do it does something would it be something like this if (map.put(player.getKiller() == 1) { does something

    Im not sure so can u help
     
  18. Offline

    NinjaWAffles

    Again, I can't help but want to help, but please read some Java and Bukkit tutorials before posting another thread, please. On to your topic, something like this would check if the player has 2 or more kills:
    Code:Java
    1. if(map.get(player.getKiller().getName()) >= 2)
    2. {
    3. //Do something
    4. }
     
  19. Offline

    Chibbey

    NinjaWAffles
    Lol you sound like your begging for your life but instead wanting me to watch some tutorials, lol, but anyways you say you cant help but you want to all i needed to know was that that you just told me... Thanks so much!

    NinjaWAffles
    Ok so that is using the HashMap named map and when a player dies it will get the killers integer which is the score, and it will see if they have 2 kills or whatever you want... And if they do it will do something, thats how i am understanding it.

    Ok so I have the hashmap and everything and its not working ill show you my code...


    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent evt) {
    3. evt.getDrops().clear();
    4. Player player = evt.getEntity();
    5. EntityDamageEvent ede = player.getLastDamageCause();
    6. DamageCause dc = ede.getCause();
    7. if (player instanceof Player && dc == DamageCause.VOID) {
    8. evt.setDeathMessage(ChatColor.DARK_RED + player.getName() + "has just died because someone through him into the void with a fish!");
    9. }
    10. map.put(player.getName(),0);
    11. map.put(player.getKiller().getName(),map.get(player.getKiller().getName()) + 1);
    12. if (map.get(player.getKiller().getName()) == 2) {
    13. ItemStack fish = new ItemStack(Material.RAW_FISH);
    14. fish.addEnchantment(Enchantment.KNOCKBACK, 3);
    15. ItemMeta fishmeta = fish.getItemMeta();
    16. fishmeta.setDisplayName(ChatColor.RED + "FishSlapper 3000");
    17. List<String> fishlore = new ArrayList<String>();
    18. fishlore.add(ChatColor.GOLD + "FishSlapper 3000? OMG!");
    19. fishlore.add(ChatColor.GOLD + "Lets see if theres a 4000!");
    20. fishmeta.setLore(fishlore);
    21. fish.setItemMeta(fishmeta);
    22. player.getInventory().addItem(fish);
    23. player.sendMessage(ChatColor.GOLD + "[FishSlap]" + ChatColor.GREEN + "You are on a 2 killstreak! You got a new fish!");
    24. Bukkit.getServer().broadcastMessage(ChatColor.GOLD + "[FishSlap]" + ChatColor.GREEN + player.getKiller().getName() + " is on a 2 killstreak!");
    25.  
    26. }
    27. if (map.get(player.getKiller().getName()) == 4) {
    28. ItemStack fish = new ItemStack(Material.RAW_FISH);
    29. fish.addEnchantment(Enchantment.KNOCKBACK, 4);
    30. ItemMeta fishmeta = fish.getItemMeta();
    31. fishmeta.setDisplayName(ChatColor.RED + "FishSlapper 4000");
    32. List<String> fishlore = new ArrayList<String>();
    33. fishlore.add(ChatColor.GOLD + "FishSlapper 4000? OMG!");
    34. fishlore.add(ChatColor.GOLD + "I knew there was one!");
    35. fishmeta.setLore(fishlore);
    36. fish.setItemMeta(fishmeta);
    37. player.getInventory().addItem(fish);
    38. player.sendMessage(ChatColor.GOLD + "[FishSlap]" + ChatColor.GREEN + "You are on a 4 killstreak! You got a new fish!");
    39. Bukkit.getServer().broadcastMessage(ChatColor.GOLD + "[FishSlap]" + ChatColor.GREEN + player.getKiller().getName() + " is on a 4 killstreak!");
    40.  
    41. }

    And they get added to Map when they join ill show you...
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent evt) {
    3. Player p = evt.getPlayer();
    4. p.sendMessage(ChatColor.GOLD + "[FishSlap]" + ChatColor.DARK_RED + "Giving Fish for FishSlap [Coded by Chibbey]");
    5. p.getInventory().clear();
    6. ItemStack fish = new ItemStack(Material.RAW_FISH);
    7. ItemMeta fishmeta = fish.getItemMeta();
    8. fishmeta.setDisplayName(ChatColor.RED + "FishSlapper 2000");
    9. List<String> fishlore = new ArrayList<String>();
    10. fishlore.add(ChatColor.GOLD + "Lets start Slappin!");
    11. fishmeta.setLore(fishlore);
    12. fish.setItemMeta(fishmeta);
    13. fish.addUnsafeEnchantment(Enchantment.KNOCKBACK, 2);
    14. p.getInventory().addItem(fish);
    15. p.sendMessage(ChatColor.GOLD + "[FishSlap]" + ChatColor.GREEN + "Welcome, You got a fish for FishSlap!");
    16. map.put(p.getName(),0);


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

    NinjaWAffles

    I didn't read all of your code. I got to this part:
    Code:Java
    1. map.put(player.getName(),0);
    2. map.put(player.getKiller().getName(),map.get(player.getKiller().getName()) + 1);

    Whenever you do this, you're putting the users score to 0, then adding 1 from 0. This is the reason the rest of your code isn't running. Let me put it this way.
    • Player gets killed
    • Damager gets score set to 0
    • Damager's score gets incremented by 1
    ...then...
    • Player gets killed again
    • Damager gets score set to 0
    • Damager's score gets incremented by 1
    Do you see where this is wrong?
     
  21. Offline

    Chibbey

    NinjaWAffles
    No not really I thought it is putting the Player that died the player.getName() is the player that died and its setting his score to 0 and then it is getting the players killer and get his score and adding 1 to his score? its not doing that, could you please help me then.
     
  22. Offline

    NinjaWAffles

    Oh, sorry, I must have mis-read that. You are right. So, what is the error you're getting?
     
  23. Offline

    Chibbey

    NinjaWAffles
    its not saying anything in console its just not giving them there item and sending a message to them like I have it to do
     
  24. Offline

    NinjaWAffles

    It looks like on this line...
    Code:Java
    1. player.getInventory().addItem(fish);

    ...you're attempting to give the reward to the player who died because the player variable is defined to be the player who died earlier in your code. Try changing it to:
    Code:Java
    1. Bukkit.getPlayer(player.getKiller().getName()).getInventory().addItem(fish);
     
  25. Offline

    Chibbey

    NinjaWAffles
    Ok it was saying something in console, I figured it out though! It sends them a message now its not clearing there inventory and adding the new fish though :( ill post what its saying in the console also I just added clear inventory so yea!

    Console log:
    11.11 16:57:39 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:57:14 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:56:49 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:56:24 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:55:59 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:55:34 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:55:12 [Server] INFO Chibbey was slain by FeaRDaMiNeZ
    11.11 16:55:12 [Server] INFO [FishSlap]FeaRDaMiNeZ is on a 4 killstreak!
    11.11 16:55:10 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:54:59 [Server] INFO Chibbey was slain by FeaRDaMiNeZ
    11.11 16:54:45 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:54:20 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:53:55 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:53:40 [Server] INFO Chibbey was slain by FeaRDaMiNeZ
    11.11 16:53:40 [Server] INFO [FishSlap]FeaRDaMiNeZ is on a 2 killstreak!
    11.11 16:53:30 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:53:27 [Server] INFO Chibbey was slain by FeaRDaMiNeZ
    11.11 16:53:05 [Server] INFO Admins: [Admin]FeaRDaMiNeZ, [Owner]Chibbey
    11.11 16:52:49 [Server] INFO §4Chibbey has just died because someone through him into the void with a fish!
    11.11 16:52:49 [Server] INFO ... 26 more
    11.11 16:52:49 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    11.11 16:52:49 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:601)
    11.11 16:52:49 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    11.11 16:52:49 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    11.11 16:52:49 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    11.11 16:52:49 [Server] INFO at me.chibbey.fishslap.JoinEvent.onPlayerDeath(JoinEvent.java:61)
    11.11 16:52:49 [Server] INFO Caused by: java.lang.NullPointerException
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:30)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:116)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.Packet10Flying.handle(SourceFile:136)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:343)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.EntityPlayer.h(EntityPlayer.java:228)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.EntityHuman.l_(EntityHuman.java:157)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.EntityLiving.l_(EntityLiving.java:1243)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.Entity.l_(Entity.java:230)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.EntityLiving.y(EntityLiving.java:145)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.Entity.y(Entity.java:323)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.EntityLiving.C(EntityLiving.java:981)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.EntityPlayer.damageEntity(EntityPlayer.java:383)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.EntityHuman.damageEntity(EntityHuman.java:714)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.EntityLiving.damageEntity(EntityLiving.java:710)
    11.11 16:52:49 [Server] INFO at net.minecraft.server.v1_6_R3.EntityPlayer.die(EntityPlayer.java:312)
    11.11 16:52:49 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:344)
    11.11 16:52:49 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    11.11 16:52:49 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    11.11 16:52:49 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    11.11 16:52:49 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    11.11 16:52:49 [Server] INFO org.bukkit.event.EventException
    11.11 16:52:49 [Server] SEVERE Could not pass event PlayerDeathEvent to FishSlap v1.0
     
  26. Offline

    NinjaWAffles

    What is line 61 of JoinEvent.java? It's highlighted above.
     
  27. Offline

    Chibbey

    NinjaWAffles

    I see it now, I haven't tested it but I just changed code and 100% it will work, ty so much, and also you don't gotta do player.getKiller().<getName()>.getInventory you just gotta do player.getKiller().getInventory().addItem(fish) anyways though ty so much, and now I learned so much more about HashMaps also! ty! and it didn't clear inventory because I needed to do player.getKiller().getInventory().clear(); but ty sooooo much, Ill msg you again if I have a problem!

    NinjaWAffles

    it was where it increments the score. But I figured it out. So no worrys :)

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

    NinjaWAffles

    You're welcome. Also, to make things easier you could always just make a variable for the killer, such as:
    Code:Java
    1. Player killer = player.getKiller();

    This way accessing the killer's methods wouldn't be so much code. Anyway, if you need any more help, you can always shoot me a PM. Also, if we're done with this thread, please mark it as solved. Thanks. :)
     
  29. Offline

    Chibbey

    NinjaWAffles
    Ok and ill do that next time for the killer :) ill follow you so I don't forget you! and if you want to join my server come its not that good right now but heres the IP: 192.95.17.195:25565

    Hey, so its all working besides when a player dies from the void, So its all setup its just not giving a player a point it will say the message just not give the killer a point, im guessing it thinks the killer is the void or something so could you help me please :)


    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent evt) {
    3. evt.getDrops().clear();
    4. Player player = evt.getEntity();
    5. EntityDamageEvent ede = player.getLastDamageCause();
    6. DamageCause dc = ede.getCause();
    7. if (player instanceof Player && dc == DamageCause.VOID) {
    8. evt.setDeathMessage(ChatColor.DARK_RED + player.getName() + " has just died because someone through him into the void with a fish!");
    9. map.put(player.getKiller().getName(),map.get(player.getKiller().getName()) + 1);


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

Share This Page