Skip to content

Commit

Permalink
Abstract Attackable to a separate interface (#2555)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImMorpheus committed Jul 7, 2024
1 parent b4fab13 commit f8faf0d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
42 changes: 42 additions & 0 deletions src/main/java/org/spongepowered/api/entity/Attackable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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<Value.Mutable<Entity>> lastAttacker() {
return this.getValue(Keys.LAST_ATTACKER).map(Value::asMutable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
*/
package org.spongepowered.api.entity;

public interface Interaction extends Entity {
public interface Interaction extends Entity, Attackable {
// TODO Data
}
12 changes: 2 additions & 10 deletions src/main/java/org/spongepowered/api/entity/living/Living.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,7 +46,7 @@
* <p>Living entities can have {@link PotionEffect}s, breathing air
* under water, custom names, hold {@link Attribute}s, and become invisible.</p>
*/
public interface Living extends AttributeHolder, Entity {
public interface Living extends AttributeHolder, Entity, Attackable {

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

/**
* {@link Keys#LAST_ATTACKER}
*
* @return The last attacker who attacked this entity
*/
default Optional<Value.Mutable<Entity>> lastAttacker() {
return this.getValue(Keys.LAST_ATTACKER).map(Value::asMutable);
}

/**
* {@link Keys#HEAD_ROTATION}
*
Expand Down

0 comments on commit f8faf0d

Please sign in to comment.