Skip to content

Commit

Permalink
Add delay to legacy recipe detection
Browse files Browse the repository at this point in the history
Workaround for an issue which will be properly fixed later.
  • Loading branch information
AJ-Ferguson committed Jan 14, 2021
1 parent 5ddb189 commit 4ee3143
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public class GeyserSession implements CommandSender {
@Getter(AccessLevel.NONE)
private CompletableFuture<Void> inventoryFuture;

@Setter
private ScheduledFuture<?> craftingGridFuture;

/**
* Stores session collision
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.Collections;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

@Translator(packet = ServerSetSlotPacket.class)
public class JavaSetSlotTranslator extends PacketTranslator<ServerSetSlotPacket> {
Expand All @@ -73,7 +74,10 @@ public void translate(ServerSetSlotPacket packet, GeyserSession session) {

InventoryTranslator translator = session.getInventoryTranslator();
if (translator != null) {
updateCraftingGrid(session, packet, inventory, translator);
if (session.getCraftingGridFuture() != null) {
session.getCraftingGridFuture().cancel(false);
}
session.setCraftingGridFuture(session.getConnector().getGeneralThreadPool().schedule(() -> session.addInventoryTask(() -> updateCraftingGrid(session, packet, inventory, translator)), 150, TimeUnit.MILLISECONDS));

GeyserItemStack newItem = GeyserItemStack.from(packet.getItem());
inventory.setItem(packet.getSlot(), newItem, session);
Expand Down Expand Up @@ -208,7 +212,6 @@ private static void updateCraftingGrid(GeyserSession session, ServerSetSlotPacke
}

ShapedRecipeData data = new ShapedRecipeData(width, height, "", javaIngredients, packet.getItem());
session.getConnector().getLogger().error(data.toString());
// Cache this recipe so we know the client has received it
session.getCraftingRecipes().put(newRecipeId, new Recipe(RecipeType.CRAFTING_SHAPED, uuid.toString(), data));

Expand Down

0 comments on commit 4ee3143

Please sign in to comment.