From 47865f0ec5a18328948e2b9eff3db56f0f1c088a Mon Sep 17 00:00:00 2001 From: ArpyAge Date: Tue, 1 Sep 2020 00:22:21 +0200 Subject: [PATCH 1/3] Plugin events to make everything stackable if needed (in case of :buildheight) --- .../com/eu/habbo/habbohotel/rooms/Room.java | 28 ++++++++++++++----- .../events/furniture/FurnitureMovedEvent.java | 12 ++++++-- .../furniture/FurniturePlacedEvent.java | 11 +++++++- .../furniture/FurnitureStackHeightEvent.java | 27 ++++++++++++++++++ 4 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureStackHeightEvent.java 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 82543235..8ccbcc72 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -3560,7 +3560,13 @@ public class Room implements Comparable, ISerialize, Runnable { } } - if (!stackHelper) { + boolean pluginHelper = false; + if (Emulator.getPluginManager().isRegistered(FurnitureStackHeightEvent.class, true)) { + FurnitureStackHeightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureStackHeightEvent(x, y, this)); + stackHelper = event.hasPluginHelper(); + } + + if (!stackHelper && !pluginHelper) { HabboItem item = this.getTopItemAt(x, y, exclude); if (item != null) { canStack = item.getBaseItem().allowStack(); @@ -4443,19 +4449,22 @@ public class Room implements Comparable, ISerialize, Runnable { } public FurnitureMovementError placeFloorFurniAt(HabboItem item, RoomTile tile, int rotation, Habbo owner) throws Exception { + boolean pluginHelper = false; if (Emulator.getPluginManager().isRegistered(FurniturePlacedEvent.class, true)) { - Event furniturePlacedEvent = new FurniturePlacedEvent(item, owner, tile); - Emulator.getPluginManager().fireEvent(furniturePlacedEvent); + FurniturePlacedEvent event = Emulator.getPluginManager().fireEvent(new FurniturePlacedEvent(item, owner, tile)); - if (furniturePlacedEvent.isCancelled()) + if (event.isCancelled()) { return FurnitureMovementError.CANCEL_PLUGIN_PLACE; + } + + pluginHelper = event.hasPluginHelper(); } THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); FurnitureMovementError fits = furnitureFitsAt(tile, item, rotation); - if (!fits.equals(FurnitureMovementError.NONE)) { + if (!fits.equals(FurnitureMovementError.NONE) && !pluginHelper) { return fits; } @@ -4520,9 +4529,14 @@ public class Room implements Comparable, ISerialize, Runnable { public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, Habbo actor) { RoomTile oldLocation = this.layout.getTile(item.getX(), item.getY()); + + boolean pluginHelper = false; if (Emulator.getPluginManager().isRegistered(FurnitureMovedEvent.class, true)) { - if (Emulator.getPluginManager().fireEvent(new FurnitureMovedEvent(item, actor, oldLocation, tile)).isCancelled()) + FurnitureMovedEvent event = Emulator.getPluginManager().fireEvent(new FurnitureMovedEvent(item, actor, oldLocation, tile)); + if(event.isCancelled()) { return FurnitureMovementError.CANCEL_PLUGIN_MOVE; + } + pluginHelper = event.hasPluginHelper(); } HabboItem topItem = this.getTopItemAt(tile.x, tile.y); @@ -4534,7 +4548,7 @@ public class Room implements Comparable, ISerialize, Runnable { //Check if can be placed at new position THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); - if (!stackHelper.isPresent()) { + if (!stackHelper.isPresent() && !pluginHelper) { if (topItem != item) { for (RoomTile t : occupiedTiles) { HabboItem tileTopItem = this.getTopItemAt(t.x, t.y); diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureMovedEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureMovedEvent.java index 13ce67e0..cbf4e1e5 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureMovedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureMovedEvent.java @@ -7,9 +7,8 @@ import com.eu.habbo.habbohotel.users.HabboItem; public class FurnitureMovedEvent extends FurnitureUserEvent { public final RoomTile oldPosition; - - public final RoomTile newPosition; + private boolean pluginHelper; public FurnitureMovedEvent(HabboItem furniture, Habbo habbo, RoomTile oldPosition, RoomTile newPosition) { @@ -17,5 +16,14 @@ public class FurnitureMovedEvent extends FurnitureUserEvent { this.oldPosition = oldPosition; this.newPosition = newPosition; + this.pluginHelper = false; + } + + public void setPluginHelper(boolean helper) { + this.pluginHelper = helper; + } + + public boolean hasPluginHelper() { + return this.pluginHelper; } } diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePlacedEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePlacedEvent.java index 10308ebb..6af5747e 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePlacedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePlacedEvent.java @@ -7,11 +7,20 @@ import com.eu.habbo.habbohotel.users.HabboItem; public class FurniturePlacedEvent extends FurnitureUserEvent { public final RoomTile location; - + private boolean pluginHelper; public FurniturePlacedEvent(HabboItem furniture, Habbo habbo, RoomTile location) { super(furniture, habbo); this.location = location; + this.pluginHelper = false; + } + + public void setPluginHelper(boolean helper) { + this.pluginHelper = helper; + } + + public boolean hasPluginHelper() { + return this.pluginHelper; } } diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureStackHeightEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureStackHeightEvent.java new file mode 100644 index 00000000..f6359407 --- /dev/null +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureStackHeightEvent.java @@ -0,0 +1,27 @@ +package com.eu.habbo.plugin.events.furniture; + +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.plugin.Event; + +public class FurnitureStackHeightEvent extends Event { + + public final short x; + public final short y; + public final Room room; + private boolean pluginHelper; + + public FurnitureStackHeightEvent(short x, short y, Room room) { + this.x = x; + this.y = y; + this.room = room; + this.pluginHelper = false; + } + + public void setPluginHelper(boolean helper) { + this.pluginHelper = helper; + } + + public boolean hasPluginHelper() { + return this.pluginHelper; + } +} From 3600a8f53ce92200910a0bf15df0407f961f2674 Mon Sep 17 00:00:00 2001 From: ArpyAge Date: Thu, 3 Sep 2020 22:07:45 +0200 Subject: [PATCH 2/3] updated getStackHeight so it's the same as the devbuild --- .../com/eu/habbo/habbohotel/rooms/Room.java | 53 +++++++++---------- .../furniture/FurnitureStackHeightEvent.java | 10 ++++ 2 files changed, 35 insertions(+), 28 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 8ccbcc72..9625ce26 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -3542,43 +3542,40 @@ public class Room implements Comparable, ISerialize, Runnable { } public double getStackHeight(short x, short y, boolean calculateHeightmap, HabboItem exclude) { + if (x < 0 || y < 0 || this.layout == null) return calculateHeightmap ? Short.MAX_VALUE : 0.0; + boolean pluginHelper = false; + if (Emulator.getPluginManager().isRegistered(FurnitureStackHeightEvent.class, true)) { + FurnitureStackHeightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureStackHeightEvent(x, y, this)); + if(event.hasPluginHelper()) { + return calculateHeightmap ? event.getHeight() * 256.0D : event.getHeight(); + } + } + double height = this.layout.getHeightAtSquare(x, y); boolean canStack = true; - boolean stackHelper = false; - THashSet items = this.getItemsAt(x, y); - if (items != null) { - for (HabboItem item : items) { + + THashSet stackHelpers = this.getItemsAt(InteractionStackHelper.class, x, y); + + if(stackHelpers.size() > 0) { + for(HabboItem item : stackHelpers) { if (item == exclude) continue; - - if (item instanceof InteractionStackHelper) { - stackHelper = true; - height = item.getExtradata().isEmpty() ? Double.valueOf("0.0") : (Double.valueOf(item.getExtradata()) / 100); - canStack = true; - } + return calculateHeightmap ? item.getZ() * 256.0D : item.getZ(); } + } - boolean pluginHelper = false; - if (Emulator.getPluginManager().isRegistered(FurnitureStackHeightEvent.class, true)) { - FurnitureStackHeightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureStackHeightEvent(x, y, this)); - stackHelper = event.hasPluginHelper(); - } + HabboItem item = this.getTopItemAt(x, y, exclude); + if (item != null) { + canStack = item.getBaseItem().allowStack(); + height = item.getZ() + Item.getCurrentHeight(item); + } - if (!stackHelper && !pluginHelper) { - HabboItem item = this.getTopItemAt(x, y, exclude); - if (item != null) { - canStack = item.getBaseItem().allowStack(); - height = item.getZ() + Item.getCurrentHeight(item); - } - - HabboItem lowestChair = this.getLowestChair(x, y); - if (lowestChair != null && lowestChair != exclude) { - canStack = true; - height = lowestChair.getZ() + Item.getCurrentHeight(lowestChair); - } - } + HabboItem lowestChair = this.getLowestChair(x, y); + if (lowestChair != null && lowestChair != exclude) { + canStack = true; + height = lowestChair.getZ(); } if (calculateHeightmap) { diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureStackHeightEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureStackHeightEvent.java index f6359407..80bb8e82 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureStackHeightEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureStackHeightEvent.java @@ -9,12 +9,14 @@ public class FurnitureStackHeightEvent extends Event { public final short y; public final Room room; private boolean pluginHelper; + private Double height; public FurnitureStackHeightEvent(short x, short y, Room room) { this.x = x; this.y = y; this.room = room; this.pluginHelper = false; + this.height = 0.0D; } public void setPluginHelper(boolean helper) { @@ -24,4 +26,12 @@ public class FurnitureStackHeightEvent extends Event { public boolean hasPluginHelper() { return this.pluginHelper; } + + public void setHeight(Double height) { + this.height = height; + } + + public Double getHeight() { + return this.height; + } } From 86ae72c02d5e73b20ad25430023ec40724bb31b2 Mon Sep 17 00:00:00 2001 From: ArpyAge Date: Thu, 3 Sep 2020 22:08:24 +0200 Subject: [PATCH 3/3] Removed unused code --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 3 +-- 1 file changed, 1 insertion(+), 2 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 9625ce26..3ca76525 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -3545,8 +3545,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (x < 0 || y < 0 || this.layout == null) return calculateHeightmap ? Short.MAX_VALUE : 0.0; - - boolean pluginHelper = false; + if (Emulator.getPluginManager().isRegistered(FurnitureStackHeightEvent.class, true)) { FurnitureStackHeightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureStackHeightEvent(x, y, this)); if(event.hasPluginHelper()) {