Skip to content

Commit 4c64de4

Browse files
committed
Move willCauseDeath back to impl
1 parent b128dd0 commit 4c64de4

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/main/java/org/spongepowered/api/event/entity/DamageEntityEvent.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@
2525
package org.spongepowered.api.event.entity;
2626

2727
import org.spongepowered.api.block.entity.carrier.Dispenser;
28-
import org.spongepowered.api.data.Keys;
2928
import org.spongepowered.api.entity.Entity;
3029
import org.spongepowered.api.entity.living.monster.skeleton.Skeleton;
3130
import org.spongepowered.api.entity.living.player.Player;
3231
import org.spongepowered.api.entity.projectile.arrow.ArrowLike;
3332
import org.spongepowered.api.event.Cause;
3433
import org.spongepowered.api.event.cause.entity.damage.DamageType;
3534
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;
35+
import org.spongepowered.api.event.impl.entity.AbstractDamageEntityEventPost;
3636
import org.spongepowered.api.item.ItemTypes;
3737
import org.spongepowered.api.item.inventory.ItemStack;
3838
import org.spongepowered.api.world.World;
3939
import org.spongepowered.api.world.difficulty.Difficulties;
4040
import org.spongepowered.api.world.difficulty.Difficulty;
41-
42-
import java.util.Optional;
41+
import org.spongepowered.eventgen.annotations.ImplementedBy;
42+
import org.spongepowered.eventgen.annotations.PropertySettings;
4343

4444
/**
4545
* Represents the base event for when an {@link Entity} is being "damaged".
@@ -85,6 +85,7 @@ interface Pre extends DamageEntityEvent, DamageCalculationEvent.Pre {
8585
/**
8686
* Fires after the damage steps and their side effects have been applied.
8787
*/
88+
@ImplementedBy(AbstractDamageEntityEventPost.class)
8889
interface Post extends DamageEntityEvent, DamageCalculationEvent.Post {
8990

9091
/**
@@ -93,9 +94,7 @@ interface Post extends DamageEntityEvent, DamageCalculationEvent.Post {
9394
*
9495
* @return Whether the entity will die
9596
*/
96-
default boolean willCauseDeath() {
97-
final Optional<Double> health = this.entity().get(Keys.HEALTH);
98-
return health.isPresent() && health.get() - this.finalDamage() <= 0;
99-
}
97+
@PropertySettings(requiredParameter = false, generateMethods = false)
98+
boolean willCauseDeath();
10099
}
101100
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.event.impl.entity;
26+
27+
import org.spongepowered.api.data.Keys;
28+
import org.spongepowered.api.event.entity.DamageEntityEvent;
29+
import org.spongepowered.api.event.impl.AbstractEvent;
30+
31+
import java.util.Optional;
32+
33+
public abstract class AbstractDamageEntityEventPost extends AbstractEvent implements DamageEntityEvent.Post {
34+
35+
@Override
36+
public boolean willCauseDeath() {
37+
final Optional<Double> health = this.entity().get(Keys.HEALTH);
38+
return health.isPresent() && health.get() - this.finalDamage() <= 0;
39+
}
40+
}

0 commit comments

Comments
 (0)