Skip to content

Commit f8faf0d

Browse files
authored
Abstract Attackable to a separate interface (#2555)
1 parent b4fab13 commit f8faf0d

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.entity;
26+
27+
import org.spongepowered.api.data.Keys;
28+
import org.spongepowered.api.data.value.Value;
29+
30+
import java.util.Optional;
31+
32+
public interface Attackable extends Entity {
33+
34+
/**
35+
* {@link Keys#LAST_ATTACKER}
36+
*
37+
* @return The last attacker who attacked this entity
38+
*/
39+
default Optional<Value.Mutable<Entity>> lastAttacker() {
40+
return this.getValue(Keys.LAST_ATTACKER).map(Value::asMutable);
41+
}
42+
}

src/main/java/org/spongepowered/api/entity/Interaction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
*/
2525
package org.spongepowered.api.entity;
2626

27-
public interface Interaction extends Entity {
27+
public interface Interaction extends Entity, Attackable {
2828
// TODO Data
2929
}

src/main/java/org/spongepowered/api/entity/living/Living.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.spongepowered.api.data.value.MapValue;
3131
import org.spongepowered.api.data.value.Value;
3232
import org.spongepowered.api.effect.potion.PotionEffect;
33+
import org.spongepowered.api.entity.Attackable;
3334
import org.spongepowered.api.entity.Entity;
3435
import org.spongepowered.api.entity.attribute.Attribute;
3536
import org.spongepowered.api.entity.attribute.AttributeHolder;
@@ -45,7 +46,7 @@
4546
* <p>Living entities can have {@link PotionEffect}s, breathing air
4647
* under water, custom names, hold {@link Attribute}s, and become invisible.</p>
4748
*/
48-
public interface Living extends AttributeHolder, Entity {
49+
public interface Living extends AttributeHolder, Entity, Attackable {
4950

5051
/**
5152
* {@link Keys#ABSORPTION}
@@ -92,15 +93,6 @@ default Value.Mutable<Double> maxHealth() {
9293
return this.requireValue(Keys.MAX_HEALTH).asMutable();
9394
}
9495

95-
/**
96-
* {@link Keys#LAST_ATTACKER}
97-
*
98-
* @return The last attacker who attacked this entity
99-
*/
100-
default Optional<Value.Mutable<Entity>> lastAttacker() {
101-
return this.getValue(Keys.LAST_ATTACKER).map(Value::asMutable);
102-
}
103-
10496
/**
10597
* {@link Keys#HEAD_ROTATION}
10698
*

0 commit comments

Comments
 (0)