[Help] setCancelled(true); not working!

Discussion in 'Plugin Development' started by dadukeplus, Aug 26, 2014.

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

    dadukeplus

    Ok so I have this team wars game and I store if a member is in a team by using arraylist. I wanna make it so you can team kill so I added a EntitydamagebyEntity event. I check if there a player and if there on the same team if they are then u cancelled. For some reason its not cancelling it. I did some debug test and the debugs worked but setcancelled isnt. There is no error in console and im using 1.7.9.
     
  2. Offline

    SantaClawz69

    Post the code that isn't currently working so we have a better idea of what's going on.
     
  3. Offline

    mine-care

    SantaClawz69 is right also make sure you are not having any ifs in the way blocking it.
     
  4. Offline

    reider45

    Have you also tried .setDamage(0)
     
  5. Offline

    dadukeplus

    Code:java
    1. @EventHandler
    2. public void damage(EntityDamageByEntityEvent event)
    3. {
    4. if (event.getDamager() instanceof Player){
    5. Player damaged = (Player) event.getEntity();
    6. Player damager = (Player) event.getDamager();
    7. if(Core.getTeam(damaged) == Core.getTeam(damager))
    8. {
    9. event.setCancelled(true);
    10. }
    11. }
    12. }


    As you can see it checks if there a play and check if there on the same team. If true it cancels.
    I also have another plugin where setCancelled(true); worked but now both doesnt. Heres the code for that one:
    Code:java
    1. @EventHandler(priority = EventPriority.LOW)
    2. public void SpecDamage(EntityDamageByEntityEvent event)
    3. {
    4. if(event.getDamager() instanceof Player)
    5. {
    6. Player damager = (Player) event.getDamager();
    7. if(Core._spectators.contains(damager))
    8. {
    9. event.setCancelled(true);
    10. }
    11. }
    12. }
     
  6. Offline

    mythbusterma

    dadukeplus

    You're going to generate a ton of stack traces, you forgot to check if the damaged entity is a player, furthermore, you're using statics inappropriately.

    I'm going to take one guess at the return type of Core.getTeam(), it's a String isn't it?
     
    GrandmaJam likes this.
  7. Offline

    dadukeplus

    Yea it returns the arraylist of the team there on. I tried string already it didnt work too.
     
  8. Offline

    mythbusterma

    dadukeplus

    getTeam() returns an ArrayList? That doesn't make much sense.
     
  9. Offline

    TedTheTechie

    mythbusterma I've been working with duke on this issue. It doesn't return an arraylist, the Method checks if the player is in a specific arraylist, then returns "Blue" or "Red", or "None". That is not the cause of the issue though. He's just being stupid and saying the wrong things. The issue we're getting, is whenever we try cancelling entitydamagebyentityevent, It doesn't cancel. Nothing happens. At all. Goes through. Ignores the cancel.

    reider45, that just sets the damage to 0, not cancels the event.
     
  10. Offline

    Totom3

    TedTheTechie Well "Blue" is a String... Don't compare Strings using ==. Always always with .equals() or .equalsIgnoreCase()

    If that doesn't work then your getTeam() method is probably broken.

    Compilers don't ignore instructions (setCancelled(true)).
     
  11. Offline

    TedTheTechie

    Totom3, We're not talking about that, We're talking about the EntityDamageByEntityEvent going through when we cancelled the event. I really don't care about it at the moment, There was ANOTHER example too, we're talking about cancelling the event, not "fix my code", we already have the code updated in the project, just look at the 2nd example.
     
  12. Offline

    Necrodoom

    TedTheTechie debug it and see what parts fire in the event.
     
    XXLuigiMario likes this.
  13. Offline

    dadukeplus

    We have already debugged it everything fired except the cancel.
     
  14. Offline

    MineStein

    Priority?
     
  15. Offline

    Necrodoom

    Paste debugged code.
     
  16. Offline

    unon1100

    add this to your code:
    @EventHandler(priority = EventPriority.MONITOR)
    public void(EntityDamageByEntityEvent event){
    Bukkit.getLogger(Boolean.toString(event.isCancelled()));
    }
     
Thread Status:
Not open for further replies.

Share This Page