Solved Best Way to Go About Cancelling Fireball Deflection?

Discussion in 'Plugin Development' started by AppleBabies, Dec 27, 2015.

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

    AppleBabies

    Hello all. Recently I've been working on a stick that shoots a fireball for a minigame type thing. (Whoo, I know) The only problem is, players can just knock back the fireball no problem. It takes FOREVER to complete one game.

    I've tried EntityDamageEntityEvent, getting if the attacker is a Player and the entity a Fireball. Doesn't work. Although I am wondering if Fireball should be Fireball.class.

    I also don't want to use small fireballs, as they are way too fast in this case.

    So, how can I go about cancelling fireball deflection? Thank you!
     
  2. Offline

    Xerox262

    Have you tried debugging? Something like making a EntityDamageByEntityEvent that just debugs to see if it is called at all? Then try debugging after your if and you'll be able to tell what the problem is.

    Edit: Always post code when applicable.
     
  3. Offline

    AppleBabies

    @Xerox262 I know the event is called, because I have the event also detect players. Here's my code:
    Code:
    if(e.getDamager() instanceof Player) {
                if(e.getEntityType().equals(Fireball.class)){
                    return;
                }
            }
     
  4. Offline

    Xerox262

    If that is called then what is the problem? Also an entity type cannot equal a class.
    It'd be EntityType.FIREBALL, since they're enums you can compare with ==
     
  5. Offline

    AppleBabies

    @Xerox262 My problem is it still is not working. I thought the problem was because I had set up a fireball called fb in another class, but I can still knock back regular ghast fireballs as well. I also made your changes. Nothing.
     
  6. Offline

    Xerox262

    Show your full event.
     
  7. Offline

    AppleBabies

    @Xerox262
    Code:
    @EventHandler
        public void onPlayerDamage(EntityDamageByEntityEvent e) {
           
            if(e.getDamager() instanceof Player) {
                if(e.getEntityType() == EntityType.FIREBALL){
                    return;
                }
            }
           
            if(ArenaManager.getInstance().getArena((Player) e.getEntity()).getState() != ArenaState.STARTED){
               
                if (((e.getDamager() instanceof Player)) && ((e.getEntity() instanceof Player))) {
                MessageManager.getInstance().msg((Player) e.getDamager(), MessageType.BAD, "You can't hurt players until the game starts!");
                  e.setCancelled(true);
                }
                }
       
        }
     
  8. Offline

    Nibbit

    Have you tried the playerinteractentity event?
     
  9. Offline

    AppleBabies

    @Nibbit A fireball is an entity, not an item.
     
  10. Offline

    Xerox262

    You're telling it to return if the entity hit is a fireball, you have to cancel it first. Also you need a Player check at the bottom or you will get errors in your console
     
    Nibbit likes this.
  11. Offline

    Nibbit

    ...
    Uhm Idk but PlayerInteractEvent is rightclicking an item and PlayerInteractEntityEvent is interacting with entity :/

    EDIT : Look at Xeroc262 post :p I think PlayerInteractEntityEvent is only for rightclicking mobs :p
     
  12. Offline

    AppleBabies

    @Xerox262 Hah. That was my problem...I returned instead of cancelling. Also, the bottom code works fine with no errors. But thanks much!
     
  13. Offline

    Xerox262

    You will get errors if you don't fix it, even if it works now. But if you want to risk it then feel free... Remember to set the thread as solved.
     
    Nibbit likes this.
  14. Offline

    AppleBabies

    @Xerox262 What do you mean? :p
    Code:
    if (((e.getDamager() instanceof Player)) && ((e.getEntity() instanceof Player))) {
    That works fine. Anyways, marked as solved.
     
  15. Offline

    Xerox262

    I mean the line before that.
    You're telling your plugin that it will ALWAYS be a player, if you don't believe me punch an entity, something like a cow or chicken (#CowAndChicken) then look at your console
    Code:
           if(ArenaManager.getInstance().getArena((Player) e.getEntity()).getState() != ArenaState.STARTED){
     
    Nibbit likes this.
  16. Offline

    AppleBabies

    @Xerox262 That doesn't matter in my case. No LivingEntities spawn in my game. Thanks, though!
     
  17. Offline

    Nibbit

    Still... :p Better no errors than some errors.
     
Thread Status:
Not open for further replies.

Share This Page