RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
ItemOptionPacketListener.java
1package com.osroyale.net.packet.in;
2
3import com.osroyale.content.event.EventDispatcher;
4import com.osroyale.content.event.impl.FirstItemClickInteractionEvent;
5import com.osroyale.content.event.impl.SecondItemClickInteractionEvent;
6import com.osroyale.content.event.impl.ThirdItemClickInteractionEvent;
7import com.osroyale.content.itemaction.ItemActionRepository;
8import com.osroyale.game.event.impl.ItemClickEvent;
9import com.osroyale.game.plugin.PluginManager;
10import com.osroyale.game.world.InterfaceConstants;
11import com.osroyale.game.world.entity.mob.data.PacketType;
12import com.osroyale.game.world.entity.mob.player.Player;
13import com.osroyale.game.world.items.Item;
14import com.osroyale.net.codec.ByteModification;
15import com.osroyale.net.codec.ByteOrder;
16import com.osroyale.net.packet.GamePacket;
17import com.osroyale.net.packet.PacketListener;
18import com.osroyale.net.packet.PacketListenerMeta;
19import static com.google.common.base.Preconditions.checkState;
20import static com.osroyale.net.packet.ClientPackets.*;
21
28@PacketListenerMeta({ FIRST_ITEM_OPTION, SECOND_ITEM_OPTION, THIRD_ITEM_OPTION })
59
61
62 @Override
63 public void handlePacket(Player player, GamePacket packet) {
64 checkState(player != null, "Player does not exist.");
65
66 if (player.locking.locked(PacketType.CLICK_ITEM)) {
67 return;
68 }
69
70 if (player.isDead()) {
71 return;
72 }
73
74 switch (packet.getOpcode()) {
75
76 case FIRST_ITEM_OPTION:
77 handleFirstOption(player, packet);
78 break;
79
80 case SECOND_ITEM_OPTION:
81 handleSecondOption(player, packet);
82 break;
83
84 case THIRD_ITEM_OPTION:
85 handleThirdOption(player, packet);
86 break;
87
88 }
89 }
90
91 private static void handleFirstOption(Player player, GamePacket packet) {
92 final int interfaceId = packet.readShort(ByteOrder.LE, ByteModification.ADD);
93 final int slot = packet.readShort(false, ByteModification.ADD);
94 final int id = packet.readShort(ByteOrder.LE);
95
96 switch (interfaceId) {
97 case 57716:
98 player.forClan(channel -> channel.getShowcase().select(player, id, slot));
99 break;
100 case InterfaceConstants.INVENTORY_INTERFACE:
101 final Item item = player.inventory.get(slot);
102
103 if (item == null || item.getId() != id) {
104 return;
105 }
106
107 if (EventDispatcher.execute(player, new FirstItemClickInteractionEvent(item, slot))) {
108 return;
109 }
110
111 if (ItemActionRepository.inventory(player, item, 1)) {
112 return;
113 }
114
115 if (player.mysteryBox.click(item)) {
116 return;
117 }
118
119 PluginManager.getDataBus().publish(player, new ItemClickEvent(1, item, slot));
120 break;
121 }
122 }
123
124 private static void handleSecondOption(Player player, GamePacket packet) {
125 final int itemId = packet.readShort(ByteModification.ADD);
126 final int slot = packet.readShort(ByteOrder.LE, ByteModification.ADD);
127 final int interfaceId = packet.readShort(ByteOrder.LE, ByteModification.ADD);
128
129 switch (interfaceId) {
130 case InterfaceConstants.INVENTORY_INTERFACE:
131 final Item item = player.inventory.get(slot);
132
133 if (item == null || item.getId() != itemId) {
134 return;
135 }
136
137 if (EventDispatcher.execute(player, new SecondItemClickInteractionEvent(item, slot))) {
138 return;
139 }
140
141 if (ItemActionRepository.inventory(player, item, 2)) {
142 return;
143 }
144
145 PluginManager.getDataBus().publish(player, new ItemClickEvent(2, item, slot));
146 break;
147 }
148 }
149
150 private static void handleThirdOption(Player player, GamePacket packet) {
151 final int interfaceId = packet.readShort(ByteOrder.LE, ByteModification.ADD);
152 final int slot = packet.readShort(ByteOrder.LE);
153 final int itemId = packet.readShort(ByteModification.ADD);
154
155 switch (interfaceId) {
156 case InterfaceConstants.INVENTORY_INTERFACE:
157 Item item = player.inventory.get(slot);
158
159 if (item == null || item.getId() != itemId) {
160 return;
161 }
162
163 if (EventDispatcher.execute(player, new ThirdItemClickInteractionEvent(item, slot))) {
164 return;
165 }
166
167 if (ItemActionRepository.inventory(player, item, 3)) {
168 return;
169 }
170
171 PluginManager.getDataBus().publish(player, new ItemClickEvent(3, item, slot));
172 break;
173 }
174 }
175
176}