RuneHive-Game
Loading...
Searching...
No Matches
ItemContainerAdapter.java
Go to the documentation of this file.
1package com.runehive.game.world.items.containers;
2
3import com.runehive.net.packet.out.SendMessage;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.game.world.items.Item;
6
7import java.util.Optional;
8
9/**
10 * An adapter for {@link ItemContainerListener} that updates {@link Item}s on a widget whenever items change, and sends the
11 * underlying {@link Player} a message when the container is full.
12 * @author lare96 <http://github.org/lare96>
13 */
14public abstract class ItemContainerAdapter implements ItemContainerListener {
15
16 /**
17 * The {@link Player} instance.
18 */
19 private final Player player;
20
21 /**
22 * Creates a new {@link ItemContainerAdapter}.
23 * @param player The {@link Player} instance.
24 */
26 this.player = player;
27 }
28
29 /**
30 * Queues a message that displays items from an {@link ItemContainer} on a widget.
31 */
32 protected void sendItemsToWidget(ItemContainer container) {
33 container.refresh(player, getWidgetId());
34 }
35
36 /**
37 * @return The widget to display items on.
38 */
39 public abstract int getWidgetId();
40
41 /**
42 * @return The message sent when the {@link ItemContainer} exceeds its capacity.
43 */
44 public abstract String getCapacityExceededMsg();
45
46 @Override
47 public void itemUpdated(ItemContainer container, Optional<Item> oldItem, Optional<Item> newItem, int index, boolean refresh, boolean login) {
48 if(refresh)
49 sendItemsToWidget(container);
50 }
51
52 @Override
53 public void bulkItemsUpdated(ItemContainer container) {
54 sendItemsToWidget(container);
55 }
56
57 @Override
58 public void capacityExceeded(ItemContainer container) {
60 }
61}
This class represents a character controlled by a player.
Definition Player.java:125
void bulkItemsUpdated(ItemContainer container)
Fired when an Items are added, removed, or replaced in bulk.
void sendItemsToWidget(ItemContainer container)
Queues a message that displays items from an ItemContainer on a widget.
void itemUpdated(ItemContainer container, Optional< Item > oldItem, Optional< Item > newItem, int index, boolean refresh, boolean login)
Fired when an Item is added, removed, or replaced.
ItemContainerAdapter(Player player)
Creates a new ItemContainerAdapter.
void capacityExceeded(ItemContainer container)
Fired when the capacity of container is exceeded.
An abstraction game representing a group of Items.
void refresh(Player player, int widget)
Sends the items on the itemcontainer.
The OutgoingPacket that sends a message to a Players chatbox in the client.