Auto-Permission when getting 20 kills

Discussion in 'Spigot Plugin Development' started by iChris, Jun 13, 2016.

  1. Hey, so I got this plugin when you click on a compass it opens 2 options ( kits) and when i press it, it gives me the kit, so i want one of them to be able to choose only if you 20 player kills, how can i do it?

    i made this plugin myself
     
    #1 iChris, Jun 13, 2016
    Last edited: Jun 13, 2016
  2. Did you get this plugin made privately by a dev or did you download it from somewhere or what?
    That would need to be implemented as a feature for the kit plugin.
     
  3. I made it my self.
     
  4. Ah okay. I wasn't sure from your post.

    To do this you will need to keep track of a player's kill count - you would probably want to do so with a FileConfiguration by setting the player's UUID to an integer (the amount of kills) and update it when they get a kill. Then, when they click in the inventory check the configuration for how many kills they have.

    If that made no sense to you, check this out: https://www.spigotmc.org/wiki/creating-a-config-file/
     
  5. Yep, I know how to make a config file but the problem is that I don't really know how to track the player's kill count - its java code, and that's why i am struggling :p
     
  6. Well, you have to use EntityDeathEvent, check if it's a player, then Entity#getLastDamageCause and check if it's an EntityDamageByEntityEvent and then check if the damager was a player and if it was give credit to that player for a kill. I know, it's annoyingly complicated. :l
     
  7. that's what i've come to so far
    @EventHandler
    public void onEntity(EntityDeathEvent event){
    Entity en = event.getEntity();
    if(en instanceof Player){
    en.getLastDamageCause().getEntity()


    I am pretty much a beginner so it's the most complicated plugin i had :p
     
  8. No point in doing en.getLastDamageCause().getEntity(), you already have the entity.
    You need to next check if en.getLastDamageCause() is an instance of EntityDamageByEntityEvent, then cast it to EntityDamageByEntityEvent and .getDamager(), and then check if that's a player, then add to their kill count.
     
  9. I honestly can't match anything with EntityDamageByEntityEvent, I am trying to do "if(en.getLastDamageCause() and from there I don't know what to type :/
     
  10. I'm trying to give you enough to figure it out without just dumping free code on you xD

    if (en.getLastDamageCause() instanceof EntityD...)
     
  11. Yeah ofcourse xD
    I am here to learn...
    Well, I tried it aswell before but I guess I wrote something else.. So we have passed this step and I'm still stuck haha..
    I have tried
    "EntityDamageByEntityEvent.getDamager"
    But i guess its not that and I tried en.getLastDamageCause.getDamager
    But itll show only .getDamage so its not that aswell


    I've never tried to do a plugin complicated like that so I guess its the first time to learn lol :p
     
  12. Do you know how object casting works?
    Like in a command you check if it's a player and then do Player player = (Player) sender;
    That's casting a 'CommandSender' to a 'Player' because even though you have a CommandSender you know it's actually a Player

    Well you need to do that with en.getLastDamageCause() so you have a EntityDamageByEntityEvent
     
  13. I just saw a tutorial based on it... And I understand it all finaly :/

    My main problem now is just letting only players with X kills to choose this kit
     
  14. on kill:
    Code (Text):
    config.set(player.getUniqueId().toString(), config.getInt(player.getUniqueId().toString(), 0) + 1);
    when clicking in the gui:
    Code (Text):
    if (config.getInt(player.getUniqueId().toString(), 0) >= 20) {
    ....
    }
    You said you already know config stuff and this is fairly simple so just giving you an example this time ;P
    btw in the config.get() methods the reason I put two arguments is because the second one is like a fallback for if it cant find it in the config.

    Oh and dont forget to save the config onDisable
     
  15. Thank you!! :)
     

  16. @EventHandler
    public void onInventoryClick(InventoryClickEvent event){
    if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Kit Selector"))
    return;
    Player player = (Player) event.getWhoClicked();
    event.setCancelled(true);

    if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR||!event.getCurrentItem().hasItemMeta()){
    player.closeInventory();
    return;

    }

    switch (event.getCurrentItem().getType()) {
    case IRON_SWORD:
    player.getInventory().addItem(new ItemStack(Material.BOW));
    player.closeInventory();
    player.sendMessage(ChatColor.YELLOW + "You have chosen the Knight kit!");
    break;

    I can't really understand where to put this...