use of com.github.steveice10.packetlib.Session in project DragonProxy by DragonetMC.
the class PERequestChunkRadiusPacketTranslator method translate.
@Override
public Packet[] translate(UpstreamSession session, RequestChunkRadiusPacket packet) {
session.getDataCache().put(CacheKey.PLAYER_REQUESTED_CHUNK_RADIUS, packet.radius);
// System.out.println("Requested chunk radius : " + packet.radius);
session.sendPacket(new ChunkRadiusUpdatedPacket(((RequestChunkRadiusPacket) packet).radius));
session.getChunkCache().sendOrderedChunks();
ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket((String) session.getDataCache().getOrDefault(CacheKey.PLAYER_LANGUAGE, "enUS"), (int) session.getDataCache().getOrDefault(CacheKey.PLAYER_REQUESTED_CHUNK_RADIUS, 5), ChatVisibility.FULL, false, new SkinPart[] {}, Hand.OFF_HAND);
((PCDownstreamSession) session.getDownstream()).send(clientSettingsPacket);
return null;
}
use of com.github.steveice10.packetlib.Session in project DragonProxy by DragonetMC.
the class InventoryTranslatorRegister method updateSlot.
public static void updateSlot(UpstreamSession session, ServerSetSlotPacket packet) {
if (packet.getWindowId() == 0)
// We don't process player inventory updates here.
return;
if (!session.getDataCache().containsKey(CacheKey.CURRENT_WINDOW_ID) || !session.getWindowCache().hasWindow(packet.getWindowId())) {
session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
return;
}
int openedId = (int) session.getDataCache().get(CacheKey.CURRENT_WINDOW_ID);
if (packet.getWindowId() != openedId) {
// Hmm
closeOpened(session, true);
session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
return;
}
CachedWindow win = session.getWindowCache().get(openedId);
if (win.size <= packet.getSlot()) {
session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
return;
}
IInventoryTranslator translator = TRANSLATORS.get(win.pcType);
if (translator == null) {
session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
return;
}
// Update here
win.slots[packet.getSlot()] = packet.getItem();
translator.updateSlot(session, win, packet.getSlot());
}
use of com.github.steveice10.packetlib.Session in project DragonProxy by DragonetMC.
the class InventoryTranslatorRegister method open.
public static void open(UpstreamSession session, ServerOpenWindowPacket win) {
closeOpened(session, true);
if (TRANSLATORS.containsKey(win.getType())) {
CachedWindow cached = new CachedWindow(win.getWindowId(), win.getType(), win.getSlots() + 36);
session.getWindowCache().cacheWindow(cached);
final IInventoryTranslator translator = TRANSLATORS.get(win.getType());
session.getDataCache().put(CacheKey.CURRENT_WINDOW_ID, win.getWindowId());
// -36 for the player inv size
session.getDataCache().put(CacheKey.CURRENT_WINDOW_SIZE, win.getSlots());
translator.prepare(session, cached);
DragonProxy.getInstance().getGeneralThreadPool().schedule(() -> {
// with this -> double chest, without -> content....
translator.open(session, cached);
cached.isOpen = true;
com.github.steveice10.packetlib.packet.Packet[] items = session.getWindowCache().getCachedPackets(win.getWindowId());
for (com.github.steveice10.packetlib.packet.Packet item : items) if (item != null)
if (ServerWindowItemsPacket.class.isAssignableFrom(item.getClass()))
updateContent(session, (ServerWindowItemsPacket) item);
else
updateSlot(session, (ServerSetSlotPacket) item);
}, 200, TimeUnit.MILLISECONDS);
} else
// Not supported
session.getDownstream().send(new ClientCloseWindowPacket(win.getWindowId()));
}
use of com.github.steveice10.packetlib.Session in project DragonProxy by DragonetMC.
the class InventoryTranslatorRegister method updateContent.
public static void updateContent(UpstreamSession session, ServerWindowItemsPacket packet) {
if (packet.getWindowId() == 0)
// We don't process player inventory updates here.
return;
if (!session.getDataCache().containsKey(CacheKey.CURRENT_WINDOW_ID) || !session.getWindowCache().hasWindow(packet.getWindowId())) {
session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
return;
}
int openedId = (int) session.getDataCache().get(CacheKey.CURRENT_WINDOW_ID);
if (packet.getWindowId() != openedId) {
// Hmm
closeOpened(session, true);
return;
}
CachedWindow win = session.getWindowCache().get(openedId);
IInventoryTranslator translator = TRANSLATORS.get(win.pcType);
if (translator == null) {
session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
return;
}
win.slots = packet.getItems();
translator.updateContent(session, win);
}
Aggregations