From 8d6cd27b8562e19d6a51b9d72389206953d01205 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Wed, 4 Mar 2020 18:45:33 +0200 Subject: [PATCH] Fix rotating furniture with a stack helper --- .../com/eu/habbo/habbohotel/rooms/Room.java | 47 ++++++++++++------- .../events/users/HabboAddedToRoomEvent.java | 2 +- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index 11f81d96..1815fe56 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -4471,26 +4471,31 @@ public class Room implements Comparable, ISerialize, Runnable { boolean magicTile = item instanceof InteractionStackHelper; + Optional stackHelper = this.getItemsAt(tile).stream().filter(i -> i instanceof InteractionStackHelper).findAny(); + //Check if can be placed at new position THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); - if (topItem != item) { - for (RoomTile t : occupiedTiles) { - HabboItem tileTopItem = this.getTopItemAt(t.x, t.y); - if (!magicTile && ((tileTopItem != null && tileTopItem != item ? (t.state.equals(RoomTileState.INVALID) || !t.getAllowStack() || !tileTopItem.getBaseItem().allowStack()) : this.calculateTileState(t, item).equals(RoomTileState.INVALID)))) - return FurnitureMovementError.CANT_STACK; - if (this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS; - if (this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS; - if (this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS; + + if (!stackHelper.isPresent()) { + if (topItem != item) { + for (RoomTile t : occupiedTiles) { + HabboItem tileTopItem = this.getTopItemAt(t.x, t.y); + if (!magicTile && ((tileTopItem != null && tileTopItem != item ? (t.state.equals(RoomTileState.INVALID) || !t.getAllowStack() || !tileTopItem.getBaseItem().allowStack()) : this.calculateTileState(t, item).equals(RoomTileState.INVALID)))) + return FurnitureMovementError.CANT_STACK; + if (this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS; + if (this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS; + if (this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS; + } } - } - List>> tileFurniList = new ArrayList<>(); - for (RoomTile t : occupiedTiles) { - tileFurniList.add(Pair.create(t, this.getItemsAt(t))); - } + List>> tileFurniList = new ArrayList<>(); + for (RoomTile t : occupiedTiles) { + tileFurniList.add(Pair.create(t, this.getItemsAt(t))); + } - if (!magicTile && !item.canStackAt(this, tileFurniList)) { - return FurnitureMovementError.CANT_STACK; + if (!magicTile && !item.canStackAt(this, tileFurniList)) { + return FurnitureMovementError.CANT_STACK; + } } THashSet oldOccupiedTiles = this.layout.getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); @@ -4511,8 +4516,16 @@ public class Room implements Comparable, ISerialize, Runnable { } //Place at new position - double height = this.getStackHeight(tile.x, tile.y, false, item); - if (item.equals(topItem) && tile.x == item.getX() && tile.y == item.getY()) height = item.getZ(); + double height; + + if (stackHelper.isPresent()) { + height = stackHelper.get().getExtradata().isEmpty() ? Double.valueOf("0.0") : (Double.valueOf(stackHelper.get().getExtradata()) / 100); + } else if (item.equals(topItem) && tile.x == item.getX() && tile.y == item.getY()) { + height = item.getZ(); + } else { + height = this.getStackHeight(tile.x, tile.y, false, item); + } + if(height > 40d) return FurnitureMovementError.CANT_STACK; item.setX(tile.x); diff --git a/src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java b/src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java index d31f4a6c..2e5ab84b 100644 --- a/src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java @@ -8,7 +8,7 @@ import java.util.Collection; public class HabboAddedToRoomEvent extends UserEvent { public final Room room; - public final Collection habbosToSendEnter; + public Collection habbosToSendEnter; public HabboAddedToRoomEvent(Habbo habbo, Room room, Collection habbosToSendEnter) {