Friends Plugin not working

Discussion in 'Plugin Development' started by Licio123, Sep 15, 2014.

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

    Licio123

    Guys the comand part and hand damage are done, but if a projectile hits your friend i get a fucking big stack trace

    Code:java
    1. @EventHandler (priority = EventPriority.MONITOR)
    2. public void friendsdamage(EntityDamageByEntityEvent e){
    3.  
    4. Entity damager = e.getDamager();
    5. Entity target = e.getEntity();
    6.  
    7. Player pldamager = (Player)e.getDamager();
    8. Player pltarget = (Player)e.getEntity();
    9.  
    10. List<String> targetfriends = WarZ.getPlugin().getConfig().getStringList(WarZ.pluginname + ".Friends." + pltarget.getUniqueId().toString() + ".friends");
    11. List<String> damagerfriends = WarZ.getPlugin().getConfig().getStringList(WarZ.pluginname + ".Friends." + pldamager.getUniqueId().toString() + ".friends");
    12.  
    13. if (damager instanceof Player && target instanceof Player){
    14.  
    15. if((damagerfriends.contains(pltarget.getName().toLowerCase())) && targetfriends.contains(pldamager.getName().toLowerCase())){
    16. e.setCancelled(true);
    17. pldamager.sendMessage("You cannot attack friends!");
    18. }
    19. }
    20.  
    21. if (damager instanceof Snowball && target instanceof Player){
    22.  
    23. Snowball snow = (Snowball)e.getDamager();
    24. Player shooter = (Player)snow.getShooter();
    25.  
    26. List<String> shooterfriends = WarZ.getPlugin().getConfig().getStringList(WarZ.pluginname + ".Friends." + shooter.getUniqueId().toString() + ".friends");
    27.  
    28. if((shooterfriends.contains(pltarget.getName().toLowerCase())) && targetfriends.contains(shooter.getName().toLowerCase())){
    29. e.setCancelled(true);
    30. pldamager.sendMessage("You cannot attack friends!");
    31. }
    32.  
    33. }
    34. }
     
  2. Offline

    Konato_K

    Your problem is on line 7, arrows are Projectiles, not players, you should first check if the damage is a player before casting it to it, now, about the Projectile issue, you check if the damager is a projectile, then cast it and get it's shooter.

    Never assume the damager is always a player, what if a zombie hits the friend?
     
  3. Offline

    mythbusterma

    Licio123

    And if you were to damage a mob, you would get a "big fucking stack trace." This is BCBlowz level code right here. I suggest you go learn Java before you try to do anything with Bukkit, and don't abuse event priority.
     
  4. Offline

    Skionz

  5. Offline

    Licio123

    thanks.. and I fineshed that at all thx everyone
     
  6. Offline

    mythbusterma

    Skionz

    He really is though. Also, we should probably not talk about this at risk of thread derailment.
     
Thread Status:
Not open for further replies.

Share This Page