From 58ca14e287a1c8a5a832eb1902cf94dfd8b1c039 Mon Sep 17 00:00:00 2001
From: duckietm
Date: Wed, 7 Jan 2026 10:46:38 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=86=99=20=20Start=20of=20Beta?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../main/java/com/eu/habbo/core/Easter.java | 2 +-
.../eu/habbo/core/RoomUserPetComposer.java | 3 -
.../eu/habbo/crypto/HabboDiffieHellman.java | 4 +-
.../eu/habbo/habbohotel/GameEnvironment.java | 12 +-
.../achievements/AchievementManager.java | 8 +-
.../com/eu/habbo/habbohotel/bots/Bot.java | 38 +-
.../eu/habbo/habbohotel/bots/ButlerBot.java | 7 +-
.../campaign/calendar/CalendarManager.java | 4 +-
.../habbo/habbohotel/catalog/CatalogPage.java | 2 +-
.../catalog/marketplace/MarketPlace.java | 21 +-
.../catalog/marketplace/MarketPlaceOffer.java | 4 +-
.../habbohotel/commands/AboutCommand.java | 2 +-
.../habbohotel/commands/CommandHandler.java | 5 +-
.../habbohotel/commands/InvisibleCommand.java | 5 +-
.../habbohotel/commands/PetInfoCommand.java | 5 +-
.../habbohotel/commands/PixelCommand.java | 6 +-
.../habbohotel/commands/RedeemCommand.java | 2 +-
.../habbohotel/commands/SetSpeedCommand.java | 17 +-
.../habbohotel/commands/TestCommand.java | 4 +-
.../commands/UpdateChatBubblesCommand.java | 20 +
.../habbohotel/gameclients/GameClient.java | 38 +-
.../com/eu/habbo/habbohotel/games/Game.java | 10 +-
.../eu/habbo/habbohotel/games/GamePlayer.java | 7 +-
.../games/football/FootballGame.java | 2 +-
.../hotelview/HallOfFameWinner.java | 8 +-
.../habbo/habbohotel/items/ItemManager.java | 31 +-
.../eu/habbo/habbohotel/items/SoundTrack.java | 12 +-
.../habbohotel/items/YoutubeManager.java | 5 +-
.../InteractionBackgroundToner.java | 8 +-
.../interactions/InteractionBuildArea.java | 2 +-
.../items/interactions/InteractionCannon.java | 45 +-
.../interactions/InteractionCrackable.java | 2 +-
.../interactions/InteractionDefault.java | 3 +-
.../interactions/InteractionEffectTile.java | 5 +-
.../InteractionEffectVendingMachine.java | 3 +-
.../interactions/InteractionMuteArea.java | 2 +-
.../interactions/InteractionObstacle.java | 2 +-
.../interactions/InteractionOneWayGate.java | 7 +-
.../interactions/InteractionVoteCounter.java | 2 +-
.../items/interactions/InteractionWater.java | 3 +-
.../items/interactions/InteractionWired.java | 94 +-
.../InteractionWiredCondition.java | 23 +-
.../interactions/InteractionWiredEffect.java | 141 +-
.../InteractionWiredHighscore.java | 5 +-
.../interactions/InteractionWiredTrigger.java | 44 +-
.../games/InteractionGameTimer.java | 13 +-
.../InteractionBattleBanzaiTeleporter.java | 41 +-
.../gates/InteractionBattleBanzaiGate.java | 2 +-
.../games/football/InteractionFootball.java | 2 +-
.../freeze/gates/InteractionFreezeGate.java | 2 +-
.../interfaces/ConditionalGate.java | 2 +-
.../WiredConditionDateRangeActive.java | 15 +-
.../WiredConditionFurniHaveFurni.java | 40 +-
.../WiredConditionFurniHaveHabbo.java | 59 +-
.../WiredConditionFurniTypeMatch.java | 28 +-
.../conditions/WiredConditionGroupMember.java | 11 +-
.../conditions/WiredConditionHabboCount.java | 17 +-
.../WiredConditionHabboHasEffect.java | 21 +-
.../WiredConditionHabboHasHandItem.java | 16 +-
.../WiredConditionHabboWearsBadge.java | 17 +-
.../WiredConditionLessTimeElapsed.java | 15 +-
.../WiredConditionMatchStatePosition.java | 20 +-
.../WiredConditionMoreTimeElapsed.java | 15 +-
.../WiredConditionMovementValidation.java | 124 +
.../WiredConditionNotFurniHaveFurni.java | 40 +-
.../WiredConditionNotFurniHaveHabbo.java | 35 +-
.../WiredConditionNotFurniTypeMatch.java | 28 +-
.../WiredConditionNotHabboCount.java | 17 +-
.../WiredConditionNotHabboHasEffect.java | 16 +-
.../WiredConditionNotHabboWearsBadge.java | 17 +-
.../conditions/WiredConditionNotInGroup.java | 11 +-
.../conditions/WiredConditionNotInTeam.java | 17 +-
.../WiredConditionNotMatchStatePosition.java | 9 +-
.../WiredConditionNotTriggerOnFurni.java | 12 +-
.../conditions/WiredConditionTeamMember.java | 17 +-
.../WiredConditionTriggerOnFurni.java | 20 +-
.../wired/effects/WiredEffectAlert.java | 12 +-
.../wired/effects/WiredEffectBotClothes.java | 18 +-
.../effects/WiredEffectBotFollowHabbo.java | 20 +-
.../effects/WiredEffectBotGiveHandItem.java | 22 +-
.../wired/effects/WiredEffectBotTalk.java | 24 +-
.../effects/WiredEffectBotTalkToHabbo.java | 26 +-
.../wired/effects/WiredEffectBotTeleport.java | 39 +-
.../effects/WiredEffectBotWalkToFurni.java | 24 +-
.../WiredEffectChangeFurniDirection.java | 54 +-
.../wired/effects/WiredEffectGiveEffect.java | 15 +-
.../effects/WiredEffectGiveHandItem.java | 8 +-
...redEffectGiveHotelviewBonusRarePoints.java | 19 +-
.../WiredEffectGiveHotelviewHofPoints.java | 19 +-
.../wired/effects/WiredEffectGiveRespect.java | 22 +-
.../wired/effects/WiredEffectGiveReward.java | 105 +-
.../wired/effects/WiredEffectGiveScore.java | 24 +-
.../effects/WiredEffectGiveScoreToTeam.java | 18 +-
.../wired/effects/WiredEffectJoinTeam.java | 18 +-
.../wired/effects/WiredEffectKickHabbo.java | 25 +-
.../wired/effects/WiredEffectLeaveTeam.java | 18 +-
.../wired/effects/WiredEffectMatchFurni.java | 40 +-
.../effects/WiredEffectMoveFurniAway.java | 74 +-
.../wired/effects/WiredEffectMoveFurniTo.java | 81 +-
.../effects/WiredEffectMoveFurniTowards.java | 96 +-
.../effects/WiredEffectMoveRotateFurni.java | 95 +-
.../wired/effects/WiredEffectMuteHabbo.java | 21 +-
.../wired/effects/WiredEffectResetTimers.java | 16 +-
.../wired/effects/WiredEffectTeleport.java | 38 +-
.../wired/effects/WiredEffectToggleFurni.java | 20 +-
.../effects/WiredEffectToggleRandom.java | 100 +-
.../effects/WiredEffectTriggerStacks.java | 88 +-
.../wired/effects/WiredEffectWhisper.java | 26 +-
.../interactions/wired/extra/WiredBlob.java | 2 +-
.../wired/extra/WiredExtraOrEval.java | 2 +-
.../wired/extra/WiredExtraRandom.java | 2 +-
.../wired/extra/WiredExtraUnseen.java | 83 +-
.../InteractionWiredMatchFurniSettings.java | 8 +-
.../wired/triggers/WiredTriggerAtSetTime.java | 99 +-
.../triggers/WiredTriggerAtTimeLong.java | 100 +-
.../triggers/WiredTriggerBotReachedFurni.java | 30 +-
.../triggers/WiredTriggerBotReachedHabbo.java | 18 +-
.../wired/triggers/WiredTriggerCollision.java | 15 +-
.../WiredTriggerFurniStateToggled.java | 31 +-
.../wired/triggers/WiredTriggerGameEnds.java | 10 +-
.../triggers/WiredTriggerGameStarts.java | 10 +-
.../triggers/WiredTriggerHabboEntersRoom.java | 18 +-
.../WiredTriggerHabboSaysKeyword.java | 27 +-
.../WiredTriggerHabboWalkOffFurni.java | 31 +-
.../WiredTriggerHabboWalkOnFurni.java | 31 +-
.../wired/triggers/WiredTriggerRepeater.java | 97 +-
.../triggers/WiredTriggerRepeaterLong.java | 89 +-
.../triggers/WiredTriggerScoreAchieved.java | 17 +-
.../wired/triggers/WiredTriggerTeamLoses.java | 2 +-
.../wired/triggers/WiredTriggerTeamWins.java | 2 +-
.../messenger/MessengerCategory.java | 2 +-
.../habbo/habbohotel/modtool/ModToolBan.java | 2 +-
.../habbohotel/navigation/EventCategory.java | 6 +-
.../navigation/NavigatorSavedSearch.java | 4 +-
.../permissions/PermissionsManager.java | 5 +-
.../eu/habbo/habbohotel/permissions/Rank.java | 3 +-
.../habbohotel/pets/MonsterplantPet.java | 5 +-
.../com/eu/habbo/habbohotel/polls/Poll.java | 2 +-
.../habbo/habbohotel/polls/PollQuestion.java | 2 +-
.../com/eu/habbo/habbohotel/rooms/Room.java | 7370 ++++++-----------
.../habbo/habbohotel/rooms/RoomCategory.java | 18 +-
.../rooms/RoomChatBubbleManager.java | 38 +
.../habbohotel/rooms/RoomChatManager.java | 642 ++
.../habbohotel/rooms/RoomChatMessage.java | 31 +-
.../rooms/RoomChatMessageBubbles.java | 217 +-
.../habbohotel/rooms/RoomCycleManager.java | 486 ++
.../habbohotel/rooms/RoomGameManager.java | 96 +
.../habbohotel/rooms/RoomItemManager.java | 1629 ++++
.../eu/habbo/habbohotel/rooms/RoomLayout.java | 1032 +--
.../habbo/habbohotel/rooms/RoomManager.java | 48 +-
.../rooms/RoomMessagingManager.java | 83 +
.../rooms/RoomPromotionManager.java | 127 +
.../habbohotel/rooms/RoomRightsManager.java | 433 +
.../habbohotel/rooms/RoomRollerManager.java | 377 +
.../habbohotel/rooms/RoomSpecialTypes.java | 562 +-
.../eu/habbo/habbohotel/rooms/RoomTile.java | 92 +-
.../habbohotel/rooms/RoomTileManager.java | 481 ++
.../eu/habbo/habbohotel/rooms/RoomTrade.java | 9 +-
.../habbohotel/rooms/RoomTradeManager.java | 61 +
.../eu/habbo/habbohotel/rooms/RoomUnit.java | 1504 ++--
.../habbohotel/rooms/RoomUnitManager.java | 1360 +++
.../habbohotel/rooms/RoomUserRotation.java | 5 +
.../habbohotel/rooms/RoomWordQuizManager.java | 124 +
.../rooms/pathfinding/Pathfinder.java | 74 +
.../pathfinding/impl/AdjacentTileFinder.java | 176 +
.../pathfinding/impl/PathFinderException.java | 7 +
.../pathfinding/impl/PathfinderConstants.java | 16 +
.../pathfinding/impl/PathfinderContext.java | 85 +
.../pathfinding/impl/PathfinderImpl.java | 240 +
.../rooms/pathfinding/impl/Rotation.java | 20 +
.../rooms/pathfinding/impl/TileValidator.java | 73 +
.../eu/habbo/habbohotel/users/HabboBadge.java | 2 +-
.../eu/habbo/habbohotel/users/HabboStats.java | 14 +-
.../users/cache/HabboOfferPurchase.java | 3 -
.../subscriptions/SubscriptionHabboClub.java | 28 +-
.../habbohotel/wired/WiredConditionType.java | 3 +-
.../habbohotel/wired/api/IWiredCondition.java | 58 +
.../habbohotel/wired/api/IWiredEffect.java | 102 +
.../habbohotel/wired/api/IWiredTrigger.java | 72 +
.../habbohotel/wired/api/WiredStack.java | 188 +
.../wired/core/DefaultWiredServices.java | 351 +
.../wired/core/RoomWiredStackIndex.java | 235 +
.../habbohotel/wired/core/WiredContext.java | 319 +
.../habbohotel/wired/core/WiredEngine.java | 736 ++
.../habbohotel/wired/core/WiredEvent.java | 337 +
.../wired/core/WiredLimitException.java | 41 +
.../habbohotel/wired/core/WiredManager.java | 860 ++
.../habbohotel/wired/core/WiredServices.java | 260 +
.../wired/core/WiredSimulation.java | 202 +
.../wired/core/WiredStackIndex.java | 77 +
.../habbohotel/wired/core/WiredState.java | 167 +
.../habbohotel/wired/core/WiredTargets.java | 198 +
.../habbohotel/wired/migrate/WiredEvents.java | 357 +
.../wired/tick/WiredTickService.java | 464 ++
.../habbohotel/wired/tick/WiredTickable.java | 99 +
.../catalog/CatalogBuyItemAsGiftEvent.java | 32 +-
.../catalog/CatalogSelectClubGiftEvent.java | 2 +-
.../catalog/marketplace/SellItemEvent.java | 2 +-
.../FloorPlanEditorSaveEvent.java | 5 +-
.../incoming/friends/FriendRequestEvent.java | 4 +-
.../guilds/GuildAcceptMembershipEvent.java | 2 +
.../guilds/GuildChangeBadgeEvent.java | 2 +-
.../incoming/guilds/RequestGuildBuyEvent.java | 2 +-
.../CompleteDiffieHandshakeEvent.java | 2 +-
.../incoming/handshake/SecureLoginEvent.java | 8 +-
.../navigator/RequestDeleteRoomEvent.java | 3 +-
.../incoming/rooms/RequestHeightmapEvent.java | 6 +-
.../incoming/rooms/RequestRoomDataEvent.java | 7 +
.../rooms/RequestRoomHeightmapEvent.java | 15 +-
.../incoming/rooms/RequestRoomLoadEvent.java | 15 +
.../incoming/rooms/RoomBackgroundEvent.java | 2 +-
.../incoming/rooms/RoomSettingsSaveEvent.java | 9 +-
.../rooms/items/PostItSaveDataEvent.java | 7 +-
.../rooms/items/RoomPlaceItemEvent.java | 5 +-
.../rooms/items/ToggleFloorItemEvent.java | 2 +-
.../rooms/items/UseRandomStateItemEvent.java | 3 +-
.../youtube/YoutubeRequestPlaylistChange.java | 2 +-
.../youtube/YoutubeRequestPlaylists.java | 5 +-
.../youtube/YoutubeRequestStateChange.java | 6 +-
.../rooms/pets/HorseRemoveSaddleEvent.java | 4 +-
.../incoming/rooms/pets/PetPickupEvent.java | 3 +-
.../incoming/rooms/pets/PetRideEvent.java | 4 +-
.../rooms/pets/PetRideSettingsEvent.java | 4 +-
.../incoming/rooms/pets/PetUseItemEvent.java | 12 +-
.../rooms/users/RoomUserGiveRespectEvent.java | 4 +
.../rooms/users/RoomUserWalkEvent.java | 310 +-
.../wired/WiredApplySetConditionsEvent.java | 4 +-
.../wired/WiredConditionSaveDataEvent.java | 7 +
.../wired/WiredEffectSaveDataEvent.java | 7 +
.../wired/WiredTriggerSaveDataEvent.java | 7 +
.../achievements/AchievementListComposer.java | 2 +-
.../catalog/RecyclerLogicComposer.java | 2 +-
.../friends/UpdateFriendComposer.java | 14 +-
.../GuildConfirmRemoveMemberComposer.java | 4 +-
.../guilds/GuildEditFailComposer.java | 2 +-
.../GuildFavoriteRoomUserUpdateComposer.java | 4 +-
.../guilds/RemoveGuildFromRoomComposer.java | 2 +-
.../inventory/InventoryItemsComposer.java | 2 +-
.../modtool/ModToolUserInfoComposer.java | 5 +-
.../rooms/items/FloorItemUpdateComposer.java | 2 +-
.../rooms/users/RoomUnitOnRollerComposer.java | 41 +-
.../rooms/users/RoomUserActionComposer.java | 4 +-
.../rooms/users/RoomUserDataComposer.java | 9 +-
.../RoomUserReceivedHandItemComposer.java | 4 +-
.../rooms/users/RoomUserShoutComposer.java | 2 +-
.../outgoing/users/UserProfileComposer.java | 2 +-
.../camera/CameraOutgoingMessage.java | 4 +-
.../com/eu/habbo/plugin/PluginManager.java | 83 +-
.../threading/runnables/BotFollowHabbo.java | 5 +-
.../threading/runnables/CannonKickAction.java | 11 +-
.../runnables/GuardianVotingFinish.java | 2 +-
.../threading/runnables/KickBallAction.java | 2 +-
.../runnables/OneWayGateActionOne.java | 6 +-
.../threading/runnables/PetEatAction.java | 2 +-
.../runnables/QueryDeleteHabboBadge.java | 2 +-
.../runnables/QueryDeleteHabboItems.java | 2 +-
.../threading/runnables/RandomDiceNumber.java | 2 +-
.../threading/runnables/RoomUnitRidePet.java | 6 +-
.../threading/runnables/RoomUnitTeleport.java | 11 +-
.../runnables/RoomUnitWalkToLocation.java | 18 +-
.../runnables/RoomUnitWalkToRoomUnit.java | 15 +-
.../runnables/WiredCollissionRunnable.java | 14 +-
.../runnables/WiredRepeatEffectTask.java | 13 +-
.../threading/runnables/WiredResetTimers.java | 16 +-
.../threading/runnables/YouAreAPirate.java | 2 +-
.../runnables/hopper/HopperActionThree.java | 1 +
.../teleport/TeleportActionFive.java | 8 +-
.../teleport/TeleportActionFour.java | 2 +
.../runnables/teleport/TeleportActionOne.java | 6 +-
.../teleport/TeleportActionThree.java | 6 +-
.../runnables/teleport/TeleportActionTwo.java | 6 +-
.../main/java/com/eu/habbo/util/HexUtils.java | 2 +-
.../com/eu/habbo/util/figure/FigureUtil.java | 2 +-
273 files changed, 18831 insertions(+), 8076 deletions(-)
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/commands/UpdateChatBubblesCommand.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMovementValidation.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomChatBubbleManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomChatManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomCycleManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomGameManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomItemManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomMessagingManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomPromotionManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRollerManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTileManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTradeManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomWordQuizManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/pathfinding/Pathfinder.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/pathfinding/impl/AdjacentTileFinder.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/pathfinding/impl/PathFinderException.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/pathfinding/impl/PathfinderConstants.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/pathfinding/impl/PathfinderContext.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/pathfinding/impl/PathfinderImpl.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/pathfinding/impl/Rotation.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/pathfinding/impl/TileValidator.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/api/IWiredCondition.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/api/IWiredEffect.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/api/IWiredTrigger.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/api/WiredStack.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/DefaultWiredServices.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/RoomWiredStackIndex.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredContext.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredEngine.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredEvent.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredLimitException.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredManager.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredServices.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredSimulation.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredStackIndex.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredState.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredTargets.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/migrate/WiredEvents.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/tick/WiredTickService.java
create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/tick/WiredTickable.java
diff --git a/Emulator/src/main/java/com/eu/habbo/core/Easter.java b/Emulator/src/main/java/com/eu/habbo/core/Easter.java
index aa110823..f358dbc8 100644
--- a/Emulator/src/main/java/com/eu/habbo/core/Easter.java
+++ b/Emulator/src/main/java/com/eu/habbo/core/Easter.java
@@ -9,7 +9,7 @@ import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer;
import com.eu.habbo.plugin.EventHandler;
import com.eu.habbo.plugin.events.users.UserSavedMottoEvent;
-public final class Easter {
+public class Easter {
@EventHandler
public static void onUserChangeMotto(UserSavedMottoEvent event) {
if (Emulator.getConfig().getBoolean("easter_eggs.enabled") && event.newMotto.equalsIgnoreCase("crickey!")) {
diff --git a/Emulator/src/main/java/com/eu/habbo/core/RoomUserPetComposer.java b/Emulator/src/main/java/com/eu/habbo/core/RoomUserPetComposer.java
index d1bf6a75..d593d1ff 100644
--- a/Emulator/src/main/java/com/eu/habbo/core/RoomUserPetComposer.java
+++ b/Emulator/src/main/java/com/eu/habbo/core/RoomUserPetComposer.java
@@ -25,9 +25,6 @@ public class RoomUserPetComposer extends MessageComposer {
this.response.appendInt(this.habbo.getHabboInfo().getId());
this.response.appendString(this.habbo.getHabboInfo().getUsername());
this.response.appendString("");
- this.response.appendInt(0);
- this.response.appendInt(0);
- this.response.appendInt(0);
this.response.appendString(this.petType + " " + this.race + " " + this.color + " 2 2 -1 0 3 -1 0");
this.response.appendInt(this.habbo.getRoomUnit().getId());
this.response.appendInt(this.habbo.getRoomUnit().getX());
diff --git a/Emulator/src/main/java/com/eu/habbo/crypto/HabboDiffieHellman.java b/Emulator/src/main/java/com/eu/habbo/crypto/HabboDiffieHellman.java
index 25fb761b..f9db196d 100644
--- a/Emulator/src/main/java/com/eu/habbo/crypto/HabboDiffieHellman.java
+++ b/Emulator/src/main/java/com/eu/habbo/crypto/HabboDiffieHellman.java
@@ -88,11 +88,11 @@ public class HabboDiffieHellman {
}
if (this.DHPrime.compareTo(BigInteger.valueOf(2)) < 1) {
- throw new HabboCryptoException("Prime cannot be <= 2!\nPrime: " + this.DHPrime);
+ throw new HabboCryptoException("Prime cannot be <= 2!\nPrime: " + this.DHPrime.toString());
}
if (this.DHGenerator.compareTo(this.DHPrime) > -1) {
- throw new HabboCryptoException("Generator cannot be >= Prime!\nPrime: " + this.DHPrime + "\nGenerator: " + this.DHGenerator.toString());
+ throw new HabboCryptoException("Generator cannot be >= Prime!\nPrime: " + this.DHPrime.toString() + "\nGenerator: " + this.DHGenerator.toString());
}
generateDHKeys();
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java
index 9cff9140..879e2d6b 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java
@@ -1,10 +1,7 @@
package com.eu.habbo.habbohotel;
import com.eu.habbo.Emulator;
-import com.eu.habbo.core.CreditsScheduler;
-import com.eu.habbo.core.GotwPointsScheduler;
-import com.eu.habbo.core.PixelScheduler;
-import com.eu.habbo.core.PointsScheduler;
+import com.eu.habbo.core.*;
import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.bots.BotManager;
import com.eu.habbo.habbohotel.campaign.calendar.CalendarManager;
@@ -22,6 +19,7 @@ import com.eu.habbo.habbohotel.navigation.NavigatorManager;
import com.eu.habbo.habbohotel.permissions.PermissionsManager;
import com.eu.habbo.habbohotel.pets.PetManager;
import com.eu.habbo.habbohotel.polls.PollManager;
+import com.eu.habbo.habbohotel.rooms.RoomChatBubbleManager;
import com.eu.habbo.habbohotel.rooms.RoomManager;
import com.eu.habbo.habbohotel.users.HabboManager;
import com.eu.habbo.habbohotel.users.subscriptions.SubscriptionManager;
@@ -59,6 +57,7 @@ public class GameEnvironment {
private PollManager pollManager;
private SubscriptionManager subscriptionManager;
private CalendarManager calendarManager;
+ private RoomChatBubbleManager roomChatBubbleManager;
public void load() throws Exception {
LOGGER.info("GameEnvironment -> Loading...");
@@ -84,6 +83,7 @@ public class GameEnvironment {
this.craftingManager = new CraftingManager();
this.pollManager = new PollManager();
this.calendarManager = new CalendarManager();
+ this.roomChatBubbleManager = new RoomChatBubbleManager();
this.roomManager.loadPublicRooms();
this.navigatorManager.loadNavigator();
@@ -215,4 +215,8 @@ public class GameEnvironment {
}
public CalendarManager getCalendarManager() { return this.calendarManager; }
+
+ public RoomChatBubbleManager getRoomChatBubbleManager() {
+ return roomChatBubbleManager;
+ }
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java
index b8c45589..ff3700c4 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java
@@ -50,7 +50,8 @@ public class AchievementManager {
progressAchievement(habbo, achievement, amount);
} else {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
- PreparedStatement statement = connection.prepareStatement("INSERT INTO users_achievements_queue (user_id, achievement_id, amount) VALUES (?, ?, ?) " +
+ PreparedStatement statement = connection.prepareStatement("" +
+ "INSERT INTO users_achievements_queue (user_id, achievement_id, amount) VALUES (?, ?, ?) " +
"ON DUPLICATE KEY UPDATE amount = amount + ?")) {
statement.setInt(1, habboId);
statement.setInt(2, achievement.id);
@@ -360,7 +361,7 @@ public class AchievementManager {
}
}
- if (level.badges != null) {
+ if (level.badges != null && level.badges.length > 0) {
for (String badge : level.badges) {
if (!badge.isEmpty()) {
if (!habbo.getInventory().getBadgesComponent().hasBadge(badge)) {
@@ -373,11 +374,10 @@ public class AchievementManager {
}
}
- if (level.perks != null) {
+ if (level.perks != null && level.perks.length > 0) {
for (String perk : level.perks) {
if (perk.equalsIgnoreCase("TRADE")) {
habbo.getHabboStats().perkTrade = true;
- break;
}
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java
index 4c0c11e9..7f0a8df2 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java
@@ -4,8 +4,7 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.outgoing.rooms.users.*;
import com.eu.habbo.plugin.events.bots.BotChatEvent;
import com.eu.habbo.plugin.events.bots.BotShoutEvent;
@@ -21,7 +20,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
public class Bot implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(Bot.class);
@@ -113,7 +111,7 @@ public class Bot implements Runnable {
this.chatRandom = false;
this.chatDelay = 10;
this.chatTimeOut = Emulator.getIntUnixTimestamp() + this.chatDelay;
- this.chatLines = new ArrayList<>(List.of("Default Message :D"));
+ this.chatLines = new ArrayList<>(Arrays.asList("Default Message :D"));
this.type = bot.getType();
this.effect = bot.getEffect();
this.bubble = bot.getBubbleId();
@@ -140,26 +138,30 @@ public class Bot implements Runnable {
@Override
public void run() {
if (this.needsUpdate) {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE bots SET name = ?, motto = ?, figure = ?, gender = ?, user_id = ?, room_id = ?, dance = ?, freeroam = ?, chat_lines = ?, chat_auto = ?, chat_random = ?, chat_delay = ?, effect = ?, bubble_id = ? WHERE id = ?")) {
+ try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE bots SET name = ?, motto = ?, figure = ?, gender = ?, user_id = ?, room_id = ?, x = ?, y = ?, z = ?, rot = ?, dance = ?, freeroam = ?, chat_lines = ?, chat_auto = ?, chat_random = ?, chat_delay = ?, effect = ?, bubble_id = ? WHERE id = ?")) {
statement.setString(1, this.name);
statement.setString(2, this.motto);
statement.setString(3, this.figure);
statement.setString(4, this.gender.toString());
statement.setInt(5, this.ownerId);
statement.setInt(6, this.room == null ? 0 : this.room.getId());
- statement.setInt(7, this.roomUnit == null ? 0 : this.roomUnit.getDanceType().getType());
- statement.setString(8, this.canWalk ? "1" : "0");
+ statement.setInt(7, this.roomUnit == null ? 0 : this.roomUnit.getX());
+ statement.setInt(8, this.roomUnit == null ? 0 : this.roomUnit.getY());
+ statement.setDouble(9, this.roomUnit == null ? 0 : this.roomUnit.getZ());
+ statement.setInt(10, this.roomUnit == null ? 0 : this.roomUnit.getBodyRotation().getValue());
+ statement.setInt(11, this.roomUnit == null ? 0 : this.roomUnit.getDanceType().getType());
+ statement.setString(12, this.canWalk ? "1" : "0");
StringBuilder text = new StringBuilder();
for (String s : this.chatLines) {
text.append(s).append("\r");
}
- statement.setString(9, text.toString());
- statement.setString(10, this.chatAuto ? "1" : "0");
- statement.setString(11, this.chatRandom ? "1" : "0");
- statement.setInt(12, this.chatDelay);
- statement.setInt(13, this.effect);
- statement.setInt(14, this.bubble);
- statement.setInt(15, this.id);
+ statement.setString(13, text.toString());
+ statement.setString(14, this.chatAuto ? "1" : "0");
+ statement.setString(15, this.chatRandom ? "1" : "0");
+ statement.setInt(16, this.chatDelay);
+ statement.setInt(17, this.effect);
+ statement.setInt(18, this.bubble);
+ statement.setInt(19, this.id);
statement.execute();
this.needsUpdate = false;
} catch (SQLException e) {
@@ -177,7 +179,7 @@ public class Bot implements Runnable {
Bot.BOT_LIMIT_WALKING_DISTANCE
? this.room.getRandomWalkableTilesAround(
this.getRoomUnit(),
- this.room.getLayout().getTile(this.roomUnit.getX(), this.roomUnit.getY()),
+ this.room.getLayout().getTile(this.roomUnit.getBotStartLocation().x, this.roomUnit.getBotStartLocation().y),
Bot.BOT_WALKING_DISTANCE_RADIUS)
: this.room.getRandomWalkableTile()
);
@@ -187,7 +189,7 @@ public class Bot implements Runnable {
}
}/* else {
for (RoomTile t : this.room.getLayout().getTilesAround(this.room.getLayout().getTile(this.getRoomUnit().getX(), this.getRoomUnit().getY()))) {
- WiredHandler.handle(WiredTriggerType.BOT_REACHED_STF, this.roomUnit, this.room, this.room.getItemsAt(t).toArray());
+ WiredManager.handle(WiredTriggerType.BOT_REACHED_STF, this.roomUnit, this.room, this.room.getItemsAt(t).toArray());
}
}*/
}
@@ -205,7 +207,7 @@ public class Bot implements Runnable {
.replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), this.room.getName())
.replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), this.room.getUserCount() + "");
- if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), room, new Object[]{ message })) {
+ if(!WiredManager.triggerUserSays(room, this.getRoomUnit(), message)) {
this.talk(message);
}
@@ -273,7 +275,7 @@ public class Bot implements Runnable {
if(PLACEMENT_MESSAGES.length > 0) {
String message = PLACEMENT_MESSAGES[Emulator.getRandom().nextInt(PLACEMENT_MESSAGES.length)];
- if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), room, new Object[]{message})) {
+ if (!WiredManager.triggerUserSays(room, this.getRoomUnit(), message)) {
this.talk(message);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java
index b5acb9f2..0ae110e2 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java
@@ -3,8 +3,7 @@ package com.eu.habbo.habbohotel.bots;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.rooms.RoomChatMessage;
import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.plugin.events.bots.BotServerItemEvent;
import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem;
import com.eu.habbo.threading.runnables.RoomUnitWalkToRoomUnit;
@@ -100,7 +99,7 @@ public class ButlerBot extends Bot {
.replace("%key%", key)
.replace("%username%", serveEvent.habbo.getHabboInfo().getUsername());
- if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{ botMessage })) {
+ if (!WiredManager.triggerUserSays(this.getRoom(), this.getRoomUnit(), botMessage)) {
bot.talk(botMessage);
}
}
@@ -128,7 +127,7 @@ public class ButlerBot extends Bot {
this.getRoom().giveHandItem(serveEvent.habbo, serveEvent.itemId);
String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", keyword).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername());
- if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) {
+ if (!WiredManager.triggerUserSays(this.getRoom(), this.getRoomUnit(), msg)) {
this.talk(msg);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java
index bfa1de13..1336f88f 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java
@@ -9,10 +9,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.*;
+import java.util.*;
import java.util.Date;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
import static java.time.temporal.ChronoUnit.DAYS;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogPage.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogPage.java
index 8a1a4865..6d36c279 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogPage.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogPage.java
@@ -71,7 +71,7 @@ public abstract class CatalogPage implements Comparable, ISerialize
if (!set.getString("includes").isEmpty()) {
for (String id : set.getString("includes").split(";")) {
try {
- this.included.add(Integer.parseInt(id));
+ this.included.add(Integer.valueOf(id));
} catch (Exception e) {
LOGGER.error("Caught exception", e);
LOGGER.error("Failed to parse includes column value of ({}) for catalog page ({})", id, this.id);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java
index 631658b3..be96d0eb 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java
@@ -26,7 +26,7 @@ import java.util.ArrayList;
import java.util.List;
-public final class MarketPlace {
+public class MarketPlace {
private static final Logger LOGGER = LoggerFactory.getLogger(MarketPlace.class);
//Configuration. Loaded from database & updated accordingly.
@@ -142,9 +142,10 @@ public final class MarketPlace {
case 2:
query += " ORDER BY minPrice ASC";
break;
- case 1:
default:
+ case 1:
query += " ORDER BY minPrice DESC";
+ break;
}
query += ")";
@@ -365,13 +366,15 @@ public final class MarketPlace {
THashSet offers = new THashSet<>();
offers.addAll(client.getHabbo().getInventory().getMarketplaceItems());
- for (MarketPlaceOffer offer : offers) {
- if (offer.getState().equals(MarketPlaceState.SOLD)) {
- client.getHabbo().getInventory().removeMarketplaceOffer(offer);
- credits += offer.getPrice();
- removeUser(offer);
- offer.needsUpdate(true);
- Emulator.getThreading().run(offer);
+ synchronized (client.getHabbo().getInventory()) {
+ for (MarketPlaceOffer offer : offers) {
+ if (offer.getState().equals(MarketPlaceState.SOLD)) {
+ client.getHabbo().getInventory().removeMarketplaceOffer(offer);
+ credits += offer.getPrice();
+ removeUser(offer);
+ offer.needsUpdate(true);
+ Emulator.getThreading().run(offer);
+ }
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlaceOffer.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlaceOffer.java
index ac5ae45f..37bd2ab1 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlaceOffer.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlaceOffer.java
@@ -16,8 +16,8 @@ public class MarketPlaceOffer implements Runnable {
public int avarage;
public int count;
private int offerId;
- private final Item baseItem;
- private final int itemId;
+ private Item baseItem;
+ private int itemId;
private int price;
private int limitedStack;
private int limitedNumber;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java
index 5c37bf39..1b5a7c2e 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java
@@ -15,7 +15,7 @@ public class AboutCommand extends Command {
}
public static String credits = "Arcturus Morningstar is an opensource project based on Arcturus By TheGeneral \n" +
"The Following people have all contributed to this emulator:\n" +
- " TheGeneral\n Beny\n Alejandro\n Capheus\n Skeletor\n Harmonic\n Mike\n Remco\n zGrav \n Quadral \n Harmony\n Swirny\n ArpyAge\n Mikkel\n Rodolfo\n Rasmus\n Kitt Mustang\n Snaiker\n nttzx\n necmi\n Dome\n Jose Flores\n Cam\n Oliver\n Narzo\n Tenshie\n MartenM\n Ridge\n SenpaiDipper\n Snaiker\n Thijmen\n DuckieTM";
+ " TheGeneral\n Beny\n Alejandro\n Capheus\n Skeletor\n Harmonic\n Mike\n Remco\n zGrav \n Quadral \n Harmony\n Swirny\n ArpyAge\n Mikkel\n Rodolfo\n Rasmus\n Kitt Mustang\n Snaiker\n nttzx\n necmi\n Dome\n Jose Flores\n Cam\n Oliver\n Narzo\n Tenshie\n MartenM\n Ridge\n SenpaiDipper\n Snaiker\n Thijmen";
@Override
public boolean handle(GameClient gameClient, String[] params) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java
index 55a6a120..08eb4f6e 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java
@@ -191,7 +191,7 @@ public class CommandHandler {
addCommand(new ControlCommand());
addCommand(new CoordsCommand());
addCommand(new CreditsCommand());
- addCommand(new DanceCommand());
+ addCommand(new DanceCommand());
addCommand(new DiagonalCommand());
addCommand(new DisconnectCommand());
addCommand(new EjectAllCommand());
@@ -231,7 +231,7 @@ public class CommandHandler {
addCommand(new MutePetsCommand());
addCommand(new PetInfoCommand());
addCommand(new PickallCommand());
- addCommand(new PingCommand());
+ addCommand(new PingCommand());
addCommand(new PixelCommand());
addCommand(new PluginsCommand());
addCommand(new PointsCommand());
@@ -296,6 +296,7 @@ public class CommandHandler {
addCommand(new AddYoutubePlaylistCommand());
addCommand(new SoftKickCommand());
addCommand(new SubscriptionCommand());
+ addCommand(new UpdateChatBubblesCommand());
addCommand(new TestCommand());
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/InvisibleCommand.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/InvisibleCommand.java
index e4337358..03ba22d1 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/InvisibleCommand.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/InvisibleCommand.java
@@ -4,8 +4,7 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.rooms.RoomLayout;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserRemoveComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer;
@@ -31,7 +30,7 @@ public class InvisibleCommand extends Command {
roomUnit.getRoom().sendComposer(new RoomUsersComposer(gameClient.getHabbo()).compose());
roomUnit.getRoom().sendComposer(new RoomUserStatusComposer(roomUnit).compose());
- WiredHandler.handle(WiredTriggerType.ENTER_ROOM, roomUnit, roomUnit.getRoom(), null);
+ WiredManager.triggerUserEntersRoom(roomUnit.getRoom(), roomUnit);
roomUnit.getRoom().habboEntered(gameClient.getHabbo());
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_invisible.updated.back"));
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/PetInfoCommand.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/PetInfoCommand.java
index 74150280..b368c11c 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/PetInfoCommand.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/PetInfoCommand.java
@@ -24,7 +24,8 @@ public class PetInfoCommand extends Command {
@Override
public boolean execute(int a, Pet pet) {
if (pet.getName().equalsIgnoreCase(name)) {
- gameClient.getHabbo().alert(Emulator.getTexts().getValue("commands.generic.cmd_pet_info.title") + ": " + pet.getName() + "\r\n" +
+ gameClient.getHabbo().alert("" +
+ Emulator.getTexts().getValue("commands.generic.cmd_pet_info.title") + ": " + pet.getName() + "\r\n" +
Emulator.getTexts().getValue("generic.pet.id") + ": " + pet.getId() + "\r" +
Emulator.getTexts().getValue("generic.pet.name") + ": " + pet.getName() + "\r" +
Emulator.getTexts().getValue("generic.pet.age") + ": " + pet.daysAlive() + " " + Emulator.getTexts().getValue("generic.pet.days.alive") + "\r" +
@@ -37,7 +38,7 @@ public class PetInfoCommand extends Command {
Emulator.getTexts().getValue("generic.pet.level.thirst") + ": " + pet.levelThirst + "\r" +
Emulator.getTexts().getValue("generic.pet.level.hunger") + ": " + pet.levelHunger + "\r" +
Emulator.getTexts().getValue("generic.pet.current_action") + ": " + (pet.getTask() == null ? Emulator.getTexts().getValue("generic.nothing") : pet.getTask().name()) + "\r" +
- Emulator.getTexts().getValue("generic.can.walk") + ": " + (pet.getRoomUnit().canWalk() ? Emulator.getTexts().getValue("generic.yes") : Emulator.getTexts().getValue("generic.no"))
+ Emulator.getTexts().getValue("generic.can.walk") + ": " + (pet.getRoomUnit().canWalk() ? Emulator.getTexts().getValue("generic.yes") : Emulator.getTexts().getValue("generic.no")) + ""
);
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/PixelCommand.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/PixelCommand.java
index 11a7eb99..327dc4e9 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/PixelCommand.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/PixelCommand.java
@@ -20,11 +20,11 @@ public class PixelCommand extends Command {
if (Integer.parseInt(params[2]) != 0) {
habbo.givePixels(Integer.parseInt(params[2]));
if (habbo.getHabboInfo().getCurrentRoom() != null)
- habbo.whisper(Emulator.getTexts().getValue("commands.generic.cmd_duckets.received").replace("%amount%", Integer.parseInt(params[2]) + ""), RoomChatMessageBubbles.ALERT);
+ habbo.whisper(Emulator.getTexts().getValue("commands.generic.cmd_duckets.received").replace("%amount%", Integer.valueOf(params[2]) + ""), RoomChatMessageBubbles.ALERT);
else
- habbo.alert(Emulator.getTexts().getValue("commands.generic.cmd_duckets.received").replace("%amount%", Integer.parseInt(params[2]) + ""));
+ habbo.alert(Emulator.getTexts().getValue("commands.generic.cmd_duckets.received").replace("%amount%", Integer.valueOf(params[2]) + ""));
- gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_duckets.send").replace("%amount%", Integer.parseInt(params[2]) + "").replace("%user%", params[1]), RoomChatMessageBubbles.ALERT);
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_duckets.send").replace("%amount%", Integer.valueOf(params[2]) + "").replace("%user%", params[1]), RoomChatMessageBubbles.ALERT);
} else {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_duckets.invalid_amount"), RoomChatMessageBubbles.ALERT);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/RedeemCommand.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/RedeemCommand.java
index 663e1f65..9f2632f3 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/RedeemCommand.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/RedeemCommand.java
@@ -85,7 +85,7 @@ public class RedeemCommand extends Command {
if (pixels > 0) {
message[0] += ", " + Emulator.getTexts().getValue("generic.pixels");
- message[0] += ": " + pixels;
+ message[0] += ": " + pixels + "";
}
if (!points.isEmpty()) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/SetSpeedCommand.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/SetSpeedCommand.java
index 46d52be9..ab9c1fe2 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/SetSpeedCommand.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/SetSpeedCommand.java
@@ -26,27 +26,14 @@ public class SetSpeedCommand extends Command {
return true;
}
- // First check against the config bounds
- int configMax = Emulator.getConfig().getInt("hotel.rollers.speed.maximum");
- if (newSpeed < -1 || newSpeed > configMax) {
+ if (newSpeed < -1 || newSpeed > Emulator.getConfig().getInt("hotel.rollers.speed.maximum")) {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_setspeed.bounds"), RoomChatMessageBubbles.ALERT);
return true;
}
- // Enforce maximum speed of 10 regardless of config.
- if (newSpeed > 10) {
- newSpeed = 10;
- gameClient.getHabbo().whisper("Speed cannot be set above 10. Setting speed to 10.", RoomChatMessageBubbles.ALERT);
- }
-
room.setRollerSpeed(newSpeed);
- gameClient.getHabbo().whisper(
- Emulator.getTexts().getValue("commands.succes.cmd_setspeed")
- .replace("%oldspeed%", oldSpeed + "")
- .replace("%newspeed%", newSpeed + ""),
- RoomChatMessageBubbles.ALERT
- );
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_setspeed").replace("%oldspeed%", oldSpeed + "").replace("%newspeed%", newSpeed + ""), RoomChatMessageBubbles.ALERT);
return true;
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/TestCommand.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/TestCommand.java
index 6c9eceab..a6fb01a8 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/TestCommand.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/TestCommand.java
@@ -31,9 +31,9 @@ public class TestCommand extends Command {
message.appendString("");
}
} else if (data[0].equals("i")) {
- message.appendInt(Integer.parseInt(data[1]));
+ message.appendInt(Integer.valueOf(data[1]));
} else if (data[0].equalsIgnoreCase("by")) {
- message.appendByte(Integer.parseInt(data[1]));
+ message.appendByte(Integer.valueOf(data[1]));
} else if (data[0].equalsIgnoreCase("sh")) {
message.appendShort(Integer.parseInt(data[1]));
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/UpdateChatBubblesCommand.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/UpdateChatBubblesCommand.java
new file mode 100644
index 00000000..d3be00ba
--- /dev/null
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/UpdateChatBubblesCommand.java
@@ -0,0 +1,20 @@
+package com.eu.habbo.habbohotel.commands;
+
+import com.eu.habbo.Emulator;
+import com.eu.habbo.habbohotel.gameclients.GameClient;
+import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
+
+public class UpdateChatBubblesCommand extends Command {
+
+ public UpdateChatBubblesCommand() {
+ super("cmd_update_chat_bubbles", Emulator.getTexts().getValue("commands.keys.cmd_update_chat_bubbles").split(";"));
+ }
+
+ @Override
+ public boolean handle(GameClient gameClient, String[] params) {
+ RoomChatMessageBubbles.removeDynamicBubbles();
+ Emulator.getGameEnvironment().getRoomChatBubbleManager().reload();
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.success.cmd_update_chat_bubbles"), RoomChatMessageBubbles.ALERT);
+ return true;
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/gameclients/GameClient.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/gameclients/GameClient.java
index 95202eb4..61c219cc 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/gameclients/GameClient.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/gameclients/GameClient.java
@@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.MessageComposer;
+import com.eu.habbo.plugin.events.emulator.OutgoingPacketEvent;
import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -20,7 +21,8 @@ public class GameClient {
private final Channel channel;
private final HabboEncryption encryption;
- private final LatencyTracker latencyTracker;
+ private final LatencyTracker latencyTracker;
+
private Habbo habbo;
private boolean handshakeFinished;
private String machineId = "";
@@ -37,7 +39,7 @@ public class GameClient {
Emulator.getCrypto().getModulus(),
Emulator.getCrypto().getPrivateExponent())
: null;
- this.latencyTracker = new LatencyTracker();
+ this.latencyTracker = new LatencyTracker();
}
public Channel getChannel() {
@@ -47,8 +49,10 @@ public class GameClient {
public HabboEncryption getEncryption() {
return encryption;
}
-
- public LatencyTracker getLatencyTracker() { return latencyTracker; }
+
+ public LatencyTracker getLatencyTracker() {
+ return latencyTracker;
+ }
public Habbo getHabbo() {
return this.habbo;
@@ -88,6 +92,17 @@ public class GameClient {
return;
}
+ OutgoingPacketEvent event = new OutgoingPacketEvent(this.habbo, response.getComposer(), response);
+ Emulator.getPluginManager().fireEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+
+ if (event.hasCustomMessage()) {
+ response = event.getCustomMessage();
+ }
+
this.channel.write(response, this.channel.voidPromise());
this.channel.flush();
}
@@ -100,14 +115,25 @@ public class GameClient {
return;
}
+ OutgoingPacketEvent event = new OutgoingPacketEvent(this.habbo, response.getComposer(), response);
+ Emulator.getPluginManager().fireEvent(event);
+
+ if (event.isCancelled()) {
+ continue;
+ }
+
+ if (event.hasCustomMessage()) {
+ response = event.getCustomMessage();
+ }
+
this.channel.write(response);
}
this.channel.flush();
}
}
-
- public void sendKeepAlive() {
+
+ public void sendKeepAlive() {
if (this.channel != null && this.channel.isOpen()) {
this.channel.writeAndFlush(new ServerMessage(-1));
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/games/Game.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/games/Game.java
index 337649fc..de1ec247 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/games/Game.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/games/Game.java
@@ -5,13 +5,11 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredHighscore;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob;
-import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamLoses;
-import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamWins;
+import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreDataEntry;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreDataEntry;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.outgoing.guides.GuideSessionPartnerIsPlayingComposer;
import com.eu.habbo.plugin.Event;
import com.eu.habbo.plugin.events.games.GameHabboJoinEvent;
@@ -153,7 +151,7 @@ public abstract class Game implements Runnable {
if (winningTeam != null) {
for (GamePlayer player : winningTeam.getMembers()) {
- WiredHandler.handleCustomTrigger(WiredTriggerTeamWins.class, player.getHabbo().getRoomUnit(), this.room, new Object[]{this});
+ WiredManager.triggerTeamWins(this.room, player.getHabbo().getRoomUnit());
Habbo winner = player.getHabbo();
if (winner != null) {
@@ -171,7 +169,7 @@ public abstract class Game implements Runnable {
if (team == winningTeam) continue;
for (GamePlayer player : team.getMembers()) {
- WiredHandler.handleCustomTrigger(WiredTriggerTeamLoses.class, player.getHabbo().getRoomUnit(), this.room, new Object[]{this});
+ WiredManager.triggerTeamLoses(this.room, player.getHabbo().getRoomUnit());
}
if (team.getMembers().size() > 0 && team.getTotalScore() > 0) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java
index 672ceaa2..608bb448 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java
@@ -1,15 +1,14 @@
package com.eu.habbo.habbohotel.games;
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.habbohotel.wired.core.WiredManager;
public class GamePlayer {
private final Habbo habbo;
- private final GameTeamColors teamColor;
+ private GameTeamColors teamColor;
private int score;
@@ -41,7 +40,7 @@ public class GamePlayer {
this.wiredScore += amount;
}
- WiredHandler.handle(WiredTriggerType.SCORE_ACHIEVED, this.habbo.getRoomUnit(), this.habbo.getHabboInfo().getCurrentRoom(), new Object[]{this.habbo.getHabboInfo().getCurrentRoom().getGame(this.habbo.getHabboInfo().getCurrentGame()).getTeamForHabbo(this.habbo).getTotalScore(), amount});
+ WiredManager.triggerScoreAchieved(this.habbo.getHabboInfo().getCurrentRoom(), this.habbo.getRoomUnit(), this.score);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/games/football/FootballGame.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/games/football/FootballGame.java
index b3f902c6..addadf8b 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/games/football/FootballGame.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/games/football/FootballGame.java
@@ -15,7 +15,7 @@ import java.util.Map;
public class FootballGame extends Game {
- private final Room room;
+ private Room room;
public FootballGame(Room room) {
super(null, null, room, true);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/hotelview/HallOfFameWinner.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/hotelview/HallOfFameWinner.java
index 6f5d15f2..998de6f2 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/hotelview/HallOfFameWinner.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/hotelview/HallOfFameWinner.java
@@ -5,16 +5,16 @@ import java.sql.SQLException;
public class HallOfFameWinner implements Comparable {
- private final int id;
+ private int id;
- private final String username;
+ private String username;
- private final String look;
+ private String look;
- private final int points;
+ private int points;
public HallOfFameWinner(ResultSet set) throws SQLException {
this.id = set.getInt("id");
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java
index b1481dd4..12baf283 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java
@@ -3,10 +3,7 @@ package com.eu.habbo.habbohotel.items;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.interactions.*;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
-import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiPuck;
-import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiSphere;
-import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter;
-import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTile;
+import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.*;
import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.gates.InteractionBattleBanzaiGateBlue;
import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.gates.InteractionBattleBanzaiGateGreen;
import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.gates.InteractionBattleBanzaiGateRed;
@@ -48,12 +45,13 @@ import com.eu.habbo.habbohotel.items.interactions.totems.InteractionTotemPlanet;
import com.eu.habbo.habbohotel.items.interactions.wired.conditions.*;
import com.eu.habbo.habbohotel.items.interactions.wired.effects.*;
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob;
+import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraOrEval;
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraRandom;
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraUnseen;
+import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreManager;
import com.eu.habbo.habbohotel.items.interactions.wired.triggers.*;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
-import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreManager;
import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer;
import com.eu.habbo.plugin.events.emulator.EmulatorLoadItemsManagerEvent;
import com.eu.habbo.threading.runnables.QueryDeleteHabboItem;
@@ -170,6 +168,7 @@ public class ItemManager {
this.interactionsList.add(new ItemInteraction("youtube", InteractionYoutubeTV.class));
this.interactionsList.add(new ItemInteraction("jukebox", InteractionJukeBox.class));
this.interactionsList.add(new ItemInteraction("switch", InteractionSwitch.class));
+ this.interactionsList.add(new ItemInteraction("switch_remote_control", InteractionSwitchRemoteControl.class));
this.interactionsList.add(new ItemInteraction("fx_box", InteractionFXBox.class));
this.interactionsList.add(new ItemInteraction("blackhole", InteractionBlackHole.class));
this.interactionsList.add(new ItemInteraction("effect_toggle", InteractionEffectToggle.class));
@@ -191,6 +190,7 @@ public class ItemManager {
this.interactionsList.add(new ItemInteraction("crackable_subscription_box", InteractionRedeemableSubscriptionBox.class));
this.interactionsList.add(new ItemInteraction("random_state", InteractionRandomState.class));
this.interactionsList.add(new ItemInteraction("vendingmachine_no_sides", InteractionNoSidesVendingMachine.class));
+ this.interactionsList.add(new ItemInteraction("tile_walkmagic", InteractionTileWalkMagic.class));
this.interactionsList.add(new ItemInteraction("game_timer", InteractionGameTimer.class));
@@ -268,11 +268,13 @@ public class ItemManager {
this.interactionsList.add(new ItemInteraction("wf_cnd_trggrer_on_frn", WiredConditionTriggerOnFurni.class));
this.interactionsList.add(new ItemInteraction("wf_cnd_has_handitem", WiredConditionHabboHasHandItem.class));
this.interactionsList.add(new ItemInteraction("wf_cnd_date_rng_active", WiredConditionDateRangeActive.class));
+ this.interactionsList.add(new ItemInteraction("wf_cnd_valid_moves", WiredConditionMovementValidation.class));
this.interactionsList.add(new ItemInteraction("wf_xtra_random", WiredExtraRandom.class));
this.interactionsList.add(new ItemInteraction("wf_xtra_unseen", WiredExtraUnseen.class));
this.interactionsList.add(new ItemInteraction("wf_blob", WiredBlob.class));
+ this.interactionsList.add(new ItemInteraction("wf_xtra_or_eval", WiredExtraOrEval.class));
this.interactionsList.add(new ItemInteraction("wf_highscore", InteractionWiredHighscore.class));
@@ -344,9 +346,7 @@ public class ItemManager {
this.interactionsList.add(new ItemInteraction("totem_leg", InteractionTotemLegs.class));
this.interactionsList.add(new ItemInteraction("totem_head", InteractionTotemHead.class));
this.interactionsList.add(new ItemInteraction("totem_planet", InteractionTotemPlanet.class));
-
- this.interactionsList.add(new ItemInteraction("tile_walkmagic", InteractionTileWalkMagic.class));
- }
+ }
public void addItemInteraction(ItemInteraction itemInteraction) {
@@ -519,20 +519,6 @@ public class ItemManager {
}
}
- public HabboItem createItemNoSql(int habboId, Item item, int limitedStack, int limitedSells, String extraData) {
- Class extends HabboItem> itemClass = item.getInteractionType().getType();
- int id = new Random().nextInt(10000000) + 1000000000;
- if (itemClass != null) {
- try {
- return itemClass.getDeclaredConstructor(int.class, int.class, Item.class, String.class, int.class, int.class).newInstance(id, habboId, item, extraData, limitedStack, limitedSells);
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- return new InteractionDefault(id, habboId, item, extraData, limitedStack, limitedSells);
- }
- }
- return null;
- }
-
public void addNewUserGift(NewUserGift gift) {
this.newuserGifts.put(gift.getId(), gift);
}
@@ -784,7 +770,6 @@ public class ItemManager {
return null;
}
-
public YoutubeManager getYoutubeManager() {
return this.youtubeManager;
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/SoundTrack.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/SoundTrack.java
index b214f0fc..53430c13 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/SoundTrack.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/SoundTrack.java
@@ -4,12 +4,12 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class SoundTrack {
- private final int id;
- private final String name;
- private final String author;
- private final String code;
- private final String data;
- private final int length;
+ private int id;
+ private String name;
+ private String author;
+ private String code;
+ private String data;
+ private int length;
public SoundTrack(ResultSet set) throws SQLException {
this.id = set.getInt("id");
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/YoutubeManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/YoutubeManager.java
index 0ca98b54..17e2f1cf 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/YoutubeManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/YoutubeManager.java
@@ -16,10 +16,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.sql.*;
import java.time.Duration;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java
index 072eb40b..ab6bf36e 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java
@@ -28,10 +28,10 @@ public class InteractionBackgroundToner extends HabboItem {
serverMessage.appendInt(4);
if (this.getExtradata().split(":").length == 4) {
String[] colorData = this.getExtradata().split(":");
- serverMessage.appendInt(Integer.parseInt(colorData[0]));
- serverMessage.appendInt(Integer.parseInt(colorData[1]));
- serverMessage.appendInt(Integer.parseInt(colorData[2]));
- serverMessage.appendInt(Integer.parseInt(colorData[3]));
+ serverMessage.appendInt(Integer.valueOf(colorData[0]));
+ serverMessage.appendInt(Integer.valueOf(colorData[1]));
+ serverMessage.appendInt(Integer.valueOf(colorData[2]));
+ serverMessage.appendInt(Integer.valueOf(colorData[3]));
} else {
serverMessage.appendInt(0);
serverMessage.appendInt(126);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBuildArea.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBuildArea.java
index b0d2a23a..015ab451 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBuildArea.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBuildArea.java
@@ -46,7 +46,7 @@ public class InteractionBuildArea extends InteractionCustomValues {
}
};
- private final THashSet tiles;
+ private THashSet tiles;
public InteractionBuildArea(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem, defaultValues);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCannon.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCannon.java
index d3a24ff4..00ea3d9b 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCannon.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCannon.java
@@ -4,6 +4,7 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
+import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
@@ -12,6 +13,7 @@ import com.eu.habbo.threading.runnables.CannonResetCooldownAction;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.List;
public class InteractionCannon extends HabboItem {
public boolean cooldown = false;
@@ -46,30 +48,33 @@ public class InteractionCannon extends HabboItem {
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
+ if (client != null) {
+ super.onClick(client, room, objects);
+ }
+
if (room == null)
return;
- if (client != null) {
- RoomUnit roomUnit = client.getHabbo().getRoomUnit();
- int rotation = this.getRotation();
- int dx = (rotation == 4) ? -1 : (rotation == 0) ? 2 : 0;
- int dy = (rotation == 2) ? 2 : (rotation == 6) ? -1 : 0;
- int x = this.getX() + dx;
- int y = this.getY() + dy;
- if (roomUnit.getX() == x && roomUnit.getY() == y) {
- this.shoot(room, client);
- }
- } else {
- this.shoot(room, null);
- }
- }
+ RoomTile tile = room.getLayout().getTile(this.getX(), this.getY());
+ RoomTile fuseTile = this.getRotation() >= 4 ? tile : room.getLayout().getTileInFront(tile, ((this.getRotation() % 2) + 2) % 8);
+ List tiles = room.getLayout().getTilesAround(fuseTile);
+ tiles.remove(room.getLayout().getTileInFront(tile, (this.getRotation() + (this.getRotation() >= 4 ? -1 : 0)) % 8));
+ tiles.remove(room.getLayout().getTileInFront(tile, (this.getRotation() + (this.getRotation() >= 4 ? 5 : 4)) % 8));
- private void shoot(Room room, GameClient client) {
- this.cooldown = true;
- this.setExtradata(this.getExtradata().equals("1") ? "0" : "1");
- room.updateItemState(this);
- Emulator.getThreading().run(new CannonKickAction(this, room, client), 750);
- Emulator.getThreading().run(new CannonResetCooldownAction(this), 2000);
+ if ((client == null || (tiles.contains(client.getHabbo().getRoomUnit().getCurrentLocation())) && client.getHabbo().getRoomUnit().canWalk()) && !this.cooldown) {
+ if (client != null) {
+ client.getHabbo().getRoomUnit().setCanWalk(false);
+ client.getHabbo().getRoomUnit().setGoalLocation(client.getHabbo().getRoomUnit().getCurrentLocation());
+ client.getHabbo().getRoomUnit().lookAtPoint(fuseTile);
+ client.getHabbo().getRoomUnit().statusUpdate(true);
+ }
+
+ this.cooldown = true;
+ this.setExtradata(this.getExtradata().equals("1") ? "0" : "1");
+ room.updateItemState(this);
+ Emulator.getThreading().run(new CannonKickAction(this, room, client), 750);
+ Emulator.getThreading().run(new CannonResetCooldownAction(this), 2000);
+ }
}
@Override
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java
index 2e7873c2..055d9faa 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java
@@ -39,7 +39,7 @@ public class InteractionCrackable extends HabboItem {
serverMessage.appendInt(7 + (this.isLimited() ? 256 : 0));
serverMessage.appendString(Emulator.getGameEnvironment().getItemManager().calculateCrackState(Integer.parseInt(this.getExtradata()), Emulator.getGameEnvironment().getItemManager().getCrackableCount(this.getBaseItem().getId()), this.getBaseItem()) + "");
- serverMessage.appendInt(Integer.parseInt(this.getExtradata()));
+ serverMessage.appendInt(Integer.valueOf(this.getExtradata()));
serverMessage.appendInt(Emulator.getGameEnvironment().getItemManager().getCrackableCount(this.getBaseItem().getId()));
super.serializeExtradata(serverMessage);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java
index d234d471..4339706d 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java
@@ -143,7 +143,8 @@ public class InteractionDefault extends HabboItem {
int nextEffectF = 0;
if (objects != null && objects.length == 2) {
- if (objects[0] instanceof RoomTile goalTile && objects[1] instanceof RoomTile) {
+ if (objects[0] instanceof RoomTile && objects[1] instanceof RoomTile) {
+ RoomTile goalTile = (RoomTile) objects[0];
HabboItem topItem = room.getTopItemAt(goalTile.x, goalTile.y, (objects[0] != objects[1]) ? this : null);
if (topItem != null && (topItem.getBaseItem().getEffectM() == this.getBaseItem().getEffectM() || topItem.getBaseItem().getEffectF() == this.getBaseItem().getEffectF())) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectTile.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectTile.java
index ac10dcc7..c3af560c 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectTile.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectTile.java
@@ -8,8 +8,7 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.rooms.RoomUnitType;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -38,7 +37,7 @@ public class InteractionEffectTile extends InteractionPressurePlate {
Emulator.getThreading().run(() -> updateState(room), 100);
if(objects != null && objects.length > 0) {
- WiredHandler.handle(WiredTriggerType.WALKS_OFF_FURNI, roomUnit, room, new Object[]{this});
+ WiredManager.triggerUserWalksOff(room, roomUnit, this);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachine.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachine.java
index 49261af4..ba49ed7a 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachine.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachine.java
@@ -1,8 +1,7 @@
package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.habbohotel.items.Item;
-import com.eu.habbo.habbohotel.rooms.Room;
-import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.rooms.*;
import java.sql.ResultSet;
import java.sql.SQLException;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java
index d8d676da..beed1131 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java
@@ -43,7 +43,7 @@ public class InteractionMuteArea extends InteractionCustomValues {
}
};
- private final THashSet tiles;
+ private THashSet tiles;
public InteractionMuteArea(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem, defaultValues);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java
index 00bec0ac..a63dcad8 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java
@@ -17,7 +17,7 @@ import java.util.Objects;
public class InteractionObstacle extends HabboItem implements ICycleable {
- private final THashSet middleTiles;
+ private THashSet middleTiles;
public InteractionObstacle(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java
index 17e661d4..346290f0 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java
@@ -7,8 +7,7 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.items.ItemIntStateComposer;
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
@@ -89,7 +88,9 @@ public class InteractionOneWayGate extends HabboItem {
unit.setGoalLocation(tile);
Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tile, room, onFail, onFail));
- Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.WALKS_ON_FURNI, unit, room, new Object[]{this}), 500);
+ Emulator.getThreading().run(() -> {
+ WiredManager.triggerUserWalksOn(room, unit, this);
+ }, 500);
});
onFail.add(() -> {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVoteCounter.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVoteCounter.java
index c4aee567..32f4b51f 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVoteCounter.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVoteCounter.java
@@ -17,7 +17,7 @@ public class InteractionVoteCounter extends HabboItem {
private boolean frozen;
private int votes;
- private final List votedUsers;
+ private List votedUsers;
public InteractionVoteCounter(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java
index c69df8b0..d697ee4a 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java
@@ -274,7 +274,8 @@ public class InteractionWater extends InteractionDefault {
private boolean isValidForMask(Room room, int x, int y, double z, boolean corner) {
for (HabboItem item : room.getItemsAt(x, y, z)) {
- if (item instanceof InteractionWater water) {
+ if (item instanceof InteractionWater) {
+ InteractionWater water = (InteractionWater) item;
// Take out picked up water from the recalculation.
if (!water.isInRoom) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java
index f53429eb..8250b6ea 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java
@@ -15,12 +15,54 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+/**
+ * Base abstract class for all wired furniture items (triggers, effects, conditions, extras).
+ *
+ * The wired system allows room owners to create automated behaviors in their rooms.
+ * It consists of:
+ *
+ * - Triggers ({@link InteractionWiredTrigger}) - Events that start the wired chain
+ * - Conditions ({@link InteractionWiredCondition}) - Requirements that must be met
+ * - Effects ({@link InteractionWiredEffect}) - Actions that are executed
+ * - Extras ({@link InteractionWiredExtra}) - Modifiers like random selection
+ *
+ *
+ *
+ * Wired items at the same tile coordinates form a "stack" and execute together.
+ * The {@link com.eu.habbo.habbohotel.wired.core.WiredManager} orchestrates execution.
+ *
+ *
+ * Key features:
+ *
+ * - Cooldown system to prevent spam triggering
+ * - Per-user execution caching with automatic cleanup
+ * - JSON-based data persistence via {@link #getWiredData()}
+ *
+ *
+ *
+ * @see com.eu.habbo.habbohotel.wired.core.WiredManager
+ * @see com.eu.habbo.habbohotel.rooms.RoomSpecialTypes
+ */
public abstract class InteractionWired extends InteractionDefault {
private static final Logger LOGGER = LoggerFactory.getLogger(InteractionWired.class);
+
+ /**
+ * Maximum number of entries in the user execution cache to prevent memory leaks.
+ */
+ private static final int MAX_USER_CACHE_SIZE = 500;
+
+ /**
+ * Cache entries older than this (in milliseconds) will be cleaned up.
+ * Default: 5 minutes
+ */
+ private static final long CACHE_EXPIRY_MS = 5 * 60 * 1000;
+
private long cooldown;
- private final HashMap userExecutionCache = new HashMap<>();
+ private final ConcurrentHashMap userExecutionCache = new ConcurrentHashMap<>();
InteractionWired(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -32,6 +74,14 @@ public abstract class InteractionWired extends InteractionDefault {
this.setExtradata("0");
}
+ /**
+ * Executes this wired item's logic.
+ *
+ * @param roomUnit the room unit that triggered this (may be null for non-user triggers)
+ * @param room the room where this is happening
+ * @param stuff additional context data passed from the trigger
+ * @return true if execution was successful, false otherwise
+ */
public abstract boolean execute(RoomUnit roomUnit, Room room, Object[] stuff);
public abstract String getWiredData();
@@ -72,7 +122,7 @@ public abstract class InteractionWired extends InteractionDefault {
public abstract void onPickUp();
public void activateBox(Room room) {
- this.activateBox(room, null, 0L);
+ this.activateBox(room, (RoomUnit)null, 0L);
}
public void activateBox(Room room, RoomUnit roomUnit, long millis) {
@@ -126,7 +176,41 @@ public abstract class InteractionWired extends InteractionDefault {
}
public void addUserExecutionCache(int roomUnitId, long timestamp) {
- this.userExecutionCache.put((long)roomUnitId, timestamp);
+ // Enforce max size limit to prevent memory leaks
+ if (this.userExecutionCache.size() >= MAX_USER_CACHE_SIZE) {
+ cleanExpiredCacheEntries(timestamp);
+
+ // If still too large after cleanup, remove oldest entries
+ if (this.userExecutionCache.size() >= MAX_USER_CACHE_SIZE) {
+ // Remove approximately 10% of entries
+ int toRemove = MAX_USER_CACHE_SIZE / 10;
+ Iterator> iterator = this.userExecutionCache.entrySet().iterator();
+ while (iterator.hasNext() && toRemove > 0) {
+ iterator.next();
+ iterator.remove();
+ toRemove--;
+ }
+ }
+ }
+ this.userExecutionCache.put((long) roomUnitId, timestamp);
+ }
+
+ /**
+ * Removes cache entries older than CACHE_EXPIRY_MS.
+ * @param currentTimestamp the current timestamp to compare against
+ */
+ public void cleanExpiredCacheEntries(long currentTimestamp) {
+ this.userExecutionCache.entrySet().removeIf(
+ entry -> currentTimestamp - entry.getValue() > CACHE_EXPIRY_MS
+ );
+ }
+
+ /**
+ * Gets the current size of the user execution cache.
+ * @return the number of cached entries
+ */
+ public int getUserExecutionCacheSize() {
+ return this.userExecutionCache.size();
}
public static WiredSettings readSettings(ClientMessage packet, boolean isEffect)
@@ -159,4 +243,4 @@ public abstract class InteractionWired extends InteractionDefault {
settings.setStuffTypeSelectionCode(packet.readInt());
return settings;
}
-}
\ No newline at end of file
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java
index ef63491f..97018e8b 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java
@@ -7,12 +7,21 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionOperator;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
+import com.eu.habbo.habbohotel.wired.api.IWiredCondition;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.outgoing.wired.WiredConditionDataComposer;
import java.sql.ResultSet;
import java.sql.SQLException;
-public abstract class InteractionWiredCondition extends InteractionWired {
+/**
+ * Base class for all wired conditions in the game.
+ *
+ * Conditions are evaluated before effects execute to determine if they should run.
+ * They now implement {@link IWiredCondition} for the new context-driven architecture.
+ *
+ */
+public abstract class InteractionWiredCondition extends InteractionWired implements IWiredCondition {
public InteractionWiredCondition(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@@ -48,5 +57,17 @@ public abstract class InteractionWiredCondition extends InteractionWired {
public WiredConditionOperator operator() {
return WiredConditionOperator.AND;
}
+
+ // ========== IWiredCondition Implementation ==========
+
+ /**
+ * Evaluates whether this condition passes.
+ * Subclasses must implement this to define their evaluation logic.
+ *
+ * @param ctx the wired context containing event data
+ * @return true if the condition passes
+ */
+ @Override
+ public abstract boolean evaluate(WiredContext ctx);
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java
index e58e3659..d303291d 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java
@@ -1,18 +1,60 @@
package com.eu.habbo.habbohotel.items.interactions;
+import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
+import com.eu.habbo.habbohotel.wired.api.IWiredEffect;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.wired.WiredEffectDataComposer;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Collection;
+import java.util.function.Predicate;
-public abstract class InteractionWiredEffect extends InteractionWired {
+/**
+ * Base class for all wired effects in the game.
+ *
+ * Wired effects are triggered by {@link InteractionWiredTrigger} when conditions
+ * (defined by {@link InteractionWiredCondition}) are met. Effects can perform
+ * various actions like moving furniture, teleporting users, toggling states, etc.
+ *
+ *
+ * Subclasses must implement:
+ *
+ * - {@link #execute(RoomUnit, Room, Object[])} - The actual effect logic
+ * - {@link #getType()} - Returns the effect type enum
+ * - {@link #saveData(WiredSettings, GameClient)} - Saves configuration from client
+ * - {@link #getWiredData()} - Serializes data for database storage
+ * - {@link #loadWiredData(java.sql.ResultSet, Room)} - Loads data from database
+ * - {@link #serializeWiredData(com.eu.habbo.messages.ServerMessage, Room)} - Sends config to client
+ *
+ *
+ *
+ * @see InteractionWiredTrigger
+ * @see InteractionWiredCondition
+ * @see com.eu.habbo.habbohotel.wired.core.WiredManager
+ */
+public abstract class InteractionWiredEffect extends InteractionWired implements IWiredEffect {
+
+ // Common cooldown constants (in milliseconds)
+ /** No cooldown - effect can trigger as fast as possible */
+ public static final long COOLDOWN_NONE = 0L;
+ /** Default cooldown for most effects */
+ public static final long COOLDOWN_DEFAULT = 50L;
+ /** Cooldown for movement effects (move to, move towards, move away) */
+ public static final long COOLDOWN_MOVEMENT = 495L;
+ /** Cooldown for trigger stacks effect to prevent rapid re-triggering */
+ public static final long COOLDOWN_TRIGGER_STACKS = 250L;
+ /** Cooldown for teleport effect */
+ public static final long COOLDOWN_TELEPORT = 500L;
+
private int delay;
public InteractionWiredEffect(ResultSet set, Item baseItem) throws SQLException {
@@ -55,8 +97,105 @@ public abstract class InteractionWiredEffect extends InteractionWired {
public abstract WiredEffectType getType();
+ // ========== IWiredEffect Implementation ==========
+
+ /**
+ * Executes this effect with the given context.
+ * Subclasses must implement this to define their effect logic.
+ *
+ * @param ctx the wired context containing event data
+ */
+ @Override
+ public abstract void execute(WiredContext ctx);
+
+ /**
+ * Returns whether this effect requires an actor (user) to execute.
+ */
+ @Override
+ public boolean requiresActor() {
+ return requiresTriggeringUser();
+ }
+ /**
+ * Indicates whether this effect requires a triggering user (RoomUnit) to execute.
+ * Effects that require a user will not execute if no user triggered them.
+ *
+ * @return true if this effect requires a triggering user, false otherwise
+ */
public boolean requiresTriggeringUser() {
return false;
}
+
+ /**
+ * Gets the room this wired effect is placed in.
+ * Convenience method to avoid repeated lookups.
+ *
+ * @return the Room, or null if not found
+ */
+ protected Room getRoom() {
+ return Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
+ }
+
+ /**
+ * Validates and cleans a collection of items, removing those that are no longer valid.
+ * An item is invalid if:
+ *
+ * - It's null
+ * - Its room ID doesn't match this effect's room ID
+ * - It no longer exists in the room
+ *
+ *
+ * @param items the collection of items to validate
+ * @param the type extending HabboItem
+ * @return the number of items removed
+ */
+ protected int validateItems(Collection items) {
+ if (items == null || items.isEmpty()) {
+ return 0;
+ }
+
+ Room room = this.getRoom();
+ if (room == null) {
+ int size = items.size();
+ items.clear();
+ return size;
+ }
+
+ int roomId = this.getRoomId();
+ int sizeBefore = items.size();
+ items.removeIf(item -> item == null
+ || item.getRoomId() != roomId
+ || room.getHabboItem(item.getId()) == null);
+ return sizeBefore - items.size();
+ }
+
+ /**
+ * Validates and cleans a collection of items with an additional custom predicate.
+ * Items matching the predicate will be removed in addition to standard validation.
+ *
+ * @param items the collection of items to validate
+ * @param additionalRemoveCondition additional condition that, if true, causes removal
+ * @param the type extending HabboItem
+ * @return the number of items removed
+ */
+ protected int validateItems(Collection items, Predicate additionalRemoveCondition) {
+ if (items == null || items.isEmpty()) {
+ return 0;
+ }
+
+ Room room = this.getRoom();
+ if (room == null) {
+ int size = items.size();
+ items.clear();
+ return size;
+ }
+
+ int roomId = this.getRoomId();
+ int sizeBefore = items.size();
+ items.removeIf(item -> item == null
+ || item.getRoomId() != roomId
+ || room.getHabboItem(item.getId()) == null
+ || additionalRemoveCondition.test(item));
+ return sizeBefore - items.size();
+ }
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java
index b8a638b2..c02b251a 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java
@@ -7,8 +7,7 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreClearType;
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreRow;
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreScoreType;
@@ -97,7 +96,7 @@ public class InteractionWiredHighscore extends HabboItem {
}
if(client != null && !(objects.length >= 2 && objects[1] instanceof WiredEffectType)) {
- WiredHandler.handle(WiredTriggerType.STATE_CHANGED, client.getHabbo().getRoomUnit(), room, new Object[]{this});
+ WiredManager.triggerFurniStateChanged(room, client.getHabbo().getRoomUnit(), this);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java
index 528c6b80..e6410040 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java
@@ -5,13 +5,23 @@ import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.api.IWiredTrigger;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.outgoing.wired.WiredTriggerDataComposer;
import java.sql.ResultSet;
import java.sql.SQLException;
-public abstract class InteractionWiredTrigger extends InteractionWired {
+/**
+ * Base class for all wired triggers in the game.
+ *
+ * Triggers are the entry points for wired execution. They now implement
+ * {@link IWiredTrigger} for the new context-driven architecture.
+ *
+ */
+public abstract class InteractionWiredTrigger extends InteractionWired implements IWiredTrigger {
private int delay;
protected InteractionWiredTrigger(ResultSet set, Item baseItem) throws SQLException {
@@ -57,5 +67,37 @@ public abstract class InteractionWiredTrigger extends InteractionWired {
public boolean isTriggeredByRoomUnit() {
return false;
}
+
+ // ========== IWiredTrigger Implementation ==========
+
+ /**
+ * Returns the event type this trigger responds to.
+ * Maps the WiredTriggerType to the new WiredEvent.Type.
+ *
+ * @return the event type this trigger responds to
+ */
+ @Override
+ public WiredEvent.Type listensTo() {
+ return WiredEvent.Type.fromLegacyType(this.getType());
+ }
+
+ /**
+ * Checks if this trigger matches the given event.
+ * Subclasses must implement this to define their matching logic.
+ *
+ * @param triggerItem the wired trigger furniture item
+ * @param event the event that occurred
+ * @return true if this trigger should activate
+ */
+ @Override
+ public abstract boolean matches(HabboItem triggerItem, WiredEvent event);
+
+ /**
+ * Returns whether this trigger requires an actor (user) to activate.
+ */
+ @Override
+ public boolean requiresActor() {
+ return isTriggeredByRoomUnit();
+ }
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java
index 0fbe9e89..e93d5308 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java
@@ -11,8 +11,7 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.threading.runnables.games.GameTimer;
import org.slf4j.Logger;
@@ -208,7 +207,7 @@ public class InteractionGameTimer extends HabboItem {
this.endGame(room, true);
if(wasPaused) {
- WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
+ WiredManager.triggerGameEnds(room);
}
this.createNewGame(room);
@@ -218,7 +217,7 @@ public class InteractionGameTimer extends HabboItem {
this.isPaused = false;
room.updateItem(this);
- WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[]{});
+ WiredManager.triggerGameStarts(room);
if (!this.threadActive) {
this.threadActive = true;
@@ -255,7 +254,7 @@ public class InteractionGameTimer extends HabboItem {
room.updateItem(this);
this.createNewGame(room);
- WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[]{this});
+ WiredManager.triggerGameStarts(room);
if (!this.threadActive) {
this.threadActive = true;
@@ -271,7 +270,7 @@ public class InteractionGameTimer extends HabboItem {
} else if (this.isPaused) {
this.endGame(room);
this.increaseTimer(room);
- WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
+ WiredManager.triggerGameEnds(room);
}
break;
@@ -296,7 +295,7 @@ public class InteractionGameTimer extends HabboItem {
room.updateItem(this);
}
this.createNewGame(room);
- WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[]{this});
+ WiredManager.triggerGameStarts(room);
if (!threadActive) {
threadActive = true;
Emulator.getThreading().run(new GameTimer(this), 1000);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java
index f57850a5..98a627fe 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java
@@ -3,19 +3,15 @@ package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
-import com.eu.habbo.habbohotel.pets.RideablePet;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
-import com.eu.habbo.habbohotel.rooms.RoomUserRotation;
-import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.threading.runnables.BanzaiRandomTeleport;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
public class InteractionBattleBanzaiTeleporter extends HabboItem {
public InteractionBattleBanzaiTeleporter(ResultSet set, Item baseItem) throws SQLException {
@@ -60,43 +56,16 @@ public class InteractionBattleBanzaiTeleporter extends HabboItem {
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects);
- if (objects.length < 3) {
+ if(objects.length < 3) {
HabboItem target = room.getRoomSpecialTypes().getRandomTeleporter(null, this);
-
- if (target == null)
- return;
+ if (target == null) return;
this.setExtradata("1");
room.updateItemState(this);
+ roomUnit.removeStatus(RoomUnitStatus.MOVE);
+ roomUnit.setGoalLocation(roomUnit.getCurrentLocation());
roomUnit.setCanWalk(false);
-
- Habbo habbo = room.getHabbo(roomUnit);
- RoomUserRotation rotation = RoomUserRotation.fromValue(Emulator.getRandom().nextInt(8));
- ArrayList roomUnitsToTeleport = new ArrayList<>();
- if (habbo != null) {
- RideablePet pet = habbo.getHabboInfo().getRiding();
- if (pet != null)
- roomUnitsToTeleport.add(pet.getRoomUnit());
- }
-
- roomUnitsToTeleport.add(roomUnit);
-
- Emulator.getThreading().run(() -> {
- target.setExtradata("1");
- room.updateItemState(target);
-
- for (RoomUnit ru : roomUnitsToTeleport) {
- ru.removeStatus(RoomUnitStatus.MOVE);
- ru.setCanWalk(false);
-
- Emulator.getThreading().run(() -> {
- this.setExtradata("0");
- room.updateItemState(this);
-
- new BanzaiRandomTeleport(this, target, ru, room, rotation).run();
- }, 500);
- }
- }, 500);
+ Emulator.getThreading().run(new BanzaiRandomTeleport(this, target, roomUnit, room), 500);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java
index eab2817f..819a864e 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java
@@ -25,7 +25,7 @@ public class InteractionBattleBanzaiGate extends InteractionGameGate {
@Override
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
- return room.getGame(BattleBanzaiGame.class) == null || room.getGame(BattleBanzaiGame.class).state.equals(GameState.IDLE);
+ return room.getGame(BattleBanzaiGame.class) == null || ((BattleBanzaiGame) room.getGame(BattleBanzaiGame.class)).state.equals(GameState.IDLE);
}
@Override
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java
index c897cdac..6bd21167 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java
@@ -167,7 +167,7 @@ public class InteractionFootball extends InteractionPushable {
BigDecimal topItemHeight = BigDecimal.valueOf(topItem.getZ() + topItem.getBaseItem().getHeight());
BigDecimal ballHeight = BigDecimal.valueOf(this.getZ());
- if (topItemHeight.subtract(ballHeight).compareTo(new BigDecimal("1.65")) > 0) {
+ if (topItemHeight.subtract(ballHeight).compareTo(new BigDecimal(1.65)) > 0) {
return false;
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java
index b2d75882..ec583fde 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java
@@ -25,7 +25,7 @@ public class InteractionFreezeGate extends InteractionGameGate {
@Override
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
- return room.getGame(FreezeGame.class) == null || room.getGame(FreezeGame.class).state.equals(GameState.IDLE);
+ return room.getGame(FreezeGame.class) == null || ((FreezeGame) room.getGame(FreezeGame.class)).state.equals(GameState.IDLE);
}
@Override
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/interfaces/ConditionalGate.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/interfaces/ConditionalGate.java
index 58eea046..3f1b06cb 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/interfaces/ConditionalGate.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/interfaces/ConditionalGate.java
@@ -4,5 +4,5 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
public interface ConditionalGate {
- void onRejected(RoomUnit roomUnit, Room room, Object[] objects);
+ public void onRejected(RoomUnit roomUnit, Room room, Object[] objects);
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java
index 142e00d7..0b92d4e6 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java
@@ -7,7 +7,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -58,14 +59,20 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
int time = Emulator.getIntUnixTimestamp();
return this.startDate < time && this.endDate >= time;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.startDate,
this.endDate
));
@@ -76,7 +83,7 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.startDate = data.startDate;
this.endDate = data.endDate;
} else {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java
index 4d9b6a4b..546e9152 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java
@@ -9,7 +9,8 @@ import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
@@ -22,7 +23,7 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.FURNI_HAS_FURNI;
private boolean all;
- private final THashSet items;
+ private THashSet items;
public WiredConditionFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -35,32 +36,51 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ Room room = ctx.room();
+
this.refresh();
if(this.items.isEmpty())
return true;
+ if (room.getLayout() == null)
+ return false;
+
if(this.all) {
return this.items.stream().allMatch(item -> {
+ if (item == null) return false;
+ RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
+ if (baseTile == null) return false;
double minZ = item.getZ() + Item.getCurrentHeight(item);
- THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
- return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
+ THashSet occupiedTiles = room.getLayout().getTilesAt(baseTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ if (occupiedTiles == null) return false;
+ return occupiedTiles.stream().anyMatch(tile -> tile != null && room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
});
}
else {
return this.items.stream().anyMatch(item -> {
+ if (item == null) return false;
+ RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
+ if (baseTile == null) return false;
double minZ = item.getZ() + Item.getCurrentHeight(item);
- THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
- return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
+ THashSet occupiedTiles = room.getLayout().getTilesAt(baseTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ if (occupiedTiles == null) return false;
+ return occupiedTiles.stream().anyMatch(tile -> tile != null && room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
});
}
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
this.refresh();
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.all,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
@@ -71,7 +91,7 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.all = data.all;
for(int id : data.itemIds) {
@@ -118,7 +138,7 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
this.refresh();
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java
index 80b5225f..7b6bd83a 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java
@@ -12,7 +12,8 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
@@ -25,7 +26,6 @@ import java.util.stream.Collectors;
public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.FURNI_HAVE_HABBO;
protected THashSet items;
- private boolean all;
public WiredConditionFurniHaveHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -40,44 +40,45 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
@Override
public void onPickUp() {
this.items.clear();
- this.all = false;
}
-
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ Room room = ctx.room();
+
this.refresh();
- if (this.items.isEmpty()) {
+ if (this.items.isEmpty())
return true;
- }
+
+ if (room.getLayout() == null)
+ return false;
Collection habbos = room.getHabbos();
Collection bots = room.getCurrentBots().valueCollection();
Collection pets = room.getCurrentPets().valueCollection();
- if (this.all) {
- return this.items.stream().allMatch(item -> {
- THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
- return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
- bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
- pets.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation()));
- });
- } else {
- return this.items.stream().anyMatch(item -> {
- THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
- return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
- bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
- pets.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation()));
- });
- }
+ return this.items.stream().filter(item -> item != null).allMatch(item -> {
+ RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
+ if (baseTile == null) return false;
+
+ THashSet occupiedTiles = room.getLayout().getTilesAt(baseTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ return habbos.stream().anyMatch(character -> character.getRoomUnit() != null && occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
+ bots.stream().anyMatch(character -> character.getRoomUnit() != null && occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
+ pets.stream().anyMatch(character -> character.getRoomUnit() != null && occupiedTiles.contains(character.getRoomUnit().getCurrentLocation()));
+ });
+ }
+
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
this.refresh();
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
- this.all,
+ return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@@ -88,8 +89,7 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
- this.all = data.all;
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
@@ -102,7 +102,6 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
String[] data = wiredData.split(":");
if (data.length >= 1) {
- this.all = (data[0].equals("1"));
String[] items = data[1].split(";");
@@ -126,7 +125,7 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
this.refresh();
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
@@ -185,11 +184,9 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
}
static class JsonData {
- boolean all;
List itemIds;
- public JsonData(boolean all, List itemIds) {
- this.all = all;
+ public JsonData(List itemIds) {
this.itemIds = itemIds;
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java
index d4c202e3..be2fcb8c 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java
@@ -8,7 +8,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
@@ -20,7 +21,7 @@ import java.util.stream.Collectors;
public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.STUFF_IS;
- private final THashSet items = new THashSet<>();
+ private THashSet items = new THashSet<>();
public WiredConditionFurniTypeMatch(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -36,27 +37,30 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
this.refresh();
if(items.isEmpty())
return false;
- if (stuff != null) {
- if (stuff.length >= 1) {
- if (stuff[0] instanceof HabboItem triggeringItem) {
- return this.items.stream().anyMatch(item -> item == triggeringItem);
- }
- }
+ HabboItem triggeringItem = ctx.sourceItem().orElse(null);
+ if (triggeringItem != null) {
+ return this.items.stream().anyMatch(item -> item == triggeringItem);
}
return false;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
this.refresh();
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@@ -67,7 +71,7 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
@@ -99,7 +103,7 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
this.refresh();
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java
index 189d4598..0364abce 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java
@@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -24,7 +25,9 @@ public class WiredConditionGroupMember extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ Room room = ctx.room();
if (room.getGuildId() == 0)
return false;
@@ -33,6 +36,12 @@ public class WiredConditionGroupMember extends InteractionWiredCondition {
return habbo != null && habbo.getHabboStats().hasGuild(room.getGuildId());
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
return "";
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java
index 124cbee6..7747d9e0 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java
@@ -6,7 +6,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -27,15 +28,21 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- int count = room.getUserCount();
+ public boolean evaluate(WiredContext ctx) {
+ int count = ctx.room().getUserCount();
return count >= this.lowerLimit && count <= this.upperLimit;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.lowerLimit,
this.upperLimit
));
@@ -46,7 +53,7 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.lowerLimit = data.lowerLimit;
this.upperLimit = data.upperLimit;
} else {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java
index bb85f578..5247e5c2 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java
@@ -6,7 +6,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -26,14 +27,21 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
if (roomUnit == null) return false;
return roomUnit.getEffectId() == this.effectId;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.effectId
));
}
@@ -43,7 +51,7 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.effectId = data.effectId;
} else {
this.effectId = Integer.parseInt(wiredData);
@@ -67,8 +75,9 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
message.appendInt(0);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
- message.appendString(this.effectId + "");
- message.appendInt(0);
+ message.appendString("");
+ message.appendInt(1);
+ message.appendInt(this.effectId);
message.appendInt(0);
message.appendInt(this.getType().code);
message.appendInt(0);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java
index 7e90bf3b..0175aadf 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java
@@ -6,7 +6,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,14 +60,21 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
if (roomUnit == null) return false;
return roomUnit.getHandItem() == this.handItem;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.handItem
));
}
@@ -77,7 +85,7 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.handItem = data.handItemId;
} else {
this.handItem = Integer.parseInt(wiredData);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java
index c40d58d7..7cb6f29f 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java
@@ -8,7 +8,8 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboBadge;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -28,7 +29,9 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ Room room = ctx.room();
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
@@ -43,9 +46,15 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
return false;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.badge
));
}
@@ -55,7 +64,7 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.badge = data.badge;
} else {
this.badge = wiredData;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java
index 237216ff..7086ea7d 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java
@@ -7,7 +7,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -26,14 +27,20 @@ public class WiredConditionLessTimeElapsed extends InteractionWiredCondition {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
+ @Override
+ public boolean evaluate(WiredContext ctx) {
+ return (Emulator.getIntUnixTimestamp() - ctx.room().getLastTimerReset()) / 0.5 < this.cycles;
+ }
+
+ @Deprecated
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- return (Emulator.getIntUnixTimestamp() - room.getLastTimerReset()) / 0.5 < this.cycles;
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.cycles
));
}
@@ -44,7 +51,7 @@ public class WiredConditionLessTimeElapsed extends InteractionWiredCondition {
try {
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.cycles = data.cycles;
} else {
if (!wiredData.equals(""))
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java
index 96e9edd6..82f745c4 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java
@@ -8,8 +8,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWi
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
@@ -22,7 +23,7 @@ import java.util.List;
public class WiredConditionMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings {
public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT;
- private final THashSet settings;
+ private THashSet settings;
private boolean state;
private boolean position;
@@ -48,7 +49,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
this.refresh();
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.settings.size());
for (WiredMatchFurniSetting item : this.settings)
@@ -97,7 +98,8 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ Room room = ctx.room();
if (this.settings.isEmpty())
return true;
@@ -135,9 +137,15 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
return true;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.state,
this.position,
this.direction,
@@ -150,7 +158,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.state = data.state;
this.position = data.position;
this.direction = data.direction;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java
index 2ff2c288..2ae00378 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java
@@ -7,7 +7,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -26,14 +27,20 @@ public class WiredConditionMoreTimeElapsed extends InteractionWiredCondition {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
+ @Override
+ public boolean evaluate(WiredContext ctx) {
+ return (Emulator.getIntUnixTimestamp() - ctx.room().getLastTimerReset()) / 0.5 > this.cycles;
+ }
+
+ @Deprecated
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- return (Emulator.getIntUnixTimestamp() - room.getLastTimerReset()) / 0.5 > this.cycles;
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.cycles
));
}
@@ -44,7 +51,7 @@ public class WiredConditionMoreTimeElapsed extends InteractionWiredCondition {
try {
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.cycles = data.cycles;
} else {
if (!wiredData.equals(""))
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMovementValidation.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMovementValidation.java
new file mode 100644
index 00000000..44ce8ba2
--- /dev/null
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMovementValidation.java
@@ -0,0 +1,124 @@
+package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
+
+import com.eu.habbo.habbohotel.items.Item;
+import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
+import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
+import com.eu.habbo.habbohotel.rooms.Room;
+import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.wired.WiredConditionType;
+import com.eu.habbo.habbohotel.wired.api.IWiredEffect;
+import com.eu.habbo.habbohotel.wired.api.WiredStack;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredSimulation;
+import com.eu.habbo.messages.ServerMessage;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * Wired condition that validates all movement effects can complete successfully.
+ *
+ * When this condition is present in a wired stack, all movement effects are first
+ * simulated to verify they can complete. If ANY movement would fail (e.g., destination
+ * has a user, bot, furniture, or is a hole), this condition returns FALSE and the
+ * stack does not execute.
+ *
+ *
+ * Key Feature: The simulation tracks cumulative position changes. If Effect 1
+ * moves an item from tile 0 to tile 1, and Effect 2 moves it forward again, the
+ * simulation correctly validates the move from tile 1 to tile 2 (not from tile 0).
+ *
+ *
+ * Use cases:
+ *
+ * - Moving furniture in formation - if one piece can't move, none should
+ * - Puzzles where partial movement would break the puzzle state
+ * - Chain movements where items depend on each other's positions
+ *
+ *
+ *
+ * @see WiredSimulation
+ * @see IWiredEffect#simulate
+ */
+public class WiredConditionMovementValidation extends InteractionWiredCondition {
+
+ public static final WiredConditionType type = WiredConditionType.MOVEMENT_VALIDATION;
+
+ public WiredConditionMovementValidation(ResultSet set, Item baseItem) throws SQLException {
+ super(set, baseItem);
+ }
+
+ public WiredConditionMovementValidation(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
+ super(id, userId, item, extradata, limitedStack, limitedSells);
+ }
+
+ @Override
+ public boolean evaluate(WiredContext ctx) {
+ WiredStack stack = ctx.stack();
+ if (stack == null) {
+ return true;
+ }
+
+ WiredSimulation simulation = new WiredSimulation(ctx.room());
+
+ for (IWiredEffect effect : stack.effects()) {
+ if (effect.requiresActor() && !ctx.hasActor()) {
+ continue;
+ }
+
+ try {
+ boolean success = effect.simulate(ctx, simulation);
+ if (!success || simulation.hasFailed()) {
+ return false;
+ }
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public String getWiredData() {
+ return "";
+ }
+
+ @Override
+ public void loadWiredData(ResultSet set, Room room) throws SQLException {
+ }
+
+ @Override
+ public void onPickUp() {
+ }
+
+ @Override
+ public WiredConditionType getType() {
+ return type;
+ }
+
+ @Override
+ public void serializeWiredData(ServerMessage message, Room room) {
+ message.appendBoolean(false);
+ message.appendInt(5);
+ message.appendInt(0);
+ message.appendInt(this.getBaseItem().getSpriteId());
+ message.appendInt(this.getId());
+ message.appendString("");
+ message.appendInt(0);
+ message.appendInt(0);
+ message.appendInt(this.getType().code);
+ message.appendInt(0);
+ message.appendInt(0);
+ }
+
+ @Override
+ public boolean saveData(WiredSettings settings) {
+ return true;
+ }
+
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java
index 8ef79e63..629a2702 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java
@@ -10,7 +10,8 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionOperator;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
@@ -23,7 +24,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_FURNI;
private boolean all;
- private final THashSet items;
+ private THashSet items;
public WiredConditionNotFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -36,32 +37,51 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ Room room = ctx.room();
+
this.refresh();
if (this.items.isEmpty())
return true;
+ if (room.getLayout() == null)
+ return true;
+
if(this.all) {
return this.items.stream().allMatch(item -> {
+ if (item == null) return true;
+ RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
+ if (baseTile == null) return true;
double minZ = item.getZ() + Item.getCurrentHeight(item);
- THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
- return occupiedTiles.stream().noneMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
+ THashSet occupiedTiles = room.getLayout().getTilesAt(baseTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ if (occupiedTiles == null) return true;
+ return occupiedTiles.stream().noneMatch(tile -> tile != null && room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
});
}
else {
return this.items.stream().anyMatch(item -> {
+ if (item == null) return true;
+ RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
+ if (baseTile == null) return true;
double minZ = item.getZ() + Item.getCurrentHeight(item);
- THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
- return occupiedTiles.stream().noneMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
+ THashSet occupiedTiles = room.getLayout().getTilesAt(baseTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ if (occupiedTiles == null) return true;
+ return occupiedTiles.stream().noneMatch(tile -> tile != null && room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
});
}
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
this.refresh();
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.all,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
@@ -73,7 +93,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.all = data.all;
for (int id : data.itemIds) {
@@ -119,7 +139,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
this.refresh();
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java
index 23d17edc..02324a60 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java
@@ -12,7 +12,8 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
@@ -43,28 +44,42 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ Room room = ctx.room();
+
this.refresh();
if (this.items.isEmpty())
return true;
+ if (room.getLayout() == null)
+ return false;
+
Collection habbos = room.getHabbos();
Collection bots = room.getCurrentBots().valueCollection();
Collection pets = room.getCurrentPets().valueCollection();
- return this.items.stream().noneMatch(item -> {
- THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
- return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
- bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
- pets.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation()));
+ return this.items.stream().filter(item -> item != null).noneMatch(item -> {
+ RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
+ if (baseTile == null) return false;
+
+ THashSet occupiedTiles = room.getLayout().getTilesAt(baseTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ return habbos.stream().anyMatch(character -> character.getRoomUnit() != null && occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
+ bots.stream().anyMatch(character -> character.getRoomUnit() != null && occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
+ pets.stream().anyMatch(character -> character.getRoomUnit() != null && occupiedTiles.contains(character.getRoomUnit().getCurrentLocation()));
});
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
this.refresh();
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@@ -75,7 +90,7 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- WiredConditionFurniHaveHabbo.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniHaveHabbo.JsonData.class);
+ WiredConditionFurniHaveHabbo.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionFurniHaveHabbo.JsonData.class);
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
@@ -110,7 +125,7 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
this.refresh();
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java
index 49525576..19e841aa 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java
@@ -8,7 +8,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
@@ -20,7 +21,7 @@ import java.util.stream.Collectors;
public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_STUFF_IS;
- private final THashSet items = new THashSet<>();
+ private THashSet items = new THashSet<>();
public WiredConditionNotFurniTypeMatch(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -31,27 +32,30 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
this.refresh();
if(items.isEmpty())
return true;
- if (stuff != null) {
- if (stuff.length >= 1) {
- if (stuff[0] instanceof HabboItem triggeringItem) {
- return this.items.stream().noneMatch(item -> item == triggeringItem);
- }
- }
+ HabboItem triggeringItem = ctx.sourceItem().orElse(null);
+ if (triggeringItem != null) {
+ return this.items.stream().noneMatch(item -> item == triggeringItem);
}
return true;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
this.refresh();
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@@ -62,7 +66,7 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- WiredConditionFurniTypeMatch.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class);
+ WiredConditionFurniTypeMatch.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class);
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
@@ -99,7 +103,7 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
this.refresh();
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java
index 109e1f68..cbdbb7b4 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java
@@ -6,7 +6,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -27,15 +28,21 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- int count = room.getUserCount();
+ public boolean evaluate(WiredContext ctx) {
+ int count = ctx.room().getUserCount();
return count < this.lowerLimit || count > this.upperLimit;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.lowerLimit,
this.upperLimit
));
@@ -46,7 +53,7 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- WiredConditionHabboCount.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionHabboCount.JsonData.class);
+ WiredConditionHabboCount.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionHabboCount.JsonData.class);
this.lowerLimit = data.lowerLimit;
this.upperLimit = data.upperLimit;
} else {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java
index fb908728..1a622641 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java
@@ -6,7 +6,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -26,14 +27,21 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
if (roomUnit == null) return false;
return roomUnit.getEffectId() != this.effectId;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.effectId
));
}
@@ -43,7 +51,7 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.effectId = data.effectId;
} else {
this.effectId = Integer.parseInt(wiredData);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java
index d806810c..81bc279b 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java
@@ -8,7 +8,8 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboBadge;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -28,7 +29,9 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ Room room = ctx.room();
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
@@ -44,9 +47,15 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition
return true;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.badge
));
}
@@ -56,7 +65,7 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.badge = data.badge;
} else {
this.badge = wiredData;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java
index 75f2e5a9..4670912e 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java
@@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -24,7 +25,9 @@ public class WiredConditionNotInGroup extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ Room room = ctx.room();
if (room.getGuildId() == 0)
return false;
@@ -33,6 +36,12 @@ public class WiredConditionNotInGroup extends InteractionWiredCondition {
return habbo == null || !habbo.getHabboStats().hasGuild(room.getGuildId());
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
return "";
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java
index b7ef4a22..7ae8bb03 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java
@@ -7,8 +7,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -28,7 +29,9 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ Room room = ctx.room();
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
@@ -38,9 +41,15 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
return true;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.teamColor
));
}
@@ -51,7 +60,7 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.teamColor = data.teamColor;
} else {
if (!wiredData.equals(""))
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java
index d6b11988..2121bf97 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java
@@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import java.sql.ResultSet;
@@ -19,9 +20,15 @@ public class WiredConditionNotMatchStatePosition extends WiredConditionMatchStat
super(id, userId, item, extradata, limitedStack, limitedSells);
}
+ @Override
+ public boolean evaluate(WiredContext ctx) {
+ return !super.evaluate(ctx);
+ }
+
+ @Deprecated
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- return !super.execute(roomUnit, room, stuff);
+ return false;
}
@Override
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java
index 21ea027e..88558789 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java
@@ -4,6 +4,7 @@ import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -20,7 +21,10 @@ public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurn
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ Room room = ctx.room();
+
if (roomUnit == null)
return false;
@@ -32,6 +36,12 @@ public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurn
return !triggerOnFurni(roomUnit, room);
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public WiredConditionType getType() {
return type;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java
index 486983fc..5f1ac3a6 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java
@@ -8,7 +8,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -28,7 +29,9 @@ public class WiredConditionTeamMember extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ Room room = ctx.room();
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
@@ -40,9 +43,15 @@ public class WiredConditionTeamMember extends InteractionWiredCondition {
return false;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.teamColor
));
}
@@ -53,7 +62,7 @@ public class WiredConditionTeamMember extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.teamColor = data.teamColor;
} else {
if (!wiredData.equals(""))
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java
index 20028f9d..3ced00ba 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java
@@ -9,7 +9,8 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionOperator;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
@@ -32,7 +33,10 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean evaluate(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ Room room = ctx.room();
+
if (roomUnit == null)
return false;
@@ -44,6 +48,12 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
return triggerOnFurni(roomUnit, room);
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
protected boolean triggerOnFurni(RoomUnit roomUnit, Room room) {
THashSet itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation());
return this.items.stream().anyMatch(itemsAtUser::contains);
@@ -52,7 +62,7 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
@Override
public String getWiredData() {
this.refresh();
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@@ -63,7 +73,7 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
@@ -100,7 +110,7 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
this.refresh();
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java
index 14e83480..72869321 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java
@@ -3,8 +3,8 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
-import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -19,17 +19,15 @@ public class WiredEffectAlert extends WiredEffectWhisper {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- Habbo habbo = room.getHabbo(roomUnit);
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ Habbo habbo = ctx.actor().map(room::getHabbo).orElse(null);
if (habbo != null) {
habbo.alert(this.message
.replace("%online%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "")
.replace("%username%", habbo.getHabboInfo().getUsername())
.replace("%roomsloaded%", Emulator.getGameEnvironment().getRoomManager().loadedRoomsCount() + ""));
- return true;
}
-
- return false;
}
-}
\ No newline at end of file
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java
index e7462244..6cc5af2b 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java
@@ -9,7 +9,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
@@ -39,7 +40,7 @@ public class WiredEffectBotClothes extends InteractionWiredEffect {
message.appendInt(0);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
- message.appendString(this.botName + ((char) 9) + this.botLook);
+ message.appendString(this.botName + ((char) 9) + "" + this.botLook);
message.appendInt(0);
message.appendInt(0);
message.appendInt(this.getType().code);
@@ -77,20 +78,25 @@ public class WiredEffectBotClothes extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
List bots = room.getBots(this.botName);
if (bots.size() == 1) {
Bot bot = bots.get(0);
bot.setFigure(this.botLook);
}
+ }
- return true;
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.botLook, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.botName, this.botLook, this.getDelay()));
}
@Override
@@ -98,7 +104,7 @@ public class WiredEffectBotClothes extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.botName = data.bot_name;
this.botLook = data.look;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java
index 7cb69764..28ba0c3a 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java
@@ -11,7 +11,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
@@ -99,9 +100,12 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- Habbo habbo = room.getHabbo(roomUnit);
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ if (roomUnit == null) return;
+ Habbo habbo = room.getHabbo(roomUnit);
List bots = room.getBots(this.botName);
if (habbo != null && bots.size() == 1) {
@@ -112,16 +116,18 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
} else {
bot.stopFollowingHabbo();
}
-
- return true;
}
+ }
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.botName, this.mode, this.getDelay()));
}
@Override
@@ -129,7 +135,7 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.mode = data.mode;
this.botName = data.bot_name;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java
index 80537049..d39d1044 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java
@@ -12,8 +12,8 @@ import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem;
@@ -102,7 +102,11 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ if (roomUnit == null) return;
+
Habbo habbo = room.getHabbo(roomUnit);
List bots = room.getBots(this.botName);
@@ -114,7 +118,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
tasks.add(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, 0));
tasks.add(() -> {
if(roomUnit.getRoom() != null && roomUnit.getRoom().getId() == room.getId() && roomUnit.getCurrentLocation().distance(bot.getRoomUnit().getCurrentLocation()) < 2) {
- WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, bot.getRoomUnit(), room, new Object[]{});
+ WiredManager.triggerBotReachedHabbo(room, bot.getRoomUnit(), roomUnit);
}
});
@@ -126,16 +130,18 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId));
Emulator.getThreading().run(new RoomUnitWalkToLocation(bot.getRoomUnit(), tile, room, tasks, tasks));
-
- return true;
}
+ }
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.itemId, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.botName, this.itemId, this.getDelay()));
}
@Override
@@ -143,7 +149,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.itemId = data.item_id;
this.botName = data.bot_name;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java
index c42ef54e..8301f508 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java
@@ -10,8 +10,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
@@ -42,7 +42,7 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
message.appendInt(0);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
- message.appendString(this.botName + ((char) 9) + this.message);
+ message.appendString(this.botName + "" + ((char) 9) + "" + this.message);
message.appendInt(1);
message.appendInt(this.mode);
message.appendInt(0);
@@ -89,10 +89,12 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ RoomUnit roomUnit = ctx.actor().orElse(null);
String message = this.message;
- Habbo habbo = room.getHabbo(roomUnit);
+ Habbo habbo = roomUnit != null ? room.getHabbo(roomUnit) : null;
if (habbo != null) {
message = message.replace(Emulator.getTexts().getValue("wired.variable.username", "%username%"), habbo.getHabboInfo().getUsername())
@@ -111,7 +113,7 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
if (bots.size() == 1) {
Bot bot = bots.get(0);
- if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ message })) {
+ if(!WiredManager.triggerUserSays(room, bot.getRoomUnit(), message)) {
if (this.mode == 1) {
bot.shout(message);
} else {
@@ -119,13 +121,17 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
}
}
}
+ }
- return true;
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay()));
}
@Override
@@ -133,7 +139,7 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.mode = data.mode;
this.botName = data.bot_name;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java
index 469f666f..ec2222d5 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java
@@ -11,8 +11,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
@@ -45,7 +45,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
message.appendInt(0);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
- message.appendString(this.botName + ((char) 9) + this.message);
+ message.appendString(this.botName + "" + ((char) 9) + "" + this.message);
message.appendInt(1);
message.appendInt(this.mode);
message.appendInt(0);
@@ -109,7 +109,11 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ if (roomUnit == null) return;
+
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
@@ -127,28 +131,30 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
List bots = room.getBots(this.botName);
if (bots.size() != 1) {
- return false;
+ return;
}
Bot bot = bots.get(0);
- if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ m })) {
+ if(!WiredManager.triggerUserSays(room, bot.getRoomUnit(), m)) {
if (this.mode == 1) {
bot.whisper(m, habbo);
} else {
bot.talk(habbo.getHabboInfo().getUsername() + ": " + m);
}
}
-
- return true;
}
+ }
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay()));
}
@Override
@@ -156,7 +162,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.mode = data.mode;
this.botName = data.bot_name;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java
index d12fb444..5a72aac0 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java
@@ -12,7 +12,8 @@ import com.eu.habbo.habbohotel.rooms.RoomTileState;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer;
@@ -56,7 +57,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
roomUnit.getRoom().unIdle(roomUnit.getRoom().getHabbo(roomUnit));
room.sendComposer(new RoomUserEffectComposer(roomUnit, 4).compose());
- Emulator.getThreading().run(new SendRoomUnitEffectComposer(room, roomUnit), WiredHandler.TELEPORT_DELAY + 1000);
+ Emulator.getThreading().run(new SendRoomUnitEffectComposer(room, roomUnit), WiredManager.TELEPORT_DELAY + 1000);
if (tile == roomUnit.getCurrentLocation()) {
return;
@@ -79,8 +80,8 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
}
}
- Emulator.getThreading().run(() -> { roomUnit.isWiredTeleporting = true; }, Math.max(0, WiredHandler.TELEPORT_DELAY - 500));
- Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.x, tile.y, tile.getStackHeight() + (tile.state == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY);
+ Emulator.getThreading().run(() -> { roomUnit.isWiredTeleporting = true; }, Math.max(0, WiredManager.TELEPORT_DELAY - 500));
+ Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.x, tile.y, tile.getStackHeight() + (tile.state == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredManager.TELEPORT_DELAY);
}
@Override
@@ -97,7 +98,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
message.appendInt(item.getId());
@@ -152,14 +153,19 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+
if (this.items.isEmpty())
- return false;
+ return;
+
+ if (room.getLayout() == null)
+ return;
List bots = room.getBots(this.botName);
if (bots.size() != 1) {
- return false;
+ return;
}
Bot bot = bots.get(0);
@@ -170,15 +176,22 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
for (HabboItem item : this.items) {
if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) {
if (i == j) {
- teleportUnitToTile(bot.getRoomUnit(), room.getLayout().getTile(item.getX(), item.getY()));
- return true;
+ RoomTile tile = room.getLayout().getTile(item.getX(), item.getY());
+ if (tile != null) {
+ teleportUnitToTile(bot.getRoomUnit(), tile);
+ }
+ return;
} else {
j++;
}
}
}
+ }
- return true;
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
@@ -193,7 +206,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
}
}
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, itemIds, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.botName, itemIds, this.getDelay()));
}
@Override
@@ -203,7 +216,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.botName = data.bot_name;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java
index 461da90c..766744e3 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java
@@ -10,7 +10,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.set.hash.THashSet;
@@ -51,7 +52,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
message.appendInt(item.getId());
@@ -106,11 +107,12 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
List bots = room.getBots(this.botName);
if (this.items.isEmpty() || bots.size() != 1) {
- return true;
+ return;
}
Bot bot = bots.get(0);
@@ -126,11 +128,17 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
HabboItem item = possibleItems.get(Emulator.getRandom().nextInt(possibleItems.size()));
if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) {
- bot.getRoomUnit().setGoalLocation(room.getLayout().getTile(item.getX(), item.getY()));
+ if (room.getLayout() != null) {
+ bot.getRoomUnit().setGoalLocation(room.getLayout().getTile(item.getX(), item.getY()));
+ }
}
}
+ }
- return true;
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
@@ -145,7 +153,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
}
}
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, itemIds, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.botName, itemIds, this.getDelay()));
}
@Override
@@ -155,7 +163,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.botName = data.bot_name;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java
index 1f194598..7dc86a92 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java
@@ -7,10 +7,9 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.HabboItem;
-import com.eu.habbo.habbohotel.wired.WiredChangeDirectionSetting;
-import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.*;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
@@ -47,11 +46,14 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ if (room == null || room.getLayout() == null) return;
+
THashSet items = new THashSet<>();
for (HabboItem item : this.items.keySet()) {
- if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
+ if (item == null || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
items.add(item);
}
@@ -59,17 +61,22 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
this.items.remove(item);
}
- if (this.items.isEmpty()) return false;
+ if (this.items.isEmpty()) return;
for (Map.Entry entry : this.items.entrySet()) {
HabboItem item = entry.getKey();
- RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), entry.getValue().direction.getValue());
+ if (item == null || entry.getValue() == null) continue;
+
+ RoomTile itemTile = room.getLayout().getTile(item.getX(), item.getY());
+ if (itemTile == null) continue;
+
+ RoomTile targetTile = room.getLayout().getTileInFront(itemTile, entry.getValue().direction.getValue());
int count = 1;
while ((targetTile == null || targetTile.state == RoomTileState.INVALID || room.furnitureFitsAt(targetTile, item, item.getRotation(), false) != FurnitureMovementError.NONE) && count < 8) {
entry.getValue().direction = this.nextRotation(entry.getValue().direction);
- RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), entry.getValue().direction.getValue());
+ RoomTile tile = room.getLayout().getTileInFront(itemTile, entry.getValue().direction.getValue());
if (tile != null && tile.state != RoomTileState.INVALID) {
targetTile = tile;
}
@@ -80,47 +87,60 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
for (Map.Entry entry : this.items.entrySet()) {
HabboItem item = entry.getKey();
+ if (item == null || entry.getValue() == null) continue;
+
int newDirection = entry.getValue().direction.getValue();
- RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), newDirection);
+ RoomTile itemTile = room.getLayout().getTile(item.getX(), item.getY());
+ if (itemTile == null) continue;
+
+ RoomTile targetTile = room.getLayout().getTileInFront(itemTile, newDirection);
if(item.getRotation() != entry.getValue().rotation) {
- if(room.furnitureFitsAt(targetTile, item, entry.getValue().rotation, false) != FurnitureMovementError.NONE)
+ if(targetTile == null || room.furnitureFitsAt(targetTile, item, entry.getValue().rotation, false) != FurnitureMovementError.NONE)
continue;
room.moveFurniTo(entry.getKey(), targetTile, entry.getValue().rotation, null, true);
}
+ if (targetTile == null) continue;
+
boolean hasRoomUnits = false;
THashSet newOccupiedTiles = room.getLayout().getTilesAt(targetTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
for(RoomTile tile : newOccupiedTiles) {
for (RoomUnit _roomUnit : room.getRoomUnits(tile)) {
hasRoomUnits = true;
if(_roomUnit.getCurrentLocation() == targetTile) {
- Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{entry.getKey()}));
+ Emulator.getThreading().run(() -> {
+ WiredManager.triggerBotCollision(room, _roomUnit);
+ });
break;
}
}
}
- if (targetTile != null && targetTile.state != RoomTileState.INVALID && room.furnitureFitsAt(targetTile, item, item.getRotation(), false) == FurnitureMovementError.NONE) {
+ if (targetTile.state != RoomTileState.INVALID && room.furnitureFitsAt(targetTile, item, item.getRotation(), false) == FurnitureMovementError.NONE) {
if (!hasRoomUnits) {
RoomTile oldLocation = room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY());
double oldZ = entry.getKey().getZ();
- if(room.moveFurniTo(entry.getKey(), targetTile, item.getRotation(), null, false) == FurnitureMovementError.NONE) {
+ if(oldLocation != null && room.moveFurniTo(entry.getKey(), targetTile, item.getRotation(), null, false) == FurnitureMovementError.NONE) {
room.sendComposer(new FloorItemOnRollerComposer(entry.getKey(), null, oldLocation, oldZ, targetTile, entry.getKey().getZ(), 0, room).compose());
}
}
}
}
+ }
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return false;
}
@Override
public String getWiredData() {
ArrayList settings = new ArrayList<>(this.items.values());
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.startRotation, this.blockedAction, settings, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.startRotation, this.blockedAction, settings, this.getDelay()));
}
@Override
@@ -131,7 +151,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.startRotation = data.start_direction;
this.blockedAction = data.blocked_action;
@@ -195,7 +215,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
@Override
public void serializeWiredData(ServerMessage message, Room room) {
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (Map.Entry item : this.items.entrySet()) {
message.appendInt(item.getKey().getId());
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java
index 71345755..eece5048 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java
@@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -17,20 +18,20 @@ public class WiredEffectGiveEffect extends WiredEffectWhisper {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
int effectId;
try {
effectId = Integer.parseInt(this.message);
} catch (Exception e) {
- return false;
+ return;
}
- if (effectId >= 0) {
+ Room room = ctx.room();
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+
+ if (effectId >= 0 && roomUnit != null) {
room.giveEffect(roomUnit, effectId, Integer.MAX_VALUE);
- return true;
}
-
- return false;
}
-}
\ No newline at end of file
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java
index 468cadaa..da7261b1 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java
@@ -2,8 +2,8 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
-import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -18,17 +18,17 @@ public class WiredEffectGiveHandItem extends WiredEffectWhisper {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
try {
int itemId = Integer.parseInt(this.message);
- Habbo habbo = room.getHabbo(roomUnit);
+ Room room = ctx.room();
+ Habbo habbo = ctx.actor().map(room::getHabbo).orElse(null);
if (habbo != null) {
room.giveHandItem(habbo, itemId);
}
} catch (Exception e) {
}
- return false;
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java
index 7a54401f..0834f54d 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java
@@ -10,7 +10,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.hotelview.BonusRareComposer;
import gnu.trove.procedure.TObjectProcedure;
@@ -85,23 +86,27 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- Habbo habbo = room.getHabbo(roomUnit);
+ public void execute(WiredContext ctx) {
+ Habbo habbo = ctx.actor().map(unit -> ctx.room().getHabbo(unit)).orElse(null);
if (habbo == null)
- return false;
+ return;
if (this.amount > 0) {
habbo.givePoints(Emulator.getConfig().getInt("hotelview.promotional.points.type"), this.amount);
habbo.getClient().sendResponse(new BonusRareComposer(habbo));
}
+ }
- return true;
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.getDelay(), this.amount));
+ return WiredManager.getGson().toJson(new JsonData(this.getDelay(), this.amount));
}
@Override
@@ -110,7 +115,7 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
this.amount = 0;
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.amount = data.amount;
} else {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java
index 5af1cd99..56d1cf94 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java
@@ -10,7 +10,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.procedure.TObjectProcedure;
@@ -84,23 +85,27 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- Habbo habbo = room.getHabbo(roomUnit);
+ public void execute(WiredContext ctx) {
+ Habbo habbo = ctx.actor().map(unit -> ctx.room().getHabbo(unit)).orElse(null);
if (habbo == null)
- return false;
+ return;
if (this.amount > 0) {
habbo.getHabboStats().hofPoints += this.amount;
Emulator.getThreading().run(habbo.getHabboStats());
}
+ }
- return true;
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.amount, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.amount, this.getDelay()));
}
@Override
@@ -108,7 +113,7 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.amount = data.amount;
this.setDelay(data.delay);
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java
index a0aa38bf..94e40db0 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java
@@ -11,7 +11,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.procedure.TObjectProcedure;
@@ -85,21 +86,26 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- Habbo habbo = room.getHabbo(roomUnit);
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ Habbo habbo = ctx.actor().map(room::getHabbo).orElse(null);
if (habbo == null)
- return false;
+ return;
habbo.getHabboStats().respectPointsReceived += this.respects;
AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RespectEarned"), this.respects);
+ }
- return true;
+ @Override
+ @Deprecated
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.respects, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.respects, this.getDelay()));
}
@Override
@@ -107,7 +113,7 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.respects = data.amount;
this.setDelay(data.delay);
}
@@ -148,4 +154,4 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
this.delay = delay;
}
}
-}
\ No newline at end of file
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java
index fb6f5a76..a6c2bae3 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java
@@ -13,7 +13,8 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredGiveRewardItem;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.generic.alerts.UpdateFailedComposer;
@@ -26,19 +27,19 @@ import java.util.ArrayList;
import java.util.List;
public class WiredEffectGiveReward extends InteractionWiredEffect {
- public final static int LIMIT_ONCE = 0;
- public final static int LIMIT_N_DAY = 1;
- public final static int LIMIT_N_HOURS = 2;
- public final static int LIMIT_N_MINUTES = 3;
+ public static final int LIMIT_ONCE = 0;
+ public static final int LIMIT_N_DAY = 1;
+ public static final int LIMIT_N_HOURS = 2;
+ public static final int LIMIT_N_MINUTES = 3;
- public final static WiredEffectType type = WiredEffectType.GIVE_REWARD;
- public int limit;
- public int limitationInterval;
- public int given;
- public int rewardTime;
- public boolean uniqueRewards;
-
- public THashSet rewardItems = new THashSet<>();
+ public static final WiredEffectType type = WiredEffectType.GIVE_REWARD;
+
+ private int limit;
+ private int limitationInterval;
+ private int given;
+ private int rewardTime;
+ private boolean uniqueRewards;
+ private THashSet rewardItems = new THashSet<>();
public WiredEffectGiveReward(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -49,17 +50,29 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ if (roomUnit == null) return;
+
Habbo habbo = room.getHabbo(roomUnit);
- return habbo != null && WiredHandler.getReward(habbo, this);
+ if (habbo != null) {
+ WiredManager.getReward(habbo, this);
+ }
+ }
+
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
ArrayList rewards = new ArrayList<>(this.rewardItems);
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.limit, this.given, this.rewardTime, this.uniqueRewards, this.limitationInterval, rewards, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.limit, this.given, this.rewardTime, this.uniqueRewards, this.limitationInterval, rewards, this.getDelay()));
}
@Override
@@ -67,7 +80,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.limit = data.limit;
this.given = data.given;
@@ -207,7 +220,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
this.setDelay(settings.getDelay());
- WiredHandler.dropRewards(this.getId());
+ WiredManager.dropRewards(this.getId());
return true;
}
@@ -222,7 +235,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
@Override
protected long requiredCooldown() {
- return 0;
+ return COOLDOWN_NONE;
}
static class JsonData {
@@ -244,4 +257,58 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
this.delay = delay;
}
}
+
+ // Getters and Setters
+
+ public int getLimit() {
+ return this.limit;
+ }
+
+ public void setLimit(int limit) {
+ this.limit = limit;
+ }
+
+ public int getLimitationInterval() {
+ return this.limitationInterval;
+ }
+
+ public void setLimitationInterval(int limitationInterval) {
+ this.limitationInterval = limitationInterval;
+ }
+
+ public int getGiven() {
+ return this.given;
+ }
+
+ public void setGiven(int given) {
+ this.given = given;
+ }
+
+ public void incrementGiven() {
+ this.given++;
+ }
+
+ public int getRewardTime() {
+ return this.rewardTime;
+ }
+
+ public void setRewardTime(int rewardTime) {
+ this.rewardTime = rewardTime;
+ }
+
+ public boolean isUniqueRewards() {
+ return this.uniqueRewards;
+ }
+
+ public void setUniqueRewards(boolean uniqueRewards) {
+ this.uniqueRewards = uniqueRewards;
+ }
+
+ public THashSet getRewardItems() {
+ return this.rewardItems;
+ }
+
+ public void setRewardItems(THashSet rewardItems) {
+ this.rewardItems = rewardItems;
+ }
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java
index 10a73a12..c5c86e74 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java
@@ -11,7 +11,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.iterator.TObjectIntIterator;
@@ -32,7 +33,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
private int score;
private int count;
- private final TObjectIntMap> data = new TObjectIntHashMap<>();
+ private TObjectIntMap> data = new TObjectIntHashMap<>();
public WiredEffectGiveScore(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -43,14 +44,15 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- Habbo habbo = room.getHabbo(roomUnit);
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ Habbo habbo = ctx.actor().map(room::getHabbo).orElse(null);
if (habbo != null && habbo.getHabboInfo().getCurrentGame() != null) {
Game game = room.getGame(habbo.getHabboInfo().getCurrentGame());
if (game == null)
- return false;
+ return;
int gameStartTime = game.getStartTime();
@@ -70,7 +72,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
habbo.getHabboInfo().getGamePlayer().addScore(this.score, true);
- return true;
+ return;
}
} else {
iterator.remove();
@@ -89,16 +91,18 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
if (habbo.getHabboInfo().getGamePlayer() != null) {
habbo.getHabboInfo().getGamePlayer().addScore(this.score, true);
}
-
- return true;
}
+ }
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.score, this.count, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.score, this.count, this.getDelay()));
}
@Override
@@ -106,7 +110,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.score = data.score;
this.count = data.count;
this.setDelay(data.delay);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java
index af27870e..7b2c0efd 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java
@@ -12,7 +12,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.map.hash.TIntIntHashMap;
@@ -27,7 +28,7 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect {
private int count;
private GameTeamColors teamColor = GameTeamColors.RED;
- private final TIntIntHashMap startTimes = new TIntIntHashMap();
+ private TIntIntHashMap startTimes = new TIntIntHashMap();
public WiredEffectGiveScoreToTeam(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
@@ -38,7 +39,8 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
for (Game game : room.getGames()) {
if (game != null && game.state.equals(GameState.RUNNING)) {
int c = this.startTimes.get(game.getStartTime());
@@ -54,13 +56,17 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect {
}
}
}
+ }
- return true;
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.points, this.count, this.teamColor, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.points, this.count, this.teamColor, this.getDelay()));
}
@Override
@@ -68,7 +74,7 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.points = data.score;
this.count = data.count;
this.teamColor = data.team;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java
index 4b4a686f..5664771a 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java
@@ -13,7 +13,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
@@ -37,8 +38,9 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- Habbo habbo = room.getHabbo(roomUnit);
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ Habbo habbo = ctx.actor().map(room::getHabbo).orElse(null);
if (habbo != null) {
WiredGame game = (WiredGame) room.getGameOrCreate(WiredGame.class);
@@ -52,16 +54,18 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
if(habbo.getHabboInfo().getGamePlayer() == null) {
game.addHabbo(habbo, this.teamColor);
}
-
- return true;
}
+ }
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.teamColor, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.teamColor, this.getDelay()));
}
@Override
@@ -69,7 +73,7 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.teamColor = data.team;
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java
index cb796b17..c4f765df 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java
@@ -13,7 +13,8 @@ import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer;
@@ -39,21 +40,19 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- if (room == null)
- return false;
-
- Habbo habbo = room.getHabbo(roomUnit);
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ Habbo habbo = ctx.actor().map(room::getHabbo).orElse(null);
if (habbo != null) {
if (habbo.hasPermission(Permission.ACC_UNKICKABLE)) {
habbo.whisper(Emulator.getTexts().getValue("hotel.wired.kickexception.unkickable"));
- return true;
+ return;
}
if (habbo.getHabboInfo().getId() == room.getOwnerId()) {
habbo.whisper(Emulator.getTexts().getValue("hotel.wired.kickexception.owner"));
- return true;
+ return;
}
room.giveEffect(habbo, 4, 2);
@@ -62,16 +61,18 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(this.message, habbo, habbo, RoomChatMessageBubbles.ALERT)));
Emulator.getThreading().run(new RoomUnitKick(habbo, room, true), 2000);
-
- return true;
}
+ }
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.message, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.message, this.getDelay()));
}
@Override
@@ -79,7 +80,7 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.message = data.message;
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java
index 500ef04d..881c9efd 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java
@@ -12,7 +12,8 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
@@ -34,8 +35,9 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- Habbo habbo = room.getHabbo(roomUnit);
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ Habbo habbo = ctx.actor().map(room::getHabbo).orElse(null);
if (habbo != null) {
if (habbo.getHabboInfo().getCurrentGame() != null) {
@@ -47,16 +49,20 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
if (game != null) {
game.removeHabbo(habbo);
- return true;
}
}
}
+ }
+
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.getDelay()));
}
@Override
@@ -64,7 +70,7 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
}
else {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java
index d793cc23..5c11be6f 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java
@@ -8,8 +8,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings;
import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
@@ -45,10 +46,14 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
if(this.settings.isEmpty())
- return true;
+ return;
+
+ if (room.getLayout() == null)
+ return;
for (WiredMatchFurniSetting setting : this.settings) {
HabboItem item = room.getHabboItem(setting.item_id);
@@ -61,6 +66,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
}
RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
+ if (oldLocation == null) continue;
double oldZ = item.getZ();
if(this.direction && !this.position) {
@@ -84,14 +90,18 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
}
}
+ }
- return true;
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
this.refresh();
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.state, this.direction, this.position, new ArrayList(this.settings), this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.state, this.direction, this.position, new ArrayList(this.settings), this.getDelay()));
}
@Override
@@ -99,7 +109,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.state = data.state;
this.direction = data.direction;
@@ -155,7 +165,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
this.refresh();
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.settings.size());
for (WiredMatchFurniSetting item : this.settings)
@@ -196,7 +206,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
for (int i = 0; i < itemsCount; i++) {
int itemId = settings.getFurniIds()[i];
- HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
+ HabboItem it = room.getHabboItem(itemId);
if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId));
@@ -223,18 +233,8 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null && room.isLoaded()) {
- THashSet remove = new THashSet<>();
-
- for (WiredMatchFurniSetting setting : this.settings) {
- HabboItem item = room.getHabboItem(setting.item_id);
- if (item == null) {
- remove.add(setting);
- }
- }
-
- for (WiredMatchFurniSetting setting : remove) {
- this.settings.remove(setting);
- }
+ // Use removeIf for O(n) instead of O(n²) with separate remove set
+ this.settings.removeIf(setting -> room.getHabboItem(setting.item_id) == null);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java
index a4e7f11c..1cf00a46 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java
@@ -8,8 +8,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredSimulation;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
@@ -36,7 +37,10 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ if (room.getLayout() == null) return;
+
THashSet items = new THashSet<>();
for (HabboItem item : this.items) {
@@ -47,13 +51,18 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
this.items.removeAll(items);
for (HabboItem item : this.items) {
+ if (item == null) continue;
+
RoomTile t = room.getLayout().getTile(item.getX(), item.getY());
+ if (t == null) continue;
RoomUnit target = room.getRoomUnits().stream().min(Comparator.comparingDouble(a -> a.getCurrentLocation().distance(t))).orElse(null);
if (target != null) {
if (target.getCurrentLocation().distance(t) <= 1) {
- Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, target, room, new Object[]{item}), 500);
+ Emulator.getThreading().run(() -> {
+ WiredManager.triggerBotCollision(room, target);
+ }, 500);
continue;
}
@@ -93,12 +102,63 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
}
}
}
+ }
+
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
+ @Override
+ public boolean simulate(WiredContext ctx, WiredSimulation simulation) {
+ Room room = ctx.room();
+ if (room.getLayout() == null) return true;
+
+ for (HabboItem item : this.items) {
+ if (item == null) continue;
+
+ WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item);
+ RoomTile t = room.getLayout().getTile(currentPos.x, currentPos.y);
+ if (t == null) continue;
+
+ RoomUnit target = room.getRoomUnits().stream()
+ .min(Comparator.comparingDouble(a -> a.getCurrentLocation().distance(t)))
+ .orElse(null);
+
+ if (target != null && target.getCurrentLocation().distance(t) > 1) {
+ int x = 0;
+ int y = 0;
+
+ if (target.getX() == currentPos.x) {
+ y = currentPos.y < target.getY() ? -1 : 1;
+ } else if (target.getY() == currentPos.y) {
+ x = currentPos.x < target.getX() ? -1 : 1;
+ } else if (target.getX() - currentPos.x > target.getY() - currentPos.y) {
+ x = target.getX() - currentPos.x > 0 ? -1 : 1;
+ } else {
+ y = target.getY() - currentPos.y > 0 ? -1 : 1;
+ }
+
+ short newX = (short) (currentPos.x + x);
+ short newY = (short) (currentPos.y + y);
+
+ if (!simulation.isTileValidForItem(newX, newY, item)) {
+ return false;
+ }
+
+ if (!simulation.moveItem(item, newX, newY, currentPos.z, currentPos.rotation)) {
+ return false;
+ }
+ }
+ }
+
return true;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
@@ -110,7 +170,7 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
@@ -161,7 +221,7 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
this.items.remove(item);
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
message.appendInt(item.getId());
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java
index 90e5bdfe..5ebb283d 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java
@@ -10,7 +10,9 @@ import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredSimulation;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
@@ -29,7 +31,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
private final List items = new ArrayList<>();
private int direction;
private int spacing = 1;
- private final Map indexOffset = new LinkedHashMap<>();
+ private Map indexOffset = new LinkedHashMap<>();
public WiredEffectMoveFurniTo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -69,11 +71,14 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ if (room == null || room.getLayout() == null) return;
+
List items = new ArrayList<>();
for (HabboItem item : this.items) {
- if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
+ if (item == null || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
items.add(item);
}
@@ -82,9 +87,10 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
}
if (this.items.isEmpty())
- return false;
+ return;
- if (stuff != null) {
+ Object[] stuff = ctx.legacySettings();
+ if (stuff != null && stuff.length > 0) {
for (Object object : stuff) {
if (object instanceof HabboItem) {
HabboItem targetItem = this.items.get(Emulator.getRandom().nextInt(this.items.size()));
@@ -100,7 +106,10 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
RoomTile objectTile = room.getLayout().getTile(targetItem.getX(), targetItem.getY());
if (objectTile != null) {
- THashSet refreshTiles = room.getLayout().getTilesAt(room.getLayout().getTile(((HabboItem) object).getX(), ((HabboItem) object).getY()), ((HabboItem) object).getBaseItem().getWidth(), ((HabboItem) object).getBaseItem().getLength(), ((HabboItem) object).getRotation());
+ RoomTile sourceTile = room.getLayout().getTile(((HabboItem) object).getX(), ((HabboItem) object).getY());
+ if (sourceTile == null) continue;
+
+ THashSet refreshTiles = room.getLayout().getTilesAt(sourceTile, ((HabboItem) object).getBaseItem().getWidth(), ((HabboItem) object).getBaseItem().getLength(), ((HabboItem) object).getRotation());
RoomTile tile = room.getLayout().getTileInFront(objectTile, this.direction, indexOffset);
if (tile == null || !tile.getAllowStack()) {
@@ -108,8 +117,16 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
tile = room.getLayout().getTileInFront(objectTile, this.direction, indexOffset);
}
+ if(tile == null) {
+ continue;
+ }
+
room.sendComposer(new FloorItemOnRollerComposer((HabboItem) object, null, tile, tile.getStackHeight() - ((HabboItem) object).getZ(), room).compose());
- refreshTiles.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(((HabboItem) object).getX(), ((HabboItem) object).getY()), ((HabboItem) object).getBaseItem().getWidth(), ((HabboItem) object).getBaseItem().getLength(), ((HabboItem) object).getRotation()));
+
+ RoomTile newSourceTile = room.getLayout().getTile(((HabboItem) object).getX(), ((HabboItem) object).getY());
+ if (newSourceTile != null) {
+ refreshTiles.addAll(room.getLayout().getTilesAt(newSourceTile, ((HabboItem) object).getBaseItem().getWidth(), ((HabboItem) object).getBaseItem().getLength(), ((HabboItem) object).getRotation()));
+ }
room.updateTiles(refreshTiles);
this.indexOffset.put(targetItem.getId(), indexOffset);
}
@@ -117,7 +134,47 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
}
}
}
+ }
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
+ @Override
+ public boolean simulate(WiredContext ctx, WiredSimulation simulation) {
+ Room room = ctx.room();
+ if (room == null || room.getLayout() == null) return true;
+
+ Object[] stuff = ctx.legacySettings();
+ if (stuff == null || stuff.length == 0) return true;
+
+ for (Object object : stuff) {
+ if (object instanceof HabboItem) {
+ HabboItem item = (HabboItem) object;
+
+ if (this.items.isEmpty()) continue;
+ HabboItem targetItem = this.items.get(0);
+ if (targetItem == null) continue;
+
+ WiredSimulation.SimulatedPosition targetPos = simulation.getItemPosition(targetItem);
+ RoomTile objectTile = room.getLayout().getTile(targetPos.x, targetPos.y);
+ if (objectTile == null) continue;
+
+ RoomTile tile = room.getLayout().getTileInFront(objectTile, this.direction, 0);
+ if (tile == null) continue;
+
+ WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item);
+ if (!simulation.isTileValidForItem(tile.x, tile.y, item)) {
+ return false;
+ }
+ if (!simulation.moveItem(item, tile.x, tile.y, tile.getStackHeight(), currentPos.rotation)) {
+ return false;
+ }
+ }
+ }
+
return true;
}
@@ -134,7 +191,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
this.items.remove(item);
}
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.direction,
this.spacing,
this.getDelay(),
@@ -156,7 +213,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
message.appendInt(item.getId());
@@ -178,7 +235,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.direction = data.direction;
this.spacing = data.spacing;
this.setDelay(data.delay);
@@ -237,4 +294,4 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
this.itemIds = itemIds;
}
}
-}
\ No newline at end of file
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java
index aaadf032..aa49c097 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java
@@ -8,7 +8,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredSimulation;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
@@ -34,7 +36,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
private THashSet items;
- private final THashMap lastDirections;
+ private THashMap lastDirections;
public WiredEffectMoveFurniTowards(ResultSet set, Item baseItem) throws SQLException {
@@ -53,7 +55,10 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
List availableDirections = new ArrayList<>();
RoomLayout layout = room.getLayout();
+ if (layout == null) return availableDirections;
+
RoomTile currentTile = layout.getTile(item.getX(), item.getY());
+ if (currentTile == null) return availableDirections;
RoomUserRotation[] rotations = new RoomUserRotation[]{RoomUserRotation.NORTH, RoomUserRotation.EAST, RoomUserRotation.SOUTH, RoomUserRotation.WEST};
@@ -82,7 +87,8 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
THashSet items = new THashSet<>();
@@ -135,7 +141,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
target = roomUnitsAtTile.iterator().next();
if (i == 0) { // i = 0 means right next to it
collided = true;
- Emulator.getThreading().run(new WiredCollissionRunnable(target, room, new Object[]{item}));
+ Emulator.getThreading().run(new WiredCollissionRunnable(target, room));
}
break;
}
@@ -213,9 +219,11 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
}
}
- RoomTile newTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), moveDirection.getValue());
-
RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
+ if (oldLocation == null) continue;
+
+ RoomTile newTile = room.getLayout().getTileInFront(oldLocation, moveDirection.getValue());
+
double oldZ = item.getZ();
if(newTile != null) {
@@ -227,13 +235,83 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
}
}
}
+ }
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
+ @Override
+ public boolean simulate(WiredContext ctx, WiredSimulation simulation) {
+ Room room = ctx.room();
+ RoomLayout layout = room.getLayout();
+ if (layout == null) return true;
+
+ for (HabboItem item : this.items) {
+ if (item == null) continue;
+
+ WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item);
+ RoomTile currentTile = layout.getTile(currentPos.x, currentPos.y);
+ if (currentTile == null) continue;
+
+ RoomUnit target = null;
+
+ for (int i = 0; i < 3; i++) {
+ if (target != null) break;
+
+ RoomUserRotation[] rotations = new RoomUserRotation[]{RoomUserRotation.NORTH, RoomUserRotation.EAST, RoomUserRotation.SOUTH, RoomUserRotation.WEST};
+
+ for (RoomUserRotation rot : rotations) {
+ RoomTile startTile = currentTile;
+
+ for (int ii = 0; ii <= i; ii++) {
+ if (startTile == null) break;
+ startTile = layout.getTileInFront(startTile, rot.getValue());
+ }
+
+ if (startTile != null && layout.tileExists(startTile.x, startTile.y)) {
+ Collection roomUnitsAtTile = room.getRoomUnitsAt(startTile);
+ if (!roomUnitsAtTile.isEmpty()) {
+ target = roomUnitsAtTile.iterator().next();
+ break;
+ }
+ }
+ }
+ }
+
+ if (target != null) {
+ RoomUserRotation moveDirection;
+
+ if (target.getX() == currentPos.x) {
+ moveDirection = currentPos.y < target.getY() ? RoomUserRotation.SOUTH : RoomUserRotation.NORTH;
+ } else if (target.getY() == currentPos.y) {
+ moveDirection = currentPos.x < target.getX() ? RoomUserRotation.EAST : RoomUserRotation.WEST;
+ } else if (target.getX() - currentPos.x > target.getY() - currentPos.y) {
+ moveDirection = target.getX() - currentPos.x > 0 ? RoomUserRotation.EAST : RoomUserRotation.WEST;
+ } else {
+ moveDirection = target.getY() - currentPos.y > 0 ? RoomUserRotation.SOUTH : RoomUserRotation.NORTH;
+ }
+
+ RoomTile newTile = layout.getTileInFront(currentTile, moveDirection.getValue());
+ if (newTile != null && newTile.state != RoomTileState.INVALID) {
+ if (!simulation.isTileValidForItem(newTile.x, newTile.y, item)) {
+ return false;
+ }
+ if (!simulation.moveItem(item, newTile.x, newTile.y, currentPos.z, currentPos.rotation)) {
+ return false;
+ }
+ }
+ }
+ }
+
return true;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
@@ -245,7 +323,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
for (Integer id: data.itemIds) {
@@ -297,7 +375,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
this.items.remove(item);
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
message.appendInt(item.getId());
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java
index 9aa91491..37557c37 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java
@@ -9,7 +9,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredSimulation;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
@@ -17,30 +19,33 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implements ICycleable {
public static final WiredEffectType type = WiredEffectType.MOVE_ROTATE;
- private final THashSet items = new THashSet<>(WiredHandler.MAXIMUM_FURNI_SELECTION / 2);
+ // Use LinkedHashSet to preserve insertion order for consistent movement
+ private final Set items = new LinkedHashSet<>(WiredManager.MAXIMUM_FURNI_SELECTION / 2);
private int direction;
private int rotation;
- private final THashSet itemCooldowns;
+ // Use thread-safe set for cooldowns since execute() can be called from async threads
+ private final Set itemCooldowns = ConcurrentHashMap.newKeySet();
+ // Pre-selected directions from simulation (itemId -> direction)
+ private final Map preSelectedDirections = new ConcurrentHashMap<>();
public WiredEffectMoveRotateFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
- this.itemCooldowns = new THashSet<>();
}
public WiredEffectMoveRotateFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
- this.itemCooldowns = new THashSet<>();
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
// remove items that are no longer in the room
this.items.removeIf(item -> Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
@@ -54,7 +59,11 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
double oldZ = item.getZ();
if(this.direction > 0) {
- RoomUserRotation moveDirection = this.getMovementDirection();
+ // Use pre-selected direction if available, otherwise pick random
+ RoomUserRotation moveDirection = this.preSelectedDirections.remove(item.getId());
+ if (moveDirection == null) {
+ moveDirection = this.getMovementDirection();
+ }
newLocation = room.getLayout().getTile(
(short) (item.getX() + ((moveDirection == RoomUserRotation.WEST || moveDirection == RoomUserRotation.NORTH_WEST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : (((moveDirection == RoomUserRotation.EAST || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.NORTH_EAST) ? 1 : 0)))),
(short) (item.getY() + ((moveDirection == RoomUserRotation.NORTH || moveDirection == RoomUserRotation.NORTH_EAST || moveDirection == RoomUserRotation.NORTH_WEST) ? 1 : ((moveDirection == RoomUserRotation.SOUTH || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : 0)))
@@ -73,13 +82,54 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
}
}
}
+ }
+ @Override
+ public boolean simulate(WiredContext ctx, WiredSimulation simulation) {
+ // Clear any previous pre-selected directions
+ this.preSelectedDirections.clear();
+
+ for (HabboItem item : this.items) {
+ if (item == null) continue;
+
+ WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item);
+ short newX = currentPos.x;
+ short newY = currentPos.y;
+
+ if (this.direction > 0) {
+ // Pick the actual random direction now (same logic as getMovementDirection)
+ RoomUserRotation selectedDirection = this.getMovementDirection();
+
+ // Calculate target position for the selected direction
+ short testX = (short) (currentPos.x + ((selectedDirection == RoomUserRotation.WEST || selectedDirection == RoomUserRotation.NORTH_WEST || selectedDirection == RoomUserRotation.SOUTH_WEST) ? -1 :
+ (((selectedDirection == RoomUserRotation.EAST || selectedDirection == RoomUserRotation.SOUTH_EAST || selectedDirection == RoomUserRotation.NORTH_EAST) ? 1 : 0))));
+ short testY = (short) (currentPos.y + ((selectedDirection == RoomUserRotation.NORTH || selectedDirection == RoomUserRotation.NORTH_EAST || selectedDirection == RoomUserRotation.NORTH_WEST) ? 1 :
+ ((selectedDirection == RoomUserRotation.SOUTH || selectedDirection == RoomUserRotation.SOUTH_EAST || selectedDirection == RoomUserRotation.SOUTH_WEST) ? -1 : 0)));
+
+ // Validate this specific direction
+ if (!simulation.isTileValidForItem(testX, testY, item)) {
+ return false; // This specific move would fail
+ }
+
+ // Store the pre-selected direction for execution
+ this.preSelectedDirections.put(item.getId(), selectedDirection);
+ newX = testX;
+ newY = testY;
+ }
+
+ if (newX != currentPos.x || newY != currentPos.y) {
+ if (!simulation.moveItem(item, newX, newY, currentPos.z, currentPos.rotation)) {
+ return false;
+ }
+ }
+ }
+
return true;
}
@Override
public String getWiredData() {
- THashSet itemsToRemove = new THashSet<>(this.items.size() / 2);
+ List itemsToRemove = new ArrayList<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
@@ -92,7 +142,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
this.items.remove(item);
}
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.direction,
this.rotation,
this.getDelay(),
@@ -106,7 +156,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.direction = data.direction;
this.rotation = data.rotation;
@@ -153,19 +203,19 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
@Override
public void serializeWiredData(ServerMessage message, Room room) {
- THashSet items = new THashSet<>();
+ List itemsToRemove = new ArrayList<>();
for (HabboItem item : this.items) {
if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
- items.add(item);
+ itemsToRemove.add(item);
}
- for (HabboItem item : items) {
+ for (HabboItem item : itemsToRemove) {
this.items.remove(item);
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
message.appendInt(item.getId());
@@ -198,7 +248,10 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
this.items.clear();
for (int i = 0; i < count; i++) {
- this.items.add(room.getHabboItem(settings.getFurniIds()[i]));
+ HabboItem item = room.getHabboItem(settings.getFurniIds()[i]);
+ if (item != null) {
+ this.items.add(item);
+ }
}
this.setDelay(settings.getDelay());
@@ -214,8 +267,6 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
* @return new rotation
*/
private int getNewRotation(HabboItem item) {
- int rotationToAdd = 0;
-
if(item.getMaximumRotations() == 2) {
return item.getRotation() == 0 ? 4 : 0;
}
@@ -310,6 +361,12 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
@Override
public void cycle(Room room) {
this.itemCooldowns.clear();
+ this.preSelectedDirections.clear();
+ }
+
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
static class JsonData {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java
index bfb81afa..ce053643 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java
@@ -11,7 +11,8 @@ import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer;
@@ -62,27 +63,33 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
if (roomUnit == null)
- return true;
+ return;
+ Room room = ctx.room();
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
if (room.hasRights(habbo))
- return false;
+ return;
room.muteHabbo(habbo, 60);
habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(this.message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), habbo, habbo, RoomChatMessageBubbles.WIRED)));
}
+ }
- return true;
+ @Override
+ @Deprecated
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.getDelay(),
this.length,
this.message
@@ -94,7 +101,7 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.length = data.length;
this.message = data.message;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java
index c11afb94..e0abd1da 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java
@@ -9,7 +9,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.threading.runnables.WiredResetTimers;
import gnu.trove.procedure.TObjectProcedure;
@@ -73,15 +74,20 @@ public class WiredEffectResetTimers extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
Emulator.getThreading().run(new WiredResetTimers(room), this.delay);
+ }
- return true;
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.getDelay()
));
}
@@ -91,7 +97,7 @@ public class WiredEffectResetTimers extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.delay = data.delay;
} else {
try {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java
index edfe89ff..7e1ba81d 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java
@@ -10,9 +10,10 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomTileState;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer;
@@ -57,7 +58,7 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
roomUnit.getRoom().unIdle(roomUnit.getRoom().getHabbo(roomUnit));
room.sendComposer(new RoomUserEffectComposer(roomUnit, 4).compose());
- Emulator.getThreading().run(new SendRoomUnitEffectComposer(room, roomUnit), WiredHandler.TELEPORT_DELAY + 1000);
+ Emulator.getThreading().run(new SendRoomUnitEffectComposer(room, roomUnit), WiredManager.TELEPORT_DELAY + 1000);
if (tile == roomUnit.getCurrentLocation()) {
return;
@@ -80,8 +81,8 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
}
}
- Emulator.getThreading().run(() -> { roomUnit.isWiredTeleporting = true; }, Math.max(0, WiredHandler.TELEPORT_DELAY - 500));
- Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.x, tile.y, tile.getStackHeight() + (tile.state == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY);
+ Emulator.getThreading().run(() -> { roomUnit.isWiredTeleporting = true; }, Math.max(0, WiredManager.TELEPORT_DELAY - 500));
+ Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.x, tile.y, tile.getStackHeight() + (tile.state == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredManager.TELEPORT_DELAY);
}
@Override
@@ -97,7 +98,7 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
this.items.remove(item);
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
message.appendInt(item.getId());
@@ -162,24 +163,39 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+
+ if (roomUnit == null || room == null || room.getLayout() == null) {
+ return;
+ }
+
this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId()
|| Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
if (!this.items.isEmpty()) {
int i = Emulator.getRandom().nextInt(this.items.size());
HabboItem item = this.items.get(i);
+
+ if (item == null) return;
- teleportUnitToTile(roomUnit, room.getLayout().getTile(item.getX(), item.getY()));
- return true;
+ RoomTile tile = room.getLayout().getTile(item.getX(), item.getY());
+ if (tile != null) {
+ teleportUnitToTile(roomUnit, tile);
+ }
}
+ }
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
@@ -191,7 +207,7 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
@@ -236,7 +252,7 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
@Override
protected long requiredCooldown() {
- return 50L;
+ return COOLDOWN_DEFAULT;
}
static class JsonData {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java
index db6c1046..4daefe37 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java
@@ -19,9 +19,10 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
@@ -106,7 +107,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items) {
message.appendInt(item.getId());
@@ -172,8 +173,9 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- Habbo habbo = room.getHabbo(roomUnit);
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ Habbo habbo = ctx.actor().map(unit -> room.getHabbo(unit)).orElse(null);
THashSet itemsToRemove = new THashSet<>();
for (HabboItem item : this.items) {
@@ -200,13 +202,17 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
}
this.items.removeAll(itemsToRemove);
+ }
- return true;
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
@@ -218,7 +224,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java
index d35a9aa9..bf4c7a22 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java
@@ -19,8 +19,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
@@ -31,7 +32,6 @@ import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -42,47 +42,45 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
private final THashSet items = new THashSet<>();
- private static final List> FORBIDDEN_TYPES;
-
- static {
- FORBIDDEN_TYPES = new ArrayList<>(Arrays.asList(
- InteractionWired.class,
- InteractionTeleport.class,
- InteractionPushable.class,
- InteractionTagPole.class,
- InteractionTagField.class,
- InteractionCrackable.class,
- InteractionGameScoreboard.class,
- InteractionGameGate.class,
- InteractionFreezeTile.class,
- InteractionFreezeBlock.class,
- InteractionFreezeExitTile.class,
- InteractionBattleBanzaiTeleporter.class,
- InteractionBattleBanzaiTile.class,
- InteractionMonsterPlantSeed.class,
- InteractionPetBreedingNest.class,
- InteractionPetDrink.class,
- InteractionPetFood.class,
- InteractionPetToy.class,
- InteractionBadgeDisplay.class,
- InteractionClothing.class,
- InteractionVendingMachine.class,
- InteractionGift.class,
- InteractionPressurePlate.class,
- InteractionMannequin.class,
- InteractionGymEquipment.class,
- InteractionHopper.class,
- InteractionObstacle.class,
- InteractionOneWayGate.class,
- InteractionPuzzleBox.class,
- InteractionRoller.class,
- InteractionSwitch.class,
- InteractionTent.class,
- InteractionTrap.class,
- InteractionTrophy.class,
- InteractionWater.class
- ));
- }
+ private static final List> FORBIDDEN_TYPES = new ArrayList>() {
+ {
+ this.add(InteractionWired.class);
+ this.add(InteractionTeleport.class);
+ this.add(InteractionPushable.class);
+ this.add(InteractionTagPole.class);
+ this.add(InteractionTagField.class);
+ this.add(InteractionCrackable.class);
+ this.add(InteractionGameScoreboard.class);
+ this.add(InteractionGameGate.class);
+ this.add(InteractionFreezeTile.class);
+ this.add(InteractionFreezeBlock.class);
+ this.add(InteractionFreezeExitTile.class);
+ this.add(InteractionBattleBanzaiTeleporter.class);
+ this.add(InteractionBattleBanzaiTile.class);
+ this.add(InteractionMonsterPlantSeed.class);
+ this.add(InteractionPetBreedingNest.class);
+ this.add(InteractionPetDrink.class);
+ this.add(InteractionPetFood.class);
+ this.add(InteractionPetToy.class);
+ this.add(InteractionBadgeDisplay.class);
+ this.add(InteractionClothing.class);
+ this.add(InteractionVendingMachine.class);
+ this.add(InteractionGift.class);
+ this.add(InteractionPressurePlate.class);
+ this.add(InteractionMannequin.class);
+ this.add(InteractionGymEquipment.class);
+ this.add(InteractionHopper.class);
+ this.add(InteractionObstacle.class);
+ this.add(InteractionOneWayGate.class);
+ this.add(InteractionPuzzleBox.class);
+ this.add(InteractionRoller.class);
+ this.add(InteractionSwitch.class);
+ this.add(InteractionTent.class);
+ this.add(InteractionTrap.class);
+ this.add(InteractionTrophy.class);
+ this.add(InteractionWater.class);
+ }
+ };
public WiredEffectToggleRandom(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -106,7 +104,7 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items) {
message.appendInt(item.getId());
@@ -172,7 +170,8 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
THashSet items = this.items;
for (HabboItem item : items) {
@@ -188,12 +187,17 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
LOGGER.error("Caught exception", e);
}
}
- return true;
+ }
+
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
@@ -205,7 +209,7 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java
index 9b7e9064..3a14c42c 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java
@@ -9,9 +9,10 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
@@ -51,7 +52,7 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
this.items.remove(item);
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items) {
message.appendInt(item.getId());
@@ -116,44 +117,81 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
return true;
}
+ /**
+ * Maximum recursion depth to prevent infinite loops when trigger stacks call each other.
+ */
+ private static final int MAX_STACK_DEPTH = 10;
+
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
-
- if (stuff == null || (stuff.length >= 1 && stuff[stuff.length - 1] instanceof WiredEffectTriggerStacks)) {
- return false;
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
+ RoomUnit roomUnit = ctx.actor().orElse(null);
+ Object[] stuff = ctx.legacyStuff();
+
+ // Prevent infinite recursion by checking for WiredEffectTriggerStacks in the call chain
+ // and limiting the recursion depth
+ int stackDepth = 0;
+ if (stuff != null) {
+ for (Object obj : stuff) {
+ if (obj instanceof WiredEffectTriggerStacks) {
+ stackDepth++;
+ // If this specific stack is already in the chain, prevent infinite loop
+ if (obj == this) {
+ return;
+ }
+ }
+ }
+ }
+
+ // Prevent excessive recursion depth
+ if (stackDepth >= MAX_STACK_DEPTH) {
+ return;
}
THashSet usedTiles = new THashSet<>();
- boolean found;
-
for (HabboItem item : this.items) {
- //if(item instanceof InteractionWiredTrigger)
- {
- found = false;
- for (RoomTile tile : usedTiles) {
- if (tile.x == item.getX() && tile.y == item.getY()) {
- found = true;
- break;
- }
+ if (item == null) continue;
+
+ boolean found = false;
+ for (RoomTile tile : usedTiles) {
+ if (tile.x == item.getX() && tile.y == item.getY()) {
+ found = true;
+ break;
}
+ }
- if (!found) {
- usedTiles.add(room.getLayout().getTile(item.getX(), item.getY()));
+ if (!found) {
+ RoomTile tile = room.getLayout().getTile(item.getX(), item.getY());
+ if (tile != null) {
+ usedTiles.add(tile);
}
}
}
- Object[] newStuff = new Object[stuff.length + 1];
+
+ // Create new stuff array with this trigger stack added for recursion tracking
+ Object[] newStuff;
+ if (stuff != null) {
+ newStuff = new Object[stuff.length + 1];
System.arraycopy(stuff, 0, newStuff, 0, stuff.length);
newStuff[newStuff.length - 1] = this;
- WiredHandler.executeEffectsAtTiles(usedTiles, roomUnit, room, newStuff);
-
- return true;
+ } else {
+ newStuff = new Object[] { this };
}
+
+ WiredManager.executeEffectsAtTiles(usedTiles, roomUnit, room, newStuff);
+ }
+
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
@@ -165,7 +203,7 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
@@ -205,7 +243,7 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
@Override
protected long requiredCooldown() {
- return 250;
+ return COOLDOWN_TRIGGER_STACKS;
}
static class JsonData {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java
index 6514ac0d..45744c93 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java
@@ -7,14 +7,11 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.permissions.Permission;
-import com.eu.habbo.habbohotel.rooms.Room;
-import com.eu.habbo.habbohotel.rooms.RoomChatMessage;
-import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
-import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer;
@@ -91,35 +88,38 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public void execute(WiredContext ctx) {
+ Room room = ctx.room();
if (this.message.length() > 0) {
+ RoomUnit roomUnit = ctx.actor().orElse(null);
if (roomUnit != null) {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
String msg = this.message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + "");
habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(msg, habbo, habbo, RoomChatMessageBubbles.WIRED)));
- Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, roomUnit, room, new Object[]{ msg }));
if (habbo.getRoomUnit().isIdle()) {
habbo.getRoomUnit().getRoom().unIdle(habbo);
}
- return true;
}
} else {
for (Habbo h : room.getHabbos()) {
h.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(this.message.replace("%user%", h.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), h, h, RoomChatMessageBubbles.WIRED)));
}
-
- return true;
}
}
+ }
+
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.message, this.getDelay()));
+ return WiredManager.getGson().toJson(new JsonData(this.message, this.getDelay()));
}
@Override
@@ -127,7 +127,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.message = data.message;
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java
index a77c1189..8f859fd2 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java
@@ -23,7 +23,7 @@ public class WiredBlob extends InteractionDefault {
ACTIVE("0"),
USED("1");
- private final String state;
+ private String state;
WiredBlobState(String state) {
this.state = state;
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraOrEval.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraOrEval.java
index 0e58c51f..0f1feb67 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraOrEval.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraOrEval.java
@@ -47,4 +47,4 @@ public class WiredExtraOrEval extends InteractionWiredExtra {
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
}
-}
\ No newline at end of file
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraRandom.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraRandom.java
index b8d8e3bf..3a78591a 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraRandom.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraRandom.java
@@ -47,4 +47,4 @@ public class WiredExtraRandom extends InteractionWiredExtra {
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
}
-}
\ No newline at end of file
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraUnseen.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraUnseen.java
index a7b04568..127021db 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraUnseen.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraUnseen.java
@@ -11,10 +11,22 @@ import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Set;
public class WiredExtraUnseen extends InteractionWiredExtra {
- public List seenList = new ArrayList<>();
+ /**
+ * Maximum number of effect IDs to track to prevent memory leaks.
+ * When limit is reached, oldest entries are removed automatically.
+ */
+ private static final int MAX_SEEN_LIST_SIZE = 1000;
+
+ /**
+ * Thread-safe set of seen effect IDs. Uses LinkedHashSet for insertion order
+ * to support LRU-style eviction when max size is reached.
+ */
+ private final Set seenList = new LinkedHashSet<>();
public WiredExtraUnseen(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -46,7 +58,9 @@ public class WiredExtraUnseen extends InteractionWiredExtra {
@Override
public void onPickUp() {
- this.seenList.clear();
+ synchronized (this.seenList) {
+ this.seenList.clear();
+ }
}
@Override
@@ -57,31 +71,60 @@ public class WiredExtraUnseen extends InteractionWiredExtra {
@Override
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
super.onMove(room, oldLocation, newLocation);
- this.seenList.clear();
+ synchronized (this.seenList) {
+ this.seenList.clear();
+ }
}
public InteractionWiredEffect getUnseenEffect(List effects) {
- List unseenEffects = new ArrayList<>();
- for (InteractionWiredEffect effect : effects) {
- if (!this.seenList.contains(effect.getId())) {
- unseenEffects.add(effect);
+ synchronized (this.seenList) {
+ List unseenEffects = new ArrayList<>();
+ for (InteractionWiredEffect effect : effects) {
+ if (!this.seenList.contains(effect.getId())) {
+ unseenEffects.add(effect);
+ }
}
- }
- InteractionWiredEffect effect = null;
- if (!unseenEffects.isEmpty()) {
- effect = unseenEffects.get(0);
- } else {
- this.seenList.clear();
+ InteractionWiredEffect effect = null;
+ if (!unseenEffects.isEmpty()) {
+ effect = unseenEffects.get(0);
+ } else {
+ this.seenList.clear();
- if (!effects.isEmpty()) {
- effect = effects.get(0);
+ if (!effects.isEmpty()) {
+ effect = effects.get(0);
+ }
}
- }
- if (effect != null) {
- this.seenList.add(effect.getId());
+ if (effect != null) {
+ // Enforce max size limit to prevent memory leaks
+ if (this.seenList.size() >= MAX_SEEN_LIST_SIZE) {
+ // Remove oldest entry (first in insertion order)
+ Integer oldest = this.seenList.iterator().next();
+ this.seenList.remove(oldest);
+ }
+ this.seenList.add(effect.getId());
+ }
+ return effect;
}
- return effect;
}
-}
\ No newline at end of file
+
+ /**
+ * Gets the current size of the seen list.
+ * @return the number of tracked effect IDs
+ */
+ public int getSeenListSize() {
+ synchronized (this.seenList) {
+ return this.seenList.size();
+ }
+ }
+
+ /**
+ * Clears the seen list.
+ */
+ public void clearSeenList() {
+ synchronized (this.seenList) {
+ this.seenList.clear();
+ }
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java
index 9f631c9d..6db447f7 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java
@@ -4,8 +4,8 @@ import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting;
import gnu.trove.set.hash.THashSet;
public interface InteractionWiredMatchFurniSettings {
- THashSet getMatchFurniSettings();
- boolean shouldMatchState();
- boolean shouldMatchRotation();
- boolean shouldMatchPosition();
+ public THashSet getMatchFurniSettings();
+ public boolean shouldMatchState();
+ public boolean shouldMatchRotation();
+ public boolean shouldMatchPosition();
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java
index 7912173c..c1bfecef 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java
@@ -1,6 +1,5 @@
package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
-import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
@@ -8,10 +7,12 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.tick.WiredTickable;
import com.eu.habbo.messages.ServerMessage;
-import com.eu.habbo.threading.runnables.WiredExecuteTask;
import gnu.trove.procedure.TObjectProcedure;
import java.sql.ResultSet;
@@ -19,11 +20,24 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
-public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements WiredTriggerReset {
- public final static WiredTriggerType type = WiredTriggerType.AT_GIVEN_TIME;
+/**
+ * One-shot timer wired trigger that fires once after a set time.
+ *
+ * Uses the new 50ms tick system via {@link WiredTickable} for accurate
+ * timing. After firing, the timer automatically resets and starts again.
+ *
+ */
+public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements WiredTickable, WiredTriggerReset {
+ public static final WiredTriggerType type = WiredTriggerType.AT_GIVEN_TIME;
+ /** The time in milliseconds until the trigger fires */
public int executeTime;
- public int taskId;
+
+ /** Accumulated time since last reset (in milliseconds) */
+ private long accumulatedTime = 0;
+
+ /** Whether the timer has fired and is waiting for reset */
+ private boolean hasFired = false;
public WiredTriggerAtSetTime(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -33,16 +47,21 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi
super(id, userId, item, extradata, limitedStack, limitedSells);
}
+ @Override
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ // Only match if this timer is the one that actually fired
+ return event.getSourceItem().map(item -> item.getId() == this.getId()).orElse(false);
+ }
+
+ @Deprecated
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- return true;
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
- this.executeTime
- ));
+ return WiredManager.getGson().toJson(new JsonData(this.executeTime));
}
@Override
@@ -50,7 +69,7 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.executeTime = data.executeTime;
} else {
if (wiredData.length() >= 1) {
@@ -61,14 +80,17 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi
if (this.executeTime < 500) {
this.executeTime = 20 * 500;
}
- this.taskId = 1;
- Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime);
+
+ // Initialize for tick system - will be registered by RoomItemManager
+ this.accumulatedTime = 0;
+ this.hasFired = false;
}
@Override
public void onPickUp() {
this.executeTime = 0;
- this.taskId = 0;
+ this.accumulatedTime = 0;
+ this.hasFired = false;
}
@Override
@@ -111,7 +133,7 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi
@Override
public boolean saveData(WiredSettings settings) {
- if(settings.getIntParams().length < 1) return false;
+ if (settings.getIntParams().length < 1) return false;
this.executeTime = settings.getIntParams()[0] * 500;
this.resetTimer();
@@ -119,13 +141,54 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi
return true;
}
+ // ========== WiredTickable Implementation ==========
+
+ @Override
+ public void onWiredTick(Room room, long tickCount, int tickIntervalMs) {
+ // Don't tick if already fired (waiting for manual reset)
+ if (this.hasFired) {
+ return;
+ }
+
+ // Add fixed tick interval
+ this.accumulatedTime += tickIntervalMs;
+
+ // Check if enough time has passed
+ if (this.accumulatedTime >= this.executeTime) {
+ this.hasFired = true;
+ this.accumulatedTime = 0;
+
+ if (this.getRoomId() != 0 && room.isLoaded()) {
+ WiredManager.triggerTimerTick(room, this);
+ }
+ }
+ }
+
@Override
public void resetTimer() {
- this.taskId++;
-
- Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime);
+ this.accumulatedTime = 0;
+ this.hasFired = false;
}
+ @Override
+ public void onRegistered(Room room, long currentTimeMillis) {
+ this.accumulatedTime = 0;
+ this.hasFired = false;
+ }
+
+ @Override
+ public void onUnregistered(Room room) {
+ this.accumulatedTime = 0;
+ this.hasFired = false;
+ }
+
+ @Override
+ public boolean isOneShot() {
+ return true; // One-shot timer, fires once then waits for reset
+ }
+
+ // ========== JSON Data ==========
+
static class JsonData {
int executeTime;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java
index 185224cb..24475dcc 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java
@@ -1,6 +1,5 @@
package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
-import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
@@ -8,10 +7,12 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.tick.WiredTickable;
import com.eu.habbo.messages.ServerMessage;
-import com.eu.habbo.threading.runnables.WiredExecuteTask;
import gnu.trove.procedure.TObjectProcedure;
import java.sql.ResultSet;
@@ -19,10 +20,24 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
-public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements WiredTriggerReset {
+/**
+ * Long-interval one-shot timer wired trigger.
+ *
+ * Uses the new 50ms tick system via {@link WiredTickable} for accurate
+ * timing with 5-second increments.
+ *
+ */
+public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements WiredTickable, WiredTriggerReset {
private static final WiredTriggerType type = WiredTriggerType.AT_GIVEN_TIME;
- public int taskId;
+
+ /** The time in milliseconds until the trigger fires */
private int executeTime;
+
+ /** Accumulated time since last reset (in milliseconds) */
+ private long accumulatedTime = 0;
+
+ /** Whether the timer has fired and is waiting for reset */
+ private boolean hasFired = false;
public WiredTriggerAtTimeLong(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -32,16 +47,21 @@ public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements W
super(id, userId, item, extradata, limitedStack, limitedSells);
}
+ @Override
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ // Only match if this timer is the one that actually fired
+ return event.getSourceItem().map(item -> item.getId() == this.getId()).orElse(false);
+ }
+
+ @Deprecated
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- return true;
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
- this.executeTime
- ));
+ return WiredManager.getGson().toJson(new JsonData(this.executeTime));
}
@Override
@@ -49,7 +69,7 @@ public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements W
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.executeTime = data.executeTime;
} else {
if (wiredData.length() >= 1) {
@@ -60,14 +80,17 @@ public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements W
if (this.executeTime < 500) {
this.executeTime = 20 * 500;
}
- this.taskId = 1;
- Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime);
+
+ // Initialize for tick system
+ this.accumulatedTime = 0;
+ this.hasFired = false;
}
@Override
public void onPickUp() {
this.executeTime = 0;
- this.taskId = 0;
+ this.accumulatedTime = 0;
+ this.hasFired = false;
}
@Override
@@ -110,19 +133,62 @@ public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements W
@Override
public boolean saveData(WiredSettings settings) {
- if(settings.getIntParams().length < 1) return false;
+ if (settings.getIntParams().length < 1) return false;
this.executeTime = settings.getIntParams()[0] * 500;
+
+ this.resetTimer();
return true;
}
+ // ========== WiredTickable Implementation ==========
+
+ @Override
+ public void onWiredTick(Room room, long tickCount, int tickIntervalMs) {
+ // Don't tick if already fired (waiting for manual reset)
+ if (this.hasFired) {
+ return;
+ }
+
+ // Add fixed tick interval
+ this.accumulatedTime += tickIntervalMs;
+
+ // Check if enough time has passed
+ if (this.accumulatedTime >= this.executeTime) {
+ this.hasFired = true;
+ this.accumulatedTime = 0;
+
+ if (this.getRoomId() != 0 && room.isLoaded()) {
+ WiredManager.triggerTimerTick(room, this);
+ }
+ }
+ }
+
@Override
public void resetTimer() {
- this.taskId++;
-
- Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime);
+ this.accumulatedTime = 0;
+ this.hasFired = false;
}
+ @Override
+ public void onRegistered(Room room, long currentTimeMillis) {
+ this.accumulatedTime = 0;
+ this.hasFired = false;
+ }
+
+ @Override
+ public void onUnregistered(Room room) {
+ this.accumulatedTime = 0;
+ this.hasFired = false;
+ }
+
+ @Override
+ public boolean isOneShot() {
+ return true; // One-shot timer
+ }
+
+ // ========== JSON Data ==========
+
static class JsonData {
int executeTime;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java
index 32a7a120..462d4b0e 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java
@@ -8,8 +8,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.procedure.TObjectProcedure;
import gnu.trove.set.hash.THashSet;
@@ -27,7 +28,7 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
public final static WiredTriggerType type = WiredTriggerType.WALKS_ON_FURNI;
- private final THashSet items;
+ private THashSet items;
private String botName = "";
public WiredTriggerBotReachedFurni(ResultSet set, Item baseItem) throws SQLException {
@@ -63,7 +64,7 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items) {
message.appendInt(item.getId());
@@ -102,16 +103,25 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
this.items.clear();
int count = settings.getFurniIds().length;
+ Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
+ if (room == null) return false;
for (int i = 0; i < count; i++) {
- this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i]));
+ HabboItem item = room.getHabboItem(settings.getFurniIds()[i]);
+ if (item != null) {
+ this.items.add(item);
+ }
}
return true;
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ RoomUnit roomUnit = event.getActor().orElse(null);
+ Room room = event.getRoom();
+ Object[] stuff = event.getLegacyStuff();
+
if (stuff.length >= 1) {
if (stuff[0] instanceof HabboItem) {
return this.items.contains(stuff[0]) && room.getBots(this.botName).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit);
@@ -120,9 +130,15 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
return false;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.botName,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
@@ -134,7 +150,7 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.botName = data.botName;
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java
index 346a5f38..50c39e71 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java
@@ -5,8 +5,10 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -53,13 +55,21 @@ public class WiredTriggerBotReachedHabbo extends InteractionWiredTrigger {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ RoomUnit roomUnit = event.getActor().orElse(null);
+ Room room = event.getRoom();
return room.getBots(this.botName).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit);
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.botName
));
}
@@ -69,7 +79,7 @@ public class WiredTriggerBotReachedHabbo extends InteractionWiredTrigger {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.botName = data.botName;
} else {
this.botName = wiredData;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerCollision.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerCollision.java
index 1d255b5b..81e3f031 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerCollision.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerCollision.java
@@ -6,8 +6,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -24,9 +25,17 @@ public class WiredTriggerCollision extends InteractionWiredTrigger {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
+ @Override
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ // Collision trigger fires when a furniture item moves and collides with a room unit
+ // The actor is the room unit that was collided with
+ return event.getActor().isPresent();
+ }
+
+ @Deprecated
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- return stuff.length > 0 && stuff[0] instanceof HabboItem;
+ return false;
}
@Override
@@ -52,7 +61,7 @@ public class WiredTriggerCollision extends InteractionWiredTrigger {
@Override
public void serializeWiredData(ServerMessage message, Room room) {
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(0);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java
index ac6347a0..5db6591a 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java
@@ -9,8 +9,9 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
@@ -35,7 +36,11 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ RoomUnit roomUnit = event.getActor().orElse(null);
+ Room room = event.getRoom();
+ Object[] stuff = event.getLegacyStuff();
+
if (stuff.length >= 1) {
Habbo habbo = room.getHabbo(roomUnit);
@@ -46,17 +51,24 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
}
}
- if (stuff[0] instanceof HabboItem) {
- return this.items.contains(stuff[0]);
+ HabboItem sourceItem = event.getSourceItem().orElse(null);
+ if (sourceItem != null) {
+ return this.items.contains(sourceItem);
}
}
}
return false;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@@ -67,7 +79,7 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
@@ -120,7 +132,7 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items) {
message.appendInt(item.getId());
@@ -141,7 +153,10 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
int count = settings.getFurniIds().length;
for (int i = 0; i < count; i++) {
- this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i]));
+ HabboItem item = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i]);
+ if (item != null) {
+ this.items.add(item);
+ }
}
return true;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameEnds.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameEnds.java
index aada946d..b6ffb232 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameEnds.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameEnds.java
@@ -6,7 +6,9 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.procedure.TObjectProcedure;
@@ -27,10 +29,16 @@ public class WiredTriggerGameEnds extends InteractionWiredTrigger {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
return true;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
return "";
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameStarts.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameStarts.java
index 5b31dd65..6e1085d4 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameStarts.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameStarts.java
@@ -6,7 +6,9 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.procedure.TObjectProcedure;
@@ -27,10 +29,16 @@ public class WiredTriggerGameStarts extends InteractionWiredTrigger {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
return true;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
return "";
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboEntersRoom.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboEntersRoom.java
index bb1f5f1e..7f631d72 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboEntersRoom.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboEntersRoom.java
@@ -6,8 +6,10 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -27,7 +29,9 @@ public class WiredTriggerHabboEntersRoom extends InteractionWiredTrigger {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ RoomUnit roomUnit = event.getActor().orElse(null);
+ Room room = event.getRoom();
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
@@ -40,9 +44,15 @@ public class WiredTriggerHabboEntersRoom extends InteractionWiredTrigger {
return false;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.username
));
}
@@ -52,7 +62,7 @@ public class WiredTriggerHabboEntersRoom extends InteractionWiredTrigger {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.username = data.username;
} else {
this.username = wiredData;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java
index a2e10c71..b05746eb 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java
@@ -6,8 +6,10 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -28,21 +30,28 @@ public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
if (this.key.length() > 0) {
- if (stuff[0] instanceof String) {
- if (((String) stuff[0]).toLowerCase().contains(this.key.toLowerCase())) {
- Habbo habbo = room.getHabbo(roomUnit);
- return !this.ownerOnly || (habbo != null && room.getOwnerId() == habbo.getHabboInfo().getId());
- }
+ String text = event.getText().orElse(null);
+ if (text != null && text.toLowerCase().contains(this.key.toLowerCase())) {
+ RoomUnit roomUnit = event.getActor().orElse(null);
+ Room room = event.getRoom();
+ Habbo habbo = room.getHabbo(roomUnit);
+ return !this.ownerOnly || (habbo != null && room.getOwnerId() == habbo.getHabboInfo().getId());
}
}
return false;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.ownerOnly,
this.key
));
@@ -53,7 +62,7 @@ public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.ownerOnly = data.ownerOnly;
this.key = data.key;
} else {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOffFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOffFurni.java
index f4d2c7b2..55c2af03 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOffFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOffFurni.java
@@ -7,8 +7,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
@@ -20,7 +21,7 @@ import java.util.stream.Collectors;
public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger {
public static final WiredTriggerType type = WiredTriggerType.WALKS_OFF_FURNI;
- private final THashSet items;
+ private THashSet items;
public WiredTriggerHabboWalkOffFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -33,18 +34,23 @@ public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- if (stuff.length >= 1) {
- if (stuff[0] instanceof HabboItem) {
- return this.items.contains(stuff[0]);
- }
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ HabboItem sourceItem = event.getSourceItem().orElse(null);
+ if (sourceItem != null) {
+ return this.items.contains(sourceItem);
}
return false;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new WiredTriggerFurniStateToggled.JsonData(
+ return WiredManager.getGson().toJson(new WiredTriggerFurniStateToggled.JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@@ -55,7 +61,7 @@ public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
@@ -112,7 +118,7 @@ public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger {
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items) {
message.appendInt(item.getId());
@@ -134,7 +140,10 @@ public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger {
int count = settings.getFurniIds().length;
for (int i = 0; i < count; i++) {
- this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i]));
+ HabboItem item = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i]);
+ if (item != null) {
+ this.items.add(item);
+ }
}
return true;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOnFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOnFurni.java
index e6480ed9..40dd0170 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOnFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOnFurni.java
@@ -7,8 +7,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
@@ -20,7 +21,7 @@ import java.util.stream.Collectors;
public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
public static final WiredTriggerType type = WiredTriggerType.WALKS_ON_FURNI;
- private final THashSet items;
+ private THashSet items;
public WiredTriggerHabboWalkOnFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -33,15 +34,20 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- if (stuff.length >= 1) {
- if (stuff[0] instanceof HabboItem) {
- return this.items.contains(stuff[0]);
- }
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ HabboItem sourceItem = event.getSourceItem().orElse(null);
+ if (sourceItem != null) {
+ return this.items.contains(sourceItem);
}
return false;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public WiredTriggerType getType() {
return type;
@@ -65,7 +71,7 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
}
message.appendBoolean(false);
- message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
+ message.appendInt(WiredManager.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items) {
message.appendInt(item.getId());
@@ -87,7 +93,10 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
int count = settings.getFurniIds().length;
for (int i = 0; i < count; i++) {
- this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i]));
+ HabboItem item = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i]);
+ if (item != null) {
+ this.items.add(item);
+ }
}
return true;
@@ -95,7 +104,7 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@@ -106,7 +115,7 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java
index 94f3aeaa..e91a43f3 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java
@@ -1,7 +1,5 @@
package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
-import com.eu.habbo.Emulator;
-import com.eu.habbo.habbohotel.items.ICycleable;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
@@ -9,8 +7,11 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.tick.WiredTickable;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.procedure.TObjectProcedure;
@@ -19,12 +20,19 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
-public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICycleable, WiredTriggerReset {
+/**
+ * Repeating wired trigger that fires periodically.
+ *
+ * Uses the new 50ms tick system via {@link WiredTickable} for higher-resolution
+ * timing compared to the old 500ms room cycle.
+ *
+ */
+public class WiredTriggerRepeater extends InteractionWiredTrigger implements WiredTickable, WiredTriggerReset {
public static final WiredTriggerType type = WiredTriggerType.PERIODICALLY;
- public static final int DEFAULT_DELAY = 10 * 500;
+ public static final int DEFAULT_DELAY = 10 * 500; // 5 seconds default
+ /** The interval in milliseconds between triggers */
protected int repeatTime = DEFAULT_DELAY;
- protected int counter = 0;
public WiredTriggerRepeater(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -34,16 +42,21 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy
super(id, userId, item, extradata, limitedStack, limitedSells);
}
+ @Override
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ // Only match if this repeater is the one that actually fired
+ return event.getSourceItem().map(item -> item.getId() == this.getId()).orElse(false);
+ }
+
+ @Deprecated
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- return true;
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
- this.repeatTime
- ));
+ return WiredManager.getGson().toJson(new JsonData(this.repeatTime));
}
@Override
@@ -51,7 +64,7 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.repeatTime = data.repeatTime;
} else {
if (wiredData.length() >= 1) {
@@ -67,7 +80,6 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy
@Override
public void onPickUp() {
this.repeatTime = DEFAULT_DELAY;
- this.counter = 0;
}
@Override
@@ -110,47 +122,56 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy
@Override
public boolean saveData(WiredSettings settings) {
- if(settings.getIntParams().length < 1) return false;
- this.repeatTime = settings.getIntParams()[0] * 500;
- this.counter = 0;
+ if (settings.getIntParams().length < 1) return false;
+ int newRepeatTime = settings.getIntParams()[0] * 500;
- if (this.repeatTime < 500) {
- this.repeatTime = 500;
+ if (newRepeatTime < 500) {
+ newRepeatTime = 500;
}
+ this.repeatTime = newRepeatTime;
+
return true;
}
+ // ========== WiredTickable Implementation ==========
+
@Override
- public void cycle(Room room) {
- this.counter += 500;
- long currentMillis = System.currentTimeMillis();
- String Key = Double.toString(this.getX()) + Double.toString(this.getY());
-
- room.repeatersLastTick.putIfAbsent(Key, currentMillis);
-
- if (this.counter >= this.repeatTime && room.repeatersLastTick.get(Key) < currentMillis - 450) {
- this.counter = 0;
- if (this.getRoomId() != 0) {
- if (room.isLoaded()) {
- room.repeatersLastTick.put(Key, currentMillis);
- WiredHandler.handle(this, null, room, new Object[]{this});
- }
+ public void onWiredTick(Room room, long tickCount, int tickIntervalMs) {
+ // Calculate elapsed time based on global tick count
+ // All repeaters with the same interval fire on the exact same tick
+ long elapsedMs = tickCount * tickIntervalMs;
+
+ // Fire when elapsed time is a multiple of repeatTime
+ if (elapsedMs % this.repeatTime == 0) {
+ if (this.getRoomId() != 0 && room.isLoaded()) {
+ WiredManager.triggerTimerRepeat(room, this);
}
}
}
@Override
public void resetTimer() {
- this.counter = 0;
- if (this.getRoomId() != 0) {
- Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
- if (room != null && room.isLoaded()) {
- WiredHandler.handle(this, null, room, new Object[]{this});
- }
- }
+ // No-op - using global tick count, no local state to reset
}
+ @Override
+ public void onRegistered(Room room, long currentTimeMillis) {
+ // No-op - using global tick count
+ }
+
+ @Override
+ public void onUnregistered(Room room) {
+ // No-op - using global tick count
+ }
+
+ @Override
+ public boolean isOneShot() {
+ return false; // Repeating timer
+ }
+
+ // ========== JSON Data ==========
+
static class JsonData {
int repeatTime;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java
index 584c264b..f9094c09 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java
@@ -1,7 +1,5 @@
package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
-import com.eu.habbo.Emulator;
-import com.eu.habbo.habbohotel.items.ICycleable;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
@@ -9,8 +7,11 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
+import com.eu.habbo.habbohotel.wired.tick.WiredTickable;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.procedure.TObjectProcedure;
@@ -19,11 +20,19 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
-public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements ICycleable, WiredTriggerReset {
- public static final int DEFAULT_DELAY = 10 * 5000;
+/**
+ * Long-interval repeating wired trigger that fires periodically.
+ *
+ * Uses the new 50ms tick system via {@link WiredTickable} for accurate
+ * timing. Intervals are in 5-second increments.
+ *
+ */
+public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements WiredTickable, WiredTriggerReset {
+ public static final int DEFAULT_DELAY = 10 * 5000; // 50 seconds default
private static final WiredTriggerType type = WiredTriggerType.PERIODICALLY_LONG;
+
+ /** The interval in milliseconds between triggers */
private int repeatTime = DEFAULT_DELAY;
- private int counter = 0;
public WiredTriggerRepeaterLong(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -33,16 +42,21 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements
super(id, userId, item, extradata, limitedStack, limitedSells);
}
+ @Override
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ // Only match if this repeater is the one that actually fired
+ return event.getSourceItem().map(item -> item.getId() == this.getId()).orElse(false);
+ }
+
+ @Deprecated
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- return true;
+ return false;
}
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
- this.repeatTime
- ));
+ return WiredManager.getGson().toJson(new JsonData(this.repeatTime));
}
@Override
@@ -50,7 +64,7 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.repeatTime = data.repeatTime;
} else {
if (wiredData.length() >= 1) {
@@ -108,43 +122,50 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements
@Override
public boolean saveData(WiredSettings settings) {
- if(settings.getIntParams().length < 1) return false;
+ if (settings.getIntParams().length < 1) return false;
this.repeatTime = settings.getIntParams()[0] * 5000;
- this.counter = 0;
+ // No accumulated time reset needed - using global tick count
return true;
}
+ // ========== WiredTickable Implementation ==========
@Override
- public void cycle(Room room) {
- this.counter += 500;
- long currentMillis = System.currentTimeMillis();
- String Key = Double.toString(this.getX()) + Double.toString(this.getY());
-
- room.repeatersLastTick.putIfAbsent(Key, currentMillis);
-
- if (this.counter >= this.repeatTime && room.repeatersLastTick.get(Key) < currentMillis - 4950) {
- this.counter = 0;
- if (this.getRoomId() != 0) {
- if (room.isLoaded()) {
- room.repeatersLastTick.put(Key, currentMillis);
- WiredHandler.handle(this, null, room, new Object[]{this});
- }
+ public void onWiredTick(Room room, long tickCount, int tickIntervalMs) {
+ // Use global tick counter - all repeaters with same interval fire together
+ // This ensures perfect synchronization regardless of when they were registered
+ long elapsedMs = tickCount * tickIntervalMs;
+
+ // Fire when elapsed time is a multiple of repeat time
+ if (elapsedMs % this.repeatTime == 0) {
+ if (this.getRoomId() != 0 && room.isLoaded()) {
+ WiredManager.triggerTimerRepeat(room, this);
}
}
}
@Override
public void resetTimer() {
- this.counter = 0;
- if (this.getRoomId() != 0) {
- Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
- if (room != null && room.isLoaded()) {
- WiredHandler.handle(this, null, room, new Object[]{this});
- }
- }
+ // No-op - using global tick count for synchronization
}
+ @Override
+ public void onRegistered(Room room, long currentTimeMillis) {
+ // No-op - using global tick count
+ }
+
+ @Override
+ public void onUnregistered(Room room) {
+ // No-op - using global tick count
+ }
+
+ @Override
+ public boolean isOneShot() {
+ return false; // Repeating timer
+ }
+
+ // ========== JSON Data ==========
+
static class JsonData {
int repeatTime;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java
index 5fe4720f..fb3f1be0 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java
@@ -5,8 +5,10 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.wired.core.WiredEvent;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
@@ -25,7 +27,8 @@ public class WiredTriggerScoreAchieved extends InteractionWiredTrigger {
}
@Override
- public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ public boolean matches(HabboItem triggerItem, WiredEvent event) {
+ Object[] stuff = event.getLegacyStuff();
if (stuff.length >= 2) {
int points = (Integer) stuff[0];
int amountAdded = (Integer) stuff[1];
@@ -36,9 +39,15 @@ public class WiredTriggerScoreAchieved extends InteractionWiredTrigger {
return false;
}
+ @Deprecated
+ @Override
+ public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
+ return false;
+ }
+
@Override
public String getWiredData() {
- return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
+ return WiredManager.getGson().toJson(new JsonData(
this.score
));
}
@@ -48,7 +57,7 @@ public class WiredTriggerScoreAchieved extends InteractionWiredTrigger {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
- JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.score = data.score;
} else {
try {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamLoses.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamLoses.java
index feee2674..9a68311a 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamLoses.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamLoses.java
@@ -19,4 +19,4 @@ public class WiredTriggerTeamLoses extends WiredTriggerGameStarts {
public WiredTriggerType getType() {
return WiredTriggerType.CUSTOM;
}
-}
\ No newline at end of file
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamWins.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamWins.java
index afe8124c..43bde787 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamWins.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamWins.java
@@ -19,4 +19,4 @@ public class WiredTriggerTeamWins extends WiredTriggerGameStarts {
public WiredTriggerType getType() {
return WiredTriggerType.CUSTOM;
}
-}
\ No newline at end of file
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerCategory.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerCategory.java
index 76897835..b19a43b0 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerCategory.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerCategory.java
@@ -1,7 +1,7 @@
package com.eu.habbo.habbohotel.messenger;
public class MessengerCategory {
- private final int user_id;
+ private int user_id;
private String name;
private int id;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolBan.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolBan.java
index 69c7d434..3c8517da 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolBan.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolBan.java
@@ -24,7 +24,7 @@ public class ModToolBan implements Runnable {
public ModToolBanType type;
public int cfhTopic;
- private final boolean needsInsert;
+ private boolean needsInsert;
public ModToolBan(ResultSet set) throws SQLException {
this.userId = set.getInt("user_id");
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/navigation/EventCategory.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/navigation/EventCategory.java
index f53e5a7f..674040d0 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/navigation/EventCategory.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/navigation/EventCategory.java
@@ -3,9 +3,9 @@ package com.eu.habbo.habbohotel.navigation;
import com.eu.habbo.messages.ServerMessage;
public class EventCategory {
- private final int id;
- private final String caption;
- private final boolean visible;
+ private int id;
+ private String caption;
+ private boolean visible;
public EventCategory(int id, String caption, boolean visible) {
this.id = id;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorSavedSearch.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorSavedSearch.java
index f433fef6..8bcbc62c 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorSavedSearch.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorSavedSearch.java
@@ -1,8 +1,8 @@
package com.eu.habbo.habbohotel.navigation;
public class NavigatorSavedSearch {
- private final String searchCode;
- private final String filter;
+ private String searchCode;
+ private String filter;
private int id;
public NavigatorSavedSearch(String searchCode, String filter) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java
index 64f53ec0..b9d24931 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java
@@ -9,10 +9,7 @@ import gnu.trove.map.hash.TIntObjectHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
+import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/permissions/Rank.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/permissions/Rank.java
index 20929cd7..cbbc01dc 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/permissions/Rank.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/permissions/Rank.java
@@ -11,7 +11,7 @@ public class Rank {
private final int id;
- private final int level;
+ private int level;
private final THashMap permissions;
private final THashMap variables;
private String name;
@@ -55,6 +55,7 @@ public class Rank {
this.logCommands = set.getString("log_commands").equals("1");
this.prefix = set.getString("prefix");
this.prefixColor = set.getString("prefix_color");
+ this.level = set.getInt("level");
this.diamondsTimerAmount = set.getInt("auto_points_amount");
this.creditsTimerAmount = set.getInt("auto_credits_amount");
this.pixelsTimerAmount = set.getInt("auto_pixels_amount");
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java
index 6a3020d0..3dce2a58 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java
@@ -69,8 +69,8 @@ public class MonsterplantPet extends Pet implements IPetLook {
private final int mouth;
private final int mouthColor;
public String look;
- private final int type;
- private final int hue;
+ private int type;
+ private int hue;
private int deathTimestamp = Emulator.getIntUnixTimestamp() + timeToLive;
private boolean canBreed = true;
private boolean publiclyBreedable = false;
@@ -171,7 +171,6 @@ public class MonsterplantPet extends Pet implements IPetLook {
for (RoomUnitStatus s : this.roomUnit.getStatusMap().keySet()) {
if (s.equals(RoomUnitStatus.GROW)) {
clear = true;
- break;
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/polls/Poll.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/polls/Poll.java
index a337c52d..8e7927dc 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/polls/Poll.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/polls/Poll.java
@@ -20,7 +20,7 @@ public class Poll {
public int lastQuestionId;
- private final ArrayList questions;
+ private ArrayList questions;
public Poll(ResultSet set) throws SQLException {
this.id = set.getInt("id");
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/polls/PollQuestion.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/polls/PollQuestion.java
index cbeb0381..b1c159e6 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/polls/PollQuestion.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/polls/PollQuestion.java
@@ -32,7 +32,7 @@ public class PollQuestion implements ISerialize, Comparable {
public final int order;
- private final ArrayList subQuestions;
+ private ArrayList subQuestions;
public PollQuestion(ResultSet set) throws SQLException {
this.id = set.getInt("id");
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java
index 9dc0eae1..ceeeba49 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java
@@ -1,63 +1,67 @@
package com.eu.habbo.habbohotel.rooms;
+import java.awt.Color;
+import java.awt.Rectangle;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.eu.habbo.Emulator;
-import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.bots.Bot;
-import com.eu.habbo.habbohotel.bots.VisitorBot;
-import com.eu.habbo.habbohotel.commands.CommandHandler;
import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.GuildMember;
import com.eu.habbo.habbohotel.items.FurnitureType;
-import com.eu.habbo.habbohotel.items.ICycleable;
import com.eu.habbo.habbohotel.items.Item;
-import com.eu.habbo.habbohotel.items.interactions.*;
-import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate;
-import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard;
+import com.eu.habbo.habbohotel.items.interactions.InteractionBackgroundToner;
+import com.eu.habbo.habbohotel.items.interactions.InteractionFireworks;
+import com.eu.habbo.habbohotel.items.interactions.InteractionGuildFurni;
+import com.eu.habbo.habbohotel.items.interactions.InteractionJukeBox;
+import com.eu.habbo.habbohotel.items.interactions.InteractionMultiHeight;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
-import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiSphere;
-import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter;
-import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile;
-import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField;
-import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole;
-import com.eu.habbo.habbohotel.items.interactions.pets.InteractionNest;
-import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetBreedingNest;
-import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetDrink;
-import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetFood;
-import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob;
-import com.eu.habbo.habbohotel.messenger.MessengerBuddy;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.PetManager;
-import com.eu.habbo.habbohotel.pets.RideablePet;
-import com.eu.habbo.habbohotel.users.*;
-import com.eu.habbo.habbohotel.wired.WiredHandler;
-import com.eu.habbo.habbohotel.wired.WiredTriggerType;
+import com.eu.habbo.habbohotel.users.DanceType;
+import com.eu.habbo.habbohotel.users.Habbo;
+import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ISerialize;
import com.eu.habbo.messages.ServerMessage;
-import com.eu.habbo.messages.outgoing.MessageComposer;
-import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer;
-import com.eu.habbo.messages.outgoing.generic.alerts.GenericErrorMessagesComposer;
import com.eu.habbo.messages.outgoing.guilds.GuildInfoComposer;
import com.eu.habbo.messages.outgoing.hotelview.HotelViewComposer;
import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer;
-import com.eu.habbo.messages.outgoing.inventory.AddPetComposer;
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
-import com.eu.habbo.messages.outgoing.polls.infobus.SimplePollAnswerComposer;
-import com.eu.habbo.messages.outgoing.polls.infobus.SimplePollStartComposer;
-import com.eu.habbo.messages.outgoing.rooms.*;
-import com.eu.habbo.messages.outgoing.rooms.items.*;
-import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer;
-import com.eu.habbo.messages.outgoing.rooms.users.*;
-import com.eu.habbo.messages.outgoing.users.MutedWhisperComposer;
+import com.eu.habbo.messages.outgoing.rooms.HideDoorbellComposer;
+import com.eu.habbo.messages.outgoing.rooms.UpdateStackHeightComposer;
+import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer;
+import com.eu.habbo.messages.outgoing.rooms.items.ItemStateComposer;
+import com.eu.habbo.messages.outgoing.rooms.items.RemoveFloorItemComposer;
+import com.eu.habbo.messages.outgoing.rooms.items.RemoveWallItemComposer;
+import com.eu.habbo.messages.outgoing.rooms.items.RoomFloorItemsComposer;
+import com.eu.habbo.messages.outgoing.rooms.items.WallItemUpdateComposer;
+import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
import com.eu.habbo.plugin.Event;
-import com.eu.habbo.plugin.events.furniture.*;
+import com.eu.habbo.plugin.events.furniture.FurniturePickedUpEvent;
import com.eu.habbo.plugin.events.rooms.RoomLoadedEvent;
import com.eu.habbo.plugin.events.rooms.RoomUnloadedEvent;
import com.eu.habbo.plugin.events.rooms.RoomUnloadingEvent;
-import com.eu.habbo.plugin.events.users.*;
-import com.eu.habbo.threading.runnables.YouAreAPirate;
-import gnu.trove.TCollections;
+
import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.TIntIntMap;
@@ -65,5114 +69,2382 @@ import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.THashMap;
import gnu.trove.map.hash.TIntIntHashMap;
import gnu.trove.map.hash.TIntObjectHashMap;
-import gnu.trove.procedure.TIntObjectProcedure;
-import gnu.trove.procedure.TObjectProcedure;
import gnu.trove.set.hash.THashSet;
-import org.apache.commons.math3.util.Pair;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.awt.*;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
public class Room implements Comparable, ISerialize, Runnable {
- private static final Logger LOGGER = LoggerFactory.getLogger(Room.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(Room.class);
- public static final Comparator SORT_SCORE = (o1, o2) -> {
+ // Manager instances for better separation of concerns
+ private RoomTileManager tileManager;
+ private RoomGameManager gameManager;
+ private RoomTradeManager tradeManager;
+ private RoomPromotionManager promotionManager;
+ private RoomWordQuizManager wordQuizManager;
+ private RoomRightsManager rightsManager;
+ private RoomUnitManager unitManager;
+ private RoomItemManager itemManager;
+ private RoomChatManager chatManager;
+ private RoomRollerManager rollerManager;
+ private RoomMessagingManager messagingManager;
+ private RoomCycleManager cycleManager;
- if (!(o1 instanceof Room && o2 instanceof Room))
- return 0;
+ public static final Comparator SORT_SCORE = (o1, o2) -> o2.getScore() - o1.getScore();
+ public static final Comparator SORT_ID = (o1, o2) -> o2.getId() - o1.getId();
+ private static final TIntObjectHashMap defaultMoodData = new TIntObjectHashMap<>();
+ //Configuration. Loaded from database & updated accordingly.
+ public static boolean HABBO_CHAT_DELAY = false;
+ public static int MAXIMUM_BOTS = 10;
+ public static int MAXIMUM_PETS = 10;
+ public static int MAXIMUM_FURNI = 2500;
+ public static int MAXIMUM_POSTITNOTES = 200;
+ public static int HAND_ITEM_TIME = 10;
+ public static int IDLE_CYCLES = 240;
+ public static int IDLE_CYCLES_KICK = 480;
+ public static String PREFIX_FORMAT = "[%prefix%] ";
+ public static int ROLLERS_MAXIMUM_ROLL_AVATARS = 1;
+ public static boolean MUTEAREA_CAN_WHISPER = false;
+ public static double MAXIMUM_FURNI_HEIGHT = 40d;
- return o2.getScore() - o1.getScore();
- };
- public static final Comparator SORT_ID = (o1, o2) -> {
+ static {
+ for (int i = 1; i <= 3; i++) {
+ RoomMoodlightData data = RoomMoodlightData.fromString("");
+ data.setId(i);
+ defaultMoodData.put(i, data);
+ }
+ }
- if (!(o1 instanceof Room && o2 instanceof Room))
- return 0;
+ public final Object roomUnitLock = new Object();
+ public final ConcurrentHashMap> tileCache = new ConcurrentHashMap<>();
+ public final List userVotes;
+ private final TIntArrayList rights;
+ private final TIntIntHashMap mutedHabbos;
+ private final TIntObjectHashMap bannedHabbos;
+ private final Set games;
+ private final TIntObjectMap moodlightData;
+ private final Object loadLock = new Object();
+ //Use appropriately. Could potentially cause memory leaks when used incorrectly.
+ public volatile boolean preventUnloading = false;
+ public volatile boolean preventUncaching = false;
+ public Set scheduledComposers = ConcurrentHashMap.newKeySet();
+ public Set scheduledTasks = ConcurrentHashMap.newKeySet();
+ public String wordQuiz = "";
+ public int noVotes = 0;
+ public int yesVotes = 0;
+ public int wordQuizEnd = 0;
+ public ScheduledFuture> roomCycleTask;
+ private int id;
+ private int ownerId;
+ private String ownerName;
+ private String name;
+ private String description;
+ private RoomLayout layout;
+ private boolean overrideModel;
+ private String layoutName;
+ private String password;
+ private RoomState state;
+ private int usersMax;
+ private volatile int score;
+ private volatile int category;
+ private String floorPaint;
+ private String wallPaint;
+ private String backgroundPaint;
+ private int wallSize;
+ private int wallHeight;
+ private int floorSize;
+ private int guild;
+ private String tags;
+ private volatile boolean publicRoom;
+ private volatile boolean staffPromotedRoom;
+ private volatile boolean allowPets;
+ private volatile boolean allowPetsEat;
+ private volatile boolean allowWalkthrough;
+ private volatile boolean allowBotsWalk;
+ private volatile boolean allowEffects;
+ private volatile boolean hideWall;
+ private volatile int chatMode;
+ private volatile int chatWeight;
+ private volatile int chatSpeed;
+ private volatile int chatDistance;
+ private volatile int chatProtection;
+ private volatile int muteOption;
+ private volatile int kickOption;
+ private volatile int banOption;
+ private volatile int pollId;
+ private volatile boolean promoted;
+ private volatile int tradeMode;
+ private volatile boolean moveDiagonally;
+ private volatile boolean jukeboxActive;
+ private volatile boolean hideWired;
+ private RoomPromotion promotion;
+ private volatile boolean needsUpdate;
+ private volatile boolean loaded;
+ private volatile boolean preLoaded;
+ private volatile boolean loadingInProgress;
+ private volatile CompletableFuture loadingFuture;
+ private volatile int rollerSpeed;
+ private volatile int lastTimerReset = Emulator.getIntUnixTimestamp();
+ private volatile boolean muted;
+ private RoomSpecialTypes roomSpecialTypes;
+ private TraxManager traxManager;
+
+ public final THashMap cache;
- return o2.getId() - o1.getId();
- };
- private static final TIntObjectHashMap defaultMoodData = new TIntObjectHashMap<>();
- //Configuration. Loaded from database & updated accordingly.
- public static boolean HABBO_CHAT_DELAY = false;
- public static int MAXIMUM_BOTS = 10;
- public static int MAXIMUM_PETS = 10;
- public static int MAXIMUM_FURNI = 2500;
- public static int MAXIMUM_POSTITNOTES = 200;
- public static int HAND_ITEM_TIME = 10;
- public static int IDLE_CYCLES = 240;
- public static int IDLE_CYCLES_KICK = 480;
- public static String PREFIX_FORMAT = "[%prefix%] ";
- public static int ROLLERS_MAXIMUM_ROLL_AVATARS = 1;
- public static boolean MUTEAREA_CAN_WHISPER = false;
- public static double MAXIMUM_FURNI_HEIGHT = 40d;
+ public Room(ResultSet set) throws SQLException {
+ this.cache = new THashMap<>(1000);
+ this.id = set.getInt("id");
+ this.ownerId = set.getInt("owner_id");
+ this.ownerName = set.getString("owner_name");
+ this.name = set.getString("name");
+ this.description = set.getString("description");
+ this.password = set.getString("password");
+ this.state = RoomState.valueOf(set.getString("state").toUpperCase());
+ this.usersMax = set.getInt("users_max");
+ this.score = set.getInt("score");
+ this.category = set.getInt("category");
+ this.floorPaint = set.getString("paper_floor");
+ this.wallPaint = set.getString("paper_wall");
+ this.backgroundPaint = set.getString("paper_landscape");
+ this.wallSize = set.getInt("thickness_wall");
+ this.wallHeight = set.getInt("wall_height");
+ this.floorSize = set.getInt("thickness_floor");
+ this.tags = set.getString("tags");
+ this.publicRoom = set.getBoolean("is_public");
+ this.staffPromotedRoom = set.getBoolean("is_staff_picked");
+ this.allowPets = set.getBoolean("allow_other_pets");
+ this.allowPetsEat = set.getBoolean("allow_other_pets_eat");
+ this.allowWalkthrough = set.getBoolean("allow_walkthrough");
+ this.hideWall = set.getBoolean("allow_hidewall");
+ this.chatMode = set.getInt("chat_mode");
+ this.chatWeight = set.getInt("chat_weight");
+ this.chatSpeed = set.getInt("chat_speed");
+ this.chatDistance = set.getInt("chat_hearing_distance");
+ this.chatProtection = set.getInt("chat_protection");
+ this.muteOption = set.getInt("who_can_mute");
+ this.kickOption = set.getInt("who_can_kick");
+ this.banOption = set.getInt("who_can_ban");
+ this.pollId = set.getInt("poll_id");
+ this.guild = set.getInt("guild_id");
+ this.rollerSpeed = set.getInt("roller_speed");
+ this.overrideModel = set.getString("override_model").equals("1");
+ this.layoutName = set.getString("model");
+ this.promoted = set.getString("promoted").equals("1");
+ this.jukeboxActive = set.getString("jukebox_active").equals("1");
+ this.hideWired = set.getString("hidewired").equals("1");
- static {
- for (int i = 1; i <= 3; i++) {
- RoomMoodlightData data = RoomMoodlightData.fromString("");
- data.setId(i);
- defaultMoodData.put(i, data);
+ this.bannedHabbos = new TIntObjectHashMap<>();
+
+ try (Connection connection = Emulator.getDatabase().getDataSource()
+ .getConnection(); PreparedStatement statement = connection.prepareStatement(
+ "SELECT * FROM room_promotions WHERE room_id = ? AND end_timestamp > ? LIMIT 1")) {
+ if (this.promoted) {
+ statement.setInt(1, this.id);
+ statement.setInt(2, Emulator.getIntUnixTimestamp());
+
+ try (ResultSet promotionSet = statement.executeQuery()) {
+ this.promoted = false;
+ if (promotionSet.next()) {
+ this.promoted = true;
+ this.promotion = new RoomPromotion(this, promotionSet);
+ }
}
+ }
+
+ this.loadBans(connection);
+ } catch (SQLException e) {
+ LOGGER.error("Caught SQL exception", e);
}
- public final Object roomUnitLock = new Object();
- public final ConcurrentHashMap> tileCache = new ConcurrentHashMap<>();
- public final List userVotes;
- private final ConcurrentHashMap currentHabbos = new ConcurrentHashMap<>(3);
- private final TIntObjectMap habboQueue = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
- private final TIntObjectMap currentBots = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
- private final TIntObjectMap currentPets = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
- private final THashSet activeTrades;
- private final TIntArrayList rights;
- private final TIntIntHashMap mutedHabbos;
- private final TIntObjectHashMap bannedHabbos;
- private final Set games;
- private final TIntObjectMap furniOwnerNames;
- private final TIntIntMap furniOwnerCount;
- private final TIntObjectMap moodlightData;
- private final THashSet wordFilterWords;
- private final TIntObjectMap roomItems;
- private final Object loadLock = new Object();
- //Use appropriately. Could potentially cause memory leaks when used incorrectly.
- public volatile boolean preventUnloading = false;
- public volatile boolean preventUncaching = false;
- public Set scheduledComposers = ConcurrentHashMap.newKeySet();
- public Set scheduledTasks = ConcurrentHashMap.newKeySet();
- public String wordQuiz = "";
- public int noVotes = 0;
- public int yesVotes = 0;
- public int wordQuizEnd = 0;
- public ScheduledFuture> roomCycleTask;
- private final int id;
- private int ownerId;
- private String ownerName;
- private String name;
- private String description;
- private RoomLayout layout;
- private boolean overrideModel;
- private final String layoutName;
- private String password;
- private RoomState state;
- private int usersMax;
- private volatile int score;
- private volatile int category;
- private String floorPaint;
- private String wallPaint;
- private String backgroundPaint;
- private int wallSize;
- private int wallHeight;
- private int floorSize;
- private int guild;
- private String tags;
- private volatile boolean publicRoom;
- private volatile boolean staffPromotedRoom;
- private volatile boolean allowPets;
- private volatile boolean allowPetsEat;
- private volatile boolean allowWalkthrough;
- private volatile boolean allowBotsWalk;
- private volatile boolean allowEffects;
- private volatile boolean hideWall;
- private volatile int chatMode;
- private volatile int chatWeight;
- private volatile int chatSpeed;
- private volatile int chatDistance;
- private volatile int chatProtection;
- private volatile int muteOption;
- private volatile int kickOption;
- private volatile int banOption;
- private volatile int pollId;
- private volatile boolean promoted;
- private volatile int tradeMode;
- private volatile boolean moveDiagonally;
- private volatile boolean jukeboxActive;
- private volatile boolean hideWired;
- private RoomPromotion promotion;
- private volatile boolean needsUpdate;
- private volatile boolean loaded;
- private volatile boolean preLoaded;
- private int idleCycles;
- private int idleHostingCycles;
- private volatile int unitCounter;
- private volatile int rollerSpeed;
- private final int muteTime = Emulator.getConfig().getInt("hotel.flood.mute.time", 30);
- private long rollerCycle = System.currentTimeMillis();
- private volatile int lastTimerReset = Emulator.getIntUnixTimestamp();
- private volatile boolean muted;
- private RoomSpecialTypes roomSpecialTypes;
- private TraxManager traxManager;
- private boolean cycleOdd;
- private long cycleTimestamp;
- public Map repeatersLastTick = new HashMap<>();
+ this.tradeMode = set.getInt("trade_mode");
+ this.moveDiagonally = set.getString("move_diagonally").equals("1");
- public Room(ResultSet set) throws SQLException {
- this.id = set.getInt("id");
- this.ownerId = set.getInt("owner_id");
- this.ownerName = set.getString("owner_name");
- this.name = set.getString("name");
- this.description = set.getString("description");
- this.password = set.getString("password");
- this.state = RoomState.valueOf(set.getString("state").toUpperCase());
- this.usersMax = set.getInt("users_max");
- this.score = set.getInt("score");
- this.category = set.getInt("category");
- this.floorPaint = set.getString("paper_floor");
- this.wallPaint = set.getString("paper_wall");
- this.backgroundPaint = set.getString("paper_landscape");
- this.wallSize = set.getInt("thickness_wall");
- this.wallHeight = set.getInt("wall_height");
- this.floorSize = set.getInt("thickness_floor");
- this.tags = set.getString("tags");
- this.publicRoom = set.getBoolean("is_public");
- this.staffPromotedRoom = set.getBoolean("is_staff_picked");
- this.allowPets = set.getBoolean("allow_other_pets");
- this.allowPetsEat = set.getBoolean("allow_other_pets_eat");
- this.allowWalkthrough = set.getBoolean("allow_walkthrough");
- this.hideWall = set.getBoolean("allow_hidewall");
- this.chatMode = set.getInt("chat_mode");
- this.chatWeight = set.getInt("chat_weight");
- this.chatSpeed = set.getInt("chat_speed");
- this.chatDistance = set.getInt("chat_hearing_distance");
- this.chatProtection = set.getInt("chat_protection");
- this.muteOption = set.getInt("who_can_mute");
- this.kickOption = set.getInt("who_can_kick");
- this.banOption = set.getInt("who_can_ban");
- this.pollId = set.getInt("poll_id");
- this.guild = set.getInt("guild_id");
- this.rollerSpeed = set.getInt("roller_speed");
- this.overrideModel = set.getString("override_model").equals("1");
- this.layoutName = set.getString("model");
- this.promoted = set.getString("promoted").equals("1");
- this.jukeboxActive = set.getString("jukebox_active").equals("1");
- this.hideWired = set.getString("hidewired").equals("1");
+ this.preLoaded = true;
+ this.allowBotsWalk = true;
+ this.allowEffects = true;
+ this.moodlightData = new TIntObjectHashMap<>(defaultMoodData);
- this.bannedHabbos = new TIntObjectHashMap<>();
-
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_promotions WHERE room_id = ? AND end_timestamp > ? LIMIT 1")) {
- if (this.promoted) {
- statement.setInt(1, this.id);
- statement.setInt(2, Emulator.getIntUnixTimestamp());
-
- try (ResultSet promotionSet = statement.executeQuery()) {
- this.promoted = false;
- if (promotionSet.next()) {
- this.promoted = true;
- this.promotion = new RoomPromotion(this, promotionSet);
- }
- }
- }
-
- this.loadBans(connection);
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
-
- this.tradeMode = set.getInt("trade_mode");
- this.moveDiagonally = set.getString("move_diagonally").equals("1");
-
- this.preLoaded = true;
- this.allowBotsWalk = true;
- this.allowEffects = true;
- this.furniOwnerNames = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
- this.furniOwnerCount = TCollections.synchronizedMap(new TIntIntHashMap(0));
- this.roomItems = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
- this.wordFilterWords = new THashSet<>(0);
- this.moodlightData = new TIntObjectHashMap<>(defaultMoodData);
-
- for (String s : set.getString("moodlight_data").split(";")) {
- RoomMoodlightData data = RoomMoodlightData.fromString(s);
- this.moodlightData.put(data.getId(), data);
- }
-
- this.mutedHabbos = new TIntIntHashMap();
- this.games = ConcurrentHashMap.newKeySet();
-
- this.activeTrades = new THashSet<>(0);
- this.rights = new TIntArrayList();
- this.userVotes = new ArrayList<>();
+ for (String s : set.getString("moodlight_data").split(";")) {
+ RoomMoodlightData data = RoomMoodlightData.fromString(s);
+ this.moodlightData.put(data.getId(), data);
}
- public synchronized void loadData() {
- synchronized (this.loadLock) {
- if (!this.preLoaded || this.loaded)
- return;
+ this.mutedHabbos = new TIntIntHashMap();
+ this.games = ConcurrentHashMap.newKeySet();
- this.preLoaded = false;
+ this.rights = new TIntArrayList();
+ this.userVotes = new ArrayList<>();
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
- synchronized (this.roomUnitLock) {
- this.unitCounter = 0;
- this.currentHabbos.clear();
- this.currentPets.clear();
- this.currentBots.clear();
- }
+ // Initialize managers
+ this.initializeManagers();
+ }
- this.roomSpecialTypes = new RoomSpecialTypes();
+ /**
+ * Initializes all manager instances for this room.
+ */
+ private void initializeManagers() {
+ this.tileManager = new RoomTileManager(this);
+ this.gameManager = new RoomGameManager(this);
+ this.tradeManager = new RoomTradeManager(this);
+ this.promotionManager = new RoomPromotionManager(this);
+ this.wordQuizManager = new RoomWordQuizManager(this);
+ this.rightsManager = new RoomRightsManager(this);
+ this.unitManager = new RoomUnitManager(this);
+ this.itemManager = new RoomItemManager(this);
+ this.chatManager = new RoomChatManager(this);
+ this.rollerManager = new RoomRollerManager(this);
+ this.messagingManager = new RoomMessagingManager(this);
+ this.cycleManager = new RoomCycleManager(this);
+ }
- try {
- this.loadLayout();
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
+ // ==================== MANAGER GETTERS ====================
- try {
- this.loadRights(connection);
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
+ /**
+ * Gets the tile manager for this room.
+ */
+ public RoomTileManager getTileManager() {
+ return this.tileManager;
+ }
- try {
- this.loadItems(connection);
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
+ /**
+ * Gets the game manager for this room.
+ */
+ public RoomGameManager getGameManager() {
+ return this.gameManager;
+ }
- try {
- this.loadHeightmap();
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
+ /**
+ * Gets the trade manager for this room.
+ */
+ public RoomTradeManager getTradeManager() {
+ return this.tradeManager;
+ }
- try {
- this.loadBots(connection);
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
+ /**
+ * Gets the promotion manager for this room.
+ */
+ public RoomPromotionManager getPromotionManager() {
+ return this.promotionManager;
+ }
- try {
- this.loadPets(connection);
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
+ /**
+ * Gets the word quiz manager for this room.
+ */
+ public RoomWordQuizManager getWordQuizManager() {
+ return this.wordQuizManager;
+ }
- try {
- this.loadWordFilter(connection);
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
+ /**
+ * Gets the rights manager for this room.
+ */
+ public RoomRightsManager getRightsManager() {
+ return this.rightsManager;
+ }
- try {
- this.loadWiredData(connection);
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
+ /**
+ * Gets the unit manager for this room.
+ */
+ public RoomUnitManager getUnitManager() {
+ return this.unitManager;
+ }
- this.idleCycles = 0;
- this.idleHostingCycles = 0;
- this.loaded = true;
+ /**
+ * Gets the item manager for this room.
+ */
+ public RoomItemManager getItemManager() {
+ return this.itemManager;
+ }
- this.roomCycleTask = Emulator.getThreading().getService().scheduleAtFixedRate(this, 500, 500, TimeUnit.MILLISECONDS);
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
+ /**
+ * Gets the chat manager for this room.
+ */
+ public RoomChatManager getChatManager() {
+ return this.chatManager;
+ }
- this.traxManager = new TraxManager(this);
+ /**
+ * Gets the messaging manager for this room.
+ */
+ public RoomMessagingManager getMessagingManager() {
+ return this.messagingManager;
+ }
- if (this.jukeboxActive) {
- this.traxManager.play(0);
- for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionJukeBox.class)) {
- item.setExtradata("1");
- this.updateItem(item);
- }
- }
+ /**
+ * Gets the cycle manager for this room.
+ */
+ public RoomCycleManager getCycleManager() {
+ return this.cycleManager;
+ }
- for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionFireworks.class)) {
- item.setExtradata("1");
- this.updateItem(item);
- }
- }
+ /**
+ * Gets the roller manager for this room.
+ */
+ public RoomRollerManager getRollerManager() {
+ return this.rollerManager;
+ }
- Emulator.getPluginManager().fireEvent(new RoomLoadedEvent(this));
+ /**
+ * Checks if the room is currently loading data.
+ */
+ public boolean isLoadingInProgress() {
+ synchronized (this.loadLock) {
+ return this.loadingInProgress;
+ }
+ }
+
+ /**
+ * Checks if the room data is loaded or is currently being loaded.
+ */
+ public boolean isLoadedOrLoading() {
+ synchronized (this.loadLock) {
+ return this.loaded || this.loadingInProgress;
+ }
+ }
+
+ /**
+ * Starts loading room data asynchronously in the background.
+ * This allows the room to start loading before the user fully enters,
+ * reducing perceived load time.
+ */
+ public void startBackgroundLoad() {
+ synchronized (this.loadLock) {
+ if (this.loaded || this.loadingInProgress || !this.preLoaded) {
+ return;
+ }
+
+ this.loadingInProgress = true;
+ this.loadingFuture = CompletableFuture.runAsync(() -> {
+ this.loadDataInternal();
+ }, Emulator.getThreading().getService());
+ }
+ }
+
+ /**
+ * Waits for background loading to complete if it's in progress.
+ * If loading hasn't started yet, starts loading synchronously.
+ */
+ public void waitForLoad() {
+ CompletableFuture future;
+ synchronized (this.loadLock) {
+ if (this.loaded) {
+ return;
+ }
+ future = this.loadingFuture;
+ }
+
+ if (future != null) {
+ try {
+ future.join();
+ } catch (Exception e) {
+ LOGGER.error("Error waiting for room load", e);
+ }
+ } else {
+ this.loadData();
+ }
+ }
+
+ public void loadData() {
+ CompletableFuture futureToWait = null;
+ boolean shouldLoad = false;
+
+ synchronized (this.loadLock) {
+ if (this.loadingInProgress) {
+ // Get the future to wait on outside the lock
+ futureToWait = this.loadingFuture;
+ } else if (this.preLoaded && !this.loaded) {
+ this.loadingInProgress = true;
+ shouldLoad = true;
+ }
+ }
+
+ // Wait for existing load outside the lock
+ if (futureToWait != null) {
+ try {
+ futureToWait.join();
+ } catch (Exception e) {
+ LOGGER.error("Error waiting for room load", e);
+ }
+ return;
+ }
+
+ // Load if needed
+ if (shouldLoad) {
+ this.loadDataInternal();
+ }
+ }
+
+ /**
+ * Internal method that performs the actual room data loading.
+ * Uses parallel loading for independent operations to reduce total load time.
+ */
+ private void loadDataInternal() {
+ // Check if already loaded (with lock)
+ synchronized (this.loadLock) {
+ if (this.loaded) {
+ this.loadingInProgress = false;
+ return;
+ }
+ this.preLoaded = false;
}
- private synchronized void loadLayout() {
- if (this.layout == null) {
- if (this.overrideModel) {
- this.layout = Emulator.getGameEnvironment().getRoomManager().loadCustomLayout(this);
- } else {
- this.layout = Emulator.getGameEnvironment().getRoomManager().loadLayout(this.layoutName, this);
- }
- }
- }
+ // Perform loading WITHOUT holding the lock to avoid deadlocks
+ try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
+ synchronized (this.roomUnitLock) {
+ this.unitManager.clear();
+ }
- private synchronized void loadHeightmap() {
- if (this.layout != null) {
- for (short x = 0; x < this.layout.getMapSizeX(); x++) {
- for (short y = 0; y < this.layout.getMapSizeY(); y++) {
- RoomTile tile = this.layout.getTile(x, y);
- if (tile != null) {
- this.updateTile(tile);
- }
- }
- }
- } else {
- LOGGER.error("Unknown Room Layout for Room (ID: {})", this.id);
- }
- }
+ this.roomSpecialTypes = new RoomSpecialTypes();
- private synchronized void loadItems(Connection connection) {
- this.roomItems.clear();
+ // Phase 1: Load layout first (required for bots/pets positioning)
+ try {
+ this.loadLayout();
+ } catch (Exception e) {
+ LOGGER.error("Caught exception loading layout", e);
+ }
- try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM items WHERE room_id = ?")) {
- statement.setInt(1, this.id);
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- this.addHabboItem(Emulator.getGameEnvironment().getItemManager().loadHabboItem(set));
- }
- }
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
-
- if (this.itemCount() > Room.MAXIMUM_FURNI) {
- LOGGER.error("Room ID: {} has exceeded the furniture limit ({} > {}).", this.getId(), this.itemCount(), Room.MAXIMUM_FURNI);
- }
- }
-
- private synchronized void loadWiredData(Connection connection) {
- try (PreparedStatement statement = connection.prepareStatement("SELECT id, wired_data FROM items WHERE room_id = ? AND wired_data<>''")) {
- statement.setInt(1, this.id);
-
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- try {
- HabboItem item = this.getHabboItem(set.getInt("id"));
-
- if (item instanceof InteractionWired) {
- ((InteractionWired) item).loadWiredData(set, this);
- }
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
- }
- }
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
+ // Phase 2: Load items and rights in parallel (independent operations)
+ CompletableFuture itemsFuture = CompletableFuture.runAsync(() -> {
+ try (Connection itemConnection = Emulator.getDatabase().getDataSource().getConnection()) {
+ this.loadItems(itemConnection);
} catch (Exception e) {
- LOGGER.error("Caught exception", e);
+ LOGGER.error("Caught exception loading items", e);
}
- }
+ }, Emulator.getThreading().getService());
- private synchronized void loadBots(Connection connection) {
- this.currentBots.clear();
-
- try (PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.user_id = users.id WHERE room_id = ?")) {
- statement.setInt(1, this.id);
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- Bot b = Emulator.getGameEnvironment().getBotManager().loadBot(set);
-
- if (b != null) {
- b.setRoom(this);
- b.setRoomUnit(new RoomUnit());
- b.getRoomUnit().setPathFinderRoom(this);
- b.getRoomUnit().setLocation(this.layout.getTile((short) set.getInt("x"), (short) set.getInt("y")));
- if (b.getRoomUnit().getCurrentLocation() == null) {
- b.getRoomUnit().setLocation(this.getLayout().getDoorTile());
- b.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection()));
- } else {
- b.getRoomUnit().setZ(set.getDouble("z"));
- b.getRoomUnit().setPreviousLocationZ(set.getDouble("z"));
- b.getRoomUnit().setRotation(RoomUserRotation.values()[set.getInt("rot")]);
- }
- b.getRoomUnit().setRoomUnitType(RoomUnitType.BOT);
- b.getRoomUnit().setDanceType(DanceType.values()[set.getInt("dance")]);
- //b.getRoomUnit().setCanWalk(set.getBoolean("freeroam"));
- b.getRoomUnit().setInRoom(true);
- this.giveEffect(b.getRoomUnit(), set.getInt("effect"), Integer.MAX_VALUE);
- this.addBot(b);
- }
- }
- }
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
- }
-
- private synchronized void loadPets(Connection connection) {
- this.currentPets.clear();
-
- try (PreparedStatement statement = connection.prepareStatement("SELECT users.username as pet_owner_name, users_pets.* FROM users_pets INNER JOIN users ON users_pets.user_id = users.id WHERE room_id = ?")) {
- statement.setInt(1, this.id);
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- try {
- Pet pet = PetManager.loadPet(set);
- pet.setRoom(this);
- pet.setRoomUnit(new RoomUnit());
- pet.getRoomUnit().setPathFinderRoom(this);
- pet.getRoomUnit().setLocation(this.layout.getTile((short) set.getInt("x"), (short) set.getInt("y")));
- if (pet.getRoomUnit().getCurrentLocation() == null) {
- pet.getRoomUnit().setLocation(this.getLayout().getDoorTile());
- pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection()));
- } else {
- pet.getRoomUnit().setZ(set.getDouble("z"));
- pet.getRoomUnit().setRotation(RoomUserRotation.values()[set.getInt("rot")]);
- }
- pet.getRoomUnit().setRoomUnitType(RoomUnitType.PET);
- pet.getRoomUnit().setCanWalk(true);
- this.addPet(pet);
-
- this.getFurniOwnerNames().put(pet.getUserId(), set.getString("pet_owner_name"));
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
- }
- }
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
- }
-
- private synchronized void loadWordFilter(Connection connection) {
- this.wordFilterWords.clear();
-
- try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_wordfilter WHERE room_id = ?")) {
- statement.setInt(1, this.id);
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- this.wordFilterWords.add(set.getString("word"));
- }
- }
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
- }
-
- public void updateTile(RoomTile tile) {
- if (tile != null) {
- tile.setStackHeight(this.getStackHeight(tile.x, tile.y, false));
- tile.setState(this.calculateTileState(tile));
- }
- }
-
- public void updateTiles(THashSet tiles) {
- for (RoomTile tile : tiles) {
- this.tileCache.remove(tile);
- tile.setStackHeight(this.getStackHeight(tile.x, tile.y, false));
- tile.setState(this.calculateTileState(tile));
- }
-
- this.sendComposer(new UpdateStackHeightComposer(this, tiles).compose());
- }
-
- private RoomTileState calculateTileState(RoomTile tile) {
- return this.calculateTileState(tile, null);
- }
-
- private RoomTileState calculateTileState(RoomTile tile, HabboItem exclude) {
- if (tile == null || tile.state == RoomTileState.INVALID)
- return RoomTileState.INVALID;
-
- RoomTileState result = RoomTileState.OPEN;
- //HabboItem highestItem = null;
- //HabboItem lowestChair = this.getLowestChair(tile);
- THashSet items = this.getItemsAt(tile);
-
- if (items == null) return RoomTileState.INVALID;
-
- HabboItem tallestItem = null;
-
- for (HabboItem item : items) {
- if (exclude != null && item == exclude) continue;
-
- if (item.getBaseItem().allowLay()) {
- return RoomTileState.LAY;
- }
-
- /*if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
- continue;
-
- highestItem = item;*/
-
- if (tallestItem != null && tallestItem.getZ() + Item.getCurrentHeight(tallestItem) > item.getZ() + Item.getCurrentHeight(item))
- continue;
-
- result = this.checkStateForItem(item, tile);
- tallestItem = item;
-
- /*if (lowestChair != null && item.getZ() > lowestChair.getZ() + 1.5) {
- continue;
- }
-
- if (lowestItem == null || lowestItem.getZ() < item.getZ()) {
- lowestItem = item;
-
- result = this.checkStateForItem(lowestItem, tile);
- } else if (lowestItem.getZ() == item.getZ()) {
- if (result == RoomTileState.OPEN) {
- result = this.checkStateForItem(item, tile);
- }
- }*/
- }
-
- //if (lowestChair != null) return RoomTileState.SIT;
-
- return result;
- }
-
- private RoomTileState checkStateForItem(HabboItem item, RoomTile tile) {
- RoomTileState result = RoomTileState.BLOCKED;
-
- if (item.isWalkable()) {
- result = RoomTileState.OPEN;
- }
-
- if (item.getBaseItem().allowSit()) {
- result = RoomTileState.SIT;
- }
-
- if (item.getBaseItem().allowLay()) {
- result = RoomTileState.LAY;
- }
-
- RoomTileState overriddenState = item.getOverrideTileState(tile, this);
- if (overriddenState != null) {
- result = overriddenState;
- }
-
- if (this.getItemsAt(tile).stream().anyMatch(i -> i instanceof InteractionTileWalkMagic)) {
- result = RoomTileState.OPEN;
- }
-
- return result;
- }
-
- public boolean tileWalkable(RoomTile t) {
- return this.tileWalkable(t.x, t.y);
- }
-
- public boolean tileWalkable(short x, short y) {
- boolean walkable = this.layout.tileWalkable(x, y);
- RoomTile tile = this.getLayout().getTile(x, y);
-
- if (walkable && tile != null) {
- if (tile.hasUnits() && !this.allowWalkthrough) {
- walkable = false;
- }
- }
-
- return walkable;
- }
-
- public void pickUpItem(HabboItem item, Habbo picker) {
- if (item == null)
- return;
-
- if (Emulator.getPluginManager().isRegistered(FurniturePickedUpEvent.class, true)) {
- Event furniturePickedUpEvent = new FurniturePickedUpEvent(item, picker);
- Emulator.getPluginManager().fireEvent(furniturePickedUpEvent);
-
- if (furniturePickedUpEvent.isCancelled())
- return;
- }
-
- this.removeHabboItem(item.getId());
- item.onPickUp(this);
- item.setRoomId(0);
- item.needsUpdate(true);
-
- if (item.getBaseItem().getType() == FurnitureType.FLOOR) {
- this.sendComposer(new RemoveFloorItemComposer(item).compose());
-
- THashSet updatedTiles = new THashSet<>();
- Rectangle rectangle = RoomLayout.getRectangle(item.getX(), item.getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
-
- for (short x = (short) rectangle.x; x < rectangle.x + rectangle.getWidth(); x++) {
- for (short y = (short) rectangle.y; y < rectangle.y + rectangle.getHeight(); y++) {
- double stackHeight = this.getStackHeight(x, y, false);
- RoomTile tile = this.layout.getTile(x, y);
-
- if (tile != null) {
- tile.setStackHeight(stackHeight);
- updatedTiles.add(tile);
- }
- }
- }
- this.sendComposer(new UpdateStackHeightComposer(this, updatedTiles).compose());
- this.updateTiles(updatedTiles);
- for (RoomTile tile : updatedTiles) {
- this.updateHabbosAt(tile.x, tile.y);
- this.updateBotsAt(tile.x, tile.y);
- }
- } else if (item.getBaseItem().getType() == FurnitureType.WALL) {
- this.sendComposer(new RemoveWallItemComposer(item).compose());
- }
-
- Habbo habbo = (picker != null && picker.getHabboInfo().getId() == item.getId() ? picker : Emulator.getGameServer().getGameClientManager().getHabbo(item.getUserId()));
- if (habbo != null) {
- habbo.getInventory().getItemsComponent().addItem(item);
- habbo.getClient().sendResponse(new AddHabboItemComposer(item));
- habbo.getClient().sendResponse(new InventoryRefreshComposer());
- }
- Emulator.getThreading().run(item);
- }
-
- public void updateHabbosAt(Rectangle rectangle) {
- for (short i = (short) rectangle.x; i < rectangle.x + rectangle.width; i++) {
- for (short j = (short) rectangle.y; j < rectangle.y + rectangle.height; j++) {
- this.updateHabbosAt(i, j);
- }
- }
- }
-
- public void updateHabbo(Habbo habbo) {
- this.updateRoomUnit(habbo.getRoomUnit());
- }
-
- public void updateRoomUnit(RoomUnit roomUnit) {
- HabboItem item = this.getTopItemAt(roomUnit.getX(), roomUnit.getY());
-
- if ((item == null && !roomUnit.cmdSit) || (item != null && !item.getBaseItem().allowSit()))
- roomUnit.removeStatus(RoomUnitStatus.SIT);
-
- double oldZ = roomUnit.getZ();
-
- if (item != null) {
- if (item.getBaseItem().allowSit()) {
- roomUnit.setZ(item.getZ());
- } else {
- roomUnit.setZ(item.getZ() + Item.getCurrentHeight(item));
- }
-
- if (oldZ != roomUnit.getZ()) {
- this.scheduledTasks.add(() -> {
- try {
- item.onWalkOn(roomUnit, Room.this, null);
- } catch (Exception e) {
-
- }
- });
- }
- }
-
- this.sendComposer(new RoomUserStatusComposer(roomUnit).compose());
- }
-
- public void updateHabbosAt(short x, short y) {
- this.updateHabbosAt(x, y, this.getHabbosAt(x, y));
- }
-
- public void updateHabbosAt(short x, short y, THashSet habbos) {
- HabboItem item = this.getTopItemAt(x, y);
-
- for (Habbo habbo : habbos) {
-
- double oldZ = habbo.getRoomUnit().getZ();
- RoomUserRotation oldRotation = habbo.getRoomUnit().getBodyRotation();
- double z = habbo.getRoomUnit().getCurrentLocation().getStackHeight();
- boolean updated = false;
-
- if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT) && ((item == null && !habbo.getRoomUnit().cmdSit) || (item != null && !item.getBaseItem().allowSit()))) {
- habbo.getRoomUnit().removeStatus(RoomUnitStatus.SIT);
- updated = true;
- }
-
- if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.LAY) && ((item == null && !habbo.getRoomUnit().cmdLay) || (item != null && !item.getBaseItem().allowLay()))) {
- habbo.getRoomUnit().removeStatus(RoomUnitStatus.LAY);
- updated = true;
- }
-
- if (item != null && (item.getBaseItem().allowSit() || item.getBaseItem().allowLay())) {
- habbo.getRoomUnit().setZ(item.getZ());
- habbo.getRoomUnit().setPreviousLocationZ(item.getZ());
- habbo.getRoomUnit().setRotation(RoomUserRotation.fromValue(item.getRotation()));
- } else {
- habbo.getRoomUnit().setZ(z);
- habbo.getRoomUnit().setPreviousLocationZ(z);
- }
-
- if (habbo.getRoomUnit().getCurrentLocation().is(x, y) && (oldZ != z || updated || oldRotation != habbo.getRoomUnit().getBodyRotation())) {
- habbo.getRoomUnit().statusUpdate(true);
- //roomUnits.add(habbo.getRoomUnit());
- }
- }
-
- /*if (!roomUnits.isEmpty()) {
- this.sendComposer(new RoomUserStatusComposer(roomUnits, true).compose());
- }*/
- }
-
- public void updateBotsAt(short x, short y) {
- HabboItem topItem = this.getTopItemAt(x, y);
-
- THashSet roomUnits = new THashSet<>();
-
- for (Bot bot : this.getBotsAt(this.layout.getTile(x, y))) {
- if (topItem != null) {
- if (topItem.getBaseItem().allowSit()) {
- bot.getRoomUnit().setZ(topItem.getZ());
- bot.getRoomUnit().setPreviousLocationZ(topItem.getZ());
- bot.getRoomUnit().setRotation(RoomUserRotation.fromValue(topItem.getRotation()));
- } else {
- bot.getRoomUnit().setZ(topItem.getZ() + Item.getCurrentHeight(topItem));
-
- if (topItem.getBaseItem().allowLay()) {
- bot.getRoomUnit().setStatus(RoomUnitStatus.LAY, (topItem.getZ() + topItem.getBaseItem().getHeight()) + "");
- }
- }
- } else {
- bot.getRoomUnit().setZ(bot.getRoomUnit().getCurrentLocation().getStackHeight());
- bot.getRoomUnit().setPreviousLocationZ(bot.getRoomUnit().getCurrentLocation().getStackHeight());
- }
-
- roomUnits.add(bot.getRoomUnit());
- }
-
- if (!roomUnits.isEmpty()) {
- this.sendComposer(new RoomUserStatusComposer(roomUnits, true).compose());
- }
- }
-
- public void updatePetsAt(short x, short y) {
- HabboItem topItem = this.getTopItemAt(x, y);
-
- THashSet roomUnits = new THashSet<>();
-
- for (Pet pet : this.getPetsAt(this.layout.getTile(x, y))) {
- if (topItem != null) {
- if (topItem.getBaseItem().allowSit()) {
- pet.getRoomUnit().setZ(topItem.getZ());
- pet.getRoomUnit().setPreviousLocationZ(topItem.getZ());
- pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(topItem.getRotation()));
- } else {
- pet.getRoomUnit().setZ(topItem.getZ() + Item.getCurrentHeight(topItem));
-
- if (topItem.getBaseItem().allowLay()) {
- pet.getRoomUnit().setStatus(RoomUnitStatus.LAY, (topItem.getZ() + topItem.getBaseItem().getHeight()) + "");
- }
- }
- } else {
- pet.getRoomUnit().setZ(pet.getRoomUnit().getCurrentLocation().getStackHeight());
- pet.getRoomUnit().setPreviousLocationZ(pet.getRoomUnit().getCurrentLocation().getStackHeight());
- }
-
- roomUnits.add(pet.getRoomUnit());
- }
-
- if (!roomUnits.isEmpty()) {
- this.sendComposer(new RoomUserStatusComposer(roomUnits, true).compose());
- }
- }
-
- public void pickupPetsForHabbo(Habbo habbo) {
- THashSet pets = new THashSet<>();
-
- synchronized (this.currentPets) {
- for (Pet pet : this.currentPets.valueCollection()) {
- if (pet.getUserId() == habbo.getHabboInfo().getId()) {
- pets.add(pet);
- }
- }
- }
-
- for (Pet pet : pets) {
- pet.removeFromRoom();
- Emulator.getThreading().run(pet);
- habbo.getInventory().getPetsComponent().addPet(pet);
- habbo.getClient().sendResponse(new AddPetComposer(pet));
- this.currentPets.remove(pet.getId());
- }
-
- }
-
- public void startTrade(Habbo userOne, Habbo userTwo) {
- RoomTrade trade = new RoomTrade(userOne, userTwo, this);
- synchronized (this.activeTrades) {
- this.activeTrades.add(trade);
- }
-
- trade.start();
- }
-
- public void stopTrade(RoomTrade trade) {
- synchronized (this.activeTrades) {
- this.activeTrades.remove(trade);
- }
- }
-
- public RoomTrade getActiveTradeForHabbo(Habbo user) {
- synchronized (this.activeTrades) {
- for (RoomTrade trade : this.activeTrades) {
- for (RoomTradeUser habbo : trade.getRoomTradeUsers()) {
- if (habbo.getHabbo() == user)
- return trade;
- }
- }
- }
- return null;
- }
-
- public synchronized void dispose() {
- synchronized (this.loadLock) {
- if (this.preventUnloading)
- return;
-
- if (Emulator.getPluginManager().fireEvent(new RoomUnloadingEvent(this)).isCancelled())
- return;
-
- if (this.loaded) {
- try {
-
- if (this.traxManager != null && !this.traxManager.disposed()) {
- this.traxManager.dispose();
- }
-
- this.roomCycleTask.cancel(false);
- this.scheduledTasks.clear();
- this.scheduledComposers.clear();
- this.loaded = false;
-
- this.tileCache.clear();
-
- synchronized (this.mutedHabbos) {
- this.mutedHabbos.clear();
- }
-
- for (InteractionGameTimer timer : this.getRoomSpecialTypes().getGameTimers().values()) {
- timer.setRunning(false);
- }
-
- for (Game game : this.games) {
- game.dispose();
- }
- this.games.clear();
-
- removeAllPets(ownerId);
-
- synchronized (this.roomItems) {
- TIntObjectIterator iterator = this.roomItems.iterator();
-
- for (int i = this.roomItems.size(); i-- > 0; ) {
- try {
- iterator.advance();
-
- if (iterator.value().needsUpdate())
- iterator.value().run();
- } catch (NoSuchElementException e) {
- break;
- }
- }
- }
-
- if (this.roomSpecialTypes != null) {
- this.roomSpecialTypes.dispose();
- }
-
- synchronized (this.roomItems) {
- this.roomItems.clear();
- }
-
- synchronized (this.habboQueue) {
- this.habboQueue.clear();
- }
-
-
- for (Habbo habbo : this.currentHabbos.values()) {
- Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this);
- }
-
- this.sendComposer(new HotelViewComposer().compose());
-
- this.currentHabbos.clear();
-
-
- TIntObjectIterator botIterator = this.currentBots.iterator();
-
- for (int i = this.currentBots.size(); i-- > 0; ) {
- try {
- botIterator.advance();
- botIterator.value().needsUpdate(true);
- Emulator.getThreading().run(botIterator.value());
- } catch (NoSuchElementException e) {
- LOGGER.error("Caught exception", e);
- break;
- }
- }
-
- this.currentBots.clear();
- this.currentPets.clear();
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
- }
-
- try {
- this.wordQuiz = "";
- this.yesVotes = 0;
- this.noVotes = 0;
- this.updateDatabaseUserCount();
- this.preLoaded = true;
- this.layout = null;
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
- }
-
- Emulator.getPluginManager().fireEvent(new RoomUnloadedEvent(this));
- }
-
- @Override
- public int compareTo(Room o) {
- if (o.getUserCount() != this.getUserCount()) {
- return o.getCurrentHabbos().size() - this.getCurrentHabbos().size();
- }
-
- return this.id - o.id;
- }
-
- @Override
- public void serialize(ServerMessage message) {
- message.appendInt(this.id);
- message.appendString(this.name);
- if (this.isPublicRoom()) {
- message.appendInt(0);
- message.appendString("");
- } else {
- message.appendInt(this.ownerId);
- message.appendString(this.ownerName);
- }
- message.appendInt(this.state.getState());
- message.appendInt(this.getUserCount());
- message.appendInt(this.usersMax);
- message.appendString(this.description);
- message.appendInt(0);
- message.appendInt(this.score);
- message.appendInt(0);
- message.appendInt(this.category);
-
- String[] tags = Arrays.stream(this.tags.split(";")).filter(t -> !t.isEmpty()).toArray(String[]::new);
- message.appendInt(tags.length);
- for (String s : tags) {
- message.appendString(s);
- }
-
- int base = 0;
-
- if (this.getGuildId() > 0) {
- base = base | 2;
- }
-
- if (this.isPromoted()) {
- base = base | 4;
- }
-
- if (!this.isPublicRoom()) {
- base = base | 8;
- }
-
- if (this.isAllowPets()) {
- base = base | 16;
- }
-
- message.appendInt(base);
-
- if (this.getGuildId() > 0) {
- Guild g = Emulator.getGameEnvironment().getGuildManager().getGuild(this.getGuildId());
- if (g != null) {
- message.appendInt(g.getId());
- message.appendString(g.getName());
- message.appendString(g.getBadge());
- } else {
- message.appendInt(0);
- message.appendString("");
- message.appendString("");
- }
- }
-
- if (this.promoted) {
- message.appendString(this.promotion.getTitle());
- message.appendString(this.promotion.getDescription());
- message.appendInt((this.promotion.getEndTimestamp() - Emulator.getIntUnixTimestamp()) / 60);
- }
-
- }
-
- @Override
- public void run() {
- synchronized (this.loadLock) {
- if (this.loaded) {
- try {
- Emulator.getThreading().run(
- Room.this::cycle);
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
- }
- }
-
- this.save();
- }
-
- public void save() {
- if (this.needsUpdate) {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE rooms SET name = ?, description = ?, password = ?, state = ?, users_max = ?, category = ?, score = ?, paper_floor = ?, paper_wall = ?, paper_landscape = ?, thickness_wall = ?, wall_height = ?, thickness_floor = ?, moodlight_data = ?, tags = ?, allow_other_pets = ?, allow_other_pets_eat = ?, allow_walkthrough = ?, allow_hidewall = ?, chat_mode = ?, chat_weight = ?, chat_speed = ?, chat_hearing_distance = ?, chat_protection =?, who_can_mute = ?, who_can_kick = ?, who_can_ban = ?, poll_id = ?, guild_id = ?, roller_speed = ?, override_model = ?, is_staff_picked = ?, promoted = ?, trade_mode = ?, move_diagonally = ?, owner_id = ?, owner_name = ?, jukebox_active = ?, hidewired = ? WHERE id = ?")) {
- statement.setString(1, this.name);
- statement.setString(2, this.description);
- statement.setString(3, this.password);
- statement.setString(4, this.state.name().toLowerCase());
- statement.setInt(5, this.usersMax);
- statement.setInt(6, this.category);
- statement.setInt(7, this.score);
- statement.setString(8, this.floorPaint);
- statement.setString(9, this.wallPaint);
- statement.setString(10, this.backgroundPaint);
- statement.setInt(11, this.wallSize);
- statement.setInt(12, this.wallHeight);
- statement.setInt(13, this.floorSize);
- StringBuilder moodLightData = new StringBuilder();
-
- int id = 1;
- for (RoomMoodlightData data : this.moodlightData.valueCollection()) {
- data.setId(id);
- moodLightData.append(data).append(";");
- id++;
- }
-
- statement.setString(14, moodLightData.toString());
- statement.setString(15, this.tags);
- statement.setString(16, this.allowPets ? "1" : "0");
- statement.setString(17, this.allowPetsEat ? "1" : "0");
- statement.setString(18, this.allowWalkthrough ? "1" : "0");
- statement.setString(19, this.hideWall ? "1" : "0");
- statement.setInt(20, this.chatMode);
- statement.setInt(21, this.chatWeight);
- statement.setInt(22, this.chatSpeed);
- statement.setInt(23, this.chatDistance);
- statement.setInt(24, this.chatProtection);
- statement.setInt(25, this.muteOption);
- statement.setInt(26, this.kickOption);
- statement.setInt(27, this.banOption);
- statement.setInt(28, this.pollId);
- statement.setInt(29, this.guild);
- statement.setInt(30, this.rollerSpeed);
- statement.setString(31, this.overrideModel ? "1" : "0");
- statement.setString(32, this.staffPromotedRoom ? "1" : "0");
- statement.setString(33, this.promoted ? "1" : "0");
- statement.setInt(34, this.tradeMode);
- statement.setString(35, this.moveDiagonally ? "1" : "0");
- statement.setInt(36, this.ownerId);
- statement.setString(37, this.ownerName);
- statement.setString(38, this.jukeboxActive ? "1" : "0");
- statement.setString(39, this.hideWired ? "1" : "0");
- statement.setInt(40, this.id);
- statement.executeUpdate();
- this.needsUpdate = false;
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
- }
- }
-
- private void updateDatabaseUserCount() {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE rooms SET users = ? WHERE id = ? LIMIT 1")) {
- statement.setInt(1, this.currentHabbos.size());
- statement.setInt(2, this.id);
- statement.executeUpdate();
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
- }
-
- private boolean isOnRoller(RoomUnit unit) {
- RoomTile currentTile = unit.getCurrentLocation();
- // Iterate over all rollers in the room.
- for (HabboItem roller : this.roomSpecialTypes.getRollers().values()) {
- if (roller.getX() == currentTile.x && roller.getY() == currentTile.y) {
- return true;
- }
- }
- return false;
- }
-
- private final Map loopTrackers = new ConcurrentHashMap<>();
-
- private static class LoopTracker {
- double x, y, z;
- int counter;
- RoomTile nextTile;
-
- public LoopTracker(double x, double y, double z, RoomTile nextTile) {
- this.x = x;
- this.y = y;
- this.z = z;
- this.counter = 0;
- this.nextTile = nextTile;
- }
-
- public boolean isSamePosition(double newX, double newY, double newZ) {
- // Use an epsilon for double comparison if necessary.
- final double EPSILON = 0.001;
- return Math.abs(newX - x) < EPSILON && Math.abs(newY - y) < EPSILON && Math.abs(newZ - z) < EPSILON;
- }
-
- public void update(double newX, double newY, double newZ, RoomTile nextTile) {
- this.x = newX;
- this.y = newY;
- this.z = newZ;
- this.counter = 0;
- this.nextTile = nextTile;
- }
- }
-
- private void cycle() {
- this.cycleOdd = !this.cycleOdd;
- this.cycleTimestamp = System.currentTimeMillis();
- final boolean[] foundRightHolder = {false};
-
- boolean loaded;
- synchronized (this.loadLock) {
- loaded = this.loaded;
- }
- this.tileCache.clear();
- if (loaded) {
- if (!this.scheduledTasks.isEmpty()) {
- Set tasks = this.scheduledTasks;
- this.scheduledTasks = ConcurrentHashMap.newKeySet();
-
- for (Runnable runnable : tasks) {
- Emulator.getThreading().run(runnable);
- }
- }
-
- for (ICycleable task : this.roomSpecialTypes.getCycleTasks()) {
- task.cycle(this);
- }
-
- if (Emulator.getConfig().getBoolean("hotel.rooms.deco_hosting")) {
- if (this.idleHostingCycles < 120) {
- this.idleHostingCycles++;
- } else {
- this.idleHostingCycles = 0;
-
- int amount = (int) this.currentHabbos.values().stream().filter(habbo -> habbo.getHabboInfo().getId() != this.ownerId).count();
- if (amount > 0) {
- AchievementManager.progressAchievement(this.ownerId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting"), amount);
- }
- }
- }
-
- if (!this.currentHabbos.isEmpty()) {
- this.idleCycles = 0;
-
- THashSet updatedUnit = new THashSet<>();
- ArrayList toKick = new ArrayList<>();
-
- final Room room = this;
-
- final long millis = System.currentTimeMillis();
-
- for (Habbo habbo : this.currentHabbos.values()) {
- RoomUnit unit = habbo.getRoomUnit();
- // Only run loop detection if the unit is on a roller.
- if (!unit.hasStatus(RoomUnitStatus.MOVE) && isOnRoller(unit)) {
- // Get the current coordinates of the unit on the roller:
- double curX = unit.getX();
- double curY = unit.getY();
- double curZ = unit.getZ();
-
- // Get or create a loop tracker for this unit.
- LoopTracker tracker = loopTrackers.computeIfAbsent(unit, u -> {
- RoomTile nextTile = null;
- for (InteractionRoller roller : this.roomSpecialTypes.getRollers().values()) {
- RoomTile rollerTile = this.getLayout().getTile(roller.getX(), roller.getY());
- RoomTile potentialNextTile = this.getLayout().getTileInFront(rollerTile, roller.getRotation());
- if (potentialNextTile != null) {
- nextTile = potentialNextTile;
- break; // use the first valid next tile found
- }
- }
- return new LoopTracker(curX, curY, curZ, nextTile);
- });
-
- // Check if the unit’s current position is the same as last cycle.
- if (tracker.isSamePosition(curX, curY, curZ)) {
- // Find the roller that is on the current tile.
- InteractionRoller currentRoller = null;
- RoomTile currentTile = this.getLayout().getTile((short) curX, (short) curY);
- for (InteractionRoller roller : this.roomSpecialTypes.getRollers().values()) {
- if (roller.getX() == currentTile.x && roller.getY() == currentTile.y) {
- currentRoller = roller;
- break;
- }
- }
-
- // Calculate the next tile using the current roller.
- RoomTile currentCalculatedNextTile = null;
- if (currentRoller != null) {
- RoomTile rollerTile = this.getLayout().getTile(currentRoller.getX(), currentRoller.getY());
- currentCalculatedNextTile = this.getLayout().getTileInFront(rollerTile, currentRoller.getRotation());
- }
-
- // Here we add a check:
- // If the unit's goal is either on the roller itself or is within a small distance (epsilon) of the roller tile,
- // then we assume the habbo is "almost there" and do not increment the loop counter.
- if (currentTile != null && unit.getGoal() != null) {
- double distanceToGoal = Math.hypot(unit.getGoal().x - currentTile.x, unit.getGoal().y - currentTile.y);
- final double ACCEPTABLE_DISTANCE = 0.5; // adjust as needed
- if (distanceToGoal <= ACCEPTABLE_DISTANCE) {
- tracker.update(curX, curY, curZ, currentCalculatedNextTile);
- tracker.counter = 0;
- continue;
- }
- }
-
- // Otherwise, use your normal loop detection logic:
- // (for example, checking if the next tile contains a roller, etc.)
- boolean nextTileHasRoller = false;
- if (currentCalculatedNextTile != null) {
- for (InteractionRoller roller : this.roomSpecialTypes.getRollers().values()) {
- if (roller.getX() == currentCalculatedNextTile.x && roller.getY() == currentCalculatedNextTile.y) {
- nextTileHasRoller = true;
- break;
- }
- }
- }
-
- if (currentCalculatedNextTile != null && !nextTileHasRoller) {
- tracker.update(curX, curY, curZ, currentCalculatedNextTile);
- tracker.counter = 0;
- } else {
- if (unit.getGoal() != null && tracker.nextTile != null &&
- unit.getGoal().x == tracker.nextTile.x && unit.getGoal().y == tracker.nextTile.y) {
- tracker.counter = 0;
- } else {
- tracker.counter++;
- int loopThreshold = Math.max(10, 3 + this.getRollerSpeed());
- if (tracker.counter >= loopThreshold) {
- RoomTile doorTile = this.getLayout().getDoorTile();
- unit.setBodyRotation(RoomUserRotation.values()[this.getLayout().getDoorDirection()]);
- unit.setHeadRotation(RoomUserRotation.values()[this.getLayout().getDoorDirection()]);
- this.teleportRoomUnitToLocation(unit, doorTile.x, doorTile.y, doorTile.z);
- tracker.counter = 0;
- }
- }
- }
- } else {
- // Unit has moved; update tracker accordingly.
- InteractionRoller currentRoller = null;
- RoomTile currentTile = this.getLayout().getTile((short) curX, (short) curY);
- for (InteractionRoller roller : this.roomSpecialTypes.getRollers().values()) {
- if (roller.getX() == currentTile.x && roller.getY() == currentTile.y) {
- currentRoller = roller;
- break;
- }
- }
- RoomTile nextTile = null;
- if (currentRoller != null) {
- RoomTile rollerTile = this.getLayout().getTile(currentRoller.getX(), currentRoller.getY());
- nextTile = this.getLayout().getTileInFront(rollerTile, currentRoller.getRotation());
- }
- tracker.update(curX, curY, curZ, nextTile);
- }
- }
-
- if (!foundRightHolder[0]) {
- foundRightHolder[0] = habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE;
- }
-
- if (habbo.getRoomUnit().getHandItem() > 0 && millis - habbo.getRoomUnit().getHandItemTimestamp() > (Room.HAND_ITEM_TIME * 1000L)) {
- this.giveHandItem(habbo, 0);
- }
-
- if (habbo.getRoomUnit().getEffectId() > 0 && millis / 1000 > habbo.getRoomUnit().getEffectEndTimestamp()) {
- this.giveEffect(habbo, 0, -1);
- }
-
- if (habbo.getRoomUnit().isKicked) {
- habbo.getRoomUnit().kickCount++;
-
- if (habbo.getRoomUnit().kickCount >= 5) {
- this.scheduledTasks.add(() -> Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, room));
- continue;
- }
- }
-
- if (Emulator.getConfig().getBoolean("hotel.rooms.auto.idle")) {
- if (!habbo.getRoomUnit().isIdle()) {
- habbo.getRoomUnit().increaseIdleTimer();
-
- if (habbo.getRoomUnit().isIdle()) {
- boolean danceIsNone = (habbo.getRoomUnit().getDanceType() == DanceType.NONE);
- if (danceIsNone)
- this.sendComposer(new RoomUnitIdleComposer(habbo.getRoomUnit()).compose());
- if (danceIsNone && !Emulator.getConfig().getBoolean("hotel.roomuser.idle.not_dancing.ignore.wired_idle"))
- WiredHandler.handle(WiredTriggerType.IDLES, habbo.getRoomUnit(), this, new Object[]{habbo});
- }
- } else {
- habbo.getRoomUnit().increaseIdleTimer();
-
- if (!this.isOwner(habbo) && habbo.getRoomUnit().getIdleTimer() >= Room.IDLE_CYCLES_KICK) {
- UserExitRoomEvent event = new UserExitRoomEvent(habbo, UserExitRoomEvent.UserExitRoomReason.KICKED_IDLE);
- Emulator.getPluginManager().fireEvent(event);
-
- if (!event.isCancelled()) {
- toKick.add(habbo);
- }
- }
- }
- }
-
- if (habbo.getHabboStats().mutedBubbleTracker && habbo.getHabboStats().allowTalk()) {
- habbo.getHabboStats().mutedBubbleTracker = false;
- this.sendComposer(new RoomUserIgnoredComposer(habbo, RoomUserIgnoredComposer.UNIGNORED).compose());
- }
-
- // Substract 1 from the chatCounter every odd cycle, which is every (500ms * 2).
- if (this.cycleOdd && habbo.getHabboStats().chatCounter.get() > 0) {
- habbo.getHabboStats().chatCounter.decrementAndGet();
- }
-
- if (this.cycleRoomUnit(habbo.getRoomUnit(), RoomUnitType.USER)) {
- updatedUnit.add(habbo.getRoomUnit());
- }
- }
-
- if (!toKick.isEmpty()) {
- for (Habbo habbo : toKick) {
- Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this);
- }
- }
-
- if (!this.currentBots.isEmpty()) {
- TIntObjectIterator botIterator = this.currentBots.iterator();
- for (int i = this.currentBots.size(); i-- > 0; ) {
- try {
- final Bot bot;
- try {
- botIterator.advance();
- bot = botIterator.value();
- } catch (Exception e) {
- break;
- }
-
- if (!this.allowBotsWalk && bot.getRoomUnit().isWalking()) {
- bot.getRoomUnit().stopWalking();
- updatedUnit.add(bot.getRoomUnit());
- continue;
- }
-
- botIterator.value().cycle(this.allowBotsWalk);
-
-
- if (this.cycleRoomUnit(bot.getRoomUnit(), RoomUnitType.BOT)) {
- updatedUnit.add(bot.getRoomUnit());
- }
-
-
- } catch (NoSuchElementException e) {
- LOGGER.error("Caught exception", e);
- break;
- }
- }
- }
-
- if (!this.currentPets.isEmpty()) {
- if (this.allowBotsWalk) {
- TIntObjectIterator petIterator = this.currentPets.iterator();
- for (int i = this.currentPets.size(); i-- > 0; ) {
- try {
- petIterator.advance();
- } catch (NoSuchElementException e) {
- LOGGER.error("Caught exception", e);
- break;
- }
-
- Pet pet = petIterator.value();
- if (this.cycleRoomUnit(pet.getRoomUnit(), RoomUnitType.PET)) {
- updatedUnit.add(pet.getRoomUnit());
- }
-
- pet.cycle();
-
- if (pet.packetUpdate) {
- updatedUnit.add(pet.getRoomUnit());
- pet.packetUpdate = false;
- }
-
- if (pet.getRoomUnit().isWalking() && pet.getRoomUnit().getPath().size() == 1 && pet.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) {
- pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE);
- updatedUnit.add(pet.getRoomUnit());
- }
- }
- }
- }
-
- List rollers = new ArrayList<>(this.roomSpecialTypes.getRollers().values());
-
- // Sort rollers using a custom comparator that uses a projection of the roller's position
- rollers.sort((r1, r2) -> {
- // Convert the roller's rotation into an angle in radians.
- double angle1 = Math.toRadians(r1.getRotation() * 45);
- double angle2 = Math.toRadians(r2.getRotation() * 45);
-
- // Compute the movement vector for each roller (a unit vector in its direction)
- double vx1 = Math.cos(angle1);
- double vy1 = Math.sin(angle1);
- double vx2 = Math.cos(angle2);
- double vy2 = Math.sin(angle2);
-
- // Calculate the projection of the roller's position along its movement vector
- double proj1 = r1.getX() * vx1 + r1.getY() * vy1;
- double proj2 = r2.getX() * vx2 + r2.getY() * vy2;
-
- return Double.compare(proj1, proj2);
- });
- if (this.rollerSpeed != -1 && this.rollerCycle >= this.rollerSpeed) {
- this.rollerCycle = 0;
-
- THashSet messages = new THashSet<>();
-
- //Find alternative for this.
- //Reason is that tile gets updated after every roller.
- List rollerFurniIds = new ArrayList<>();
- List rolledUnitIds = new ArrayList<>();
-
-
- this.roomSpecialTypes.getRollers().forEachValue(roller -> {
-
- HabboItem newRoller = null;
-
- RoomTile rollerTile = this.getLayout().getTile(roller.getX(), roller.getY());
-
- if (rollerTile == null)
- return true;
-
- THashSet itemsOnRoller = new THashSet<>();
-
- for (HabboItem item : getItemsAt(rollerTile)) {
- if (item.getZ() >= roller.getZ() + Item.getCurrentHeight(roller)) {
- itemsOnRoller.add(item);
- }
- }
-
- // itemsOnRoller.addAll(this.getItemsAt(rollerTile));
- itemsOnRoller.remove(roller);
-
- if (!rollerTile.hasUnits() && itemsOnRoller.isEmpty())
- return true;
-
- // RoomTile currentTile = Room.this.layout.getTile(roller.getX(), roller.getY());
- RoomTile tileInFront = Room.this.layout.getTileInFront(Room.this.layout.getTile(roller.getX(), roller.getY()), roller.getRotation());
-
- // LOGGER.debug("Roller at: (" + roller.getX() + ", " + roller.getY() + "), Rotation: " + roller.getRotation());
- // LOGGER.debug("Next tile calculated: (" + (tileInFront != null ? tileInFront.x : "NULL") + ", " + (tileInFront != null ? tileInFront.y : "NULL") + ")");
-
- if (tileInFront == null)
- return true;
-
- if (!Room.this.layout.tileExists(tileInFront.x, tileInFront.y))
- return true;
-
- if (tileInFront.state == RoomTileState.INVALID)
- return true;
-
- if (!tileInFront.getAllowStack() && !(tileInFront.isWalkable() || tileInFront.state == RoomTileState.SIT || tileInFront.state == RoomTileState.LAY))
- return true;
-
- if (tileInFront.hasUnits())
- return true;
-
- THashSet itemsNewTile = new THashSet<>();
- itemsNewTile.addAll(getItemsAt(tileInFront));
- itemsNewTile.removeAll(itemsOnRoller);
-
- List toRemove = new ArrayList<>();
- for (HabboItem item : itemsOnRoller) {
- if (item.getX() != roller.getX() || item.getY() != roller.getY() || rollerFurniIds.contains(item.getId())) {
- toRemove.add(item);
- }
- }
- itemsOnRoller.removeAll(toRemove);
- HabboItem topItem = Room.this.getTopItemAt(tileInFront.x, tileInFront.y);
-
- boolean allowUsers = true;
- boolean allowFurniture = true;
- boolean stackContainsRoller = false;
-
- for (HabboItem item : itemsNewTile) {
- if (!(item.getBaseItem().allowWalk() || item.getBaseItem().allowSit()) && !(item instanceof InteractionGate && item.getExtradata().equals("1"))) {
- allowUsers = false;
- }
- if (item instanceof InteractionRoller) {
- newRoller = item;
- stackContainsRoller = true;
-
- if ((item.getZ() != roller.getZ() || (itemsNewTile.size() > 1 && item != topItem)) && !InteractionRoller.NO_RULES) {
- allowUsers = false;
- allowFurniture = false;
- continue;
- }
-
- break;
- } else {
- allowFurniture = false;
- }
- }
-
- if (allowFurniture) {
- allowFurniture = tileInFront.getAllowStack();
- }
-
- double zOffset = 0;
- if (newRoller != null) {
- if ((!itemsNewTile.isEmpty() && (itemsNewTile.size() > 1)) && !InteractionRoller.NO_RULES) {
- return true;
- }
- } else {
- zOffset = -Item.getCurrentHeight(roller) + tileInFront.getStackHeight() - rollerTile.z;
- }
-
- if (allowUsers) {
- Event roomUserRolledEvent = null;
-
- if (Emulator.getPluginManager().isRegistered(UserRolledEvent.class, true)) {
- roomUserRolledEvent = new UserRolledEvent(null, null, null);
- }
-
- ArrayList unitsOnTile = new ArrayList<>(rollerTile.getUnits());
-
- for (RoomUnit unit : rollerTile.getUnits()) {
- if (unit.getRoomUnitType() == RoomUnitType.PET) {
- Pet pet = this.getPet(unit);
- if (pet instanceof RideablePet && ((RideablePet) pet).getRider() != null) {
- unitsOnTile.remove(unit);
- }
- }
- }
-
- THashSet usersRolledThisTile = new THashSet<>();
-
- for (RoomUnit unit : unitsOnTile) {
- if (rolledUnitIds.contains(unit.getId())) continue;
-
- if (usersRolledThisTile.size() >= Room.ROLLERS_MAXIMUM_ROLL_AVATARS) break;
-
- if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable()))
- continue;
-
- if (unit.hasStatus(RoomUnitStatus.MOVE))
- continue;
-
- RoomTile tile = tileInFront.copy();
- tile.setStackHeight(unit.getZ() + zOffset);
-
- if (roomUserRolledEvent != null && unit.getRoomUnitType() == RoomUnitType.USER) {
- roomUserRolledEvent = new UserRolledEvent(getHabbo(unit), roller, tile);
- Emulator.getPluginManager().fireEvent(roomUserRolledEvent);
-
- if (roomUserRolledEvent.isCancelled())
- continue;
- }
-
- // horse riding
- boolean isRiding = false;
- if (unit.getRoomUnitType() == RoomUnitType.USER) {
- Habbo rollingHabbo = this.getHabbo(unit);
- if (rollingHabbo != null && rollingHabbo.getHabboInfo() != null) {
- RideablePet riding = rollingHabbo.getHabboInfo().getRiding();
- if (riding != null) {
- RoomUnit ridingUnit = riding.getRoomUnit();
- tile.setStackHeight(ridingUnit.getZ() + zOffset);
- rolledUnitIds.add(ridingUnit.getId());
- updatedUnit.remove(ridingUnit);
- messages.add(new RoomUnitOnRollerComposer(ridingUnit, roller, ridingUnit.getCurrentLocation(), ridingUnit.getZ(), tile, tile.getStackHeight(), room));
- isRiding = true;
- }
- }
- }
-
- usersRolledThisTile.add(unit.getId());
- rolledUnitIds.add(unit.getId());
- updatedUnit.remove(unit);
- messages.add(new RoomUnitOnRollerComposer(unit, roller, unit.getCurrentLocation(), unit.getZ() + (isRiding ? 1 : 0), tile, tile.getStackHeight() + (isRiding ? 1 : 0), room));
-
- if (itemsOnRoller.isEmpty()) {
- HabboItem item = room.getTopItemAt(tileInFront.x, tileInFront.y);
-
- if (item != null && itemsNewTile.contains(item) && !itemsOnRoller.contains(item)) {
- Emulator.getThreading().run(() -> {
- if (unit.getGoal() == rollerTile) {
- try {
- item.onWalkOn(unit, room, new Object[]{rollerTile, tileInFront});
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
- }
- }, this.getRollerSpeed() == 0 ? 250 : InteractionRoller.DELAY);
- }
- }
-
- if (unit.hasStatus(RoomUnitStatus.SIT)) {
- unit.sitUpdate = true;
- }
- }
- }
-
- if (!messages.isEmpty()) {
- for (MessageComposer message : messages) {
- room.sendComposer(message.compose());
- }
- messages.clear();
- }
-
- if (allowFurniture || !stackContainsRoller || InteractionRoller.NO_RULES) {
- Event furnitureRolledEvent = null;
-
- if (Emulator.getPluginManager().isRegistered(FurnitureRolledEvent.class, true)) {
- furnitureRolledEvent = new FurnitureRolledEvent(null, null, null);
- }
-
- if (newRoller == null || topItem == newRoller) {
- List sortedItems = new ArrayList<>(itemsOnRoller);
- sortedItems.sort((o1, o2) -> o1.getZ() > o2.getZ() ? -1 : 1);
-
- for (HabboItem item : sortedItems) {
- if (item.getX() == roller.getX() && item.getY() == roller.getY() && zOffset <= 0) {
- if (item != roller) {
- if (furnitureRolledEvent != null) {
- furnitureRolledEvent = new FurnitureRolledEvent(item, roller, tileInFront);
- Emulator.getPluginManager().fireEvent(furnitureRolledEvent);
-
- if (furnitureRolledEvent.isCancelled())
- continue;
- }
-
- messages.add(new FloorItemOnRollerComposer(item, roller, tileInFront, zOffset, room));
- rollerFurniIds.add(item.getId());
- }
- }
- }
- }
- }
-
-
- if (!messages.isEmpty()) {
- for (MessageComposer message : messages) {
- room.sendComposer(message.compose());
- }
- messages.clear();
- }
-
- return true;
- });
-
-
- int currentTime = (int) (this.cycleTimestamp / 1000);
- for (HabboItem pyramid : this.roomSpecialTypes.getItemsOfType(InteractionPyramid.class)) {
- if (pyramid instanceof InteractionPyramid) {
-
- if (((InteractionPyramid) pyramid).getNextChange() < currentTime) {
- ((InteractionPyramid) pyramid).change(this);
- }
- }
- }
- } else {
- this.rollerCycle++;
- }
-
- if (!updatedUnit.isEmpty()) {
- this.sendComposer(new RoomUserStatusComposer(updatedUnit, true).compose());
- }
-
- this.traxManager.cycle();
- } else {
-
- if (this.idleCycles < 60)
- this.idleCycles++;
- else
- this.dispose();
- }
- }
-
- synchronized (this.habboQueue) {
- if (!this.habboQueue.isEmpty() && !foundRightHolder[0]) {
- this.habboQueue.forEachEntry(new TIntObjectProcedure() {
- @Override
- public boolean execute(int a, Habbo b) {
- if (b.isOnline()) {
- if (b.getHabboInfo().getRoomQueueId() == Room.this.getId()) {
- b.getClient().sendResponse(new RoomAccessDeniedComposer(""));
- }
- }
-
- return true;
- }
- });
-
- this.habboQueue.clear();
- }
- }
-
- if (!this.scheduledComposers.isEmpty()) {
- for (ServerMessage message : this.scheduledComposers) {
- this.sendComposer(message);
- }
-
- this.scheduledComposers.clear();
- }
- }
-
-
- private boolean cycleRoomUnit(RoomUnit unit, RoomUnitType type) {
- boolean update = unit.needsStatusUpdate();
- if (unit.hasStatus(RoomUnitStatus.SIGN)) {
- this.sendComposer(new RoomUserStatusComposer(unit).compose());
- unit.removeStatus(RoomUnitStatus.SIGN);
- }
-
- if (unit.isWalking() && unit.getPath() != null && !unit.getPath().isEmpty()) {
- if (!unit.cycle(this)) {
- return true;
- }
- } else {
- if ((unit.hasStatus(RoomUnitStatus.MOVE) || unit.hasStatus(RoomUnitStatus.SNOWWAR_RUN)) && !unit.animateWalk) {
- unit.removeStatus(RoomUnitStatus.MOVE);
- unit.removeStatus(RoomUnitStatus.SNOWWAR_RUN);
-
- update = true;
- }
-
- if (!unit.isWalking() && !unit.cmdSit) {
- RoomTile thisTile = this.getLayout().getTile(unit.getX(), unit.getY());
- HabboItem topItem = this.getTallestChair(thisTile);
-
- if (topItem == null || !topItem.getBaseItem().allowSit()) {
- if (unit.hasStatus(RoomUnitStatus.SIT)) {
- unit.removeStatus(RoomUnitStatus.SIT);
- update = true;
- }
- } else if (thisTile.state == RoomTileState.SIT && (!unit.hasStatus(RoomUnitStatus.SIT) || unit.sitUpdate)) {
- this.dance(unit, DanceType.NONE);
- //int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z;
- unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem)) + "");
- unit.setZ(topItem.getZ());
- unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]);
- unit.sitUpdate = false;
- return true;
- }
- }
- }
-
- if (!unit.isWalking() && !unit.cmdLay && !unit.hasStatus(RoomUnitStatus.SNOWWAR_DIE_BACK)) {
- HabboItem topItem = this.getTopItemAt(unit.getX(), unit.getY());
-
- if (topItem == null || !topItem.getBaseItem().allowLay()) {
- if (unit.hasStatus(RoomUnitStatus.LAY)) {
- unit.removeStatus(RoomUnitStatus.LAY);
- update = true;
- }
- } else {
- if (!unit.hasStatus(RoomUnitStatus.LAY)) {
- unit.setStatus(RoomUnitStatus.LAY, Item.getCurrentHeight(topItem) + "");
- unit.setRotation(RoomUserRotation.values()[topItem.getRotation() % 4]);
-
- if (topItem.getRotation() == 0 || topItem.getRotation() == 4) {
- unit.setLocation(this.layout.getTile(unit.getX(), topItem.getY()));
- //unit.setOldY(topItem.getY());
- } else {
- unit.setLocation(this.layout.getTile(topItem.getX(), unit.getY()));
- //unit.setOldX(topItem.getX());
- }
- update = true;
- }
- }
- }
-
- if (update) {
- unit.statusUpdate(false);
- }
-
- return update;
- }
-
- public int getId() {
- return this.id;
- }
-
- public int getOwnerId() {
- return this.ownerId;
- }
-
- public void setOwnerId(int ownerId) {
- this.ownerId = ownerId;
- }
-
- public String getOwnerName() {
- return this.ownerName;
- }
-
- public void setOwnerName(String ownerName) {
- this.ownerName = ownerName;
- }
-
- public String getName() {
- return this.name;
- }
-
- public void setName(String name) {
- this.name = name;
-
- if (this.name.length() > 50) {
- this.name = this.name.substring(0, 50);
- }
-
- if (this.hasGuild()) {
- Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guild);
-
- if (guild != null) {
- guild.setRoomName(name);
- }
- }
- }
-
- public String getDescription() {
- return this.description;
- }
-
- public void setDescription(String description) {
- this.description = description;
-
- if (this.description.length() > 250) {
- this.description = this.description.substring(0, 250);
- }
- }
-
- public RoomLayout getLayout() {
- return this.layout;
- }
-
- public void setLayout(RoomLayout layout) {
- this.layout = layout;
- }
-
- public boolean hasCustomLayout() {
- return this.overrideModel;
- }
-
- public void setHasCustomLayout(boolean overrideModel) {
- this.overrideModel = overrideModel;
- }
-
- public String getPassword() {
- return this.password;
- }
-
- public void setPassword(String password) {
- this.password = password;
-
- if (this.password.length() > 20) {
- this.password = this.password.substring(0, 20);
- }
- }
-
- public RoomState getState() {
- return this.state;
- }
-
- public void setState(RoomState state) {
- this.state = state;
- }
-
- public int getUsersMax() {
- return this.usersMax;
- }
-
- public void setUsersMax(int usersMax) {
- this.usersMax = usersMax;
- }
-
- public int getScore() {
- return this.score;
- }
-
- public void setScore(int score) {
- this.score = score;
- }
-
- public int getCategory() {
- return this.category;
- }
-
- public void setCategory(int category) {
- this.category = category;
- }
-
- public String getFloorPaint() {
- return this.floorPaint;
- }
-
- public void setFloorPaint(String floorPaint) {
- this.floorPaint = floorPaint;
- }
-
- public String getWallPaint() {
- return this.wallPaint;
- }
-
- public void setWallPaint(String wallPaint) {
- this.wallPaint = wallPaint;
- }
-
- public String getBackgroundPaint() {
- return this.backgroundPaint;
- }
-
- public void setBackgroundPaint(String backgroundPaint) {
- this.backgroundPaint = backgroundPaint;
- }
-
- public int getWallSize() {
- return this.wallSize;
- }
-
- public void setWallSize(int wallSize) {
- this.wallSize = wallSize;
- }
-
- public int getWallHeight() {
- return this.wallHeight;
- }
-
- public void setWallHeight(int wallHeight) {
- this.wallHeight = wallHeight;
- }
-
- public int getFloorSize() {
- return this.floorSize;
- }
-
- public void setFloorSize(int floorSize) {
- this.floorSize = floorSize;
- }
-
- public String getTags() {
- return this.tags;
- }
-
- public void setTags(String tags) {
- this.tags = tags;
- }
-
- public int getTradeMode() {
- return this.tradeMode;
- }
-
- public void setTradeMode(int tradeMode) {
- this.tradeMode = tradeMode;
- }
-
- public boolean moveDiagonally() {
- return this.moveDiagonally;
- }
-
- public void moveDiagonally(boolean moveDiagonally) {
- this.moveDiagonally = moveDiagonally;
- this.layout.moveDiagonally(this.moveDiagonally);
- this.needsUpdate = true;
- }
-
- public int getGuildId() {
- return this.guild;
- }
-
- public boolean hasGuild() {
- return this.guild != 0;
- }
-
- public void setGuild(int guild) {
- this.guild = guild;
- }
-
- public String getGuildName() {
- if (this.hasGuild()) {
- Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guild);
-
- if (guild != null) {
- return guild.getName();
- }
- }
-
- return "";
- }
-
- public boolean isPublicRoom() {
- return this.publicRoom;
- }
-
- public void setPublicRoom(boolean publicRoom) {
- this.publicRoom = publicRoom;
- }
-
- public boolean isStaffPromotedRoom() {
- return this.staffPromotedRoom;
- }
-
- public void setStaffPromotedRoom(boolean staffPromotedRoom) {
- this.staffPromotedRoom = staffPromotedRoom;
- }
-
- public boolean isAllowPets() {
- return this.allowPets;
- }
-
- public void setAllowPets(boolean allowPets) {
- this.allowPets = allowPets;
- if (!allowPets) {
- removeAllPets(ownerId);
- }
- }
-
- public boolean isAllowPetsEat() {
- return this.allowPetsEat;
- }
-
- public void setAllowPetsEat(boolean allowPetsEat) {
- this.allowPetsEat = allowPetsEat;
- }
-
- public boolean isAllowWalkthrough() {
- return this.allowWalkthrough;
- }
-
- public void setAllowWalkthrough(boolean allowWalkthrough) {
- this.allowWalkthrough = allowWalkthrough;
- }
-
- public boolean isAllowBotsWalk() {
- return this.allowBotsWalk;
- }
-
- public void setAllowBotsWalk(boolean allowBotsWalk) {
- this.allowBotsWalk = allowBotsWalk;
- }
-
- public boolean isAllowEffects() {
- return this.allowEffects;
- }
-
- public void setAllowEffects(boolean allowEffects) {
- this.allowEffects = allowEffects;
- }
-
- public boolean isHideWall() {
- return this.hideWall;
- }
-
- public void setHideWall(boolean hideWall) {
- this.hideWall = hideWall;
- }
-
- public Color getBackgroundTonerColor() {
- Color color = new Color(0, 0, 0);
- TIntObjectIterator iterator = this.roomItems.iterator();
-
- for (int i = this.roomItems.size(); i > 0; i--) {
- try {
- iterator.advance();
- HabboItem object = iterator.value();
-
- if (object instanceof InteractionBackgroundToner) {
- String[] extraData = object.getExtradata().split(":");
-
- if (extraData.length == 4) {
- if (extraData[0].equalsIgnoreCase("1")) {
- return Color.getHSBColor(Integer.parseInt(extraData[1]), Integer.parseInt(extraData[2]), Integer.parseInt(extraData[3]));
- }
- }
- }
- } catch (Exception e) {
- }
- }
-
- return color;
- }
-
- public int getChatMode() {
- return this.chatMode;
- }
-
- public void setChatMode(int chatMode) {
- this.chatMode = chatMode;
- }
-
- public int getChatWeight() {
- return this.chatWeight;
- }
-
- public void setChatWeight(int chatWeight) {
- this.chatWeight = chatWeight;
- }
-
- public int getChatSpeed() {
- return this.chatSpeed;
- }
-
- public void setChatSpeed(int chatSpeed) {
- this.chatSpeed = chatSpeed;
- }
-
- public int getChatDistance() {
- return this.chatDistance;
- }
-
- public void setChatDistance(int chatDistance) {
- this.chatDistance = chatDistance;
- }
-
- public void removeAllPets() {
- removeAllPets(-1);
- }
-
- /**
- * Removes all pets from the room except if the owner id is excludeUserId
- *
- * @param excludeUserId Habbo id to keep pets
- */
- public void removeAllPets(int excludeUserId) {
- ArrayList toRemovePets = new ArrayList<>();
- ArrayList removedPets = new ArrayList<>();
- synchronized (this.currentPets) {
- for (Pet pet : this.currentPets.valueCollection()) {
- try {
- if (pet.getUserId() != excludeUserId) {
- toRemovePets.add(pet);
- }
-
- } catch (NoSuchElementException e) {
- LOGGER.error("Caught exception", e);
- break;
- }
- }
- }
-
- for (Pet pet : toRemovePets) {
- removedPets.add(pet);
-
- pet.removeFromRoom();
-
- Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId());
- if (habbo != null) {
- habbo.getInventory().getPetsComponent().addPet(pet);
- habbo.getClient().sendResponse(new AddPetComposer(pet));
- }
-
- pet.needsUpdate = true;
- pet.run();
- }
-
- for (Pet pet : removedPets) {
- this.currentPets.remove(pet.getId());
- }
- }
-
- public int getChatProtection() {
- return this.chatProtection;
- }
-
- public void setChatProtection(int chatProtection) {
- this.chatProtection = chatProtection;
- }
-
- public int getMuteOption() {
- return this.muteOption;
- }
-
- public void setMuteOption(int muteOption) {
- this.muteOption = muteOption;
- }
-
- public int getKickOption() {
- return this.kickOption;
- }
-
- public void setKickOption(int kickOption) {
- this.kickOption = kickOption;
- }
-
- public int getBanOption() {
- return this.banOption;
- }
-
- public void setBanOption(int banOption) {
- this.banOption = banOption;
- }
-
- public int getPollId() {
- return this.pollId;
- }
-
- public void setPollId(int pollId) {
- this.pollId = pollId;
- }
-
- public int getRollerSpeed() {
- return this.rollerSpeed;
- }
-
- public void setRollerSpeed(int rollerSpeed) {
- this.rollerSpeed = rollerSpeed;
- this.rollerCycle = 0;
- this.needsUpdate = true;
- }
-
- public String[] filterAnything() {
- return new String[]{this.getOwnerName(), this.getGuildName(), this.getDescription(), this.getPromotionDesc()};
- }
-
- public long getCycleTimestamp() {
- return this.cycleTimestamp;
- }
-
- public boolean isPromoted() {
- this.promoted = this.promotion != null && this.promotion.getEndTimestamp() > Emulator.getIntUnixTimestamp();
- this.needsUpdate = true;
-
- return this.promoted;
- }
-
- public RoomPromotion getPromotion() {
- return this.promotion;
- }
-
- public String getPromotionDesc() {
- if (this.promotion != null) {
- return this.promotion.getDescription();
- }
-
- return "";
- }
-
- public void createPromotion(String title, String description, int category) {
- this.promoted = true;
-
- if (this.promotion == null) {
- this.promotion = new RoomPromotion(this, title, description, Emulator.getIntUnixTimestamp() + (120 * 60), Emulator.getIntUnixTimestamp(), category);
- } else {
- this.promotion.setTitle(title);
- this.promotion.setDescription(description);
- this.promotion.setEndTimestamp(Emulator.getIntUnixTimestamp() + (120 * 60));
- this.promotion.setCategory(category);
- }
-
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_promotions (room_id, title, description, end_timestamp, start_timestamp, category) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE title = ?, description = ?, end_timestamp = ?, category = ?")) {
- statement.setInt(1, this.id);
- statement.setString(2, title);
- statement.setString(3, description);
- statement.setInt(4, this.promotion.getEndTimestamp());
- statement.setInt(5, this.promotion.getStartTimestamp());
- statement.setInt(6, category);
- statement.setString(7, this.promotion.getTitle());
- statement.setString(8, this.promotion.getDescription());
- statement.setInt(9, this.promotion.getEndTimestamp());
- statement.setInt(10, this.promotion.getCategory());
- statement.execute();
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
-
- this.needsUpdate = true;
- }
-
- public boolean addGame(Game game) {
- synchronized (this.games) {
- return this.games.add(game);
- }
- }
-
- public boolean deleteGame(Game game) {
- game.stop();
- game.dispose();
- synchronized (this.games) {
- return this.games.remove(game);
- }
- }
-
- public Game getGame(Class extends Game> gameType) {
- if (gameType == null) return null;
-
- synchronized (this.games) {
- for (Game game : this.games) {
- if (gameType.isInstance(game)) {
- return game;
- }
- }
- }
-
- return null;
- }
-
- public Game getGameOrCreate(Class extends Game> gameType) {
- Game game = this.getGame(gameType);
- if (game == null) {
- try {
- game = gameType.getDeclaredConstructor(Room.class).newInstance(this);
- this.addGame(game);
- } catch (Exception e) {
- LOGGER.error("Error getting game {}", gameType.getName(), e);
- }
- }
-
- return game;
- }
-
- public Set getGames() {
- return this.games;
- }
-
- public int getUserCount() {
- return this.currentHabbos.size();
- }
-
- public ConcurrentHashMap getCurrentHabbos() {
- return this.currentHabbos;
- }
-
- public Collection getHabbos() {
- return this.currentHabbos.values();
- }
-
- public TIntObjectMap getHabboQueue() {
- return this.habboQueue;
- }
-
- public TIntObjectMap getFurniOwnerNames() {
- return this.furniOwnerNames;
- }
-
- public String getFurniOwnerName(int userId) {
- return this.furniOwnerNames.get(userId);
- }
-
- public TIntIntMap getFurniOwnerCount() {
- return this.furniOwnerCount;
- }
-
- public TIntObjectMap getMoodlightData() {
- return this.moodlightData;
- }
-
- public int getLastTimerReset() {
- return this.lastTimerReset;
- }
-
- public void setLastTimerReset(int lastTimerReset) {
- this.lastTimerReset = lastTimerReset;
- }
-
- public void addToQueue(Habbo habbo) {
- synchronized (this.habboQueue) {
- this.habboQueue.put(habbo.getHabboInfo().getId(), habbo);
- }
- }
-
- public boolean removeFromQueue(Habbo habbo) {
- try {
- this.sendComposer(new HideDoorbellComposer(habbo.getHabboInfo().getUsername()).compose());
-
- synchronized (this.habboQueue) {
- return this.habboQueue.remove(habbo.getHabboInfo().getId()) != null;
- }
+ CompletableFuture rightsFuture = CompletableFuture.runAsync(() -> {
+ try (Connection rightsConnection = Emulator.getDatabase().getDataSource().getConnection()) {
+ this.loadRights(rightsConnection);
} catch (Exception e) {
- LOGGER.error("Caught exception", e);
+ LOGGER.error("Caught exception loading rights", e);
}
+ }, Emulator.getThreading().getService());
- return true;
+ CompletableFuture wordFilterFuture = CompletableFuture.runAsync(() -> {
+ try (Connection wordFilterConnection = Emulator.getDatabase().getDataSource().getConnection()) {
+ this.loadWordFilter(wordFilterConnection);
+ } catch (Exception e) {
+ LOGGER.error("Caught exception loading word filter", e);
+ }
+ }, Emulator.getThreading().getService());
+
+ // Wait for items to be loaded before loading wired data (wired depends on items)
+ try {
+ itemsFuture.join();
+ } catch (Exception e) {
+ LOGGER.error("Error waiting for items to load", e);
+ }
+
+ // Phase 3: Load heightmap after items are loaded (depends on items for stack heights)
+ try {
+ this.loadHeightmap();
+ } catch (Exception e) {
+ LOGGER.error("Caught exception loading heightmap", e);
+ }
+
+ // Phase 4: Load bots, pets, and wired data in parallel (all depend on layout + items)
+ CompletableFuture botsFuture = CompletableFuture.runAsync(() -> {
+ try (Connection botsConnection = Emulator.getDatabase().getDataSource().getConnection()) {
+ this.loadBots(botsConnection);
+ } catch (Exception e) {
+ LOGGER.error("Caught exception loading bots", e);
+ }
+ }, Emulator.getThreading().getService());
+
+ CompletableFuture petsFuture = CompletableFuture.runAsync(() -> {
+ try (Connection petsConnection = Emulator.getDatabase().getDataSource().getConnection()) {
+ this.loadPets(petsConnection);
+ } catch (Exception e) {
+ LOGGER.error("Caught exception loading pets", e);
+ }
+ }, Emulator.getThreading().getService());
+
+ CompletableFuture wiredFuture = CompletableFuture.runAsync(() -> {
+ try (Connection wiredConnection = Emulator.getDatabase().getDataSource().getConnection()) {
+ this.loadWiredData(wiredConnection);
+ } catch (Exception e) {
+ LOGGER.error("Caught exception loading wired data", e);
+ }
+ }, Emulator.getThreading().getService());
+
+ // Wait for all parallel operations to complete
+ try {
+ CompletableFuture.allOf(rightsFuture, wordFilterFuture, botsFuture, petsFuture, wiredFuture).join();
+ } catch (Exception e) {
+ LOGGER.error("Error waiting for parallel room data loading", e);
+ }
+
+ this.cycleManager.resetIdleCycles();
+
+ this.roomCycleTask = Emulator.getThreading().getService()
+ .scheduleAtFixedRate(this, 500, 500, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
+ LOGGER.error("Caught exception during room load", e);
}
- public TIntObjectMap getCurrentBots() {
- return this.currentBots;
+ this.traxManager = new TraxManager(this);
+
+ if (this.jukeboxActive) {
+ this.traxManager.play(0);
+ for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionJukeBox.class)) {
+ item.setExtradata("1");
+ this.updateItem(item);
+ }
}
- public TIntObjectMap getCurrentPets() {
- return this.currentPets;
+ for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionFireworks.class)) {
+ item.setExtradata("1");
+ this.updateItem(item);
+ }
+
+ // Set loaded flag with lock
+ synchronized (this.loadLock) {
+ this.loaded = true;
+ this.loadingInProgress = false;
+ this.loadingFuture = null;
}
- public THashSet getWordFilterWords() {
- return this.wordFilterWords;
+ Emulator.getPluginManager().fireEvent(new RoomLoadedEvent(this));
+ }
+
+ private synchronized void loadLayout() {
+ if (this.layout == null) {
+ if (this.overrideModel) {
+ this.layout = Emulator.getGameEnvironment().getRoomManager().loadCustomLayout(this);
+ } else {
+ this.layout = Emulator.getGameEnvironment().getRoomManager()
+ .loadLayout(this.layoutName, this);
+ }
}
+ }
- public RoomSpecialTypes getRoomSpecialTypes() {
- return this.roomSpecialTypes;
+ private synchronized void loadHeightmap() {
+ if (this.layout != null) {
+ for (short x = 0; x < this.layout.getMapSizeX(); x++) {
+ for (short y = 0; y < this.layout.getMapSizeY(); y++) {
+ RoomTile tile = this.layout.getTile(x, y);
+ if (tile != null) {
+ this.updateTile(tile);
+ }
+ }
+ }
+ } else {
+ LOGGER.error("Unknown Room Layout for Room (ID: {})", this.id);
}
+ }
- public boolean isPreLoaded() {
- return this.preLoaded;
- }
+ private synchronized void loadItems(Connection connection) {
+ this.itemManager.loadItems(connection);
+ }
- public boolean isLoaded() {
- return this.loaded;
- }
+ private synchronized void loadWiredData(Connection connection) {
+ this.itemManager.loadWiredData(connection);
+ }
- public void setNeedsUpdate(boolean needsUpdate) {
- this.needsUpdate = needsUpdate;
- }
+ private synchronized void loadBots(Connection connection) {
+ this.unitManager.clearBots();
- public TIntArrayList getRights() {
- return this.rights;
- }
-
- public boolean isMuted() {
- return this.muted;
- }
-
- public void setMuted(boolean muted) {
- this.muted = muted;
- }
-
- public TraxManager getTraxManager() {
- return this.traxManager;
- }
-
- public void addHabboItem(HabboItem item) {
- if (item == null)
- return;
-
- synchronized (this.roomItems) {
- try {
- this.roomItems.put(item.getId(), item);
- } catch (Exception e) {
+ try (PreparedStatement statement = connection.prepareStatement(
+ "SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.user_id = users.id WHERE room_id = ?")) {
+ statement.setInt(1, this.id);
+ try (ResultSet set = statement.executeQuery()) {
+ while (set.next()) {
+ Bot b = Emulator.getGameEnvironment().getBotManager().loadBot(set);
+ if (b != null) {
+ b.setRoom(this);
+ b.setRoomUnit(new RoomUnit());
+ b.getRoomUnit().setPathFinderRoom(this);
+ b.getRoomUnit()
+ .setLocation(this.layout.getTile((short) set.getInt("x"), (short) set.getInt("y")));
+ if (b.getRoomUnit().getCurrentLocation() == null) {
+ b.getRoomUnit().setLocation(this.getLayout().getDoorTile());
+ b.getRoomUnit()
+ .setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection()));
+ } else {
+ b.getRoomUnit().setZ(set.getDouble("z"));
+ b.getRoomUnit().setPreviousLocationZ(set.getDouble("z"));
+ b.getRoomUnit().setRotation(RoomUserRotation.values()[set.getInt("rot")]);
}
+ b.getRoomUnit().setRoomUnitType(RoomUnitType.BOT);
+ b.getRoomUnit().setDanceType(DanceType.values()[set.getInt("dance")]);
+ //b.getRoomUnit().setCanWalk(set.getBoolean("freeroam"));
+ b.getRoomUnit().setInRoom(true);
+ this.giveEffect(b.getRoomUnit(), set.getInt("effect"), Integer.MAX_VALUE);
+ this.addBot(b);
+ }
}
-
- synchronized (this.furniOwnerCount) {
- this.furniOwnerCount.put(item.getUserId(), this.furniOwnerCount.get(item.getUserId()) + 1);
- }
-
- synchronized (this.furniOwnerNames) {
- if (!this.furniOwnerNames.containsKey(item.getUserId())) {
- HabboInfo habbo = HabboManager.getOfflineHabboInfo(item.getUserId());
-
- if (habbo != null) {
- this.furniOwnerNames.put(item.getUserId(), habbo.getUsername());
- } else {
- LOGGER.error("Failed to find username for item (ID: {}, UserID: {})", item.getId(), item.getUserId());
- }
- }
- }
-
- //TODO: Move this list
- synchronized (this.roomSpecialTypes) {
- if (item instanceof ICycleable) {
- this.roomSpecialTypes.addCycleTask((ICycleable) item);
- }
-
- if (item instanceof InteractionWiredTrigger) {
- this.roomSpecialTypes.addTrigger((InteractionWiredTrigger) item);
- } else if (item instanceof InteractionWiredEffect) {
- this.roomSpecialTypes.addEffect((InteractionWiredEffect) item);
- } else if (item instanceof InteractionWiredCondition) {
- this.roomSpecialTypes.addCondition((InteractionWiredCondition) item);
- } else if (item instanceof InteractionWiredExtra) {
- this.roomSpecialTypes.addExtra((InteractionWiredExtra) item);
- } else if (item instanceof InteractionBattleBanzaiTeleporter) {
- this.roomSpecialTypes.addBanzaiTeleporter((InteractionBattleBanzaiTeleporter) item);
- } else if (item instanceof InteractionRoller) {
- this.roomSpecialTypes.addRoller((InteractionRoller) item);
- } else if (item instanceof InteractionGameScoreboard) {
- this.roomSpecialTypes.addGameScoreboard((InteractionGameScoreboard) item);
- } else if (item instanceof InteractionGameGate) {
- this.roomSpecialTypes.addGameGate((InteractionGameGate) item);
- } else if (item instanceof InteractionGameTimer) {
- this.roomSpecialTypes.addGameTimer((InteractionGameTimer) item);
- } else if (item instanceof InteractionFreezeExitTile) {
- this.roomSpecialTypes.addFreezeExitTile((InteractionFreezeExitTile) item);
- } else if (item instanceof InteractionNest) {
- this.roomSpecialTypes.addNest((InteractionNest) item);
- } else if (item instanceof InteractionPetDrink) {
- this.roomSpecialTypes.addPetDrink((InteractionPetDrink) item);
- } else if (item instanceof InteractionPetFood) {
- this.roomSpecialTypes.addPetFood((InteractionPetFood) item);
- } else if (item instanceof InteractionMoodLight) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionPyramid) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionMusicDisc) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionBattleBanzaiSphere) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionTalkingFurniture) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionWater) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionWaterItem) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionMuteArea) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionBuildArea) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionTagPole) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionTagField) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionJukeBox) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionPetBreedingNest) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionBlackHole) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionWiredHighscore) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionStickyPole) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof WiredBlob) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionTent) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionSnowboardSlope) {
- this.roomSpecialTypes.addUndefined(item);
- } else if (item instanceof InteractionFireworks) {
- this.roomSpecialTypes.addUndefined(item);
- }
-
- }
+ }
+ } catch (SQLException e) {
+ LOGGER.error("Caught SQL exception", e);
}
-
- public HabboItem getHabboItem(int id) {
- if (this.roomItems == null || this.roomSpecialTypes == null)
- return null; // room not loaded completely
-
- HabboItem item;
- synchronized (this.roomItems) {
- item = this.roomItems.get(id);
- }
-
- if (item == null)
- item = this.roomSpecialTypes.getBanzaiTeleporter(id);
-
- if (item == null)
- item = this.roomSpecialTypes.getTrigger(id);
-
- if (item == null)
- item = this.roomSpecialTypes.getEffect(id);
-
- if (item == null)
- item = this.roomSpecialTypes.getCondition(id);
-
- if (item == null)
- item = this.roomSpecialTypes.getGameGate(id);
-
- if (item == null)
- item = this.roomSpecialTypes.getGameScorebord(id);
-
- if (item == null)
- item = this.roomSpecialTypes.getGameTimer(id);
-
- if (item == null)
- item = this.roomSpecialTypes.getFreezeExitTiles().get(id);
-
- if (item == null)
- item = this.roomSpecialTypes.getRoller(id);
-
- if (item == null)
- item = this.roomSpecialTypes.getNest(id);
-
- if (item == null)
- item = this.roomSpecialTypes.getPetDrink(id);
-
- if (item == null)
- item = this.roomSpecialTypes.getPetFood(id);
-
- return item;
- }
-
- void removeHabboItem(int id) {
- this.removeHabboItem(this.getHabboItem(id));
- }
-
-
- public void removeHabboItem(HabboItem item) {
- if (item != null) {
-
- HabboItem i;
- synchronized (this.roomItems) {
- i = this.roomItems.remove(item.getId());
- }
-
- if (i != null) {
- synchronized (this.furniOwnerCount) {
- synchronized (this.furniOwnerNames) {
- int count = this.furniOwnerCount.get(i.getUserId());
-
- if (count > 1)
- this.furniOwnerCount.put(i.getUserId(), count - 1);
- else {
- this.furniOwnerCount.remove(i.getUserId());
- this.furniOwnerNames.remove(i.getUserId());
- }
- }
- }
-
- if (item instanceof ICycleable) {
- this.roomSpecialTypes.removeCycleTask((ICycleable) item);
- }
-
- if (item instanceof InteractionBattleBanzaiTeleporter) {
- this.roomSpecialTypes.removeBanzaiTeleporter((InteractionBattleBanzaiTeleporter) item);
- } else if (item instanceof InteractionWiredTrigger) {
- this.roomSpecialTypes.removeTrigger((InteractionWiredTrigger) item);
- } else if (item instanceof InteractionWiredEffect) {
- this.roomSpecialTypes.removeEffect((InteractionWiredEffect) item);
- } else if (item instanceof InteractionWiredCondition) {
- this.roomSpecialTypes.removeCondition((InteractionWiredCondition) item);
- } else if (item instanceof InteractionWiredExtra) {
- this.roomSpecialTypes.removeExtra((InteractionWiredExtra) item);
- } else if (item instanceof InteractionRoller) {
- this.roomSpecialTypes.removeRoller((InteractionRoller) item);
- } else if (item instanceof InteractionGameScoreboard) {
- this.roomSpecialTypes.removeScoreboard((InteractionGameScoreboard) item);
- } else if (item instanceof InteractionGameGate) {
- this.roomSpecialTypes.removeGameGate((InteractionGameGate) item);
- } else if (item instanceof InteractionGameTimer) {
- this.roomSpecialTypes.removeGameTimer((InteractionGameTimer) item);
- } else if (item instanceof InteractionFreezeExitTile) {
- this.roomSpecialTypes.removeFreezeExitTile((InteractionFreezeExitTile) item);
- } else if (item instanceof InteractionNest) {
- this.roomSpecialTypes.removeNest((InteractionNest) item);
- } else if (item instanceof InteractionPetDrink) {
- this.roomSpecialTypes.removePetDrink((InteractionPetDrink) item);
- } else if (item instanceof InteractionPetFood) {
- this.roomSpecialTypes.removePetFood((InteractionPetFood) item);
- } else if (item instanceof InteractionMoodLight) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionPyramid) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionMusicDisc) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionBattleBanzaiSphere) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionTalkingFurniture) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionWaterItem) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionWater) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionMuteArea) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionTagPole) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionTagField) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionJukeBox) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionPetBreedingNest) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionBlackHole) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionWiredHighscore) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionStickyPole) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof WiredBlob) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionTent) {
- this.roomSpecialTypes.removeUndefined(item);
- } else if (item instanceof InteractionSnowboardSlope) {
- this.roomSpecialTypes.removeUndefined(item);
- }
- }
- }
- }
-
- public THashSet getFloorItems() {
- THashSet items = new THashSet<>();
- TIntObjectIterator iterator = this.roomItems.iterator();
-
- for (int i = this.roomItems.size(); i-- > 0; ) {
- try {
- iterator.advance();
- } catch (Exception e) {
- break;
- }
-
- if (iterator.value().getBaseItem().getType() == FurnitureType.FLOOR)
- items.add(iterator.value());
-
- }
-
-
- return items;
-
- }
-
- public THashSet getWallItems() {
- THashSet items = new THashSet<>();
- TIntObjectIterator iterator = this.roomItems.iterator();
-
- for (int i = this.roomItems.size(); i-- > 0; ) {
- try {
- iterator.advance();
- } catch (Exception e) {
- break;
- }
-
- if (iterator.value().getBaseItem().getType() == FurnitureType.WALL)
- items.add(iterator.value());
- }
-
- return items;
-
- }
-
- public THashSet getPostItNotes() {
- THashSet items = new THashSet<>();
- TIntObjectIterator iterator = this.roomItems.iterator();
-
- for (int i = this.roomItems.size(); i-- > 0; ) {
- try {
- iterator.advance();
- } catch (Exception e) {
- break;
- }
-
- if (iterator.value().getBaseItem().getInteractionType().getType() == InteractionPostIt.class)
- items.add(iterator.value());
- }
-
- return items;
-
- }
-
- public void addHabbo(Habbo habbo) {
- synchronized (this.roomUnitLock) {
- habbo.getRoomUnit().setId(this.unitCounter);
- this.currentHabbos.put(habbo.getHabboInfo().getId(), habbo);
- this.unitCounter++;
- this.updateDatabaseUserCount();
- }
- }
-
- public void kickHabbo(Habbo habbo, boolean alert) {
- if (alert) {
- habbo.getClient().sendResponse(new GenericErrorMessagesComposer(GenericErrorMessagesComposer.KICKED_OUT_OF_THE_ROOM));
- }
-
- habbo.getRoomUnit().isKicked = true;
- habbo.getRoomUnit().setGoalLocation(this.layout.getDoorTile());
-
- if (habbo.getRoomUnit().getPath() == null || habbo.getRoomUnit().getPath().size() <= 1 || this.isPublicRoom()) {
- habbo.getRoomUnit().setCanWalk(true);
- Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this);
- }
- }
-
- public void removeHabbo(Habbo habbo) {
- removeHabbo(habbo, false);
- }
-
- public void removeHabbo(Habbo habbo, boolean sendRemovePacket) {
- if (habbo.getRoomUnit() != null && habbo.getRoomUnit().getCurrentLocation() != null) {
- habbo.getRoomUnit().getCurrentLocation().removeUnit(habbo.getRoomUnit());
- }
-
- synchronized (this.roomUnitLock) {
- this.currentHabbos.remove(habbo.getHabboInfo().getId());
- }
-
- if (sendRemovePacket && habbo.getRoomUnit() != null && !habbo.getRoomUnit().isTeleporting) {
- this.sendComposer(new RoomUserRemoveComposer(habbo.getRoomUnit()).compose());
- }
-
- if (habbo.getRoomUnit().getCurrentLocation() != null) {
- HabboItem item = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY());
-
- if (item != null) {
- try {
- item.onWalkOff(habbo.getRoomUnit(), this, new Object[]{});
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
- }
- }
-
- if (habbo.getHabboInfo().getCurrentGame() != null) {
- if (this.getGame(habbo.getHabboInfo().getCurrentGame()) != null) {
- this.getGame(habbo.getHabboInfo().getCurrentGame()).removeHabbo(habbo);
- }
- }
-
- RoomTrade trade = this.getActiveTradeForHabbo(habbo);
-
- if (trade != null) {
- trade.stopTrade(habbo);
- }
-
- if (habbo.getHabboInfo().getId() != this.ownerId) {
- this.pickupPetsForHabbo(habbo);
- }
-
- this.updateDatabaseUserCount();
- }
-
- public void addBot(Bot bot) {
- synchronized (this.roomUnitLock) {
- bot.getRoomUnit().setId(this.unitCounter);
- this.currentBots.put(bot.getId(), bot);
- this.unitCounter++;
- }
- }
-
- public void addPet(Pet pet) {
- synchronized (this.roomUnitLock) {
- pet.getRoomUnit().setId(this.unitCounter);
- this.currentPets.put(pet.getId(), pet);
- this.unitCounter++;
-
- Habbo habbo = this.getHabbo(pet.getUserId());
- if (habbo != null) {
- this.furniOwnerNames.put(pet.getUserId(), this.getHabbo(pet.getUserId()).getHabboInfo().getUsername());
- }
- }
- }
-
- public Bot getBot(int botId) {
- return this.currentBots.get(botId);
- }
-
- public Bot getBot(RoomUnit roomUnit) {
- synchronized (this.currentBots) {
- TIntObjectIterator iterator = this.currentBots.iterator();
-
- for (int i = this.currentBots.size(); i-- > 0; ) {
- try {
- iterator.advance();
- } catch (NoSuchElementException e) {
- LOGGER.error("Caught exception", e);
- break;
- }
-
- if (iterator.value().getRoomUnit() == roomUnit)
- return iterator.value();
- }
- }
-
- return null;
- }
-
- public Bot getBotByRoomUnitId(int id) {
- synchronized (this.currentBots) {
- TIntObjectIterator iterator = this.currentBots.iterator();
-
- for (int i = this.currentBots.size(); i-- > 0; ) {
- try {
- iterator.advance();
- } catch (NoSuchElementException e) {
- LOGGER.error("Caught exception", e);
- break;
- }
-
- if (iterator.value().getRoomUnit().getId() == id)
- return iterator.value();
- }
- }
-
- return null;
- }
-
- public List getBots(String name) {
- List bots = new ArrayList<>();
-
- synchronized (this.currentBots) {
- TIntObjectIterator iterator = this.currentBots.iterator();
-
- for (int i = this.currentBots.size(); i-- > 0; ) {
- try {
- iterator.advance();
- } catch (NoSuchElementException e) {
- LOGGER.error("Caught exception", e);
- break;
- }
-
- if (iterator.value().getName().equalsIgnoreCase(name))
- bots.add(iterator.value());
- }
- }
-
- return bots;
- }
-
- public boolean hasBotsAt(final int x, final int y) {
- final boolean[] result = {false};
-
- synchronized (this.currentBots) {
- this.currentBots.forEachValue(new TObjectProcedure() {
- @Override
- public boolean execute(Bot object) {
- if (object.getRoomUnit().getX() == x && object.getRoomUnit().getY() == y) {
- result[0] = true;
- return false;
- }
-
- return true;
- }
- });
- }
-
- return result[0];
- }
-
- public Pet getPet(int petId) {
- return this.currentPets.get(petId);
- }
-
- public Pet getPet(RoomUnit roomUnit) {
- TIntObjectIterator petIterator = this.currentPets.iterator();
-
- for (int i = this.currentPets.size(); i-- > 0; ) {
- try {
- petIterator.advance();
- } catch (NoSuchElementException e) {
- LOGGER.error("Caught exception", e);
- break;
- }
-
- if (petIterator.value().getRoomUnit() == roomUnit)
- return petIterator.value();
- }
-
- return null;
- }
-
- public boolean removeBot(Bot bot) {
- synchronized (this.currentBots) {
- if (this.currentBots.containsKey(bot.getId())) {
- if (bot.getRoomUnit() != null && bot.getRoomUnit().getCurrentLocation() != null) {
- bot.getRoomUnit().getCurrentLocation().removeUnit(bot.getRoomUnit());
- }
-
- this.currentBots.remove(bot.getId());
- bot.getRoomUnit().setInRoom(false);
- bot.setRoom(null);
- this.sendComposer(new RoomUserRemoveComposer(bot.getRoomUnit()).compose());
- bot.setRoomUnit(null);
- return true;
- }
- }
-
- return false;
- }
-
- public void placePet(Pet pet, short x, short y, double z, int rot) {
- synchronized (this.currentPets) {
- RoomTile tile = this.layout.getTile(x, y);
-
- if (tile == null) {
- tile = this.layout.getDoorTile();
- }
-
- pet.setRoomUnit(new RoomUnit());
+ }
+
+ private synchronized void loadPets(Connection connection) {
+ this.unitManager.clearPets();
+
+ try (PreparedStatement statement = connection.prepareStatement(
+ "SELECT users.username as pet_owner_name, users_pets.* FROM users_pets INNER JOIN users ON users_pets.user_id = users.id WHERE room_id = ?")) {
+ statement.setInt(1, this.id);
+ try (ResultSet set = statement.executeQuery()) {
+ while (set.next()) {
+ try {
+ Pet pet = PetManager.loadPet(set);
pet.setRoom(this);
- pet.getRoomUnit().setGoalLocation(tile);
- pet.getRoomUnit().setLocation(tile);
+ pet.setRoomUnit(new RoomUnit());
+ pet.getRoomUnit().setPathFinderRoom(this);
+ pet.getRoomUnit()
+ .setLocation(this.layout.getTile((short) set.getInt("x"), (short) set.getInt("y")));
+ if (pet.getRoomUnit().getCurrentLocation() == null) {
+ pet.getRoomUnit().setLocation(this.getLayout().getDoorTile());
+ pet.getRoomUnit()
+ .setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection()));
+ } else {
+ pet.getRoomUnit().setZ(set.getDouble("z"));
+ pet.getRoomUnit().setRotation(RoomUserRotation.values()[set.getInt("rot")]);
+ }
pet.getRoomUnit().setRoomUnitType(RoomUnitType.PET);
pet.getRoomUnit().setCanWalk(true);
- pet.getRoomUnit().setPathFinderRoom(this);
- pet.getRoomUnit().setPreviousLocationZ(z);
- pet.getRoomUnit().setZ(z);
- if (pet.getRoomUnit().getCurrentLocation() == null) {
- pet.getRoomUnit().setLocation(this.getLayout().getDoorTile());
- pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection()));
- }
-
- pet.needsUpdate = true;
- this.furniOwnerNames.put(pet.getUserId(), this.getHabbo(pet.getUserId()).getHabboInfo().getUsername());
this.addPet(pet);
- this.sendComposer(new RoomPetComposer(pet).compose());
- }
- }
- public Pet removePet(int petId) {
- return this.currentPets.remove(petId);
- }
-
- public boolean hasHabbosAt(int x, int y) {
- for (Habbo habbo : this.getHabbos()) {
- if (habbo.getRoomUnit().getX() == x && habbo.getRoomUnit().getY() == y)
- return true;
- }
- return false;
- }
-
- public boolean hasPetsAt(int x, int y) {
- synchronized (this.currentPets) {
- TIntObjectIterator petIterator = this.currentPets.iterator();
-
- for (int i = this.currentPets.size(); i-- > 0; ) {
- try {
- petIterator.advance();
- } catch (NoSuchElementException e) {
- LOGGER.error("Caught exception", e);
- break;
- }
-
- if (petIterator.value().getRoomUnit().getX() == x && petIterator.value().getRoomUnit().getY() == y)
- return true;
- }
- }
-
- return false;
- }
-
- public THashSet getBotsAt(RoomTile tile) {
- THashSet bots = new THashSet<>();
- synchronized (this.currentBots) {
- TIntObjectIterator botIterator = this.currentBots.iterator();
-
- for (int i = this.currentBots.size(); i-- > 0; ) {
- try {
- botIterator.advance();
-
- if (botIterator.value().getRoomUnit().getCurrentLocation().equals(tile)) {
- bots.add(botIterator.value());
- }
- } catch (Exception e) {
- break;
- }
- }
- }
-
- return bots;
- }
-
- public THashSet getPetsAt(RoomTile tile) {
- THashSet pets = new THashSet<>();
- synchronized (this.currentPets) {
- TIntObjectIterator petIterator = this.currentPets.iterator();
-
- for (int i = this.currentPets.size(); i-- > 0; ) {
- try {
- petIterator.advance();
-
- if (petIterator.value().getRoomUnit().getCurrentLocation().equals(tile)) {
- pets.add(petIterator.value());
- }
- } catch (Exception e) {
- break;
- }
- }
- }
-
- return pets;
- }
-
- public THashSet getHabbosAt(short x, short y) {
- return this.getHabbosAt(this.layout.getTile(x, y));
- }
-
- public THashSet getHabbosAt(RoomTile tile) {
- THashSet habbos = new THashSet<>();
-
- for (Habbo habbo : this.getHabbos()) {
- if (habbo.getRoomUnit().getCurrentLocation().equals(tile))
- habbos.add(habbo);
- }
-
- return habbos;
- }
-
- public THashSet getHabbosAndBotsAt(short x, short y) {
- return this.getHabbosAndBotsAt(this.layout.getTile(x, y));
- }
-
- public THashSet getHabbosAndBotsAt(RoomTile tile) {
- THashSet list = new THashSet<>();
-
- for (Bot bot : this.getBotsAt(tile)) {
- list.add(bot.getRoomUnit());
- }
-
- for (Habbo habbo : this.getHabbosAt(tile)) {
- list.add(habbo.getRoomUnit());
- }
-
- return list;
- }
-
- public THashSet getHabbosOnItem(HabboItem item) {
- THashSet habbos = new THashSet<>();
- for (short x = item.getX(); x < item.getX() + item.getBaseItem().getLength(); x++) {
- for (short y = item.getY(); y < item.getY() + item.getBaseItem().getWidth(); y++) {
- habbos.addAll(this.getHabbosAt(x, y));
- }
- }
-
- return habbos;
- }
-
- public THashSet getBotsOnItem(HabboItem item) {
- THashSet bots = new THashSet<>();
- for (short x = item.getX(); x < item.getX() + item.getBaseItem().getLength(); x++) {
- for (short y = item.getY(); y < item.getY() + item.getBaseItem().getWidth(); y++) {
- bots.addAll(this.getBotsAt(this.getLayout().getTile(x, y)));
- }
- }
-
- return bots;
- }
-
- public void teleportHabboToItem(Habbo habbo, HabboItem item) {
- this.teleportRoomUnitToLocation(habbo.getRoomUnit(), item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item));
- }
-
- public void teleportHabboToLocation(Habbo habbo, short x, short y) {
- this.teleportRoomUnitToLocation(habbo.getRoomUnit(), x, y, 0.0);
- }
-
- public void teleportRoomUnitToItem(RoomUnit roomUnit, HabboItem item) {
- this.teleportRoomUnitToLocation(roomUnit, item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item));
- }
-
- public void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y) {
- this.teleportRoomUnitToLocation(roomUnit, x, y, 0.0);
- }
-
- public void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y, double z) {
- if (this.loaded) {
- RoomTile tile = this.layout.getTile(x, y);
-
- if (z < tile.z) {
- z = tile.z;
- }
-
- roomUnit.setLocation(tile);
- roomUnit.setGoalLocation(tile);
- roomUnit.setZ(z);
- roomUnit.setPreviousLocationZ(z);
- this.updateRoomUnit(roomUnit);
-
-
- }
- }
-
- public void muteHabbo(Habbo habbo, int minutes) {
- synchronized (this.mutedHabbos) {
- this.mutedHabbos.put(habbo.getHabboInfo().getId(), Emulator.getIntUnixTimestamp() + (minutes * 60));
- }
- }
-
- public boolean isMuted(Habbo habbo) {
- if (this.isOwner(habbo) || this.hasRights(habbo))
- return false;
-
- if (this.mutedHabbos.containsKey(habbo.getHabboInfo().getId())) {
- boolean time = this.mutedHabbos.get(habbo.getHabboInfo().getId()) > Emulator.getIntUnixTimestamp();
-
- if (!time) {
- this.mutedHabbos.remove(habbo.getHabboInfo().getId());
- }
-
- return time;
- }
-
- return false;
- }
-
- public void habboEntered(Habbo habbo) {
- habbo.getRoomUnit().animateWalk = false;
-
- synchronized (this.currentBots) {
- if (habbo.getHabboInfo().getId() != this.getOwnerId())
- return;
-
- TIntObjectIterator botIterator = this.currentBots.iterator();
-
- for (int i = this.currentBots.size(); i-- > 0; ) {
- try {
- botIterator.advance();
-
- if (botIterator.value() instanceof VisitorBot) {
- ((VisitorBot) botIterator.value()).onUserEnter(habbo);
- break;
- }
- } catch (Exception e) {
- break;
- }
- }
- }
-
- HabboItem doorTileTopItem = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY());
- if (doorTileTopItem != null && !(doorTileTopItem instanceof InteractionTeleportTile)) {
- try {
- doorTileTopItem.onWalkOn(habbo.getRoomUnit(), this, new Object[]{});
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
- }
- }
-
- public void floodMuteHabbo(Habbo habbo, int timeOut) {
- habbo.getHabboStats().mutedCount++;
- timeOut += (timeOut * (int) Math.ceil(Math.pow(habbo.getHabboStats().mutedCount, 2)));
- habbo.getHabboStats().chatCounter.set(0);
- habbo.mute(timeOut, true);
- }
-
- public void talk(Habbo habbo, RoomChatMessage roomChatMessage, RoomChatType chatType) {
- this.talk(habbo, roomChatMessage, chatType, false);
- }
-
- public void talk(final Habbo habbo, final RoomChatMessage roomChatMessage, RoomChatType chatType, boolean ignoreWired) {
- if (!habbo.getHabboStats().allowTalk())
- return;
-
- if (habbo.getRoomUnit().isInvisible() && Emulator.getConfig().getBoolean("invisible.prevent.chat", false)) {
- if (!CommandHandler.handleCommand(habbo.getClient(), roomChatMessage.getUnfilteredMessage())) {
- habbo.whisper(Emulator.getTexts().getValue("invisible.prevent.chat.error"));
- }
-
- return;
- }
-
- if (habbo.getHabboInfo().getCurrentRoom() != this)
- return;
-
- long millis = System.currentTimeMillis();
- if (HABBO_CHAT_DELAY) {
- if (millis - habbo.getHabboStats().lastChat < 750) {
- return;
- }
- }
- habbo.getHabboStats().lastChat = millis;
- if (roomChatMessage != null && Emulator.getConfig().getBoolean("easter_eggs.enabled") && roomChatMessage.getMessage().equalsIgnoreCase("i am a pirate")) {
- habbo.getHabboStats().chatCounter.addAndGet(1);
- Emulator.getThreading().run(new YouAreAPirate(habbo, this));
- return;
- }
-
- UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.TALKED, false);
- Emulator.getPluginManager().fireEvent(event);
-
- if (!event.isCancelled()) {
- if (!event.idle) {
- this.unIdle(habbo);
- }
- }
-
- this.sendComposer(new RoomUserTypingComposer(habbo.getRoomUnit(), false).compose());
-
- if (roomChatMessage == null || roomChatMessage.getMessage() == null || roomChatMessage.getMessage().equals(""))
- return;
-
- if (!habbo.hasPermission(Permission.ACC_NOMUTE) && (!MUTEAREA_CAN_WHISPER || chatType != RoomChatType.WHISPER)) {
- for (HabboItem area : this.getRoomSpecialTypes().getItemsOfType(InteractionMuteArea.class)) {
- if (((InteractionMuteArea) area).inSquare(habbo.getRoomUnit().getCurrentLocation())) {
- return;
- }
- }
- }
-
- if (!this.wordFilterWords.isEmpty()) {
- if (!habbo.hasPermission(Permission.ACC_CHAT_NO_FILTER)) {
- for (String string : this.wordFilterWords) {
- roomChatMessage.setMessage(roomChatMessage.getMessage().replaceAll("(?i)" + Pattern.quote(string), "bobba"));
- }
- }
- }
-
- if (!habbo.hasPermission(Permission.ACC_NOMUTE)) {
- if (this.isMuted() && !this.hasRights(habbo)) {
- return;
- }
-
- if (this.isMuted(habbo)) {
- habbo.getClient().sendResponse(new MutedWhisperComposer(this.mutedHabbos.get(habbo.getHabboInfo().getId()) - Emulator.getIntUnixTimestamp()));
- return;
- }
- }
-
- if (!habbo.hasPermission(Permission.ACC_CHAT_NO_FLOOD)) {
- final int chatCounter = habbo.getHabboStats().chatCounter.addAndGet(1);
-
- if (chatCounter > 3) {
- final boolean floodRights = Emulator.getConfig().getBoolean("flood.with.rights");
- final boolean hasRights = this.hasRights(habbo);
-
- if (floodRights || !hasRights) {
- this.floodMuteHabbo(habbo, muteTime);
- return;
-
- /*if (this.chatProtection == 0) {
- this.floodMuteHabbo(habbo, muteTime);
- return;
- } else if (this.chatProtection == 1 && chatCounter > 4) {
- this.floodMuteHabbo(habbo, muteTime);
- return;
- } else if (this.chatProtection == 2 && chatCounter > 5) {
- this.floodMuteHabbo(habbo, muteTime);
- return;
- }*/
- }
- }
- }
-
- if (chatType != RoomChatType.WHISPER) {
- if (CommandHandler.handleCommand(habbo.getClient(), roomChatMessage.getUnfilteredMessage())) {
- WiredHandler.handle(WiredTriggerType.SAY_COMMAND, habbo.getRoomUnit(), habbo.getHabboInfo().getCurrentRoom(), new Object[]{roomChatMessage.getMessage()});
- roomChatMessage.isCommand = true;
- return;
- }
-
- if (!ignoreWired) {
- if (WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, habbo.getRoomUnit(), habbo.getHabboInfo().getCurrentRoom(), new Object[]{roomChatMessage.getMessage()})) {
- habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(roomChatMessage.getMessage(), habbo, habbo, roomChatMessage.getBubble())));
- return;
- }
- }
- }
-
- ServerMessage prefixMessage = null;
-
- if (Emulator.getPluginManager().isRegistered(UsernameTalkEvent.class, true)) {
- UsernameTalkEvent usernameTalkEvent = Emulator.getPluginManager().fireEvent(new UsernameTalkEvent(habbo, roomChatMessage, chatType));
- if (usernameTalkEvent.hasCustomComposer()) {
- prefixMessage = usernameTalkEvent.getCustomComposer();
- }
- }
-
- if (prefixMessage == null) {
- prefixMessage = roomChatMessage.getHabbo().getHabboInfo().getRank().hasPrefix() ? new RoomUserNameChangedComposer(habbo, true).compose() : null;
- }
- ServerMessage clearPrefixMessage = prefixMessage != null ? new RoomUserNameChangedComposer(habbo).compose() : null;
-
- Rectangle tentRectangle = this.roomSpecialTypes.tentAt(habbo.getRoomUnit().getCurrentLocation());
-
- String trimmedMessage = roomChatMessage.getMessage().replaceAll("\\s+$", "");
-
- if (trimmedMessage.isEmpty()) trimmedMessage = " ";
-
- roomChatMessage.setMessage(trimmedMessage);
-
- if (chatType == RoomChatType.WHISPER) {
- if (roomChatMessage.getTargetHabbo() == null) {
- return;
- }
-
- RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage);
- staffChatMessage.setMessage("To " + staffChatMessage.getTargetHabbo().getHabboInfo().getUsername() + ": " + staffChatMessage.getMessage());
-
- final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose();
- final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose();
-
- for (Habbo h : this.getHabbos()) {
- if (h == roomChatMessage.getTargetHabbo() || h == habbo) {
- if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
- if (prefixMessage != null) {
- h.getClient().sendResponse(prefixMessage);
- }
- h.getClient().sendResponse(message);
-
- if (clearPrefixMessage != null) {
- h.getClient().sendResponse(clearPrefixMessage);
- }
- }
-
- continue;
- }
- if (h.hasPermission(Permission.ACC_SEE_WHISPERS)) {
- h.getClient().sendResponse(staffMessage);
- }
- }
- } else if (chatType == RoomChatType.TALK) {
- ServerMessage message = new RoomUserTalkComposer(roomChatMessage).compose();
- boolean noChatLimit = habbo.hasPermission(Permission.ACC_CHAT_NO_LIMIT);
-
- for (Habbo h : this.getHabbos()) {
- if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance ||
- h.equals(habbo) ||
- this.hasRights(h) ||
- noChatLimit) && (tentRectangle == null || RoomLayout.tileInSquare(tentRectangle, h.getRoomUnit().getCurrentLocation()))) {
- if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
- if (prefixMessage != null && !h.getHabboStats().preferOldChat) {
- h.getClient().sendResponse(prefixMessage);
- }
- h.getClient().sendResponse(message);
- if (clearPrefixMessage != null && !h.getHabboStats().preferOldChat) {
- h.getClient().sendResponse(clearPrefixMessage);
- }
- }
- continue;
- }
- // Staff should be able to see the tent chat anyhow
- showTentChatMessageOutsideTentIfPermitted(h, roomChatMessage, tentRectangle);
- }
- } else if (chatType == RoomChatType.SHOUT) {
- ServerMessage message = new RoomUserShoutComposer(roomChatMessage).compose();
-
- for (Habbo h : this.getHabbos()) {
- // Show the message
- // If the receiving Habbo has not ignored the sending Habbo
- // AND the sending Habbo is NOT in a tent OR the receiving Habbo is in the same tent as the sending Habbo
- if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()) && (tentRectangle == null || RoomLayout.tileInSquare(tentRectangle, h.getRoomUnit().getCurrentLocation()))) {
- if (prefixMessage != null && !h.getHabboStats().preferOldChat) {
- h.getClient().sendResponse(prefixMessage);
- }
- h.getClient().sendResponse(message);
- if (clearPrefixMessage != null && !h.getHabboStats().preferOldChat) {
- h.getClient().sendResponse(clearPrefixMessage);
- }
- continue;
- }
- // Staff should be able to see the tent chat anyhow, even when not in the same tent
- showTentChatMessageOutsideTentIfPermitted(h, roomChatMessage, tentRectangle);
- }
- }
-
- if (chatType == RoomChatType.TALK || chatType == RoomChatType.SHOUT) {
- synchronized (this.currentBots) {
- TIntObjectIterator botIterator = this.currentBots.iterator();
-
- for (int i = this.currentBots.size(); i-- > 0; ) {
- try {
- botIterator.advance();
- Bot bot = botIterator.value();
- bot.onUserSay(roomChatMessage);
-
- } catch (NoSuchElementException e) {
- LOGGER.error("Caught exception", e);
- break;
- }
- }
- }
-
- if (roomChatMessage.getBubble().triggersTalkingFurniture()) {
- THashSet items = this.roomSpecialTypes.getItemsOfType(InteractionTalkingFurniture.class);
-
- for (HabboItem item : items) {
- if (this.layout.getTile(item.getX(), item.getY()).distance(habbo.getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("furniture.talking.range")) {
- int count = Emulator.getConfig().getInt(item.getBaseItem().getName() + ".message.count", 0);
-
- if (count > 0) {
- int randomValue = Emulator.getRandom().nextInt(count + 1);
-
- RoomChatMessage itemMessage = new RoomChatMessage(Emulator.getTexts().getValue(item.getBaseItem().getName() + ".message." + randomValue, item.getBaseItem().getName() + ".message." + randomValue + " not found!"), habbo, RoomChatMessageBubbles.getBubble(Emulator.getConfig().getInt(item.getBaseItem().getName() + ".message.bubble", RoomChatMessageBubbles.PARROT.getType())));
-
- this.sendComposer(new RoomUserTalkComposer(itemMessage).compose());
-
- try {
- item.onClick(habbo.getClient(), this, new Object[0]);
- item.setExtradata("1");
- updateItemState(item);
-
- Emulator.getThreading().run(() -> {
- item.setExtradata("0");
- updateItemState(item);
- }, 2000);
-
- break;
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
- }
- }
- }
- }
- }
- }
-
- /**
- * Sends the given message to the receiving Habbo if the Habbo has the ACC_SEE_TENTCHAT permission and is not within the tent
- *
- * @param receivingHabbo The receiving Habbo
- * @param roomChatMessage The message to receive
- * @param tentRectangle The whole tent area from where the sending Habbo is saying something
- */
- private void showTentChatMessageOutsideTentIfPermitted(Habbo receivingHabbo, RoomChatMessage roomChatMessage, Rectangle tentRectangle) {
- if (receivingHabbo != null && receivingHabbo.hasPermission(Permission.ACC_SEE_TENTCHAT) && tentRectangle != null && !RoomLayout.tileInSquare(tentRectangle, receivingHabbo.getRoomUnit().getCurrentLocation())) {
- RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage);
- staffChatMessage.setMessage("[" + Emulator.getTexts().getValue("hotel.room.tent.prefix") + "] " + staffChatMessage.getMessage());
- final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose();
- receivingHabbo.getClient().sendResponse(staffMessage);
- }
- }
-
- public THashSet getLockedTiles() {
- THashSet lockedTiles = new THashSet<>();
-
- TIntObjectIterator iterator = this.roomItems.iterator();
-
- for (int i = this.roomItems.size(); i-- > 0; ) {
- HabboItem item;
- try {
- iterator.advance();
- item = iterator.value();
- } catch (Exception e) {
- break;
- }
-
- if (item.getBaseItem().getType() != FurnitureType.FLOOR)
- continue;
-
- boolean found = false;
- for (RoomTile tile : lockedTiles) {
- if (tile.x == item.getX() &&
- tile.y == item.getY()) {
- found = true;
- break;
- }
- }
-
- if (!found) {
- if (item.getRotation() == 0 || item.getRotation() == 4) {
- for (short y = 0; y < item.getBaseItem().getLength(); y++) {
- for (short x = 0; x < item.getBaseItem().getWidth(); x++) {
- RoomTile tile = this.layout.getTile((short) (item.getX() + x), (short) (item.getY() + y));
-
- if (tile != null) {
- lockedTiles.add(tile);
- }
- }
- }
- } else {
- for (short y = 0; y < item.getBaseItem().getWidth(); y++) {
- for (short x = 0; x < item.getBaseItem().getLength(); x++) {
- RoomTile tile = this.layout.getTile((short) (item.getX() + x), (short) (item.getY() + y));
-
- if (tile != null) {
- lockedTiles.add(tile);
- }
- }
- }
- }
- }
- }
-
- return lockedTiles;
- }
-
- @Deprecated
- public THashSet getItemsAt(int x, int y) {
- RoomTile tile = this.getLayout().getTile((short) x, (short) y);
-
- if (tile != null) {
- return this.getItemsAt(tile);
- }
-
- return new THashSet<>(0);
- }
-
- public THashSet getItemsAt(RoomTile tile) {
- return getItemsAt(tile, false);
- }
-
- public THashSet getItemsAt(RoomTile tile, boolean returnOnFirst) {
- THashSet items = new THashSet<>(0);
-
- if (tile == null)
- return items;
-
- if (this.loaded) {
- THashSet cachedItems = this.tileCache.get(tile);
- if (cachedItems != null)
- return cachedItems;
- }
-
- TIntObjectIterator iterator = this.roomItems.iterator();
-
- for (int i = this.roomItems.size(); i-- > 0; ) {
- HabboItem item;
- try {
- iterator.advance();
- item = iterator.value();
- } catch (Exception e) {
- break;
- }
-
- if (item == null)
- continue;
-
- if (item.getBaseItem().getType() != FurnitureType.FLOOR)
- continue;
-
- int width, length;
-
- if (item.getRotation() != 2 && item.getRotation() != 6) {
- width = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1;
- length = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1;
- } else {
- width = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1;
- length = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1;
- }
-
- if (!(tile.x >= item.getX() && tile.x <= item.getX() + width - 1 && tile.y >= item.getY() && tile.y <= item.getY() + length - 1))
- continue;
-
- items.add(item);
-
- if (returnOnFirst) {
- return items;
- }
- }
-
- if (this.loaded) {
- this.tileCache.put(tile, items);
- }
-
- return items;
- }
-
- public THashSet getItemsAt(int x, int y, double minZ) {
- THashSet items = new THashSet<>();
-
- for (HabboItem item : this.getItemsAt(x, y)) {
- if (item.getZ() < minZ)
- continue;
-
- items.add(item);
- }
- return items;
- }
-
- public THashSet getItemsAt(Class extends HabboItem> type, int x, int y) {
- THashSet items = new THashSet<>();
-
- for (HabboItem item : this.getItemsAt(x, y)) {
- if (!item.getClass().equals(type))
- continue;
-
- items.add(item);
- }
- return items;
- }
-
- public boolean hasItemsAt(int x, int y) {
- RoomTile tile = this.getLayout().getTile((short) x, (short) y);
-
- if (tile == null)
- return false;
-
- return this.getItemsAt(tile, true).size() > 0;
- }
-
- public HabboItem getTopItemAt(int x, int y) {
- return this.getTopItemAt(x, y, null);
- }
-
- public HabboItem getTopItemAt(int x, int y, HabboItem exclude) {
- RoomTile tile = this.getLayout().getTile((short) x, (short) y);
-
- if (tile == null)
- return null;
-
- HabboItem highestItem = null;
-
- for (HabboItem item : this.getItemsAt(x, y)) {
- if (exclude != null && exclude == item)
- continue;
-
- if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
- continue;
-
- highestItem = item;
- }
-
- return highestItem;
- }
-
- public HabboItem getTopItemAt(THashSet tiles, HabboItem exclude) {
- HabboItem highestItem = null;
- for (RoomTile tile : tiles) {
-
- if (tile == null)
- continue;
-
- for (HabboItem item : this.getItemsAt(tile.x, tile.y)) {
- if (exclude != null && exclude == item)
- continue;
-
- if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
- continue;
-
- highestItem = item;
- }
- }
-
- return highestItem;
- }
-
- public double getTopHeightAt(int x, int y) {
- HabboItem item = this.getTopItemAt(x, y);
-
- if (item != null)
- return (item.getZ() + Item.getCurrentHeight(item) - (item.getBaseItem().allowSit() ? 1 : 0));
- else
- return this.layout.getHeightAtSquare(x, y);
- }
-
- @Deprecated
- public HabboItem getLowestChair(int x, int y) {
- if (this.layout == null) return null;
-
- RoomTile tile = this.layout.getTile((short) x, (short) y);
-
- if (tile != null) {
- return this.getLowestChair(tile);
- }
-
- return null;
- }
-
- public HabboItem getLowestChair(RoomTile tile) {
- HabboItem lowestChair = null;
-
- THashSet items = this.getItemsAt(tile);
- if (items != null && !items.isEmpty()) {
- for (HabboItem item : items) {
-
- if (!item.getBaseItem().allowSit())
- continue;
-
- if (lowestChair != null && lowestChair.getZ() < item.getZ())
- continue;
-
- lowestChair = item;
- }
- }
-
- return lowestChair;
- }
-
- public HabboItem getTallestChair(RoomTile tile) {
- HabboItem lowestChair = null;
-
- THashSet items = this.getItemsAt(tile);
- if (items != null && !items.isEmpty()) {
- for (HabboItem item : items) {
-
- if (!item.getBaseItem().allowSit())
- continue;
-
- if (lowestChair != null && lowestChair.getZ() + Item.getCurrentHeight(lowestChair) > item.getZ() + Item.getCurrentHeight(item))
- continue;
-
- lowestChair = item;
- }
- }
-
- return lowestChair;
- }
-
- 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;
-
- 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;
-
- THashSet stackHelpers = this.getItemsAt(InteractionStackHelper.class, x, y);
- stackHelpers.addAll(this.getItemsAt(InteractionTileWalkMagic.class, x, y));
-
- if (stackHelpers.size() > 0) {
- for (HabboItem item : stackHelpers) {
- if (item == exclude) continue;
- return calculateHeightmap ? item.getZ() * 256.0D : item.getZ();
- }
- }
-
- HabboItem item = this.getTopItemAt(x, y, exclude);
- if (item != null) {
- canStack = item.getBaseItem().allowStack();
- height = item.getZ() + (item.getBaseItem().allowSit() ? 0 : Item.getCurrentHeight(item));
- }
-
- /*HabboItem lowestChair = this.getLowestChair(x, y);
- if (lowestChair != null && lowestChair != exclude) {
- canStack = true;
- height = lowestChair.getZ();
- }*/
-
- if (calculateHeightmap) {
- return (canStack ? height * 256.0D : Short.MAX_VALUE);
- }
-
- return canStack ? height : -1;
- }
-
- public double getStackHeight(short x, short y, boolean calculateHeightmap) {
- return this.getStackHeight(x, y, calculateHeightmap, null);
- }
-
- public boolean hasObjectTypeAt(Class> type, int x, int y) {
- THashSet items = this.getItemsAt(x, y);
-
- for (HabboItem item : items) {
- if (item.getClass() == type) {
- return true;
- }
- }
-
- return false;
- }
-
- public boolean canSitOrLayAt(int x, int y) {
- if (this.hasHabbosAt(x, y))
- return false;
-
- THashSet items = this.getItemsAt(x, y);
-
- return this.canSitAt(items) || this.canLayAt(items);
- }
-
- public boolean canSitAt(int x, int y) {
- if (this.hasHabbosAt(x, y))
- return false;
-
- return this.canSitAt(this.getItemsAt(x, y));
- }
-
- boolean canWalkAt(RoomTile roomTile) {
- if (roomTile == null) {
- return false;
- }
-
- if (roomTile.state == RoomTileState.INVALID)
- return false;
-
- HabboItem topItem = null;
- boolean canWalk = true;
- THashSet items = this.getItemsAt(roomTile);
- if (items != null) {
- for (HabboItem item : items) {
- if (topItem == null) {
- topItem = item;
- }
-
- if (item.getZ() > topItem.getZ()) {
- topItem = item;
- canWalk = topItem.isWalkable() || topItem.getBaseItem().allowWalk();
- } else if (item.getZ() == topItem.getZ() && canWalk) {
- if ((!topItem.isWalkable() && !topItem.getBaseItem().allowWalk()) || (!item.getBaseItem().allowWalk() && !item.isWalkable())) {
- canWalk = false;
- }
- }
- }
- }
-
- return canWalk;
- }
-
- boolean canSitAt(THashSet items) {
- if (items == null)
- return false;
-
- HabboItem tallestItem = null;
-
- for (HabboItem item : items) {
- if (tallestItem != null && tallestItem.getZ() + Item.getCurrentHeight(tallestItem) > item.getZ() + Item.getCurrentHeight(item))
- continue;
-
- tallestItem = item;
- }
-
- if (tallestItem == null)
- return false;
-
- return tallestItem.getBaseItem().allowSit();
- }
-
- public boolean canLayAt(int x, int y) {
- return this.canLayAt(this.getItemsAt(x, y));
- }
-
- boolean canLayAt(THashSet items) {
- if (items == null || items.isEmpty())
- return true;
-
- HabboItem topItem = null;
-
- for (HabboItem item : items) {
- if ((topItem == null || item.getZ() > topItem.getZ())) {
- topItem = item;
- }
- }
-
- return (topItem == null || topItem.getBaseItem().allowLay());
- }
-
- public RoomTile getRandomWalkableTile() {
- for (int i = 0; i < 10; i++) {
- RoomTile tile = this.layout.getTile((short) (Math.random() * this.layout.getMapSizeX()), (short) (Math.random() * this.layout.getMapSizeY()));
- if (tile != null && tile.getState() != RoomTileState.BLOCKED && tile.getState() != RoomTileState.INVALID) {
- return tile;
- }
- }
-
- return null;
- }
-
- public RoomTile getRandomWalkableTilesAround(RoomUnit roomUnit, RoomTile tile, int radius) {
- if (!layout.tileExists(tile.x, tile.y)) {
- tile = layout.getTile(roomUnit.getX(), roomUnit.getY());
- this.getBot(roomUnit).needsUpdate(true);
- }
-
- List walkableTiles = new ArrayList<>();
-
- int minX = Math.max(0, tile.x - radius);
- int minY = Math.max(0, tile.y - radius);
- int maxX = Math.min(this.getLayout().getMapSizeX() - 1, tile.x + radius);
- int maxY = Math.min(this.getLayout().getMapSizeY() - 1, tile.y + radius);
-
- for (int x = minX; x <= maxX; x++) {
- for (int y = minY; y <= maxY; y++) {
- RoomTile candidateTile = this.getLayout().getTile((short) x, (short) y);
-
- if (candidateTile != null && candidateTile.getState() != RoomTileState.BLOCKED && candidateTile.getState() != RoomTileState.INVALID) {
- walkableTiles.add(candidateTile);
- }
- }
- }
-
- if (walkableTiles.isEmpty()) {
- return tile;
- }
-
- Collections.shuffle(walkableTiles);
- return walkableTiles.get(0);
- }
-
- public Habbo getHabbo(String username) {
- for (Habbo habbo : this.getHabbos()) {
- if (habbo.getHabboInfo().getUsername().equalsIgnoreCase(username))
- return habbo;
- }
- return null;
- }
-
- public Habbo getHabbo(RoomUnit roomUnit) {
- for (Habbo habbo : this.getHabbos()) {
- if (habbo.getRoomUnit() == roomUnit)
- return habbo;
- }
- return null;
- }
-
- public Habbo getHabbo(int userId) {
- return this.currentHabbos.get(userId);
- }
-
- public Habbo getHabboByRoomUnitId(int roomUnitId) {
- for (Habbo habbo : this.getHabbos()) {
- if (habbo.getRoomUnit().getId() == roomUnitId)
- return habbo;
- }
-
- return null;
- }
-
- public void sendComposer(ServerMessage message) {
- for (Habbo habbo : this.getHabbos()) {
- if (habbo.getClient() == null) continue;
-
- habbo.getClient().sendResponse(message);
- }
- }
-
- public void sendComposerToHabbosWithRights(ServerMessage message) {
- for (Habbo habbo : this.getHabbos()) {
- if (this.hasRights(habbo)) {
- habbo.getClient().sendResponse(message);
- }
- }
- }
-
- public void petChat(ServerMessage message) {
- for (Habbo habbo : this.getHabbos()) {
- if (!habbo.getHabboStats().ignorePets)
- habbo.getClient().sendResponse(message);
- }
- }
-
- public void botChat(ServerMessage message) {
- if (message == null) {
- return;
- }
-
- for (Habbo habbo : this.getHabbos()) {
- if (habbo == null) { continue; }
- if (!habbo.getHabboStats().ignoreBots)
- habbo.getClient().sendResponse(message);
- }
- }
-
- private void loadRights(Connection connection) {
- this.rights.clear();
- try (PreparedStatement statement = connection.prepareStatement("SELECT user_id FROM room_rights WHERE room_id = ?")) {
- statement.setInt(1, this.id);
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- this.rights.add(set.getInt("user_id"));
- }
- }
- } catch (SQLException e) {
+ this.getFurniOwnerNames().put(pet.getUserId(), set.getString("pet_owner_name"));
+ } catch (SQLException e) {
LOGGER.error("Caught SQL exception", e);
+ }
}
+ }
+ } catch (SQLException e) {
+ LOGGER.error("Caught SQL exception", e);
+ }
+ }
+
+ private synchronized void loadWordFilter(Connection connection) {
+ this.chatManager.loadWordFilter(connection);
+ }
+
+ public void updateTile(RoomTile tile) {
+ this.tileManager.updateTile(tile);
+ }
+
+ public void updateTiles(THashSet