Skip to content

Commit

Permalink
Update Trader and Merchant api classes (#2546)
Browse files Browse the repository at this point in the history
* Update Trader and Merchant api classes

* Update more classes
  • Loading branch information
ImMorpheus authored Jul 3, 2024
1 parent 3a4be66 commit 8a00331
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 45 deletions.
15 changes: 7 additions & 8 deletions src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
import org.spongepowered.api.entity.living.player.gamemode.GameMode;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.entity.living.slime.Slime;
import org.spongepowered.api.entity.living.trader.Trader;
import org.spongepowered.api.entity.living.trader.Villager;
import org.spongepowered.api.entity.projectile.DamagingProjectile;
import org.spongepowered.api.entity.projectile.EyeOfEnder;
Expand Down Expand Up @@ -225,6 +224,7 @@
import org.spongepowered.api.item.inventory.equipment.EquipmentType;
import org.spongepowered.api.item.inventory.slot.EquipmentSlot;
import org.spongepowered.api.item.inventory.type.GridInventory;
import org.spongepowered.api.item.merchant.Merchant;
import org.spongepowered.api.item.merchant.TradeOffer;
import org.spongepowered.api.item.potion.PotionType;
import org.spongepowered.api.map.MapCanvas;
Expand Down Expand Up @@ -811,6 +811,11 @@ public final class Keys {
*/
public static final Key<ListValue<PotionEffect>> CUSTOM_POTION_EFFECTS = Keys.listKey(ResourceKey.sponge("custom_potion_effects"), PotionEffect.class);

/**
* The currently trading customer with this {@link Merchant}.
*/
public static final Key<Value<Player>> CUSTOMER = Keys.key(ResourceKey.sponge("customer"), Player.class);

/**
* The damage absorbed by an armor {@link ItemStack}.
* Readonly
Expand Down Expand Up @@ -2020,12 +2025,6 @@ public final class Keys {
*/
public static final Key<Value<Boolean>> IS_TAMED = Keys.key(ResourceKey.sponge("is_tamed"), Boolean.class);

/**
* Whether a {@link Trader} is currently trading with a {@link Player}.
* Readonly
*/
public static final Key<Value<Boolean>> IS_TRADING = Keys.key(ResourceKey.sponge("is_trading"), Boolean.class);

/**
* Whether a {@link Turtle} is currently traveling.
*/
Expand Down Expand Up @@ -3206,7 +3205,7 @@ public final class Keys {
public static final Key<Value<Boolean>> TRACKS_OUTPUT = Keys.key(ResourceKey.sponge("tracks_output"), Boolean.class);

/**
* The {@link TradeOffer}s offered by a {@link Trader} or a {@link org.spongepowered.api.item.inventory.type.ViewableInventory.Custom}
* The {@link TradeOffer}s offered by a {@link Merchant} or a {@link org.spongepowered.api.item.inventory.type.ViewableInventory.Custom}
*/
public static final Key<ListValue<TradeOffer>> TRADE_OFFERS = Keys.listKey(ResourceKey.sponge("trade_offers"), TradeOffer.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
import org.spongepowered.api.data.type.ProfessionTypes;
import org.spongepowered.api.data.type.VillagerType;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.living.Ageable;

/**
* Represents a Villager.
*/
public interface Villager extends Trader, Ageable {
public interface Villager extends VillagerLike {

/**
* {@link Keys#VILLAGER_TYPE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,11 @@
*/
package org.spongepowered.api.entity.living.trader;

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.living.PathfinderAgent;
import org.spongepowered.api.entity.living.Ageable;
import org.spongepowered.api.item.merchant.Merchant;

public interface Trader extends PathfinderAgent, Merchant {

/**
* {@link Keys#IS_TRADING}
*
* @return Whether this trader is currently trading with a player
*/
default Value<Boolean> trading() {
return this.requireValue(Keys.IS_TRADING);
}
/**
* An abstract representation of a Villager.
*/
public interface VillagerLike extends Ageable, Merchant {
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
*/
package org.spongepowered.api.entity.living.trader;


/**
* Represents a Wandering Trader.
*/
public interface WanderingTrader extends Trader {
public interface WanderingTrader extends VillagerLike {

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.spongepowered.api.entity.FallingBlock;
import org.spongepowered.api.entity.Item;
import org.spongepowered.api.entity.living.animal.Animal;
import org.spongepowered.api.entity.living.trader.Trader;
import org.spongepowered.api.entity.vehicle.minecart.SpawnerMinecart;
import org.spongepowered.api.item.merchant.Merchant;
import org.spongepowered.api.registry.DefaultedRegistryReference;
import org.spongepowered.api.registry.Registry;
import org.spongepowered.api.registry.RegistryKey;
Expand Down Expand Up @@ -93,7 +93,7 @@ public final class SpawnTypes {

/**
* When an {@link ExperienceOrb} is spawned as a result of a "reward" from
* an {@link Entity} granting experience for the kill, or a {@link Trader}
* an {@link Entity} granting experience for the kill, or a {@link Merchant}
* granting experience for a successful trade, or a block being mined.
*/
public static final DefaultedRegistryReference<SpawnType> EXPERIENCE = SpawnTypes.key(ResourceKey.sponge("experience"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.spongepowered.api.item.inventory.Container;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.item.inventory.Slot;
import org.spongepowered.api.item.merchant.Merchant;
import org.spongepowered.api.item.merchant.TradeOffer;

import java.util.Optional;
Expand Down Expand Up @@ -182,7 +183,7 @@ interface All extends Recipe {}
}

/**
* Fies when the client requests to select a trade from a {@link org.spongepowered.api.entity.living.trader.Trader}
* Fies when the client requests to select a trade from a {@link Merchant}
*/
interface SelectTrade extends ClickContainerEvent {

Expand Down
29 changes: 11 additions & 18 deletions src/main/java/org/spongepowered/api/item/merchant/Merchant.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
*/
package org.spongepowered.api.item.merchant;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.data.DataHolder;
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.ListValue;
import org.spongepowered.api.entity.living.Humanoid;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.item.inventory.Carrier;
import org.spongepowered.api.world.Locatable;

Expand All @@ -39,22 +39,6 @@
*/
public interface Merchant extends DataHolder.Mutable, Carrier, Locatable {

/**
* Gets the currently trading customer with this merchant.
*
* @return The currently trading customer if available
*/
Optional<Humanoid> customer();

/**
* Sets the currently trading customer with this merchant.
* <p>If the humanoid is available, a new trading window may open
* with this merchant.</p>
*
* @param humanoid The humanoid to trade with
*/
void setCustomer(@Nullable Humanoid humanoid);

/**
* {@link Keys#TRADE_OFFERS}
*
Expand All @@ -64,4 +48,13 @@ default ListValue.Mutable<TradeOffer> tradeOffers() {
return this.requireValue(Keys.TRADE_OFFERS).asMutable();
}

/**
* {@link Keys#CUSTOMER}
*
* @return Whether this trader is currently trading with a player
*/
default Optional<Value.Mutable<Player>> customer() {
return this.getValue(Keys.CUSTOMER).map(Value::asMutable);
}

}

0 comments on commit 8a00331

Please sign in to comment.