diff --git a/src/main/java/org/spongepowered/api/entity/Attackable.java b/src/main/java/org/spongepowered/api/entity/Attackable.java new file mode 100644 index 0000000000..62f776fb2c --- /dev/null +++ b/src/main/java/org/spongepowered/api/entity/Attackable.java @@ -0,0 +1,42 @@ +/* + * This file is part of SpongeAPI, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.entity; + +import org.spongepowered.api.data.Keys; +import org.spongepowered.api.data.value.Value; + +import java.util.Optional; + +public interface Attackable extends Entity { + + /** + * {@link Keys#LAST_ATTACKER} + * + * @return The last attacker who attacked this entity + */ + default Optional> lastAttacker() { + return this.getValue(Keys.LAST_ATTACKER).map(Value::asMutable); + } +} diff --git a/src/main/java/org/spongepowered/api/entity/Interaction.java b/src/main/java/org/spongepowered/api/entity/Interaction.java index 9b3a2d094f..26e531448c 100644 --- a/src/main/java/org/spongepowered/api/entity/Interaction.java +++ b/src/main/java/org/spongepowered/api/entity/Interaction.java @@ -24,6 +24,6 @@ */ package org.spongepowered.api.entity; -public interface Interaction extends Entity { +public interface Interaction extends Entity, Attackable { // TODO Data } diff --git a/src/main/java/org/spongepowered/api/entity/living/Living.java b/src/main/java/org/spongepowered/api/entity/living/Living.java index 58b8b1473e..5597a444cb 100644 --- a/src/main/java/org/spongepowered/api/entity/living/Living.java +++ b/src/main/java/org/spongepowered/api/entity/living/Living.java @@ -30,6 +30,7 @@ import org.spongepowered.api.data.value.MapValue; import org.spongepowered.api.data.value.Value; import org.spongepowered.api.effect.potion.PotionEffect; +import org.spongepowered.api.entity.Attackable; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.attribute.Attribute; import org.spongepowered.api.entity.attribute.AttributeHolder; @@ -45,7 +46,7 @@ *

Living entities can have {@link PotionEffect}s, breathing air * under water, custom names, hold {@link Attribute}s, and become invisible.

*/ -public interface Living extends AttributeHolder, Entity { +public interface Living extends AttributeHolder, Entity, Attackable { /** * {@link Keys#ABSORPTION} @@ -92,15 +93,6 @@ default Value.Mutable maxHealth() { return this.requireValue(Keys.MAX_HEALTH).asMutable(); } - /** - * {@link Keys#LAST_ATTACKER} - * - * @return The last attacker who attacked this entity - */ - default Optional> lastAttacker() { - return this.getValue(Keys.LAST_ATTACKER).map(Value::asMutable); - } - /** * {@link Keys#HEAD_ROTATION} *