Solved Disable sword Sweep Attack ability?

Discussion in 'Spigot Plugin Development' started by Macaron, Jun 16, 2016.

  1. I have been googling for almost half an hour, yet could not find any way to identify if an entity is hit by a direct attack, or the sweep attack ability added in 1.9.
    It looks like the sweep attack is a sequence of EntityDamageByEntityEvent for each of the victim. There's no something like "DamageCause.ENTITY_ATTACK_SWEEP" provided.

    Also, how do I get the charging percentage of a player's attack meter? I have tried the method from HERE, but as for now (June 2016), the attack meter still got reset before the damage event. Has there been a proper way to get that now?
     
    #1 Macaron, Jun 16, 2016
    Last edited: Jun 17, 2016
  2. I'm sorry I don't have a better answer. But I found a way to disable the sweep attack AND ensure that all melee attacks occur at full charge. This won't solve your problem if you're looking to keep 1.9 pvp mechanics. I'm not 100% certain on how this works or why 16 is the magic number, but I suspect it makes the player's attack recharge fast enough that 1.9 damage reduction will not occur.

    on PlayerJoinEvent:
    Code (Text):
    player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(16);
    I wouldn't be surprised if Spigot devised a way to access this attribute and added it to their API. It's fairly fundamental in my opinion.
     

  3. Yes, I'm trying to keep the 1.9 combat mechanics in some way.
    16 is the legacy "maximum" (Depends on how fast player can click) attack speed in 1.8.
     
  4. Does anyone have a clue, or it's just not implemented...?
     
  5. You could attempt to detect the sweep attack. Below example is used to detect it, it needs fetching the tick (e.g. a tick task counting up, or you try to use attacker.getTicksLived, which might be as good in this case, i've only tested with a tick task though) keeping some data (tick + location hash), it's not perfect / maximally confined but appears to work quite well.

    // 1.9: sweep attack.
    final int locHashCode = LocUtil.hashCode(loc); // ATTACKER
    if (originalDamage == 1.0) {
    // Might be a sweep attack.
    if (tick == data.sweepTick && locHashCode == data.sweepLocationHashCode) {
    return cancelled;
    }
    }
    else {
    data.sweepTick = tick;
    data.sweepLocationHashCode = locHashCode;
    }

    (Idea being that 1.0 original (!) damage seems to be what the sweep attack does, it'll also be the same tick. Confine by location of the attackr, update location+ tick with other than 1.0 original damage.)
     
  6. Thanks for the concept! That's a really flawless way to guess.
    By the way, I also noticed that a charged sword hit is impossible to deal 1 damage, so I just cancel out the event if the player is holding a sword, charge meter is 100% and the damage is 1.0 ;) Anyways, thanks for the help, it's really appreciated!
     
  7. Also, for anyone else who is struggling with the charge meter resetting before the damage event... Since I only need to know if a player is charged, I simply use a Set containing all uncharged players, add player to it when the player attacks, and use a Runnable to remove the player after the charge is done.