Disable pvp from arrow doesnt work

Discussion in 'Plugin Development' started by Doknesss, Aug 13, 2019.

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


    Hi, i need to make plugin which will block damage from arrows when damager and victim are in the same team -> in this case != yt

    but when im put plugin on server im getting just "-1" message on chat and default pvp is blocked properly but i want also to block damage from arrows and i wrote code like this

    public void pvp(EntityDamageByEntityEvent e) {
    Player ofiara = (Player) e.getEntity();
    Player napast = (Player) e.getDamager();

    if(!yt.contains(ofiara) && widzowie.contains(napast)) {
    napast.sendMessage(ChatColor.RED + "To twój sojusznik!");

    if(yt.contains(ofiara) && yt.contains(napast)) {

    Arrow arrow = (Arrow)e.getDamager();
    if (arrow.getShooter() instanceof Player && (e.getEntity() instanceof Player))
    Player ataker = napast;
    Player beinataked = ofiara;
    if (!yt.contains(ataker))
    ataker.sendMessage(ChatColor.RED + "Nie mozesz atakowac swoich sojusznikow!");
    } else {

    any suggestions what i could do wrong?
  2. Offline


    1. You are casting without checking.
    ofiara = e.getEntity() -> Player
    napast = e.getDamager() -> Player
    arrow = e.getDamager() -> Arrow
    2. I'm guessing 'yt' is a list, but what does it contain?
    3. You should check if the victim is a player, then check if the damager is a player, if not, check if it's an arrow, and then get the shooter from the arrow.
    DerDonut likes this.
  3. Offline


    ArrayList<Player> yt = new ArrayList<Player>();


    i did something like this

    if(ofiara instanceof Player && napast instanceof Arrow) {

    but this still not works
  4. Offline


    You are handling both, the 'default' pvp and the arrow in this listener right?
    So as @KarimAKL said, at the beginning, check if the victim is a player, then check if the damager is a player (using instanceof) or if he's an arrow, in the last case get the shooter of the arrow with arrow.getShooter(). Now you have 2 player objects and you can test if they are in the same team or not (and then cancel the event)

    EDIT: and please use the function insert > code for posting code
  5. Offline


    That doesn't help me; i was asking what it contains. Which players do you add to the list?
  6. Offline


  7. Offline


    @Doknesss please rewrite the whole listener with our advises and post it again. You should also get lots of errors because of wrong casting so maybe show us the console log too
  8. Offline


    Could not pass event EntityDamageByEntityEvent to VS100widzow v1.0
  9. Offline


    Of course you get an error in the EntitydamageByentityEvent xd
    If you want us to help you we need the whole stacktrace but since you didn't change anything we already told you about the things you have to do,
    so please...
    If you want us to explain something more detailed say so
  10. Offline


    i dont know how to "rewrite the whole listener" because i cant understand your advises ;-;
    cant you just write what should i change by write example?
    You know what i want to do because i wrote about this
    this would be more helpful for me
  11. Offline


    So what, you expect the Bukkit forum users to write the plugin for you? lol It's not that complex. Basically:

    Event {
        Is the entity not a player?  Return if so
        Is the damager not an arrow or player?  Return if so
        Is the damager an arrow & arrow's shooter not a player?  Return if so
        Create a var for the victim
        Create a var for the aggressor
        Is the damager a player and aggressor's held item not crossbow?  Return if so
        Loop the board's team list {
            Does entries list contain both victim and aggressor name? Cancel & return if so
    That worked for me.

    EDIT: Updated to account for crossbows. Apparently when you left click a player with a loaded crossbow, it registers a regular melee attack not an arrow attack. Interesting.
    Last edited: Aug 24, 2019
Thread Status:
Not open for further replies.

Share This Page