Fix disabling PvP on invulnerability.
@@ -11,6 +11,7 @@ import io.github.nucleuspowered.nucleus.modules.invulnerability.handlers.Invulne
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
+import org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource;
import org.spongepowered.api.event.entity.AttackEntityEvent;
import org.spongepowered.api.event.filter.Getter;
import org.spongepowered.api.event.filter.cause.Root;
@@ -18,18 +19,17 @@ import org.spongepowered.api.event.filter.cause.Root;
public class InvulnerabilityPvpListener extends ListenerBase implements ListenerBase.Conditional {
private final InvulnerabilityService service = getServiceUnchecked(InvulnerabilityService.class);
- private final String perm;
-
- public InvulnerabilityPvpListener() {
- this.perm = getPermissionHandlerFor(GodCommand.class).getPermissionWithSuffix(GodCommand.PVP_OVERRIDE);
- }
+ private final String perm = getPermissionHandlerFor(GodCommand.class).getPermissionWithSuffix(GodCommand.PVP_OVERRIDE);
@Listener
- public void onAttack(AttackEntityEvent event, @Root Player player, @Getter("getTargetEntity") Entity target) {
- if (this.service.isInvulnerable(player) && !player.hasPermission(this.perm) && target instanceof Player) {
+ public void onAttack(AttackEntityEvent event, @Root EntityDamageSource source, @Getter("getTargetEntity") Entity entity) {
+ if (source.getSource() instanceof Player) {
+ Player player = (Player) source.getSource();
+ if (this.service.isInvulnerable(player) && !player.hasPermission(this.perm) && entity instanceof Player) {
event.setCancelled(true);
}
}
+ }
@Override
public boolean shouldEnable() {
