No void damage?

Discussion in 'Spigot Plugin Development' started by DeadlyDeath001, May 9, 2015.

  1. Would this work on no void damage?
    Code (Text):
        @EventHandler(priority=EventPriority.LOWEST, ignoreCancelled=true)
        final void onDamage(final EntityDamageEvent event){
            if (event.getEntityType() != EntityType.PLAYER) return;
            if (event.getCause() == DamageCause.FALL)
                event.setCancelled(true);
            if (event.getCause() == DamageCause.VOID)
                event.setCancelled(true);
     
    #1 DeadlyDeath001, May 9, 2015
    Last edited: May 9, 2015
  2. gigosaurus

    Supporter

    [​IMG]

    Seriously though, with how disguising that code is, I really can't. What did brackets ever do to you?

    Code (Java):
    @EventHandler(priority=EventPriority.LOWEST, ignoreCancelled=true)
    You want to stop void damage, yet you open up the possibility for another listener to cancel the event, and thereby cause the void damage to happen?

    Code (Java):
    final void onDamage(final EntityDamageEvent event){
    Why the "final" modifier on everything? And why is it package visible?

    Code (Java):
    if (event.getCause() == DamageCause.VOID)
                if (checkVoid(event.getEntity())) event.setCancelled(true);
    A player will only get damaged by the void when they are in the void, so what's the point in the checkVoid method?

    To answer your question, something as simple as this would stop void damage, so as long as your code does this it'll stop the void damage:
    Code (Java):
    @EventHandler
    public void onDamage(EntityDamageEvent event) {
        if (event.getDamage() == DamageCause.VOID) {
            event.setCancelled(true);
        }
    }
     
    #2 gigosaurus, May 9, 2015
    Last edited: May 9, 2015
    • Funny Funny x 2
    • Like Like x 1
    • Agree Agree x 1
  3. Argh, somebody that don't know what he is doing. Maybe some spoonfeed code which he tried but did not work.
     
  4. Nothing wrong with braceless if statements.
    why not final? As for the package private, it's better than public.
     
  5. You could always... you know... test it?
     
    • Agree Agree x 1
  6. gigosaurus

    Supporter

    He originally had some nested if statements before he edited them out, all without braces. Also braceless if's are extremely confusing to read, quite often end up resulting in unintended behaviour (accidently adding a ; after the if, trying to add two statements to the braceless if, etc) and it completely violates oracles code conventions (as well as pretty much any other). I can't think of one good reason why anyone should use them.

    I doubt he has or is intended to ever add any subclasses which could override the method, and so the final modifier is completely pointless. Declaring a parameter final is also pointless unless you have a nested class in that method.

    I doubt he is using that class somewhere else in the package, so really it should be private.