diff --git a/src/main/java/org/spongepowered/api/data/Keys.java b/src/main/java/org/spongepowered/api/data/Keys.java index 5ac39dabea..59871ac3a9 100644 --- a/src/main/java/org/spongepowered/api/data/Keys.java +++ b/src/main/java/org/spongepowered/api/data/Keys.java @@ -2133,7 +2133,7 @@ public final class Keys { public static final Key> LAYER = Keys.key(ResourceKey.sponge("layer"), Integer.class); /** - * The holder of a leashed {@link Agent} + * The holder of a leashed {@link Entity} * e.g. a {@link Player} or {@link LeashKnot}. *

Usually, a {@link LeashKnot} will always exist so long as there is * a leashed {@link Entity} attached. If the leash is broken, the leash diff --git a/src/main/java/org/spongepowered/api/entity/Leashable.java b/src/main/java/org/spongepowered/api/entity/Leashable.java new file mode 100644 index 0000000000..69a9465726 --- /dev/null +++ b/src/main/java/org/spongepowered/api/entity/Leashable.java @@ -0,0 +1,45 @@ +/* + * 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; + +/** + * Represents an {@link Entity} which can be leashed. + */ +public interface Leashable extends Entity { + + /** + * {@link Keys#LEASH_HOLDER} + * + * @return The holder of the leashed entity + */ + default Optional> leashHolder() { + return this.getValue(Keys.LEASH_HOLDER).map(Value::asMutable); + } +} diff --git a/src/main/java/org/spongepowered/api/entity/living/Agent.java b/src/main/java/org/spongepowered/api/entity/living/Agent.java index f44e8e8bb8..56f371a3a4 100644 --- a/src/main/java/org/spongepowered/api/entity/living/Agent.java +++ b/src/main/java/org/spongepowered/api/entity/living/Agent.java @@ -28,6 +28,7 @@ import org.spongepowered.api.data.type.HandPreference; import org.spongepowered.api.data.value.Value; import org.spongepowered.api.entity.Entity; +import org.spongepowered.api.entity.Leashable; import org.spongepowered.api.entity.ai.goal.GoalExecutor; import org.spongepowered.api.entity.ai.goal.GoalExecutorType; import org.spongepowered.api.entity.ai.goal.builtin.creature.target.TargetGoal; @@ -39,7 +40,7 @@ * An Agent represents a {@link Living} that has AI. In the future Sponge will * allow for custom AIs, but for now vanilla behavior can only be disabled. */ -public interface Agent extends Living, ArmorEquipable { +public interface Agent extends Living, Leashable, ArmorEquipable { /** * {@link Keys#TARGET_ENTITY} @@ -78,15 +79,6 @@ default Value.Mutable persistent() { return this.requireValue(Keys.IS_PERSISTENT).asMutable(); } - /** - * {@link Keys#LEASH_HOLDER} - * - * @return The holder of the leashed agent - */ - default Optional> leashHolder() { - return this.getValue(Keys.LEASH_HOLDER).map(Value::asMutable); - } - /** * Gets a {@link GoalExecutor} based on the {@link GoalExecutorType}. * diff --git a/src/main/java/org/spongepowered/api/entity/vehicle/Boat.java b/src/main/java/org/spongepowered/api/entity/vehicle/Boat.java index 7e97906a3e..0353033ce9 100644 --- a/src/main/java/org/spongepowered/api/entity/vehicle/Boat.java +++ b/src/main/java/org/spongepowered/api/entity/vehicle/Boat.java @@ -27,11 +27,12 @@ import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.type.BoatType; import org.spongepowered.api.data.value.Value; +import org.spongepowered.api.entity.Leashable; /** * Represents a Boat entity. */ -public interface Boat extends Vehicle { +public interface Boat extends Vehicle, Leashable { /** * {@link Keys#BOAT_TYPE}