From f973f7885d86890d7c3a1b712b90b4d66937cafd Mon Sep 17 00:00:00 2001 From: Dom Bridge Date: Wed, 11 Jan 2023 12:45:21 +0000 Subject: [PATCH] Code optimisations and readability --- pom.xml | 1 - .../com/eu/habbo/habbohotel/bots/Bot.java | 3 +- .../campaign/CalendarRewardClaimed.java | 3 +- .../habbohotel/catalog/CatalogManager.java | 3 +- .../catalog/VoucherHistoryEntry.java | 3 +- .../catalog/marketplace/MarketPlace.java | 3 +- .../com/eu/habbo/habbohotel/guilds/Guild.java | 3 +- .../habbo/habbohotel/guilds/GuildManager.java | 3 +- .../habbo/habbohotel/guilds/GuildMember.java | 3 +- .../guilds/forums/ForumThreadComment.java | 3 +- .../habbohotel/guilds/forums/ForumView.java | 3 +- .../interactions/InteractionMultiHeight.java | 2 +- .../interactions/InteractionPushable.java | 2 +- .../games/football/InteractionFootball.java | 2 +- .../pets/InteractionPetBreedingNest.java | 2 +- .../interactions/pets/InteractionPetToy.java | 2 +- .../pets/InteractionPetTrampoline.java | 2 +- .../interactions/pets/InteractionPetTree.java | 2 +- .../WiredEffectChangeFurniDirection.java | 3 +- .../habbo/habbohotel/modtool/ModToolBan.java | 3 +- .../habbohotel/pets/MonsterplantPet.java | 2 +- .../com/eu/habbo/habbohotel/pets/Pet.java | 3 +- .../com/eu/habbo/habbohotel/rooms/Room.java | 858 ++++++------------ .../eu/habbo/habbohotel/rooms/RoomBan.java | 3 +- .../habbo/habbohotel/rooms/RoomManager.java | 54 +- .../eu/habbo/habbohotel/rooms/RoomUnit.java | 115 +-- .../eu/habbo/habbohotel/users/HabboInfo.java | 3 +- .../eu/habbo/habbohotel/users/HabboItem.java | 7 +- .../users/HabboNavigatorWindowSettings.java | 3 +- .../users/cache/HabboOfferPurchase.java | 3 +- .../users/inventory/EffectsComponent.java | 3 +- .../subscriptions/SubscriptionHabboClub.java | 9 +- .../subscriptions/SubscriptionManager.java | 3 +- .../rooms/items/UseFurnitureEvent.java | 2 +- .../rooms/pets/OpenPetPackageEvent.java | 2 +- .../modtool/ModeratorUserInfoComposer.java | 11 +- .../outgoing/rooms/items/ItemsComposer.java | 4 +- .../rooms/users/UserUpdateComposer.java | 4 +- .../threading/runnables/RoomUnitRidePet.java | 2 +- .../RoomUnitTeleportWalkToAction.java | 2 +- .../RoomUnitVendingMachineAction.java | 2 +- .../runnables/RoomUnitWalkToLocation.java | 2 +- .../runnables/RoomUnitWalkToRoomUnit.java | 2 +- 43 files changed, 411 insertions(+), 739 deletions(-) diff --git a/pom.xml b/pom.xml index 29df7372..c6481300 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,6 @@ 19 19 - --enable-preview diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java b/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java index 1e8b91b4..ed58bbfa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.bots; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; @@ -82,7 +83,7 @@ public class Bot implements Runnable { this.motto = set.getString("motto"); this.figure = set.getString("figure"); this.gender = HabboGender.valueOf(set.getString("gender")); - this.ownerId = set.getInt("user_id"); + this.ownerId = set.getInt(DatabaseConstants.USER_ID); this.ownerName = set.getString("owner_name"); this.chatAuto = set.getString("chat_auto").equals("1"); this.chatRandom = set.getString("chat_random").equals("1"); diff --git a/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarRewardClaimed.java b/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarRewardClaimed.java index e136d339..56ee00f5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarRewardClaimed.java +++ b/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarRewardClaimed.java @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.campaign; +import com.eu.habbo.database.DatabaseConstants; import lombok.AllArgsConstructor; import lombok.Getter; @@ -17,7 +18,7 @@ public class CalendarRewardClaimed { private final Timestamp timestamp; public CalendarRewardClaimed(ResultSet set) throws SQLException { - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.campaignId = set.getInt("campaign_id"); this.day = set.getInt("day"); this.rewardId = set.getInt("reward_id"); diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java index 1b3a2409..e124d481 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.catalog; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.catalog.layouts.*; @@ -249,7 +250,7 @@ public class CatalogManager { totals.adjustOrPutValue(set.getInt("catalog_item_id"), 1, 1); - if (set.getInt("user_id") == 0) { + if (set.getInt(DatabaseConstants.USER_ID) == 0) { limiteds.get(set.getInt("catalog_item_id")).push(set.getInt("number")); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/VoucherHistoryEntry.java b/src/main/java/com/eu/habbo/habbohotel/catalog/VoucherHistoryEntry.java index 9e69ccc1..9d3fd498 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/VoucherHistoryEntry.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/VoucherHistoryEntry.java @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.catalog; +import com.eu.habbo.database.DatabaseConstants; import lombok.AllArgsConstructor; import lombok.Getter; @@ -17,7 +18,7 @@ public class VoucherHistoryEntry { public VoucherHistoryEntry(ResultSet set) throws SQLException { this.voucherId = set.getInt("voucher_id"); - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.timestamp = set.getInt("timestamp"); } diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java b/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java index 2474d626..08b91d28 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.catalog.marketplace; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboItem; @@ -262,7 +263,7 @@ public class MarketPlace { updateOffer.setInt(2, offerId); updateOffer.execute(); } - Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(set.getInt("user_id")); + Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(set.getInt(DatabaseConstants.USER_ID)); HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(itemSet); MarketPlaceItemSoldEvent event = new MarketPlaceItemSoldEvent(habbo, client.getHabbo(), item, set.getInt("price")); diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/Guild.java b/src/main/java/com/eu/habbo/habbohotel/guilds/Guild.java index 4a8d7cf9..045c96e1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/Guild.java +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/Guild.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.guilds; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -65,7 +66,7 @@ public class Guild implements Runnable { public Guild(ResultSet set) throws SQLException { this.id = set.getInt("id"); - this.ownerId = set.getInt("user_id"); + this.ownerId = set.getInt(DatabaseConstants.USER_ID); this.ownerName = set.getString("username"); this.name = set.getString("name"); this.description = set.getString("description"); diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java b/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java index d23dfc5b..06827a70 100644 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.guilds; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.guilds.forums.ForumView; import com.eu.habbo.habbohotel.items.interactions.InteractionGuildFurni; @@ -433,7 +434,7 @@ public class GuildManager { statement.setInt(1, guild.getId()); try (ResultSet set = statement.executeQuery()) { while (set.next()) { - guildAdmins.put(set.getInt("user_id"), new GuildMember(set)); + guildAdmins.put(set.getInt(DatabaseConstants.USER_ID), new GuildMember(set)); } } } catch (SQLException e) { diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/GuildMember.java b/src/main/java/com/eu/habbo/habbohotel/guilds/GuildMember.java index 143aaa6a..5e743608 100644 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/GuildMember.java +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/GuildMember.java @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.guilds; +import com.eu.habbo.database.DatabaseConstants; import lombok.Getter; import lombok.Setter; @@ -22,7 +23,7 @@ public class GuildMember implements Comparable { private GuildRank rank; public GuildMember(ResultSet set) throws SQLException { - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.username = set.getString("username"); this.look = set.getString("look"); this.joinDate = set.getInt("member_since"); diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadComment.java b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadComment.java index 9cfd6b93..692e9f9a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadComment.java +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadComment.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.guilds.forums; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ISerialize; @@ -50,7 +51,7 @@ public class ForumThreadComment implements Runnable, ISerialize { public ForumThreadComment(ResultSet set) throws SQLException { this.commentId = set.getInt("id"); this.threadId = set.getInt("thread_id"); - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.message = set.getString("message"); this.createdAt = set.getInt("created_at"); this.state = ForumThreadState.fromValue(set.getInt("state")); diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumView.java b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumView.java index 66dba2ef..f3d30173 100644 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumView.java +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumView.java @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.guilds.forums; +import com.eu.habbo.database.DatabaseConstants; import lombok.AllArgsConstructor; import lombok.Getter; @@ -16,7 +17,7 @@ public class ForumView { private final int timestamp; public ForumView(ResultSet set) throws SQLException { - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.guildId = set.getInt("guild_id"); this.timestamp = set.getInt("timestamp"); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java index 04cadffc..972ea6e8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java @@ -80,7 +80,7 @@ public class InteractionMultiHeight extends HabboItem { Collection unitsOnItem = room.getRoomUnitsAt(room.getLayout().getTile(tile.getX(), tile.getY())); for (RoomUnit unit : unitsOnItem) { - if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoal() != tile) + if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoalLocation() != tile) continue; if (this.getBaseItem().allowSit() || unit.hasStatus(RoomUnitStatus.SIT)) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java index 1a894f80..008370b8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java @@ -83,7 +83,7 @@ public abstract class InteractionPushable extends InteractionDefault { boolean isDrag = false; RoomUserRotation direction; - if (this.getX() == roomUnit.getGoal().getX() && this.getY() == roomUnit.getGoal().getY()) //User clicked on the tile the ball is on, they want to kick it + if (this.getX() == roomUnit.getGoalLocation().getX() && this.getY() == roomUnit.getGoalLocation().getY()) //User clicked on the tile the ball is on, they want to kick it { velocity = this.getWalkOnVelocity(roomUnit, room); direction = this.getWalkOnDirection(roomUnit, room); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java index cd80544e..e3e6e314 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java @@ -69,7 +69,7 @@ public class InteractionFootball extends InteractionPushable { @Override public RoomUserRotation getWalkOffDirection(RoomUnit roomUnit, Room room) { RoomTile peek = roomUnit.getPath().peek(); - RoomTile nextWalkTile = peek != null ? room.getLayout().getTile(peek.getX(), peek.getY()) : roomUnit.getGoal(); + RoomTile nextWalkTile = peek != null ? room.getLayout().getTile(peek.getX(), peek.getY()) : roomUnit.getGoalLocation(); return RoomUserRotation.values()[(RoomUserRotation.values().length + Rotation.Calculate(roomUnit.getX(), roomUnit.getY(), nextWalkTile.getX(), nextWalkTile.getY()) + 4) % 8]; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetBreedingNest.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetBreedingNest.java index 84c4da58..ef3380f6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetBreedingNest.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetBreedingNest.java @@ -154,7 +154,7 @@ public class InteractionPetBreedingNest extends HabboItem { Pet offspring = Emulator.getGameEnvironment().getPetManager().createPet(petOne.getPetData().getOffspringType(), (int) Math.min(Math.round(Math.max(1d, PetManager.getNormalDistributionForBreeding(petOne.getLevel(), petTwo.getLevel()).sample())), 20), name, habbo.getClient()); //habbo.getClient().sendResponse(new PetPackageNameValidationComposer(box.getId(), PetPackageNameValidationComposer.CLOSE_WIDGET, "")); - habbo.getHabboInfo().getCurrentRoom().placePet(offspring, box.getX(), box.getY(), box.getZ(), box.getRotation()); + habbo.getHabboInfo().getCurrentRoom().placePet(offspring, box.getX(), box.getY(), box.getZ()); offspring.needsUpdate = true; offspring.run(); InteractionPetBreedingNest.this.freePets(); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetToy.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetToy.java index f427e465..15981803 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetToy.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetToy.java @@ -52,7 +52,7 @@ public class InteractionPetToy extends InteractionDefault { Pet pet = room.getPet(roomUnit); - if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoal())) { + if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoalLocation())) { if (pet.getEnergy() <= 35) { return; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTrampoline.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTrampoline.java index 122ba764..53f3e838 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTrampoline.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTrampoline.java @@ -53,7 +53,7 @@ public class InteractionPetTrampoline extends InteractionDefault { Pet pet = room.getPet(roomUnit); - if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoal())) { + if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoalLocation())) { if (pet.getEnergy() <= 35) { return; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTree.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTree.java index f50ac58d..d312b814 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTree.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTree.java @@ -39,7 +39,7 @@ public class InteractionPetTree extends InteractionDefault { super.onWalkOn(roomUnit, room, objects); Pet pet = room.getPet(roomUnit); - if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoal())) { + if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoalLocation())) { RoomUnitStatus task = switch (pet.getTask()) { case RING_OF_FIRE -> RoomUnitStatus.RINGOFFIRE; case SWING -> RoomUnitStatus.SWING; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java index 733718d2..c0383efb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java @@ -271,7 +271,8 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { case ACTION_TURN_RIGHT_45 -> RoomUserRotation.clockwise(currentRotation); case ACTION_TURN_RIGHT_90 -> RoomUserRotation.clockwise(RoomUserRotation.clockwise(currentRotation)); case ACTION_TURN_RANDOM -> RoomUserRotation.fromValue(Emulator.getRandom().nextInt(8)); - case ACTION_WAIT, default -> currentRotation; + case ACTION_WAIT -> currentRotation; + default -> currentRotation; }; } diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolBan.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolBan.java index af80afab..492c58f6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolBan.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolBan.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -28,7 +29,7 @@ public class ModToolBan implements Runnable { private final boolean needsInsert; public ModToolBan(ResultSet set) throws SQLException { - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.ip = set.getString("ip"); this.machineId = set.getString("machine_id"); this.staffId = set.getInt("user_staff_id"); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java b/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java index 5b79f107..1279e063 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java @@ -167,7 +167,7 @@ public class MonsterplantPet extends Pet implements IPetLook { if (difference >= growTime) { this.growthStage = 7; boolean clear = false; - for (RoomUnitStatus s : this.roomUnit.getStatusMap().keySet()) { + for (RoomUnitStatus s : this.roomUnit.getStatus().keySet()) { if (s.equals(RoomUnitStatus.GROW)) { clear = true; break; diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java index c61d6c8f..9b453dff 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.pets; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.users.Habbo; @@ -138,7 +139,7 @@ public class Pet implements ISerialize, Runnable { public Pet(ResultSet set) throws SQLException { super(); this.id = set.getInt("id"); - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.room = null; this.name = set.getString("name"); this.petData = Emulator.getGameEnvironment().getPetManager().getPetData(set.getInt("type")); diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index f52e7771..49b4b31a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.bots.VisitorBot; @@ -84,6 +85,8 @@ import java.util.stream.Collectors; @Slf4j public class Room implements Comparable, ISerialize, Runnable { + private static final String CAUGHT_SQL_EXCEPTION = "Caught SQL exception"; + private static final String CAUGHT_EXCEPTION = "Caught exception"; public static final Comparator SORT_SCORE = (o1, o2) -> o2.getScore() - o1.getScore(); public static final Comparator SORT_ID = (o1, o2) -> o2.getId() - o1.getId(); @@ -102,6 +105,7 @@ public class Room implements Comparable, ISerialize, Runnable { public static boolean MUTEAREA_CAN_WHISPER = false; public static final double MAXIMUM_FURNI_HEIGHT = 40d; + static { for (int i = 1; i <= 3; i++) { RoomMoodlightData data = RoomMoodlightData.fromString(""); @@ -141,13 +145,17 @@ public class Room implements Comparable, ISerialize, Runnable { //Use appropriately. Could potentially cause memory leaks when used incorrectly. public volatile boolean preventUnloading = false; public volatile boolean preventUncaching = false; - public final ConcurrentSet scheduledComposers = new ConcurrentSet<>(); - public ConcurrentSet scheduledTasks = new ConcurrentSet<>(); - public String wordQuiz = ""; - public int noVotes = 0; - public int yesVotes = 0; - public int wordQuizEnd = 0; - public ScheduledFuture roomCycleTask; + public final ConcurrentHashMap.KeySetView scheduledComposers = ConcurrentHashMap.newKeySet(); + public ConcurrentHashMap.KeySetView scheduledTasks = ConcurrentHashMap.newKeySet(); + @Getter + private String wordQuiz = ""; + @Getter + private int noVotes = 0; + @Getter + private int yesVotes = 0; + @Getter + private int wordQuizEnd = 0; + public ScheduledFuture roomCycleTask; @Getter private final int id; @Getter @@ -347,7 +355,7 @@ public class Room implements Comparable, ISerialize, Runnable { this.loadBans(connection); } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } this.tradeMode = set.getInt("trade_mode"); @@ -392,60 +400,21 @@ public class Room implements Comparable, ISerialize, Runnable { this.roomSpecialTypes = new RoomSpecialTypes(); - try { - this.loadLayout(); - } catch (Exception e) { - log.error("Caught exception", e); - } - - try { - this.loadRights(connection); - } catch (Exception e) { - log.error("Caught exception", e); - } - - try { - this.loadItems(connection); - } catch (Exception e) { - log.error("Caught exception", e); - } - - try { - this.loadHeightmap(); - } catch (Exception e) { - log.error("Caught exception", e); - } - - try { - this.loadBots(connection); - } catch (Exception e) { - log.error("Caught exception", e); - } - - try { - this.loadPets(connection); - } catch (Exception e) { - log.error("Caught exception", e); - } - - try { - this.loadWordFilter(connection); - } catch (Exception e) { - log.error("Caught exception", e); - } - - try { - this.loadWiredData(connection); - } catch (Exception e) { - log.error("Caught exception", e); - } + this.loadLayout(); + this.loadRights(connection); + this.loadItems(connection); + this.loadHeightmap(); + this.loadBots(connection); + this.loadPets(connection); + this.loadWordFilter(connection); + this.loadWiredData(connection); this.idleCycles = 0; this.loaded = true; this.roomCycleTask = Emulator.getThreading().getService().scheduleAtFixedRate(this, 500, 500, TimeUnit.MILLISECONDS); } catch (Exception e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); } this.traxManager = new TraxManager(this); @@ -453,14 +422,12 @@ public class Room implements Comparable, ISerialize, Runnable { if (this.jukeboxActive) { this.traxManager.play(0); for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionJukeBox.class)) { - item.setExtradata("1"); - this.updateItem(item); + this.updateItem(item.setExtradata("1")); } } for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionFireworks.class)) { - item.setExtradata("1"); - this.updateItem(item); + this.updateItem(item.setExtradata("1")); } } @@ -468,27 +435,35 @@ public class Room implements Comparable, ISerialize, Runnable { } 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); + try { + if (this.layout == null) { + if (this.overrideModel) { + this.layout = Emulator.getGameEnvironment().getRoomManager().loadCustomLayout(this); + } else { + this.layout = Emulator.getGameEnvironment().getRoomManager().loadLayout(this.layoutName, this); + } } + } catch (Exception e) { + log.error(CAUGHT_EXCEPTION, e); } } 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); + try { + 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 { + log.error("Unknown Room Layout for Room (ID: {})", this.id); } - } else { - log.error("Unknown Room Layout for Room (ID: {})", this.id); + } catch (Exception e) { + log.error(CAUGHT_EXCEPTION, e); } } @@ -503,7 +478,9 @@ public class Room implements Comparable, ISerialize, Runnable { } } } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); + } catch (Exception e) { + log.error(CAUGHT_EXCEPTION, e); } if (this.itemCount() > Room.MAXIMUM_FURNI) { @@ -520,18 +497,18 @@ public class Room implements Comparable, ISerialize, Runnable { try { HabboItem item = this.getHabboItem(set.getInt("id")); - if (item instanceof InteractionWired) { - ((InteractionWired) item).loadWiredData(set, this); + if (item instanceof InteractionWired interactionWired) { + interactionWired.loadWiredData(set, this); } } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } } } } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } catch (Exception e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); } } @@ -560,7 +537,6 @@ public class Room implements Comparable, ISerialize, Runnable { } 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); @@ -568,43 +544,45 @@ public class Room implements Comparable, ISerialize, Runnable { } } } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); + } catch (Exception e) { + log.error(CAUGHT_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().getCurrentLocation().getState() == RoomTileState.INVALID) { - pet.getRoomUnit().setZ(this.getLayout().getDoorTile().getStackHeight()); - 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) { - log.error("Caught SQL exception", e); + 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().getCurrentLocation().getState() == RoomTileState.INVALID) { + pet.getRoomUnit().setZ(this.getLayout().getDoorTile().getStackHeight()); + 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) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); + } catch (Exception e) { + log.error(CAUGHT_EXCEPTION, e); } } @@ -619,7 +597,9 @@ public class Room implements Comparable, ISerialize, Runnable { } } } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); + } catch (Exception e) { + log.error(CAUGHT_EXCEPTION, e); } } @@ -649,8 +629,6 @@ public class Room implements Comparable, ISerialize, Runnable { 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; @@ -664,34 +642,13 @@ public class Room implements Comparable, ISerialize, Runnable { 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; } @@ -700,13 +657,9 @@ public class Room implements Comparable, ISerialize, Runnable { if (item.isWalkable()) { result = RoomTileState.OPEN; - } - - if (item.getBaseItem().allowSit()) { + } else if (item.getBaseItem().allowSit()) { result = RoomTileState.SIT; - } - - if (item.getBaseItem().allowLay()) { + } else if (item.getBaseItem().allowLay()) { result = RoomTileState.LAY; } @@ -726,10 +679,8 @@ public class Room implements Comparable, ISerialize, Runnable { 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; - } + if ((walkable && tile != null) && (tile.hasUnits() && !this.allowWalkthrough)) { + walkable = false; } return walkable; @@ -771,10 +722,10 @@ public class Room implements Comparable, ISerialize, Runnable { } this.sendComposer(new HeightMapUpdateMessageComposer(this, updatedTiles).compose()); this.updateTiles(updatedTiles); - for (RoomTile tile : updatedTiles) { + updatedTiles.forEach(tile -> { this.updateHabbosAt(tile.getX(), tile.getY()); this.updateBotsAt(tile.getX(), tile.getY()); - } + }); } else if (item.getBaseItem().getType() == FurnitureType.WALL) { this.sendComposer(new ItemRemoveMessageComposer(item).compose()); } @@ -833,7 +784,7 @@ public class Room implements Comparable, ISerialize, Runnable { this.updateHabbosAt(x, y, this.getHabbosAt(x, y)); } - public void updateHabbosAt(short x, short y, THashSet habbos) { + public void updateHabbosAt(short x, short y, List habbos) { HabboItem item = this.getTopItemAt(x, y); for (Habbo habbo : habbos) { @@ -864,13 +815,8 @@ public class Room implements Comparable, ISerialize, Runnable { 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) { @@ -878,7 +824,7 @@ public class Room implements Comparable, ISerialize, Runnable { THashSet roomUnits = new THashSet<>(); - for (Bot bot : this.getBotsAt(this.layout.getTile(x, y))) { + this.getBotsAt(this.layout.getTile(x, y)).forEach(bot -> { if (topItem != null) { if (topItem.getBaseItem().allowSit()) { bot.getRoomUnit().setZ(topItem.getZ()); @@ -895,9 +841,8 @@ public class Room implements Comparable, ISerialize, Runnable { bot.getRoomUnit().setZ(bot.getRoomUnit().getCurrentLocation().getStackHeight()); bot.getRoomUnit().setPreviousLocationZ(bot.getRoomUnit().getCurrentLocation().getStackHeight()); } - roomUnits.add(bot.getRoomUnit()); - } + }); if (!roomUnits.isEmpty()) { this.sendComposer(new UserUpdateComposer(roomUnits, true).compose()); @@ -992,6 +937,7 @@ public class Room implements Comparable, ISerialize, Runnable { synchronized (this.roomItems) { TIntObjectIterator iterator = this.roomItems.iterator(); + for (int i = this.roomItems.size(); i-- > 0; ) { try { iterator.advance(); @@ -1034,7 +980,7 @@ public class Room implements Comparable, ISerialize, Runnable { botIterator.value().needsUpdate(true); Emulator.getThreading().run(botIterator.value()); } catch (NoSuchElementException e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); break; } } @@ -1042,7 +988,7 @@ public class Room implements Comparable, ISerialize, Runnable { this.currentBots.clear(); this.currentPets.clear(); } catch (Exception e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); } } @@ -1054,7 +1000,7 @@ public class Room implements Comparable, ISerialize, Runnable { this.preLoaded = true; this.layout = null; } catch (Exception e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); } } @@ -1143,7 +1089,7 @@ public class Room implements Comparable, ISerialize, Runnable { Emulator.getThreading().run( Room.this::cycle); } catch (Exception e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); } } } @@ -1206,7 +1152,7 @@ public class Room implements Comparable, ISerialize, Runnable { statement.executeUpdate(); this.needsUpdate = false; } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } } } @@ -1217,7 +1163,7 @@ public class Room implements Comparable, ISerialize, Runnable { statement.setInt(2, this.id); statement.executeUpdate(); } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } } @@ -1234,8 +1180,8 @@ public class Room implements Comparable, ISerialize, Runnable { this.tileCache.clear(); if (loaded) { if (!this.scheduledTasks.isEmpty()) { - ConcurrentSet tasks = this.scheduledTasks; - this.scheduledTasks = new ConcurrentSet<>(); + ConcurrentHashMap.KeySetView tasks = this.scheduledTasks; + this.scheduledTasks = ConcurrentHashMap.newKeySet(); for (Runnable runnable : tasks) { Emulator.getThreading().run(runnable); @@ -1303,16 +1249,13 @@ public class Room implements Comparable, ISerialize, Runnable { } } - if (Emulator.getConfig().getBoolean("hotel.rooms.deco_hosting")) { - //Check if the user isn't the owner id - if (this.ownerId != habbo.getHabboInfo().getId()) { - //Check if the time already have 1 minute (120 / 2 = 60s) - if (habbo.getRoomUnit().getTimeInRoom() >= 120) { - AchievementManager.progressAchievement(this.ownerId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting")); - habbo.getRoomUnit().resetTimeInRoom(); - } else { - habbo.getRoomUnit().increaseTimeInRoom(); - } + if (Emulator.getConfig().getBoolean("hotel.rooms.deco_hosting") && this.ownerId != habbo.getHabboInfo().getId()) { + //Check if the time already have 1 minute (120 / 2 = 60s) + if (habbo.getRoomUnit().getTimeInRoom() >= 120) { + AchievementManager.progressAchievement(this.ownerId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting")); + habbo.getRoomUnit().resetTimeInRoom(); + } else { + habbo.getRoomUnit().increaseTimeInRoom(); } } @@ -1364,43 +1307,42 @@ public class Room implements Comparable, ISerialize, Runnable { } catch (NoSuchElementException e) { - log.error("Caught exception", e); + log.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) { - log.error("Caught exception", e); - break; - } + if (!this.currentPets.isEmpty() && this.allowBotsWalk) { + TIntObjectIterator petIterator = this.currentPets.iterator(); + for (int i = this.currentPets.size(); i-- > 0; ) { + try { + petIterator.advance(); + } catch (NoSuchElementException e) { + log.error(CAUGHT_EXCEPTION, e); + break; + } - Pet pet = petIterator.value(); - if (this.cycleRoomUnit(pet.getRoomUnit())) { - updatedUnit.add(pet.getRoomUnit()); - } + Pet pet = petIterator.value(); + if (this.cycleRoomUnit(pet.getRoomUnit())) { + updatedUnit.add(pet.getRoomUnit()); + } - pet.cycle(); + pet.cycle(); - if (pet.packetUpdate) { - updatedUnit.add(pet.getRoomUnit()); - pet.packetUpdate = false; - } + 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()); - } + if (pet.getRoomUnit().isWalking() && pet.getRoomUnit().getPath().size() == 1 && pet.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) { + pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); + updatedUnit.add(pet.getRoomUnit()); } } } + if (this.rollerSpeed != -1 && this.rollerCycle >= this.rollerSpeed) { this.rollerCycle = 0; @@ -1429,7 +1371,6 @@ public class Room implements Comparable, ISerialize, Runnable { } } - // itemsOnRoller.addAll(this.getItemsAt(rollerTile)); itemsOnRoller.remove(roller); if (!rollerTile.hasUnits() && itemsOnRoller.isEmpty()) @@ -1509,7 +1450,7 @@ public class Room implements Comparable, ISerialize, Runnable { for (RoomUnit unit : rollerTile.getUnits()) { if (unit.getRoomUnitType() == RoomUnitType.PET) { Pet pet = this.getPet(unit); - if (pet instanceof RideablePet && ((RideablePet) pet).getRider() != null) { + if (pet instanceof RideablePet rideablePet && rideablePet.getRider() != null) { unitsOnTile.remove(unit); } } @@ -1529,10 +1470,9 @@ public class Room implements Comparable, ISerialize, Runnable { continue; double newZ = unit.getZ() + zOffset; - RoomTile tile = tileInFront; if (roomUserRolledEvent != null && unit.getRoomUnitType() == RoomUnitType.USER) { - roomUserRolledEvent = new UserRolledEvent(getHabbo(unit), roller, tile); + roomUserRolledEvent = new UserRolledEvent(getHabbo(unit), roller, tileInFront); Emulator.getPluginManager().fireEvent(roomUserRolledEvent); if (roomUserRolledEvent.isCancelled()) @@ -1550,7 +1490,7 @@ public class Room implements Comparable, ISerialize, Runnable { newZ = ridingUnit.getZ() + zOffset; rolledUnitIds.add(ridingUnit.getId()); updatedUnit.remove(ridingUnit); - messages.add(new RoomUnitOnRollerComposer(ridingUnit, roller, ridingUnit.getCurrentLocation(), ridingUnit.getZ(), tile, newZ, room)); + messages.add(new RoomUnitOnRollerComposer(ridingUnit, roller, ridingUnit.getCurrentLocation(), ridingUnit.getZ(), tileInFront, newZ, room)); isRiding = true; } } @@ -1559,18 +1499,18 @@ public class Room implements Comparable, ISerialize, Runnable { 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, newZ + (isRiding ? 1 : 0), room)); + messages.add(new RoomUnitOnRollerComposer(unit, roller, unit.getCurrentLocation(), unit.getZ() + (isRiding ? 1 : 0), tileInFront, newZ + (isRiding ? 1 : 0), room)); if (itemsOnRoller.isEmpty()) { HabboItem item = room.getTopItemAt(tileInFront.getX(), tileInFront.getY()); if (item != null && itemsNewTile.contains(item) && !itemsOnRoller.contains(item)) { Emulator.getThreading().run(() -> { - if (unit.getGoal() == rollerTile) { + if (unit.getGoalLocation() == rollerTile) { try { item.onWalkOn(unit, room, new Object[]{rollerTile, tileInFront}); } catch (Exception e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); } } }, this.getRollerSpeed() == 0 ? 250 : InteractionRoller.DELAY); @@ -1599,22 +1539,20 @@ public class Room implements Comparable, ISerialize, Runnable { if (newRoller == null || topItem == newRoller) { List sortedItems = new ArrayList<>(itemsOnRoller); - sortedItems.sort((o1, o2) -> o1.getZ() > o2.getZ() ? -1 : 1); + sortedItems.sort((o1, o2) -> Double.compare(o2.getZ(), o1.getZ())); 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 ((item.getX() == roller.getX() && item.getY() == roller.getY() && zOffset <= 0) && (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 (furnitureRolledEvent.isCancelled()) + continue; } + + messages.add(new FloorItemOnRollerComposer(item, roller, tileInFront, zOffset, room)); + rollerFurniIds.add(item.getId()); } } } @@ -1634,11 +1572,8 @@ public class Room implements Comparable, ISerialize, Runnable { 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); - } + if (pyramid instanceof InteractionPyramid interactionPyramid && interactionPyramid.getNextChange() < currentTime) { + interactionPyramid.change(this); } } } else { @@ -1662,12 +1597,9 @@ public class Room implements Comparable, ISerialize, Runnable { synchronized (this.habboQueue) { if (!this.habboQueue.isEmpty() && !foundRightHolder[0]) { this.habboQueue.forEachEntry((a, b) -> { - if (b.isOnline()) { - if (b.getHabboInfo().getRoomQueueId() == Room.this.getId()) { - b.getClient().sendResponse(new FlatAccessDeniedMessageComposer("")); - } + if (b.isOnline() && b.getHabboInfo().getRoomQueueId() == Room.this.getId()) { + b.getClient().sendResponse(new FlatAccessDeniedMessageComposer("")); } - return true; }); @@ -1714,7 +1646,6 @@ public class Room implements Comparable, ISerialize, Runnable { } } else if (thisTile.getState() == 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()]); @@ -1739,10 +1670,8 @@ public class Room implements Comparable, ISerialize, Runnable { 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; } @@ -1841,10 +1770,9 @@ public class Room implements Comparable, ISerialize, Runnable { 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])); - } + if (extraData.length == 4 && extraData[0].equalsIgnoreCase("1")) { + return Color.getHSBColor(Integer.parseInt(extraData[1]), Integer.parseInt(extraData[2]), Integer.parseInt(extraData[3])); + } } } catch (Exception ignored) { @@ -1874,7 +1802,7 @@ public class Room implements Comparable, ISerialize, Runnable { } } catch (NoSuchElementException e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); break; } } @@ -1950,7 +1878,7 @@ public class Room implements Comparable, ISerialize, Runnable { statement.setInt(10, this.promotion.getCategory()); statement.execute(); } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } this.needsUpdate = true; @@ -2024,7 +1952,7 @@ public class Room implements Comparable, ISerialize, Runnable { return this.habboQueue.remove(habbo.getHabboInfo().getId()) != null; } } catch (Exception e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); } return true; @@ -2064,34 +1992,34 @@ public class Room implements Comparable, ISerialize, Runnable { 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 InteractionPetToy) { - this.roomSpecialTypes.addPetToy((InteractionPetToy) item); + if (item instanceof InteractionWiredTrigger interactionWiredTrigger) { + this.roomSpecialTypes.addTrigger(interactionWiredTrigger); + } else if (item instanceof InteractionWiredEffect interactionWiredEffect) { + this.roomSpecialTypes.addEffect(interactionWiredEffect); + } else if (item instanceof InteractionWiredCondition interactionWiredCondition) { + this.roomSpecialTypes.addCondition(interactionWiredCondition); + } else if (item instanceof InteractionWiredExtra interactionWiredExtra) { + this.roomSpecialTypes.addExtra(interactionWiredExtra); + } else if (item instanceof InteractionBattleBanzaiTeleporter interactionBattleBanzaiTeleporter) { + this.roomSpecialTypes.addBanzaiTeleporter(interactionBattleBanzaiTeleporter); + } else if (item instanceof InteractionRoller interactionRoller) { + this.roomSpecialTypes.addRoller(interactionRoller); + } else if (item instanceof InteractionGameScoreboard interactionGameScoreboard) { + this.roomSpecialTypes.addGameScoreboard(interactionGameScoreboard); + } else if (item instanceof InteractionGameGate interactionGameGate) { + this.roomSpecialTypes.addGameGate(interactionGameGate); + } else if (item instanceof InteractionGameTimer interactionGameTimer) { + this.roomSpecialTypes.addGameTimer(interactionGameTimer); + } else if (item instanceof InteractionFreezeExitTile interactionFreezeExitTile) { + this.roomSpecialTypes.addFreezeExitTile(interactionFreezeExitTile); + } else if (item instanceof InteractionNest interactionNest) { + this.roomSpecialTypes.addNest(interactionNest); + } else if (item instanceof InteractionPetDrink interactionPetDrink) { + this.roomSpecialTypes.addPetDrink(interactionPetDrink); + } else if (item instanceof InteractionPetFood interactionPetFood) { + this.roomSpecialTypes.addPetFood(interactionPetFood); + } else if (item instanceof InteractionPetToy interactionPetToy) { + this.roomSpecialTypes.addPetToy(interactionPetToy); } else if (item instanceof InteractionPetTree) { this.roomSpecialTypes.addUndefined(item); } else if (item instanceof InteractionPetTrampoline) { @@ -2295,63 +2223,16 @@ public class Room implements Comparable, ISerialize, Runnable { } } - 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 List getFloorItems() { + return roomItems.valueCollection().stream().filter(i -> i.getBaseItem().getType() == FurnitureType.FLOOR).toList(); } - 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 List getWallItems() { + return roomItems.valueCollection().stream().filter(i -> i.getBaseItem().getType() == FurnitureType.WALL).toList(); } - 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 List getPostItNotes() { + return roomItems.valueCollection().stream().filter(i -> i.getBaseItem().getInteractionType().getType() == InteractionPostIt.class).toList(); } public void addHabbo(Habbo habbo) { @@ -2401,15 +2282,13 @@ public class Room implements Comparable, ISerialize, Runnable { try { item.onWalkOff(habbo.getRoomUnit(), this, new Object[]{}); } catch (Exception e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); } } } - if (habbo.getHabboInfo().getCurrentGame() != null) { - if (this.getGame(habbo.getHabboInfo().getCurrentGame()) != null) { - this.getGame(habbo.getHabboInfo().getCurrentGame()).removeHabbo(habbo); - } + if (habbo.getHabboInfo().getCurrentGame() != null && this.getGame(habbo.getHabboInfo().getCurrentGame()) != null) { + this.getGame(habbo.getHabboInfo().getCurrentGame()).removeHabbo(habbo); } RoomTrade trade = this.getActiveTradeForHabbo(habbo); @@ -2451,65 +2330,20 @@ public class Room implements Comparable, ISerialize, Runnable { } 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) { - log.error("Caught exception", e); - break; - } - - if (iterator.value().getRoomUnit() == roomUnit) - return iterator.value(); - } - } - - return null; + return getBot(roomUnit.getId()); } 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) { - log.error("Caught exception", e); - break; - } - - if (iterator.value().getRoomUnit().getId() == id) - return iterator.value(); - } + return currentBots.valueCollection().stream().filter(b -> b.getRoomUnit().getId() == id).findFirst().orElse(null); } - - return null; } public List getBots(String name) { - List bots = new ArrayList<>(); - synchronized (this.currentBots) { - TIntObjectIterator iterator = this.currentBots.iterator(); + return currentBots.valueCollection().stream().filter(b -> b.getName().equalsIgnoreCase(name)).toList(); - for (int i = this.currentBots.size(); i-- > 0; ) { - try { - iterator.advance(); - } catch (NoSuchElementException e) { - log.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) { @@ -2534,21 +2368,7 @@ public class Room implements Comparable, ISerialize, Runnable { } public Pet getPet(RoomUnit roomUnit) { - TIntObjectIterator petIterator = this.currentPets.iterator(); - - for (int i = this.currentPets.size(); i-- > 0; ) { - try { - petIterator.advance(); - } catch (NoSuchElementException e) { - log.error("Caught exception", e); - break; - } - - if (petIterator.value().getRoomUnit() == roomUnit) - return petIterator.value(); - } - - return null; + return currentPets.valueCollection().stream().filter(p -> p.getRoomUnit() == roomUnit).findFirst().orElse(null); } public boolean removeBot(Bot bot) { @@ -2570,7 +2390,7 @@ public class Room implements Comparable, ISerialize, Runnable { return false; } - public void placePet(Pet pet, short x, short y, double z, int rot) { + public void placePet(Pet pet, short x, short y, double z) { synchronized (this.currentPets) { RoomTile tile = this.layout.getTile(x, y); @@ -2580,16 +2400,19 @@ public class Room implements Comparable, ISerialize, Runnable { pet.setRoomUnit(new RoomUnit()); pet.setRoom(this); - pet.getRoomUnit().setGoalLocation(tile); - pet.getRoomUnit().setLocation(tile); - pet.getRoomUnit().setRoomUnitType(RoomUnitType.PET); - pet.getRoomUnit().setCanWalk(true); - pet.getRoomUnit().setPathFinderRoom(this); - pet.getRoomUnit().setPreviousLocationZ(z); - pet.getRoomUnit().setZ(z); + pet.getRoomUnit() + .setGoalLocation(tile) + .setLocation(tile) + .setRoomUnitType(RoomUnitType.PET) + .setCanWalk(true) + .setPathFinderRoom(this) + .setPreviousLocationZ(z) + .setZ(z); + if (pet.getRoomUnit().getCurrentLocation() == null) { - pet.getRoomUnit().setLocation(this.getLayout().getDoorTile()); - pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection())); + pet.getRoomUnit() + .setLocation(this.getLayout().getDoorTile()) + .setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection())); } pet.needsUpdate = true; @@ -2604,88 +2427,33 @@ public class Room implements Comparable, ISerialize, Runnable { } 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; + return getHabbos().stream().anyMatch(h -> h.getRoomUnit().getX() == x && h.getRoomUnit().getY() == y); } 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) { - log.error("Caught exception", e); - break; - } - - if (petIterator.value().getRoomUnit().getX() == x && petIterator.value().getRoomUnit().getY() == y) - return true; - } + return currentPets.valueCollection().stream().anyMatch(p -> p.getRoomUnit().getX() == x && p.getRoomUnit().getY() == y); } - - return false; } - public THashSet getPetsAt(RoomTile tile) { - THashSet pets = new THashSet<>(); + public List getPetsAt(RoomTile tile) { 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 currentPets.valueCollection().stream().filter(p -> p.getRoomUnit().getCurrentLocation().equals(tile)).toList(); } - - return pets; } - public THashSet getBotsAt(RoomTile tile) { - THashSet bots = new THashSet<>(); + public List getBotsAt(RoomTile tile) { 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 currentBots.valueCollection().stream().filter(b -> b.getRoomUnit().getCurrentLocation().equals(tile)).toList(); } - - return bots; } - public THashSet getHabbosAt(short x, short y) { + public List 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 List getHabbosAt(RoomTile tile) { + return getHabbos().stream().filter(h -> h.getRoomUnit().getCurrentLocation().equals(tile)).toList(); } public THashSet getHabbosAndBotsAt(short x, short y) { @@ -2694,14 +2462,8 @@ public class Room implements Comparable, ISerialize, Runnable { 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()); - } + list.addAll(getBotsAt(tile).stream().map(Bot::getRoomUnit).toList()); + list.addAll(getHabbosAt(tile).stream().map(Habbo::getRoomUnit).toList()); return list; } @@ -2809,8 +2571,8 @@ public class Room implements Comparable, ISerialize, Runnable { try { botIterator.advance(); - if (botIterator.value() instanceof VisitorBot) { - ((VisitorBot) botIterator.value()).onUserEnter(habbo); + if (botIterator.value() instanceof VisitorBot visitorBot) { + visitorBot.onUserEnter(habbo); break; } } catch (Exception e) { @@ -2824,7 +2586,7 @@ public class Room implements Comparable, ISerialize, Runnable { try { doorTileTopItem.onWalkOn(habbo.getRoomUnit(), this, new Object[]{}); } catch (Exception e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); } } } @@ -2856,11 +2618,10 @@ public class Room implements Comparable, ISerialize, Runnable { return; long millis = System.currentTimeMillis(); - if (HABBO_CHAT_DELAY) { - if (millis - habbo.getHabboStats().getLastChat() < 750) { - return; - } + if (HABBO_CHAT_DELAY && millis - habbo.getHabboStats().getLastChat() < 750) { + return; } + habbo.getHabboStats().setLastChat(millis); if (roomChatMessage != null && Emulator.getConfig().getBoolean("easter_eggs.enabled") && roomChatMessage.getMessage().equalsIgnoreCase("i am a pirate")) { habbo.getHabboStats().getChatCounter().addAndGet(1); @@ -2871,10 +2632,8 @@ public class Room implements Comparable, ISerialize, Runnable { UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.TALKED, false); Emulator.getPluginManager().fireEvent(event); - if (!event.isCancelled()) { - if (!event.isIdle()) { - this.unIdle(habbo); - } + if (!event.isCancelled() && !event.isIdle()) { + this.unIdle(habbo); } this.sendComposer(new UserTypingMessageComposer(habbo.getRoomUnit(), false).compose()); @@ -2890,11 +2649,9 @@ public class Room implements Comparable, ISerialize, Runnable { } } - 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 (!this.wordFilterWords.isEmpty() && !habbo.hasPermission(Permission.ACC_CHAT_NO_FILTER)) { + for (String string : this.wordFilterWords) { + roomChatMessage.setMessage(roomChatMessage.getMessage().replaceAll("(?i)" + Pattern.quote(string), "bobba")); } } @@ -2932,13 +2689,7 @@ public class Room implements Comparable, ISerialize, Runnable { final boolean hasRights = this.hasRights(habbo); if (floodRights || !hasRights) { - 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) { + if (this.chatProtection == 0 || (this.chatProtection == 1 && chatCounter > 4) || (this.chatProtection == 2 && chatCounter > 5)) { this.floodMuteHabbo(habbo, muteTime); return; } @@ -3054,7 +2805,7 @@ public class Room implements Comparable, ISerialize, Runnable { bot.onUserSay(roomChatMessage); } catch (NoSuchElementException e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); break; } } @@ -3086,7 +2837,7 @@ public class Room implements Comparable, ISerialize, Runnable { break; } catch (Exception e) { - log.error("Caught exception", e); + log.error(CAUGHT_EXCEPTION, e); } } } @@ -3116,6 +2867,7 @@ public class Room implements Comparable, ISerialize, Runnable { TIntObjectIterator iterator = this.roomItems.iterator(); + for (int i = this.roomItems.size(); i-- > 0; ) { HabboItem item; try { @@ -3128,14 +2880,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (item.getBaseItem().getType() != FurnitureType.FLOOR) continue; - boolean found = false; - for (RoomTile tile : lockedTiles) { - if (tile.getX() == item.getX() && - tile.getY() == item.getY()) { - found = true; - break; - } - } + boolean found = lockedTiles.stream().anyMatch(tile -> tile.getX() == item.getX() && tile.getY() == item.getY()); if (!found) { if (item.getRotation() == 0 || item.getRotation() == 4) { @@ -3266,7 +3011,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (tile == null) return false; - return this.getItemsAt(tile, true).size() > 0; + return !this.getItemsAt(tile, true).isEmpty(); } public HabboItem getTopItemAt(int x, int y) { @@ -3324,19 +3069,6 @@ public class Room implements Comparable, ISerialize, Runnable { 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; @@ -3394,25 +3126,19 @@ public class Room implements Comparable, ISerialize, Runnable { THashSet stackHelpers = this.getItemsAt(InteractionStackHelper.class, x, y); - if (stackHelpers.size() > 0) { - for (HabboItem item : stackHelpers) { - if (item == exclude) continue; - return calculateHeightmap ? item.getZ() * 256.0D : item.getZ(); - } + + 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); } @@ -3473,7 +3199,8 @@ public class Room implements Comparable, ISerialize, Runnable { 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())) { + if ((!topItem.isWalkable() && !topItem.getBaseItem().allowWalk()) + || (!item.getBaseItem().allowWalk() && !item.isWalkable())) { canWalk = false; } } @@ -3601,11 +3328,13 @@ public class Room implements Comparable, ISerialize, Runnable { statement.setInt(1, this.id); try (ResultSet set = statement.executeQuery()) { while (set.next()) { - this.rights.add(set.getInt("user_id")); + this.rights.add(set.getInt(DatabaseConstants.USER_ID)); } } } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); + } catch (Exception e) { + log.error(CAUGHT_EXCEPTION, e); } } @@ -3617,14 +3346,14 @@ public class Room implements Comparable, ISerialize, Runnable { statement.setInt(2, this.id); try (ResultSet set = statement.executeQuery()) { while (set.next()) { - if (this.bannedHabbos.containsKey(set.getInt("user_id"))) + if (this.bannedHabbos.containsKey(set.getInt(DatabaseConstants.USER_ID))) continue; - this.bannedHabbos.put(set.getInt("user_id"), new RoomBan(set)); + this.bannedHabbos.put(set.getInt(DatabaseConstants.USER_ID), new RoomBan(set)); } } } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } } @@ -3675,7 +3404,7 @@ public class Room implements Comparable, ISerialize, Runnable { statement.setInt(2, userId); statement.execute(); } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } } @@ -3705,14 +3434,14 @@ public class Room implements Comparable, ISerialize, Runnable { return; this.sendComposer(new FlatControllerRemovedComposer(this, userId).compose()); - + if (this.rights.remove(userId)) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_rights WHERE room_id = ? AND user_id = ?")) { statement.setInt(1, this.id); statement.setInt(2, userId); statement.execute(); } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } } @@ -3735,7 +3464,7 @@ public class Room implements Comparable, ISerialize, Runnable { statement.setInt(1, this.id); statement.execute(); } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } this.refreshRightsInRoom(); @@ -3761,10 +3490,7 @@ public class Room implements Comparable, ISerialize, Runnable { } } - if (habbo.hasPermission(Permission.ACC_ANYROOMOWNER)) { - habbo.getClient().sendResponse(new YouAreOwnerMessageComposer()); - flatCtrl = RoomRightLevels.MODERATOR; - } else if (this.isOwner(habbo)) { + if (habbo.hasPermission(Permission.ACC_ANYROOMOWNER) || this.isOwner(habbo)) { habbo.getClient().sendResponse(new YouAreOwnerMessageComposer()); flatCtrl = RoomRightLevels.MODERATOR; } else if (this.hasRights(habbo) && !this.hasGuild()) { @@ -3791,11 +3517,11 @@ public class Room implements Comparable, ISerialize, Runnable { statement.setInt(1, this.id); try (ResultSet set = statement.executeQuery()) { while (set.next()) { - rightsMap.put(set.getInt("user_id"), set.getString("username")); + rightsMap.put(set.getInt(DatabaseConstants.USER_ID), set.getString("username")); } } } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } } @@ -3863,14 +3589,17 @@ public class Room implements Comparable, ISerialize, Runnable { this.giveEffect(habbo.getRoomUnit(), effectId, duration, ignoreChecks); } } + public void giveEffect(Habbo habbo, int effectId, int duration) { if (habbo != null && habbo.getRoomUnit() != null && this.currentHabbos.containsKey(habbo.getHabboInfo().getId())) { this.giveEffect(habbo.getRoomUnit(), effectId, duration, false); } } + public void giveEffect(RoomUnit roomUnit, int effectId, int duration) { this.giveEffect(roomUnit, effectId, duration, false); } + public void giveEffect(RoomUnit roomUnit, int effectId, int duration, boolean ignoreChecks) { if (roomUnit == null || roomUnit.getRoom() == null) return; @@ -3902,18 +3631,19 @@ public class Room implements Comparable, ISerialize, Runnable { } public void updateItem(HabboItem item) { - if (this.isLoaded()) { - if (item != null && item.getRoomId() == this.id) { - if (item.getBaseItem() != null) { - if (item.getBaseItem().getType() == FurnitureType.FLOOR) { - this.sendComposer(new ObjectUpdateMessageComposer(item).compose()); - this.updateTiles(this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); - } else if (item.getBaseItem().getType() == FurnitureType.WALL) { - this.sendComposer(new ItemUpdateMessageComposer(item).compose()); - } - } + if (!this.isLoaded()) { + return; + } + + if (item != null && item.getRoomId() == this.id && item.getBaseItem() != null) { + if (item.getBaseItem().getType() == FurnitureType.FLOOR) { + this.sendComposer(new ObjectUpdateMessageComposer(item).compose()); + this.updateTiles(this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); + } else if (item.getBaseItem().getType() == FurnitureType.WALL) { + this.sendComposer(new ItemUpdateMessageComposer(item).compose()); } } + } public void updateItemState(HabboItem item) { @@ -3928,8 +3658,8 @@ public class Room implements Comparable, ISerialize, Runnable { this.updateTiles(this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); - if (item instanceof InteractionMultiHeight) { - ((InteractionMultiHeight) item).updateUnitsOnItem(this); + if (item instanceof InteractionMultiHeight interactionMultiHeight) { + interactionMultiHeight.updateUnitsOnItem(this); } } } @@ -4054,9 +3784,8 @@ public class Room implements Comparable, ISerialize, Runnable { HabboItem habboItem = iterator.value(); - if (habboItem instanceof InteractionGuildFurni) { - if (((InteractionGuildFurni) habboItem).getGuildId() == guild.getId()) - this.updateItem(habboItem); + if (habboItem instanceof InteractionGuildFurni interactionGuildFurni && interactionGuildFurni.getGuildId() == guild.getId()) { + this.updateItem(habboItem); } } } @@ -4064,15 +3793,13 @@ public class Room implements Comparable, ISerialize, Runnable { public void refreshGuildRightsInRoom() { for (Habbo habbo : this.getHabbos()) { - if (habbo.getHabboInfo().getCurrentRoom() == this) { - if (habbo.getHabboInfo().getId() != this.ownerId) { - if (!(habbo.hasPermission(Permission.ACC_ANYROOMOWNER) || habbo.hasPermission(Permission.ACC_MOVEROTATE))) - this.refreshRightsForHabbo(habbo); - } - } + if ((habbo.getHabboInfo().getCurrentRoom() == this && habbo.getHabboInfo().getId() != this.ownerId) + && (!(habbo.hasPermission(Permission.ACC_ANYROOMOWNER) || habbo.hasPermission(Permission.ACC_MOVEROTATE)))) + this.refreshRightsForHabbo(habbo); } } + public void idle(Habbo habbo) { habbo.getRoomUnit().setIdle(); @@ -4120,7 +3847,7 @@ public class Room implements Comparable, ISerialize, Runnable { statement.setString(2, word); statement.execute(); } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); return; } @@ -4137,7 +3864,7 @@ public class Room implements Comparable, ISerialize, Runnable { statement.setString(2, word); statement.execute(); } catch (SQLException e) { - log.error("Caught SQL exception", e); + log.error(CAUGHT_SQL_EXCEPTION, e); } } } @@ -4279,7 +4006,7 @@ public class Room implements Comparable, ISerialize, Runnable { } } - Optional stackHelper = this.getItemsAt(tile).stream().filter(i -> i instanceof InteractionStackHelper).findAny(); + Optional stackHelper = this.getItemsAt(tile).stream().filter(InteractionStackHelper.class::isInstance).findAny(); List>> tileFurniList = new ArrayList<>(); for (RoomTile t : occupiedTiles) { @@ -4410,7 +4137,7 @@ public class Room implements Comparable, ISerialize, Runnable { boolean magicTile = item instanceof InteractionStackHelper; - Optional stackHelper = this.getItemsAt(tile).stream().filter(i -> i instanceof InteractionStackHelper).findAny(); + Optional stackHelper = this.getItemsAt(tile).stream().filter(InteractionStackHelper.class::isInstance).findAny(); //Check if can be placed at new position THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); @@ -4428,10 +4155,13 @@ public class Room implements Comparable, ISerialize, Runnable { } if (!Emulator.getConfig().getBoolean("wired.place.under", false) || (Emulator.getConfig().getBoolean("wired.place.under", false) && !item.isWalkable() && !item.getBaseItem().allowSit())) { - if (checkForUnits) { - if (!magicTile && this.hasHabbosAt(t.getX(), t.getY())) return FurnitureMovementError.TILE_HAS_HABBOS; - if (!magicTile && this.hasBotsAt(t.getX(), t.getY())) return FurnitureMovementError.TILE_HAS_BOTS; - if (!magicTile && this.hasPetsAt(t.getX(), t.getY())) return FurnitureMovementError.TILE_HAS_PETS; + if (checkForUnits && !magicTile) { + if (this.hasHabbosAt(t.getX(), t.getY())) + return FurnitureMovementError.TILE_HAS_HABBOS; + if (this.hasBotsAt(t.getX(), t.getY())) + return FurnitureMovementError.TILE_HAS_BOTS; + if (this.hasPetsAt(t.getX(), t.getY())) + return FurnitureMovementError.TILE_HAS_PETS; } } } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomBan.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomBan.java index cd7c61c2..8260c736 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomBan.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomBan.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -22,7 +23,7 @@ public class RoomBan { public RoomBan(ResultSet set) throws SQLException { this.roomId = set.getInt("room_id"); - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.username = set.getString("username"); this.endTimestamp = set.getInt("ends"); } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java index a3f661c4..6182b671 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -68,6 +68,7 @@ public class RoomManager { public static int MAXIMUM_ROOMS_HC = 35; public static int HOME_ROOM_ID = 0; public static boolean SHOW_PUBLIC_IN_POPULAR_TAB = false; + @Getter private final THashMap roomCategories; private final List mapNames; private final ConcurrentHashMap activeRooms; @@ -151,9 +152,8 @@ public class RoomManager { public THashMap> findRooms(NavigatorFilterField filterField, String value, int category, boolean showInvisible) { THashMap> rooms = new THashMap<>(); - String query = filterField.getDatabaseQuery() + " AND rooms.state NOT LIKE " + (showInvisible ? "''" : "'invisible'") + (category >= 0 ? "AND rooms.category = '" + category + "'" : "") + " ORDER BY rooms.users, rooms.id DESC LIMIT " + (/* TODO: This is always 0?*/page * NavigatorManager.MAXIMUM_RESULTS_PER_PAGE) + "" + ((page * NavigatorManager.MAXIMUM_RESULTS_PER_PAGE) + NavigatorManager.MAXIMUM_RESULTS_PER_PAGE); + String query = filterField.getDatabaseQuery() + " AND rooms.state NOT LIKE " + (showInvisible ? "''" : "'invisible'") + (category >= 0 ? "AND rooms.category = '" + category + "'" : "") + " ORDER BY rooms.users, rooms.id DESC LIMIT " + NavigatorManager.MAXIMUM_RESULTS_PER_PAGE; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement(query)) { - statement.setString(1, (filterField.getComparator() == NavigatorFilterComparator.EQUALS ? value : "%" + value + "%")); try (ResultSet set = statement.executeQuery()) { while (set.next()) { Room room = this.activeRooms.get(set.getInt("id")); @@ -178,32 +178,15 @@ public class RoomManager { } public RoomCategory getCategory(int id) { - for (RoomCategory category : this.roomCategories.values()) { - if (category.getId() == id) - return category; - } - - return null; + return roomCategories.values().stream().filter(c -> c.getId() == id).findFirst().orElse(null); } public RoomCategory getCategory(String name) { - for (RoomCategory category : this.roomCategories.values()) { - if (category.getCaption().equalsIgnoreCase(name)) { - return category; - } - } - - return null; + return roomCategories.values().stream().filter(c -> c.getCaption().equalsIgnoreCase(name)).findFirst().orElse(null); } public RoomCategory getCategoryBySafeCaption(String safeCaption) { - for (RoomCategory category : this.roomCategories.values()) { - if (category.getCaptionSave().equalsIgnoreCase(safeCaption)) { - return category; - } - } - - return null; + return roomCategories.values().stream().filter(c -> c.getCaptionSave().equalsIgnoreCase(safeCaption)).findFirst().orElse(null); } public List roomCategoriesForHabbo(Habbo habbo) { @@ -219,19 +202,7 @@ public class RoomManager { } public boolean hasCategory(int categoryId, Habbo habbo) { - for (RoomCategory category : this.roomCategories.values()) { - if (category.getId() == categoryId) { - if (category.getMinRank() <= habbo.getHabboInfo().getRank().getId()) { - return true; - } - } - } - - return false; - } - - public THashMap getRoomCategories() { - return this.roomCategories; + return roomCategories.values().stream().anyMatch(c -> c.getId() == categoryId && c.getMinRank() <= habbo.getHabboInfo().getRank().getId()); } public List getRoomsByScore() { @@ -294,10 +265,8 @@ public class RoomManager { if (this.activeRooms.containsKey(id)) { room = this.activeRooms.get(id); - if (loadData) { - if (room.isPreLoaded() && !room.isLoaded()) { - room.loadData(); - } + if (loadData && (room.isPreLoaded() && !room.isLoaded())) { + room.loadData(); } return room; @@ -602,7 +571,8 @@ public class RoomManager { habbo.getRoomUnit().clearStatus(); if (habbo.getRoomUnit().getCurrentLocation() == null) { habbo.getRoomUnit().setLocation(doorLocation != null ? doorLocation : room.getLayout().getDoorTile()); - if (habbo.getRoomUnit().getCurrentLocation() != null) habbo.getRoomUnit().setZ(habbo.getRoomUnit().getCurrentLocation().getStackHeight()); + if (habbo.getRoomUnit().getCurrentLocation() != null) + habbo.getRoomUnit().setZ(habbo.getRoomUnit().getCurrentLocation().getStackHeight()); if (doorLocation == null) { habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); @@ -899,10 +869,10 @@ public class RoomManager { } if (room.hasActiveWordQuiz()) { - habbo.getClient().sendResponse(new QuestionComposer((Emulator.getIntUnixTimestamp() - room.wordQuizEnd) * 1000, room.wordQuiz)); + habbo.getClient().sendResponse(new QuestionComposer((Emulator.getIntUnixTimestamp() - room.getWordQuizEnd()) * 1000, room.getWordQuiz())); if (room.hasVotedInWordQuiz(habbo)) { - habbo.getClient().sendResponse(new QuestionFinishedComposer(room.noVotes, room.yesVotes)); + habbo.getClient().sendResponse(new QuestionFinishedComposer(room.getNoVotes(), room.getYesVotes())); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java index 7e20e953..4a178ebd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -22,6 +22,9 @@ import com.eu.habbo.util.pathfinding.Rotation; import gnu.trove.map.TMap; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; import java.util.*; @@ -35,6 +38,7 @@ public class RoomUnit { public boolean isWiredTeleporting = false; public boolean isLeavingTeleporter = false; public boolean isSwimming = false; + @Getter private final ConcurrentHashMap status; private final THashMap cacheable; public boolean canRotate = true; @@ -48,22 +52,42 @@ public class RoomUnit { public boolean isKicked; public int kickCount = 0; private int id; + @Getter private RoomTile startLocation; + @Getter private RoomTile previousLocation; + @Getter + @Setter @Accessors(chain = true) private double previousLocationZ; private RoomTile currentLocation; + @Getter private RoomTile goalLocation; + @Getter private double z; private int tilesWalked; + @Getter + @Setter private boolean inRoom; + @Setter + @Accessors(chain = true) private boolean canWalk; + @Setter + @Getter private boolean fastWalk = false; private boolean statusUpdate = false; private boolean invisible = false; private boolean canLeaveRoomByDoor = true; + @Setter private RoomUserRotation bodyRotation = RoomUserRotation.NORTH; + @Getter + @Setter private RoomUserRotation headRotation = RoomUserRotation.NORTH; + @Getter + @Setter private DanceType danceType; + @Getter + @Setter + @Accessors(chain = true) private RoomUnitType roomUnitType; private Deque path = new LinkedList<>(); private int handItem; @@ -129,7 +153,7 @@ public class RoomUnit { if (rider != null) { // copy things from rider - if (this.status.containsKey(RoomUnitStatus.MOVE) && !rider.getRoomUnit().getStatusMap().containsKey(RoomUnitStatus.MOVE)) { + if (this.status.containsKey(RoomUnitStatus.MOVE) && !rider.getRoomUnit().getStatus().containsKey(RoomUnitStatus.MOVE)) { this.status.remove(RoomUnitStatus.MOVE); } @@ -341,7 +365,7 @@ public class RoomUnit { this.setZ(zHeight - 1.0); ridingUnit.setRotation(RoomUserRotation.values()[Rotation.Calculate(this.getX(), this.getY(), next.getX(), next.getY())]); ridingUnit.setPreviousLocation(this.getCurrentLocation()); - ridingUnit.setGoalLocation(this.getGoal()); + ridingUnit.setGoalLocation(this.getGoalLocation()); ridingUnit.setStatus(RoomUnitStatus.MOVE, next.getX() + "," + next.getY() + "," + (zHeight - 1.0)); room.sendComposer(new UserUpdateComposer(ridingUnit).compose()); //ridingUnit.setZ(zHeight - 1.0); @@ -404,10 +428,6 @@ public class RoomUnit { return this.currentLocation.getY(); } - public double getZ() { - return this.z; - } - public void setZ(double z) { this.z = z; @@ -419,22 +439,6 @@ public class RoomUnit { } } - public synchronized boolean isInRoom() { - return this.inRoom; - } - - public synchronized void setInRoom(boolean inRoom) { - this.inRoom = inRoom; - } - - public synchronized RoomUnitType getRoomUnitType() { - return this.roomUnitType; - } - - public synchronized void setRoomUnitType(RoomUnitType roomUnitType) { - this.roomUnitType = roomUnitType; - } - public void setRotation(RoomUserRotation rotation) { this.bodyRotation = rotation; this.headRotation = rotation; @@ -444,60 +448,19 @@ public class RoomUnit { return this.bodyRotation; } - public void setBodyRotation(RoomUserRotation bodyRotation) { - this.bodyRotation = bodyRotation; - } - - public RoomUserRotation getHeadRotation() { - return this.headRotation; - } - - public void setHeadRotation(RoomUserRotation headRotation) { - this.headRotation = headRotation; - } - - public synchronized DanceType getDanceType() { - return this.danceType; - } - - public synchronized void setDanceType(DanceType danceType) { - this.danceType = danceType; - } - - public void setCanWalk(boolean value) { - this.canWalk = value; - } - public boolean canWalk() { return this.canWalk; } - public boolean isFastWalk() { - return this.fastWalk; - } - - public void setFastWalk(boolean fastWalk) { - this.fastWalk = fastWalk; - } - - public RoomTile getStartLocation() { - return this.startLocation; - } - public int tilesWalked() { return this.tilesWalked; } - public RoomTile getGoal() { - return this.goalLocation; - } - - public void setGoalLocation(RoomTile goalLocation) { + public RoomUnit setGoalLocation(RoomTile goalLocation) { if (goalLocation != null) { - // if (goalLocation.state != RoomTileState.INVALID) { this.setGoalLocation(goalLocation, false); } - //} + return this; } public void setGoalLocation(RoomTile goalLocation, boolean noReset) { @@ -525,17 +488,14 @@ public class RoomUnit { } } - public void setLocation(RoomTile location) { + public RoomUnit setLocation(RoomTile location) { if (location != null) { this.startLocation = location; setPreviousLocation(location); setCurrentLocation(location); this.goalLocation = location; } - } - - public RoomTile getPreviousLocation() { - return this.previousLocation; + return this; } public void setPreviousLocation(RoomTile previousLocation) { @@ -543,16 +503,9 @@ public class RoomUnit { this.previousLocationZ = this.z; } - public double getPreviousLocationZ() { - return this.previousLocationZ; - } - - public void setPreviousLocationZ(double z) { - this.previousLocationZ = z; - } - - public void setPathFinderRoom(Room room) { + public RoomUnit setPathFinderRoom(Room room) { this.room = room; + return this; } public void findPath() { @@ -574,10 +527,6 @@ public class RoomUnit { return this.status.get(key); } - public ConcurrentHashMap getStatusMap() { - return this.status; - } - public void removeStatus(RoomUnitStatus key) { this.status.remove(key); } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java index d41f6c29..2d223480 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.users; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.catalog.CatalogItem; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GamePlayer; @@ -211,7 +212,7 @@ public class HabboInfo implements Runnable { statement.setInt(1, this.id); try (ResultSet set = statement.executeQuery()) { while (set.next()) { - this.messengerCategories.add(new MessengerCategory(set.getString("name"), set.getInt("user_id"), set.getInt("id"))); + this.messengerCategories.add(new MessengerCategory(set.getString("name"), set.getInt(DatabaseConstants.USER_ID), set.getInt("id"))); } } } catch (SQLException e) { diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java index 5bb26eb9..0fbb7b29 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.users; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.achievements.Achievement; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.bots.Bot; @@ -21,6 +22,7 @@ import com.eu.habbo.messages.outgoing.users.FigureUpdateComposer; import gnu.trove.set.hash.THashSet; import lombok.Getter; import lombok.Setter; +import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.math3.util.Pair; @@ -70,6 +72,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers { private int rotation; @Setter @Getter + @Accessors(chain = true) private String extradata; @Getter private int limitedStack; @@ -81,7 +84,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers { public HabboItem(ResultSet set, Item baseItem) throws SQLException { this.id = set.getInt("id"); - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.roomId = set.getInt("room_id"); this.baseItem = baseItem; this.wallPosition = set.getString("wall_pos"); @@ -260,7 +263,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers { room.sendComposer(new DanceMessageComposer(roomUnit).compose()); } - if (!this.getBaseItem().getClothingOnWalk().isEmpty() && roomUnit.getPreviousLocation() != roomUnit.getGoal() && roomUnit.getGoal() == room.getLayout().getTile(this.x, this.y)) { + if (!this.getBaseItem().getClothingOnWalk().isEmpty() && roomUnit.getPreviousLocation() != roomUnit.getGoalLocation() && roomUnit.getGoalLocation() == room.getLayout().getTile(this.x, this.y)) { Habbo habbo = room.getHabbo(roomUnit); if (habbo != null && habbo.getClient() != null) { diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboNavigatorWindowSettings.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboNavigatorWindowSettings.java index abd67166..9fa2c6ed 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboNavigatorWindowSettings.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboNavigatorWindowSettings.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.users; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.navigation.DisplayMode; import com.eu.habbo.habbohotel.navigation.ListMode; import gnu.trove.map.hash.THashMap; @@ -32,7 +33,7 @@ public class HabboNavigatorWindowSettings { } public HabboNavigatorWindowSettings(ResultSet set) throws SQLException { - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.x = set.getInt("x"); this.y = set.getInt("y"); this.width = set.getInt("width"); diff --git a/src/main/java/com/eu/habbo/habbohotel/users/cache/HabboOfferPurchase.java b/src/main/java/com/eu/habbo/habbohotel/users/cache/HabboOfferPurchase.java index 4da9ffba..f48a42e5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/cache/HabboOfferPurchase.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/cache/HabboOfferPurchase.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.users.cache; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.users.Habbo; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -24,7 +25,7 @@ public class HabboOfferPurchase { private boolean needsUpdate = false; public HabboOfferPurchase(ResultSet set) throws SQLException { - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.offerId = set.getInt("offer_id"); this.state = set.getInt("state"); this.amount = set.getInt("amount"); diff --git a/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java b/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java index 9a70c1f4..c790ed1b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.users.inventory; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.outgoing.inventory.AvatarEffectActivatedMessageComposer; import com.eu.habbo.messages.outgoing.inventory.AvatarEffectAddedMessageComposer; @@ -165,7 +166,7 @@ public class EffectsComponent { public HabboEffect(ResultSet set) throws SQLException { this.effect = set.getInt("effect"); - this.userId = set.getInt("user_id"); + this.userId = set.getInt(DatabaseConstants.USER_ID); this.duration = set.getInt("duration"); this.activationTimestamp = set.getInt("activation_timestamp"); this.total = set.getInt("total"); diff --git a/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java b/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java index 18017ba9..2a95d11c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.users.subscriptions; import com.eu.habbo.Emulator; import com.eu.habbo.database.Database; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.achievements.Achievement; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.messenger.Messenger; @@ -265,7 +266,7 @@ public class SubscriptionHabboClub extends Subscription { try (ResultSet set = statement.executeQuery()) { while (set.next()) { try { - int userId = set.getInt("user_id"); + int userId = set.getInt(DatabaseConstants.USER_ID); HabboInfo habboInfo = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(userId); HabboStats stats = habboInfo.getHabboStats(); ScrSendKickbackInfoMessageComposer calculated = calculatePayday(habboInfo); @@ -278,7 +279,7 @@ public class SubscriptionHabboClub extends Subscription { stats.setLastHCPayday(timestampNow); Emulator.getThreading().run(stats); } catch (Exception e) { - log.error("Exception processing HC payday for user #" + set.getInt("user_id"), e); + log.error("Exception processing HC payday for user #" + set.getInt(DatabaseConstants.USER_ID), e); } } } @@ -328,7 +329,7 @@ public class SubscriptionHabboClub extends Subscription { while (set.next()) { try { int logId = set.getInt("id"); - int userId = set.getInt("user_id"); + int userId = set.getInt(DatabaseConstants.USER_ID); int totalPayout = set.getInt("total_payout"); String currency = set.getString("currency"); @@ -339,7 +340,7 @@ public class SubscriptionHabboClub extends Subscription { } } } catch (Exception e) { - log.error("Exception processing HC payday for user #" + set.getInt("user_id"), e); + log.error("Exception processing HC payday for user #" + set.getInt(DatabaseConstants.USER_ID), e); } } } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionManager.java b/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionManager.java index 16814a09..838ee77a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionManager.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.users.subscriptions; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; import lombok.Getter; @@ -67,7 +68,7 @@ public class SubscriptionManager { Class subClazz = Emulator.getGameEnvironment().getSubscriptionManager().getSubscriptionClass(set.getString("subscription_type")); Constructor c = subClazz.getConstructor(Integer.class, Integer.class, String.class, Integer.class, Integer.class, Boolean.class); c.setAccessible(true); - Subscription subscription = c.newInstance(set.getInt("id"), set.getInt("user_id"), set.getString("subscription_type"), set.getInt("timestamp_start"), set.getInt("duration"), set.getInt("active") == 1); + Subscription subscription = c.newInstance(set.getInt("id"), set.getInt(DatabaseConstants.USER_ID), set.getString("subscription_type"), set.getInt("timestamp_start"), set.getInt("duration"), set.getInt("active") == 1); subscriptions.add(subscription); } } catch (IllegalAccessException e) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java index ff9a2e2e..8f29c9f9 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java @@ -109,7 +109,7 @@ public class UseFurnitureEvent extends MessageHandler { room.sendComposer(new RemoveFloorItemComposer(item, true).compose()); room.removeHabboItem(item); room.updateTile(room.getLayout().getTile(item.getX(), item.getY())); - room.placePet(pet, item.getX(), item.getY(), item.getZ(), item.getRotation()); + room.placePet(pet, item.getX(), item.getY(), item.getZ()); pet.cycle(); room.sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/OpenPetPackageEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/OpenPetPackageEvent.java index 9a8a27c6..f2343880 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/OpenPetPackageEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/OpenPetPackageEvent.java @@ -52,7 +52,7 @@ public class OpenPetPackageEvent extends MessageHandler { } if (pet != null) { - room.placePet(pet, item.getX(), item.getY(), item.getZ(), item.getRotation()); + room.placePet(pet, item.getX(), item.getY(), item.getZ()); pet.setUserId(this.client.getHabbo().getHabboInfo().getId()); pet.needsUpdate = true; pet.getRoomUnit().setLocation(room.getLayout().getTile(item.getX(), item.getY())); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorUserInfoComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorUserInfoComposer.java index 83669e2f..bafcd4b1 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorUserInfoComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorUserInfoComposer.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.outgoing.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.modtool.ModToolSanctionItem; import com.eu.habbo.habbohotel.modtool.ModToolSanctionLevelItem; import com.eu.habbo.habbohotel.modtool.ModToolSanctions; @@ -31,7 +32,7 @@ public class ModeratorUserInfoComposer extends MessageComposer { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT COUNT(*) AS amount FROM bans WHERE user_id = ?")) { - statement.setInt(1, this.set.getInt("user_id")); + statement.setInt(1, this.set.getInt(DatabaseConstants.USER_ID)); try (ResultSet set = statement.executeQuery()) { if (set.next()) { totalBans = set.getInt("amount"); @@ -43,7 +44,7 @@ public class ModeratorUserInfoComposer extends MessageComposer { log.error("Caught SQL exception", e); } - this.response.appendInt(this.set.getInt("user_id")); + this.response.appendInt(this.set.getInt(DatabaseConstants.USER_ID)); this.response.appendString(this.set.getString("username")); this.response.appendString(this.set.getString("look")); this.response.appendInt((Emulator.getIntUnixTimestamp() - this.set.getInt("account_created")) / 60); @@ -56,7 +57,7 @@ public class ModeratorUserInfoComposer extends MessageComposer { this.response.appendInt(this.set.getInt("tradelock_amount")); this.response.appendString(""); //Trading lock expiry timestamp this.response.appendString(""); //Last Purchase Timestamp - this.response.appendInt(this.set.getInt("user_id")); //Personal Identification # + this.response.appendInt(this.set.getInt(DatabaseConstants.USER_ID)); //Personal Identification # this.response.appendInt(0); // Number of account bans this.response.appendString(this.set.getBoolean("hide_mail") ? "" : this.set.getString("mail")); this.response.appendString("Rank (" + this.set.getInt("rank_id") + "): " + this.set.getString("rank_name")); //user_class_txt @@ -64,8 +65,8 @@ public class ModeratorUserInfoComposer extends MessageComposer { ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { - THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(this.set.getInt("user_id")); - ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(this.set.getInt("user_id")); + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(this.set.getInt(DatabaseConstants.USER_ID)); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(this.set.getInt(DatabaseConstants.USER_ID)); if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) //has sanction { diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsComposer.java index 919701be..13ff6004 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsComposer.java @@ -8,9 +8,9 @@ import com.eu.habbo.messages.outgoing.Outgoing; import gnu.trove.iterator.TIntObjectIterator; import gnu.trove.map.TIntObjectMap; import gnu.trove.map.hash.THashMap; -import gnu.trove.set.hash.THashSet; import lombok.AllArgsConstructor; +import java.util.List; import java.util.Map; import java.util.NoSuchElementException; @@ -42,7 +42,7 @@ public class ItemsComposer extends MessageComposer { this.response.appendString(set.getValue()); } - THashSet items = this.room.getWallItems(); + List items = this.room.getWallItems(); this.response.appendInt(items.size()); for (HabboItem item : items) { diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUpdateComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUpdateComposer.java index 9c492cb6..d75a8cac 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUpdateComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUpdateComposer.java @@ -50,7 +50,7 @@ public class UserUpdateComposer extends MessageComposer { this.response.appendInt(roomUnit.getBodyRotation().getValue()); StringBuilder status = new StringBuilder("/"); - for (Map.Entry entry : roomUnit.getStatusMap().entrySet()) { + for (Map.Entry entry : roomUnit.getStatus().entrySet()) { status.append(entry.getKey()).append(" ").append(entry.getValue()).append("/"); } @@ -72,7 +72,7 @@ public class UserUpdateComposer extends MessageComposer { StringBuilder status = new StringBuilder("/"); - for (Map.Entry entry : habbo.getRoomUnit().getStatusMap().entrySet()) { + for (Map.Entry entry : habbo.getRoomUnit().getStatus().entrySet()) { status.append(entry.getKey()).append(" ").append(entry.getValue()).append("/"); } this.response.appendString(status.toString()); diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java index f9d8ea6b..75f3ad42 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java @@ -18,7 +18,7 @@ public class RoomUnitRidePet implements Runnable { @Override public void run() { - if (this.habbo.getRoomUnit() == null || this.pet.getRoomUnit() == null || this.pet.getRoom() != this.habbo.getHabboInfo().getCurrentRoom() || this.goalTile == null || this.habbo.getRoomUnit().getGoal() != this.goalTile) + if (this.habbo.getRoomUnit() == null || this.pet.getRoomUnit() == null || this.pet.getRoom() != this.habbo.getHabboInfo().getCurrentRoom() || this.goalTile == null || this.habbo.getRoomUnit().getGoalLocation() != this.goalTile) return; if (habbo.getRoomUnit().getCurrentLocation().distance(pet.getRoomUnit().getCurrentLocation()) <= 1) { diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleportWalkToAction.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleportWalkToAction.java index 6d61abd4..d68a2eed 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleportWalkToAction.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleportWalkToAction.java @@ -24,7 +24,7 @@ public class RoomUnitTeleportWalkToAction implements Runnable { RoomTile tile = HabboItem.getSquareInFront(this.room.getLayout(), this.habboItem); if (tile != null) { - if (this.habbo.getRoomUnit().getGoal().equals(tile)) { + if (this.habbo.getRoomUnit().getGoalLocation().equals(tile)) { if (this.habbo.getRoomUnit().getCurrentLocation().equals(tile)) { try { this.habboItem.onClick(this.habbo.getClient(), this.room, new Object[]{0}); diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitVendingMachineAction.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitVendingMachineAction.java index c3a131c4..fc9a9ec2 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitVendingMachineAction.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitVendingMachineAction.java @@ -22,7 +22,7 @@ public class RoomUnitVendingMachineAction implements Runnable { if (this.habboItem.getRoomId() == this.room.getId()) { RoomTile tile = HabboItem.getSquareInFront(this.room.getLayout(), this.habboItem); if (tile != null) { - if (this.habbo.getRoomUnit().getGoal().equals(tile)) { + if (this.habbo.getRoomUnit().getGoalLocation().equals(tile)) { if (this.habbo.getRoomUnit().getCurrentLocation().equals(tile)) { try { this.habboItem.onClick(this.habbo.getClient(), this.room, new Object[]{0}); diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java index 80689fa4..23737f2e 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java @@ -43,7 +43,7 @@ public class RoomUnitWalkToLocation implements Runnable { return; } - if (!this.walker.getGoal().equals(this.goalTile) || (this.walker.getPath().size() == 0 && !this.walker.hasStatus(RoomUnitStatus.MOVE))) { + if (!this.walker.getGoalLocation().equals(this.goalTile) || (this.walker.getPath().size() == 0 && !this.walker.hasStatus(RoomUnitStatus.MOVE))) { onFail(); return; } diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java index d59a433e..7e84e3c9 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java @@ -38,7 +38,7 @@ public class RoomUnitWalkToRoomUnit implements Runnable { return; } - if (this.walker.getGoal().equals(this.goalTile)) { // check that the action hasn't been cancelled by changing the goal + if (this.walker.getGoalLocation().equals(this.goalTile)) { // check that the action hasn't been cancelled by changing the goal if (this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance) { for (Runnable r : this.targetReached) { Emulator.getThreading().run(r);