Skip to content

Commit

Permalink
Abstract Leashable to a separate interface (#2554)
Browse files Browse the repository at this point in the history
* Abstract Leashable to a separate interface

* Update Leashable.java
  • Loading branch information
ImMorpheus authored Jul 7, 2024
1 parent 6dbea4e commit aaa9d23
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ public final class Keys {
public static final Key<Value<Integer>> 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}.
* <p>Usually, a {@link LeashKnot} will always exist so long as there is
* a leashed {@link Entity} attached. If the leash is broken, the leash
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/org/spongepowered/api/entity/Leashable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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;

/**
* 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<Value.Mutable<Entity>> leashHolder() {
return this.getValue(Keys.LEASH_HOLDER).map(Value::asMutable);
}
}
12 changes: 2 additions & 10 deletions src/main/java/org/spongepowered/api/entity/living/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
Expand Down Expand Up @@ -78,15 +79,6 @@ default Value.Mutable<Boolean> persistent() {
return this.requireValue(Keys.IS_PERSISTENT).asMutable();
}

/**
* {@link Keys#LEASH_HOLDER}
*
* @return The holder of the leashed agent
*/
default Optional<Value.Mutable<Entity>> leashHolder() {
return this.getValue(Keys.LEASH_HOLDER).map(Value::asMutable);
}

/**
* Gets a {@link GoalExecutor} based on the {@link GoalExecutorType}.
*
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/spongepowered/api/entity/vehicle/Boat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit aaa9d23

Please sign in to comment.