From ab529344ef3fd76a334b45919c3490221d3f3803 Mon Sep 17 00:00:00 2001 From: Stankman Date: Tue, 18 Jul 2023 15:24:46 -0500 Subject: [PATCH] Separating DanceType from RoomUnit --- .../com/eu/habbo/habbohotel/rooms/Room.java | 26 ++++--------------- .../rooms/entities/items/RoomItem.java | 9 ++++--- .../rooms/entities/units/RoomUnit.java | 6 ----- .../entities/units/types/RoomAvatar.java | 17 ++++++++++++ .../com/eu/habbo/habbohotel/users/Habbo.java | 2 +- .../rooms/users/DanceMessageComposer.java | 8 +++--- 6 files changed, 33 insertions(+), 35 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 de340115..009ceaa5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1265,7 +1265,9 @@ public class Room implements Comparable, ISerialize, Runnable { update = true; } } else if (thisTile.getState() == RoomTileState.SIT && (!unit.hasStatus(RoomUnitStatus.SIT) || unit.isSitUpdate())) { - this.dance(unit, DanceType.NONE); + if(unit instanceof RoomAvatar roomAvatar) { + roomAvatar.setDance(DanceType.NONE); + } unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem)) + ""); unit.setCurrentZ(topItem.getZ()); unit.setRotation(RoomRotation.values()[topItem.getRotation()]); @@ -2852,7 +2854,7 @@ public class Room implements Comparable, ISerialize, Runnable { return; } - this.dance(habbo, DanceType.NONE); + habbo.getRoomUnit().setDance(DanceType.NONE); habbo.getRoomUnit().setCmdSitEnabled(true); habbo.getRoomUnit().setBodyRotation(RoomRotation.values()[habbo.getRoomUnit().getBodyRotation().getValue() - habbo.getRoomUnit().getBodyRotation().getValue() % 2]); habbo.getRoomUnit().setStatus(RoomUnitStatus.SIT, 0.5 + ""); @@ -3082,7 +3084,7 @@ public class Room implements Comparable, ISerialize, Runnable { habbo.getRoomUnit().setIdle(); if (habbo.getRoomUnit().getDanceType() != DanceType.NONE) { - this.dance(habbo, DanceType.NONE); + habbo.getRoomUnit().setDance(DanceType.NONE); } this.sendComposer(new SleepMessageComposer(habbo.getRoomUnit()).compose()); @@ -3096,24 +3098,6 @@ public class Room implements Comparable, ISerialize, Runnable { WiredHandler.handle(WiredTriggerType.UNIDLES, habbo.getRoomUnit(), this, new Object[]{habbo}); } - public void dance(Habbo habbo, DanceType danceType) { - this.dance(habbo.getRoomUnit(), danceType); - } - - public void dance(RoomUnit unit, DanceType danceType) { - if (unit.getDanceType() != danceType) { - boolean isDancing = !unit.getDanceType().equals(DanceType.NONE); - unit.setDanceType(danceType); - this.sendComposer(new DanceMessageComposer(unit).compose()); - - if (danceType.equals(DanceType.NONE) && isDancing) { - WiredHandler.handle(WiredTriggerType.STOPS_DANCING, unit, this, new Object[]{unit}); - } else if (!danceType.equals(DanceType.NONE) && !isDancing) { - WiredHandler.handle(WiredTriggerType.STARTS_DANCING, unit, this, new Object[]{unit}); - } - } - } - public void addToWordFilter(String word) { synchronized (this.wordFilterWords) { if (this.wordFilterWords.contains(word)) diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/items/RoomItem.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/items/RoomItem.java index 02dd89f6..e2ad56ce 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/items/RoomItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/items/RoomItem.java @@ -16,6 +16,7 @@ import com.eu.habbo.habbohotel.rooms.RoomLayout; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomTileState; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; import com.eu.habbo.habbohotel.users.DanceType; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; @@ -263,9 +264,11 @@ public abstract class RoomItem implements Runnable, IEventTriggers { WiredHandler.handle(WiredTriggerType.WALKS_ON_FURNI, roomUnit, room, new Object[]{this}); - if ((this.getBaseItem().allowSit() || this.getBaseItem().allowLay()) && !roomUnit.getDanceType().equals(DanceType.NONE)) { - roomUnit.setDanceType(DanceType.NONE); - room.sendComposer(new DanceMessageComposer(roomUnit).compose()); + if(roomUnit instanceof RoomAvatar roomAvatar) { + if ((this.getBaseItem().allowSit() || this.getBaseItem().allowLay()) && !roomAvatar.getDanceType().equals(DanceType.NONE)) { + roomAvatar.setDanceType(DanceType.NONE); + room.sendComposer(new DanceMessageComposer(roomAvatar).compose()); + } } if (!this.getBaseItem().getClothingOnWalk().isEmpty() && roomUnit.getPreviousLocation() != roomUnit.getGoalLocation() && roomUnit.getGoalLocation() == room.getLayout().getTile(this.x, this.y)) { diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnit.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnit.java index 6556c9ff..bdc11e53 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnit.java @@ -11,7 +11,6 @@ import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; import com.eu.habbo.habbohotel.rooms.entities.RoomEntity; import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; -import com.eu.habbo.habbohotel.users.DanceType; import com.eu.habbo.plugin.Event; import com.eu.habbo.plugin.events.roomunit.RoomUnitLookAtPointEvent; import com.eu.habbo.plugin.events.roomunit.RoomUnitSetGoalEvent; @@ -103,9 +102,6 @@ public abstract class RoomUnit extends RoomEntity { private boolean invisible = false; @Setter private boolean canLeaveRoomByDoor = true; - @Getter - @Setter - private DanceType danceType; private int walkTimeOut; private int previousEffectId; private int previousEffectEndTimestamp; @@ -135,7 +131,6 @@ public abstract class RoomUnit extends RoomEntity { this.timeInRoom = 0; //RoomAvatar - this.danceType = DanceType.NONE; this.previousEffectId = 0; this.previousEffectEndTimestamp = -1; @@ -425,7 +420,6 @@ public abstract class RoomUnit extends RoomEntity { this.fastWalkEnabled = false; this.cmdTeleportEnabled = false; this.clearStatuses(); - this.danceType = DanceType.NONE; this.previousEffectId = 0; this.previousEffectEndTimestamp = -1; this.isKicked = false; diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomAvatar.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomAvatar.java index b4eeb770..a0a8989c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomAvatar.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomAvatar.java @@ -11,6 +11,9 @@ import com.eu.habbo.habbohotel.rooms.entities.items.types.RoomFloorItem; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.DanceType; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; +import com.eu.habbo.messages.outgoing.rooms.users.DanceMessageComposer; import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import com.eu.habbo.plugin.Event; import com.eu.habbo.plugin.events.users.UserIdleEvent; @@ -275,6 +278,20 @@ public class RoomAvatar extends RoomUnit { return false; } } + + public void setDance(DanceType danceType) { + if (this.danceType != danceType) { + boolean isDancing = !this.danceType.equals(DanceType.NONE); + this.danceType = danceType; + this.getRoom().sendComposer(new DanceMessageComposer(this).compose()); + + if (danceType.equals(DanceType.NONE) && isDancing) { + WiredHandler.handle(WiredTriggerType.STOPS_DANCING, this, this.getRoom(), new Object[]{this}); + } else if (!danceType.equals(DanceType.NONE) && !isDancing) { + WiredHandler.handle(WiredTriggerType.STARTS_DANCING, this, this.getRoom(), new Object[]{this}); + } + } + } public RoomAvatar setHandItem(int handItem) { this.handItem = handItem; diff --git a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java index 3eac30f3..35889c5a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java @@ -468,7 +468,7 @@ public class Habbo extends Unit implements Runnable { AchievementManager.progressAchievement(target, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RespectEarned")); this.client.getHabbo().getRoomUnit().getRoom().unIdle(this.client.getHabbo()); - this.client.getHabbo().getRoomUnit().getRoom().dance(this.client.getHabbo().getRoomUnit(), DanceType.NONE); + this.client.getHabbo().getRoomUnit().setDance(DanceType.NONE); } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/DanceMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/DanceMessageComposer.java index fbac4cf0..92a28ac1 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/DanceMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/DanceMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.users; -import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,14 +8,14 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class DanceMessageComposer extends MessageComposer { - private final RoomUnit roomUnit; + private final RoomAvatar roomAvatar; @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.danceMessageComposer); - this.response.appendInt(this.roomUnit.getVirtualId()); - this.response.appendInt(this.roomUnit.getDanceType().getType()); + this.response.appendInt(this.roomAvatar.getVirtualId()); + this.response.appendInt(this.roomAvatar.getDanceType().getType()); return this.response; } }