Advertisement
Guest User

Untitled

a guest
Jan 11th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 192.92 KB | None | 0 0
  1. package com.eu.habbo.habbohotel.rooms;
  2.  
  3. import com.eu.habbo.Emulator;
  4. import com.eu.habbo.habbohotel.bots.Bot;
  5. import com.eu.habbo.habbohotel.bots.VisitorBot;
  6. import com.eu.habbo.habbohotel.commands.CommandHandler;
  7. import com.eu.habbo.habbohotel.games.Game;
  8. import com.eu.habbo.habbohotel.guilds.Guild;
  9. import com.eu.habbo.habbohotel.guilds.GuildMember;
  10. import com.eu.habbo.habbohotel.items.FurnitureType;
  11. import com.eu.habbo.habbohotel.items.ICycleable;
  12. import com.eu.habbo.habbohotel.items.Item;
  13. import com.eu.habbo.habbohotel.items.interactions.*;
  14. import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate;
  15. import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard;
  16. import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
  17. import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiSphere;
  18. import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter;
  19. import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile;
  20. import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField;
  21. import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole;
  22. import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob;
  23. import com.eu.habbo.habbohotel.messenger.MessengerBuddy;
  24. import com.eu.habbo.habbohotel.permissions.Permission;
  25. import com.eu.habbo.habbohotel.pets.HorsePet;
  26. import com.eu.habbo.habbohotel.pets.Pet;
  27. import com.eu.habbo.habbohotel.pets.PetManager;
  28. import com.eu.habbo.habbohotel.pets.PetTasks;
  29. import com.eu.habbo.habbohotel.users.*;
  30. import com.eu.habbo.habbohotel.wired.*;
  31. import com.eu.habbo.messages.ISerialize;
  32. import com.eu.habbo.messages.ServerMessage;
  33. import com.eu.habbo.messages.outgoing.MessageComposer;
  34. import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer;
  35. import com.eu.habbo.messages.outgoing.generic.alerts.GenericErrorMessagesComposer;
  36. import com.eu.habbo.messages.outgoing.guilds.GuildInfoComposer;
  37. import com.eu.habbo.messages.outgoing.hotelview.HotelViewComposer;
  38. import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer;
  39. import com.eu.habbo.messages.outgoing.inventory.AddPetComposer;
  40. import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
  41. import com.eu.habbo.messages.outgoing.polls.infobus.SimplePollAnswerComposer;
  42. import com.eu.habbo.messages.outgoing.polls.infobus.SimplePollStartComposer;
  43. import com.eu.habbo.messages.outgoing.rooms.*;
  44. import com.eu.habbo.messages.outgoing.rooms.items.*;
  45. import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer;
  46. import com.eu.habbo.messages.outgoing.rooms.users.*;
  47. import com.eu.habbo.messages.outgoing.users.MutedWhisperComposer;
  48. import com.eu.habbo.plugin.Event;
  49. import com.eu.habbo.plugin.events.furniture.*;
  50. import com.eu.habbo.plugin.events.rooms.RoomLoadedEvent;
  51. import com.eu.habbo.plugin.events.rooms.RoomUnloadedEvent;
  52. import com.eu.habbo.plugin.events.rooms.RoomUnloadingEvent;
  53. import com.eu.habbo.plugin.events.users.UserExitRoomEvent;
  54. import com.eu.habbo.plugin.events.users.UserIdleEvent;
  55. import com.eu.habbo.plugin.events.users.UserRightsTakenEvent;
  56. import com.eu.habbo.plugin.events.users.UserRolledEvent;
  57. import com.eu.habbo.threading.runnables.YouAreAPirate;
  58. import gnu.trove.TCollections;
  59. import gnu.trove.iterator.TIntObjectIterator;
  60. import gnu.trove.list.array.TIntArrayList;
  61. import gnu.trove.map.TIntIntMap;
  62. import gnu.trove.map.TIntObjectMap;
  63. import gnu.trove.map.hash.THashMap;
  64. import gnu.trove.map.hash.TIntIntHashMap;
  65. import gnu.trove.map.hash.TIntObjectHashMap;
  66. import gnu.trove.procedure.TIntObjectProcedure;
  67. import gnu.trove.procedure.TObjectProcedure;
  68. import gnu.trove.set.hash.THashSet;
  69. import io.netty.util.internal.ConcurrentSet;
  70. import org.apache.commons.math3.util.Pair;
  71.  
  72. import java.awt.*;
  73. import java.sql.Connection;
  74. import java.sql.PreparedStatement;
  75. import java.sql.ResultSet;
  76. import java.sql.SQLException;
  77. import java.util.*;
  78. import java.util.List;
  79. import java.util.concurrent.ConcurrentHashMap;
  80. import java.util.concurrent.ScheduledFuture;
  81. import java.util.concurrent.TimeUnit;
  82.  
  83. public class Room implements Comparable<Room>, ISerialize, Runnable
  84. {
  85. //Configuration. Loaded from database & updated accordingly.
  86. public static boolean HABBO_CHAT_DELAY = false;
  87. public static int MAXIMUM_BOTS = 10;
  88. public static int MAXIMUM_PETS = 10;
  89. public static int HAND_ITEM_TIME = 10;
  90. public static int IDLE_CYCLES = 240;
  91. public static int IDLE_CYCLES_KICK = 480;
  92. public static String PREFIX_FORMAT = "[<font color=\"%color%\">%prefix%</font>] ";
  93.  
  94. private static final TIntObjectHashMap<RoomMoodlightData> defaultMoodData = new TIntObjectHashMap<>();
  95.  
  96. static
  97. {
  98. for(int i = 1; i <= 3; i++)
  99. {
  100. RoomMoodlightData data = RoomMoodlightData.fromString("");
  101. data.setId(i);
  102. defaultMoodData.put(i, data);
  103. }
  104. }
  105. private int id;
  106. private int ownerId;
  107. private String ownerName;
  108. private String name;
  109. private String description;
  110. private RoomLayout layout;
  111. private boolean overrideModel;
  112. private String layoutName;
  113. private String password;
  114. private RoomState state;
  115. private int usersMax;
  116. private volatile int score;
  117. private volatile int category;
  118.  
  119. private String floorPaint;
  120. private String wallPaint;
  121. private String backgroundPaint;
  122.  
  123. private int wallSize;
  124. private int wallHeight;
  125. private int floorSize;
  126.  
  127. private int guild;
  128.  
  129. private String tags;
  130. private volatile boolean publicRoom;
  131. private volatile boolean staffPromotedRoom;
  132. private volatile boolean allowPets;
  133. private volatile boolean allowPetsEat;
  134. private volatile boolean allowWalkthrough;
  135. private volatile boolean allowBotsWalk;
  136. private volatile boolean allowEffects;
  137. private volatile boolean hideWall;
  138. private volatile int chatMode;
  139. private volatile int chatWeight;
  140. private volatile int chatSpeed;
  141. private volatile int chatDistance;
  142. private volatile int chatProtection;
  143. private volatile int muteOption;
  144. private volatile int kickOption;
  145. private volatile int banOption;
  146. private volatile int pollId;
  147. private volatile boolean promoted;
  148. private volatile int tradeMode;
  149. private volatile boolean moveDiagonally;
  150. private volatile boolean jukeboxActive;
  151. private volatile boolean hideWired;
  152.  
  153. private final ConcurrentHashMap<Integer, Habbo> currentHabbos = new ConcurrentHashMap<>(3);
  154. private final TIntObjectMap<Habbo> habboQueue = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
  155. private final TIntObjectMap<Bot> currentBots = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
  156. private final TIntObjectMap<Pet> currentPets = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
  157. private final THashSet<RoomTrade> activeTrades;
  158. private final TIntArrayList rights;
  159. private final TIntIntHashMap mutedHabbos;
  160. private final TIntObjectHashMap<RoomBan> bannedHabbos;
  161. private final ConcurrentSet<Game> games;
  162. private final TIntObjectMap<String> furniOwnerNames;
  163. private final TIntIntMap furniOwnerCount;
  164. private final TIntObjectMap<RoomMoodlightData> moodlightData;
  165. private final THashSet<String> wordFilterWords;
  166. private final TIntObjectMap<HabboItem> roomItems;
  167. private final THashMap<WiredHighscoreScoreType, THashMap<WiredHighscoreClearType, THashSet<WiredHighscoreData>>> wiredHighscoreData;
  168. private RoomPromotion promotion;
  169.  
  170. private volatile boolean needsUpdate;
  171. private volatile boolean loaded;
  172. private volatile boolean preLoaded;
  173. private int idleCycles;
  174. private volatile int unitCounter;
  175. private volatile int rollerSpeed;
  176. private long rollerCycle = System.currentTimeMillis();
  177. private volatile int lastTimerReset = Emulator.getIntUnixTimestamp();
  178. private volatile boolean muted;
  179.  
  180. private RoomSpecialTypes roomSpecialTypes;
  181.  
  182. private final Object loadLock = new Object();
  183. public final Object roomUnitLock = new Object();
  184.  
  185. //Use appropriately. Could potentially cause memory leaks when used incorrectly.
  186. public volatile boolean preventUnloading = false;
  187. public volatile boolean preventUncaching = false;
  188. public THashMap<Short, TIntArrayList> waterTiles;
  189. public final ConcurrentHashMap<RoomTile, THashSet<HabboItem>> tileCache = new ConcurrentHashMap<>();
  190. public ConcurrentSet<ServerMessage> scheduledComposers = new ConcurrentSet<>();
  191. public ConcurrentSet<Runnable> scheduledTasks = new ConcurrentSet<>();
  192. public String wordQuiz = "";
  193. public int noVotes = 0;
  194. public int yesVotes = 0;
  195. public int wordQuizEnd = 0;
  196. public final List<Integer> userVotes;
  197. public ScheduledFuture roomCycleTask;
  198. private TraxManager traxManager;
  199. private long cycleTimestamp;
  200.  
  201. public Room(ResultSet set) throws SQLException
  202. {
  203. this.id = set.getInt("id");
  204. this.ownerId = set.getInt("owner_id");
  205. this.ownerName = set.getString("owner_name");
  206. this.name = set.getString("name");
  207. this.description = set.getString("description");
  208. this.password = set.getString("password");
  209. this.state = RoomState.valueOf(set.getString("state").toUpperCase());
  210. this.usersMax = set.getInt("users_max");
  211. this.score = set.getInt("score");
  212. this.category = set.getInt("category");
  213. this.floorPaint = set.getString("paper_floor");
  214. this.wallPaint = set.getString("paper_wall");
  215. this.backgroundPaint = set.getString("paper_landscape");
  216. this.wallSize = set.getInt("thickness_wall");
  217. this.wallHeight = set.getInt("wall_height");
  218. this.floorSize = set.getInt("thickness_floor");
  219. this.tags = set.getString("tags");
  220. this.publicRoom = set.getBoolean("is_public");
  221. this.staffPromotedRoom = set.getBoolean("is_staff_picked");
  222. this.allowPets = set.getBoolean("allow_other_pets");
  223. this.allowPetsEat = set.getBoolean("allow_other_pets_eat");
  224. this.allowWalkthrough = set.getBoolean("allow_walkthrough");
  225. this.hideWall = set.getBoolean("allow_hidewall");
  226. this.chatMode = set.getInt("chat_mode");
  227. this.chatWeight = set.getInt("chat_weight");
  228. this.chatSpeed = set.getInt("chat_speed");
  229. this.chatDistance = set.getInt("chat_hearing_distance");
  230. this.chatProtection = set.getInt("chat_protection");
  231. this.muteOption = set.getInt("who_can_mute");
  232. this.kickOption = set.getInt("who_can_kick");
  233. this.banOption = set.getInt("who_can_ban");
  234. this.pollId = set.getInt("poll_id");
  235. this.guild = set.getInt("guild_id");
  236. this.rollerSpeed = set.getInt("roller_speed");
  237. this.overrideModel = set.getString("override_model").equals("1");
  238. this.layoutName = set.getString("model");
  239. this.promoted = set.getString("promoted").equals("1");
  240. this.jukeboxActive = set.getString("jukebox_active").equals("1");
  241. this.hideWired = set.getString("hidewired").equals("1");
  242.  
  243. this.bannedHabbos = new TIntObjectHashMap<>();
  244.  
  245. // for (String itemString : set.getString("trax").split(";"))
  246. // {
  247. // try
  248. // {
  249. // this.traxItems.add(Integer.valueOf(itemString));
  250. // }
  251. // catch (Exception e)
  252. // {
  253. // Emulator.getLogging().logErrorLine(e);
  254. // }
  255. // }
  256. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_promotions WHERE room_id = ? AND end_timestamp > ? LIMIT 1"))
  257. {
  258. if(this.promoted)
  259. {
  260. statement.setInt(1, this.id);
  261. statement.setInt(2, Emulator.getIntUnixTimestamp());
  262.  
  263. try (ResultSet promotionSet = statement.executeQuery())
  264. {
  265. this.promoted = false;
  266. if (promotionSet.next())
  267. {
  268. this.promoted = true;
  269. this.promotion = new RoomPromotion(this, promotionSet);
  270. }
  271. }
  272. }
  273.  
  274. this.loadBans(connection);
  275. }
  276. this.tradeMode = set.getInt("trade_mode");
  277. this.moveDiagonally = set.getString("move_diagonally").equals("1");
  278.  
  279. this.preLoaded = true;
  280. this.allowBotsWalk = true;
  281. this.allowEffects = true;
  282. this.furniOwnerNames = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
  283. this.furniOwnerCount = TCollections.synchronizedMap(new TIntIntHashMap(0));
  284. this.roomItems = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
  285. this.wordFilterWords = new THashSet<>(0);
  286. this.moodlightData = new TIntObjectHashMap<>(defaultMoodData);
  287.  
  288. for(String s : set.getString("moodlight_data").split(";"))
  289. {
  290. RoomMoodlightData data = RoomMoodlightData.fromString(s);
  291. this.moodlightData.put(data.getId(), data);
  292. }
  293.  
  294. this.mutedHabbos = new TIntIntHashMap();
  295. this.games = new ConcurrentSet<>();
  296.  
  297. this.activeTrades = new THashSet<>(0);
  298. this.rights = new TIntArrayList();
  299. this.wiredHighscoreData = new THashMap<>();
  300. this.userVotes = new ArrayList<>();
  301. }
  302.  
  303. public synchronized void loadData()
  304. {
  305. synchronized (this.loadLock)
  306. {
  307. if (!this.preLoaded || this.loaded)
  308. return;
  309.  
  310. this.preLoaded = false;
  311.  
  312. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection())
  313. {
  314. synchronized ( this.roomUnitLock)
  315. {
  316. this.unitCounter = 0;
  317. this.currentHabbos.clear();
  318. this.currentPets.clear();
  319. this.currentBots.clear();
  320. }
  321.  
  322. this.roomSpecialTypes = new RoomSpecialTypes();
  323.  
  324. try
  325. {
  326. this.loadLayout();
  327. }
  328. catch (Exception e)
  329. {
  330. Emulator.getLogging().logErrorLine(e);
  331. }
  332.  
  333. try
  334. {
  335. this.loadRights(connection);
  336. }
  337. catch (Exception e)
  338. {
  339. Emulator.getLogging().logErrorLine(e);
  340. }
  341.  
  342. try
  343. {
  344. this.loadItems(connection);
  345. }
  346. catch (Exception e)
  347. {
  348. Emulator.getLogging().logErrorLine(e);
  349. }
  350.  
  351. try
  352. {
  353. this.loadHeightmap();
  354. }
  355. catch (Exception e)
  356. {
  357. Emulator.getLogging().logErrorLine(e);
  358. }
  359.  
  360. try
  361. {
  362. this.loadBots(connection);
  363. }
  364. catch (Exception e)
  365. {
  366. Emulator.getLogging().logErrorLine(e);
  367. }
  368.  
  369. try
  370. {
  371. this.loadPets(connection);
  372. }
  373. catch (Exception e)
  374. {
  375. Emulator.getLogging().logErrorLine(e);
  376. }
  377.  
  378. try
  379. {
  380. this.loadWordFilter(connection);
  381. }
  382. catch (Exception e)
  383. {
  384. Emulator.getLogging().logErrorLine(e);
  385. }
  386.  
  387. try
  388. {
  389. this.loadWiredData(connection);
  390. }
  391. catch (Exception e)
  392. {
  393. Emulator.getLogging().logErrorLine(e);
  394. }
  395.  
  396. this.idleCycles = 0;
  397. this.loaded = true;
  398.  
  399. this.roomCycleTask = Emulator.getThreading().getService().scheduleAtFixedRate(this, 500, 500, TimeUnit.MILLISECONDS);
  400. }
  401. catch (Exception e)
  402. {
  403. Emulator.getLogging().logErrorLine(e);
  404. }
  405.  
  406. this.traxManager = new TraxManager(this);
  407.  
  408. if (this.jukeboxActive)
  409. {
  410. this.traxManager.play(0);
  411. for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionJukeBox.class))
  412. {
  413. item.setExtradata("1");
  414. this.updateItem(item);
  415. }
  416. }
  417. }
  418.  
  419. Emulator.getPluginManager().fireEvent(new RoomLoadedEvent(this));
  420. }
  421.  
  422. private synchronized void loadLayout()
  423. {
  424. if (this.layout == null)
  425. {
  426. if (this.overrideModel)
  427. {
  428. this.layout = Emulator.getGameEnvironment().getRoomManager().loadCustomLayout(this);
  429. }
  430. else
  431. {
  432. this.layout = Emulator.getGameEnvironment().getRoomManager().loadLayout(this.layoutName, this);
  433. }
  434. }
  435. }
  436.  
  437. private synchronized void loadHeightmap()
  438. {
  439. if (this.layout != null)
  440. {
  441. for (short x = 0; x < this.layout.getMapSizeX(); x++)
  442. {
  443. for (short y = 0; y < this.layout.getMapSizeY(); y++)
  444. {
  445. RoomTile tile = this.layout.getTile(x, y);
  446. if (tile != null)
  447. {
  448. this.updateTile(tile);
  449. }
  450. }
  451. }
  452. }
  453. else
  454. {
  455. Emulator.getLogging().logErrorLine("Unknown Room Layout for Room (ID: " + this.id + ")");
  456. }
  457. }
  458.  
  459. private synchronized void loadItems(Connection connection) throws SQLException
  460. {
  461. this.roomItems.clear();
  462.  
  463. try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM items WHERE room_id = ?"))
  464. {
  465. statement.setInt(1, this.id);
  466. try (ResultSet set = statement.executeQuery())
  467. {
  468. while (set.next())
  469. {
  470. this.addHabboItem(Emulator.getGameEnvironment().getItemManager().loadHabboItem(set));
  471. }
  472. }
  473. }
  474. }
  475.  
  476. private synchronized void loadWiredData(Connection connection) throws SQLException
  477. {
  478. try (PreparedStatement statement = connection.prepareStatement("SELECT id, wired_data FROM items WHERE room_id = ? AND wired_data<>''"))
  479. {
  480. statement.setInt(1, this.id);
  481.  
  482. try (ResultSet set = statement.executeQuery())
  483. {
  484. while (set.next())
  485. {
  486. try
  487. {
  488. HabboItem item = this.getHabboItem(set.getInt("id"));
  489.  
  490. if (item instanceof InteractionWired)
  491. {
  492. ((InteractionWired) item).loadWiredData(set, this);
  493. }
  494. }
  495. catch (SQLException e)
  496. {
  497. Emulator.getLogging().logSQLException(e);
  498. }
  499. }
  500. }
  501. }
  502. catch (Exception e)
  503. {
  504. Emulator.getLogging().logErrorLine(e);
  505. }
  506. }
  507.  
  508. private synchronized void loadBots(Connection connection) throws SQLException
  509. {
  510. this.currentBots.clear();
  511.  
  512. try (PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.user_id = users.id WHERE room_id = ?"))
  513. {
  514. statement.setInt(1, this.id);
  515. try (ResultSet set = statement.executeQuery())
  516. {
  517. while (set.next())
  518. {
  519. Bot b = Emulator.getGameEnvironment().getBotManager().loadBot(set);
  520.  
  521. if (b != null)
  522. {
  523. b.setRoom(this);
  524. b.setRoomUnit(new RoomUnit());
  525. b.getRoomUnit().setPathFinderRoom(this);
  526. b.getRoomUnit().setLocation(this.layout.getTile((short) set.getInt("x"), (short) set.getInt("y")));
  527. if (b.getRoomUnit().getCurrentLocation() == null)
  528. {
  529. b.getRoomUnit().setLocation(this.getLayout().getDoorTile());
  530. b.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection()));
  531. }
  532. else
  533. {
  534. b.getRoomUnit().setZ(set.getDouble("z"));
  535. b.getRoomUnit().setRotation(RoomUserRotation.values()[set.getInt("rot")]);
  536. }
  537. b.getRoomUnit().setRoomUnitType(RoomUnitType.BOT);
  538. b.getRoomUnit().setDanceType(DanceType.values()[set.getInt("dance")]);
  539. //b.getRoomUnit().setCanWalk(set.getBoolean("freeroam"));
  540. b.getRoomUnit().setInRoom(true);
  541. this.giveEffect(b.getRoomUnit(), set.getInt("effect"), Integer.MAX_VALUE);
  542. this.addBot(b);
  543. }
  544. }
  545. }
  546. }
  547. catch (SQLException e)
  548. {
  549. Emulator.getLogging().logSQLException(e);
  550. }
  551. }
  552.  
  553. private synchronized void loadPets(Connection connection) throws SQLException
  554. {
  555. this.currentPets.clear();
  556.  
  557. 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 = ?"))
  558. {
  559. statement.setInt(1, this.id);
  560. try (ResultSet set = statement.executeQuery())
  561. {
  562. while (set.next())
  563. {
  564. try
  565. {
  566. Pet pet = PetManager.loadPet(set);
  567. pet.setRoom(this);
  568. pet.setRoomUnit(new RoomUnit());
  569. pet.getRoomUnit().setPathFinderRoom(this);
  570. pet.getRoomUnit().setLocation(this.layout.getTile((short) set.getInt("x"), (short) set.getInt("y")));
  571. if (pet.getRoomUnit().getCurrentLocation() == null)
  572. {
  573. pet.getRoomUnit().setLocation(this.getLayout().getDoorTile());
  574. pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection()));
  575. }
  576. else
  577. {
  578. pet.getRoomUnit().setZ(set.getDouble("z"));
  579. pet.getRoomUnit().setRotation(RoomUserRotation.values()[set.getInt("rot")]);
  580. }
  581. pet.getRoomUnit().setRoomUnitType(RoomUnitType.PET);
  582. pet.getRoomUnit().setCanWalk(true);
  583. this.addPet(pet);
  584.  
  585. this.getFurniOwnerNames().put(pet.getUserId(), set.getString("pet_owner_name"));
  586. }
  587. catch (SQLException e)
  588. {
  589. Emulator.getLogging().logSQLException(e);
  590. }
  591. }
  592. }
  593. }
  594. }
  595.  
  596. private synchronized void loadWordFilter(Connection connection) throws SQLException
  597. {
  598. this.wordFilterWords.clear();
  599.  
  600. try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_wordfilter WHERE room_id = ?"))
  601. {
  602. statement.setInt(1, this.id);
  603. try (ResultSet set = statement.executeQuery())
  604. {
  605. while (set.next())
  606. {
  607. this.wordFilterWords.add(set.getString("word"));
  608. }
  609. }
  610. }
  611. }
  612.  
  613. public void updateTile(RoomTile tile)
  614. {
  615. if (tile != null)
  616. {
  617. tile.setStackHeight(this.getStackHeight(tile.x, tile.y, false));
  618.  
  619. tile.setState(this.calculateTileState(tile));
  620. }
  621. }
  622.  
  623. public void updateTiles(THashSet<RoomTile> tiles)
  624. {
  625. for (RoomTile tile : tiles)
  626. {
  627. this.tileCache.remove(tile);
  628. tile.setStackHeight(this.getStackHeight(tile.x, tile.y, false));
  629. tile.setState(this.calculateTileState(tile));
  630. }
  631.  
  632. this.sendComposer(new UpdateStackHeightComposer(tiles).compose());
  633. }
  634.  
  635. private RoomTileState calculateTileState(RoomTile tile)
  636. {
  637. return this.calculateTileState(tile, null);
  638. }
  639.  
  640. private RoomTileState calculateTileState(RoomTile tile, HabboItem exclude)
  641. {
  642. if (tile.state == RoomTileState.INVALID)
  643. return RoomTileState.INVALID;
  644.  
  645. RoomTileState result = RoomTileState.OPEN;
  646. HabboItem lowestItem = null;
  647. HabboItem lowestChair = this.getLowestChair(tile);
  648. for (HabboItem item : this.getItemsAt(tile))
  649. {
  650. if (exclude != null && item == exclude) continue;
  651.  
  652. if (lowestChair != null && item.getZ() > lowestChair.getZ() + 1.5)
  653. {
  654. continue;
  655. }
  656.  
  657. if (lowestItem == null || lowestItem.getZ() < item.getZ())
  658. {
  659. lowestItem = item;
  660.  
  661. result = this.checkStateForItem(lowestItem);
  662. }
  663. else if (lowestItem.getZ() == item.getZ())
  664. {
  665. if (result == RoomTileState.OPEN)
  666. {
  667. result = this.checkStateForItem(item);
  668. }
  669. }
  670. }
  671.  
  672. if (lowestChair != null) return RoomTileState.SIT;
  673.  
  674. return result;
  675. }
  676.  
  677. private RoomTileState checkStateForItem(HabboItem item)
  678. {
  679. RoomTileState result = RoomTileState.BLOCKED;
  680.  
  681. if (item.isWalkable())
  682. {
  683. result = RoomTileState.OPEN;
  684. }
  685.  
  686. if (item.getBaseItem().allowSit())
  687. {
  688. result = RoomTileState.SIT;
  689. }
  690.  
  691. if (item.getBaseItem().allowLay())
  692. {
  693. result = RoomTileState.LAY;
  694. }
  695.  
  696. return result;
  697. }
  698. public boolean tileWalkable(RoomTile t)
  699. {
  700. return this.tileWalkable(t.x, t.y);
  701. }
  702.  
  703. public boolean tileWalkable(short x, short y)
  704. {
  705. boolean walkable = this.layout.tileWalkable(x, y);
  706.  
  707. if (walkable)
  708. {
  709. if (this.hasHabbosAt(x, y) && !this.allowWalkthrough)
  710. {
  711. walkable = false;
  712. }
  713. }
  714. return walkable; //&& (!this.allowWalkthrough && !this.hasHabbosAt(x, y)));
  715. //if(this.layout.tileWalkable(x, y))
  716. // {
  717. // if(!this.allowWalkthrough)
  718. // {
  719. // if (hasHabbosAt(x, y))
  720. // return false;
  721. //
  722. // if (hasBotsAt(x, y))
  723. // return false;
  724. // }
  725. //
  726. // THashSet<HabboItem> items = getItemsAt(x, y);
  727. // if(items.isEmpty())
  728. // return true;
  729. //
  730. // boolean walkAble = true;
  731. // for(HabboItem item : items)
  732. // {
  733. // if(!item.getBaseItem().allowWalk())
  734. // walkAble = false;
  735. //
  736. // if(item.getBaseItem().allowSit())
  737. // walkAble = false;
  738. //
  739. // if(item instanceof InteractionGate)
  740. // {
  741. // walkAble = item.isWalkable();
  742. // }
  743. // else if(item instanceof InteractionGameGate)
  744. // {
  745. // walkAble = item.isWalkable();
  746. // }
  747. // else if(item instanceof InteractionFreezeBlock)
  748. // {
  749. // walkAble = item.isWalkable();
  750. // }
  751. // }
  752. //
  753. // return walkAble;
  754. // HabboItem item = this.getTopItemAt(x, y);
  755. //
  756. // return item == null || item.isWalkable();
  757. // }
  758. // return false;
  759. }
  760.  
  761. public void pickUpItem(HabboItem item, Habbo picker)
  762. {
  763. if(item == null)
  764. return;
  765.  
  766. if(Emulator.getPluginManager().isRegistered(FurniturePickedUpEvent.class, true))
  767. {
  768. Event furniturePickedUpEvent = new FurniturePickedUpEvent(item, picker);
  769. Emulator.getPluginManager().fireEvent(furniturePickedUpEvent);
  770.  
  771. if(furniturePickedUpEvent.isCancelled())
  772. return;
  773. }
  774.  
  775. this.removeHabboItem(item.getId());
  776. item.onPickUp(this);
  777. item.setRoomId(0);
  778. item.needsUpdate(true);
  779.  
  780. if (item.getBaseItem().getType() == FurnitureType.FLOOR)
  781. {
  782. this.sendComposer(new RemoveFloorItemComposer(item).compose());
  783.  
  784. THashSet<RoomTile> updatedTiles = new THashSet<>();
  785. Rectangle rectangle = RoomLayout.getRectangle(item.getX(), item.getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
  786.  
  787. for (short x = (short)rectangle.x; x < rectangle.x + rectangle.getWidth(); x++)
  788. {
  789. for (short y = (short)rectangle.y; y < rectangle.y + rectangle.getHeight(); y++)
  790. {
  791. double stackHeight = this.getStackHeight(x, y, false);
  792. RoomTile tile = this.layout.getTile(x, y);
  793.  
  794. if (tile != null)
  795. {
  796. tile.setStackHeight(stackHeight);
  797. updatedTiles.add(tile);
  798. }
  799. }
  800. }
  801. this.sendComposer(new UpdateStackHeightComposer(updatedTiles).compose());
  802. this.updateTiles(updatedTiles);
  803. for (RoomTile tile : updatedTiles)
  804. {
  805. this.updateHabbosAt(tile.x, tile.y);
  806. }
  807. }
  808. else if (item.getBaseItem().getType() == FurnitureType.WALL)
  809. {
  810. this.sendComposer(new RemoveWallItemComposer(item).compose());
  811. }
  812.  
  813. Habbo habbo = (picker != null && picker.getHabboInfo().getId() == item.getId() ? picker : Emulator.getGameServer().getGameClientManager().getHabbo(item.getUserId()));
  814. if (habbo != null) {
  815. habbo.getInventory().getItemsComponent().addItem(item);
  816. habbo.getClient().sendResponse(new AddHabboItemComposer(item));
  817. habbo.getClient().sendResponse(new InventoryRefreshComposer());
  818. }
  819. Emulator.getThreading().run(item);
  820. }
  821.  
  822. public void updateHabbosAt(Rectangle rectangle)
  823. {
  824. for(short i = (short) rectangle.x; i < rectangle.x + rectangle.width; i++)
  825. {
  826. for(short j = (short) rectangle.y; j < rectangle.y + rectangle.height; j++)
  827. {
  828. this.updateHabbosAt(i, j);
  829. }
  830. }
  831. }
  832.  
  833. public void updateHabbo(Habbo habbo)
  834. {
  835. this.updateRoomUnit(habbo.getRoomUnit());
  836. }
  837. public void updateRoomUnit(RoomUnit roomUnit)
  838. {
  839. HabboItem item = this.getTopItemAt(roomUnit.getX(), roomUnit.getY());
  840.  
  841. if((item == null && !roomUnit.cmdSit) || (item != null && !item.getBaseItem().allowSit()))
  842. roomUnit.removeStatus(RoomUnitStatus.SIT);
  843.  
  844. double oldZ = roomUnit.getZ();
  845.  
  846. if(item != null)
  847. {
  848. if(item.getBaseItem().allowSit())
  849. {
  850. roomUnit.setZ(item.getZ());
  851. }
  852. else
  853. {
  854. roomUnit.setZ(item.getZ() + item.getBaseItem().getHeight());
  855. }
  856.  
  857. if (oldZ != roomUnit.getZ())
  858. {
  859. this.scheduledTasks.add(new Runnable()
  860. {
  861. @Override
  862. public void run()
  863. {
  864. try
  865. {
  866. item.onWalkOn(roomUnit, Room.this, null);
  867. } catch (Exception e)
  868. {
  869.  
  870. }
  871. }
  872. });
  873. }
  874. }
  875.  
  876. this.sendComposer(new RoomUserStatusComposer(roomUnit).compose());
  877. }
  878.  
  879. public void updateHabbosAt(short x, short y)
  880. {
  881. THashSet<Habbo> habbos = this.getHabbosAt(x, y);
  882.  
  883. HabboItem item = this.getTopItemAt(x, y);
  884.  
  885. THashSet<RoomUnit> roomUnits = new THashSet<>();
  886. for (Habbo habbo : habbos)
  887. {
  888. if ((item == null && !habbo.getRoomUnit().cmdSit) || (item != null && !item.getBaseItem().allowSit()))
  889. habbo.getRoomUnit().removeStatus(RoomUnitStatus.SIT);
  890.  
  891. if ((item == null && !habbo.getRoomUnit().cmdLay) || (item != null && !item.getBaseItem().allowLay()))
  892. habbo.getRoomUnit().removeStatus(RoomUnitStatus.LAY);
  893.  
  894. if(item != null)
  895. {
  896. if(item.getBaseItem().allowSit())
  897. {
  898. habbo.getRoomUnit().setZ(item.getZ());
  899. habbo.getRoomUnit().setPreviousLocationZ(item.getZ());
  900. habbo.getRoomUnit().setRotation(RoomUserRotation.fromValue(item.getRotation()));
  901. }
  902. else
  903. {
  904. habbo.getRoomUnit().setZ(item.getZ() + item.getBaseItem().getHeight());
  905.  
  906. if (item.getBaseItem().allowLay())
  907. {
  908. habbo.getRoomUnit().setStatus(RoomUnitStatus.LAY, (item.getZ() + item.getBaseItem().getHeight()) + "");
  909. }
  910. }
  911. }
  912. else
  913. {
  914. habbo.getRoomUnit().setZ(habbo.getRoomUnit().getCurrentLocation().getStackHeight());
  915. habbo.getRoomUnit().setPreviousLocationZ(habbo.getRoomUnit().getCurrentLocation().getStackHeight());
  916. }
  917. roomUnits.add(habbo.getRoomUnit());
  918. }
  919.  
  920. if (!roomUnits.isEmpty())
  921. {
  922. this.sendComposer(new RoomUserStatusComposer(roomUnits, true).compose());
  923. }
  924. }
  925.  
  926. public void pickupPetsForHabbo(Habbo habbo)
  927. {
  928. THashSet<Pet> pets = new THashSet<>();
  929.  
  930. synchronized (this.currentPets)
  931. {
  932. for(Pet pet : this.currentPets.valueCollection())
  933. {
  934. if(pet.getUserId() == habbo.getHabboInfo().getId())
  935. {
  936. pets.add(pet);
  937. }
  938. }
  939. }
  940.  
  941. for(Pet pet : pets)
  942. {
  943. pet.setRoom(null);
  944. pet.needsUpdate = true;
  945. habbo.getInventory().getPetsComponent().addPet(pet);
  946. this.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose());
  947. habbo.getClient().sendResponse(new AddPetComposer(pet));
  948. this.currentPets.remove(pet.getId());
  949. }
  950.  
  951. }
  952.  
  953. public void startTrade(Habbo userOne, Habbo userTwo)
  954. {
  955. RoomTrade trade = new RoomTrade(userOne, userTwo, this);
  956. synchronized (this.activeTrades)
  957. {
  958. this.activeTrades.add(trade);
  959. }
  960.  
  961. trade.start();
  962. }
  963.  
  964. public void stopTrade(RoomTrade trade)
  965. {
  966. synchronized (this.activeTrades)
  967. {
  968. this.activeTrades.remove(trade);
  969. }
  970. }
  971.  
  972. public RoomTrade getActiveTradeForHabbo(Habbo user)
  973. {
  974. synchronized (this.activeTrades)
  975. {
  976. for (RoomTrade trade : this.activeTrades)
  977. {
  978. for (RoomTradeUser habbo : trade.getRoomTradeUsers())
  979. {
  980. if (habbo.getHabbo() == user)
  981. return trade;
  982. }
  983. }
  984. }
  985. return null;
  986. }
  987.  
  988. public synchronized void dispose()
  989. {
  990. synchronized (this.loadLock)
  991. {
  992. if (this.preventUnloading)
  993. return;
  994.  
  995. if (Emulator.getPluginManager().fireEvent(new RoomUnloadingEvent(this)).isCancelled())
  996. return;
  997.  
  998. if (this.loaded)
  999. {
  1000. if (!this.traxManager.disposed())
  1001. {
  1002. this.traxManager.dispose();
  1003. }
  1004. try
  1005. {
  1006. this.roomCycleTask.cancel(false);
  1007. this.scheduledTasks.clear();
  1008. this.scheduledComposers.clear();
  1009. this.loaded = false;
  1010.  
  1011. this.tileCache.clear();
  1012.  
  1013. synchronized (this.mutedHabbos)
  1014. {
  1015. this.mutedHabbos.clear();
  1016. }
  1017.  
  1018. for (Game game : this.games)
  1019. {
  1020. game.stop();
  1021. }
  1022. this.games.clear();
  1023.  
  1024. synchronized (this.roomItems)
  1025. {
  1026. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  1027.  
  1028. for (int i = this.roomItems.size(); i-- > 0; )
  1029. {
  1030. try
  1031. {
  1032. iterator.advance();
  1033.  
  1034. if (iterator.value().needsUpdate())
  1035. iterator.value().run();
  1036. } catch (NoSuchElementException e)
  1037. {
  1038. break;
  1039. }
  1040. }
  1041. }
  1042.  
  1043. if (this.roomSpecialTypes != null)
  1044. {
  1045. this.roomSpecialTypes.dispose();
  1046. }
  1047.  
  1048. synchronized (this.roomItems)
  1049. {
  1050. this.roomItems.clear();
  1051. }
  1052.  
  1053. synchronized (this.habboQueue)
  1054. {
  1055. this.habboQueue.clear();
  1056. }
  1057.  
  1058. // SAFE
  1059.  
  1060.  
  1061. for (Habbo habbo : this.currentHabbos.values())
  1062. {
  1063. Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this);
  1064. }
  1065.  
  1066. this.sendComposer(new HotelViewComposer().compose());
  1067.  
  1068. this.currentHabbos.clear();
  1069.  
  1070.  
  1071. TIntObjectIterator<Bot> botIterator = this.currentBots.iterator();
  1072.  
  1073. for (int i = this.currentBots.size(); i-- > 0; )
  1074. {
  1075. try
  1076. {
  1077. botIterator.advance();
  1078. botIterator.value().needsUpdate(true);
  1079. Emulator.getThreading().run(botIterator.value());
  1080. } catch (NoSuchElementException e)
  1081. {
  1082. Emulator.getLogging().logErrorLine(e);
  1083. break;
  1084. }
  1085. }
  1086.  
  1087. TIntObjectIterator<Pet> petIterator = this.currentPets.iterator();
  1088. for (int i = this.currentPets.size(); i-- > 0; )
  1089. {
  1090. try
  1091. {
  1092. petIterator.advance();
  1093. petIterator.value().needsUpdate = true;
  1094. Emulator.getThreading().run(petIterator.value());
  1095. }
  1096. catch (NoSuchElementException e)
  1097. {
  1098. Emulator.getLogging().logErrorLine(e);
  1099. break;
  1100. }
  1101. }
  1102.  
  1103. this.currentBots.clear();
  1104. this.currentPets.clear();
  1105. } catch (Exception e)
  1106. {
  1107. Emulator.getLogging().logErrorLine(e);
  1108. }
  1109. }
  1110.  
  1111. this.wordQuiz = "";
  1112. this.yesVotes = 0;
  1113. this.noVotes = 0;
  1114. this.updateDatabaseUserCount();
  1115. this.preLoaded = true;
  1116. this.layout = null;
  1117. }
  1118.  
  1119. Emulator.getPluginManager().fireEvent(new RoomUnloadedEvent(this));
  1120. }
  1121.  
  1122. @SuppressWarnings("NullableProblems")
  1123. @Override
  1124. public int compareTo(Room o)
  1125. {
  1126. if (o.getUserCount() != this.getUserCount())
  1127. {
  1128. return o.getCurrentHabbos().size() - this.getCurrentHabbos().size();
  1129. }
  1130.  
  1131. return this.id - o.id ;
  1132. }
  1133.  
  1134. @Override
  1135. public void serialize(ServerMessage message)
  1136. {
  1137. message.appendInt(this.id);
  1138. message.appendString(this.name);
  1139. if(this.isPublicRoom())
  1140. {
  1141. message.appendInt(0);
  1142. message.appendString("");
  1143. }
  1144. else
  1145. {
  1146. message.appendInt(this.ownerId);
  1147. message.appendString(this.ownerName);
  1148. }
  1149. message.appendInt(this.state.getState());
  1150. message.appendInt(this.getUserCount());
  1151. message.appendInt(this.usersMax);
  1152. message.appendString(this.description);
  1153. message.appendInt(0);
  1154. message.appendInt(this.score);
  1155. message.appendInt(0);
  1156. message.appendInt(this.category);
  1157. message.appendInt(this.tags.split(";").length);
  1158. for(String s : this.tags.split(";"))
  1159. {
  1160. message.appendString(s);
  1161. }
  1162.  
  1163. int base = 0;
  1164.  
  1165. if(this.getGuildId() > 0)
  1166. {
  1167. base = base | 2;
  1168. }
  1169.  
  1170. if (this.isPromoted())
  1171. {
  1172. base = base | 4;
  1173. }
  1174.  
  1175. if(!this.isPublicRoom())
  1176. {
  1177. base = base | 8;
  1178. }
  1179.  
  1180. // if (this.allowPets)
  1181. // {
  1182. // base = base | 16;
  1183. // }
  1184.  
  1185. message.appendInt(base);
  1186.  
  1187.  
  1188. if(this.getGuildId() > 0)
  1189. {
  1190. Guild g = Emulator.getGameEnvironment().getGuildManager().getGuild(this.getGuildId());
  1191. if (g != null)
  1192. {
  1193. message.appendInt(g.getId());
  1194. message.appendString(g.getName());
  1195. message.appendString(g.getBadge());
  1196. }
  1197. else
  1198. {
  1199. message.appendInt(0);
  1200. message.appendString("");
  1201. message.appendString("");
  1202. }
  1203. }
  1204.  
  1205. if(this.promoted)
  1206. {
  1207. message.appendString(this.promotion.getTitle());
  1208. message.appendString(this.promotion.getDescription());
  1209. message.appendInt((this.promotion.getEndTimestamp() - Emulator.getIntUnixTimestamp()) / 60);
  1210. }
  1211.  
  1212. }
  1213.  
  1214. public static final Comparator SORT_SCORE = new Comparator() {
  1215. @Override
  1216. public int compare(Object o1, Object o2) {
  1217.  
  1218. if (!(o1 instanceof Room && o2 instanceof Room))
  1219. return 0;
  1220.  
  1221. return ((Room) o2).getScore() - ((Room) o1).getScore();
  1222. }
  1223. };
  1224.  
  1225. public static final Comparator SORT_ID = new Comparator() {
  1226. @Override
  1227. public int compare(Object o1, Object o2) {
  1228.  
  1229. if (!(o1 instanceof Room && o2 instanceof Room))
  1230. return 0;
  1231.  
  1232. return ((Room) o2).getId() - ((Room) o1).getId();
  1233. }
  1234. };
  1235.  
  1236. @Override
  1237. public void run()
  1238. {
  1239. long millis = System.currentTimeMillis();
  1240.  
  1241. synchronized (this.loadLock)
  1242. {
  1243. if (this.loaded)
  1244. {
  1245. try
  1246. {
  1247. Emulator.getThreading().run(
  1248. new Runnable()
  1249. {
  1250. @Override
  1251. public void run()
  1252. {
  1253. Room.this.cycle();
  1254. }
  1255. });
  1256. }
  1257. catch (Exception e)
  1258. {
  1259. Emulator.getLogging().logErrorLine(e);
  1260. }
  1261. }
  1262. }
  1263.  
  1264. this.save();
  1265. }
  1266.  
  1267. public void save()
  1268. {
  1269. if(this.needsUpdate)
  1270. {
  1271. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE rooms SET name = ?, description = ?, password = ?, state = ?, users_max = ?, category = ?, score = ?, paper_floor = ?, paper_wall = ?, paper_landscape = ?, thickness_wall = ?, wall_height = ?, thickness_floor = ?, moodlight_data = ?, tags = ?, allow_other_pets = ?, allow_other_pets_eat = ?, allow_walkthrough = ?, allow_hidewall = ?, chat_mode = ?, chat_weight = ?, chat_speed = ?, chat_hearing_distance = ?, chat_protection =?, who_can_mute = ?, who_can_kick = ?, who_can_ban = ?, poll_id = ?, guild_id = ?, roller_speed = ?, override_model = ?, is_staff_picked = ?, promoted = ?, trade_mode = ?, move_diagonally = ?, owner_id = ?, owner_name = ?, jukebox_active = ?, hidewired = ? WHERE id = ?"))
  1272. {
  1273. statement.setString(1, this.name);
  1274. statement.setString(2, this.description);
  1275. statement.setString(3, this.password);
  1276. statement.setString(4, this.state.name().toLowerCase());
  1277. statement.setInt(5, this.usersMax);
  1278. statement.setInt(6, this.category);
  1279. statement.setInt(7, this.score);
  1280. statement.setString(8, this.floorPaint);
  1281. statement.setString(9, this.wallPaint);
  1282. statement.setString(10, this.backgroundPaint);
  1283. statement.setInt(11, this.wallSize);
  1284. statement.setInt(12, this.wallHeight);
  1285. statement.setInt(13, this.floorSize);
  1286. StringBuilder moodLightData = new StringBuilder();
  1287.  
  1288. int id = 1;
  1289. for(RoomMoodlightData data : this.moodlightData.valueCollection())
  1290. {
  1291. data.setId(id);
  1292. moodLightData.append(data.toString()).append(";");
  1293. id++;
  1294. }
  1295.  
  1296. statement.setString(14, moodLightData.toString());
  1297. statement.setString(15, this.tags);
  1298. statement.setString(16, this.allowPets ? "1" : "0");
  1299. statement.setString(17, this.allowPetsEat ? "1" : "0");
  1300. statement.setString(18, this.allowWalkthrough ? "1" : "0");
  1301. statement.setString(19, this.hideWall ? "1" : "0");
  1302. statement.setInt(20, this.chatMode);
  1303. statement.setInt(21, this.chatWeight);
  1304. statement.setInt(22, this.chatSpeed);
  1305. statement.setInt(23, this.chatDistance);
  1306. statement.setInt(24, this.chatProtection);
  1307. statement.setInt(25, this.muteOption);
  1308. statement.setInt(26, this.kickOption);
  1309. statement.setInt(27, this.banOption);
  1310. statement.setInt(28, this.pollId);
  1311. statement.setInt(29, this.guild);
  1312. statement.setInt(30, this.rollerSpeed);
  1313. statement.setString(31, this.overrideModel ? "1" : "0");
  1314. statement.setString(32, this.staffPromotedRoom ? "1" : "0");
  1315. statement.setString(33, this.promoted ? "1" : "0");
  1316. statement.setInt(34, this.tradeMode);
  1317. statement.setString(35, this.moveDiagonally ? "1" : "0");
  1318. statement.setInt(36, this.ownerId);
  1319. statement.setString(37, this.ownerName);
  1320. statement.setString(38, this.jukeboxActive ? "1" : "0");
  1321. statement.setString(39, this.hideWired ? "1" : "0");
  1322. statement.setInt(40, this.id);
  1323. statement.executeUpdate();
  1324. this.needsUpdate = false;
  1325. }
  1326. catch(SQLException e)
  1327. {
  1328. Emulator.getLogging().logSQLException(e);
  1329. }
  1330. }
  1331. }
  1332.  
  1333. private void updateDatabaseUserCount()
  1334. {
  1335. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE rooms SET users = ? WHERE id = ? LIMIT 1"))
  1336. {
  1337. statement.setInt(1, this.currentHabbos.size());
  1338. statement.setInt(2, this.id);
  1339. statement.executeUpdate();
  1340. }
  1341. catch (SQLException e)
  1342. {
  1343. Emulator.getLogging().logSQLException(e);
  1344. }
  1345. }
  1346.  
  1347. private void cycle()
  1348. {
  1349. this.cycleTimestamp = System.currentTimeMillis();
  1350. final boolean[] foundRightHolder = {false};
  1351.  
  1352.  
  1353. boolean loaded;
  1354. synchronized (this.loadLock)
  1355. {
  1356. loaded = this.loaded;
  1357. }
  1358. this.tileCache.clear();
  1359. if(loaded)
  1360. {
  1361. if (!this.scheduledTasks.isEmpty())
  1362. {
  1363. ConcurrentSet<Runnable> tasks = this.scheduledTasks;
  1364. this.scheduledTasks = new ConcurrentSet<>();
  1365.  
  1366. for (Runnable runnable : tasks)
  1367. {
  1368. Emulator.getThreading().run(runnable);
  1369. }
  1370. }
  1371.  
  1372. for (ICycleable task : this.roomSpecialTypes.getCycleTasks())
  1373. {
  1374. task.cycle(this);
  1375. }
  1376.  
  1377. if (!this.currentHabbos.isEmpty())
  1378. {
  1379. this.idleCycles = 0;
  1380.  
  1381. THashSet<RoomUnit> updatedUnit = new THashSet<>();
  1382. ArrayList<Habbo> toKick = new ArrayList<>();
  1383.  
  1384. final Room room = this;
  1385.  
  1386. final long millis = System.currentTimeMillis();
  1387. if(this.rollerSpeed != -1 && this.rollerCycle >= this.rollerSpeed)
  1388. {
  1389. this.rollerCycle = 0;
  1390.  
  1391. THashSet<MessageComposer> messages = new THashSet<>();
  1392.  
  1393. //Find alternative for this.
  1394. //Reason is that tile gets updated after every roller.
  1395. List<Integer> rollerFurniIds = new ArrayList<>();
  1396. List<Integer> rolledUnitIds = new ArrayList<>();
  1397.  
  1398. this.roomSpecialTypes.getRollers().forEachValue(new TObjectProcedure<InteractionRoller>()
  1399. {
  1400. @Override
  1401. public boolean execute(InteractionRoller roller)
  1402. {
  1403. //if(Double.compare(roller.getZ(), this.layout.getHeightAtSquare(roller.getX(), roller.getY())) != 0)
  1404. // {
  1405. // continue;
  1406. //}
  1407.  
  1408. HabboItem newRoller = null;
  1409.  
  1410. THashSet<Habbo> habbosOnRoller = Room.this.getHabbosAt(roller.getX(), roller.getY());
  1411. THashSet<HabboItem> itemsOnRoller = new THashSet<>(getItemsAt(roller.getX(), roller.getY()));
  1412.  
  1413. itemsOnRoller.remove(roller);
  1414.  
  1415. if (habbosOnRoller.isEmpty())
  1416. {
  1417. if (itemsOnRoller.isEmpty())
  1418. return true;
  1419. }
  1420.  
  1421. RoomTile tileInFront = Room.this.layout.getTileInFront(Room.this.layout.getTile(roller.getX(), roller.getY()), roller.getRotation());
  1422. RoomTile rollerTile = Room.this.layout.getTile(roller.getX(), roller.getY());
  1423.  
  1424. if (tileInFront == null)
  1425. return true;
  1426.  
  1427. if (!InteractionRoller.NO_RULES && roller.getZ() != rollerTile.z)
  1428. return true;
  1429.  
  1430. if (!Room.this.layout.tileExists(tileInFront.x, tileInFront.y))
  1431. return true;
  1432.  
  1433. if (tileInFront.state == RoomTileState.INVALID)
  1434. return true;
  1435.  
  1436. if (!tileInFront.getAllowStack() && !(tileInFront.isWalkable() || tileInFront.state == RoomTileState.SIT || tileInFront.state == RoomTileState.LAY))
  1437. return true;
  1438.  
  1439. if (tileInFront.getStackHeight() > Item.getCurrentHeight(roller) + rollerTile.z)
  1440. return true;
  1441.  
  1442. if (Room.this.hasHabbosAt(tileInFront.x, tileInFront.y))
  1443. return true;
  1444.  
  1445. THashSet<HabboItem> itemsNewTile = new THashSet<>(getItemsAt(tileInFront.x, tileInFront.y));
  1446. itemsNewTile.removeAll(itemsOnRoller);
  1447. List<HabboItem> toRemove = new ArrayList<>();
  1448. for (HabboItem item : itemsOnRoller)
  1449. {
  1450. if (item.getX() != roller.getX() || item.getY() != roller.getY() || rollerFurniIds.contains(item.getId()))
  1451. {
  1452. toRemove.add(item);
  1453. }
  1454. }
  1455. itemsOnRoller.removeAll(toRemove);
  1456. HabboItem topItem = Room.this.getTopItemAt(tileInFront.x, tileInFront.y);
  1457.  
  1458. boolean allowUsers = true;
  1459. boolean allowFurniture = true;
  1460. boolean stackContainsRoller = false;
  1461.  
  1462. for (HabboItem item : itemsNewTile)
  1463. {
  1464. if (!(item.getBaseItem().allowWalk() || item.getBaseItem().allowSit()) && !(item instanceof InteractionGate && item.getExtradata().equals("1")))
  1465. {
  1466. allowUsers = false;
  1467. }
  1468. if (item instanceof InteractionRoller)
  1469. {
  1470. newRoller = item;
  1471. stackContainsRoller = true;
  1472.  
  1473. if ((item.getZ() != roller.getZ() || (itemsNewTile.size() > 1 && item != topItem)) && !InteractionRoller.NO_RULES)
  1474. {
  1475. allowUsers = false;
  1476. allowFurniture = false;
  1477. continue;
  1478. }
  1479.  
  1480. break;
  1481. } else
  1482. {
  1483. allowFurniture = false;
  1484. }
  1485. }
  1486.  
  1487. if (allowFurniture)
  1488. {
  1489. allowFurniture = tileInFront.getAllowStack();
  1490. }
  1491.  
  1492. double zOffset = 0;
  1493. if (newRoller != null)
  1494. {
  1495. if ((!itemsNewTile.isEmpty() && (itemsNewTile.size() > 1)) && !InteractionRoller.NO_RULES)
  1496. {
  1497. return true;
  1498. }
  1499. }
  1500. else
  1501. {
  1502. zOffset = -roller.getBaseItem().getHeight() + tileInFront.getStackHeight() - rollerTile.z;
  1503. }
  1504.  
  1505. if (allowUsers)
  1506. {
  1507. Event roomUserRolledEvent = null;
  1508.  
  1509. if (Emulator.getPluginManager().isRegistered(UserRolledEvent.class, true))
  1510. {
  1511. roomUserRolledEvent = new UserRolledEvent(null, null, null);
  1512. }
  1513.  
  1514. for (Habbo habbo : habbosOnRoller)
  1515. {
  1516. if (rolledUnitIds.contains(habbo.getRoomUnit().getId())) continue;
  1517.  
  1518. rolledUnitIds.add(habbo.getRoomUnit().getId());
  1519.  
  1520. if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable()))
  1521. continue;
  1522.  
  1523. if (!habbo.getRoomUnit().hasStatus(RoomUnitStatus.MOVE))
  1524. {
  1525. RoomTile tile = tileInFront.copy();
  1526. tile.setStackHeight(habbo.getRoomUnit().getZ() + zOffset);
  1527. if (roomUserRolledEvent != null)
  1528. {
  1529. roomUserRolledEvent = new UserRolledEvent(habbo, roller, tile);
  1530. Emulator.getPluginManager().fireEvent(roomUserRolledEvent);
  1531.  
  1532. if (roomUserRolledEvent.isCancelled())
  1533. continue;
  1534. }
  1535.  
  1536. messages.add(new RoomUnitOnRollerComposer(habbo.getRoomUnit(), roller, habbo.getRoomUnit().getCurrentLocation(), habbo.getRoomUnit().getZ(), tile, tile.getStackHeight(), room));
  1537.  
  1538. if (itemsOnRoller.isEmpty())
  1539. {
  1540. HabboItem item = room.getTopItemAt(tileInFront.x, tileInFront.y);
  1541.  
  1542. if (item != null && itemsNewTile.contains(item))
  1543. {
  1544. try
  1545. {
  1546. item.onWalkOn(habbo.getRoomUnit(), room, null);
  1547. } catch (Exception e)
  1548. {
  1549. Emulator.getLogging().logErrorLine(e);
  1550. }
  1551. }
  1552. }
  1553. }
  1554.  
  1555. if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT))
  1556. habbo.getRoomUnit().sitUpdate = true;
  1557.  
  1558. break;
  1559. }
  1560. }
  1561.  
  1562. if (!messages.isEmpty())
  1563. {
  1564. for (MessageComposer message : messages)
  1565. {
  1566. room.sendComposer(message.compose());
  1567. }
  1568. messages.clear();
  1569. }
  1570.  
  1571. if ((allowFurniture || !stackContainsRoller) && !InteractionRoller.NO_RULES)
  1572. {
  1573. Event furnitureRolledEvent = null;
  1574.  
  1575. if (Emulator.getPluginManager().isRegistered(FurnitureRolledEvent.class, true))
  1576. {
  1577. furnitureRolledEvent = new FurnitureRolledEvent(null, null, null);
  1578. }
  1579.  
  1580. if (newRoller == null || topItem == newRoller)
  1581. {
  1582. List<HabboItem> sortedItems = new ArrayList<>(itemsOnRoller);
  1583. sortedItems.sort(new Comparator<HabboItem>()
  1584. {
  1585. @Override
  1586. public int compare(HabboItem o1, HabboItem o2)
  1587. {
  1588. return o1.getZ() > o2.getZ() ? -1 : 1;
  1589. }
  1590. });
  1591.  
  1592. for (HabboItem item : sortedItems)
  1593. {
  1594. if (item.getX() == roller.getX() && item.getY() == roller.getY() && zOffset <= 0)
  1595. {
  1596. if (item != roller)
  1597. {
  1598. if (furnitureRolledEvent != null)
  1599. {
  1600. furnitureRolledEvent = new FurnitureRolledEvent(item, roller, tileInFront);
  1601. Emulator.getPluginManager().fireEvent(furnitureRolledEvent);
  1602.  
  1603. if (furnitureRolledEvent.isCancelled())
  1604. continue;
  1605. }
  1606.  
  1607. messages.add(new FloorItemOnRollerComposer(item, roller, tileInFront, zOffset, room));
  1608. rollerFurniIds.add(item.getId());
  1609. }
  1610. }
  1611. }
  1612. }
  1613. }
  1614.  
  1615.  
  1616. if (!messages.isEmpty())
  1617. {
  1618. for (MessageComposer message : messages)
  1619. {
  1620. room.sendComposer(message.compose());
  1621. }
  1622. messages.clear();
  1623. }
  1624.  
  1625. return true;
  1626. }
  1627. });
  1628.  
  1629.  
  1630. int currentTime = (int) (this.cycleTimestamp / 1000);
  1631. for(HabboItem pyramid : this.roomSpecialTypes.getItemsOfType(InteractionPyramid.class))
  1632. {
  1633. if(pyramid instanceof InteractionPyramid)
  1634. {
  1635.  
  1636. if(((InteractionPyramid) pyramid).getNextChange() < currentTime)
  1637. {
  1638. ((InteractionPyramid) pyramid).change(this);
  1639. }
  1640. }
  1641. }
  1642. }
  1643. else
  1644. {
  1645. this.rollerCycle++;
  1646. }
  1647.  
  1648. for (Habbo habbo : this.currentHabbos.values())
  1649. {
  1650. if (!foundRightHolder[0])
  1651. {
  1652. foundRightHolder[0] = habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE;
  1653. }
  1654.  
  1655. if (habbo.getRoomUnit().getHandItem() > 0 && millis - habbo.getRoomUnit().getHandItemTimestamp() > (Room.HAND_ITEM_TIME * 1000))
  1656. {
  1657. this.giveHandItem(habbo, 0);
  1658. }
  1659.  
  1660. if (habbo.getRoomUnit().getEffectId() > 0 && millis / 1000 > habbo.getRoomUnit().getEffectEndTimestamp())
  1661. {
  1662. this.giveEffect(habbo, 0, -1);
  1663. }
  1664.  
  1665. if (habbo.getRoomUnit().isKicked)
  1666. {
  1667. habbo.getRoomUnit().kickCount++;
  1668.  
  1669. if (habbo.getRoomUnit().kickCount >= 5)
  1670. {
  1671. this.scheduledTasks.add(new Runnable()
  1672. {
  1673. @Override
  1674. public void run()
  1675. {
  1676. Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, room);
  1677. }
  1678. });
  1679. continue;
  1680. }
  1681. }
  1682.  
  1683. if (Emulator.getConfig().getBoolean("hotel.rooms.auto.idle"))
  1684. {
  1685. if (!habbo.getRoomUnit().isIdle())
  1686. {
  1687. habbo.getRoomUnit().increaseIdleTimer();
  1688.  
  1689. if (habbo.getRoomUnit().isIdle())
  1690. {
  1691. this.sendComposer(new RoomUnitIdleComposer(habbo.getRoomUnit()).compose());
  1692. }
  1693. }
  1694. else
  1695. {
  1696. habbo.getRoomUnit().increaseIdleTimer();
  1697.  
  1698. if (!this.isOwner(habbo) && habbo.getRoomUnit().getIdleTimer() >= Room.IDLE_CYCLES_KICK)
  1699. {
  1700. UserExitRoomEvent event = new UserExitRoomEvent(habbo, UserExitRoomEvent.UserExitRoomReason.KICKED_IDLE);
  1701. Emulator.getPluginManager().fireEvent(event);
  1702.  
  1703. if (!event.isCancelled())
  1704. {
  1705. toKick.add(habbo);
  1706. }
  1707. }
  1708. }
  1709. }
  1710.  
  1711. if (habbo.getHabboStats().mutedBubbleTracker && habbo.getHabboStats().allowTalk())
  1712. {
  1713. habbo.getHabboStats().mutedBubbleTracker = false;
  1714. this.sendComposer(new RoomUserIgnoredComposer(habbo, RoomUserIgnoredComposer.UNIGNORED).compose());
  1715. }
  1716. if (!habbo.hasPermission("acc_chat_no_flood") && habbo.getHabboStats().chatCounter > 0)
  1717. {
  1718. //if (habbo.getRoomUnit().talkTimeOut == 0 || currentTimestamp - habbo.getRoomUnit().talkTimeOut < 0)
  1719. {
  1720. habbo.getHabboStats().chatCounter--;
  1721.  
  1722. if (habbo.getHabboStats().chatCounter > 3 && !this.hasRights(habbo))
  1723. {
  1724. if (this.chatProtection == 0)
  1725. {
  1726. this.floodMuteHabbo(habbo, 30);
  1727. }
  1728. else if (this.chatProtection == 1 && habbo.getHabboStats().chatCounter > 4)
  1729. {
  1730. this.floodMuteHabbo(habbo, 30);
  1731. }
  1732. else if (this.chatProtection == 2 && habbo.getHabboStats().chatCounter > 5)
  1733. {
  1734. this.floodMuteHabbo(habbo, 30);
  1735. }
  1736. }
  1737. }
  1738. }
  1739. else
  1740. {
  1741. habbo.getHabboStats().chatCounter = 0;
  1742. }
  1743.  
  1744. if (this.cycleRoomUnit(habbo.getRoomUnit(), RoomUnitType.USER))
  1745. {
  1746. updatedUnit.add(habbo.getRoomUnit());
  1747. }
  1748. }
  1749.  
  1750. if(!toKick.isEmpty())
  1751. {
  1752. for(Habbo habbo : toKick)
  1753. {
  1754. Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this);
  1755. }
  1756. }
  1757.  
  1758. if (!this.currentBots.isEmpty())
  1759. {
  1760. TIntObjectIterator<Bot> botIterator = this.currentBots.iterator();
  1761. for (int i = this.currentBots.size(); i-- > 0; )
  1762. {
  1763. try
  1764. {
  1765. final Bot bot;
  1766. try
  1767. {
  1768. botIterator.advance();
  1769. bot = botIterator.value();
  1770. }
  1771. catch (Exception e)
  1772. {
  1773. break;
  1774. }
  1775.  
  1776. if (!this.allowBotsWalk && bot.getRoomUnit().isWalking())
  1777. {
  1778. bot.getRoomUnit().stopWalking();
  1779. updatedUnit.add(bot.getRoomUnit());
  1780. continue;
  1781. }
  1782.  
  1783. botIterator.value().cycle(this.allowBotsWalk);
  1784.  
  1785.  
  1786. if (this.cycleRoomUnit(bot.getRoomUnit(), RoomUnitType.BOT))
  1787. {
  1788. updatedUnit.add(bot.getRoomUnit());
  1789. }
  1790.  
  1791. /*if (!bot.getRoomUnit().isWalking())
  1792. {
  1793. if (bot.getRoomUnit().hasStatus(RoomUnitStatus.MOVE))
  1794. {
  1795. bot.getRoomUnit().removeStatus(RoomUnitStatus.MOVE);
  1796.  
  1797. updatedUnit.add(bot.getRoomUnit());
  1798. }
  1799.  
  1800. if (!bot.getRoomUnit().isWalking() && !bot.getRoomUnit().cmdSit)
  1801. {
  1802. HabboItem topItem = this.getLowestChair(bot.getRoomUnit().getX(), bot.getRoomUnit().getY());
  1803.  
  1804. if (topItem == null || !topItem.getBaseItem().allowSit())
  1805. {
  1806. if (bot.getRoomUnit().hasStatus(RoomUnitStatus.SIT))
  1807. {
  1808. bot.getRoomUnit().removeStatus(RoomUnitStatus.SIT);
  1809. updatedUnit.add(bot.getRoomUnit());
  1810. }
  1811. }
  1812. else
  1813. {
  1814. if (!bot.getRoomUnit().hasStatus(RoomUnitStatus.SIT))
  1815. {
  1816. if (topItem instanceof InteractionMultiHeight)
  1817. {
  1818. bot.getRoomUnit().setStatus(RoomUnitStatus.SIT, Item.getCurrentHeight(topItem) * 1.0D + "");
  1819. } else
  1820. {
  1821. bot.getRoomUnit().setStatus(RoomUnitStatus.SIT, topItem.getBaseItem().getHeight() * 1.0D + "");
  1822. }
  1823. bot.getRoomUnit().setRotation(RoomUserRotation.values()[topItem.getRotation()]);
  1824. updatedUnit.add(bot.getRoomUnit());
  1825. }
  1826. }
  1827. }
  1828. }
  1829.  
  1830. if (!bot.getRoomUnit().isWalking() && !bot.getRoomUnit().cmdLay)
  1831. {
  1832. HabboItem topItem = this.getTopItemAt(bot.getRoomUnit().getX(), bot.getRoomUnit().getY());
  1833.  
  1834. if (topItem == null || !topItem.getBaseItem().allowLay())
  1835. {
  1836. if (bot.getRoomUnit().hasStatus(RoomUnitStatus.LAY))
  1837. {
  1838. bot.getRoomUnit().removeStatus(RoomUnitStatus.LAY);
  1839. updatedUnit.add(bot.getRoomUnit());
  1840. }
  1841. } else
  1842. {
  1843. if (!bot.getRoomUnit().hasStatus(RoomUnitStatus.LAY))
  1844. {
  1845. if (topItem instanceof InteractionMultiHeight)
  1846. {
  1847. bot.getRoomUnit().setStatus(RoomUnitStatus.LAY, Item.getCurrentHeight(topItem) * 1.0D + "");
  1848. } else
  1849. {
  1850. bot.getRoomUnit().setStatus(RoomUnitStatus.LAY, topItem.getBaseItem().getHeight() * 1.0D + "");
  1851. }
  1852. bot.getRoomUnit().setRotation(RoomUserRotation.values()[topItem.getRotation()]);
  1853. bot.getRoomUnit().setLocation(this.layout.getTile(topItem.getX(), topItem.getY()));
  1854. updatedUnit.add(bot.getRoomUnit());
  1855. }
  1856. }
  1857. }
  1858.  
  1859. if (!botIterator.value().getRoomUnit().cycle(this))
  1860. updatedUnit.add(botIterator.value().getRoomUnit());*/
  1861. }
  1862. catch (NoSuchElementException e)
  1863. {
  1864. Emulator.getLogging().logErrorLine(e);
  1865. break;
  1866. }
  1867. }
  1868. }
  1869.  
  1870. if (!this.currentPets.isEmpty())
  1871. {
  1872. if (this.allowBotsWalk)
  1873. {
  1874. TIntObjectIterator<Pet> petIterator = this.currentPets.iterator();
  1875. for (int i = this.currentPets.size(); i-- > 0; )
  1876. {
  1877. try
  1878. {
  1879. petIterator.advance();
  1880. }
  1881. catch (NoSuchElementException e)
  1882. {
  1883. Emulator.getLogging().logErrorLine(e);
  1884. break;
  1885. }
  1886.  
  1887. Pet pet = petIterator.value();
  1888. if (this.cycleRoomUnit(pet.getRoomUnit(), RoomUnitType.PET))
  1889. {
  1890. updatedUnit.add(pet.getRoomUnit());
  1891. }
  1892.  
  1893. pet.cycle();
  1894.  
  1895. if (pet.packetUpdate)
  1896. {
  1897. updatedUnit.add(pet.getRoomUnit());
  1898. pet.packetUpdate = false;
  1899. }
  1900.  
  1901. if (pet.getTask() == PetTasks.RIDE)
  1902. {
  1903. if (pet instanceof HorsePet)
  1904. {
  1905. HorsePet horse = ((HorsePet) pet);
  1906. if (horse.getRider() != null)
  1907. {
  1908. if (!horse.getRider().getRoomUnit().getCurrentLocation().equals(horse.getRoomUnit().getCurrentLocation()))
  1909. {
  1910. horse.getRoomUnit().setGoalLocation(horse.getRider().getRoomUnit().getCurrentLocation());
  1911. }
  1912. }
  1913. }
  1914. }
  1915.  
  1916. if (pet.getRoomUnit().isWalking() && pet.getRoomUnit().getPath().size() == 1 && pet.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE))
  1917. {
  1918. pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE);
  1919. updatedUnit.add(pet.getRoomUnit());
  1920. }
  1921. }
  1922. }
  1923. }
  1924.  
  1925.  
  1926. if(!updatedUnit.isEmpty())
  1927. {
  1928. this.sendComposer(new RoomUserStatusComposer(updatedUnit, true).compose());
  1929. }
  1930.  
  1931. this.traxManager.cycle();
  1932. }
  1933. else
  1934. {
  1935.  
  1936. if(this.idleCycles < 60)
  1937. this.idleCycles++;
  1938. else
  1939. this.dispose();
  1940. }
  1941. }
  1942.  
  1943. synchronized (this.habboQueue)
  1944. {
  1945. if (!this.habboQueue.isEmpty() && !foundRightHolder[0])
  1946. {
  1947. this.habboQueue.forEachEntry(new TIntObjectProcedure<Habbo>()
  1948. {
  1949. @Override
  1950. public boolean execute(int a, Habbo b)
  1951. {
  1952. if (b.isOnline())
  1953. {
  1954. if (b.getHabboInfo().getRoomQueueId() == Room.this.getId())
  1955. {
  1956. b.getClient().sendResponse(new RoomAccessDeniedComposer(""));
  1957. }
  1958. }
  1959.  
  1960. return true;
  1961. }
  1962. });
  1963.  
  1964. this.habboQueue.clear();
  1965. }
  1966. }
  1967.  
  1968. if (!this.scheduledComposers.isEmpty())
  1969. {
  1970. for (ServerMessage message : this.scheduledComposers)
  1971. {
  1972. this.sendComposer(message);
  1973. }
  1974.  
  1975. this.scheduledComposers.clear();
  1976. }
  1977. }
  1978.  
  1979.  
  1980. private boolean cycleRoomUnit(RoomUnit unit, RoomUnitType type)
  1981. {
  1982. boolean update = unit.needsStatusUpdate();
  1983. if (unit.hasStatus(RoomUnitStatus.SIGN))
  1984. {
  1985. this.sendComposer(new RoomUserStatusComposer(unit).compose());
  1986. unit.removeStatus(RoomUnitStatus.SIGN);
  1987. }
  1988.  
  1989. if (unit.isWalking() && unit.getPath() != null && !unit.getPath().isEmpty())
  1990. {
  1991. if (!unit.cycle(this))
  1992. {
  1993. return true;
  1994. }
  1995. }
  1996. else
  1997. {
  1998. if (unit.hasStatus(RoomUnitStatus.MOVE) && !unit.animateWalk)
  1999. {
  2000. unit.removeStatus(RoomUnitStatus.MOVE);
  2001.  
  2002. update = true;
  2003. }
  2004.  
  2005. if (!unit.isWalking() && !unit.cmdSit)
  2006. {
  2007. HabboItem topItem = this.getLowestChair(unit.getX(), unit.getY());
  2008.  
  2009. if (topItem == null || !topItem.getBaseItem().allowSit())
  2010. {
  2011. if (unit.hasStatus(RoomUnitStatus.SIT))
  2012. {
  2013. unit.removeStatus(RoomUnitStatus.SIT);
  2014. update = true;
  2015. }
  2016. }
  2017. else
  2018. {
  2019. if (!unit.hasStatus(RoomUnitStatus.SIT) || unit.sitUpdate)
  2020. {
  2021. this.dance(unit, DanceType.NONE);
  2022. int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z;
  2023. if (topItem instanceof InteractionMultiHeight)
  2024. {
  2025. unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem) * 1.0D) + "");
  2026. }
  2027. else
  2028. {
  2029. unit.setStatus(RoomUnitStatus.SIT, (topItem.getBaseItem().getHeight() * 1.0D) + "");
  2030. }
  2031. unit.setPreviousLocationZ(topItem.getZ());
  2032. unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]);
  2033. unit.sitUpdate = false;
  2034. return true;
  2035. }
  2036. }
  2037. }
  2038. }
  2039.  
  2040. if (!unit.isWalking() && !unit.cmdLay)
  2041. {
  2042. HabboItem topItem = this.getTopItemAt(unit.getX(), unit.getY());
  2043.  
  2044. if (topItem == null || !topItem.getBaseItem().allowLay())
  2045. {
  2046. if (unit.hasStatus(RoomUnitStatus.LAY))
  2047. {
  2048. unit.removeStatus(RoomUnitStatus.LAY);
  2049. update = true;
  2050. }
  2051. }
  2052. else
  2053. {
  2054. if (!unit.hasStatus(RoomUnitStatus.LAY))
  2055. {
  2056. if (topItem instanceof InteractionMultiHeight)
  2057. {
  2058. unit.setStatus(RoomUnitStatus.LAY, Item.getCurrentHeight(topItem) * 1.0D + "");
  2059. }
  2060. else
  2061. {
  2062. unit.setStatus(RoomUnitStatus.LAY, topItem.getBaseItem().getHeight() * 1.0D + "");
  2063. }
  2064. unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]);
  2065.  
  2066. if (topItem.getRotation() == 0 || topItem.getRotation() == 4)
  2067. {
  2068. unit.setLocation(this.layout.getTile(unit.getX(), topItem.getY()));
  2069. //unit.setOldY(topItem.getY());
  2070. }
  2071. else
  2072. {
  2073. unit.setLocation(this.layout.getTile(topItem.getX(), unit.getY()));
  2074. //unit.setOldX(topItem.getX());
  2075. }
  2076. update = true;
  2077. }
  2078. }
  2079. }
  2080.  
  2081. if (update)
  2082. {
  2083. unit.statusUpdate(false);
  2084. }
  2085.  
  2086. return update;
  2087. }
  2088.  
  2089. public int getId()
  2090. {
  2091. return this.id;
  2092. }
  2093.  
  2094. public int getOwnerId()
  2095. {
  2096. return this.ownerId;
  2097. }
  2098.  
  2099. public void setOwnerId(int ownerId)
  2100. {
  2101. this.ownerId = ownerId;
  2102. }
  2103.  
  2104. public String getOwnerName()
  2105. {
  2106. return this.ownerName;
  2107. }
  2108.  
  2109. public void setOwnerName(String ownerName)
  2110. {
  2111. this.ownerName = ownerName;
  2112. }
  2113.  
  2114. public String getName()
  2115. {
  2116. return this.name;
  2117. }
  2118.  
  2119. public String getDescription()
  2120. {
  2121. return this.description;
  2122. }
  2123.  
  2124. public RoomLayout getLayout()
  2125. {
  2126. return this.layout;
  2127. }
  2128.  
  2129. public void setLayout(RoomLayout layout)
  2130. {
  2131. this.layout = layout;
  2132. }
  2133.  
  2134. public boolean hasCustomLayout()
  2135. {
  2136. return this.overrideModel;
  2137. }
  2138.  
  2139. public void setHasCustomLayout(boolean overrideModel)
  2140. {
  2141. this.overrideModel = overrideModel;
  2142. }
  2143.  
  2144. public String getPassword()
  2145. {
  2146. return this.password;
  2147. }
  2148.  
  2149. public RoomState getState()
  2150. {
  2151. return this.state;
  2152. }
  2153.  
  2154. public int getUsersMax()
  2155. {
  2156. return this.usersMax;
  2157. }
  2158.  
  2159. public int getScore()
  2160. {
  2161. return this.score;
  2162. }
  2163.  
  2164. public int getCategory()
  2165. {
  2166. return this.category;
  2167. }
  2168.  
  2169. public String getFloorPaint()
  2170. {
  2171. return this.floorPaint;
  2172. }
  2173.  
  2174. public String getWallPaint()
  2175. {
  2176. return this.wallPaint;
  2177. }
  2178.  
  2179. public String getBackgroundPaint()
  2180. {
  2181. return this.backgroundPaint;
  2182. }
  2183.  
  2184. public int getWallSize()
  2185. {
  2186. return this.wallSize;
  2187. }
  2188.  
  2189. public int getWallHeight()
  2190. {
  2191. return this.wallHeight;
  2192. }
  2193.  
  2194. public void setWallHeight(int wallHeight)
  2195. {
  2196. this.wallHeight = wallHeight;
  2197. }
  2198.  
  2199. public int getFloorSize()
  2200. {
  2201. return this.floorSize;
  2202. }
  2203.  
  2204. public String getTags()
  2205. {
  2206. return this.tags;
  2207. }
  2208.  
  2209. public int getTradeMode()
  2210. {
  2211. return this.tradeMode;
  2212. }
  2213.  
  2214. public boolean moveDiagonally()
  2215. {
  2216. return this.moveDiagonally;
  2217. }
  2218.  
  2219. public void moveDiagonally(boolean moveDiagonally)
  2220. {
  2221. this.moveDiagonally = moveDiagonally;
  2222. this.layout.moveDiagonally(this.moveDiagonally);
  2223. this.needsUpdate = true;
  2224. }
  2225.  
  2226. public int getGuildId()
  2227. {
  2228. return this.guild;
  2229. }
  2230.  
  2231. public boolean hasGuild()
  2232. {
  2233. return this.guild != 0;
  2234. }
  2235.  
  2236. public void setGuild(int guild)
  2237. {
  2238. this.guild = guild;
  2239. }
  2240.  
  2241. public String getGuildName()
  2242. {
  2243. if (this.hasGuild())
  2244. {
  2245. Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guild);
  2246.  
  2247. if (guild != null)
  2248. {
  2249. return guild.getName();
  2250. }
  2251. }
  2252.  
  2253. return "";
  2254. }
  2255.  
  2256. public boolean isPublicRoom()
  2257. {
  2258. return this.publicRoom;
  2259. }
  2260.  
  2261.  
  2262. public void setPublicRoom(boolean publicRoom)
  2263. {
  2264. this.publicRoom = publicRoom;
  2265. }
  2266.  
  2267. public boolean isStaffPromotedRoom()
  2268. {
  2269. return this.staffPromotedRoom;
  2270. }
  2271.  
  2272. public void setStaffPromotedRoom(boolean staffPromotedRoom)
  2273. {
  2274. this.staffPromotedRoom = staffPromotedRoom;
  2275. }
  2276.  
  2277. public boolean isAllowPets()
  2278. {
  2279. return this.allowPets;
  2280. }
  2281.  
  2282. public boolean isAllowPetsEat()
  2283. {
  2284. return this.allowPetsEat;
  2285. }
  2286.  
  2287. public boolean isAllowWalkthrough()
  2288. {
  2289. return this.allowWalkthrough;
  2290. }
  2291.  
  2292. public boolean isAllowBotsWalk()
  2293. {
  2294. return this.allowBotsWalk;
  2295. }
  2296.  
  2297. public boolean isAllowEffects()
  2298. {
  2299. return this.allowEffects;
  2300. }
  2301.  
  2302. public void setAllowEffects(boolean allowEffects)
  2303. {
  2304. this.allowEffects = allowEffects;
  2305. }
  2306.  
  2307. public boolean isHideWall()
  2308. {
  2309. return this.hideWall;
  2310. }
  2311.  
  2312. public Color getBackgroundTonerColor()
  2313. {
  2314. Color color = new Color(0, 0, 0);
  2315. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  2316.  
  2317. for (int i = this.roomItems.size(); i > 0; i--)
  2318. {
  2319. try
  2320. {
  2321. iterator.advance();
  2322. HabboItem object = iterator.value();
  2323.  
  2324. if (object instanceof InteractionBackgroundToner)
  2325. {
  2326. String[] extraData = object.getExtradata().split(":");
  2327.  
  2328. if (extraData.length == 4)
  2329. {
  2330. if (extraData[0].equalsIgnoreCase("1"))
  2331. {
  2332. return Color.getHSBColor(Integer.valueOf(extraData[1]), Integer.valueOf(extraData[2]), Integer.valueOf(extraData[3]));
  2333. }
  2334. }
  2335. }
  2336. }
  2337. catch (Exception e)
  2338. {
  2339. }
  2340. }
  2341.  
  2342. return color;
  2343. }
  2344.  
  2345. public int getChatMode()
  2346. {
  2347. return this.chatMode;
  2348. }
  2349.  
  2350. public int getChatWeight()
  2351. {
  2352. return this.chatWeight;
  2353. }
  2354.  
  2355. public int getChatSpeed()
  2356. {
  2357. return this.chatSpeed;
  2358. }
  2359.  
  2360. public int getChatDistance()
  2361. {
  2362. return this.chatDistance;
  2363. }
  2364.  
  2365. public void setName(String name)
  2366. {
  2367. this.name = name;
  2368.  
  2369. if (this.name.length() > 50)
  2370. {
  2371. this.name = this.name.substring(0, 50);
  2372. }
  2373.  
  2374. if (this.hasGuild())
  2375. {
  2376. Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guild);
  2377.  
  2378. if (guild != null)
  2379. {
  2380. guild.setRoomName(name);
  2381. }
  2382. }
  2383. }
  2384.  
  2385. public void setDescription(String description)
  2386. {
  2387. this.description = description;
  2388.  
  2389. if (this.description.length() > 250)
  2390. {
  2391. this.description = this.description.substring(0, 250);
  2392. }
  2393. }
  2394.  
  2395. public void setPassword(String password)
  2396. {
  2397. this.password = password;
  2398.  
  2399. if (this.password.length() > 20)
  2400. {
  2401. this.password = this.password.substring(0, 20);
  2402. }
  2403. }
  2404.  
  2405. public void setState(RoomState state)
  2406. {
  2407. this.state = state;
  2408. }
  2409.  
  2410. public void setUsersMax(int usersMax)
  2411. {
  2412. this.usersMax = usersMax;
  2413. }
  2414.  
  2415. public void setScore(int score)
  2416. {
  2417. this.score = score;
  2418. }
  2419.  
  2420. public void setCategory(int category)
  2421. {
  2422. this.category = category;
  2423. }
  2424.  
  2425. public void setFloorPaint(String floorPaint)
  2426. {
  2427. this.floorPaint = floorPaint;
  2428. }
  2429.  
  2430. public void setWallPaint(String wallPaint)
  2431. {
  2432. this.wallPaint = wallPaint;
  2433. }
  2434.  
  2435. public void setBackgroundPaint(String backgroundPaint)
  2436. {
  2437. this.backgroundPaint = backgroundPaint;
  2438. }
  2439.  
  2440. public void setWallSize(int wallSize)
  2441. {
  2442. this.wallSize = wallSize;
  2443. }
  2444.  
  2445. public void setFloorSize(int floorSize)
  2446. {
  2447. this.floorSize = floorSize;
  2448. }
  2449.  
  2450. public void setTags(String tags)
  2451. {
  2452. this.tags = tags;
  2453. }
  2454.  
  2455. public void setTradeMode(int tradeMode)
  2456. {
  2457. this.tradeMode = tradeMode;
  2458. }
  2459.  
  2460. public void setAllowPets(boolean allowPets)
  2461. {
  2462. this.allowPets = allowPets;
  2463. }
  2464.  
  2465. public void setAllowPetsEat(boolean allowPetsEat)
  2466. {
  2467. this.allowPetsEat = allowPetsEat;
  2468. }
  2469.  
  2470. public void setAllowWalkthrough(boolean allowWalkthrough)
  2471. {
  2472. this.allowWalkthrough = allowWalkthrough;
  2473. }
  2474.  
  2475. public void setAllowBotsWalk(boolean allowBotsWalk)
  2476. {
  2477. this.allowBotsWalk = allowBotsWalk;
  2478. }
  2479.  
  2480. public void setHideWall(boolean hideWall)
  2481. {
  2482. this.hideWall = hideWall;
  2483. }
  2484.  
  2485. public void setChatMode(int chatMode)
  2486. {
  2487. this.chatMode = chatMode;
  2488. }
  2489.  
  2490. public void setChatWeight(int chatWeight)
  2491. {
  2492. this.chatWeight = chatWeight;
  2493. }
  2494.  
  2495. public void setChatSpeed(int chatSpeed)
  2496. {
  2497. this.chatSpeed = chatSpeed;
  2498. }
  2499.  
  2500. public void setChatDistance(int chatDistance)
  2501. {
  2502. this.chatDistance = chatDistance;
  2503. }
  2504.  
  2505. public int getChatProtection()
  2506. {
  2507. return this.chatProtection;
  2508. }
  2509.  
  2510. public void setChatProtection(int chatProtection)
  2511. {
  2512. this.chatProtection = chatProtection;
  2513. }
  2514.  
  2515. public int getMuteOption()
  2516. {
  2517. return this.muteOption;
  2518. }
  2519.  
  2520. public void setMuteOption(int muteOption)
  2521. {
  2522. this.muteOption = muteOption;
  2523. }
  2524.  
  2525. public int getKickOption()
  2526. {
  2527. return this.kickOption;
  2528. }
  2529.  
  2530. public void setKickOption(int kickOption)
  2531. {
  2532. this.kickOption = kickOption;
  2533. }
  2534.  
  2535. public int getBanOption()
  2536. {
  2537. return this.banOption;
  2538. }
  2539.  
  2540. public void setBanOption(int banOption)
  2541. {
  2542. this.banOption = banOption;
  2543. }
  2544.  
  2545. public int getPollId()
  2546. {
  2547. return this.pollId;
  2548. }
  2549.  
  2550. public int getRollerSpeed()
  2551. {
  2552. return this.rollerSpeed;
  2553. }
  2554.  
  2555. public String[] filterAnything()
  2556. {
  2557. return new String[]{this.getOwnerName(), this.getGuildName(), this.getDescription(), this.getPromotionDesc()};
  2558. }
  2559.  
  2560. public long getCycleTimestamp()
  2561. {
  2562. return this.cycleTimestamp;
  2563. }
  2564.  
  2565. public boolean isPromoted()
  2566. {
  2567. this.promoted = this.promotion != null && this.promotion.getEndTimestamp() > Emulator.getIntUnixTimestamp();
  2568. this.needsUpdate = true;
  2569.  
  2570. return this.promoted;
  2571. }
  2572.  
  2573. public RoomPromotion getPromotion()
  2574. {
  2575. return this.promotion;
  2576. }
  2577.  
  2578. public String getPromotionDesc()
  2579. {
  2580. if (this.promotion != null)
  2581. {
  2582. return this.promotion.getDescription();
  2583. }
  2584.  
  2585. return "";
  2586. }
  2587.  
  2588. public void createPromotion(String title, String description)
  2589. {
  2590. this.promoted = true;
  2591.  
  2592. if(this.promotion == null)
  2593. {
  2594. this.promotion = new RoomPromotion(this, title, description, Emulator.getIntUnixTimestamp() + (120 * 60));
  2595. }
  2596. else
  2597. {
  2598. this.promotion.setTitle(title);
  2599. this.promotion.setDescription(description);
  2600. this.promotion.setEndTimestamp(Emulator.getIntUnixTimestamp() + (120 * 60));
  2601. }
  2602.  
  2603. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_promotions (room_id, title, description, end_timestamp) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE title = ?, description = ?, end_timestamp = ?"))
  2604. {
  2605. statement.setInt(1, this.id);
  2606. statement.setString(2, title);
  2607. statement.setString(3, description);
  2608. statement.setInt(4, this.promotion.getEndTimestamp());
  2609. statement.setString(5, this.promotion.getTitle());
  2610. statement.setString(6, this.promotion.getDescription());
  2611. statement.setInt(7, this.promotion.getEndTimestamp());
  2612. statement.execute();
  2613. }
  2614. catch (SQLException e)
  2615. {
  2616. Emulator.getLogging().logSQLException(e);
  2617. }
  2618.  
  2619. this.needsUpdate = true;
  2620. }
  2621.  
  2622. public void setRollerSpeed(int rollerSpeed)
  2623. {
  2624. this.rollerSpeed = rollerSpeed;
  2625. this.rollerCycle = 0;
  2626. this.needsUpdate = true;
  2627. }
  2628.  
  2629. public void setPollId(int pollId)
  2630. {
  2631. this.pollId = pollId;
  2632. }
  2633.  
  2634. public boolean addGame(Game game)
  2635. {
  2636. synchronized (this.games)
  2637. {
  2638. return this.games.add(game);
  2639. }
  2640. }
  2641.  
  2642. public boolean deleteGame(Game game)
  2643. {
  2644. game.stop();
  2645. synchronized (this.games)
  2646. {
  2647. return this.games.remove(game);
  2648. }
  2649. }
  2650.  
  2651. public Game getGame(Class<? extends Game> gameType)
  2652. {
  2653. synchronized (this.games)
  2654. {
  2655. for(Game game : this.games)
  2656. {
  2657. if(gameType.isInstance(game))
  2658. {
  2659. return game;
  2660. }
  2661. }
  2662. }
  2663.  
  2664. return null;
  2665. }
  2666.  
  2667. public int getUserCount()
  2668. {
  2669. return this.currentHabbos.size();
  2670. }
  2671.  
  2672. public ConcurrentHashMap<Integer, Habbo> getCurrentHabbos()
  2673. {
  2674. return this.currentHabbos;
  2675. }
  2676.  
  2677. public Collection<Habbo> getHabbos()
  2678. {
  2679. return this.currentHabbos.values();
  2680. }
  2681.  
  2682. public TIntObjectMap<Habbo> getHabboQueue()
  2683. {
  2684. return this.habboQueue;
  2685. }
  2686.  
  2687. public TIntObjectMap<String> getFurniOwnerNames()
  2688. {
  2689. return this.furniOwnerNames;
  2690. }
  2691.  
  2692. public String getFurniOwnerName(int userId)
  2693. {
  2694. return this.furniOwnerNames.get(userId);
  2695. }
  2696.  
  2697. public TIntIntMap getFurniOwnerCount()
  2698. {
  2699. return this.furniOwnerCount;
  2700. }
  2701.  
  2702. public TIntObjectMap<RoomMoodlightData> getMoodlightData()
  2703. {
  2704. return this.moodlightData;
  2705. }
  2706.  
  2707. public int getLastTimerReset()
  2708. {
  2709. return this.lastTimerReset;
  2710. }
  2711.  
  2712. public void setLastTimerReset(int lastTimerReset)
  2713. {
  2714. this.lastTimerReset = lastTimerReset;
  2715. }
  2716.  
  2717. public void addToQueue(Habbo habbo)
  2718. {
  2719. synchronized (this.habboQueue)
  2720. {
  2721. this.habboQueue.put(habbo.getHabboInfo().getId(), habbo);
  2722. }
  2723. }
  2724.  
  2725. public boolean removeFromQueue(Habbo habbo)
  2726. {
  2727. try
  2728. {
  2729. this.sendComposer(new HideDoorbellComposer(habbo.getHabboInfo().getUsername()).compose());
  2730.  
  2731. synchronized (this.habboQueue)
  2732. {
  2733. return this.habboQueue.remove(habbo.getHabboInfo().getId()) != null;
  2734. }
  2735. }
  2736. catch (Exception e)
  2737. {
  2738. Emulator.getLogging().logErrorLine(e);
  2739. }
  2740.  
  2741. return true;
  2742. }
  2743.  
  2744. public TIntObjectMap<Bot> getCurrentBots()
  2745. {
  2746. return this.currentBots;
  2747. }
  2748.  
  2749. public TIntObjectMap<Pet> getCurrentPets()
  2750. {
  2751. return this.currentPets;
  2752. }
  2753.  
  2754. public THashSet<String> getWordFilterWords()
  2755. {
  2756. return this.wordFilterWords;
  2757. }
  2758.  
  2759. public RoomSpecialTypes getRoomSpecialTypes()
  2760. {
  2761. return this.roomSpecialTypes;
  2762. }
  2763.  
  2764. public boolean isPreLoaded()
  2765. {
  2766. return this.preLoaded;
  2767. }
  2768.  
  2769. public boolean isLoaded()
  2770. {
  2771. return this.loaded;
  2772. }
  2773.  
  2774. public void setNeedsUpdate(boolean needsUpdate)
  2775. {
  2776. this.needsUpdate = needsUpdate;
  2777. }
  2778.  
  2779. public TIntArrayList getRights()
  2780. {
  2781. return this.rights;
  2782. }
  2783.  
  2784. public boolean isMuted()
  2785. {
  2786. return this.muted;
  2787. }
  2788.  
  2789. public void setMuted(boolean muted)
  2790. {
  2791. this.muted = muted;
  2792. }
  2793.  
  2794. public TraxManager getTraxManager()
  2795. {
  2796. return this.traxManager;
  2797. }
  2798.  
  2799. public void addHabboItem(HabboItem item)
  2800. {
  2801. if(item == null)
  2802. return;
  2803.  
  2804. synchronized (this.roomItems)
  2805. {
  2806. try
  2807. {
  2808. this.roomItems.put(item.getId(), item);
  2809. } catch (Exception e)
  2810. {
  2811.  
  2812. }
  2813. }
  2814.  
  2815. synchronized (this.furniOwnerCount)
  2816. {
  2817. this.furniOwnerCount.put(item.getUserId(), this.furniOwnerCount.get(item.getUserId()) + 1);
  2818. }
  2819.  
  2820. synchronized (this.furniOwnerNames)
  2821. {
  2822. if (!this.furniOwnerNames.containsKey(item.getUserId()))
  2823. {
  2824. HabboInfo habbo = HabboManager.getOfflineHabboInfo(item.getUserId());
  2825.  
  2826. if (habbo != null)
  2827. {
  2828. this.furniOwnerNames.put(item.getUserId(), habbo.getUsername());
  2829. }
  2830. else
  2831. {
  2832. Emulator.getLogging().logDebugLine("Failed to find username for item (ID:" + item.getId() + ", UserID: " + item.getUserId() + ")" );
  2833. }
  2834. }
  2835. }
  2836.  
  2837. //TODO: Move this list
  2838. synchronized (this.roomSpecialTypes)
  2839. {
  2840. if (item instanceof ICycleable)
  2841. {
  2842. this.roomSpecialTypes.addCycleTask((ICycleable)item);
  2843. }
  2844.  
  2845. if (item instanceof InteractionWiredTrigger)
  2846. {
  2847. this.roomSpecialTypes.addTrigger((InteractionWiredTrigger) item);
  2848. } else if (item instanceof InteractionWiredEffect)
  2849. {
  2850. this.roomSpecialTypes.addEffect((InteractionWiredEffect) item);
  2851. } else if (item instanceof InteractionWiredCondition)
  2852. {
  2853. this.roomSpecialTypes.addCondition((InteractionWiredCondition) item);
  2854. } else if (item instanceof InteractionWiredExtra)
  2855. {
  2856. this.roomSpecialTypes.addExtra((InteractionWiredExtra) item);
  2857. } else if (item instanceof InteractionBattleBanzaiTeleporter)
  2858. {
  2859. this.roomSpecialTypes.addBanzaiTeleporter((InteractionBattleBanzaiTeleporter) item);
  2860. } else if (item instanceof InteractionRoller)
  2861. {
  2862. this.roomSpecialTypes.addRoller((InteractionRoller) item);
  2863. } else if (item instanceof InteractionGameScoreboard)
  2864. {
  2865. this.roomSpecialTypes.addGameScoreboard((InteractionGameScoreboard) item);
  2866. } else if (item instanceof InteractionGameGate)
  2867. {
  2868. this.roomSpecialTypes.addGameGate((InteractionGameGate) item);
  2869. } else if (item instanceof InteractionGameTimer)
  2870. {
  2871. this.roomSpecialTypes.addGameTimer((InteractionGameTimer) item);
  2872. } else if (item instanceof InteractionFreezeExitTile)
  2873. {
  2874. this.roomSpecialTypes.addFreezeExitTile((InteractionFreezeExitTile) item);
  2875. } else if (item instanceof InteractionNest)
  2876. {
  2877. this.roomSpecialTypes.addNest((InteractionNest) item);
  2878. } else if (item instanceof InteractionPetDrink)
  2879. {
  2880. this.roomSpecialTypes.addPetDrink((InteractionPetDrink) item);
  2881. } else if (item instanceof InteractionPetFood)
  2882. {
  2883. this.roomSpecialTypes.addPetFood((InteractionPetFood) item);
  2884. } else if (item instanceof InteractionMoodLight)
  2885. {
  2886. this.roomSpecialTypes.addUndefined(item);
  2887. } else if (item instanceof InteractionPyramid)
  2888. {
  2889. this.roomSpecialTypes.addUndefined(item);
  2890. } else if (item instanceof InteractionMusicDisc)
  2891. {
  2892. this.roomSpecialTypes.addUndefined(item);
  2893. } else if (item instanceof InteractionBattleBanzaiSphere)
  2894. {
  2895. this.roomSpecialTypes.addUndefined(item);
  2896. } else if (item instanceof InteractionTalkingFurniture)
  2897. {
  2898. this.roomSpecialTypes.addUndefined(item);
  2899. } else if (item instanceof InteractionWater)
  2900. {
  2901. this.roomSpecialTypes.addUndefined(item);
  2902. } else if (item instanceof InteractionWaterItem)
  2903. {
  2904. this.roomSpecialTypes.addUndefined(item);
  2905. } else if (item instanceof InteractionMuteArea)
  2906. {
  2907. this.roomSpecialTypes.addUndefined(item);
  2908. } else if (item instanceof InteractionTagPole)
  2909. {
  2910. this.roomSpecialTypes.addUndefined(item);
  2911. } else if (item instanceof InteractionTagField)
  2912. {
  2913. this.roomSpecialTypes.addUndefined(item);
  2914. }else if (item instanceof InteractionJukeBox)
  2915. {
  2916. this.roomSpecialTypes.addUndefined(item);
  2917. }else if (item instanceof InteractionPetBreedingNest)
  2918. {
  2919. this.roomSpecialTypes.addUndefined(item);
  2920. }
  2921. else if (item instanceof InteractionBlackHole)
  2922. {
  2923. this.roomSpecialTypes.addUndefined(item);
  2924. }
  2925. else if (item instanceof InteractionWiredHighscore)
  2926. {
  2927. this.roomSpecialTypes.addUndefined(item);
  2928. }
  2929. else if (item instanceof InteractionStickyPole)
  2930. {
  2931. this.roomSpecialTypes.addUndefined(item);
  2932. }
  2933. else if (item instanceof WiredBlob)
  2934. {
  2935. this.roomSpecialTypes.addUndefined(item);
  2936. }
  2937. else if (item instanceof InteractionTent)
  2938. {
  2939. this.roomSpecialTypes.addUndefined(item);
  2940. }
  2941. else if (item instanceof InteractionSnowboardSlope)
  2942. {
  2943. this.roomSpecialTypes.addUndefined(item);
  2944. }
  2945. }
  2946. }
  2947.  
  2948. public HabboItem getHabboItem(int id)
  2949. {
  2950. HabboItem item;
  2951. synchronized (this.roomItems)
  2952. {
  2953. item = this.roomItems.get(id);
  2954. }
  2955.  
  2956. if(item == null)
  2957. item = this.roomSpecialTypes.getBanzaiTeleporter(id);
  2958.  
  2959. if(item == null)
  2960. item = this.roomSpecialTypes.getTrigger(id);
  2961.  
  2962. if(item == null)
  2963. item = this.roomSpecialTypes.getEffect(id);
  2964.  
  2965. if(item == null)
  2966. item = this.roomSpecialTypes.getCondition(id);
  2967.  
  2968. if(item == null)
  2969. item = this.roomSpecialTypes.getGameGate(id);
  2970.  
  2971. if(item == null)
  2972. item = this.roomSpecialTypes.getGameScorebord(id);
  2973.  
  2974. if(item == null)
  2975. item = this.roomSpecialTypes.getGameTimer(id);
  2976.  
  2977. if(item == null)
  2978. item = this.roomSpecialTypes.getFreezeExitTiles().get(id);
  2979.  
  2980. if(item == null)
  2981. item = this.roomSpecialTypes.getRoller(id);
  2982.  
  2983. if(item == null)
  2984. item = this.roomSpecialTypes.getNest(id);
  2985.  
  2986. if(item == null)
  2987. item = this.roomSpecialTypes.getPetDrink(id);
  2988.  
  2989. if(item == null)
  2990. item = this.roomSpecialTypes.getPetFood(id);
  2991.  
  2992. return item;
  2993. }
  2994.  
  2995. void removeHabboItem(int id)
  2996. {
  2997. this.removeHabboItem(this.getHabboItem(id));
  2998. }
  2999.  
  3000. /**
  3001. * Removes an {@see HabboItem} from the list of room items. Does not visually remove it from the room.
  3002. * @param item The item to remove.
  3003. */
  3004. public void removeHabboItem(HabboItem item)
  3005. {
  3006. if (item != null)
  3007. {
  3008.  
  3009. HabboItem i;
  3010. synchronized (this.roomItems)
  3011. {
  3012. i = this.roomItems.remove(item.getId());
  3013. }
  3014.  
  3015. if (i != null)
  3016. {
  3017. synchronized (this.furniOwnerCount)
  3018. {
  3019. synchronized (this.furniOwnerNames)
  3020. {
  3021. int count = this.furniOwnerCount.get(i.getUserId());
  3022.  
  3023. if (count > 1)
  3024. this.furniOwnerCount.put(i.getUserId(), count - 1);
  3025. else
  3026. {
  3027. this.furniOwnerCount.remove(i.getUserId());
  3028. this.furniOwnerNames.remove(i.getUserId());
  3029. }
  3030. }
  3031. }
  3032.  
  3033. if (item instanceof ICycleable)
  3034. {
  3035. this.roomSpecialTypes.removeCycleTask((ICycleable) item);
  3036. }
  3037.  
  3038. if (item instanceof InteractionBattleBanzaiTeleporter)
  3039. {
  3040. this.roomSpecialTypes.removeBanzaiTeleporter((InteractionBattleBanzaiTeleporter) item);
  3041. }
  3042. else if (item instanceof InteractionWiredTrigger)
  3043. {
  3044. this.roomSpecialTypes.removeTrigger((InteractionWiredTrigger) item);
  3045. }
  3046. else if (item instanceof InteractionWiredEffect)
  3047. {
  3048. this.roomSpecialTypes.removeEffect((InteractionWiredEffect) item);
  3049. }
  3050. else if (item instanceof InteractionWiredCondition)
  3051. {
  3052. this.roomSpecialTypes.removeCondition((InteractionWiredCondition) item);
  3053. }
  3054. else if (item instanceof InteractionWiredExtra)
  3055. {
  3056. this.roomSpecialTypes.removeExtra((InteractionWiredExtra) item);
  3057. }
  3058. else if (item instanceof InteractionRoller)
  3059. {
  3060. this.roomSpecialTypes.removeRoller((InteractionRoller) item);
  3061. }
  3062. else if (item instanceof InteractionGameScoreboard)
  3063. {
  3064. this.roomSpecialTypes.removeScoreboard((InteractionGameScoreboard) item);
  3065. }
  3066. else if (item instanceof InteractionGameGate)
  3067. {
  3068. this.roomSpecialTypes.removeGameGate((InteractionGameGate) item);
  3069. }
  3070. else if (item instanceof InteractionGameTimer)
  3071. {
  3072. this.roomSpecialTypes.removeGameTimer((InteractionGameTimer) item);
  3073. }
  3074. else if (item instanceof InteractionFreezeExitTile)
  3075. {
  3076. this.roomSpecialTypes.removeFreezeExitTile((InteractionFreezeExitTile) item);
  3077. }
  3078. else if (item instanceof InteractionNest)
  3079. {
  3080. this.roomSpecialTypes.removeNest((InteractionNest) item);
  3081. }
  3082. else if (item instanceof InteractionPetDrink)
  3083. {
  3084. this.roomSpecialTypes.removePetDrink((InteractionPetDrink) item);
  3085. }
  3086. else if (item instanceof InteractionPetFood)
  3087. {
  3088. this.roomSpecialTypes.removePetFood((InteractionPetFood) item);
  3089. }
  3090. else if (item instanceof InteractionMoodLight)
  3091. {
  3092. this.roomSpecialTypes.removeUndefined(item);
  3093. }
  3094. else if (item instanceof InteractionPyramid)
  3095. {
  3096. this.roomSpecialTypes.removeUndefined(item);
  3097. }
  3098. else if (item instanceof InteractionMusicDisc)
  3099. {
  3100. this.roomSpecialTypes.removeUndefined(item);
  3101. }
  3102. else if (item instanceof InteractionBattleBanzaiSphere)
  3103. {
  3104. this.roomSpecialTypes.removeUndefined(item);
  3105. }
  3106. else if (item instanceof InteractionTalkingFurniture)
  3107. {
  3108. this.roomSpecialTypes.removeUndefined(item);
  3109. }
  3110. else if (item instanceof InteractionWaterItem)
  3111. {
  3112. this.roomSpecialTypes.removeUndefined(item);
  3113. }
  3114. else if (item instanceof InteractionWater)
  3115. {
  3116. this.roomSpecialTypes.removeUndefined(item);
  3117. }
  3118. else if (item instanceof InteractionMuteArea)
  3119. {
  3120. this.roomSpecialTypes.removeUndefined(item);
  3121. }
  3122. else if (item instanceof InteractionTagPole)
  3123. {
  3124. this.roomSpecialTypes.removeUndefined(item);
  3125. }
  3126. else if (item instanceof InteractionTagField)
  3127. {
  3128. this.roomSpecialTypes.removeUndefined(item);
  3129. }
  3130. else if (item instanceof InteractionJukeBox)
  3131. {
  3132. this.roomSpecialTypes.removeUndefined(item);
  3133. }
  3134. else if (item instanceof InteractionPetBreedingNest)
  3135. {
  3136. this.roomSpecialTypes.removeUndefined(item);
  3137. }
  3138. else if (item instanceof InteractionBlackHole)
  3139. {
  3140. this.roomSpecialTypes.removeUndefined(item);
  3141. }
  3142. else if (item instanceof InteractionWiredHighscore)
  3143. {
  3144. this.roomSpecialTypes.removeUndefined(item);
  3145. }
  3146. else if (item instanceof InteractionStickyPole)
  3147. {
  3148. this.roomSpecialTypes.removeUndefined(item);
  3149. }
  3150. else if (item instanceof WiredBlob)
  3151. {
  3152. this.roomSpecialTypes.removeUndefined(item);
  3153. }
  3154. else if (item instanceof InteractionTent)
  3155. {
  3156. this.roomSpecialTypes.removeUndefined(item);
  3157. }
  3158. else if (item instanceof InteractionSnowboardSlope)
  3159. {
  3160. this.roomSpecialTypes.removeUndefined(item);
  3161. }
  3162. }
  3163. }
  3164. }
  3165.  
  3166. public THashSet<HabboItem> getFloorItems()
  3167. {
  3168. THashSet<HabboItem> items = new THashSet<>();
  3169. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  3170.  
  3171. for (int i = this.roomItems.size(); i-- > 0; )
  3172. {
  3173. try
  3174. {
  3175. iterator.advance();
  3176. }
  3177. catch (Exception e)
  3178. {
  3179. break;
  3180. }
  3181.  
  3182. if (iterator.value().getBaseItem().getType() == FurnitureType.FLOOR)
  3183. items.add(iterator.value());
  3184.  
  3185. }
  3186.  
  3187. /*items.addAll(this.roomSpecialTypes.getBanzaiTeleporters());
  3188. items.addAll(this.roomSpecialTypes.getNests());
  3189. items.addAll(this.roomSpecialTypes.getPetDrinks());
  3190. items.addAll(this.roomSpecialTypes.getPetFoods());
  3191. items.addAll(this.roomSpecialTypes.getRollers());
  3192. items.addAll(this.roomSpecialTypes.getTriggers());
  3193. items.addAll(this.roomSpecialTypes.getEffects());
  3194. items.addAll(this.roomSpecialTypes.getConditions());*/
  3195.  
  3196. return items;
  3197.  
  3198. }
  3199.  
  3200. public THashSet<HabboItem> getWallItems()
  3201. {
  3202. THashSet<HabboItem> items = new THashSet<>();
  3203. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  3204.  
  3205. for (int i = this.roomItems.size(); i-- > 0; )
  3206. {
  3207. try
  3208. {
  3209. iterator.advance();
  3210. }
  3211. catch (Exception e)
  3212. {
  3213. break;
  3214. }
  3215.  
  3216. if (iterator.value().getBaseItem().getType() == FurnitureType.WALL)
  3217. items.add(iterator.value());
  3218. }
  3219.  
  3220. return items;
  3221.  
  3222. }
  3223.  
  3224. public void addHabbo(Habbo habbo)
  3225. {
  3226. synchronized (this.roomUnitLock)
  3227. {
  3228. habbo.getRoomUnit().setId(this.unitCounter);
  3229. this.currentHabbos.put(habbo.getHabboInfo().getId(), habbo);
  3230. this.unitCounter++;
  3231. this.updateDatabaseUserCount();
  3232. }
  3233. }
  3234.  
  3235. public void kickHabbo(Habbo habbo, boolean alert)
  3236. {
  3237. if(alert)
  3238. {
  3239. habbo.getClient().sendResponse(new GenericErrorMessagesComposer(GenericErrorMessagesComposer.KICKED_OUT_OF_THE_ROOM));
  3240. }
  3241.  
  3242. habbo.getRoomUnit().isKicked = true;
  3243. habbo.getRoomUnit().setGoalLocation(this.layout.getDoorTile());
  3244.  
  3245. if (habbo.getRoomUnit().getPath() == null || habbo.getRoomUnit().getPath().size() <= 1 || this.isPublicRoom())
  3246. {
  3247. habbo.getRoomUnit().setCanWalk(true);
  3248. Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this);
  3249. }
  3250. }
  3251.  
  3252. public void removeHabbo(Habbo habbo)
  3253. {
  3254. HabboItem item = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY());
  3255.  
  3256. if (item != null)
  3257. {
  3258. try
  3259. {
  3260. item.onWalkOff(habbo.getRoomUnit(), this, new Object[]{});
  3261. }
  3262. catch (Exception e)
  3263. {
  3264. Emulator.getLogging().logErrorLine(e);
  3265. }
  3266. }
  3267.  
  3268. synchronized (this.roomUnitLock)
  3269. {
  3270. this.currentHabbos.remove(habbo.getHabboInfo().getId());
  3271. }
  3272.  
  3273. if(habbo.getHabboInfo().getCurrentGame() != null)
  3274. {
  3275. if (this.getGame(habbo.getHabboInfo().getCurrentGame()) != null)
  3276. {
  3277. this.getGame(habbo.getHabboInfo().getCurrentGame()).removeHabbo(habbo);
  3278. }
  3279. }
  3280.  
  3281. RoomTrade trade = this.getActiveTradeForHabbo(habbo);
  3282.  
  3283. if(trade != null)
  3284. {
  3285. trade.stopTrade(habbo);
  3286. }
  3287.  
  3288. this.updateDatabaseUserCount();
  3289. }
  3290.  
  3291. public void addBot(Bot bot)
  3292. {
  3293. synchronized (this.roomUnitLock)
  3294. {
  3295. bot.getRoomUnit().setId(this.unitCounter);
  3296. this.currentBots.put(bot.getId(), bot);
  3297. this.unitCounter++;
  3298. }
  3299. }
  3300.  
  3301. public void addPet(Pet pet)
  3302. {
  3303. synchronized (this.roomUnitLock)
  3304. {
  3305. pet.getRoomUnit().setId(this.unitCounter);
  3306. this.currentPets.put(pet.getId(), pet);
  3307. this.unitCounter++;
  3308.  
  3309. Habbo habbo = this.getHabbo(pet.getUserId());
  3310. if (habbo != null)
  3311. {
  3312. this.furniOwnerNames.put(pet.getUserId(), this.getHabbo(pet.getUserId()).getHabboInfo().getUsername());
  3313. }
  3314. }
  3315. }
  3316.  
  3317. public Bot getBot(int botId)
  3318. {
  3319. return this.currentBots.get(botId);
  3320. }
  3321.  
  3322. public Bot getBot(RoomUnit roomUnit)
  3323. {
  3324. synchronized (this.currentBots)
  3325. {
  3326. TIntObjectIterator<Bot> iterator = this.currentBots.iterator();
  3327.  
  3328. for(int i = this.currentBots.size(); i-- > 0;)
  3329. {
  3330. try
  3331. {
  3332. iterator.advance();
  3333. }
  3334. catch (NoSuchElementException e)
  3335. {
  3336. Emulator.getLogging().logErrorLine(e);
  3337. break;
  3338. }
  3339.  
  3340. if (iterator.value().getRoomUnit() == roomUnit)
  3341. return iterator.value();
  3342. }
  3343. }
  3344.  
  3345. return null;
  3346. }
  3347.  
  3348. public Bot getBotByRoomUnitId(int id)
  3349. {
  3350. synchronized (this.currentBots)
  3351. {
  3352. TIntObjectIterator<Bot> iterator = this.currentBots.iterator();
  3353.  
  3354. for(int i = this.currentBots.size(); i-- > 0;)
  3355. {
  3356. try
  3357. {
  3358. iterator.advance();
  3359. }
  3360. catch (NoSuchElementException e)
  3361. {
  3362. Emulator.getLogging().logErrorLine(e);
  3363. break;
  3364. }
  3365.  
  3366. if (iterator.value().getRoomUnit().getId() == id)
  3367. return iterator.value();
  3368. }
  3369. }
  3370.  
  3371. return null;
  3372. }
  3373.  
  3374. public List<Bot> getBots(String name)
  3375. {
  3376. List<Bot> bots = new ArrayList<>();
  3377.  
  3378. synchronized (this.currentBots)
  3379. {
  3380. TIntObjectIterator<Bot> iterator = this.currentBots.iterator();
  3381.  
  3382. for(int i = this.currentBots.size(); i-- > 0;)
  3383. {
  3384. try
  3385. {
  3386. iterator.advance();
  3387. }
  3388. catch (NoSuchElementException e)
  3389. {
  3390. Emulator.getLogging().logErrorLine(e);
  3391. break;
  3392. }
  3393.  
  3394. if (iterator.value().getName().equalsIgnoreCase(name))
  3395. bots.add(iterator.value());
  3396. }
  3397. }
  3398.  
  3399. return bots;
  3400. }
  3401.  
  3402. public boolean hasBotsAt(final int x, final int y)
  3403. {
  3404. final boolean[] result = {false};
  3405.  
  3406. synchronized (this.currentBots)
  3407. {
  3408. this.currentBots.forEachValue(new TObjectProcedure<Bot>()
  3409. {
  3410. @Override
  3411. public boolean execute(Bot object)
  3412. {
  3413. if (object.getRoomUnit().getX() == x && object.getRoomUnit().getY() == y)
  3414. {
  3415. result[0] = true;
  3416. return false;
  3417. }
  3418.  
  3419. return true;
  3420. }
  3421. });
  3422. }
  3423.  
  3424. return result[0];
  3425. }
  3426.  
  3427. public Pet getPet(int petId)
  3428. {
  3429. return this.currentPets.get(petId);
  3430. }
  3431.  
  3432. public Pet getPet(RoomUnit roomUnit)
  3433. {
  3434. TIntObjectIterator<Pet> petIterator = this.currentPets.iterator();
  3435.  
  3436. for(int i = this.currentPets.size(); i-- > 0;)
  3437. {
  3438. try
  3439. {
  3440. petIterator.advance();
  3441. }
  3442. catch (NoSuchElementException e)
  3443. {
  3444. Emulator.getLogging().logErrorLine(e);
  3445. break;
  3446. }
  3447.  
  3448. if(petIterator.value().getRoomUnit() == roomUnit)
  3449. return petIterator.value();
  3450. }
  3451.  
  3452. return null;
  3453. }
  3454.  
  3455. public boolean removeBot(Bot bot)
  3456. {
  3457. synchronized (this.currentBots)
  3458. {
  3459. if (this.currentBots.containsKey(bot.getId()))
  3460. {
  3461. this.currentBots.remove(bot.getId());
  3462. bot.getRoomUnit().setInRoom(false);
  3463. bot.setRoom(null);
  3464. this.sendComposer(new RoomUserRemoveComposer(bot.getRoomUnit()).compose());
  3465. bot.setRoomUnit(null);
  3466. return true;
  3467. }
  3468. }
  3469.  
  3470. return false;
  3471. }
  3472.  
  3473. public void placePet(Pet pet, short x, short y, double z, int rot)
  3474. {
  3475. synchronized (this.currentPets)
  3476. {
  3477. RoomTile tile = this.layout.getTile(x, y);
  3478.  
  3479. if (tile == null)
  3480. {
  3481. tile = this.layout.getDoorTile();
  3482. }
  3483.  
  3484. pet.setRoomUnit(new RoomUnit());
  3485. pet.setRoom(this);
  3486. pet.getRoomUnit().setGoalLocation(tile);
  3487. pet.getRoomUnit().setLocation(tile);
  3488. pet.getRoomUnit().setRoomUnitType(RoomUnitType.PET);
  3489. pet.getRoomUnit().setCanWalk(true);
  3490. pet.getRoomUnit().setPathFinderRoom(this);
  3491. pet.getRoomUnit().setPreviousLocationZ(z);
  3492. pet.getRoomUnit().setZ(z);
  3493. if (pet.getRoomUnit().getCurrentLocation() == null)
  3494. {
  3495. pet.getRoomUnit().setLocation(this.getLayout().getDoorTile());
  3496. pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection()));
  3497. }
  3498.  
  3499. pet.needsUpdate = true;
  3500. this.furniOwnerNames.put(pet.getUserId(), this.getHabbo(pet.getUserId()).getHabboInfo().getUsername());
  3501. this.addPet(pet);
  3502. this.sendComposer(new RoomPetComposer(pet).compose());
  3503. }
  3504. }
  3505.  
  3506. public Pet removePet(int petId)
  3507. {
  3508. return this.currentPets.remove(petId);
  3509. }
  3510.  
  3511. public boolean hasHabbosAt(int x, int y)
  3512. {
  3513. for (Habbo habbo : this.getHabbos())
  3514. {
  3515. if (habbo.getRoomUnit().getX() == x && habbo.getRoomUnit().getY() == y)
  3516. return true;
  3517. }
  3518. return false;
  3519. }
  3520.  
  3521. public boolean hasPetsAt(int x, int y)
  3522. {
  3523. synchronized (this.currentPets)
  3524. {
  3525. TIntObjectIterator<Pet> petIterator = this.currentPets.iterator();
  3526.  
  3527. for (int i = this.currentPets.size(); i-- > 0; )
  3528. {
  3529. try
  3530. {
  3531. petIterator.advance();
  3532. }
  3533. catch (NoSuchElementException e)
  3534. {
  3535. Emulator.getLogging().logErrorLine(e);
  3536. break;
  3537. }
  3538.  
  3539. if (petIterator.value().getRoomUnit().getX() == x && petIterator.value().getRoomUnit().getY() == y)
  3540. return true;
  3541. }
  3542. }
  3543.  
  3544. return false;
  3545. }
  3546.  
  3547. public THashSet<Bot> getBotsAt(RoomTile tile)
  3548. {
  3549. THashSet<Bot> bots = new THashSet<>();
  3550. synchronized (this.currentBots)
  3551. {
  3552. TIntObjectIterator<Bot> botIterator = this.currentBots.iterator();
  3553.  
  3554. for (int i = this.currentBots.size(); i-- > 0; )
  3555. {
  3556. try
  3557. {
  3558. botIterator.advance();
  3559.  
  3560. if (botIterator.value().getRoomUnit().getCurrentLocation().equals(tile))
  3561. {
  3562. bots.add(botIterator.value());
  3563. }
  3564. }
  3565. catch (Exception e)
  3566. {
  3567. break;
  3568. }
  3569. }
  3570. }
  3571.  
  3572. return bots;
  3573. }
  3574.  
  3575. public THashSet<Habbo> getHabbosAt(short x, short y)
  3576. {
  3577. return this.getHabbosAt(this.layout.getTile(x, y));
  3578. }
  3579.  
  3580. public THashSet<Habbo> getHabbosAt(RoomTile tile)
  3581. {
  3582. THashSet<Habbo> habbos = new THashSet<>();
  3583.  
  3584. for (Habbo habbo : this.getHabbos())
  3585. {
  3586. if (habbo.getRoomUnit().getCurrentLocation().equals(tile))
  3587. habbos.add(habbo);
  3588. }
  3589.  
  3590. return habbos;
  3591. }
  3592.  
  3593. public THashSet<Habbo> getHabbosOnItem(HabboItem item)
  3594. {
  3595. THashSet<Habbo> habbos = new THashSet<>();
  3596. for(short x = item.getX(); x < item.getX() + item.getBaseItem().getLength(); x++)
  3597. {
  3598. for(short y = item.getY(); y < item.getY() + item.getBaseItem().getWidth(); y++)
  3599. {
  3600. habbos.addAll(this.getHabbosAt(x, y));
  3601. }
  3602. }
  3603.  
  3604. return habbos;
  3605. }
  3606.  
  3607. public THashSet<Bot> getBotsOnItem(HabboItem item)
  3608. {
  3609. THashSet<Bot> bots = new THashSet<>();
  3610. for(short x = item.getX(); x < item.getX() + item.getBaseItem().getLength(); x++)
  3611. {
  3612. for(short y = item.getY(); y < item.getY() + item.getBaseItem().getWidth(); y++)
  3613. {
  3614. bots.addAll(this.getBotsAt(this.getLayout().getTile(x, y)));
  3615. }
  3616. }
  3617.  
  3618. return bots;
  3619. }
  3620.  
  3621. public void teleportHabboToItem(Habbo habbo, HabboItem item)
  3622. {
  3623. this.teleportRoomUnitToLocation(habbo.getRoomUnit(), item.getX(), item.getY(), item.getZ() + item.getBaseItem().getHeight());
  3624. }
  3625.  
  3626. public void teleportHabboToLocation(Habbo habbo, short x, short y)
  3627. {
  3628. this.teleportRoomUnitToLocation(habbo.getRoomUnit(), x, y, 0.0);
  3629. }
  3630.  
  3631. public void teleportRoomUnitToItem(RoomUnit roomUnit, HabboItem item)
  3632. {
  3633. this.teleportRoomUnitToLocation(roomUnit, item.getX(), item.getY(), item.getZ() + item.getBaseItem().getHeight());
  3634. }
  3635.  
  3636. public void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y)
  3637. {
  3638. this.teleportRoomUnitToLocation(roomUnit, x, y, 0.0);
  3639. }
  3640. void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y, double z)
  3641. {
  3642. if (this.loaded)
  3643. {
  3644. RoomTile tile = this.layout.getTile(x, y);
  3645.  
  3646. if (z < tile.z)
  3647. {
  3648. z = tile.z;
  3649. }
  3650.  
  3651. roomUnit.setLocation(tile);
  3652. roomUnit.setGoalLocation(tile);
  3653. roomUnit.setZ(z);
  3654. roomUnit.setPreviousLocationZ(z);
  3655. this.updateRoomUnit(roomUnit);
  3656.  
  3657.  
  3658. }
  3659. }
  3660.  
  3661. public void muteHabbo(Habbo habbo, int minutes)
  3662. {
  3663. synchronized (this.mutedHabbos)
  3664. {
  3665. this.mutedHabbos.put(habbo.getHabboInfo().getId(), Emulator.getIntUnixTimestamp() + (minutes * 60));
  3666. }
  3667. }
  3668.  
  3669. public boolean isMuted(Habbo habbo)
  3670. {
  3671. if (this.isOwner(habbo) || this.hasRights(habbo))
  3672. return false;
  3673.  
  3674. if(this.mutedHabbos.containsKey(habbo.getHabboInfo().getId()))
  3675. {
  3676. boolean time = this.mutedHabbos.get(habbo.getHabboInfo().getId()) > Emulator.getIntUnixTimestamp();
  3677.  
  3678. if (!time)
  3679. {
  3680. this.mutedHabbos.remove(habbo.getHabboInfo().getId());
  3681. }
  3682.  
  3683. return time;
  3684. }
  3685.  
  3686. return false;
  3687. }
  3688.  
  3689. public void habboEntered(Habbo habbo)
  3690. {
  3691. habbo.getRoomUnit().animateWalk = false;
  3692.  
  3693. synchronized (this.currentBots)
  3694. {
  3695. if(habbo.getHabboInfo().getId() != this.getOwnerId())
  3696. return;
  3697.  
  3698. TIntObjectIterator<Bot> botIterator = this.currentBots.iterator();
  3699.  
  3700. for (int i = this.currentBots.size(); i-- > 0; )
  3701. {
  3702. try
  3703. {
  3704. botIterator.advance();
  3705.  
  3706. if(botIterator.value() instanceof VisitorBot)
  3707. {
  3708. ((VisitorBot)botIterator.value()).onUserEnter(habbo);
  3709. break;
  3710. }
  3711. }
  3712. catch (Exception e)
  3713. {
  3714. break;
  3715. }
  3716. }
  3717. }
  3718.  
  3719. HabboItem doorTileTopItem = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY());
  3720. if (doorTileTopItem != null)
  3721. {
  3722. try
  3723. {
  3724. doorTileTopItem.onWalkOn(habbo.getRoomUnit(), this, new Object[]{});
  3725. } catch (Exception e)
  3726. {
  3727. Emulator.getLogging().logErrorLine(e);
  3728. }
  3729. }
  3730. }
  3731.  
  3732. public void floodMuteHabbo(Habbo habbo, int timeOut)
  3733. {
  3734. habbo.getHabboStats().mutedCount++;
  3735. timeOut += (timeOut * (int)Math.ceil(Math.pow(habbo.getHabboStats().mutedCount, 2)));
  3736. habbo.getHabboStats().chatCounter = 0;
  3737. habbo.mute(timeOut);
  3738. }
  3739.  
  3740. public void talk(Habbo habbo, RoomChatMessage roomChatMessage, RoomChatType chatType)
  3741. {
  3742. this.talk(habbo, roomChatMessage, chatType, false);
  3743. }
  3744.  
  3745. public void talk(final Habbo habbo, final RoomChatMessage roomChatMessage, RoomChatType chatType, boolean ignoreWired)
  3746. {
  3747. if (!habbo.getHabboStats().allowTalk())
  3748. return;
  3749.  
  3750. habbo.getHabboStats().chatCounter += 2;
  3751.  
  3752. if (habbo.getHabboInfo().getCurrentRoom() != this)
  3753. return;
  3754.  
  3755. long millis = System.currentTimeMillis();
  3756. if (HABBO_CHAT_DELAY)
  3757. {
  3758. if (millis - habbo.getHabboStats().lastChat < 750)
  3759. {
  3760. return;
  3761. }
  3762. }
  3763. habbo.getHabboStats().lastChat = millis;
  3764. if(roomChatMessage != null && roomChatMessage.getMessage().equalsIgnoreCase("i am a pirate"))
  3765. {
  3766. Emulator.getThreading().run(new YouAreAPirate(habbo, this));
  3767. return;
  3768. }
  3769.  
  3770. UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.TALKED, false);
  3771. Emulator.getPluginManager().fireEvent(event);
  3772.  
  3773. if (!event.isCancelled())
  3774. {
  3775. if (!event.idle)
  3776. {
  3777. this.unIdle(habbo);
  3778. }
  3779. }
  3780.  
  3781. this.sendComposer(new RoomUserTypingComposer(habbo.getRoomUnit(), false).compose());
  3782.  
  3783. if(roomChatMessage == null || roomChatMessage.getMessage() == null || roomChatMessage.getMessage().equals(""))
  3784. return;
  3785.  
  3786. for(HabboItem area : this.getRoomSpecialTypes().getItemsOfType(InteractionMuteArea.class))
  3787. {
  3788. if(((InteractionMuteArea)area).inSquare(habbo.getRoomUnit().getCurrentLocation()))
  3789. {
  3790. return;
  3791. }
  3792. }
  3793.  
  3794. if(!this.wordFilterWords.isEmpty())
  3795. {
  3796. if (!habbo.hasPermission("acc_chat_no_filter"))
  3797. {
  3798. for(String string : this.wordFilterWords)
  3799. {
  3800. roomChatMessage.setMessage(roomChatMessage.getMessage().replace(string, "bobba"));
  3801. }
  3802. }
  3803. }
  3804.  
  3805. if(!habbo.hasPermission("acc_nomute"))
  3806. {
  3807. if(this.isMuted() && !this.hasRights(habbo))
  3808. {
  3809. return;
  3810. }
  3811.  
  3812. if (this.isMuted(habbo))
  3813. {
  3814. habbo.getClient().sendResponse(new MutedWhisperComposer(this.mutedHabbos.get(habbo.getHabboInfo().getId()) - Emulator.getIntUnixTimestamp()));
  3815. return;
  3816. }
  3817. }
  3818.  
  3819. if (chatType != RoomChatType.WHISPER)
  3820. {
  3821. if (CommandHandler.handleCommand(habbo.getClient(), roomChatMessage.getUnfilteredMessage()))
  3822. {
  3823. WiredHandler.handle(WiredTriggerType.SAY_COMMAND, habbo.getRoomUnit(), habbo.getHabboInfo().getCurrentRoom(), new Object[]{roomChatMessage.getMessage()});
  3824. roomChatMessage.isCommand = true;
  3825. return;
  3826. }
  3827.  
  3828. if(!ignoreWired)
  3829. {
  3830. if (WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, habbo.getRoomUnit(), habbo.getHabboInfo().getCurrentRoom(), new Object[]{roomChatMessage.getMessage()}))
  3831. {
  3832. habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(roomChatMessage.getMessage(), habbo, habbo, roomChatMessage.getBubble())));
  3833. return;
  3834. }
  3835. }
  3836. }
  3837.  
  3838. ServerMessage prefixMessage = roomChatMessage.getHabbo().getHabboInfo().getRank().hasPrefix() ? new RoomUserNameChangedComposer(habbo, true).compose() : null;
  3839. ServerMessage clearPrefixMessage = prefixMessage != null ? new RoomUserNameChangedComposer(habbo).compose() : null;
  3840.  
  3841. Rectangle show = this.roomSpecialTypes.tentAt(habbo.getRoomUnit().getCurrentLocation());
  3842.  
  3843. if(chatType == RoomChatType.WHISPER)
  3844. {
  3845. if (roomChatMessage.getTargetHabbo() == null)
  3846. {
  3847. return;
  3848. }
  3849.  
  3850. final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose();
  3851. RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage);
  3852. staffChatMessage.setMessage("To " + staffChatMessage.getTargetHabbo().getHabboInfo().getUsername() + ": " + staffChatMessage.getMessage());
  3853. final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose();
  3854.  
  3855. for (Habbo h : this.getHabbos())
  3856. {
  3857. if (h == roomChatMessage.getTargetHabbo() || h == habbo)
  3858. {
  3859. if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()))
  3860. {
  3861. if (prefixMessage != null)
  3862. {
  3863. h.getClient().sendResponse(prefixMessage);
  3864. }
  3865. h.getClient().sendResponse(message);
  3866.  
  3867. if (clearPrefixMessage != null)
  3868. {
  3869. h.getClient().sendResponse(clearPrefixMessage);
  3870. }
  3871. }
  3872.  
  3873. continue;
  3874. }
  3875. if (h.hasPermission("acc_see_whispers"))
  3876. {
  3877. h.getClient().sendResponse(staffMessage);
  3878. }
  3879. }
  3880. }
  3881. else if (chatType == RoomChatType.TALK)
  3882. {
  3883. ServerMessage message = new RoomUserTalkComposer(roomChatMessage).compose();
  3884. boolean noChatLimit = habbo.hasPermission("acc_chat_no_limit");
  3885.  
  3886. for (Habbo h : this.getHabbos())
  3887. {
  3888. if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance ||
  3889. h.equals(habbo) ||
  3890. this.hasRights(h) ||
  3891. noChatLimit) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation())))
  3892. {
  3893. if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()))
  3894. {
  3895. if (prefixMessage != null && !h.getHabboStats().preferOldChat)
  3896. {
  3897. h.getClient().sendResponse(prefixMessage);
  3898. }
  3899. h.getClient().sendResponse(message);
  3900. if (clearPrefixMessage != null && !h.getHabboStats().preferOldChat)
  3901. {
  3902. h.getClient().sendResponse(clearPrefixMessage);
  3903. }
  3904. }
  3905. }
  3906. }
  3907. }
  3908. else if(chatType == RoomChatType.SHOUT)
  3909. {
  3910. ServerMessage message = new RoomUserShoutComposer(roomChatMessage).compose();
  3911.  
  3912. for (Habbo h : this.getHabbos())
  3913. {
  3914. if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation())))
  3915. {
  3916. if (prefixMessage != null && !h.getHabboStats().preferOldChat){ h.getClient().sendResponse(prefixMessage); }
  3917. h.getClient().sendResponse(message);
  3918. if (clearPrefixMessage != null && !h.getHabboStats().preferOldChat){ h.getClient().sendResponse(clearPrefixMessage); }
  3919. }
  3920. }
  3921. }
  3922.  
  3923. if(chatType == RoomChatType.TALK || chatType == RoomChatType.SHOUT)
  3924. {
  3925. synchronized (this.currentBots)
  3926. {
  3927. TIntObjectIterator<Bot> botIterator = this.currentBots.iterator();
  3928.  
  3929. for (int i = this.currentBots.size(); i-- > 0; )
  3930. {
  3931. try
  3932. {
  3933. botIterator.advance();
  3934. Bot bot = botIterator.value();
  3935. bot.onUserSay(roomChatMessage);
  3936.  
  3937. }
  3938. catch (NoSuchElementException e)
  3939. {
  3940. Emulator.getLogging().logErrorLine(e);
  3941. break;
  3942. }
  3943. }
  3944. }
  3945.  
  3946. if(roomChatMessage.getBubble().triggersTalkingFurniture())
  3947. {
  3948. THashSet<HabboItem> items = this.roomSpecialTypes.getItemsOfType(InteractionTalkingFurniture.class);
  3949.  
  3950. for (HabboItem item : items)
  3951. {
  3952. if (this.layout.getTile(item.getX(), item.getY()).distance(habbo.getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("furniture.talking.range"))
  3953. {
  3954. int count = Emulator.getConfig().getInt(item.getBaseItem().getName() + ".message.count", 0);
  3955.  
  3956. if (count > 0)
  3957. {
  3958. int randomValue = Emulator.getRandom().nextInt(count + 1);
  3959.  
  3960. RoomChatMessage itemMessage = new RoomChatMessage(Emulator.getTexts().getValue(item.getBaseItem().getName() + ".message." + randomValue, item.getBaseItem().getName() + ".message." + randomValue + " not found!"), habbo, RoomChatMessageBubbles.getBubble(Emulator.getConfig().getInt(item.getBaseItem().getName() + ".message.bubble", RoomChatMessageBubbles.PARROT.getType())));
  3961.  
  3962. this.sendComposer(new RoomUserShoutComposer(itemMessage).compose());
  3963.  
  3964. try
  3965. {
  3966. item.onClick(habbo.getClient(), this, new Object[0]);
  3967. break;
  3968. }
  3969. catch (Exception e)
  3970. {
  3971. Emulator.getLogging().logErrorLine(e);
  3972. }
  3973. }
  3974. }
  3975. }
  3976.  
  3977. }
  3978. }
  3979. }
  3980.  
  3981. public THashSet<RoomTile> getLockedTiles()
  3982. {
  3983. THashSet<RoomTile> lockedTiles = new THashSet<>();
  3984.  
  3985. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  3986.  
  3987. for (int i = this.roomItems.size(); i-- > 0; )
  3988. {
  3989. HabboItem item;
  3990. try
  3991. {
  3992. iterator.advance();
  3993. item = iterator.value();
  3994. }
  3995. catch (Exception e)
  3996. {
  3997. break;
  3998. }
  3999.  
  4000. if (item.getBaseItem().getType() != FurnitureType.FLOOR)
  4001. continue;
  4002.  
  4003. boolean found = false;
  4004. for(RoomTile tile : lockedTiles)
  4005. {
  4006. if(tile.x == item.getX() &&
  4007. tile.y == item.getY())
  4008. {
  4009. found = true;
  4010. break;
  4011. }
  4012. }
  4013.  
  4014. if(!found)
  4015. {
  4016. if(item.getRotation() == 0 || item.getRotation() == 4)
  4017. {
  4018. for(short y = 0; y < item.getBaseItem().getLength(); y++)
  4019. {
  4020. for(short x = 0; x < item.getBaseItem().getWidth(); x++)
  4021. {
  4022. RoomTile tile = this.layout.getTile((short) (item.getX() + x), (short) (item.getY() + y));
  4023.  
  4024. if (tile != null)
  4025. {
  4026. lockedTiles.add(tile);
  4027. }
  4028. }
  4029. }
  4030. }
  4031. else
  4032. {
  4033. for(short y = 0; y < item.getBaseItem().getWidth(); y++)
  4034. {
  4035. for(short x = 0; x < item.getBaseItem().getLength(); x++)
  4036. {
  4037. RoomTile tile = this.layout.getTile((short) (item.getX() + x), (short) (item.getY() + y));
  4038.  
  4039. if (tile != null)
  4040. {
  4041. lockedTiles.add(tile);
  4042. }
  4043. }
  4044. }
  4045. }
  4046. }
  4047. }
  4048.  
  4049. return lockedTiles;
  4050. }
  4051.  
  4052. @Deprecated
  4053. public THashSet<HabboItem> getItemsAt(int x, int y)
  4054. {
  4055. RoomTile tile = this.getLayout().getTile((short)x, (short)y);
  4056.  
  4057. if (tile != null)
  4058. {
  4059. return this.getItemsAt(tile);
  4060. }
  4061.  
  4062. return new THashSet<>(0);
  4063. }
  4064. public THashSet<HabboItem> getItemsAt(RoomTile tile)
  4065. {
  4066. if (this.loaded)
  4067. {
  4068. if (this.tileCache.containsKey(tile))
  4069. {
  4070. return this.tileCache.get(tile);
  4071. }
  4072. }
  4073.  
  4074. THashSet<HabboItem> items = new THashSet<>(0);
  4075.  
  4076. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  4077.  
  4078. for (int i = this.roomItems.size(); i-- > 0; )
  4079. {
  4080. HabboItem item;
  4081. try
  4082. {
  4083. iterator.advance();
  4084. item = iterator.value();
  4085. }
  4086. catch (Exception e)
  4087. {
  4088. break;
  4089. }
  4090.  
  4091. if (item.getBaseItem().getType() != FurnitureType.FLOOR)
  4092. continue;
  4093.  
  4094. if (item.getX() == tile.x && item.getY() == tile.y)
  4095. {
  4096. items.add(item);
  4097. }
  4098. else
  4099. {
  4100. if (item.getBaseItem().getWidth() <= 1 && item.getBaseItem().getLength() <= 1)
  4101. {
  4102. continue;
  4103. }
  4104.  
  4105. THashSet<RoomTile> tiles = this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
  4106. for (RoomTile t : tiles)
  4107. {
  4108. if ((t.x == tile.x) && (t.y == tile.y) && (!items.contains(item)))
  4109. {
  4110. items.add(item);
  4111. }
  4112. }
  4113. }
  4114. }
  4115.  
  4116. if (this.loaded)
  4117. {
  4118. this.tileCache.put(tile, items);
  4119. }
  4120.  
  4121. return items;
  4122. }
  4123.  
  4124. public THashSet<HabboItem> getItemsAt(int x, int y, double minZ)
  4125. {
  4126. THashSet<HabboItem> items = new THashSet<>();
  4127.  
  4128. for(HabboItem item : this.getItemsAt(x, y))
  4129. {
  4130. if(item.getZ() < minZ)
  4131. continue;
  4132.  
  4133. if(item.getX() == x && item.getY() == y && item.getZ() >= minZ)
  4134. {
  4135. items.add(item);
  4136. }
  4137. else
  4138. {
  4139. if(item.getBaseItem().getWidth() <= 1 && item.getBaseItem().getLength() <= 1)
  4140. {
  4141. continue;
  4142. }
  4143.  
  4144. THashSet<RoomTile> tiles = this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
  4145. for (RoomTile tile : tiles)
  4146. {
  4147. if ((tile.x == x) && (tile.y == y) && (!items.contains(item))) {
  4148. items.add(item);
  4149. }
  4150. }
  4151. }
  4152. }
  4153. return items;
  4154. }
  4155.  
  4156. public THashSet<HabboItem> getItemsAt(Class<? extends HabboItem> type, int x, int y)
  4157. {
  4158. THashSet<HabboItem> items = new THashSet<>();
  4159.  
  4160. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  4161.  
  4162. for (int i = this.roomItems.size(); i-- > 0; )
  4163. {
  4164. HabboItem item;
  4165. try
  4166. {
  4167. iterator.advance();
  4168. item = iterator.value();
  4169. } catch (Exception e)
  4170. {
  4171. break;
  4172. }
  4173.  
  4174. if(item.getClass().equals(type))
  4175. {
  4176. if(item.getX() == x && item.getY() == y)
  4177. {
  4178. items.add(item);
  4179. }
  4180. else
  4181. {
  4182. if(item.getBaseItem().getWidth() <= 1 && item.getBaseItem().getLength() <= 1)
  4183. {
  4184. continue;
  4185. }
  4186.  
  4187. THashSet<RoomTile> tiles = this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
  4188. for (RoomTile tile : tiles){
  4189. if ((tile.x == x) && (tile.y == y) && (!items.contains(item))) {
  4190. items.add(item);
  4191. }
  4192. }
  4193. }
  4194. }
  4195. }
  4196.  
  4197. return items;
  4198. }
  4199.  
  4200. public boolean hasItemsAt(int x, int y)
  4201. {
  4202. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  4203.  
  4204. for (int i = this.roomItems.size(); i-- > 0; )
  4205. {
  4206. HabboItem habboItem;
  4207. try
  4208. {
  4209. iterator.advance();
  4210. habboItem = iterator.value();
  4211. } catch (Exception e)
  4212. {
  4213. break;
  4214. }
  4215.  
  4216. if (habboItem.getX() == x && habboItem.getY() == y) return true;
  4217. }
  4218.  
  4219. return false;
  4220. }
  4221.  
  4222. public HabboItem getTopItemAt(int x, int y)
  4223. {
  4224. return this.getTopItemAt(x, y, null);
  4225. }
  4226.  
  4227. public HabboItem getTopItemAt(int x, int y, HabboItem exclude)
  4228. {
  4229. HabboItem item = null;
  4230.  
  4231. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  4232.  
  4233. for (int i = this.roomItems.size(); i-- > 0; )
  4234. {
  4235. HabboItem habboItem;
  4236. try
  4237. {
  4238. iterator.advance();
  4239. habboItem = iterator.value();
  4240. }
  4241. catch (Exception e)
  4242. {
  4243. break;
  4244. }
  4245.  
  4246. if (habboItem.getBaseItem().getType() != FurnitureType.FLOOR)
  4247. continue;
  4248.  
  4249. if (exclude != null)
  4250. {
  4251. if (exclude == habboItem)
  4252. continue;
  4253. }
  4254.  
  4255. if (habboItem.getX() == x && habboItem.getY() == y)
  4256. {
  4257. if (item == null || (habboItem.getZ() + Item.getCurrentHeight(habboItem)) > (item.getZ() + Item.getCurrentHeight(item)))
  4258. {
  4259. item = habboItem;
  4260. }
  4261. } else
  4262. {
  4263. if (habboItem.getBaseItem().getWidth() <= 1 && habboItem.getBaseItem().getLength() <= 1)
  4264. {
  4265. continue;
  4266. }
  4267.  
  4268. THashSet<RoomTile> tiles = this.layout.getTilesAt(
  4269. this.layout.getTile(habboItem.getX(), habboItem.getY()),
  4270. habboItem.getBaseItem().getWidth(),
  4271. habboItem.getBaseItem().getLength(),
  4272. habboItem.getRotation());
  4273.  
  4274. for (RoomTile tile : tiles)
  4275. {
  4276. if (((tile.x == x) && (tile.y == y)))
  4277. {
  4278. if (item == null || item.getZ() < habboItem.getZ())
  4279. item = habboItem;
  4280. }
  4281. }
  4282. }
  4283. }
  4284.  
  4285. return item;
  4286. }
  4287.  
  4288. public double getTopHeightAt(int x, int y)
  4289. {
  4290. HabboItem item = this.getTopItemAt(x, y);
  4291.  
  4292. if(item != null)
  4293. return (item.getZ() + item.getBaseItem().getHeight());
  4294. else
  4295. return this.layout.getHeightAtSquare(x, y);
  4296. }
  4297.  
  4298. @Deprecated
  4299. public HabboItem getLowestChair(int x, int y)
  4300. {
  4301. RoomTile tile = this.layout.getTile((short)x, (short)y);
  4302.  
  4303. if (tile != null)
  4304. {
  4305. return this.getLowestChair(tile);
  4306. }
  4307.  
  4308. return null;
  4309. }
  4310.  
  4311. public HabboItem getLowestChair(RoomTile tile)
  4312. {
  4313. HabboItem lowestChair = null;
  4314.  
  4315. THashSet<HabboItem> items = this.getItemsAt(tile);
  4316. if (items != null && !items.isEmpty())
  4317. {
  4318. for (HabboItem item : items)
  4319. {
  4320. if (item.getBaseItem().allowSit())
  4321. {
  4322. if (lowestChair == null || item.getZ() < lowestChair.getZ())
  4323. {
  4324. lowestChair = item;
  4325. }
  4326. }
  4327.  
  4328. if (lowestChair != null)
  4329. {
  4330. if (item.getZ() > lowestChair.getZ() && item.getZ() - lowestChair.getZ() < 1.5)
  4331. {
  4332. lowestChair = null;
  4333. }
  4334. }
  4335. }
  4336. }
  4337.  
  4338. return lowestChair;
  4339. }
  4340.  
  4341. public double getStackHeight(short x, short y, boolean calculateHeightmap, HabboItem exclude)
  4342. {
  4343. if(x < 0 || y < 0)
  4344. return calculateHeightmap ? Short.MAX_VALUE : 0.0;
  4345.  
  4346. double height = this.layout.getHeightAtSquare(x, y);
  4347. boolean canStack = true;
  4348. boolean stackHelper = false;
  4349. THashSet<HabboItem> items = this.getItemsAt(x, y);
  4350. if (items != null)
  4351. {
  4352. for (HabboItem item : items)
  4353. {
  4354. if (item == exclude) continue;
  4355.  
  4356. if (item instanceof InteractionStackHelper)
  4357. {
  4358. stackHelper = true;
  4359. height = item.getExtradata().isEmpty() ? Double.valueOf("0.0") : (Double.valueOf(item.getExtradata()) / 100);
  4360. canStack = true;
  4361. }
  4362. }
  4363.  
  4364. if (!stackHelper)
  4365. {
  4366. HabboItem item = this.getTopItemAt(x, y, exclude);
  4367. if (item != null)
  4368. {
  4369. canStack = item.getBaseItem().allowStack();
  4370. height = item.getZ() + Item.getCurrentHeight(item);
  4371. }
  4372. }
  4373. }
  4374.  
  4375. if(calculateHeightmap)
  4376. {
  4377. return (canStack ? height * 256.0D : Short.MAX_VALUE);
  4378. }
  4379.  
  4380. return canStack ? height : -1;
  4381. }
  4382.  
  4383. public double getStackHeight(short x, short y, boolean calculateHeightmap)
  4384. {
  4385. return this.getStackHeight(x, y, calculateHeightmap, null);
  4386. }
  4387.  
  4388. public boolean hasObjectTypeAt(Class<?> type, int x, int y)
  4389. {
  4390. THashSet<HabboItem> items = this.getItemsAt(x, y);
  4391.  
  4392. for(HabboItem item : items)
  4393. {
  4394. if(item.getClass() == type)
  4395. {
  4396. return true;
  4397. }
  4398. }
  4399.  
  4400. return false;
  4401. }
  4402.  
  4403. public boolean canSitOrLayAt(int x, int y)
  4404. {
  4405. if(this.hasHabbosAt(x, y))
  4406. return false;
  4407.  
  4408. THashSet<HabboItem> items = this.getItemsAt(x, y);
  4409.  
  4410. return this.canSitAt(items) || this.canLayAt(items);
  4411. }
  4412. public boolean canSitAt(int x, int y)
  4413. {
  4414. if(this.hasHabbosAt(x, y))
  4415. return false;
  4416.  
  4417. return this.canSitAt(this.getItemsAt(x, y));
  4418. }
  4419.  
  4420. boolean canWalkAt(RoomTile roomTile)
  4421. {
  4422. if (roomTile == null)
  4423. {
  4424. return false;
  4425. }
  4426.  
  4427. if (roomTile.state == RoomTileState.INVALID)
  4428. return false;
  4429.  
  4430. HabboItem topItem = null;
  4431. boolean canWalk = true;
  4432. THashSet<HabboItem> items = this.getItemsAt(roomTile);
  4433. if (items != null)
  4434. {
  4435. for (HabboItem item : items)
  4436. {
  4437. if (topItem == null)
  4438. {
  4439. topItem = item;
  4440. }
  4441.  
  4442. if (item.getZ() > topItem.getZ())
  4443. {
  4444. topItem = item;
  4445. canWalk = topItem.isWalkable() || topItem.getBaseItem().allowWalk();
  4446. }
  4447. else if (item.getZ() == topItem.getZ() && canWalk)
  4448. {
  4449. if ((!topItem.isWalkable() && !topItem.getBaseItem().allowWalk()) || (!item.getBaseItem().allowWalk() && !item.isWalkable()))
  4450. {
  4451. canWalk = false;
  4452. }
  4453. }
  4454. }
  4455. }
  4456.  
  4457. return canWalk;
  4458. }
  4459.  
  4460. boolean canSitAt(THashSet<HabboItem> items)
  4461. {
  4462. if (items == null)
  4463. return false;
  4464.  
  4465. HabboItem topItem = null;
  4466. HabboItem lowestSitItem = null;
  4467. boolean canSitUnder = false;
  4468.  
  4469. for(HabboItem item : items)
  4470. {
  4471. if((lowestSitItem == null || lowestSitItem.getZ() > item.getZ()) && item.getBaseItem().allowSit())
  4472. {
  4473. lowestSitItem = item;
  4474. canSitUnder = true;
  4475. }
  4476.  
  4477. if(lowestSitItem != null && canSitUnder)
  4478. {
  4479. if (item != lowestSitItem)
  4480. {
  4481. double distance = item.getZ() - lowestSitItem.getZ();
  4482.  
  4483. if (distance >= 0 && distance < 0.8)
  4484. {
  4485. canSitUnder = false;
  4486. }
  4487. }
  4488. }
  4489.  
  4490. if(topItem == null || Item.getCurrentHeight(item) > Item.getCurrentHeight(topItem))
  4491. {
  4492. topItem = item;
  4493. }
  4494. }
  4495.  
  4496. if(topItem == null)
  4497. return false;
  4498.  
  4499. if(lowestSitItem == null)
  4500. return false;
  4501.  
  4502. if(topItem == lowestSitItem)
  4503. return true;
  4504.  
  4505. return topItem.getZ() <= lowestSitItem.getZ() || (canSitUnder);
  4506. }
  4507.  
  4508. public boolean canLayAt(int x, int y)
  4509. {
  4510. return this.canLayAt(this.getItemsAt(x, y));
  4511. }
  4512.  
  4513. boolean canLayAt(THashSet<HabboItem> items)
  4514. {
  4515. if (items == null || items.isEmpty())
  4516. return true;
  4517.  
  4518. HabboItem topItem = null;
  4519.  
  4520. for(HabboItem item : items)
  4521. {
  4522. if((topItem == null || item.getZ() > topItem.getZ()))
  4523. {
  4524. topItem = item;
  4525. }
  4526. }
  4527.  
  4528. return (topItem == null || topItem.getBaseItem().allowLay());
  4529. }
  4530.  
  4531. public RoomTile getRandomWalkableTile()
  4532. {
  4533. for (int i = 0; i < 10; i++)
  4534. {
  4535. RoomTile tile = this.layout.getTile((short) (Math.random() * this.layout.getMapSizeX()), (short) (Math.random() * this.layout.getMapSizeY()));
  4536. if (tile.isWalkable())
  4537. {
  4538. return tile;
  4539. }
  4540. }
  4541.  
  4542. return null;
  4543. }
  4544.  
  4545. public Habbo getHabbo(String username)
  4546. {
  4547. for (Habbo habbo : this.getHabbos())
  4548. {
  4549. if (habbo.getHabboInfo().getUsername().equalsIgnoreCase(username))
  4550. return habbo;
  4551. }
  4552. return null;
  4553. }
  4554.  
  4555. public Habbo getHabbo(RoomUnit roomUnit)
  4556. {
  4557. for (Habbo habbo : this.getHabbos())
  4558. {
  4559. if (habbo.getRoomUnit() == roomUnit)
  4560. return habbo;
  4561. }
  4562. return null;
  4563. }
  4564.  
  4565. public Habbo getHabbo(int userId)
  4566. {
  4567. return this.currentHabbos.get(userId);
  4568. }
  4569.  
  4570. public Habbo getHabboByRoomUnitId(int roomUnitId)
  4571. {
  4572. for (Habbo habbo : this.getHabbos())
  4573. {
  4574. if(habbo.getRoomUnit().getId() == roomUnitId)
  4575. return habbo;
  4576. }
  4577.  
  4578. return null;
  4579. }
  4580.  
  4581. public void sendComposer(ServerMessage message)
  4582. {
  4583. for (Habbo habbo : this.getHabbos())
  4584. {
  4585. habbo.getClient().sendResponse(message);
  4586. }
  4587. }
  4588.  
  4589. public void sendComposerToHabbosWithRights(ServerMessage message)
  4590. {
  4591. for (Habbo habbo : this.getHabbos())
  4592. {
  4593. if (this.hasRights(habbo))
  4594. {
  4595. habbo.getClient().sendResponse(message);
  4596. }
  4597. }
  4598. }
  4599.  
  4600. public void petChat(ServerMessage message)
  4601. {
  4602. for (Habbo habbo : this.getHabbos())
  4603. {
  4604. if (!habbo.getHabboStats().ignorePets)
  4605. habbo.getClient().sendResponse(message);
  4606. }
  4607. }
  4608.  
  4609. public void botChat(ServerMessage message)
  4610. {
  4611. for (Habbo habbo : this.getHabbos())
  4612. {
  4613. if (!habbo.getHabboStats().ignoreBots)
  4614. habbo.getClient().sendResponse(message);
  4615. }
  4616. }
  4617.  
  4618. private void loadRights(Connection connection)
  4619. {
  4620. this.rights.clear();
  4621. try (PreparedStatement statement = connection.prepareStatement("SELECT user_id FROM room_rights WHERE room_id = ?"))
  4622. {
  4623. statement.setInt(1, this.id);
  4624. try (ResultSet set = statement.executeQuery())
  4625. {
  4626. while (set.next())
  4627. {
  4628. this.rights.add(set.getInt("user_id"));
  4629. }
  4630. }
  4631. }
  4632. catch (SQLException e)
  4633. {
  4634. Emulator.getLogging().logSQLException(e);
  4635. }
  4636. }
  4637.  
  4638. private void loadBans(Connection connection)
  4639. {
  4640. this.bannedHabbos.clear();
  4641.  
  4642. try (PreparedStatement statement = connection.prepareStatement("SELECT users.username, users.id, room_bans.* FROM room_bans INNER JOIN users ON room_bans.user_id = users.id WHERE ends > ? AND room_bans.room_id = ?"))
  4643. {
  4644. statement.setInt(1, Emulator.getIntUnixTimestamp());
  4645. statement.setInt(2, this.id);
  4646. try (ResultSet set = statement.executeQuery())
  4647. {
  4648. while (set.next())
  4649. {
  4650. if (this.bannedHabbos.containsKey(set.getInt("user_id")))
  4651. continue;
  4652.  
  4653. this.bannedHabbos.put(set.getInt("user_id"), new RoomBan(set));
  4654. }
  4655. }
  4656. }
  4657. catch (SQLException e)
  4658. {
  4659. Emulator.getLogging().logSQLException(e);
  4660. }
  4661. }
  4662.  
  4663. //TODO: Return Enum
  4664. public int guildRightLevel(Habbo habbo)
  4665. {
  4666. if(this.guild > 0 && habbo.getHabboStats().hasGuild(this.guild))
  4667. {
  4668. Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guild);
  4669.  
  4670. if(Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(guild).get(habbo.getHabboInfo().getId()) != null)
  4671. return 3;
  4672.  
  4673. if(guild.getRights() == 0)
  4674. {
  4675. return 2;
  4676. }
  4677. }
  4678.  
  4679. return 0;
  4680. }
  4681.  
  4682. public boolean isOwner(Habbo habbo)
  4683. {
  4684. return habbo.getHabboInfo().getId() == this.ownerId || habbo.hasPermission(Permission.ACC_ANYROOMOWNER);
  4685. }
  4686.  
  4687. public boolean hasRights(Habbo habbo)
  4688. {
  4689. return this.isOwner(habbo) || this.rights.contains(habbo.getHabboInfo().getId()) || (habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE && this.currentHabbos.containsKey(habbo.getHabboInfo().getId()));
  4690. }
  4691.  
  4692. public void giveRights(Habbo habbo)
  4693. {
  4694. if(habbo != null)
  4695. {
  4696. this.giveRights(habbo.getHabboInfo().getId());
  4697. }
  4698. }
  4699.  
  4700. public void giveRights(int userId)
  4701. {
  4702. if (this.rights.contains(userId))
  4703. return;
  4704.  
  4705. if(this.rights.add(userId))
  4706. {
  4707. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_rights VALUES (?, ?)"))
  4708. {
  4709. statement.setInt(1, this.id);
  4710. statement.setInt(2, userId);
  4711. statement.execute();
  4712. }
  4713. catch (SQLException e)
  4714. {
  4715. Emulator.getLogging().logSQLException(e);
  4716. }
  4717. }
  4718.  
  4719. Habbo habbo = this.getHabbo(userId);
  4720.  
  4721. if(habbo != null)
  4722. {
  4723. this.refreshRightsForHabbo(habbo);
  4724.  
  4725. this.sendComposer(new RoomAddRightsListComposer(this, habbo.getHabboInfo().getId(), habbo.getHabboInfo().getUsername()).compose());
  4726. }
  4727. else
  4728. {
  4729. Habbo owner = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.ownerId);
  4730.  
  4731. if(owner != null)
  4732. {
  4733. MessengerBuddy buddy = owner.getMessenger().getFriend(userId);
  4734.  
  4735. if(buddy != null)
  4736. {
  4737. this.sendComposer(new RoomAddRightsListComposer(this, userId, buddy.getUsername()).compose());
  4738. }
  4739. }
  4740. }
  4741. }
  4742.  
  4743. public void removeRights(int userId)
  4744. {
  4745. Habbo habbo = this.getHabbo(userId);
  4746.  
  4747. if(Emulator.getPluginManager().fireEvent(new UserRightsTakenEvent(this.getHabbo(this.getOwnerId()), userId, habbo)).isCancelled())
  4748. return;
  4749.  
  4750. this.sendComposer(new RoomRemoveRightsListComposer(this, userId).compose());
  4751.  
  4752. if(this.rights.remove(userId))
  4753. {
  4754. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_rights WHERE room_id = ? AND user_id = ?"))
  4755. {
  4756. statement.setInt(1, this.id);
  4757. statement.setInt(2, userId);
  4758. statement.execute();
  4759. }
  4760. catch (SQLException e)
  4761. {
  4762. Emulator.getLogging().logSQLException(e);
  4763. }
  4764. }
  4765.  
  4766. if(habbo != null)
  4767. {
  4768. habbo.getRoomUnit().setRightsLevel(RoomRightLevels.NONE);
  4769. habbo.getRoomUnit().removeStatus(RoomUnitStatus.FLAT_CONTROL);
  4770. this.refreshRightsForHabbo(habbo);
  4771. }
  4772. }
  4773.  
  4774. public void removeAllRights()
  4775. {
  4776. this.rights.clear();
  4777.  
  4778. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_rights WHERE room_id = ?"))
  4779. {
  4780. statement.setInt(1, this.id);
  4781. statement.execute();
  4782. }
  4783. catch (SQLException e)
  4784. {
  4785. Emulator.getLogging().logSQLException(e);
  4786. }
  4787.  
  4788. this.refreshRightsInRoom();
  4789. }
  4790.  
  4791. void refreshRightsInRoom()
  4792. {
  4793. Room room = this;
  4794. for (Habbo habbo : this.getHabbos())
  4795. {
  4796. if(habbo.getHabboInfo().getCurrentRoom() == room)
  4797. {
  4798. this.refreshRightsForHabbo(habbo);
  4799. }
  4800. }
  4801. }
  4802.  
  4803. public void refreshRightsForHabbo(Habbo habbo)
  4804. {
  4805. HabboItem item;
  4806. RoomRightLevels flatCtrl = RoomRightLevels.NONE;
  4807. if (habbo.getHabboStats().isRentingSpace())
  4808. {
  4809. item = this.getHabboItem(habbo.getHabboStats().getRentedItemId());
  4810.  
  4811. if (item != null)
  4812. {
  4813. return;
  4814. }
  4815. }
  4816.  
  4817. if (habbo.hasPermission(Permission.ACC_ANYROOMOWNER))
  4818. {
  4819. habbo.getClient().sendResponse(new RoomOwnerComposer());
  4820. flatCtrl = RoomRightLevels.MODERATOR;
  4821. }
  4822. else if (this.isOwner(habbo))
  4823. {
  4824. habbo.getClient().sendResponse(new RoomOwnerComposer());
  4825. flatCtrl = RoomRightLevels.MODERATOR;
  4826. }
  4827. else if (this.hasRights(habbo) && !this.hasGuild())
  4828. {
  4829. flatCtrl = RoomRightLevels.RIGHTS;
  4830. }
  4831. else if (this.hasGuild())
  4832. {
  4833. int level = this.guildRightLevel(habbo);
  4834.  
  4835. if(level == 3)
  4836. {
  4837. flatCtrl = RoomRightLevels.GUILD_ADMIN;
  4838. }
  4839. else if(level == 2)
  4840. {
  4841. flatCtrl = RoomRightLevels.GUILD_RIGHTS;
  4842. }
  4843. }
  4844.  
  4845.  
  4846. habbo.getClient().sendResponse(new RoomRightsComposer(flatCtrl));
  4847. habbo.getRoomUnit().setStatus(RoomUnitStatus.FLAT_CONTROL, flatCtrl.level + "");
  4848. habbo.getRoomUnit().setRightsLevel(flatCtrl);
  4849. habbo.getRoomUnit().statusUpdate(true);
  4850.  
  4851. if (flatCtrl.equals(RoomRightLevels.MODERATOR))
  4852. {
  4853. habbo.getClient().sendResponse(new RoomRightsListComposer(this));
  4854. }
  4855. }
  4856.  
  4857. public THashMap<Integer, String> getUsersWithRights()
  4858. {
  4859. THashMap<Integer, String> rightsMap = new THashMap<>();
  4860.  
  4861. if(!this.rights.isEmpty())
  4862. {
  4863. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT users.username AS username, users.id as user_id FROM room_rights INNER JOIN users ON room_rights.user_id = users.id WHERE room_id = ?"))
  4864. {
  4865. statement.setInt(1, this.id);
  4866. try (ResultSet set = statement.executeQuery())
  4867. {
  4868. while (set.next())
  4869. {
  4870. rightsMap.put(set.getInt("user_id"), set.getString("username"));
  4871. }
  4872. }
  4873. }
  4874. catch (SQLException e)
  4875. {
  4876. Emulator.getLogging().logSQLException(e);
  4877. }
  4878. }
  4879.  
  4880. return rightsMap;
  4881. }
  4882.  
  4883. public void unbanHabbo(int userId)
  4884. {
  4885. RoomBan ban = this.bannedHabbos.remove(userId);
  4886.  
  4887. if(ban != null)
  4888. {
  4889. ban.delete();
  4890. }
  4891.  
  4892. this.sendComposer(new RoomUserUnbannedComposer(this, userId).compose());
  4893. }
  4894.  
  4895. public boolean isBanned(Habbo habbo)
  4896. {
  4897. RoomBan ban = this.bannedHabbos.get(habbo.getHabboInfo().getId());
  4898.  
  4899. boolean banned = ban != null && ban.endTimestamp > Emulator.getIntUnixTimestamp() && !habbo.hasPermission(Permission.ACC_ANYROOMOWNER) && !habbo.hasPermission("acc_enteranyroom");
  4900.  
  4901. if (!banned && ban != null)
  4902. {
  4903. this.unbanHabbo(habbo.getHabboInfo().getId());
  4904. }
  4905.  
  4906. return banned;
  4907. }
  4908.  
  4909. public TIntObjectHashMap<RoomBan> getBannedHabbos()
  4910. {
  4911. return this.bannedHabbos;
  4912. }
  4913.  
  4914. public void addRoomBan(RoomBan roomBan)
  4915. {
  4916. this.bannedHabbos.put(roomBan.userId, roomBan);
  4917. }
  4918.  
  4919. public void makeSit(Habbo habbo)
  4920. {
  4921. if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT))
  4922. {
  4923. return;
  4924. }
  4925.  
  4926.  
  4927. this.dance(habbo, DanceType.NONE);
  4928. habbo.getRoomUnit().cmdSit = true;
  4929. habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[habbo.getRoomUnit().getBodyRotation().getValue() - habbo.getRoomUnit().getBodyRotation().getValue() % 2]);
  4930. habbo.getRoomUnit().setStatus(RoomUnitStatus.SIT, 0.5 + "");
  4931. this.sendComposer(new RoomUserStatusComposer(habbo.getRoomUnit()).compose());
  4932. }
  4933.  
  4934. public void giveEffect(Habbo habbo, int effectId, int duration)
  4935. {
  4936. if (this.currentHabbos.containsKey(habbo.getHabboInfo().getId()))
  4937. {
  4938. this.giveEffect(habbo.getRoomUnit(), effectId, duration);
  4939. }
  4940. }
  4941.  
  4942. public void giveEffect(RoomUnit roomUnit, int effectId, int duration)
  4943. {
  4944. if (duration == - 1 || duration == Integer.MAX_VALUE)
  4945. {
  4946. duration = Integer.MAX_VALUE;
  4947. }
  4948. else
  4949. {
  4950. duration += Emulator.getIntUnixTimestamp();
  4951. }
  4952.  
  4953. if (this.allowEffects && roomUnit != null)
  4954. {
  4955. roomUnit.setEffectId(effectId, duration);
  4956. this.sendComposer(new RoomUserEffectComposer(roomUnit).compose());
  4957. }
  4958. }
  4959.  
  4960. public void giveHandItem(Habbo habbo, int handItem)
  4961. {
  4962. this.giveHandItem(habbo.getRoomUnit(), handItem);
  4963. }
  4964.  
  4965. public void giveHandItem(RoomUnit roomUnit, int handItem)
  4966. {
  4967. roomUnit.setHandItem(handItem);
  4968. this.sendComposer(new RoomUserHandItemComposer(roomUnit).compose());
  4969. }
  4970.  
  4971. public void updateItem(HabboItem item)
  4972. {
  4973. if (this.isLoaded())
  4974. {
  4975. if (item != null && item.getRoomId() == this.id)
  4976. {
  4977. if (item.getBaseItem() != null)
  4978. {
  4979. if (item.getBaseItem().getType() == FurnitureType.FLOOR)
  4980. {
  4981. this.sendComposer(new FloorItemUpdateComposer(item).compose());
  4982. this.updateTiles(this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
  4983. }
  4984. else if (item.getBaseItem().getType() == FurnitureType.WALL)
  4985. {
  4986. this.sendComposer(new WallItemUpdateComposer(item).compose());
  4987. }
  4988. }
  4989. }
  4990. }
  4991. }
  4992.  
  4993. public void updateItemState(HabboItem item)
  4994. {
  4995. if (!item.isLimited())
  4996. {
  4997. this.sendComposer(new ItemStateComposer(item).compose());
  4998. }
  4999. else
  5000. {
  5001. this.sendComposer(new FloorItemUpdateComposer(item).compose());
  5002. }
  5003.  
  5004. if (item.getBaseItem().getType() == FurnitureType.FLOOR)
  5005. {
  5006. this.updateTiles(this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
  5007. }
  5008. }
  5009.  
  5010. public int getUserFurniCount(int userId)
  5011. {
  5012. return this.furniOwnerCount.get(userId);
  5013. }
  5014.  
  5015. public void ejectUserFurni(int userId)
  5016. {
  5017. THashSet<HabboItem> items = new THashSet<>();
  5018.  
  5019. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  5020.  
  5021. for (int i = this.roomItems.size(); i-- > 0; )
  5022. {
  5023. try
  5024. {
  5025. iterator.advance();
  5026. }
  5027. catch (Exception e)
  5028. {
  5029. break;
  5030. }
  5031.  
  5032. if (iterator.value().getUserId() == userId)
  5033. {
  5034. items.add(iterator.value());
  5035. iterator.value().setRoomId(0);
  5036. }
  5037. }
  5038.  
  5039. Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId);
  5040.  
  5041. if (habbo != null)
  5042. {
  5043. habbo.getInventory().getItemsComponent().addItems(items);
  5044. habbo.getClient().sendResponse(new AddHabboItemComposer(items));
  5045. }
  5046.  
  5047. for (HabboItem i : items)
  5048. {
  5049. this.pickUpItem(i, null);
  5050. }
  5051. }
  5052.  
  5053. public void ejectUserItem(HabboItem item)
  5054. {
  5055. this.pickUpItem(item, null);
  5056. }
  5057.  
  5058. /**
  5059. * Ejects all furniture from the room not belonging to the room owner.
  5060. */
  5061. public void ejectAll()
  5062. {
  5063. this.ejectAll(null);
  5064. }
  5065.  
  5066. /**
  5067. * @param habbo The Habbo to exclude to eject its items.
  5068. */
  5069. public void ejectAll(Habbo habbo)
  5070. {
  5071. THashMap<Integer, THashSet<HabboItem>> userItemsMap = new THashMap<>();
  5072.  
  5073. synchronized (this.roomItems)
  5074. {
  5075. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  5076.  
  5077. for (int i = this.roomItems.size(); i-- > 0; )
  5078. {
  5079. try
  5080. {
  5081. iterator.advance();
  5082. }
  5083. catch (Exception e)
  5084. {
  5085. break;
  5086. }
  5087.  
  5088. if (habbo != null && iterator.value().getUserId() == habbo.getHabboInfo().getId())
  5089. continue;
  5090.  
  5091. if (userItemsMap.get(iterator.value().getUserId()) == null)
  5092. {
  5093. userItemsMap.put(iterator.value().getUserId(), new THashSet<>());
  5094. }
  5095.  
  5096. userItemsMap.get(iterator.value().getUserId()).add(iterator.value());
  5097. }
  5098. }
  5099.  
  5100. for (Map.Entry<Integer, THashSet<HabboItem>> entrySet : userItemsMap.entrySet())
  5101. {
  5102. for (HabboItem i : entrySet.getValue())
  5103. {
  5104. this.pickUpItem(i, null);
  5105. }
  5106.  
  5107. Habbo user = Emulator.getGameEnvironment().getHabboManager().getHabbo(entrySet.getKey());
  5108.  
  5109. if (user != null)
  5110. {
  5111. user.getInventory().getItemsComponent().addItems(entrySet.getValue());
  5112. user.getClient().sendResponse(new AddHabboItemComposer(entrySet.getValue()));
  5113. }
  5114. }
  5115. }
  5116.  
  5117. public void refreshGuild(Guild guild)
  5118. {
  5119. if(guild.getRoomId() == this.id)
  5120. {
  5121. THashMap<Integer, GuildMember> admins = Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(guild);
  5122.  
  5123. for (Habbo habbo : this.getHabbos())
  5124. {
  5125. GuildMember member = admins.get(habbo.getHabboInfo().getId());
  5126. habbo.getClient().sendResponse(new GuildInfoComposer(guild, habbo.getClient(), false, member));
  5127. }
  5128. }
  5129.  
  5130. this.refreshGuildRightsInRoom();
  5131. }
  5132.  
  5133. public void refreshGuildColors(Guild guild)
  5134. {
  5135. if(guild.getRoomId() == this.id)
  5136. {
  5137. TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator();
  5138.  
  5139. for (int i = this.roomItems.size(); i-- > 0; )
  5140. {
  5141. try
  5142. {
  5143. iterator.advance();
  5144. }
  5145. catch (Exception e)
  5146. {
  5147. break;
  5148. }
  5149.  
  5150. HabboItem habboItem = iterator.value();
  5151.  
  5152. if (habboItem instanceof InteractionGuildFurni)
  5153. {
  5154. if (((InteractionGuildFurni) habboItem).getGuildId() == guild.getId())
  5155. this.updateItem(habboItem);
  5156. }
  5157. }
  5158. }
  5159. }
  5160.  
  5161. public void refreshGuildRightsInRoom()
  5162. {
  5163. for (Habbo habbo : this.getHabbos())
  5164. {
  5165. if (habbo.getHabboInfo().getCurrentRoom() == this)
  5166. {
  5167. if (habbo.getHabboInfo().getId() != this.ownerId)
  5168. {
  5169. if (!(habbo.hasPermission(Permission.ACC_ANYROOMOWNER) || habbo.hasPermission("acc_moverotate")))
  5170. this.refreshRightsForHabbo(habbo);
  5171. }
  5172. }
  5173. }
  5174. }
  5175.  
  5176. public void idle(Habbo habbo)
  5177. {
  5178. habbo.getRoomUnit().setIdle();
  5179. this.sendComposer(new RoomUnitIdleComposer(habbo.getRoomUnit()).compose());
  5180. WiredHandler.handle(WiredTriggerType.IDLES, habbo.getRoomUnit(), this, new Object[]{habbo});
  5181. }
  5182.  
  5183. public void unIdle(Habbo habbo)
  5184. {
  5185. habbo.getRoomUnit().resetIdleTimer();
  5186. this.sendComposer(new RoomUnitIdleComposer(habbo.getRoomUnit()).compose());
  5187. WiredHandler.handle(WiredTriggerType.UNIDLES, habbo.getRoomUnit(), this, new Object[]{habbo});
  5188. }
  5189.  
  5190. public void dance(Habbo habbo, DanceType danceType)
  5191. {
  5192. this.dance(habbo.getRoomUnit(), danceType);
  5193. }
  5194.  
  5195. public void dance(RoomUnit unit, DanceType danceType)
  5196. {
  5197. boolean isDancing = !unit.getDanceType().equals(DanceType.NONE);
  5198. unit.setDanceType(danceType);
  5199. this.sendComposer(new RoomUserDanceComposer(unit).compose());
  5200.  
  5201. if (danceType.equals(DanceType.NONE) && isDancing)
  5202. {
  5203. WiredHandler.handle(WiredTriggerType.STOPS_DANCING, unit, this, new Object[]{unit});
  5204. }
  5205. else if (!danceType.equals(DanceType.NONE) && !isDancing)
  5206. {
  5207. WiredHandler.handle(WiredTriggerType.STARTS_DANCING, unit, this, new Object[]{unit});
  5208. }
  5209. }
  5210.  
  5211. public void addToWordFilter(String word)
  5212. {
  5213. synchronized (this.wordFilterWords)
  5214. {
  5215. if (this.wordFilterWords.contains(word))
  5216. return;
  5217.  
  5218.  
  5219. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT IGNORE INTO room_wordfilter VALUES (?, ?)"))
  5220. {
  5221. statement.setInt(1, this.getId());
  5222. statement.setString(2, word);
  5223. statement.execute();
  5224. }
  5225. catch (SQLException e)
  5226. {
  5227. Emulator.getLogging().logSQLException(e);
  5228. return;
  5229. }
  5230.  
  5231. this.wordFilterWords.add(word);
  5232. }
  5233. }
  5234.  
  5235. public void removeFromWordFilter(String word)
  5236. {
  5237. synchronized (this.wordFilterWords)
  5238. {
  5239. this.wordFilterWords.remove(word);
  5240.  
  5241. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_wordfilter WHERE room_id = ? AND word = ?"))
  5242. {
  5243. statement.setInt(1, this.getId());
  5244. statement.setString(2, word);
  5245. statement.execute();
  5246. }
  5247. catch (SQLException e)
  5248. {
  5249. Emulator.getLogging().logSQLException(e);
  5250. }
  5251. }
  5252. }
  5253.  
  5254. public THashSet<WiredHighscoreData> getWiredHighscoreData(WiredHighscoreScoreType scoreType, WiredHighscoreClearType clearType)
  5255. {
  5256. if(!this.wiredHighscoreData.containsKey(scoreType))
  5257. {
  5258. this.loadWiredHighscoreData(scoreType, clearType);
  5259. }
  5260.  
  5261. return this.wiredHighscoreData.get(scoreType).get(clearType);
  5262. }
  5263.  
  5264. public void loadWiredHighscoreData(WiredHighscoreScoreType scoreType, WiredHighscoreClearType clearType)
  5265. {
  5266. this.wiredHighscoreData.clear();
  5267. THashSet<WiredHighscoreData> wiredData = new THashSet<>();
  5268.  
  5269. try
  5270. {
  5271. String query = "SELECT " +
  5272. "SUM(score + team_score) as total_score, " +
  5273. "COUNT(*) as wins, " +
  5274. "users.username, " +
  5275. "room_game_scores.*, " +
  5276. "GROUP_CONCAT(users.username) as usernames " +
  5277. "FROM room_game_scores " +
  5278. "INNER JOIN users ON room_game_scores.user_id = users.id " +
  5279. "WHERE room_id = ? AND game_start_timestamp >= ? ";
  5280.  
  5281. int timestamp = 0;
  5282. if(clearType != WiredHighscoreClearType.ALLTIME)
  5283. {
  5284. if(clearType == WiredHighscoreClearType.MONTHLY)
  5285. {
  5286. timestamp = Emulator.getIntUnixTimestamp() - (31 * 24 * 60 * 60);
  5287. }
  5288. else if(clearType == WiredHighscoreClearType.WEEKLY)
  5289. {
  5290. timestamp = Emulator.getIntUnixTimestamp() - (7 * 24 * 60 * 60);
  5291. }
  5292. else if(clearType == WiredHighscoreClearType.DAILY)
  5293. {
  5294. timestamp = Emulator.getIntUnixTimestamp() - (24 * 60 * 60);
  5295. }
  5296. }
  5297.  
  5298. /*
  5299. SELECT SUM(score + team_score) as total_score, COUNT(*) as wins, users.username, score, GROUP_CONCAT(users.username) as usernames FROM room_game_scores INNER JOIN users ON room_game_scores.user_id = users.id WHERE room_id = 0 GROUP BY game_start_timestamp, game_name, team_id ORDER BY total_score ASC, wins DESC LIMIT 10
  5300. */
  5301. if(scoreType == WiredHighscoreScoreType.CLASSIC)
  5302. {
  5303. query += "GROUP BY game_start_timestamp, user_id, team_id ORDER BY total_score DESC";
  5304. }
  5305. else if(scoreType == WiredHighscoreScoreType.MOSTWIN)
  5306. {
  5307. query += "GROUP BY game_start_timestamp, game_name, team_id ORDER BY wins DESC, total_score ASC";
  5308. }
  5309. else if(scoreType == WiredHighscoreScoreType.PERTEAM)
  5310. {
  5311. query += "GROUP BY game_start_timestamp, team_id ORDER BY team_score DESC";
  5312. }
  5313.  
  5314. query += " LIMIT " + Emulator.getConfig().getValue("wired.highscores.displaycount");
  5315.  
  5316. try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement(query))
  5317. {
  5318. statement.setInt(1, this.id);
  5319. statement.setInt(2, timestamp);
  5320.  
  5321. try (ResultSet set = statement.executeQuery())
  5322. {
  5323. while (set.next())
  5324. {
  5325. wiredData.add(new WiredHighscoreData(set.getString("usernames").split(","), set.getInt("score"), set.getInt("team_score"), set.getInt("total_score")));
  5326. }
  5327. }
  5328. }
  5329. }
  5330. catch (SQLException e)
  5331. {
  5332. Emulator.getLogging().logSQLException(e);
  5333. }
  5334.  
  5335. THashMap<WiredHighscoreClearType, THashSet<WiredHighscoreData>> dataMap = new THashMap<>();
  5336. dataMap.put(clearType, wiredData);
  5337. this.wiredHighscoreData.put(scoreType, dataMap);
  5338. }
  5339.  
  5340. public void handleWordQuiz(Habbo habbo, String answer)
  5341. {
  5342. synchronized (this.userVotes)
  5343. {
  5344. if (!this.wordQuiz.isEmpty() && !this.hasVotedInWordQuiz(habbo))
  5345. {
  5346. answer = answer.replace(":", "");
  5347.  
  5348. if (answer.equals("0"))
  5349. {
  5350. this.noVotes++;
  5351. }
  5352. else if (answer.equals("1"))
  5353. {
  5354. this.yesVotes++;
  5355. }
  5356.  
  5357. this.sendComposer(new SimplePollAnswerComposer(habbo.getHabboInfo().getId(), answer, this.noVotes, this.yesVotes).compose());
  5358. this.userVotes.add(habbo.getHabboInfo().getId());
  5359. }
  5360. }
  5361. }
  5362.  
  5363. public void startWordQuiz(String question, int duration)
  5364. {
  5365. if (!this.hasActiveWordQuiz())
  5366. {
  5367. this.wordQuiz = question;
  5368. this.noVotes = 0;
  5369. this.yesVotes = 0;
  5370. this.userVotes.clear();
  5371. this.wordQuizEnd = Emulator.getIntUnixTimestamp() + (duration / 1000);
  5372. this.sendComposer(new SimplePollStartComposer(duration, question).compose());
  5373. }
  5374. }
  5375.  
  5376. public boolean hasActiveWordQuiz()
  5377. {
  5378. return Emulator.getIntUnixTimestamp() < this.wordQuizEnd;
  5379. }
  5380.  
  5381. public boolean hasVotedInWordQuiz(Habbo habbo)
  5382. {
  5383. return this.userVotes.contains(habbo.getHabboInfo().getId());
  5384. }
  5385.  
  5386. public void alert(String message)
  5387. {
  5388. this.sendComposer(new GenericAlertComposer(message).compose());
  5389. }
  5390.  
  5391. public int itemCount()
  5392. {
  5393. return this.roomItems.size();
  5394. }
  5395.  
  5396. public void setJukeBoxActive(boolean jukeBoxActive)
  5397. {
  5398. this.jukeboxActive = jukeBoxActive;
  5399. this.needsUpdate = true;
  5400. }
  5401.  
  5402. public boolean isHideWired()
  5403. {
  5404. return this.hideWired;
  5405. }
  5406.  
  5407. public void setHideWired(boolean hideWired)
  5408. {
  5409. this.hideWired = hideWired;
  5410.  
  5411. if (this.hideWired)
  5412. {
  5413. ServerMessage response = null;
  5414. for (HabboItem item : this.roomSpecialTypes.getTriggers())
  5415. {
  5416. this.sendComposer(new RemoveFloorItemComposer(item).compose());
  5417. }
  5418.  
  5419. for (HabboItem item : this.roomSpecialTypes.getEffects())
  5420. {
  5421. this.sendComposer(new RemoveFloorItemComposer(item).compose());
  5422. }
  5423.  
  5424. for (HabboItem item : this.roomSpecialTypes.getConditions())
  5425. {
  5426. this.sendComposer(new RemoveFloorItemComposer(item).compose());
  5427. }
  5428.  
  5429. for (HabboItem item : this.roomSpecialTypes.getExtras())
  5430. {
  5431. this.sendComposer(new RemoveFloorItemComposer(item).compose());
  5432. }
  5433. }
  5434. else
  5435. {
  5436. this.sendComposer(new RoomFloorItemsComposer(this.furniOwnerNames, this.roomSpecialTypes.getTriggers()).compose());
  5437. this.sendComposer(new RoomFloorItemsComposer(this.furniOwnerNames, this.roomSpecialTypes.getEffects()).compose());
  5438. this.sendComposer(new RoomFloorItemsComposer(this.furniOwnerNames, this.roomSpecialTypes.getConditions()).compose());
  5439. this.sendComposer(new RoomFloorItemsComposer(this.furniOwnerNames, this.roomSpecialTypes.getExtras()).compose());
  5440. }
  5441. }
  5442.  
  5443. public FurnitureMovementError canPlaceFurnitureAt(HabboItem item, Habbo habbo, RoomTile tile, int rotation)
  5444. {
  5445. rotation %= 8;
  5446. if (this.hasRights(habbo) || this.guildRightLevel(habbo) >= 2 || habbo.hasPermission(Permission.ACC_MOVEROTATE))
  5447. {
  5448. return FurnitureMovementError.NONE;
  5449. }
  5450.  
  5451. if(habbo.getHabboStats().isRentingSpace())
  5452. {
  5453. HabboItem rentSpace = this.getHabboItem(habbo.getHabboStats().rentedItemId);
  5454.  
  5455. if (rentSpace != null)
  5456. {
  5457. if(!RoomLayout.squareInSquare(RoomLayout.getRectangle(rentSpace.getX(), rentSpace.getY(), rentSpace.getBaseItem().getWidth(), rentSpace.getBaseItem().getLength(), rentSpace.getRotation()), RoomLayout.getRectangle(tile.x, tile.y, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation)))
  5458. {
  5459. return FurnitureMovementError.NO_RIGHTS;
  5460. }
  5461. else
  5462. {
  5463. return FurnitureMovementError.NONE;
  5464. }
  5465. }
  5466. }
  5467.  
  5468. return FurnitureMovementError.NO_RIGHTS;
  5469. }
  5470.  
  5471. public FurnitureMovementError furnitureFitsAt(RoomTile tile, HabboItem item, int rotation)
  5472. {
  5473. THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation);
  5474.  
  5475. for (RoomTile t : occupiedTiles)
  5476. {
  5477. if (this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS;
  5478. if (this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS;
  5479. if (this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS;
  5480. }
  5481.  
  5482. List<Pair<RoomTile, THashSet<HabboItem>>> tileFurniList = new ArrayList<>();
  5483. for (RoomTile t : occupiedTiles)
  5484. {
  5485. tileFurniList.add(Pair.create(t, this.getItemsAt(t)));
  5486.  
  5487. HabboItem topItem = this.getTopItemAt(t.x, t.y, item);
  5488. if (topItem != null && !topItem.getBaseItem().allowStack())
  5489. {
  5490. return FurnitureMovementError.CANT_STACK;
  5491. }
  5492. }
  5493.  
  5494. if (!item.canStackAt(this, tileFurniList))
  5495. {
  5496. return FurnitureMovementError.CANT_STACK;
  5497. }
  5498.  
  5499. return FurnitureMovementError.NONE;
  5500. }
  5501. public FurnitureMovementError placeFloorFurniAt(HabboItem item, RoomTile tile, int rotation, Habbo owner) throws Exception
  5502. {
  5503. if(Emulator.getPluginManager().isRegistered(FurniturePlacedEvent.class, true))
  5504. {
  5505. Event furniturePlacedEvent = new FurniturePlacedEvent(item, owner, tile);
  5506. Emulator.getPluginManager().fireEvent(furniturePlacedEvent);
  5507.  
  5508. if(furniturePlacedEvent.isCancelled())
  5509. return FurnitureMovementError.CANCEL_PLUGIN_PLACE;
  5510. }
  5511.  
  5512. THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation);
  5513.  
  5514. FurnitureMovementError fits = furnitureFitsAt(tile, item, rotation);
  5515.  
  5516. if (!fits.equals(FurnitureMovementError.NONE))
  5517. {
  5518. return fits;
  5519. }
  5520.  
  5521. item.setZ(tile.getStackHeight());
  5522. item.setX(tile.x);
  5523. item.setY(tile.y);
  5524. item.setRotation(rotation);
  5525. if (!this.furniOwnerNames.containsKey(item.getUserId()) && owner != null)
  5526. {
  5527. this.furniOwnerNames.put(item.getUserId(), owner.getHabboInfo().getUsername());
  5528. }
  5529.  
  5530. item.needsUpdate(true);
  5531. this.addHabboItem(item);
  5532. item.setRoomId(this.id);
  5533. item.onPlace(this);
  5534. this.updateTiles(occupiedTiles);
  5535. this.sendComposer(new AddFloorItemComposer(item, this.getFurniOwnerName(item.getUserId())).compose());
  5536.  
  5537. for (RoomTile t : occupiedTiles)
  5538. {
  5539. this.updateHabbosAt(t.x, t.y);
  5540. }
  5541.  
  5542. Emulator.getThreading().run(item);
  5543. return FurnitureMovementError.NONE;
  5544. }
  5545.  
  5546. public FurnitureMovementError placeWallFurniAt(HabboItem item, String wallPosition, Habbo owner)
  5547. {
  5548. if (!(this.hasRights(owner) || this.guildRightLevel(owner) >= 2))
  5549. {
  5550. return FurnitureMovementError.NO_RIGHTS;
  5551. }
  5552.  
  5553. if(Emulator.getPluginManager().isRegistered(FurniturePlacedEvent.class, true))
  5554. {
  5555. Event furniturePlacedEvent = new FurniturePlacedEvent(item, owner, null);
  5556. Emulator.getPluginManager().fireEvent(furniturePlacedEvent);
  5557.  
  5558. if(furniturePlacedEvent.isCancelled())
  5559. return FurnitureMovementError.CANCEL_PLUGIN_PLACE;
  5560. }
  5561.  
  5562. item.setWallPosition(wallPosition);
  5563. if (!this.furniOwnerNames.containsKey(item.getUserId()) && owner != null)
  5564. {
  5565. this.furniOwnerNames.put(item.getUserId(), owner.getHabboInfo().getUsername());
  5566. }
  5567. this.sendComposer(new AddWallItemComposer(item, this.getFurniOwnerName(item.getUserId())).compose());
  5568. item.needsUpdate(true);
  5569. this.addHabboItem(item);
  5570. item.setRoomId(this.id);
  5571. item.onPlace(this);
  5572. Emulator.getThreading().run(item);
  5573. return FurnitureMovementError.NONE;
  5574. }
  5575.  
  5576. public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, Habbo actor)
  5577. {
  5578. RoomTile oldLocation = this.layout.getTile(item.getX(), item.getY());
  5579. if(Emulator.getPluginManager().isRegistered(FurnitureMovedEvent.class, true))
  5580. {
  5581. if (Emulator.getPluginManager().fireEvent(new FurnitureMovedEvent(item, actor, oldLocation, tile)).isCancelled())
  5582. return FurnitureMovementError.CANCEL_PLUGIN_MOVE;
  5583. }
  5584.  
  5585. HabboItem topItem = this.getTopItemAt(tile.x, tile.y);
  5586.  
  5587. boolean magicTile = item instanceof InteractionStackHelper;
  5588.  
  5589. //Check if can be placed at new position
  5590. THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation);
  5591. if (topItem != item)
  5592. {
  5593. for (RoomTile t : occupiedTiles)
  5594. {
  5595. if (!magicTile && ((this.getTopItemAt(t.x, t.y) != item ? t.state.equals(RoomTileState.INVALID) || !t.getAllowStack() : this.calculateTileState(t, item).equals(RoomTileState.INVALID))))
  5596. return FurnitureMovementError.CANT_STACK;
  5597. if (this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS;
  5598. if (this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS;
  5599. if (this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS;
  5600. }
  5601. }
  5602.  
  5603. List<Pair<RoomTile, THashSet<HabboItem>>> tileFurniList = new ArrayList<>();
  5604. for (RoomTile t : occupiedTiles)
  5605. {
  5606. tileFurniList.add(Pair.create(t, this.getItemsAt(t)));
  5607. }
  5608.  
  5609. if (!magicTile && !item.canStackAt(this, tileFurniList))
  5610. {
  5611. return FurnitureMovementError.CANT_STACK;
  5612. }
  5613.  
  5614. THashSet<RoomTile> oldOccupiedTiles = this.layout.getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
  5615.  
  5616. int oldRotation = item.getRotation();
  5617. item.setRotation(rotation);
  5618. if(Emulator.getPluginManager().isRegistered(FurnitureRotatedEvent.class, true))
  5619. {
  5620. Event furnitureRotatedEvent = new FurnitureRotatedEvent(item, actor, oldRotation);
  5621. Emulator.getPluginManager().fireEvent(furnitureRotatedEvent);
  5622.  
  5623. if(furnitureRotatedEvent.isCancelled())
  5624. {
  5625. item.setRotation(oldRotation);
  5626. return FurnitureMovementError.CANCEL_PLUGIN_ROTATE;
  5627. }
  5628. }
  5629. //Place at new position
  5630. item.setX(tile.x);
  5631. item.setY(tile.y);
  5632. item.setZ(this.getStackHeight(tile.x, tile.y, false, item));
  5633. if (magicTile)
  5634. {
  5635. item.setZ(tile.z);
  5636. item.setExtradata("" + item.getZ() * 100);
  5637. }
  5638. if (item.getZ() > 40d)
  5639. {
  5640. item.setZ(40);
  5641. }
  5642.  
  5643.  
  5644. //Update Furniture
  5645. item.onMove(this, oldLocation, tile);
  5646. item.needsUpdate(true);
  5647. Emulator.getThreading().run(item);
  5648.  
  5649. this.sendComposer(new FloorItemUpdateComposer(item).compose());
  5650. //Update old & new tiles
  5651. occupiedTiles.removeAll(oldOccupiedTiles);
  5652. occupiedTiles.addAll(oldOccupiedTiles);
  5653. this.updateTiles(occupiedTiles);
  5654.  
  5655. //Update Habbos at old position
  5656. for (RoomTile t : occupiedTiles)
  5657. {
  5658. this.updateHabbosAt(t.x, t.y);
  5659. }
  5660. return FurnitureMovementError.NONE;
  5661. }
  5662.  
  5663. public FurnitureMovementError slideFurniTo(HabboItem item, RoomTile tile, int rotation)
  5664. {
  5665. RoomTile oldLocation = this.layout.getTile(item.getX(), item.getY());
  5666.  
  5667. HabboItem topItem = this.getTopItemAt(tile.x, tile.y);
  5668.  
  5669. boolean magicTile = item instanceof InteractionStackHelper;
  5670.  
  5671. //Check if can be placed at new position
  5672. THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation);
  5673.  
  5674. List<Pair<RoomTile, THashSet<HabboItem>>> tileFurniList = new ArrayList<>();
  5675. for (RoomTile t : occupiedTiles)
  5676. {
  5677. tileFurniList.add(Pair.create(t, this.getItemsAt(t)));
  5678. }
  5679.  
  5680. if (!magicTile && !item.canStackAt(this, tileFurniList))
  5681. {
  5682. return FurnitureMovementError.CANT_STACK;
  5683. }
  5684.  
  5685. THashSet<RoomTile> oldOccupiedTiles = this.layout.getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
  5686.  
  5687. int oldRotation = item.getRotation();
  5688. item.setRotation(rotation);
  5689.  
  5690. //Place at new position
  5691. if (magicTile)
  5692. {
  5693. item.setZ(tile.z);
  5694. item.setExtradata("" + item.getZ() * 100);
  5695. }
  5696. if (item.getZ() > 40d)
  5697. {
  5698. item.setZ(40);
  5699. }
  5700.  
  5701. this.sendComposer(new FloorItemOnRollerComposer(item, null, tile, this.getStackHeight(tile.x, tile.y, false, item), this).compose());
  5702.  
  5703. //Update Habbos at old position
  5704. for (RoomTile t : occupiedTiles)
  5705. {
  5706. this.updateHabbosAt(t.x, t.y);
  5707. }
  5708. return FurnitureMovementError.NONE;
  5709. }
  5710.  
  5711.  
  5712. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement