help with team damage/damage

Discussion in 'Plugin Development' started by Swiftlicious, Aug 19, 2019.

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

    Swiftlicious

    I need help i've been at this for about a day now and I can't figure out why these two aren't working:

    1. I have a method to disable fishing rod damage for teammates (i have no other plugins that would mess with this)
    Code:
      if (e.getDamager() instanceof FishHook) {
                        FishHook a = (FishHook) e.getDamager();
                        if (a.getServer() instanceof Player) {
                        Player d = (Player) a.getServer();
                        String TeamD = Methods.getExactTeam(d);
                        String TeamP = Methods.getExactTeam(p);
                        if (TeamD.equalsIgnoreCase(TeamP)) {
                            e.setCancelled(true);
                            d.sendMessage(Chat.color(prefix + " " + friendly_fire));
                            return;
                        } else {
                            e.setCancelled(false);
                        }
                    }
                }
    I have also tried changing getServer to be getShooter but to no luck did that work.

    2. I also am having similar problems doing this same factor to tnt:
    Code:
             if (e.getDamager() instanceof TNTPrimed) {
                        TNTPrimed a = (TNTPrimed) e.getDamager();
                        if (a.getSource() instanceof Player) {
                        Player d = (Player) a.getSource();
                        String TeamD = Methods.getExactTeam(d);
                        String TeamP = Methods.getExactTeam(p);
                        if (TeamD.equalsIgnoreCase(TeamP)) {
                            if (p != d) {
                                e.setCancelled(true);
                                return;
                            }
                        } else {
                            e.setCancelled(false);
                        }
                    }
                }
    3. I am really having a problem coming up with a decent method to use BlockPlaceEvent to make it so you can't light your teammates on fire by using flint and steel or fire charges underneath them but I couldn't successfully come up with how to do that, any help as usual would be make me greatful!
     
  2. Offline

    KarimAKL

    @Swiftlicious
    1. Don't use 'getServer', use 'getShooter'.
    2. Have you tried debugging? The if statement might return false.
     
  3. Offline

    robertlit

    First problem: I am not experienced with this stuff, but, I am sure that getServer() cannot be instance of Player. As said above you may use getShooter(), I am not sure though because again, I never did this kind of stuff. Also you did not define p, you have only defined d.

    Second problem: You did not define p, you have only defined d.

    Third problem: Don't think it is possible try looking it up.

    @Swiftlicious
     
  4. Offline

    KarimAKL

    @robertlit
    1. 'p' is probably outside of the method.
    2. It's possible.
     
  5. Offline

    Swiftlicious

    I have stated like right below the code that I had used getShooter method and it did not work but anyways I solved it by using a different event that was not DamageEntitybyEntityEvent..
    it actually had to be PlayerFishEvent and it did up working.
    and yes p was defined as player event.getEntity() outside of this method I didn't think it would be needed because if I had not defined it then the problem would have been easy for me to see since it would underline it in red.
     
Thread Status:
Not open for further replies.

Share This Page