Merge branch 'code-readability' into 'ms4/dev'

Code optimisations and readability

See merge request morningstar/Arcturus-Community!29
This commit is contained in:
John 2023-01-11 21:24:07 +00:00
commit 671ab9fe9b
83 changed files with 1392 additions and 1893 deletions

View File

@ -36,7 +36,6 @@
<configuration> <configuration>
<source>19</source> <source>19</source>
<target>19</target> <target>19</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.bots; package com.eu.habbo.habbohotel.bots;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender; import com.eu.habbo.habbohotel.users.HabboGender;
@ -82,7 +83,7 @@ public class Bot implements Runnable {
this.motto = set.getString("motto"); this.motto = set.getString("motto");
this.figure = set.getString("figure"); this.figure = set.getString("figure");
this.gender = HabboGender.valueOf(set.getString("gender")); this.gender = HabboGender.valueOf(set.getString("gender"));
this.ownerId = set.getInt("user_id"); this.ownerId = set.getInt(DatabaseConstants.USER_ID);
this.ownerName = set.getString("owner_name"); this.ownerName = set.getString("owner_name");
this.chatAuto = set.getString("chat_auto").equals("1"); this.chatAuto = set.getString("chat_auto").equals("1");
this.chatRandom = set.getString("chat_random").equals("1"); this.chatRandom = set.getString("chat_random").equals("1");

View File

@ -1,5 +1,6 @@
package com.eu.habbo.habbohotel.campaign; package com.eu.habbo.habbohotel.campaign;
import com.eu.habbo.database.DatabaseConstants;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -17,7 +18,7 @@ public class CalendarRewardClaimed {
private final Timestamp timestamp; private final Timestamp timestamp;
public CalendarRewardClaimed(ResultSet set) throws SQLException { public CalendarRewardClaimed(ResultSet set) throws SQLException {
this.userId = set.getInt("user_id"); this.userId = set.getInt(DatabaseConstants.USER_ID);
this.campaignId = set.getInt("campaign_id"); this.campaignId = set.getInt("campaign_id");
this.day = set.getInt("day"); this.day = set.getInt("day");
this.rewardId = set.getInt("reward_id"); this.rewardId = set.getInt("reward_id");

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.catalog; package com.eu.habbo.habbohotel.catalog;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.catalog.layouts.*; import com.eu.habbo.habbohotel.catalog.layouts.*;
@ -44,6 +45,8 @@ import java.sql.*;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION;
@Slf4j @Slf4j
public class CatalogManager { public class CatalogManager {
@ -249,13 +252,13 @@ public class CatalogManager {
totals.adjustOrPutValue(set.getInt("catalog_item_id"), 1, 1); totals.adjustOrPutValue(set.getInt("catalog_item_id"), 1, 1);
if (set.getInt("user_id") == 0) { if (set.getInt(DatabaseConstants.USER_ID) == 0) {
limiteds.get(set.getInt("catalog_item_id")).push(set.getInt("number")); limiteds.get(set.getInt("catalog_item_id")).push(set.getInt("number"));
} }
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
for (Map.Entry<Integer, LinkedList<Integer>> set : limiteds.entrySet()) { for (Map.Entry<Integer, LinkedList<Integer>> set : limiteds.entrySet()) {
@ -288,7 +291,7 @@ public class CatalogManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
pages.forEachValue((object) -> { pages.forEachValue((object) -> {
@ -329,7 +332,7 @@ public class CatalogManager {
)); ));
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
@ -340,10 +343,7 @@ public class CatalogManager {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM catalog_items")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM catalog_items")) {
CatalogItem item; CatalogItem item;
while (set.next()) { while (set.next()) {
if (set.getString("item_ids").equals("0")) if (set.getString("item_ids").equals("0") || set.getInt("amount") < 1)
continue;
if (set.getInt("amount") < 1)
continue; continue;
if (set.getString("catalog_name").contains("HABBO_CLUB_")) { if (set.getString("catalog_name").contains("HABBO_CLUB_")) {
@ -376,7 +376,7 @@ public class CatalogManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
for (CatalogPage page : this.catalogPages.valueCollection()) { for (CatalogPage page : this.catalogPages.valueCollection()) {
@ -401,7 +401,7 @@ public class CatalogManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
@ -417,7 +417,7 @@ public class CatalogManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
} }
@ -432,7 +432,7 @@ public class CatalogManager {
this.vouchers.add(new Voucher(set)); this.vouchers.add(new Voucher(set));
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
} }
@ -456,7 +456,7 @@ public class CatalogManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
} }
@ -476,7 +476,7 @@ public class CatalogManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
} }
@ -491,7 +491,7 @@ public class CatalogManager {
this.clothing.put(set.getInt("id"), new ClothItem(set)); this.clothing.put(set.getInt("id"), new ClothItem(set));
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
} }
@ -570,7 +570,7 @@ public class CatalogManager {
return statement.executeUpdate() >= 1; return statement.executeUpdate() >= 1;
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return false; return false;
@ -727,7 +727,7 @@ public class CatalogManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
if (catalogPage != null) { if (catalogPage != null) {
@ -791,8 +791,6 @@ public class CatalogManager {
public void purchaseItem(CatalogPage page, CatalogItem item, Habbo habbo, int amount, String extradata, boolean free) { public void purchaseItem(CatalogPage page, CatalogItem item, Habbo habbo, int amount, String extradata, boolean free) {
Item cBaseItem = null;
if (item == null || habbo.getHabboStats().isPurchasingFurniture()) { if (item == null || habbo.getHabboStats().isPurchasingFurniture()) {
habbo.getClient().sendResponse(new PurchaseErrorMessageComposer(PurchaseErrorMessageComposer.SERVER_ERROR).compose()); habbo.getClient().sendResponse(new PurchaseErrorMessageComposer(PurchaseErrorMessageComposer.SERVER_ERROR).compose());
return; return;
@ -1053,23 +1051,19 @@ public class CatalogManager {
UserCatalogItemPurchasedEvent purchasedEvent = new UserCatalogItemPurchasedEvent(habbo, item, itemsList, totalCredits, totalPoints, badges); UserCatalogItemPurchasedEvent purchasedEvent = new UserCatalogItemPurchasedEvent(habbo, item, itemsList, totalCredits, totalPoints, badges);
Emulator.getPluginManager().fireEvent(purchasedEvent); Emulator.getPluginManager().fireEvent(purchasedEvent);
if (!free && !habbo.getClient().getHabbo().hasPermission(Permission.ACC_INFINITE_CREDITS)) { if (!free && !habbo.getClient().getHabbo().hasPermission(Permission.ACC_INFINITE_CREDITS) && purchasedEvent.getTotalCredits() > 0) {
if (purchasedEvent.getTotalCredits() > 0) { habbo.getClient().getHabbo().getHabboInfo().addCredits(-purchasedEvent.getTotalCredits());
habbo.getClient().getHabbo().getHabboInfo().addCredits(-purchasedEvent.getTotalCredits()); habbo.getClient().sendResponse(new CreditBalanceComposer(habbo.getClient().getHabbo()));
habbo.getClient().sendResponse(new CreditBalanceComposer(habbo.getClient().getHabbo()));
}
} }
if (!free && !habbo.getClient().getHabbo().hasPermission(Permission.ACC_INFINITE_POINTS)) { if (!free && !habbo.getClient().getHabbo().hasPermission(Permission.ACC_INFINITE_POINTS) && purchasedEvent.getTotalPoints() > 0) {
if (purchasedEvent.getTotalPoints() > 0) { habbo.getClient().getHabbo().getHabboInfo().addCurrencyAmount(item.getPointsType(), -purchasedEvent.getTotalPoints());
habbo.getClient().getHabbo().getHabboInfo().addCurrencyAmount(item.getPointsType(), -purchasedEvent.getTotalPoints()); habbo.getClient().sendResponse(new HabboActivityPointNotificationMessageComposer(habbo.getClient().getHabbo().getHabboInfo().getCurrencyAmount(item.getPointsType()), -purchasedEvent.getTotalPoints(), item.getPointsType()));
habbo.getClient().sendResponse(new HabboActivityPointNotificationMessageComposer(habbo.getClient().getHabbo().getHabboInfo().getCurrencyAmount(item.getPointsType()), -purchasedEvent.getTotalPoints(), item.getPointsType()));
}
} }
if (purchasedEvent.itemsList != null && !purchasedEvent.itemsList.isEmpty()) { if (purchasedEvent.itemsList != null && !purchasedEvent.itemsList.isEmpty()) {
habbo.getClient().getHabbo().getInventory().getItemsComponent().addItems(purchasedEvent.itemsList); habbo.getClient().getHabbo().getInventory().getItemsComponent().addItems(purchasedEvent.itemsList);
unseenItems.put(UnseenItemsComposer.AddHabboItemCategory.OWNED_FURNI, purchasedEvent.itemsList.stream().map(HabboItem::getId).collect(Collectors.toList())); unseenItems.put(UnseenItemsComposer.AddHabboItemCategory.OWNED_FURNI, purchasedEvent.itemsList.stream().map(HabboItem::getId).toList());
Emulator.getPluginManager().fireEvent(new UserCatalogFurnitureBoughtEvent(habbo, item, purchasedEvent.itemsList)); Emulator.getPluginManager().fireEvent(new UserCatalogFurnitureBoughtEvent(habbo, item, purchasedEvent.itemsList));

View File

@ -1,5 +1,6 @@
package com.eu.habbo.habbohotel.catalog; package com.eu.habbo.habbohotel.catalog;
import com.eu.habbo.database.DatabaseConstants;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -17,7 +18,7 @@ public class VoucherHistoryEntry {
public VoucherHistoryEntry(ResultSet set) throws SQLException { public VoucherHistoryEntry(ResultSet set) throws SQLException {
this.voucherId = set.getInt("voucher_id"); this.voucherId = set.getInt("voucher_id");
this.userId = set.getInt("user_id"); this.userId = set.getInt(DatabaseConstants.USER_ID);
this.timestamp = set.getInt("timestamp"); this.timestamp = set.getInt("timestamp");
} }

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.catalog.marketplace; package com.eu.habbo.habbohotel.catalog.marketplace;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
@ -25,8 +26,11 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION;
@Slf4j @Slf4j
public class MarketPlace { public class MarketPlace {
//Configuration. Loaded from database & updated accordingly. //Configuration. Loaded from database & updated accordingly.
@ -35,6 +39,9 @@ public class MarketPlace {
//Currency to use. //Currency to use.
public static int MARKETPLACE_CURRENCY = 0; public static int MARKETPLACE_CURRENCY = 0;
private MarketPlace() {
}
public static THashSet<MarketPlaceOffer> getOwnOffers(Habbo habbo) { public static THashSet<MarketPlaceOffer> getOwnOffers(Habbo habbo) {
THashSet<MarketPlaceOffer> offers = new THashSet<>(); THashSet<MarketPlaceOffer> offers = new THashSet<>();
@ -46,7 +53,7 @@ public class MarketPlace {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return offers; return offers;
@ -104,7 +111,7 @@ public class MarketPlace {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
habbo.getClient().sendResponse(new MarketplaceCancelOfferResultComposer(offer, false)); habbo.getClient().sendResponse(new MarketplaceCancelOfferResultComposer(offer, false));
} }
} }
@ -168,7 +175,7 @@ public class MarketPlace {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return offers; return offers;
@ -198,7 +205,7 @@ public class MarketPlace {
message.appendInt(1); message.appendInt(1);
message.appendInt(itemId); message.appendInt(itemId);
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
@ -213,7 +220,7 @@ public class MarketPlace {
number = set.getInt("number"); number = set.getInt("number");
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return number; return number;
@ -231,7 +238,7 @@ public class MarketPlace {
avg = set.getInt("avg"); avg = set.getInt("avg");
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return calculateCommision(avg); return calculateCommision(avg);
@ -240,58 +247,59 @@ public class MarketPlace {
public static void buyItem(int offerId, GameClient client) { public static void buyItem(int offerId, GameClient client) {
GetMarketplaceOffersEvent.cachedResults.clear(); GetMarketplaceOffersEvent.cachedResults.clear();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM marketplace_items WHERE id = ? LIMIT 1")) { PreparedStatement statement = connection.prepareStatement("SELECT * FROM marketplace_items WHERE id = ? LIMIT 1")) {
statement.setInt(1, offerId); statement.setInt(1, offerId);
try (ResultSet set = statement.executeQuery()) { try (ResultSet set = statement.executeQuery()) {
if (set.next()) { if (set.next()) {
try (PreparedStatement itemStatement = connection.prepareStatement("SELECT * FROM items WHERE id = ? LIMIT 1", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) { try (PreparedStatement itemStatement = connection.prepareStatement("SELECT * FROM items WHERE id = ? LIMIT 1", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
itemStatement.setInt(1, set.getInt("item_id")); itemStatement.setInt(1, set.getInt("item_id"));
try (ResultSet itemSet = itemStatement.executeQuery()) { try (ResultSet itemSet = itemStatement.executeQuery()) {
itemSet.first(); itemSet.first();
if (itemSet.getRow() > 0) { if (itemSet.getRow() <= 0) {
int price = MarketPlace.calculateCommision(set.getInt("price")); return;
if (set.getInt("state") != 1) { }
sendErrorMessage(client, set.getInt("item_id"), offerId);
} else if ((MARKETPLACE_CURRENCY == 0 && price > client.getHabbo().getHabboInfo().getCredits()) || (MARKETPLACE_CURRENCY > 0 && price > client.getHabbo().getHabboInfo().getCurrencyAmount(MARKETPLACE_CURRENCY))) {
client.sendResponse(new MarketplaceBuyOfferResultComposer(MarketplaceBuyOfferResultComposer.NOT_ENOUGH_CREDITS, 0, offerId, price));
} else {
try (PreparedStatement updateOffer = connection.prepareStatement("UPDATE marketplace_items SET state = 2, sold_timestamp = ? WHERE id = ?")) {
updateOffer.setInt(1, Emulator.getIntUnixTimestamp());
updateOffer.setInt(2, offerId);
updateOffer.execute();
}
Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(set.getInt("user_id"));
HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(itemSet);
MarketPlaceItemSoldEvent event = new MarketPlaceItemSoldEvent(habbo, client.getHabbo(), item, set.getInt("price")); int price = MarketPlace.calculateCommision(set.getInt("price"));
if (Emulator.getPluginManager().fireEvent(event).isCancelled()) { if (set.getInt("state") != 1) {
return; sendErrorMessage(client, set.getInt("item_id"), offerId);
} } else if ((MARKETPLACE_CURRENCY == 0 && price > client.getHabbo().getHabboInfo().getCredits()) || (MARKETPLACE_CURRENCY > 0 && price > client.getHabbo().getHabboInfo().getCurrencyAmount(MARKETPLACE_CURRENCY))) {
event.price = calculateCommision(event.price); client.sendResponse(new MarketplaceBuyOfferResultComposer(MarketplaceBuyOfferResultComposer.NOT_ENOUGH_CREDITS, 0, offerId, price));
} else {
try (PreparedStatement updateOffer = connection.prepareStatement("UPDATE marketplace_items SET state = 2, sold_timestamp = ? WHERE id = ?")) {
updateOffer.setInt(1, Emulator.getIntUnixTimestamp());
updateOffer.setInt(2, offerId);
updateOffer.execute();
}
Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(set.getInt(DatabaseConstants.USER_ID));
HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(itemSet);
item.setUserId(client.getHabbo().getHabboInfo().getId()); MarketPlaceItemSoldEvent event = new MarketPlaceItemSoldEvent(habbo, client.getHabbo(), item, set.getInt("price"));
item.needsUpdate(true); if (Emulator.getPluginManager().fireEvent(event).isCancelled()) {
Emulator.getThreading().run(item); return;
}
event.price = calculateCommision(event.price);
client.getHabbo().getInventory().getItemsComponent().addItem(item); item.setUserId(client.getHabbo().getHabboInfo().getId());
item.needsUpdate(true);
Emulator.getThreading().run(item);
if (MARKETPLACE_CURRENCY == 0) { client.getHabbo().getInventory().getItemsComponent().addItem(item);
client.getHabbo().giveCredits(-event.price);
} else {
client.getHabbo().givePoints(MARKETPLACE_CURRENCY, -event.price);
}
client.sendResponse(new CreditBalanceComposer(client.getHabbo())); if (MARKETPLACE_CURRENCY == 0) {
client.sendResponse(new UnseenItemsComposer(item)); client.getHabbo().giveCredits(-event.price);
client.sendResponse(new FurniListInvalidateComposer()); } else {
client.sendResponse(new MarketplaceBuyOfferResultComposer(MarketplaceBuyOfferResultComposer.REFRESH, 0, offerId, price)); client.getHabbo().givePoints(MARKETPLACE_CURRENCY, -event.price);
}
if (habbo != null) { client.sendResponse(new CreditBalanceComposer(client.getHabbo()));
habbo.getInventory().getOffer(offerId).setState(MarketPlaceState.SOLD); client.sendResponse(new UnseenItemsComposer(item));
} client.sendResponse(new FurniListInvalidateComposer());
} client.sendResponse(new MarketplaceBuyOfferResultComposer(MarketplaceBuyOfferResultComposer.REFRESH, 0, offerId, price));
if (habbo != null) {
habbo.getInventory().getOffer(offerId).setState(MarketPlaceState.SOLD);
} }
} }
} }
@ -299,7 +307,7 @@ public class MarketPlace {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
@ -307,15 +315,15 @@ public class MarketPlace {
public static void sendErrorMessage(GameClient client, int baseItemId, int offerId) { public static void sendErrorMessage(GameClient client, int baseItemId, int offerId) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT marketplace_items.*, COUNT( * ) AS count\n" + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT marketplace_items.*, COUNT( * ) AS count\n" +
""" """
FROM marketplace_items FROM marketplace_items
INNER JOIN items ON marketplace_items.item_id = items.id INNER JOIN items ON marketplace_items.item_id = items.id
INNER JOIN items_base ON items.item_id = items_base.id INNER JOIN items_base ON items.item_id = items_base.id
WHERE items_base.sprite_id = ( WHERE items_base.sprite_id = (
SELECT items_base.sprite_id SELECT items_base.sprite_id
FROM items_base FROM items_base
WHERE items_base.id = ? LIMIT 1) WHERE items_base.id = ? LIMIT 1)
ORDER BY price ASC ORDER BY price
LIMIT 1""", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) { LIMIT 1""", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
statement.setInt(1, baseItemId); statement.setInt(1, baseItemId);
try (ResultSet countSet = statement.executeQuery()) { try (ResultSet countSet = statement.executeQuery()) {
countSet.last(); countSet.last();
@ -327,7 +335,7 @@ public class MarketPlace {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
@ -394,7 +402,7 @@ public class MarketPlace {
statement.setInt(2, offer.getOfferId()); statement.setInt(2, offer.getOfferId());
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }

View File

@ -17,9 +17,9 @@ public class LayCommand extends Command {
if (gameClient.getHabbo().getRoomUnit() == null || !gameClient.getHabbo().getRoomUnit().canForcePosture()) if (gameClient.getHabbo().getRoomUnit() == null || !gameClient.getHabbo().getRoomUnit().canForcePosture())
return true; return true;
gameClient.getHabbo().getRoomUnit().cmdLay = true; gameClient.getHabbo().getRoomUnit().setCmdLay(true);
gameClient.getHabbo().getHabboInfo().getCurrentRoom().updateHabbo(gameClient.getHabbo()); gameClient.getHabbo().getHabboInfo().getCurrentRoom().updateHabbo(gameClient.getHabbo());
gameClient.getHabbo().getRoomUnit().cmdSit = true; gameClient.getHabbo().getRoomUnit().setCmdSit(true);
gameClient.getHabbo().getRoomUnit().setBodyRotation(RoomUserRotation.values()[gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue() - gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue() % 2]); gameClient.getHabbo().getRoomUnit().setBodyRotation(RoomUserRotation.values()[gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue() - gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue() % 2]);
RoomTile tile = gameClient.getHabbo().getRoomUnit().getCurrentLocation(); RoomTile tile = gameClient.getHabbo().getRoomUnit().getCurrentLocation();

View File

@ -12,12 +12,12 @@ public class TeleportCommand extends Command {
@Override @Override
public boolean handle(GameClient gameClient, String[] params) { public boolean handle(GameClient gameClient, String[] params) {
if (gameClient.getHabbo().getHabboInfo().getRiding() == null) //TODO Make this an event plugin which fires that can be cancelled if (gameClient.getHabbo().getHabboInfo().getRiding() == null) //TODO Make this an event plugin which fires that can be cancelled
if (gameClient.getHabbo().getRoomUnit().cmdTeleport) { if (gameClient.getHabbo().getRoomUnit().isCmdTeleport()) {
gameClient.getHabbo().getRoomUnit().cmdTeleport = false; gameClient.getHabbo().getRoomUnit().setCmdTeleport(false);
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_teleport.disabled"), RoomChatMessageBubbles.ALERT); gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_teleport.disabled"), RoomChatMessageBubbles.ALERT);
return true; return true;
} else { } else {
gameClient.getHabbo().getRoomUnit().cmdTeleport = true; gameClient.getHabbo().getRoomUnit().setCmdTeleport(true);
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_teleport.enabled"), RoomChatMessageBubbles.ALERT); gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_teleport.enabled"), RoomChatMessageBubbles.ALERT);
return true; return true;
} }

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.guilds; package com.eu.habbo.habbohotel.guilds;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -65,7 +66,7 @@ public class Guild implements Runnable {
public Guild(ResultSet set) throws SQLException { public Guild(ResultSet set) throws SQLException {
this.id = set.getInt("id"); this.id = set.getInt("id");
this.ownerId = set.getInt("user_id"); this.ownerId = set.getInt(DatabaseConstants.USER_ID);
this.ownerName = set.getString("username"); this.ownerName = set.getString("username");
this.name = set.getString("name"); this.name = set.getString("name");
this.description = set.getString("description"); this.description = set.getString("description");

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.guilds; package com.eu.habbo.habbohotel.guilds;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.guilds.forums.ForumView; import com.eu.habbo.habbohotel.guilds.forums.ForumView;
import com.eu.habbo.habbohotel.items.interactions.InteractionGuildFurni; import com.eu.habbo.habbohotel.items.interactions.InteractionGuildFurni;
@ -433,7 +434,7 @@ public class GuildManager {
statement.setInt(1, guild.getId()); statement.setInt(1, guild.getId());
try (ResultSet set = statement.executeQuery()) { try (ResultSet set = statement.executeQuery()) {
while (set.next()) { while (set.next()) {
guildAdmins.put(set.getInt("user_id"), new GuildMember(set)); guildAdmins.put(set.getInt(DatabaseConstants.USER_ID), new GuildMember(set));
} }
} }
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -1,5 +1,6 @@
package com.eu.habbo.habbohotel.guilds; package com.eu.habbo.habbohotel.guilds;
import com.eu.habbo.database.DatabaseConstants;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -22,7 +23,7 @@ public class GuildMember implements Comparable<GuildMember> {
private GuildRank rank; private GuildRank rank;
public GuildMember(ResultSet set) throws SQLException { public GuildMember(ResultSet set) throws SQLException {
this.userId = set.getInt("user_id"); this.userId = set.getInt(DatabaseConstants.USER_ID);
this.username = set.getString("username"); this.username = set.getString("username");
this.look = set.getString("look"); this.look = set.getString("look");
this.joinDate = set.getInt("member_since"); this.joinDate = set.getInt("member_since");

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.guilds.forums; package com.eu.habbo.habbohotel.guilds.forums;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.users.HabboInfo;
import com.eu.habbo.messages.ISerialize; import com.eu.habbo.messages.ISerialize;
@ -14,6 +15,8 @@ import lombok.extern.slf4j.Slf4j;
import java.sql.*; import java.sql.*;
import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION;
@Slf4j @Slf4j
public class ForumThreadComment implements Runnable, ISerialize { public class ForumThreadComment implements Runnable, ISerialize {
@ -50,7 +53,7 @@ public class ForumThreadComment implements Runnable, ISerialize {
public ForumThreadComment(ResultSet set) throws SQLException { public ForumThreadComment(ResultSet set) throws SQLException {
this.commentId = set.getInt("id"); this.commentId = set.getInt("id");
this.threadId = set.getInt("thread_id"); this.threadId = set.getInt("thread_id");
this.userId = set.getInt("user_id"); this.userId = set.getInt(DatabaseConstants.USER_ID);
this.message = set.getString("message"); this.message = set.getString("message");
this.createdAt = set.getInt("created_at"); this.createdAt = set.getInt("created_at");
this.state = ForumThreadState.fromValue(set.getInt("state")); this.state = ForumThreadState.fromValue(set.getInt("state"));
@ -75,7 +78,7 @@ public class ForumThreadComment implements Runnable, ISerialize {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return foundComment; return foundComment;
@ -114,7 +117,7 @@ public class ForumThreadComment implements Runnable, ISerialize {
Emulator.getPluginManager().fireEvent(new GuildForumThreadCommentCreated(createdComment)); Emulator.getPluginManager().fireEvent(new GuildForumThreadCommentCreated(createdComment));
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return createdComment; return createdComment;
@ -171,7 +174,7 @@ public class ForumThreadComment implements Runnable, ISerialize {
this.needsUpdate = false; this.needsUpdate = false;
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
} }

View File

@ -1,5 +1,6 @@
package com.eu.habbo.habbohotel.guilds.forums; package com.eu.habbo.habbohotel.guilds.forums;
import com.eu.habbo.database.DatabaseConstants;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -16,7 +17,7 @@ public class ForumView {
private final int timestamp; private final int timestamp;
public ForumView(ResultSet set) throws SQLException { public ForumView(ResultSet set) throws SQLException {
this.userId = set.getInt("user_id"); this.userId = set.getInt(DatabaseConstants.USER_ID);
this.guildId = set.getInt("guild_id"); this.guildId = set.getInt("guild_id");
this.timestamp = set.getInt("timestamp"); this.timestamp = set.getInt("timestamp");
} }

View File

@ -71,7 +71,7 @@ public class InteractionBackgroundToner extends HabboItem {
return; return;
} }
if (client.getHabbo().getRoomUnit().cmdSit && client.getHabbo().getRoomUnit().getEffectId() == 1337) { if (client.getHabbo().getRoomUnit().isCmdSit() && client.getHabbo().getRoomUnit().getEffectId() == 1337) {
new BackgroundAnimation(this, room).run(); new BackgroundAnimation(this, room).run();
return; return;
} }

View File

@ -41,7 +41,7 @@ public class InteractionGymEquipment extends InteractionEffectTile implements IC
if (this.forceRotation()) { if (this.forceRotation()) {
roomUnit.setRotation(RoomUserRotation.fromValue(this.getRotation())); roomUnit.setRotation(RoomUserRotation.fromValue(this.getRotation()));
roomUnit.canRotate = false; roomUnit.setCanRotate(false);
} }
this.roomUnitId = roomUnit.getId(); this.roomUnitId = roomUnit.getId();
@ -79,7 +79,7 @@ public class InteractionGymEquipment extends InteractionEffectTile implements IC
} }
if (this.forceRotation()) { if (this.forceRotation()) {
roomUnit.canRotate = true; roomUnit.setCanRotate(true);
} }
if (habbo.getHabboInfo().getGender().equals(HabboGender.M)) { if (habbo.getHabboInfo().getGender().equals(HabboGender.M)) {

View File

@ -55,7 +55,7 @@ public class InteractionHopper extends HabboItem {
RoomTile loc = HabboItem.getSquareInFront(room.getLayout(), this); RoomTile loc = HabboItem.getSquareInFront(room.getLayout(), this);
if (loc != null) { if (loc != null) {
if (this.canUseTeleport(client, loc, room)) { if (this.canUseTeleport(client, loc, room)) {
client.getHabbo().getRoomUnit().isTeleporting = true; client.getHabbo().getRoomUnit().setTeleporting(true);
this.setExtradata("1"); this.setExtradata("1");
room.updateItemState(this); room.updateItemState(this);
@ -92,7 +92,7 @@ public class InteractionHopper extends HabboItem {
if (client.getHabbo().getRoomUnit().getY() != front.getY()) if (client.getHabbo().getRoomUnit().getY() != front.getY())
return false; return false;
if (client.getHabbo().getRoomUnit().isTeleporting) if (client.getHabbo().getRoomUnit().isTeleporting())
return false; return false;
if (!room.getHabbosAt(this.getX(), this.getY()).isEmpty()) if (!room.getHabbosAt(this.getX(), this.getY()).isEmpty())

View File

@ -45,30 +45,29 @@ public class InteractionMultiHeight extends HabboItem {
public void onClick(GameClient client, Room room, Object[] objects) throws Exception { public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
super.onClick(client, room, objects); super.onClick(client, room, objects);
if (client != null) { if (client != null && !room.hasRights(client.getHabbo()) && !(objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE))
if (!room.hasRights(client.getHabbo()) && !(objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE)) return;
return;
if (objects.length <= 0) {
return;
} }
if (objects.length > 0) { if (objects[0] instanceof Integer && room != null) {
if (objects[0] instanceof Integer && room != null) { HabboItem topItem = room.getTopItemAt(this.getX(), this.getY());
HabboItem topItem = room.getTopItemAt(this.getX(), this.getY()); if (topItem != null && !topItem.equals(this)) { // multiheight items cannot change height even if there is a stackable item on top - no items allowed on top
if (topItem != null && !topItem.equals(this)) { // multiheight items cannot change height even if there is a stackable item on top - no items allowed on top return;
return; }
}
this.needsUpdate(true);
if (this.getExtradata().length() == 0)
this.setExtradata("0");
if (this.getBaseItem().getMultiHeights().length > 0) {
this.setExtradata("" + (Integer.parseInt(this.getExtradata()) + 1) % (this.getBaseItem().getMultiHeights().length));
this.needsUpdate(true); this.needsUpdate(true);
room.updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()));
if (this.getExtradata().length() == 0) room.updateItemState(this);
this.setExtradata("0");
if (this.getBaseItem().getMultiHeights().length > 0) {
this.setExtradata("" + (Integer.parseInt(this.getExtradata()) + 1) % (this.getBaseItem().getMultiHeights().length));
this.needsUpdate(true);
room.updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()));
room.updateItemState(this);
//room.sendComposer(new UpdateStackHeightComposer(this.getX(), this.getY(), this.getBaseItem().getMultiHeights()[Integer.parseInt(this.getExtradata())] * 256.0D).compose());
}
} }
} }
} }
@ -80,11 +79,11 @@ public class InteractionMultiHeight extends HabboItem {
Collection<RoomUnit> unitsOnItem = room.getRoomUnitsAt(room.getLayout().getTile(tile.getX(), tile.getY())); Collection<RoomUnit> unitsOnItem = room.getRoomUnitsAt(room.getLayout().getTile(tile.getX(), tile.getY()));
for (RoomUnit unit : unitsOnItem) { for (RoomUnit unit : unitsOnItem) {
if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoal() != tile) if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoalLocation() != tile)
continue; continue;
if (this.getBaseItem().allowSit() || unit.hasStatus(RoomUnitStatus.SIT)) { if (this.getBaseItem().allowSit() || unit.hasStatus(RoomUnitStatus.SIT)) {
unit.sitUpdate = true; unit.setSitUpdate(true);
unit.statusUpdate(true); unit.statusUpdate(true);
} else { } else {
unit.setZ(unit.getCurrentLocation().getStackHeight()); unit.setZ(unit.getCurrentLocation().getStackHeight());
@ -94,7 +93,6 @@ public class InteractionMultiHeight extends HabboItem {
} }
} }
//room.sendComposer(new RoomUserStatusComposer(updatedUnits, true).compose());
} }
@Override @Override
@ -105,21 +103,19 @@ public class InteractionMultiHeight extends HabboItem {
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects); super.onWalkOn(roomUnit, room, objects);
if (roomUnit != null) { if (roomUnit != null
if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) { && (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0)
if (roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) { && roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) {
Habbo habbo = room.getHabbo(roomUnit); Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) { if (habbo != null) {
if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) { if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) {
room.giveEffect(habbo, this.getBaseItem().getEffectM(), -1); room.giveEffect(habbo, this.getBaseItem().getEffectM(), -1);
return; return;
} }
if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) { if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) {
room.giveEffect(habbo, this.getBaseItem().getEffectF(), -1); room.giveEffect(habbo, this.getBaseItem().getEffectF(), -1);
}
}
} }
} }
} }
@ -129,21 +125,19 @@ public class InteractionMultiHeight extends HabboItem {
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOff(roomUnit, room, objects); super.onWalkOff(roomUnit, room, objects);
if (roomUnit != null) { if (roomUnit != null
if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) { && (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0)
if (roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) { && roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) {
Habbo habbo = room.getHabbo(roomUnit); Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) { if (habbo != null) {
if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) { if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) {
room.giveEffect(habbo, 0, -1); room.giveEffect(habbo, 0, -1);
return; return;
} }
if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) { if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) {
room.giveEffect(habbo, 0, -1); room.giveEffect(habbo, 0, -1);
}
}
} }
} }
} }

View File

@ -83,7 +83,7 @@ public abstract class InteractionPushable extends InteractionDefault {
boolean isDrag = false; boolean isDrag = false;
RoomUserRotation direction; RoomUserRotation direction;
if (this.getX() == roomUnit.getGoal().getX() && this.getY() == roomUnit.getGoal().getY()) //User clicked on the tile the ball is on, they want to kick it if (this.getX() == roomUnit.getGoalLocation().getX() && this.getY() == roomUnit.getGoalLocation().getY()) //User clicked on the tile the ball is on, they want to kick it
{ {
velocity = this.getWalkOnVelocity(roomUnit, room); velocity = this.getWalkOnVelocity(roomUnit, room);
direction = this.getWalkOnDirection(roomUnit, room); direction = this.getWalkOnDirection(roomUnit, room);

View File

@ -208,13 +208,13 @@ public class InteractionTeleport extends HabboItem {
} }
public void startTeleport(Room room, Habbo habbo, int delay) { public void startTeleport(Room room, Habbo habbo, int delay) {
if (habbo.getRoomUnit().isTeleporting) { if (habbo.getRoomUnit().isTeleporting()) {
walkable = this.getBaseItem().allowWalk(); walkable = this.getBaseItem().allowWalk();
return; return;
} }
this.roomUnitID = -1; this.roomUnitID = -1;
habbo.getRoomUnit().isTeleporting = true; habbo.getRoomUnit().setTeleporting(true);
Emulator.getThreading().run(new TeleportActionOne(this, room, habbo.getClient()), delay); Emulator.getThreading().run(new TeleportActionOne(this, room, habbo.getClient()), delay);
} }

View File

@ -36,7 +36,7 @@ public class InteractionTeleportTile extends InteractionTeleport {
if (!canUseTeleport(habbo.getClient(), room)) if (!canUseTeleport(habbo.getClient(), room))
return; return;
if (!habbo.getRoomUnit().isTeleporting) { if (!habbo.getRoomUnit().isTeleporting()) {
habbo.getRoomUnit().setGoalLocation(habbo.getRoomUnit().getCurrentLocation()); habbo.getRoomUnit().setGoalLocation(habbo.getRoomUnit().getCurrentLocation());
this.startTeleport(room, habbo, 1000); this.startTeleport(room, habbo, 1000);
} }

View File

@ -76,7 +76,7 @@ public class InteractionWater extends InteractionDefault {
super.onWalkOn(roomUnit, room, objects); super.onWalkOn(roomUnit, room, objects);
if(roomUnit == null) return; if(roomUnit == null) return;
roomUnit.isSwimming = true; roomUnit.setSwimming(true);
Pet pet = room.getPet(roomUnit); Pet pet = room.getPet(roomUnit);
@ -90,7 +90,7 @@ public class InteractionWater extends InteractionDefault {
@Override @Override
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
roomUnit.isSwimming = false; roomUnit.setSwimming(false);
super.onWalkOff(roomUnit, room, objects); super.onWalkOff(roomUnit, room, objects);

View File

@ -5,7 +5,6 @@ import com.eu.habbo.habbohotel.games.GameTeamColors;
import com.eu.habbo.habbohotel.games.football.FootballGame; import com.eu.habbo.habbohotel.games.football.FootballGame;
import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionPushable; import com.eu.habbo.habbohotel.items.interactions.InteractionPushable;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTeamItem;
import com.eu.habbo.habbohotel.items.interactions.games.football.goals.InteractionFootballGoal; import com.eu.habbo.habbohotel.items.interactions.games.football.goals.InteractionFootballGoal;
import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
@ -33,7 +32,7 @@ public class InteractionFootball extends InteractionPushable {
if (roomUnit.getPath().isEmpty() && roomUnit.tilesWalked() == 2 && this.getExtradata().equals("1")) if (roomUnit.getPath().isEmpty() && roomUnit.tilesWalked() == 2 && this.getExtradata().equals("1"))
return 0; return 0;
if (roomUnit.getPath().size() == 0 && roomUnit.tilesWalked() == 1) if (roomUnit.getPath().isEmpty() && roomUnit.tilesWalked() == 1)
return 6; return 6;
return 1; return 1;
@ -41,7 +40,7 @@ public class InteractionFootball extends InteractionPushable {
@Override @Override
public int getWalkOffVelocity(RoomUnit roomUnit, Room room) { public int getWalkOffVelocity(RoomUnit roomUnit, Room room) {
if (roomUnit.getPath().size() == 0 && roomUnit.tilesWalked() == 0) if (roomUnit.getPath().isEmpty() && roomUnit.tilesWalked() == 0)
return 6; return 6;
return 1; return 1;
@ -69,7 +68,7 @@ public class InteractionFootball extends InteractionPushable {
@Override @Override
public RoomUserRotation getWalkOffDirection(RoomUnit roomUnit, Room room) { public RoomUserRotation getWalkOffDirection(RoomUnit roomUnit, Room room) {
RoomTile peek = roomUnit.getPath().peek(); RoomTile peek = roomUnit.getPath().peek();
RoomTile nextWalkTile = peek != null ? room.getLayout().getTile(peek.getX(), peek.getY()) : roomUnit.getGoal(); RoomTile nextWalkTile = peek != null ? room.getLayout().getTile(peek.getX(), peek.getY()) : roomUnit.getGoalLocation();
return RoomUserRotation.values()[(RoomUserRotation.values().length + Rotation.Calculate(roomUnit.getX(), roomUnit.getY(), nextWalkTile.getX(), nextWalkTile.getY()) + 4) % 8]; return RoomUserRotation.values()[(RoomUserRotation.values().length + Rotation.Calculate(roomUnit.getX(), roomUnit.getY(), nextWalkTile.getX(), nextWalkTile.getY()) + 4) % 8];
} }
@ -85,16 +84,11 @@ public class InteractionFootball extends InteractionPushable {
@Override @Override
public int getNextRollDelay(int currentStep, int totalSteps) { public int getNextRollDelay(int currentStep, int totalSteps) {
if(totalSteps > 4) { if (totalSteps > 4 && currentStep <= 4) {
if(currentStep <= 4) { return 125;
return 125;
}
} }
return 500; return 500;
/*int t = 2500;
return (totalSteps == 1) ? 500 : 100 * ((t = t / t - 1) * t * t * t * t + 1) + (currentStep * 100);*/
} }
@Override @Override
@ -177,16 +171,13 @@ public class InteractionFootball extends InteractionPushable {
int ballDirection = Rotation.Calculate(from.getX(), from.getY(), to.getX(), to.getY()); int ballDirection = Rotation.Calculate(from.getX(), from.getY(), to.getX(), to.getY());
int goalRotation = topItem.getRotation(); int goalRotation = topItem.getRotation();
switch (goalRotation) { return switch (goalRotation) {
case 0: case 0 -> ballDirection > 2 && ballDirection < 6;
return ballDirection > 2 && ballDirection < 6; case 2 -> ballDirection > 4;
case 2: case 4 -> ballDirection > 6 || ballDirection < 2;
return ballDirection > 4; case 6 -> ballDirection > 0 && ballDirection < 4;
case 4: default -> topItem.getBaseItem().allowStack();
return ballDirection > 6 || ballDirection < 2; };
case 6:
return ballDirection > 0 && ballDirection < 4;
}
} }
return topItem.getBaseItem().allowStack(); return topItem.getBaseItem().allowStack();
@ -214,7 +205,7 @@ public class InteractionFootball extends InteractionPushable {
FootballGame game = (FootballGame) room.getGame(FootballGame.class); FootballGame game = (FootballGame) room.getGame(FootballGame.class);
if (game == null) { if (game == null) {
try { try {
game = FootballGame.class.getDeclaredConstructor(new Class[]{Room.class}).newInstance(room); game = FootballGame.class.getDeclaredConstructor(Room.class).newInstance(room);
room.addGame(game); room.addGame(game);
} catch (Exception e) { } catch (Exception e) {
return; return;
@ -222,16 +213,13 @@ public class InteractionFootball extends InteractionPushable {
} }
HabboItem currentTopItem = room.getTopItemAt(from.getX(), from.getY(), this); HabboItem currentTopItem = room.getTopItemAt(from.getX(), from.getY(), this);
HabboItem topItem = room.getTopItemAt(to.getX(), to.getY(), this); HabboItem topItem = room.getTopItemAt(to.getX(), to.getY(), this);
if ((topItem != null) && ((currentTopItem == null) || (currentTopItem.getId() != topItem.getId())) && ((topItem instanceof InteractionFootballGoal))) { if ((topItem != null) && ((currentTopItem == null) || (currentTopItem.getId() != topItem.getId())) && topItem instanceof InteractionFootballGoal interactionFootballGoal) {
GameTeamColors color = ((InteractionGameTeamItem) topItem).teamColor; GameTeamColors color = interactionFootballGoal.teamColor;
game.onScore(kicker, color); game.onScore(kicker, color);
} }
this.setExtradata(Math.abs(currentStep - (totalSteps + 1)) + ""); this.setExtradata(Math.abs(currentStep - (totalSteps + 1)) + "");
room.sendComposer(new OneWayDoorStatusMessageComposer(this).compose()); room.sendComposer(new OneWayDoorStatusMessageComposer(this).compose());
/*this.setExtradata(nextRoll <= 200 ? "8" : (nextRoll <= 250 ? "7" : (nextRoll <= 300 ? "6" : (nextRoll <= 350 ? "5" : (nextRoll <= 400 ? "4" : (nextRoll <= 450 ? "3" : (nextRoll <= 500 ? "2" : "1")))))));
room.sendComposer(new ItemStateComposer(this).compose());*/
} }
@Override @Override

View File

@ -20,8 +20,8 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
public class InteractionPetBreedingNest extends HabboItem { public class InteractionPetBreedingNest extends HabboItem {
public Pet petOne = null; private Pet petOne = null;
public Pet petTwo = null; private Pet petTwo = null;
public InteractionPetBreedingNest(ResultSet set, Item baseItem) throws SQLException { public InteractionPetBreedingNest(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@ -59,19 +59,17 @@ public class InteractionPetBreedingNest extends HabboItem {
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
Pet pet = room.getPet(roomUnit); Pet pet = room.getPet(roomUnit);
if (pet != null) { if (pet != null && !this.boxFull()) {
if (!this.boxFull()) { this.addPet(pet);
this.addPet(pet);
if (this.boxFull()) { if (this.boxFull()) {
Habbo ownerPetOne = room.getHabbo(this.petOne.getUserId()); Habbo ownerPetOne = room.getHabbo(this.petOne.getUserId());
Habbo ownerPetTwo = room.getHabbo(this.petTwo.getUserId()); Habbo ownerPetTwo = room.getHabbo(this.petTwo.getUserId());
if (ownerPetOne != null && ownerPetTwo != null && this.petOne.getPetData().getType() == this.petTwo.getPetData().getType() && this.petOne.getPetData().getOffspringType() != -1) { if (ownerPetOne != null && ownerPetTwo != null && this.petOne.getPetData().getType() == this.petTwo.getPetData().getType() && this.petOne.getPetData().getOffspringType() != -1) {
ownerPetTwo.getClient().sendResponse(new ConfirmBreedingRequestComposer(this.getId(), this.petOne.getPetData().getOffspringType(), this.petOne, ownerPetOne.getHabboInfo().getUsername(), this.petTwo, ownerPetTwo.getHabboInfo().getUsername())); ownerPetTwo.getClient().sendResponse(new ConfirmBreedingRequestComposer(this.getId(), this.petOne.getPetData().getOffspringType(), this.petOne, ownerPetOne.getHabboInfo().getUsername(), this.petTwo, ownerPetTwo.getHabboInfo().getUsername()));
this.setExtradata("1"); this.setExtradata("1");
room.updateItem(this); room.updateItem(this);
}
} }
} }
} }
@ -148,14 +146,12 @@ public class InteractionPetBreedingNest extends HabboItem {
habbo.getHabboInfo().getCurrentRoom().updateItem(this); habbo.getHabboInfo().getCurrentRoom().updateItem(this);
HabboItem box = this; HabboItem box = this;
Pet petOne = this.petOne;
Pet petTwo = this.petTwo;
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> {
Pet offspring = Emulator.getGameEnvironment().getPetManager().createPet(petOne.getPetData().getOffspringType(), (int) Math.min(Math.round(Math.max(1d, PetManager.getNormalDistributionForBreeding(petOne.getLevel(), petTwo.getLevel()).sample())), 20), name, habbo.getClient()); Pet offspring = Emulator.getGameEnvironment().getPetManager().createPet(petOne.getPetData().getOffspringType(), (int) Math.min(Math.round(Math.max(1d, PetManager.getNormalDistributionForBreeding(petOne.getLevel(), petTwo.getLevel()).sample())), 20), name, habbo.getClient());
//habbo.getClient().sendResponse(new PetPackageNameValidationComposer(box.getId(), PetPackageNameValidationComposer.CLOSE_WIDGET, "")); habbo.getHabboInfo().getCurrentRoom().placePet(offspring, box.getX(), box.getY(), box.getZ());
habbo.getHabboInfo().getCurrentRoom().placePet(offspring, box.getX(), box.getY(), box.getZ(), box.getRotation()); offspring.setNeedsUpdate(true);
offspring.needsUpdate = true;
offspring.run(); offspring.run();
InteractionPetBreedingNest.this.freePets(); InteractionPetBreedingNest.this.freePets();
habbo.getHabboInfo().getCurrentRoom().removeHabboItem(box); habbo.getHabboInfo().getCurrentRoom().removeHabboItem(box);

View File

@ -74,14 +74,14 @@ public class InteractionPetDrink extends InteractionDefault {
pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]);
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.getRoomUnit().setStatus(RoomUnitStatus.EAT, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); pet.getRoomUnit().setStatus(RoomUnitStatus.EAT, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");
pet.packetUpdate = true; pet.setPacketUpdate(true);
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> {
pet.addThirst(-75); pet.addThirst(-75);
this.change(room, -1); this.change(room, -1);
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
new PetClearPosture(pet, RoomUnitStatus.EAT, null, true); new PetClearPosture(pet, RoomUnitStatus.EAT, null, true);
pet.packetUpdate = true; pet.setPacketUpdate(true);
}, 1000); }, 1000);
AchievementManager.progressAchievement(Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()), Emulator.getGameEnvironment().getAchievementManager().getAchievement("PetFeeding"), 75); AchievementManager.progressAchievement(Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()), Emulator.getGameEnvironment().getAchievementManager().getAchievement("PetFeeding"), 75);

View File

@ -33,7 +33,7 @@ public class InteractionPetToy extends InteractionDefault {
for (Pet pet : room.getPetsAt(oldLocation)) { for (Pet pet : room.getPetsAt(oldLocation)) {
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.packetUpdate = true; pet.setPacketUpdate(true);
} }
} }
@Override @Override
@ -42,7 +42,7 @@ public class InteractionPetToy extends InteractionDefault {
for (Pet pet : room.getPetsOnItem(this)) { for (Pet pet : room.getPetsOnItem(this)) {
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.packetUpdate = true; pet.setPacketUpdate(true);
} }
} }
@ -52,7 +52,7 @@ public class InteractionPetToy extends InteractionDefault {
Pet pet = room.getPet(roomUnit); Pet pet = room.getPet(roomUnit);
if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoal())) { if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoalLocation())) {
if (pet.getEnergy() <= 35) { if (pet.getEnergy() <= 35) {
return; return;
} }
@ -62,7 +62,7 @@ public class InteractionPetToy extends InteractionDefault {
pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]);
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.getRoomUnit().setStatus(RoomUnitStatus.PLAY, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); pet.getRoomUnit().setStatus(RoomUnitStatus.PLAY, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");
pet.packetUpdate = true; pet.setPacketUpdate(true);
HabboItem item = this; HabboItem item = this;
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> {
pet.addHappiness(25); pet.addHappiness(25);
@ -70,7 +70,7 @@ public class InteractionPetToy extends InteractionDefault {
room.updateItem(item); room.updateItem(item);
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
new PetClearPosture(pet, RoomUnitStatus.PLAY, null, true).run(); new PetClearPosture(pet, RoomUnitStatus.PLAY, null, true).run();
pet.packetUpdate = true; pet.setPacketUpdate(true);
}, ((long)(Emulator.getRandom().nextInt(20) * 500) + 2500)); }, ((long)(Emulator.getRandom().nextInt(20) * 500) + 2500));
this.setExtradata("1"); this.setExtradata("1");
room.updateItemState(this); room.updateItemState(this);
@ -87,7 +87,7 @@ public class InteractionPetToy extends InteractionDefault {
this.setExtradata("0"); this.setExtradata("0");
room.updateItem(this); room.updateItem(this);
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.packetUpdate = true; pet.setPacketUpdate(true);
} }
} }

View File

@ -33,7 +33,7 @@ public class InteractionPetTrampoline extends InteractionDefault {
for (Pet pet : room.getPetsAt(oldLocation)) { for (Pet pet : room.getPetsAt(oldLocation)) {
pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP); pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP);
pet.packetUpdate = true; pet.setPacketUpdate(true);
} }
} }
@ -43,7 +43,7 @@ public class InteractionPetTrampoline extends InteractionDefault {
for (Pet pet : room.getPetsOnItem(this)) { for (Pet pet : room.getPetsOnItem(this)) {
pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP); pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP);
pet.packetUpdate = true; pet.setPacketUpdate(true);
} }
} }
@ -53,7 +53,7 @@ public class InteractionPetTrampoline extends InteractionDefault {
Pet pet = room.getPet(roomUnit); Pet pet = room.getPet(roomUnit);
if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoal())) { if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoalLocation())) {
if (pet.getEnergy() <= 35) { if (pet.getEnergy() <= 35) {
return; return;
} }
@ -84,7 +84,7 @@ public class InteractionPetTrampoline extends InteractionDefault {
this.setExtradata("0"); this.setExtradata("0");
room.updateItem(this); room.updateItem(this);
pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP); pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP);
pet.packetUpdate = true; pet.setPacketUpdate(true);
} }
} }

View File

@ -23,14 +23,14 @@ public class InteractionPetTree extends InteractionDefault {
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
for (Pet pet : room.getPetsAt(oldLocation)) { for (Pet pet : room.getPetsAt(oldLocation)) {
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.packetUpdate = true; pet.setPacketUpdate(true);
} }
} }
@Override @Override
public void onPickUp(Room room) { public void onPickUp(Room room) {
for (Pet pet : room.getPetsOnItem(this)) { for (Pet pet : room.getPetsOnItem(this)) {
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.packetUpdate = true; pet.setPacketUpdate(true);
} }
} }
@ -39,7 +39,7 @@ public class InteractionPetTree extends InteractionDefault {
super.onWalkOn(roomUnit, room, objects); super.onWalkOn(roomUnit, room, objects);
Pet pet = room.getPet(roomUnit); Pet pet = room.getPet(roomUnit);
if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoal())) { if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoalLocation())) {
RoomUnitStatus task = switch (pet.getTask()) { RoomUnitStatus task = switch (pet.getTask()) {
case RING_OF_FIRE -> RoomUnitStatus.RINGOFFIRE; case RING_OF_FIRE -> RoomUnitStatus.RINGOFFIRE;
case SWING -> RoomUnitStatus.SWING; case SWING -> RoomUnitStatus.SWING;
@ -52,7 +52,7 @@ public class InteractionPetTree extends InteractionDefault {
pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]);
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.getRoomUnit().setStatus(task, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); pet.getRoomUnit().setStatus(task, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");
pet.packetUpdate = true; pet.setPacketUpdate(true);
RoomUnitStatus finalTask = task; RoomUnitStatus finalTask = task;
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> {
pet.addHappiness(25); pet.addHappiness(25);
@ -64,13 +64,13 @@ public class InteractionPetTree extends InteractionDefault {
pet.clearPosture(); pet.clearPosture();
} }
pet.getRoomUnit().setCanWalk(true); pet.getRoomUnit().setCanWalk(true);
pet.packetUpdate = true; pet.setPacketUpdate(true);
}, (long) 2500 + (Emulator.getRandom().nextInt(20) * 500)); }, (long) 2500 + (Emulator.getRandom().nextInt(20) * 500));
} else { } else {
pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]);
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.getRoomUnit().setStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); pet.getRoomUnit().setStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");
pet.packetUpdate = true; pet.setPacketUpdate(true);
} }
} }
} }
@ -83,7 +83,7 @@ public class InteractionPetTree extends InteractionDefault {
if (pet != null) { if (pet != null) {
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.packetUpdate = true; pet.setPacketUpdate(true);
} }
} }

View File

@ -43,7 +43,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
} }
public static void teleportUnitToTile(RoomUnit roomUnit, RoomTile tile) { public static void teleportUnitToTile(RoomUnit roomUnit, RoomTile tile) {
if (roomUnit == null || tile == null || roomUnit.isWiredTeleporting) if (roomUnit == null || tile == null || roomUnit.isWiredTeleporting())
return; return;
Room room = roomUnit.getRoom(); Room room = roomUnit.getRoom();
@ -79,7 +79,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
} }
} }
Emulator.getThreading().run(() -> roomUnit.isWiredTeleporting = true, Math.max(0, WiredHandler.TELEPORT_DELAY - 500)); Emulator.getThreading().run(() -> roomUnit.setWiredTeleporting(true), Math.max(0, WiredHandler.TELEPORT_DELAY - 500));
Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.getX(), tile.getY(), tile.getStackHeight() + (tile.getState() == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY); Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.getX(), tile.getY(), tile.getStackHeight() + (tile.getState() == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY);
} }

View File

@ -271,7 +271,8 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
case ACTION_TURN_RIGHT_45 -> RoomUserRotation.clockwise(currentRotation); case ACTION_TURN_RIGHT_45 -> RoomUserRotation.clockwise(currentRotation);
case ACTION_TURN_RIGHT_90 -> RoomUserRotation.clockwise(RoomUserRotation.clockwise(currentRotation)); case ACTION_TURN_RIGHT_90 -> RoomUserRotation.clockwise(RoomUserRotation.clockwise(currentRotation));
case ACTION_TURN_RANDOM -> RoomUserRotation.fromValue(Emulator.getRandom().nextInt(8)); case ACTION_TURN_RANDOM -> RoomUserRotation.fromValue(Emulator.getRandom().nextInt(8));
case ACTION_WAIT, default -> currentRotation; case ACTION_WAIT -> currentRotation;
default -> currentRotation;
}; };
} }

View File

@ -42,7 +42,7 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
} }
public static void teleportUnitToTile(RoomUnit roomUnit, RoomTile tile) { public static void teleportUnitToTile(RoomUnit roomUnit, RoomTile tile) {
if (roomUnit == null || tile == null || roomUnit.isWiredTeleporting) if (roomUnit == null || tile == null || roomUnit.isWiredTeleporting())
return; return;
Room room = roomUnit.getRoom(); Room room = roomUnit.getRoom();
@ -78,7 +78,7 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
} }
} }
Emulator.getThreading().run(() -> { roomUnit.isWiredTeleporting = true; }, Math.max(0, WiredHandler.TELEPORT_DELAY - 500)); Emulator.getThreading().run(() -> { roomUnit.setWiredTeleporting(true); }, Math.max(0, WiredHandler.TELEPORT_DELAY - 500));
Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.getX(), tile.getY(), tile.getStackHeight() + (tile.getState() == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY); Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.getX(), tile.getY(), tile.getStackHeight() + (tile.getState() == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY);
} }

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.modtool; package com.eu.habbo.habbohotel.modtool;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -14,7 +15,7 @@ import java.text.SimpleDateFormat;
@Getter @Getter
public class ModToolBan implements Runnable { public class ModToolBan implements Runnable {
public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private final int userId; private final int userId;
private final String ip; private final String ip;
private final String machineId; private final String machineId;
@ -28,7 +29,7 @@ public class ModToolBan implements Runnable {
private final boolean needsInsert; private final boolean needsInsert;
public ModToolBan(ResultSet set) throws SQLException { public ModToolBan(ResultSet set) throws SQLException {
this.userId = set.getInt("user_id"); this.userId = set.getInt(DatabaseConstants.USER_ID);
this.ip = set.getString("ip"); this.ip = set.getString("ip");
this.machineId = set.getString("machine_id"); this.machineId = set.getString("machine_id");
this.staffId = set.getInt("user_staff_id"); this.staffId = set.getInt("user_staff_id");

View File

@ -41,7 +41,7 @@ public class GnomePet extends Pet implements IPetLook {
@Override @Override
public void run() { public void run() {
if (this.needsUpdate) { if (this.isNeedsUpdate()) {
super.run(); super.run();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET gnome_data = ? WHERE id = ? LIMIT 1")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET gnome_data = ? WHERE id = ? LIMIT 1")) {

View File

@ -36,7 +36,7 @@ public class HorsePet extends RideablePet {
@Override @Override
public void run() { public void run() {
if (this.needsUpdate) { if (this.isNeedsUpdate()) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET hair_style = ?, hair_color = ?, saddle = ?, ride = ?, saddle_item_id = ? WHERE id = ?")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET hair_style = ?, hair_color = ?, saddle = ?, ride = ?, saddle_item_id = ? WHERE id = ?")) {
statement.setInt(1, this.hairStyle); statement.setInt(1, this.hairStyle);
statement.setInt(2, this.hairColor); statement.setInt(2, this.hairColor);

View File

@ -57,10 +57,8 @@ public class MonsterplantPet extends Pet implements IPetLook {
this.put(10, new Pair<>("Cinereus", 3)); this.put(10, new Pair<>("Cinereus", 3));
} }
}; };
public static final ArrayList<Pair<String, Integer>> indexedBody = new ArrayList<>(MonsterplantPet.bodyRarity.values()); public static final int GROW_TIME = (30 * 60);
public static final ArrayList<Pair<String, Integer>> indexedColors = new ArrayList<>(MonsterplantPet.colorRarity.values()); public static final int TIME_TO_LIVE = (3 * 24 * 60 * 60); //3 days
public static final int growTime = (30 * 60);
public static final int timeToLive = (3 * 24 * 60 * 60); //3 days
private final int nose; private final int nose;
private final int noseColor; private final int noseColor;
private final int eyes; private final int eyes;
@ -70,7 +68,7 @@ public class MonsterplantPet extends Pet implements IPetLook {
public String look; public String look;
private final int type; private final int type;
private final int hue; private final int hue;
private int deathTimestamp = Emulator.getIntUnixTimestamp() + timeToLive; private int deathTimestamp = Emulator.getIntUnixTimestamp() + TIME_TO_LIVE;
private boolean canBreed = true; private boolean canBreed = true;
private boolean publiclyBreedable = false; private boolean publiclyBreedable = false;
private int growthStage = 0; private int growthStage = 0;
@ -122,7 +120,7 @@ public class MonsterplantPet extends Pet implements IPetLook {
@Override @Override
public void run() { public void run() {
if (this.needsUpdate) { if (this.isNeedsUpdate()) {
super.run(); super.run();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET mp_type = ?, mp_color = ?, mp_nose = ?, mp_eyes = ?, mp_mouth = ?, mp_nose_color = ?, mp_eyes_color = ?, mp_mouth_color = ?, mp_death_timestamp = ?, mp_breedable = ?, mp_allow_breed = ?, mp_is_dead = ? WHERE id = ?")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET mp_type = ?, mp_color = ?, mp_nose = ?, mp_eyes = ?, mp_mouth = ?, mp_nose_color = ?, mp_eyes_color = ?, mp_mouth_color = ?, mp_death_timestamp = ?, mp_breedable = ?, mp_allow_breed = ?, mp_is_dead = ? WHERE id = ?")) {
@ -156,18 +154,18 @@ public class MonsterplantPet extends Pet implements IPetLook {
AchievementManager.progressAchievement(Emulator.getGameEnvironment().getHabboManager().getHabbo(this.userId), Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantGardenOfDeath")); AchievementManager.progressAchievement(Emulator.getGameEnvironment().getHabboManager().getHabbo(this.userId), Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantGardenOfDeath"));
this.hasDied = true; this.hasDied = true;
this.needsUpdate = true; this.setNeedsUpdate(true);
} }
this.roomUnit.clearStatus(); this.roomUnit.clearStatus();
this.roomUnit.setStatus(RoomUnitStatus.RIP, ""); this.roomUnit.setStatus(RoomUnitStatus.RIP, "");
this.packetUpdate = true; this.setPacketUpdate(true);
} else { } else {
int difference = Emulator.getIntUnixTimestamp() - this.created + 1; int difference = Emulator.getIntUnixTimestamp() - this.created + 1;
if (difference >= growTime) { if (difference >= GROW_TIME) {
this.growthStage = 7; this.growthStage = 7;
boolean clear = false; boolean clear = false;
for (RoomUnitStatus s : this.roomUnit.getStatusMap().keySet()) { for (RoomUnitStatus s : this.roomUnit.getStatus().keySet()) {
if (s.equals(RoomUnitStatus.GROW)) { if (s.equals(RoomUnitStatus.GROW)) {
clear = true; clear = true;
break; break;
@ -176,22 +174,22 @@ public class MonsterplantPet extends Pet implements IPetLook {
if (clear) { if (clear) {
this.roomUnit.clearStatus(); this.roomUnit.clearStatus();
this.packetUpdate = true; this.setPacketUpdate(true);
} }
} else { } else {
int g = (int) Math.ceil(difference / (growTime / 7.0)); int g = (int) Math.ceil(difference / (GROW_TIME / 7.0));
if (g > this.growthStage) { if (g > this.growthStage) {
this.growthStage = g; this.growthStage = g;
this.roomUnit.clearStatus(); this.roomUnit.clearStatus();
this.roomUnit.setStatus(RoomUnitStatus.fromString("grw" + this.growthStage), ""); this.roomUnit.setStatus(RoomUnitStatus.fromString("grw" + this.growthStage), "");
this.packetUpdate = true; this.setPacketUpdate(true);
} }
} }
if (Emulator.getRandom().nextInt(1000) < 10) { if (Emulator.getRandom().nextInt(1000) < 10) {
super.updateGesture(Emulator.getIntUnixTimestamp()); super.updateGesture(Emulator.getIntUnixTimestamp());
this.packetUpdate = true; this.setPacketUpdate(true);
} }
} }
} }
@ -271,7 +269,7 @@ public class MonsterplantPet extends Pet implements IPetLook {
return 0; return 0;
} }
return Math.max(0, growTime - (Emulator.getIntUnixTimestamp() - this.created)); return Math.max(0, GROW_TIME - (Emulator.getIntUnixTimestamp() - this.created));
} }
public boolean isFullyGrown() { public boolean isFullyGrown() {
@ -368,7 +366,7 @@ public class MonsterplantPet extends Pet implements IPetLook {
@Override @Override
public int getMaxEnergy() { public int getMaxEnergy() {
return MonsterplantPet.timeToLive; return MonsterplantPet.TIME_TO_LIVE;
} }
@Override @Override
@ -384,7 +382,7 @@ public class MonsterplantPet extends Pet implements IPetLook {
public synchronized void scratched(Habbo habbo) { public synchronized void scratched(Habbo habbo) {
if (this.mayScratch()) { if (this.mayScratch()) {
AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantTreater"), 5); AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantTreater"), 5);
this.setDeathTimestamp(Emulator.getIntUnixTimestamp() + MonsterplantPet.timeToLive); this.setDeathTimestamp(Emulator.getIntUnixTimestamp() + MonsterplantPet.TIME_TO_LIVE);
this.addHappiness(10); this.addHappiness(10);
this.addExperience(10); this.addExperience(10);
this.room.sendComposer(new PetStatusUpdateComposer(this).compose()); this.room.sendComposer(new PetStatusUpdateComposer(this).compose());

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.pets; package com.eu.habbo.habbohotel.pets;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
@ -23,6 +24,8 @@ import java.util.Calendar;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION;
@Slf4j @Slf4j
public class Pet implements ISerialize, Runnable { public class Pet implements ISerialize, Runnable {
@ -33,15 +36,13 @@ public class Pet implements ISerialize, Runnable {
@Setter @Setter
public int levelHunger; public int levelHunger;
/** @Setter
* Whether the pet needs to be updated. @Getter
*/ private boolean needsUpdate = false;
public boolean needsUpdate = false;
/** @Setter
* Whether the pet needs to be sent as a packet update. @Getter
*/ private boolean packetUpdate = false;
public boolean packetUpdate = false;
@Getter @Getter
protected int id; protected int id;
@Getter @Getter
@ -138,7 +139,7 @@ public class Pet implements ISerialize, Runnable {
public Pet(ResultSet set) throws SQLException { public Pet(ResultSet set) throws SQLException {
super(); super();
this.id = set.getInt("id"); this.id = set.getInt("id");
this.userId = set.getInt("user_id"); this.userId = set.getInt(DatabaseConstants.USER_ID);
this.room = null; this.room = null;
this.name = set.getString("name"); this.name = set.getString("name");
this.petData = Emulator.getGameEnvironment().getPetManager().getPetData(set.getInt("type")); this.petData = Emulator.getGameEnvironment().getPetManager().getPetData(set.getInt("type"));
@ -161,10 +162,10 @@ public class Pet implements ISerialize, Runnable {
/** /**
* Creates a new pet with the given type, race, color, name, and owner. * Creates a new pet with the given type, race, color, name, and owner.
* *
* @param type the type of the pet * @param type the type of the pet
* @param race the race of the pet * @param race the race of the pet
* @param color the color of the pet * @param color the color of the pet
* @param name the name of the pet * @param name the name of the pet
* @param userId the ID of the user that owns the pet * @param userId the ID of the user that owns the pet
*/ */
public Pet(int type, int race, String color, String name, int userId) { public Pet(int type, int race, String color, String name, int userId) {
@ -280,7 +281,7 @@ public class Pet implements ISerialize, Runnable {
*/ */
@Override @Override
public void run() { public void run() {
if (this.needsUpdate) { if (this.isNeedsUpdate()) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
if (this.id > 0) { if (this.id > 0) {
try (PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET room_id = ?, experience = ?, energy = ?, respect = ?, x = ?, y = ?, z = ?, rot = ?, hunger = ?, thirst = ?, happyness = ?, created = ? WHERE id = ?")) { try (PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET room_id = ?, experience = ?, energy = ?, respect = ?, x = ?, y = ?, z = ?, rot = ?, hunger = ?, thirst = ?, happyness = ?, created = ? WHERE id = ?")) {
@ -322,16 +323,16 @@ public class Pet implements ISerialize, Runnable {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
this.needsUpdate = false; this.setNeedsUpdate(false);
} }
} }
/** /**
* Performs a cycle of updates for the pet. This includes updates to their walking, tasks, happiness, hunger, thirst, and energy levels. * Performs a cycle of updates for the pet. This includes updates to their walking, tasks, happiness, hunger, thirst, and energy levels.
* It also includes updates to their gestures and random actions, as well as vocalizing if they are not muted. * It also includes updates to their gestures and random actions, as well as vocalizing if they are not muted.
*/ */
public void cycle() { public void cycle() {
this.idleCommandTicks++; this.idleCommandTicks++;
@ -340,7 +341,7 @@ public class Pet implements ISerialize, Runnable {
if (this.roomUnit != null && this.task != PetTasks.RIDE) { if (this.roomUnit != null && this.task != PetTasks.RIDE) {
if (time - this.gestureTickTimeout > 5 && this.roomUnit.hasStatus(RoomUnitStatus.GESTURE)) { if (time - this.gestureTickTimeout > 5 && this.roomUnit.hasStatus(RoomUnitStatus.GESTURE)) {
this.roomUnit.removeStatus(RoomUnitStatus.GESTURE); this.roomUnit.removeStatus(RoomUnitStatus.GESTURE);
this.packetUpdate = true; this.setPacketUpdate(true);
} }
if (time - this.postureTimeout > 1 && this.task == null) { if (time - this.postureTimeout > 1 && this.task == null) {
@ -372,7 +373,6 @@ public class Pet implements ISerialize, Runnable {
if (this.levelThirst > 0) if (this.levelThirst > 0)
this.levelThirst--; this.levelThirst--;
//this.addEnergy(5);
this.addHappiness(1); this.addHappiness(1);
@ -429,27 +429,25 @@ public class Pet implements ISerialize, Runnable {
this.randomActionTickTimeout = time + (10 * Emulator.getRandom().nextInt(60)); this.randomActionTickTimeout = time + (10 * Emulator.getRandom().nextInt(60));
} }
if (!this.muted) { if (!this.muted && this.chatTimeout <= time) {
if (this.chatTimeout <= time) { if (this.energy <= 30) {
if (this.energy <= 30) { this.say(this.petData.randomVocal(PetVocalsType.TIRED));
this.say(this.petData.randomVocal(PetVocalsType.TIRED)); if (this.energy <= 10)
if (this.energy <= 10) this.findNest();
this.findNest(); } else if (this.happiness > 85) {
} else if (this.happiness > 85) { this.say(this.petData.randomVocal(PetVocalsType.GENERIC_HAPPY));
this.say(this.petData.randomVocal(PetVocalsType.GENERIC_HAPPY)); } else if (this.happiness < 15) {
} else if (this.happiness < 15) { this.say(this.petData.randomVocal(PetVocalsType.GENERIC_SAD));
this.say(this.petData.randomVocal(PetVocalsType.GENERIC_SAD)); } else if (this.levelHunger > 50) {
} else if (this.levelHunger > 50) { this.say(this.petData.randomVocal(PetVocalsType.HUNGRY));
this.say(this.petData.randomVocal(PetVocalsType.HUNGRY)); this.eat();
this.eat(); } else if (this.levelThirst > 50) {
} else if (this.levelThirst > 50) { this.say(this.petData.randomVocal(PetVocalsType.THIRSTY));
this.say(this.petData.randomVocal(PetVocalsType.THIRSTY)); this.drink();
this.drink();
}
int timeOut = Emulator.getRandom().nextInt(30);
this.chatTimeout = time + (timeOut < 3 ? 30 : timeOut);
} }
int timeOut = Emulator.getRandom().nextInt(30);
this.chatTimeout = time + (timeOut < 3 ? 30 : timeOut);
} }
} }
} }
@ -458,8 +456,8 @@ public class Pet implements ISerialize, Runnable {
* Handles a pet command. * Handles a pet command.
* *
* @param command The command to handle. * @param command The command to handle.
* @param habbo The user who issued the command. * @param habbo The user who issued the command.
* @param data The data for the command. * @param data The data for the command.
*/ */
public void handleCommand(PetCommand command, Habbo habbo, String[] data) { public void handleCommand(PetCommand command, Habbo habbo, String[] data) {
this.idleCommandTicks = 0; this.idleCommandTicks = 0;
@ -519,7 +517,7 @@ public class Pet implements ISerialize, Runnable {
this.roomUnit.setStatus(entry.getKey(), entry.getValue()); this.roomUnit.setStatus(entry.getKey(), entry.getValue());
} }
if (!keys.isEmpty()) this.packetUpdate = true; if (!keys.isEmpty()) this.setPacketUpdate(true);
} }
} }
@ -601,7 +599,8 @@ public class Pet implements ISerialize, Runnable {
if (this.getRoomUnit().getCurrentLocation().distance(this.room.getLayout().getTile(item.getX(), item.getY())) == 0) { if (this.getRoomUnit().getCurrentLocation().distance(this.room.getLayout().getTile(item.getX(), item.getY())) == 0) {
try { try {
item.onWalkOn(this.getRoomUnit(), this.getRoom(), null); item.onWalkOn(this.getRoomUnit(), this.getRoom(), null);
} catch (Exception ignored) {} } catch (Exception ignored) {
}
} else { } else {
this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY())); this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY()));
} }
@ -614,11 +613,9 @@ public class Pet implements ISerialize, Runnable {
*/ */
public void eat() { public void eat() {
HabboItem item = this.petData.randomFoodItem(this.room.getRoomSpecialTypes().getPetFoods()); HabboItem item = this.petData.randomFoodItem(this.room.getRoomSpecialTypes().getPetFoods());
{ if (item != null) {
if (item != null) { this.roomUnit.setCanWalk(true);
this.roomUnit.setCanWalk(true); this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY()));
this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY()));
}
} }
} }
@ -629,19 +626,19 @@ public class Pet implements ISerialize, Runnable {
*/ */
public boolean findToy() { public boolean findToy() {
HabboItem item = this.petData.randomToyItem(this.room.getRoomSpecialTypes().getPetToys()); HabboItem item = this.petData.randomToyItem(this.room.getRoomSpecialTypes().getPetToys());
{ if (item != null) {
if (item != null) { this.roomUnit.setCanWalk(true);
this.roomUnit.setCanWalk(true); if (this.getRoomUnit().getCurrentLocation().distance(this.room.getLayout().getTile(item.getX(), item.getY())) == 0) {
if (this.getRoomUnit().getCurrentLocation().distance(this.room.getLayout().getTile(item.getX(), item.getY())) == 0) { try {
try { item.onWalkOn(this.getRoomUnit(), this.getRoom(), null);
item.onWalkOn(this.getRoomUnit(), this.getRoom(), null); } catch (Exception ignored) {
} catch (Exception ignored) {}
return true;
} }
this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY()));
return true; return true;
} }
this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY()));
return true;
} }
return false; return false;
} }
@ -655,18 +652,19 @@ public class Pet implements ISerialize, Runnable {
public boolean findPetItem(PetTasks task, Class<? extends HabboItem> type) { public boolean findPetItem(PetTasks task, Class<? extends HabboItem> type) {
HabboItem item = this.petData.randomToyHabboItem(this.room.getRoomSpecialTypes().getItemsOfType(type)); HabboItem item = this.petData.randomToyHabboItem(this.room.getRoomSpecialTypes().getItemsOfType(type));
if (item != null) { if (item != null) {
this.roomUnit.setCanWalk(true); this.roomUnit.setCanWalk(true);
this.setTask(task); this.setTask(task);
if (this.getRoomUnit().getCurrentLocation().distance(this.room.getLayout().getTile(item.getX(), item.getY())) == 0) { if (this.getRoomUnit().getCurrentLocation().distance(this.room.getLayout().getTile(item.getX(), item.getY())) == 0) {
try { try {
item.onWalkOn(this.getRoomUnit(), this.getRoom(), null); item.onWalkOn(this.getRoomUnit(), this.getRoom(), null);
} catch (Exception ignored) {} } catch (Exception ignored) {
return true;
} }
this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY()));
return true; return true;
} }
this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY()));
return true;
}
return false; return false;
} }
@ -709,7 +707,7 @@ public class Pet implements ISerialize, Runnable {
if (this.room != null) { if (this.room != null) {
this.room.sendComposer(new PetExperienceComposer(this, amount).compose()); this.room.sendComposer(new PetExperienceComposer(this, amount).compose());
if(this.level < PetManager.experiences.length + 1 && this.experience >= PetManager.experiences[this.level - 1]) { if (this.level < PetManager.experiences.length + 1 && this.experience >= PetManager.experiences[this.level - 1]) {
this.levelUp(); this.levelUp();
} }
} }
@ -719,20 +717,20 @@ public class Pet implements ISerialize, Runnable {
* Levels up the pet if it has enough experience. * Levels up the pet if it has enough experience.
*/ */
protected void levelUp() { protected void levelUp() {
if (this.level >= PetManager.experiences.length + 1) if (this.level >= PetManager.experiences.length + 1)
return; return;
if (this.experience > PetManager.experiences[this.level - 1]) { if (this.experience > PetManager.experiences[this.level - 1]) {
this.experience = PetManager.experiences[this.level - 1]; this.experience = PetManager.experiences[this.level - 1];
}
this.level++;
this.say(this.petData.randomVocal(PetVocalsType.LEVEL_UP));
this.addHappiness(100);
this.roomUnit.setStatus(RoomUnitStatus.GESTURE, "exp");
this.gestureTickTimeout = Emulator.getIntUnixTimestamp();
AchievementManager.progressAchievement(Emulator.getGameEnvironment().getHabboManager().getHabbo(this.userId), Emulator.getGameEnvironment().getAchievementManager().getAchievement("PetLevelUp"));
this.room.sendComposer(new PetLevelUpdatedComposer(this).compose());
} }
this.level++;
this.say(this.petData.randomVocal(PetVocalsType.LEVEL_UP));
this.addHappiness(100);
this.roomUnit.setStatus(RoomUnitStatus.GESTURE, "exp");
this.gestureTickTimeout = Emulator.getIntUnixTimestamp();
AchievementManager.progressAchievement(Emulator.getGameEnvironment().getHabboManager().getHabbo(this.userId), Emulator.getGameEnvironment().getAchievementManager().getAchievement("PetLevelUp"));
this.room.sendComposer(new PetLevelUpdatedComposer(this).compose());
}
/** /**
* Increases the pet's thirst level by a given amount. * Increases the pet's thirst level by a given amount.
@ -784,7 +782,7 @@ public class Pet implements ISerialize, Runnable {
this.addHappiness(10); this.addHappiness(10);
this.addExperience(10); this.addExperience(10);
this.addRespect(); this.addRespect();
this.needsUpdate = true; this.setNeedsUpdate(true);
if (habbo != null) { if (habbo != null) {
habbo.getHabboStats().decreasePetRespectPointsToGive(); habbo.getHabboStats().decreasePetRespectPointsToGive();
@ -807,6 +805,7 @@ public class Pet implements ISerialize, Runnable {
/** /**
* Removes this pet from the room. * Removes this pet from the room.
*
* @param dontSendPackets if true, packets will not be sent to update clients * @param dontSendPackets if true, packets will not be sent to update clients
*/ */
public void removeFromRoom(boolean dontSendPackets) { public void removeFromRoom(boolean dontSendPackets) {
@ -822,7 +821,7 @@ public class Pet implements ISerialize, Runnable {
this.roomUnit = null; this.roomUnit = null;
this.room = null; this.room = null;
this.needsUpdate = true; this.setNeedsUpdate(true);
} }
} }

View File

@ -407,7 +407,7 @@ public class PetManager {
client.getHabbo().getHabboInfo().getId() client.getHabbo().getHabboInfo().getId()
); );
pet.needsUpdate = true; pet.setNeedsUpdate(true);
pet.run(); pet.run();
return pet; return pet;
} }
@ -421,7 +421,7 @@ public class PetManager {
public Pet createPet(int type, int race, String name, GameClient client) { public Pet createPet(int type, int race, String name, GameClient client) {
if (this.petData.containsKey(type)) { if (this.petData.containsKey(type)) {
Pet pet = new Pet(type, race, "FFFFFF", name, client.getHabbo().getHabboInfo().getId()); Pet pet = new Pet(type, race, "FFFFFF", name, client.getHabbo().getHabboInfo().getId());
pet.needsUpdate = true; pet.setNeedsUpdate(true);
pet.run(); pet.run();
return pet; return pet;
} }
@ -445,7 +445,7 @@ public class PetManager {
pet.setRoom(room); pet.setRoom(room);
pet.setRoomUnit(new RoomUnit()); pet.setRoomUnit(new RoomUnit());
pet.getRoomUnit().setPathFinderRoom(room); pet.getRoomUnit().setPathFinderRoom(room);
pet.needsUpdate = true; pet.setNeedsUpdate(true);
pet.run(); pet.run();
return pet; return pet;
} }
@ -464,7 +464,7 @@ public class PetManager {
pet.setRoom(room); pet.setRoom(room);
pet.setRoomUnit(new RoomUnit()); pet.setRoomUnit(new RoomUnit());
pet.getRoomUnit().setPathFinderRoom(room); pet.getRoomUnit().setPathFinderRoom(room);
pet.needsUpdate = true; pet.setNeedsUpdate(true);
pet.run(); pet.run();
return pet; return pet;
@ -484,7 +484,7 @@ public class PetManager {
pet.setRoom(room); pet.setRoom(room);
pet.setRoomUnit(new RoomUnit()); pet.setRoomUnit(new RoomUnit());
pet.getRoomUnit().setPathFinderRoom(room); pet.getRoomUnit().setPathFinderRoom(room);
pet.needsUpdate = true; pet.setNeedsUpdate(true);
pet.run(); pet.run();
return pet; return pet;

View File

@ -20,11 +20,11 @@ public class ActionDown extends PetAction {
@Override @Override
public boolean apply(Pet pet, Habbo habbo, String[] data) { public boolean apply(Pet pet, Habbo habbo, String[] data) {
if (pet.getTask() != PetTasks.DOWN && !pet.getRoomUnit().hasStatus(RoomUnitStatus.LAY)) { if (pet.getTask() != PetTasks.DOWN && !pet.getRoomUnit().hasStatus(RoomUnitStatus.LAY)) {
pet.getRoomUnit().cmdLay = true; pet.getRoomUnit().setCmdLay(true);
pet.getRoomUnit().setStatus(RoomUnitStatus.LAY, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); pet.getRoomUnit().setStatus(RoomUnitStatus.LAY, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> {
pet.getRoomUnit().cmdLay = false; pet.getRoomUnit().setCmdLay(false);
pet.clearPosture(); pet.clearPosture();
}, this.minimumActionDuration); }, this.minimumActionDuration);

View File

@ -21,11 +21,11 @@ public class ActionSit extends PetAction {
@Override @Override
public boolean apply(Pet pet, Habbo habbo, String[] data) { public boolean apply(Pet pet, Habbo habbo, String[] data) {
if (pet.getTask() != PetTasks.SIT && !pet.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) { if (pet.getTask() != PetTasks.SIT && !pet.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) {
pet.getRoomUnit().cmdSit = true; pet.getRoomUnit().setCmdSit(true);
pet.getRoomUnit().setStatus(RoomUnitStatus.SIT, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); pet.getRoomUnit().setStatus(RoomUnitStatus.SIT, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> {
pet.getRoomUnit().cmdSit = false; pet.getRoomUnit().setCmdSit(false);
pet.clearPosture(); pet.clearPosture();
}, this.minimumActionDuration); }, this.minimumActionDuration);

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.rooms; package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -22,7 +23,7 @@ public class RoomBan {
public RoomBan(ResultSet set) throws SQLException { public RoomBan(ResultSet set) throws SQLException {
this.roomId = set.getInt("room_id"); this.roomId = set.getInt("room_id");
this.userId = set.getInt("user_id"); this.userId = set.getInt(DatabaseConstants.USER_ID);
this.username = set.getString("username"); this.username = set.getString("username");
this.endTimestamp = set.getInt("ends"); this.endTimestamp = set.getInt("ends");
} }

View File

@ -16,7 +16,6 @@ import com.eu.habbo.habbohotel.games.wired.WiredGame;
import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.items.interactions.InteractionWired; import com.eu.habbo.habbohotel.items.interactions.InteractionWired;
import com.eu.habbo.habbohotel.messenger.MessengerBuddy; import com.eu.habbo.habbohotel.messenger.MessengerBuddy;
import com.eu.habbo.habbohotel.navigation.NavigatorFilterComparator;
import com.eu.habbo.habbohotel.navigation.NavigatorFilterField; import com.eu.habbo.habbohotel.navigation.NavigatorFilterField;
import com.eu.habbo.habbohotel.navigation.NavigatorManager; import com.eu.habbo.habbohotel.navigation.NavigatorManager;
import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.permissions.Permission;
@ -58,19 +57,23 @@ import lombok.extern.slf4j.Slf4j;
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION;
@Slf4j @Slf4j
public class RoomManager { public class RoomManager {
private static final int page = 0;
//Configuration. Loaded from database & updated accordingly. //Configuration. Loaded from database & updated accordingly.
public static int MAXIMUM_ROOMS_USER = 25; public static int MAXIMUM_ROOMS_USER = 25;
public static int MAXIMUM_ROOMS_HC = 35; public static int MAXIMUM_ROOMS_HC = 35;
public static int HOME_ROOM_ID = 0; public static int HOME_ROOM_ID = 0;
public static boolean SHOW_PUBLIC_IN_POPULAR_TAB = false; public static boolean SHOW_PUBLIC_IN_POPULAR_TAB = false;
@Getter
private final THashMap<Integer, RoomCategory> roomCategories; private final THashMap<Integer, RoomCategory> roomCategories;
private final List<String> mapNames; private final List<String> mapNames;
private final ConcurrentHashMap<Integer, Room> activeRooms; private final ConcurrentHashMap<Integer, Room> activeRooms;
@Getter
private final ArrayList<Class<? extends Game>> gameTypes; private final ArrayList<Class<? extends Game>> gameTypes;
public RoomManager() { public RoomManager() {
@ -101,7 +104,7 @@ public class RoomManager {
this.mapNames.add(set.getString("name")); this.mapNames.add(set.getString("name"));
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
@ -115,7 +118,7 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return layout; return layout;
@ -129,7 +132,7 @@ public class RoomManager {
this.roomCategories.put(set.getInt("id"), new RoomCategory(set)); this.roomCategories.put(set.getInt("id"), new RoomCategory(set));
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
@ -145,15 +148,14 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
public THashMap<Integer, List<Room>> findRooms(NavigatorFilterField filterField, String value, int category, boolean showInvisible) { public THashMap<Integer, List<Room>> findRooms(NavigatorFilterField filterField, String value, int category, boolean showInvisible) {
THashMap<Integer, List<Room>> rooms = new THashMap<>(); THashMap<Integer, List<Room>> rooms = new THashMap<>();
String query = filterField.getDatabaseQuery() + " AND rooms.state NOT LIKE " + (showInvisible ? "''" : "'invisible'") + (category >= 0 ? "AND rooms.category = '" + category + "'" : "") + " ORDER BY rooms.users, rooms.id DESC LIMIT " + (/* TODO: This is always 0?*/page * NavigatorManager.MAXIMUM_RESULTS_PER_PAGE) + "" + ((page * NavigatorManager.MAXIMUM_RESULTS_PER_PAGE) + NavigatorManager.MAXIMUM_RESULTS_PER_PAGE); String query = filterField.getDatabaseQuery() + " AND rooms.state NOT LIKE " + (showInvisible ? "''" : "'invisible'") + (category >= 0 ? "AND rooms.category = '" + category + "'" : "") + " ORDER BY rooms.users, rooms.id DESC LIMIT " + NavigatorManager.MAXIMUM_RESULTS_PER_PAGE;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement(query)) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, (filterField.getComparator() == NavigatorFilterComparator.EQUALS ? value : "%" + value + "%"));
try (ResultSet set = statement.executeQuery()) { try (ResultSet set = statement.executeQuery()) {
while (set.next()) { while (set.next()) {
Room room = this.activeRooms.get(set.getInt("id")); Room room = this.activeRooms.get(set.getInt("id"));
@ -171,39 +173,22 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return rooms; return rooms;
} }
public RoomCategory getCategory(int id) { public RoomCategory getCategory(int id) {
for (RoomCategory category : this.roomCategories.values()) { return roomCategories.values().stream().filter(c -> c.getId() == id).findFirst().orElse(null);
if (category.getId() == id)
return category;
}
return null;
} }
public RoomCategory getCategory(String name) { public RoomCategory getCategory(String name) {
for (RoomCategory category : this.roomCategories.values()) { return roomCategories.values().stream().filter(c -> c.getCaption().equalsIgnoreCase(name)).findFirst().orElse(null);
if (category.getCaption().equalsIgnoreCase(name)) {
return category;
}
}
return null;
} }
public RoomCategory getCategoryBySafeCaption(String safeCaption) { public RoomCategory getCategoryBySafeCaption(String safeCaption) {
for (RoomCategory category : this.roomCategories.values()) { return roomCategories.values().stream().filter(c -> c.getCaptionSave().equalsIgnoreCase(safeCaption)).findFirst().orElse(null);
if (category.getCaptionSave().equalsIgnoreCase(safeCaption)) {
return category;
}
}
return null;
} }
public List<RoomCategory> roomCategoriesForHabbo(Habbo habbo) { public List<RoomCategory> roomCategoriesForHabbo(Habbo habbo) {
@ -219,19 +204,7 @@ public class RoomManager {
} }
public boolean hasCategory(int categoryId, Habbo habbo) { public boolean hasCategory(int categoryId, Habbo habbo) {
for (RoomCategory category : this.roomCategories.values()) { return roomCategories.values().stream().anyMatch(c -> c.getId() == categoryId && c.getMinRank() <= habbo.getHabboInfo().getRank().getId());
if (category.getId() == categoryId) {
if (category.getMinRank() <= habbo.getHabboInfo().getRank().getId()) {
return true;
}
}
}
return false;
}
public THashMap<Integer, RoomCategory> getRoomCategories() {
return this.roomCategories;
} }
public List<Room> getRoomsByScore() { public List<Room> getRoomsByScore() {
@ -278,7 +251,7 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return rooms; return rooms;
@ -294,10 +267,8 @@ public class RoomManager {
if (this.activeRooms.containsKey(id)) { if (this.activeRooms.containsKey(id)) {
room = this.activeRooms.get(id); room = this.activeRooms.get(id);
if (loadData) { if (loadData && (room.isPreLoaded() && !room.isLoaded())) {
if (room.isPreLoaded() && !room.isLoaded()) { room.loadData();
room.loadData();
}
} }
return room; return room;
@ -319,7 +290,7 @@ public class RoomManager {
this.activeRooms.put(room.getId(), room); this.activeRooms.put(room.getId(), room);
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return room; return room;
@ -329,7 +300,8 @@ public class RoomManager {
public Room createRoom(int ownerId, String ownerName, String name, String description, String modelName, int usersMax, int categoryId, int tradeType) { public Room createRoom(int ownerId, String ownerName, String name, String description, String modelName, int usersMax, int categoryId, int tradeType) {
Room room = null; Room room = null;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO rooms (owner_id, owner_name, name, description, model, users_max, category, trade_mode) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement(
"INSERT INTO rooms (owner_id, owner_name, name, description, model, users_max, category, trade_mode) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
statement.setInt(1, ownerId); statement.setInt(1, ownerId);
statement.setString(2, ownerName); statement.setString(2, ownerName);
statement.setString(3, name); statement.setString(3, name);
@ -344,7 +316,7 @@ public class RoomManager {
room = this.loadRoom(set.getInt(1)); room = this.loadRoom(set.getInt(1));
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return room; return room;
@ -369,7 +341,7 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
@ -419,7 +391,7 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return layout; return layout;
@ -453,7 +425,7 @@ public class RoomManager {
statement.setInt(2, room.getId()); statement.setInt(2, room.getId());
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
} }
@ -474,7 +446,7 @@ public class RoomManager {
return this.activeRooms.get(roomId); return this.activeRooms.get(roomId);
} }
public ArrayList<Room> getActiveRooms() { public List<Room> getActiveRooms() {
return new ArrayList<>(this.activeRooms.values()); return new ArrayList<>(this.activeRooms.values());
} }
@ -502,12 +474,11 @@ public class RoomManager {
return; return;
} }
if (Emulator.getPluginManager().fireEvent(new UserEnterRoomEvent(habbo, room)).isCancelled()) { if (Emulator.getPluginManager().fireEvent(new UserEnterRoomEvent(habbo, room)).isCancelled()
if (habbo.getHabboInfo().getCurrentRoom() == null) { && habbo.getHabboInfo().getCurrentRoom() == null) {
habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); habbo.getClient().sendResponse(new CloseConnectionMessageComposer());
habbo.getHabboInfo().setLoadingRoom(0); habbo.getHabboInfo().setLoadingRoom(0);
return; return;
}
} }
if (room.isBanned(habbo) && !habbo.hasPermission(Permission.ACC_ANYROOMOWNER) && !habbo.hasPermission(Permission.ACC_ENTERANYROOM)) { if (room.isBanned(habbo) && !habbo.hasPermission(Permission.ACC_ANYROOMOWNER) && !habbo.hasPermission(Permission.ACC_ENTERANYROOM)) {
@ -602,14 +573,15 @@ public class RoomManager {
habbo.getRoomUnit().clearStatus(); habbo.getRoomUnit().clearStatus();
if (habbo.getRoomUnit().getCurrentLocation() == null) { if (habbo.getRoomUnit().getCurrentLocation() == null) {
habbo.getRoomUnit().setLocation(doorLocation != null ? doorLocation : room.getLayout().getDoorTile()); habbo.getRoomUnit().setLocation(doorLocation != null ? doorLocation : room.getLayout().getDoorTile());
if (habbo.getRoomUnit().getCurrentLocation() != null) habbo.getRoomUnit().setZ(habbo.getRoomUnit().getCurrentLocation().getStackHeight()); if (habbo.getRoomUnit().getCurrentLocation() != null)
habbo.getRoomUnit().setZ(habbo.getRoomUnit().getCurrentLocation().getStackHeight());
if (doorLocation == null) { if (doorLocation == null) {
habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]);
habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]);
} else { } else {
habbo.getRoomUnit().setCanLeaveRoomByDoor(false); habbo.getRoomUnit().setCanLeaveRoomByDoor(false);
habbo.getRoomUnit().isTeleporting = true; habbo.getRoomUnit().setTeleporting(true);
HabboItem topItem = room.getTopItemAt(doorLocation.getX(), doorLocation.getY()); HabboItem topItem = room.getTopItemAt(doorLocation.getX(), doorLocation.getY());
if (topItem != null) { if (topItem != null) {
habbo.getRoomUnit().setRotation(RoomUserRotation.values()[topItem.getRotation()]); habbo.getRoomUnit().setRotation(RoomUserRotation.values()[topItem.getRotation()]);
@ -629,7 +601,7 @@ public class RoomManager {
} }
habbo.getRoomUnit().clearStatus(); habbo.getRoomUnit().clearStatus();
habbo.getRoomUnit().cmdTeleport = false; habbo.getRoomUnit().setCmdTeleport(false);
habbo.getClient().sendResponse(new OpenConnectionMessageComposer()); habbo.getClient().sendResponse(new OpenConnectionMessageComposer());
@ -684,20 +656,22 @@ public class RoomManager {
return; return;
} }
habbo.getRoomUnit().removeStatus(RoomUnitStatus.FLAT_CONTROL); habbo.getRoomUnit()
habbo.getHabboInfo().setLoadingRoom(0); .removeStatus(RoomUnitStatus.FLAT_CONTROL)
habbo.getHabboInfo().setCurrentRoom(room); .setPathFinderRoom(room)
habbo.getRoomUnit().setPathFinderRoom(room); .setHandItem(0)
habbo.getRoomUnit().setHandItem(0); .setRightsLevel(RoomRightLevels.NONE);
habbo.getHabboInfo().setLoadingRoom(0)
.setCurrentRoom(room);
habbo.getRoomUnit().setRightsLevel(RoomRightLevels.NONE);
room.refreshRightsForHabbo(habbo); room.refreshRightsForHabbo(habbo);
if (habbo.getRoomUnit().isKicked && !habbo.getRoomUnit().canWalk()) { if (habbo.getRoomUnit().isKicked() && !habbo.getRoomUnit().canWalk()) {
habbo.getRoomUnit().setCanWalk(true); habbo.getRoomUnit().setCanWalk(true);
} }
habbo.getRoomUnit().isKicked = false; habbo.getRoomUnit().setKicked(false);
if (habbo.getRoomUnit().getCurrentLocation() == null && !habbo.getRoomUnit().isTeleporting) { if (habbo.getRoomUnit().getCurrentLocation() == null && !habbo.getRoomUnit().isTeleporting()) {
RoomTile doorTile = room.getLayout().getTile(room.getLayout().getDoorX(), room.getLayout().getDoorY()); RoomTile doorTile = room.getLayout().getTile(room.getLayout().getDoorX(), room.getLayout().getDoorY());
if (doorTile != null) { if (doorTile != null) {
@ -727,19 +701,12 @@ public class RoomManager {
visibleHabbos = event.getVisibleHabbos(); visibleHabbos = event.getVisibleHabbos();
} }
for (Habbo habboToSendEnter : habbosToSendEnter) { habbosToSendEnter.stream().map(Habbo::getClient).filter(Objects::nonNull).forEach(client -> {
GameClient client = habboToSendEnter.getClient(); client.sendResponse(new RoomUsersComposer(habbo).compose());
if (client != null) { client.sendResponse(new UserUpdateComposer(habbo.getRoomUnit()).compose());
client.sendResponse(new RoomUsersComposer(habbo).compose()); });
client.sendResponse(new UserUpdateComposer(habbo.getRoomUnit()).compose());
}
}
for (Habbo h : visibleHabbos) { habbos = visibleHabbos.stream().filter(h -> !h.getRoomUnit().isInvisible()).toList();
if (!h.getRoomUnit().isInvisible()) {
habbos.add(h);
}
}
synchronized (room.roomUnitLock) { synchronized (room.roomUnitLock) {
habbo.getClient().sendResponse(new RoomUsersComposer(habbos)); habbo.getClient().sendResponse(new RoomUsersComposer(habbos));
@ -761,63 +728,48 @@ public class RoomManager {
habbo.getClient().sendResponse(new RoomUsersComposer(room.getCurrentBots().valueCollection(), true)); habbo.getClient().sendResponse(new RoomUsersComposer(room.getCurrentBots().valueCollection(), true));
if (!room.getCurrentBots().isEmpty()) { if (!room.getCurrentBots().isEmpty()) {
TIntObjectIterator<Bot> botIterator = room.getCurrentBots().iterator(); room.getCurrentBots().valueCollection().stream()
for (int i = room.getCurrentBots().size(); i-- > 0; ) { .filter(b -> !b.getRoomUnit().getDanceType().equals(DanceType.NONE))
try { .forEach(b -> habbo.getClient().sendResponse(new DanceMessageComposer(b.getRoomUnit())));
botIterator.advance();
} catch (NoSuchElementException e) {
break;
}
Bot bot = botIterator.value();
if (!bot.getRoomUnit().getDanceType().equals(DanceType.NONE)) {
habbo.getClient().sendResponse(new DanceMessageComposer(bot.getRoomUnit()));
}
habbo.getClient().sendResponse(new UserUpdateComposer(bot.getRoomUnit(), bot.getRoomUnit().getZ())); room.getCurrentBots().valueCollection()
} .forEach(b -> habbo.getClient().sendResponse(new UserUpdateComposer(b.getRoomUnit(), b.getRoomUnit().getZ())));
} }
habbo.getClient().sendResponse(new RoomEntryInfoMessageComposer(room, room.isOwner(habbo))); habbo.getClient().sendResponse(new RoomEntryInfoMessageComposer(room, room.isOwner(habbo)));
habbo.getClient().sendResponse(new RoomVisualizationSettingsComposer(room)); habbo.getClient().sendResponse(new RoomVisualizationSettingsComposer(room));
habbo.getClient().sendResponse(new GetGuestRoomResultComposer(room, habbo.getClient().getHabbo(), false, true)); habbo.getClient().sendResponse(new GetGuestRoomResultComposer(room, habbo.getClient().getHabbo(), false, true));
habbo.getClient().sendResponse(new ItemsComposer(room)); habbo.getClient().sendResponse(new ItemsComposer(room));
{ final THashSet<HabboItem> floorItems = new THashSet<>();
final THashSet<HabboItem> floorItems = new THashSet<>();
THashSet<HabboItem> allFloorItems = new THashSet<>(room.getFloorItems()); THashSet<HabboItem> allFloorItems = new THashSet<>(room.getFloorItems());
if (Emulator.getPluginManager().isRegistered(RoomFloorItemsLoadEvent.class, true)) { if (Emulator.getPluginManager().isRegistered(RoomFloorItemsLoadEvent.class, true)) {
RoomFloorItemsLoadEvent roomFloorItemsLoadEvent = Emulator.getPluginManager().fireEvent(new RoomFloorItemsLoadEvent(habbo, allFloorItems)); RoomFloorItemsLoadEvent roomFloorItemsLoadEvent = Emulator.getPluginManager().fireEvent(new RoomFloorItemsLoadEvent(habbo, allFloorItems));
if (roomFloorItemsLoadEvent.hasChangedFloorItems()) { if (roomFloorItemsLoadEvent.hasChangedFloorItems()) {
allFloorItems = roomFloorItemsLoadEvent.getFloorItems(); allFloorItems = roomFloorItemsLoadEvent.getFloorItems();
} }
}
allFloorItems.forEach(object -> {
if (room.isHideWired() && object instanceof InteractionWired)
return true;
floorItems.add(object);
if (floorItems.size() == 250) {
habbo.getClient().sendResponse(new ObjectsMessageComposer(room.getFurniOwnerNames(), floorItems));
floorItems.clear();
} }
allFloorItems.forEach(object -> { return true;
if (room.isHideWired() && object instanceof InteractionWired) });
return true;
floorItems.add(object); habbo.getClient().sendResponse(new ObjectsMessageComposer(room.getFurniOwnerNames(), floorItems));
if (floorItems.size() == 250) { floorItems.clear();
habbo.getClient().sendResponse(new ObjectsMessageComposer(room.getFurniOwnerNames(), floorItems));
floorItems.clear();
}
return true;
});
habbo.getClient().sendResponse(new ObjectsMessageComposer(room.getFurniOwnerNames(), floorItems));
floorItems.clear();
}
if (!room.getCurrentPets().isEmpty()) { if (!room.getCurrentPets().isEmpty()) {
habbo.getClient().sendResponse(new RoomPetComposer(room.getCurrentPets())); habbo.getClient().sendResponse(new RoomPetComposer(room.getCurrentPets()));
for (Pet pet : room.getCurrentPets().valueCollection()) { room.getCurrentPets().valueCollection().forEach(pet -> habbo.getClient().sendResponse(new UserUpdateComposer(pet.getRoomUnit())));
habbo.getClient().sendResponse(new UserUpdateComposer(pet.getRoomUnit()));
}
} }
if (!habbo.getHabboStats().allowTalk()) { if (!habbo.getHabboStats().allowTalk()) {
@ -832,77 +784,74 @@ public class RoomManager {
THashMap<Integer, String> guildBadges = new THashMap<>(); THashMap<Integer, String> guildBadges = new THashMap<>();
for (Habbo roomHabbo : habbos) { for (Habbo roomHabbo : habbos) {
{ if (roomHabbo.getRoomUnit().getDanceType().getType() > 0) {
if (roomHabbo.getRoomUnit().getDanceType().getType() > 0) { habbo.getClient().sendResponse(new DanceMessageComposer(roomHabbo.getRoomUnit()));
habbo.getClient().sendResponse(new DanceMessageComposer(roomHabbo.getRoomUnit())); }
if (roomHabbo.getRoomUnit().getHandItem() > 0) {
habbo.getClient().sendResponse(new CarryObjectMessageComposer(roomHabbo.getRoomUnit()));
}
if (roomHabbo.getRoomUnit().getEffectId() > 0) {
habbo.getClient().sendResponse(new AvatarEffectMessageComposer(roomHabbo.getRoomUnit()));
}
if (roomHabbo.getRoomUnit().isIdle()) {
habbo.getClient().sendResponse(new SleepMessageComposer(roomHabbo.getRoomUnit()));
}
if (roomHabbo.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
roomHabbo.getClient().sendResponse(new IgnoreResultMessageComposer(habbo, IgnoreResultMessageComposer.IGNORED));
}
if (!roomHabbo.getHabboStats().allowTalk()) {
habbo.getClient().sendResponse(new IgnoreResultMessageComposer(roomHabbo, IgnoreResultMessageComposer.MUTED));
} else if (habbo.getHabboStats().userIgnored(roomHabbo.getHabboInfo().getId())) {
habbo.getClient().sendResponse(new IgnoreResultMessageComposer(roomHabbo, IgnoreResultMessageComposer.IGNORED));
}
if (roomHabbo.getHabboStats().getGuild() != 0 && !guildBadges.containsKey(roomHabbo.getHabboStats().getGuild())) {
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(roomHabbo.getHabboStats().getGuild());
if (guild != null) {
guildBadges.put(roomHabbo.getHabboStats().getGuild(), guild.getBadge());
} }
}
if (roomHabbo.getRoomUnit().getHandItem() > 0) { if (roomHabbo.getRoomUnit().getRoomUnitType().equals(RoomUnitType.PET)) {
habbo.getClient().sendResponse(new CarryObjectMessageComposer(roomHabbo.getRoomUnit())); try {
} habbo.getClient().sendResponse(new UserRemoveMessageComposer(roomHabbo.getRoomUnit()));
habbo.getClient().sendResponse(new RoomUserPetComposer(((PetData) roomHabbo.getHabboStats().getCache().get("pet_type")).getType(), (Integer) roomHabbo.getHabboStats().getCache().get("pet_race"), (String) roomHabbo.getHabboStats().getCache().get("pet_color"), roomHabbo));
} catch (Exception ignored) {
if (roomHabbo.getRoomUnit().getEffectId() > 0) {
habbo.getClient().sendResponse(new AvatarEffectMessageComposer(roomHabbo.getRoomUnit()));
}
if (roomHabbo.getRoomUnit().isIdle()) {
habbo.getClient().sendResponse(new SleepMessageComposer(roomHabbo.getRoomUnit()));
}
if (roomHabbo.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
roomHabbo.getClient().sendResponse(new IgnoreResultMessageComposer(habbo, IgnoreResultMessageComposer.IGNORED));
}
if (!roomHabbo.getHabboStats().allowTalk()) {
habbo.getClient().sendResponse(new IgnoreResultMessageComposer(roomHabbo, IgnoreResultMessageComposer.MUTED));
} else if (habbo.getHabboStats().userIgnored(roomHabbo.getHabboInfo().getId())) {
habbo.getClient().sendResponse(new IgnoreResultMessageComposer(roomHabbo, IgnoreResultMessageComposer.IGNORED));
}
if (roomHabbo.getHabboStats().getGuild() != 0 && !guildBadges.containsKey(roomHabbo.getHabboStats().getGuild())) {
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(roomHabbo.getHabboStats().getGuild());
if (guild != null) {
guildBadges.put(roomHabbo.getHabboStats().getGuild(), guild.getBadge());
}
}
if (roomHabbo.getRoomUnit().getRoomUnitType().equals(RoomUnitType.PET)) {
try {
habbo.getClient().sendResponse(new UserRemoveMessageComposer(roomHabbo.getRoomUnit()));
habbo.getClient().sendResponse(new RoomUserPetComposer(((PetData) roomHabbo.getHabboStats().getCache().get("pet_type")).getType(), (Integer) roomHabbo.getHabboStats().getCache().get("pet_race"), (String) roomHabbo.getHabboStats().getCache().get("pet_color"), roomHabbo));
} catch (Exception ignored) {
}
} }
} }
} }
habbo.getClient().sendResponse(new HabboGroupBadgesMessageComposer(guildBadges)); habbo.getClient().sendResponse(new HabboGroupBadgesMessageComposer(guildBadges));
if (room.hasRights(habbo) || (room.hasGuild() && room.getGuildRightLevel(habbo).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) { if ((room.hasRights(habbo)
if (!room.getHabboQueue().isEmpty()) { || (room.hasGuild()
for (Habbo waiting : room.getHabboQueue().valueCollection()) { && room.getGuildRightLevel(habbo).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS)))
habbo.getClient().sendResponse(new DoorbellMessageComposer(waiting.getHabboInfo().getUsername())); && !room.getHabboQueue().isEmpty()) {
} for (Habbo waiting : room.getHabboQueue().valueCollection()) {
habbo.getClient().sendResponse(new DoorbellMessageComposer(waiting.getHabboInfo().getUsername()));
} }
} }
if (room.getPollId() > 0) { if (room.getPollId() > 0 && !PollManager.donePoll(habbo.getClient().getHabbo(), room.getPollId())) {
if (!PollManager.donePoll(habbo.getClient().getHabbo(), room.getPollId())) { Poll poll = Emulator.getGameEnvironment().getPollManager().getPoll(room.getPollId());
Poll poll = Emulator.getGameEnvironment().getPollManager().getPoll(room.getPollId());
if (poll != null) { if (poll != null) {
habbo.getClient().sendResponse(new PollOfferComposer(poll)); habbo.getClient().sendResponse(new PollOfferComposer(poll));
}
} }
} }
if (room.hasActiveWordQuiz()) { if (room.hasActiveWordQuiz()) {
habbo.getClient().sendResponse(new QuestionComposer((Emulator.getIntUnixTimestamp() - room.wordQuizEnd) * 1000, room.wordQuiz)); habbo.getClient().sendResponse(new QuestionComposer((Emulator.getIntUnixTimestamp() - room.getWordQuizEnd()) * 1000, room.getWordQuiz()));
if (room.hasVotedInWordQuiz(habbo)) { if (room.hasVotedInWordQuiz(habbo)) {
habbo.getClient().sendResponse(new QuestionFinishedComposer(room.noVotes, room.yesVotes)); habbo.getClient().sendResponse(new QuestionFinishedComposer(room.getNoVotes(), room.getYesVotes()));
} }
} }
@ -925,7 +874,7 @@ public class RoomManager {
if (!habbo.getHabboStats().visitedRoom(room.getId())) if (!habbo.getHabboStats().visitedRoom(room.getId()))
habbo.getHabboStats().addVisitRoom(room.getId()); habbo.getHabboStats().addVisitRoom(room.getId());
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
@ -944,7 +893,7 @@ public class RoomManager {
habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); habbo.getClient().sendResponse(new CloseConnectionMessageComposer());
} }
habbo.getHabboInfo().setCurrentRoom(null); habbo.getHabboInfo().setCurrentRoom(null);
habbo.getRoomUnit().isKicked = false; habbo.getRoomUnit().setKicked(false);
if (room.getOwnerId() != habbo.getHabboInfo().getId()) { if (room.getOwnerId() != habbo.getHabboInfo().getId()) {
AchievementManager.progressAchievement(room.getOwnerId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting"), (int) Math.floor((Emulator.getIntUnixTimestamp() - habbo.getHabboStats().roomEnterTimestamp) / 60000.0)); AchievementManager.progressAchievement(room.getOwnerId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting"), (int) Math.floor((Emulator.getIntUnixTimestamp() - habbo.getHabboStats().roomEnterTimestamp) / 60000.0));
@ -978,7 +927,7 @@ public class RoomManager {
statement.setInt(3, room.getId()); statement.setInt(3, room.getId());
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
} }
@ -998,52 +947,24 @@ public class RoomManager {
return new TreeMap<>(tagCount).keySet(); return new TreeMap<>(tagCount).keySet();
} }
public ArrayList<Room> getPublicRooms() { public List<Room> getPublicRooms() {
ArrayList<Room> rooms = new ArrayList<>(); return this.activeRooms.values().stream().filter(Room::isPublicRoom).sorted(Room.SORT_ID).toList();
for (Room room : this.activeRooms.values()) {
if (room.isPublicRoom()) {
rooms.add(room);
}
}
rooms.sort(Room.SORT_ID);
return rooms;
} }
public ArrayList<Room> getPopularRooms(int count) { public List<Room> getPopularRooms(int count) {
ArrayList<Room> rooms = new ArrayList<>(); return this.activeRooms.values().stream()
.filter(room -> room.getUserCount() > 0 && (!room.isPublicRoom() || RoomManager.SHOW_PUBLIC_IN_POPULAR_TAB))
for (Room room : this.activeRooms.values()) { .sorted()
if (room.getUserCount() > 0) { .limit(count)
if (!room.isPublicRoom() || RoomManager.SHOW_PUBLIC_IN_POPULAR_TAB) rooms.add(room); .toList();
}
}
if (rooms.isEmpty()) {
return rooms;
}
Collections.sort(rooms);
return new ArrayList<>(rooms.subList(0, (Math.min(rooms.size(), count))));
} }
public ArrayList<Room> getPopularRooms(int count, int category) { public List<Room> getPopularRooms(int count, int category) {
ArrayList<Room> rooms = new ArrayList<>(); return this.activeRooms.values().stream()
.filter(room -> !room.isPublicRoom() && room.getCategory() == category)
for (Room room : this.activeRooms.values()) { .sorted()
if (!room.isPublicRoom() && room.getCategory() == category) { .limit(count)
rooms.add(room); .toList();
}
}
if (rooms.isEmpty()) {
return rooms;
}
Collections.sort(rooms);
return new ArrayList<>(rooms.subList(0, (Math.min(rooms.size(), count))));
} }
public Map<Integer, List<Room>> getPopularRoomsByCategory(int count) { public Map<Integer, List<Room>> getPopularRoomsByCategory(int count) {
@ -1073,14 +994,8 @@ public class RoomManager {
return result; return result;
} }
public ArrayList<Room> getRoomsWithName(String name) { public List<Room> getRoomsWithName(String name) {
ArrayList<Room> rooms = new ArrayList<>(); List<Room> rooms = new ArrayList<>(activeRooms.values().stream().filter(room -> room.getName().equalsIgnoreCase(name)).toList());
for (Room room : this.activeRooms.values()) {
if (room.getName().toLowerCase().contains(name.toLowerCase())) {
rooms.add(room);
}
}
if (rooms.size() < 25) { if (rooms.size() < 25) {
rooms.addAll(this.getOfflineRoomsWithName(name)); rooms.addAll(this.getOfflineRoomsWithName(name));
@ -1107,13 +1022,13 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return rooms; return rooms;
} }
public ArrayList<Room> getRoomsWithTag(String tag) { public List<Room> getRoomsWithTag(String tag) {
ArrayList<Room> rooms = new ArrayList<>(); ArrayList<Room> rooms = new ArrayList<>();
for (Room room : this.activeRooms.values()) { for (Room room : this.activeRooms.values()) {
@ -1130,7 +1045,7 @@ public class RoomManager {
return rooms; return rooms;
} }
public ArrayList<Room> getGroupRoomsWithName(String name) { public List<Room> getGroupRoomsWithName(String name) {
ArrayList<Room> rooms = new ArrayList<>(); ArrayList<Room> rooms = new ArrayList<>();
for (Room room : this.activeRooms.values()) { for (Room room : this.activeRooms.values()) {
@ -1167,13 +1082,13 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return rooms; return rooms;
} }
public ArrayList<Room> getRoomsFriendsNow(Habbo habbo) { public List<Room> getRoomsFriendsNow(Habbo habbo) {
ArrayList<Room> rooms = new ArrayList<>(); ArrayList<Room> rooms = new ArrayList<>();
for (MessengerBuddy buddy : habbo.getMessenger().getFriends().values()) { for (MessengerBuddy buddy : habbo.getMessenger().getFriends().values()) {
@ -1192,7 +1107,7 @@ public class RoomManager {
return rooms; return rooms;
} }
public ArrayList<Room> getRoomsFriendsOwn(Habbo habbo) { public List<Room> getRoomsFriendsOwn(Habbo habbo) {
ArrayList<Room> rooms = new ArrayList<>(); ArrayList<Room> rooms = new ArrayList<>();
for (MessengerBuddy buddy : habbo.getMessenger().getFriends().values()) { for (MessengerBuddy buddy : habbo.getMessenger().getFriends().values()) {
@ -1212,7 +1127,7 @@ public class RoomManager {
return rooms; return rooms;
} }
public ArrayList<Room> getRoomsVisited(Habbo habbo, boolean includeSelf, int limit) { public List<Room> getRoomsVisited(Habbo habbo, boolean includeSelf, int limit) {
ArrayList<Room> rooms = new ArrayList<>(); ArrayList<Room> rooms = new ArrayList<>();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT rooms.* FROM room_enter_log INNER JOIN rooms ON room_enter_log.room_id = rooms.id WHERE user_id = ? AND timestamp >= ? AND rooms.owner_id != ? GROUP BY rooms.id AND timestamp ORDER BY timestamp DESC LIMIT " + limit)) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT rooms.* FROM room_enter_log INNER JOIN rooms ON room_enter_log.room_id = rooms.id WHERE user_id = ? AND timestamp >= ? AND rooms.owner_id != ? GROUP BY rooms.id AND timestamp ORDER BY timestamp DESC LIMIT " + limit)) {
@ -1233,7 +1148,7 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
Collections.sort(rooms); Collections.sort(rooms);
@ -1241,7 +1156,7 @@ public class RoomManager {
return rooms; return rooms;
} }
public ArrayList<Room> getRoomsFavourite(Habbo habbo) { public List<Room> getRoomsFavourite(Habbo habbo) {
final ArrayList<Room> rooms = new ArrayList<>(); final ArrayList<Room> rooms = new ArrayList<>();
habbo.getHabboStats().getFavoriteRooms().forEach(value -> { habbo.getHabboStats().getFavoriteRooms().forEach(value -> {
@ -1276,7 +1191,7 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
Collections.sort(rooms); Collections.sort(rooms);
@ -1284,7 +1199,7 @@ public class RoomManager {
return rooms.subList(0, (Math.min(rooms.size(), limit))); return rooms.subList(0, (Math.min(rooms.size(), limit)));
} }
public ArrayList<Room> getRoomsWithRights(Habbo habbo) { public List<Room> getRoomsWithRights(Habbo habbo) {
ArrayList<Room> rooms = new ArrayList<>(); ArrayList<Room> rooms = new ArrayList<>();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT rooms.* FROM rooms INNER JOIN room_rights ON room_rights.room_id = rooms.id WHERE room_rights.user_id = ? ORDER BY rooms.id DESC LIMIT 30")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT rooms.* FROM rooms INNER JOIN room_rights ON room_rights.room_id = rooms.id WHERE room_rights.user_id = ? ORDER BY rooms.id DESC LIMIT 30")) {
@ -1299,13 +1214,13 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return rooms; return rooms;
} }
public ArrayList<Room> getRoomsWithFriendsIn(Habbo habbo, int limit) { public List<Room> getRoomsWithFriendsIn(Habbo habbo, int limit) {
final ArrayList<Room> rooms = new ArrayList<>(); final ArrayList<Room> rooms = new ArrayList<>();
for (MessengerBuddy buddy : habbo.getMessenger().getFriends().values()) { for (MessengerBuddy buddy : habbo.getMessenger().getFriends().values()) {
@ -1341,13 +1256,13 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return rooms; return rooms;
} }
public ArrayList<Room> getRoomsWithAdminRights(Habbo habbo) { public List<Room> getRoomsWithAdminRights(Habbo habbo) {
ArrayList<Room> rooms = new ArrayList<>(); ArrayList<Room> rooms = new ArrayList<>();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
@ -1363,71 +1278,34 @@ public class RoomManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return rooms; return rooms;
} }
public ArrayList<Room> getRoomsInGroup() { public List<Room> getRoomsInGroup() {
return new ArrayList<>(); return new ArrayList<>();
} }
public ArrayList<Room> getRoomsPromoted() { public List<Room> getRoomsPromoted() {
ArrayList<Room> r = new ArrayList<>(); return activeRooms.values().stream().filter(Room::isPromoted).toList();
for (Room room : this.getActiveRooms()) {
if (room.isPromoted()) {
r.add(room);
}
}
return r;
} }
public ArrayList<Room> getRoomsStaffPromoted() { public List<Room> getRoomsStaffPromoted() {
ArrayList<Room> r = new ArrayList<>(); return activeRooms.values().stream().filter(Room::isStaffPromotedRoom).toList();
for (Room room : this.getActiveRooms()) {
if (room.isStaffPromotedRoom()) {
r.add(room);
}
}
return r;
} }
public List<Room> filterRoomsByOwner(List<Room> rooms, String filter) { public List<Room> filterRoomsByOwner(List<Room> rooms, String filter) {
ArrayList<Room> r = new ArrayList<>(); return rooms.stream().filter(r -> r.getOwnerName().equalsIgnoreCase(filter)).toList();
for (Room room : rooms) {
if (room.getOwnerName().equalsIgnoreCase(filter))
r.add(room);
}
return r;
} }
public List<Room> filterRoomsByName(List<Room> rooms, String filter) { public List<Room> filterRoomsByName(List<Room> rooms, String filter) {
ArrayList<Room> r = new ArrayList<>(); return rooms.stream().filter(room -> room.getName().toLowerCase().contains(filter.toLowerCase())).toList();
for (Room room : rooms) {
if (room.getName().toLowerCase().contains(filter.toLowerCase()))
r.add(room);
}
return r;
} }
public List<Room> filterRoomsByNameAndDescription(List<Room> rooms, String filter) { public List<Room> filterRoomsByNameAndDescription(List<Room> rooms, String filter) {
ArrayList<Room> r = new ArrayList<>(); return rooms.stream().filter(room -> room.getName().toLowerCase().contains(filter.toLowerCase()) || room.getDescription().toLowerCase().contains(filter.toLowerCase())).toList();
for (Room room : rooms) {
if (room.getName().toLowerCase().contains(filter.toLowerCase()) || room.getDescription().toLowerCase().contains(filter.toLowerCase()))
r.add(room);
}
return r;
} }
public List<Room> filterRoomsByTag(List<Room> rooms, String filter) { public List<Room> filterRoomsByTag(List<Room> rooms, String filter) {
@ -1447,17 +1325,9 @@ public class RoomManager {
} }
public List<Room> filterRoomsByGroup(List<Room> rooms, String filter) { public List<Room> filterRoomsByGroup(List<Room> rooms, String filter) {
ArrayList<Room> r = new ArrayList<>(); return rooms.stream().filter(room -> room.getGuildId() != 0)
.filter(room -> Emulator.getGameEnvironment().getGuildManager().getGuild(room.getGuildId()).getName().toLowerCase().contains(filter.toLowerCase()))
for (Room room : rooms) { .toList();
if (room.getGuildId() == 0)
continue;
if (Emulator.getGameEnvironment().getGuildManager().getGuild(room.getGuildId()).getName().toLowerCase().contains(filter.toLowerCase()))
r.add(room);
}
return r;
} }
public synchronized void dispose() { public synchronized void dispose() {
@ -1484,7 +1354,7 @@ public class RoomManager {
statement.setString(10, map); statement.setString(10, map);
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return this.loadCustomLayout(room); return this.loadCustomLayout(room);
@ -1528,11 +1398,9 @@ public class RoomManager {
room.addRoomBan(roomBan); room.addRoomBan(roomBan);
if (habbo != null) { if (habbo != null && habbo.getHabboInfo().getCurrentRoom() == room) {
if (habbo.getHabboInfo().getCurrentRoom() == room) { room.removeHabbo(habbo, true);
room.removeHabbo(habbo, true); habbo.getClient().sendResponse(new CantConnectMessageComposer(CantConnectMessageComposer.ROOM_ERROR_BANNED));
habbo.getClient().sendResponse(new CantConnectMessageComposer(CantConnectMessageComposer.ROOM_ERROR_BANNED));
}
} }
} }
@ -1544,10 +1412,6 @@ public class RoomManager {
gameTypes.remove(gameClass); gameTypes.remove(gameClass);
} }
public ArrayList<Class<? extends Game>> getGameTypes() {
return gameTypes;
}
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum RoomBanTypes { public enum RoomBanTypes {

View File

@ -22,48 +22,98 @@ import com.eu.habbo.util.pathfinding.Rotation;
import gnu.trove.map.TMap; import gnu.trove.map.TMap;
import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.stream.Collectors;
@Slf4j @Slf4j
public class RoomUnit { public class RoomUnit {
public boolean isWiredTeleporting = false; @Getter
public boolean isLeavingTeleporter = false; @Setter
public boolean isSwimming = false; private boolean isWiredTeleporting = false;
@Getter
@Setter
private boolean isLeavingTeleporter = false;
@Getter
@Setter
private boolean isSwimming = false;
@Getter
private final ConcurrentHashMap<RoomUnitStatus, String> status; private final ConcurrentHashMap<RoomUnitStatus, String> status;
private final THashMap<String, Object> cacheable; private final THashMap<String, Object> cacheable;
public boolean canRotate = true; @Getter
public boolean animateWalk = false; @Setter
public boolean cmdTeleport = false; private boolean canRotate = true;
public boolean cmdSit = false; @Getter
public boolean cmdStand = false; @Setter
public boolean cmdLay = false; private boolean animateWalk = false;
public boolean sitUpdate = false; @Getter
public boolean isTeleporting = false; @Setter
public boolean isKicked; private boolean cmdTeleport = false;
public int kickCount = 0; @Getter
@Setter
private boolean cmdSit = false;
@Setter
@Getter
private boolean cmdStand = false;
@Getter
@Setter
private boolean cmdLay = false;
@Setter
@Getter
private boolean sitUpdate = false;
@Getter
@Setter
private boolean isTeleporting = false;
@Getter
@Setter
private boolean isKicked;
@Getter
@Setter
private int kickCount = 0;
private int id; private int id;
@Getter
private RoomTile startLocation; private RoomTile startLocation;
@Getter
private RoomTile previousLocation; private RoomTile previousLocation;
@Getter
@Setter
@Accessors(chain = true)
private double previousLocationZ; private double previousLocationZ;
private RoomTile currentLocation; private RoomTile currentLocation;
@Getter
private RoomTile goalLocation; private RoomTile goalLocation;
@Getter
private double z; private double z;
private int tilesWalked; private int tilesWalked;
@Getter
@Setter
private boolean inRoom; private boolean inRoom;
@Setter
@Accessors(chain = true)
private boolean canWalk; private boolean canWalk;
@Setter
@Getter
private boolean fastWalk = false; private boolean fastWalk = false;
private boolean statusUpdate = false; private boolean statusUpdate = false;
private boolean invisible = false; private boolean invisible = false;
@Setter
private boolean canLeaveRoomByDoor = true; private boolean canLeaveRoomByDoor = true;
@Setter
private RoomUserRotation bodyRotation = RoomUserRotation.NORTH; private RoomUserRotation bodyRotation = RoomUserRotation.NORTH;
@Getter
@Setter
private RoomUserRotation headRotation = RoomUserRotation.NORTH; private RoomUserRotation headRotation = RoomUserRotation.NORTH;
@Getter
@Setter
private DanceType danceType; private DanceType danceType;
@Getter
@Setter
@Accessors(chain = true)
private RoomUnitType roomUnitType; private RoomUnitType roomUnitType;
private Deque<RoomTile> path = new LinkedList<>(); private Deque<RoomTile> path = new LinkedList<>();
private int handItem; private int handItem;
@ -73,7 +123,6 @@ public class RoomUnit {
private int effectEndTimestamp; private int effectEndTimestamp;
private int previousEffectId; private int previousEffectId;
private int previousEffectEndTimestamp; private int previousEffectEndTimestamp;
private ScheduledFuture moveBlockingTask;
private int timeInRoom; private int timeInRoom;
private int idleTimer; private int idleTimer;
@ -95,7 +144,7 @@ public class RoomUnit {
this.effectId = 0; this.effectId = 0;
this.previousEffectId = 0; this.previousEffectId = 0;
this.previousEffectEndTimestamp = -1; this.previousEffectEndTimestamp = -1;
this.isKicked = false; this.setKicked(false);
this.overridableTiles = new THashSet<>(); this.overridableTiles = new THashSet<>();
this.timeInRoom = 0; this.timeInRoom = 0;
} }
@ -119,46 +168,17 @@ public class RoomUnit {
public boolean cycle(Room room) { public boolean cycle(Room room) {
try { try {
Habbo rider = null; if (handleRider(room))
if (this.getRoomUnitType() == RoomUnitType.PET) {
Pet pet = room.getPet(this);
if (pet instanceof RideablePet) {
rider = ((RideablePet) pet).getRider();
}
}
if (rider != null) {
// copy things from rider
if (this.status.containsKey(RoomUnitStatus.MOVE) && !rider.getRoomUnit().getStatusMap().containsKey(RoomUnitStatus.MOVE)) {
this.status.remove(RoomUnitStatus.MOVE);
}
if (rider.getRoomUnit().getCurrentLocation().getX() != this.getX() || rider.getRoomUnit().getCurrentLocation().getY() != this.getY()) {
this.status.put(RoomUnitStatus.MOVE, rider.getRoomUnit().getCurrentLocation().getX() + "," + rider.getRoomUnit().getCurrentLocation().getY() + "," + (rider.getRoomUnit().getCurrentLocation().getStackHeight()));
this.setPreviousLocation(rider.getRoomUnit().getPreviousLocation());
this.setPreviousLocationZ(rider.getRoomUnit().getPreviousLocation().getStackHeight());
this.setCurrentLocation(rider.getRoomUnit().getCurrentLocation());
this.setZ(rider.getRoomUnit().getCurrentLocation().getStackHeight());
}
return this.statusUpdate; return this.statusUpdate;
Habbo habboT = room.getHabbo(this);
if (!this.isWalking() && !this.isKicked() && this.status.remove(RoomUnitStatus.MOVE) == null && habboT != null) {
habboT.getHabboInfo().getRiding().getRoomUnit().status.remove(RoomUnitStatus.MOVE);
return true;
} }
if (this.status.remove(RoomUnitStatus.SIT) != null || this.status.remove(RoomUnitStatus.MOVE) != null || this.status.remove(RoomUnitStatus.LAY) != null)
if (!this.isWalking() && !this.isKicked) { this.statusUpdate = true;
if (this.status.remove(RoomUnitStatus.MOVE) == null) {
Habbo habboT = room.getHabbo(this);
if (habboT != null) {
habboT.getHabboInfo().getRiding().getRoomUnit().status.remove(RoomUnitStatus.MOVE);
}
return true;
}
}
if (this.status.remove(RoomUnitStatus.SIT) != null) this.statusUpdate = true;
if (this.status.remove(RoomUnitStatus.MOVE) != null) this.statusUpdate = true;
if (this.status.remove(RoomUnitStatus.LAY) != null) this.statusUpdate = true;
for (Map.Entry<RoomUnitStatus, String> set : this.status.entrySet()) { for (Map.Entry<RoomUnitStatus, String> set : this.status.entrySet()) {
if (set.getKey().isRemoveWhenWalking()) { if (set.getKey().isRemoveWhenWalking()) {
@ -169,18 +189,13 @@ public class RoomUnit {
if (this.path == null || this.path.isEmpty()) if (this.path == null || this.path.isEmpty())
return true; return true;
boolean canfastwalk = true; boolean canfastwalk = habboT == null || habboT.getHabboInfo().getRiding() == null;
Habbo habboT = room.getHabbo(this);
if (habboT != null) {
if (habboT.getHabboInfo().getRiding() != null)
canfastwalk = false;
}
RoomTile next = this.path.poll(); RoomTile next = this.path.poll();
boolean overrideChecks = next != null && this.canOverrideTile(next); boolean overrideChecks = next != null && this.canOverrideTile(next);
if (this.path.isEmpty()) { if (this.path.isEmpty()) {
this.sitUpdate = true; this.setSitUpdate(true);
if (next != null && next.hasUnits() && !overrideChecks) { if (next != null && next.hasUnits() && !overrideChecks) {
return false; return false;
@ -206,10 +221,8 @@ public class RoomUnit {
} }
} }
if (canfastwalk && this.fastWalk) { if (canfastwalk && this.fastWalk && this.path.size() > 1) {
if (this.path.size() > 1) { next = this.path.poll();
next = this.path.poll();
}
} }
if (next == null) if (next == null)
@ -224,11 +237,9 @@ public class RoomUnit {
UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false); UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false);
Emulator.getPluginManager().fireEvent(event); Emulator.getPluginManager().fireEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled() && !event.isIdle()) {
if (!event.isIdle()) { room.unIdle(habbo);
room.unIdle(habbo); this.idleTimer = 0;
this.idleTimer = 0;
}
} }
} }
@ -243,21 +254,18 @@ public class RoomUnit {
HabboItem item = room.getTopItemAt(next.getX(), next.getY()); HabboItem item = room.getTopItemAt(next.getX(), next.getY());
//if(!(this.path.size() == 0 && canSitNextTile)) double height = next.getStackHeight() - this.currentLocation.getStackHeight();
{ if (!room.tileWalkable(next) || (!RoomLayout.ALLOW_FALLING && height < -RoomLayout.MAXIMUM_STEP_HEIGHT) || (next.getState() == RoomTileState.OPEN && height > RoomLayout.MAXIMUM_STEP_HEIGHT)) {
double height = next.getStackHeight() - this.currentLocation.getStackHeight(); this.room = room;
if (!room.tileWalkable(next) || (!RoomLayout.ALLOW_FALLING && height < -RoomLayout.MAXIMUM_STEP_HEIGHT) || (next.getState() == RoomTileState.OPEN && height > RoomLayout.MAXIMUM_STEP_HEIGHT)) { this.path.clear();
this.room = room; this.findPath();
this.path.clear();
this.findPath();
if (this.path.isEmpty()) {
this.status.remove(RoomUnitStatus.MOVE);
return false;
}
next = this.path.pop();
if (this.path.isEmpty()) {
this.status.remove(RoomUnitStatus.MOVE);
return false;
} }
next = this.path.pop();
} }
boolean canSitNextTile = room.canSitAt(next.getX(), next.getY()); boolean canSitNextTile = room.canSitAt(next.getX(), next.getY());
@ -269,31 +277,21 @@ public class RoomUnit {
item = tallestChair; item = tallestChair;
} }
if (next.equals(this.goalLocation) && next.getState() == RoomTileState.SIT && !overrideChecks) { if (next.equals(this.goalLocation) && next.getState() == RoomTileState.SIT && !overrideChecks
if (item == null || item.getZ() - this.getZ() > RoomLayout.MAXIMUM_STEP_HEIGHT) { && (item == null || item.getZ() - this.getZ() > RoomLayout.MAXIMUM_STEP_HEIGHT)) {
this.status.remove(RoomUnitStatus.MOVE); this.status.remove(RoomUnitStatus.MOVE);
return false; return false;
}
} }
double zHeight = 0.0D; double zHeight = 0.0D;
if (habbo != null && habbo.getHabboInfo().getRiding() != null) {
/*if (((habbo != null && habbo.getHabboInfo().getRiding() != null) || isRiding) && next.equals(this.goalLocation) && (next.state == RoomTileState.SIT || next.state == RoomTileState.LAY)) { zHeight += 1.0D;
this.status.remove(RoomUnitStatus.MOVE);
return false;
}*/
if (habbo != null) {
if (habbo.getHabboInfo().getRiding() != null) {
zHeight += 1.0D;
}
} }
HabboItem habboItem = room.getTopItemAt(this.getX(), this.getY()); HabboItem habboItem = room.getTopItemAt(this.getX(), this.getY());
if (habboItem != null) { if (habboItem != null && (habboItem != item || !RoomLayout.pointInSquare(habboItem.getX(), habboItem.getY(), habboItem.getX() + habboItem.getBaseItem().getWidth() - 1, habboItem.getY() + habboItem.getBaseItem().getLength() - 1, next.getX(), next.getY())))
if (habboItem != item || !RoomLayout.pointInSquare(habboItem.getX(), habboItem.getY(), habboItem.getX() + habboItem.getBaseItem().getWidth() - 1, habboItem.getY() + habboItem.getBaseItem().getLength() - 1, next.getX(), next.getY())) habboItem.onWalkOff(this, room, new Object[]{this.getCurrentLocation(), next});
habboItem.onWalkOff(this, room, new Object[]{this.getCurrentLocation(), next});
}
this.tilesWalked++; this.tilesWalked++;
@ -303,7 +301,7 @@ public class RoomUnit {
if (item != habboItem || !RoomLayout.pointInSquare(item.getX(), item.getY(), item.getX() + item.getBaseItem().getWidth() - 1, item.getY() + item.getBaseItem().getLength() - 1, this.getX(), this.getY())) { if (item != habboItem || !RoomLayout.pointInSquare(item.getX(), item.getY(), item.getX() + item.getBaseItem().getWidth() - 1, item.getY() + item.getBaseItem().getLength() - 1, this.getX(), this.getY())) {
if (item.canWalkOn(this, room, null)) { if (item.canWalkOn(this, room, null)) {
item.onWalkOn(this, room, new Object[]{this.getCurrentLocation(), next}); item.onWalkOn(this, room, new Object[]{this.getCurrentLocation(), next});
} else if (item instanceof ConditionalGate) { } else if (item instanceof ConditionalGate conditionalGate) {
this.setRotation(oldRotation); this.setRotation(oldRotation);
this.tilesWalked--; this.tilesWalked--;
this.setGoalLocation(this.currentLocation); this.setGoalLocation(this.currentLocation);
@ -311,7 +309,7 @@ public class RoomUnit {
room.sendComposer(new UserUpdateComposer(this).compose()); room.sendComposer(new UserUpdateComposer(this).compose());
if (habbo != null) { if (habbo != null) {
((ConditionalGate) item).onRejected(this, this.getRoom(), new Object[]{}); conditionalGate.onRejected(this, this.getRoom(), new Object[]{});
} }
return false; return false;
} }
@ -332,23 +330,19 @@ public class RoomUnit {
this.setPreviousLocation(this.getCurrentLocation()); this.setPreviousLocation(this.getCurrentLocation());
this.setStatus(RoomUnitStatus.MOVE, next.getX() + "," + next.getY() + "," + zHeight); this.setStatus(RoomUnitStatus.MOVE, next.getX() + "," + next.getY() + "," + zHeight);
if (habbo != null) { if (habbo != null && habbo.getHabboInfo().getRiding() != null) {
if (habbo.getHabboInfo().getRiding() != null) { RoomUnit ridingUnit = habbo.getHabboInfo().getRiding().getRoomUnit();
RoomUnit ridingUnit = habbo.getHabboInfo().getRiding().getRoomUnit();
if (ridingUnit != null) { if (ridingUnit != null) {
ridingUnit.setPreviousLocationZ(this.getZ()); ridingUnit.setPreviousLocationZ(this.getZ());
this.setZ(zHeight - 1.0); this.setZ(zHeight - 1.0);
ridingUnit.setRotation(RoomUserRotation.values()[Rotation.Calculate(this.getX(), this.getY(), next.getX(), next.getY())]); ridingUnit.setRotation(RoomUserRotation.values()[Rotation.Calculate(this.getX(), this.getY(), next.getX(), next.getY())]);
ridingUnit.setPreviousLocation(this.getCurrentLocation()); ridingUnit.setPreviousLocation(this.getCurrentLocation());
ridingUnit.setGoalLocation(this.getGoal()); ridingUnit.setGoalLocation(this.getGoalLocation());
ridingUnit.setStatus(RoomUnitStatus.MOVE, next.getX() + "," + next.getY() + "," + (zHeight - 1.0)); ridingUnit.setStatus(RoomUnitStatus.MOVE, next.getX() + "," + next.getY() + "," + (zHeight - 1.0));
room.sendComposer(new UserUpdateComposer(ridingUnit).compose()); room.sendComposer(new UserUpdateComposer(ridingUnit).compose());
//ridingUnit.setZ(zHeight - 1.0);
}
} }
} }
//room.sendComposer(new RoomUserStatusComposer(this).compose());
this.setZ(zHeight); this.setZ(zHeight);
this.setCurrentLocation(room.getLayout().getTile(next.getX(), next.getY())); this.setCurrentLocation(room.getLayout().getTile(next.getX(), next.getY()));
@ -374,6 +368,34 @@ public class RoomUnit {
} }
} }
private boolean handleRider(Room room) {
Habbo rider = null;
if (this.getRoomUnitType() == RoomUnitType.PET) {
Pet pet = room.getPet(this);
if (pet instanceof RideablePet rideablePet) {
rider = rideablePet.getRider();
}
}
if (rider != null) {
// copy things from rider
if (this.status.containsKey(RoomUnitStatus.MOVE) && !rider.getRoomUnit().getStatus().containsKey(RoomUnitStatus.MOVE)) {
this.status.remove(RoomUnitStatus.MOVE);
}
if (rider.getRoomUnit().getCurrentLocation().getX() != this.getX() || rider.getRoomUnit().getCurrentLocation().getY() != this.getY()) {
this.status.put(RoomUnitStatus.MOVE, rider.getRoomUnit().getCurrentLocation().getX() + "," + rider.getRoomUnit().getCurrentLocation().getY() + "," + (rider.getRoomUnit().getCurrentLocation().getStackHeight()));
this.setPreviousLocation(rider.getRoomUnit().getPreviousLocation());
this.setPreviousLocationZ(rider.getRoomUnit().getPreviousLocation().getStackHeight());
this.setCurrentLocation(rider.getRoomUnit().getCurrentLocation());
this.setZ(rider.getRoomUnit().getCurrentLocation().getStackHeight());
}
return true;
}
return false;
}
public int getId() { public int getId() {
return this.id; return this.id;
} }
@ -404,10 +426,6 @@ public class RoomUnit {
return this.currentLocation.getY(); return this.currentLocation.getY();
} }
public double getZ() {
return this.z;
}
public void setZ(double z) { public void setZ(double z) {
this.z = z; this.z = z;
@ -419,22 +437,6 @@ public class RoomUnit {
} }
} }
public synchronized boolean isInRoom() {
return this.inRoom;
}
public synchronized void setInRoom(boolean inRoom) {
this.inRoom = inRoom;
}
public synchronized RoomUnitType getRoomUnitType() {
return this.roomUnitType;
}
public synchronized void setRoomUnitType(RoomUnitType roomUnitType) {
this.roomUnitType = roomUnitType;
}
public void setRotation(RoomUserRotation rotation) { public void setRotation(RoomUserRotation rotation) {
this.bodyRotation = rotation; this.bodyRotation = rotation;
this.headRotation = rotation; this.headRotation = rotation;
@ -444,60 +446,19 @@ public class RoomUnit {
return this.bodyRotation; return this.bodyRotation;
} }
public void setBodyRotation(RoomUserRotation bodyRotation) {
this.bodyRotation = bodyRotation;
}
public RoomUserRotation getHeadRotation() {
return this.headRotation;
}
public void setHeadRotation(RoomUserRotation headRotation) {
this.headRotation = headRotation;
}
public synchronized DanceType getDanceType() {
return this.danceType;
}
public synchronized void setDanceType(DanceType danceType) {
this.danceType = danceType;
}
public void setCanWalk(boolean value) {
this.canWalk = value;
}
public boolean canWalk() { public boolean canWalk() {
return this.canWalk; return this.canWalk;
} }
public boolean isFastWalk() {
return this.fastWalk;
}
public void setFastWalk(boolean fastWalk) {
this.fastWalk = fastWalk;
}
public RoomTile getStartLocation() {
return this.startLocation;
}
public int tilesWalked() { public int tilesWalked() {
return this.tilesWalked; return this.tilesWalked;
} }
public RoomTile getGoal() { public RoomUnit setGoalLocation(RoomTile goalLocation) {
return this.goalLocation;
}
public void setGoalLocation(RoomTile goalLocation) {
if (goalLocation != null) { if (goalLocation != null) {
// if (goalLocation.state != RoomTileState.INVALID) {
this.setGoalLocation(goalLocation, false); this.setGoalLocation(goalLocation, false);
} }
//} return this;
} }
public void setGoalLocation(RoomTile goalLocation, boolean noReset) { public void setGoalLocation(RoomTile goalLocation, boolean noReset) {
@ -518,24 +479,21 @@ public class RoomUnit {
this.findPath(); ///< Quadral: this is where we start formulating a path this.findPath(); ///< Quadral: this is where we start formulating a path
if (!this.path.isEmpty()) { if (!this.path.isEmpty()) {
this.tilesWalked = isWalking ? this.tilesWalked : 0; this.tilesWalked = isWalking ? this.tilesWalked : 0;
this.cmdSit = false; this.setCmdSit(false);
} else { } else {
this.goalLocation = this.currentLocation; this.goalLocation = this.currentLocation;
} }
} }
} }
public void setLocation(RoomTile location) { public RoomUnit setLocation(RoomTile location) {
if (location != null) { if (location != null) {
this.startLocation = location; this.startLocation = location;
setPreviousLocation(location); setPreviousLocation(location);
setCurrentLocation(location); setCurrentLocation(location);
this.goalLocation = location; this.goalLocation = location;
} }
} return this;
public RoomTile getPreviousLocation() {
return this.previousLocation;
} }
public void setPreviousLocation(RoomTile previousLocation) { public void setPreviousLocation(RoomTile previousLocation) {
@ -543,22 +501,15 @@ public class RoomUnit {
this.previousLocationZ = this.z; this.previousLocationZ = this.z;
} }
public double getPreviousLocationZ() { public RoomUnit setPathFinderRoom(Room room) {
return this.previousLocationZ;
}
public void setPreviousLocationZ(double z) {
this.previousLocationZ = z;
}
public void setPathFinderRoom(Room room) {
this.room = room; this.room = room;
return this;
} }
public void findPath() { public void findPath() {
if (this.room != null && this.room.getLayout() != null && this.goalLocation != null && (this.goalLocation.isWalkable() || this.room.canSitOrLayAt(this.goalLocation.getX(), this.goalLocation.getY()) || this.canOverrideTile(this.goalLocation))) { if (this.room != null && this.room.getLayout() != null && this.goalLocation != null && (this.goalLocation.isWalkable() || this.room.canSitOrLayAt(this.goalLocation.getX(), this.goalLocation.getY()) || this.canOverrideTile(this.goalLocation))) {
Deque<RoomTile> path = this.room.getLayout().findPath(this.currentLocation, this.goalLocation, this.goalLocation, this); Deque<RoomTile> newPath = this.room.getLayout().findPath(this.currentLocation, this.goalLocation, this.goalLocation, this);
if (path != null) this.path = path; if (newPath != null) this.path = newPath;
} }
} }
@ -574,12 +525,9 @@ public class RoomUnit {
return this.status.get(key); return this.status.get(key);
} }
public ConcurrentHashMap<RoomUnitStatus, String> getStatusMap() { public RoomUnit removeStatus(RoomUnitStatus key) {
return this.status;
}
public void removeStatus(RoomUnitStatus key) {
this.status.remove(key); this.status.remove(key);
return this;
} }
public void setStatus(RoomUnitStatus key, String value) { public void setStatus(RoomUnitStatus key, String value) {
@ -612,9 +560,10 @@ public class RoomUnit {
return this.handItem; return this.handItem;
} }
public void setHandItem(int handItem) { public RoomUnit setHandItem(int handItem) {
this.handItem = handItem; this.handItem = handItem;
this.handItemTimestamp = System.currentTimeMillis(); this.handItemTimestamp = System.currentTimeMillis();
return this;
} }
public long getHandItemTimestamp() { public long getHandItemTimestamp() {
@ -689,7 +638,7 @@ public class RoomUnit {
} }
public void lookAtPoint(RoomTile location) { public void lookAtPoint(RoomTile location) {
if (!this.canRotate) return; if (!this.isCanRotate()) return;
if (Emulator.getPluginManager().isRegistered(RoomUnitLookAtPointEvent.class, false)) { if (Emulator.getPluginManager().isRegistered(RoomUnitLookAtPointEvent.class, false)) {
Event lookAtPointEvent = new RoomUnitLookAtPointEvent(this.room, this, location); Event lookAtPointEvent = new RoomUnitLookAtPointEvent(this.room, this, location);
@ -778,10 +727,6 @@ public class RoomUnit {
return canLeaveRoomByDoor; return canLeaveRoomByDoor;
} }
public void setCanLeaveRoomByDoor(boolean canLeaveRoomByDoor) {
this.canLeaveRoomByDoor = canLeaveRoomByDoor;
}
public boolean canForcePosture() { public boolean canForcePosture() {
if (this.room == null) return false; if (this.room == null) return false;
@ -816,17 +761,11 @@ public class RoomUnit {
return this.getClosestTile( return this.getClosestTile(
rotations.stream() rotations.stream()
.map(rotation -> room.getLayout().getTileInFront(baseTile, rotation)) .map(rotation -> room.getLayout().getTileInFront(baseTile, rotation))
.filter(t -> t != null && t.isWalkable() && (this.getCurrentLocation().equals(t) || !room.hasHabbosAt(t.getX(), t.getY()))) .filter(t -> t != null && t.isWalkable() && (this.getCurrentLocation().equals(t)
.collect(Collectors.toList()) || !room.hasHabbosAt(t.getX(), t.getY())))
.toList()
); );
} }
public ScheduledFuture getMoveBlockingTask() {
return moveBlockingTask;
}
public void setMoveBlockingTask(ScheduledFuture moveBlockingTask) {
this.moveBlockingTask = moveBlockingTask;
}
} }

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.users; package com.eu.habbo.habbohotel.users;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.catalog.CatalogItem; import com.eu.habbo.habbohotel.catalog.CatalogItem;
import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.games.GamePlayer; import com.eu.habbo.habbohotel.games.GamePlayer;
@ -16,6 +17,7 @@ import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer;
import gnu.trove.map.hash.TIntIntHashMap; import gnu.trove.map.hash.TIntIntHashMap;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.sql.*; import java.sql.*;
@ -56,6 +58,7 @@ public class HabboInfo implements Runnable {
@Setter @Setter
private boolean online; private boolean online;
@Setter @Setter
@Accessors(chain = true)
private int loadingRoom; private int loadingRoom;
@Setter @Setter
private Room currentRoom; private Room currentRoom;
@ -211,7 +214,7 @@ public class HabboInfo implements Runnable {
statement.setInt(1, this.id); statement.setInt(1, this.id);
try (ResultSet set = statement.executeQuery()) { try (ResultSet set = statement.executeQuery()) {
while (set.next()) { while (set.next()) {
this.messengerCategories.add(new MessengerCategory(set.getString("name"), set.getInt("user_id"), set.getInt("id"))); this.messengerCategories.add(new MessengerCategory(set.getString("name"), set.getInt(DatabaseConstants.USER_ID), set.getInt("id")));
} }
} }
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.users; package com.eu.habbo.habbohotel.users;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.achievements.Achievement; import com.eu.habbo.habbohotel.achievements.Achievement;
import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.bots.Bot;
@ -21,6 +22,7 @@ import com.eu.habbo.messages.outgoing.users.FigureUpdateComposer;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.math3.util.Pair; import org.apache.commons.math3.util.Pair;
@ -70,6 +72,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers {
private int rotation; private int rotation;
@Setter @Setter
@Getter @Getter
@Accessors(chain = true)
private String extradata; private String extradata;
@Getter @Getter
private int limitedStack; private int limitedStack;
@ -81,7 +84,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers {
public HabboItem(ResultSet set, Item baseItem) throws SQLException { public HabboItem(ResultSet set, Item baseItem) throws SQLException {
this.id = set.getInt("id"); this.id = set.getInt("id");
this.userId = set.getInt("user_id"); this.userId = set.getInt(DatabaseConstants.USER_ID);
this.roomId = set.getInt("room_id"); this.roomId = set.getInt("room_id");
this.baseItem = baseItem; this.baseItem = baseItem;
this.wallPosition = set.getString("wall_pos"); this.wallPosition = set.getString("wall_pos");
@ -236,10 +239,8 @@ public abstract class HabboItem implements Runnable, IEventTriggers {
@Override @Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception { public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
if (client != null && this.getBaseItem().getType() == FurnitureType.FLOOR) { if (client != null && this.getBaseItem().getType() == FurnitureType.FLOOR) {
if (objects != null && objects.length >= 2) { if (objects != null && objects.length >= 2 && objects[1] instanceof WiredEffectType) {
if (objects[1] instanceof WiredEffectType) { return;
return;
}
} }
if ((this.getBaseItem().getStateCount() > 1 && !(this instanceof InteractionDice)) || Arrays.asList(HabboItem.TOGGLING_INTERACTIONS).contains(this.getClass()) || (objects != null && objects.length == 1 && objects[0].equals("TOGGLE_OVERRIDE"))) { if ((this.getBaseItem().getStateCount() > 1 && !(this instanceof InteractionDice)) || Arrays.asList(HabboItem.TOGGLING_INTERACTIONS).contains(this.getClass()) || (objects != null && objects.length == 1 && objects[0].equals("TOGGLE_OVERRIDE"))) {
@ -260,7 +261,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers {
room.sendComposer(new DanceMessageComposer(roomUnit).compose()); room.sendComposer(new DanceMessageComposer(roomUnit).compose());
} }
if (!this.getBaseItem().getClothingOnWalk().isEmpty() && roomUnit.getPreviousLocation() != roomUnit.getGoal() && roomUnit.getGoal() == room.getLayout().getTile(this.x, this.y)) { if (!this.getBaseItem().getClothingOnWalk().isEmpty() && roomUnit.getPreviousLocation() != roomUnit.getGoalLocation() && roomUnit.getGoalLocation() == room.getLayout().getTile(this.x, this.y)) {
Habbo habbo = room.getHabbo(roomUnit); Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null && habbo.getClient() != null) { if (habbo != null && habbo.getClient() != null) {
@ -387,45 +388,46 @@ public abstract class HabboItem implements Runnable, IEventTriggers {
oldHabbos.removeAll(newHabbos); oldHabbos.removeAll(newHabbos);
oldBots.removeAll(newBots); oldBots.removeAll(newBots);
for (Habbo habbo : oldHabbos) { int finalNextEffectM = nextEffectM;
int finalNextEffectF = nextEffectF;
oldHabbos.forEach(habbo -> {
if (this.getBaseItem().getEffectM() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.M) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) { if (this.getBaseItem().getEffectM() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.M) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) {
room.giveEffect(habbo, nextEffectM, -1); room.giveEffect(habbo, finalNextEffectM, -1);
} }
if (this.getBaseItem().getEffectF() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.F) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) { if (this.getBaseItem().getEffectF() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.F) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) {
room.giveEffect(habbo, nextEffectF, -1); room.giveEffect(habbo, finalNextEffectF, -1);
} }
} });
for (Habbo habbo : newHabbos) { newHabbos.forEach(habbo -> {
if (this.getBaseItem().getEffectM() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.M) && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) { if (this.getBaseItem().getEffectM() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.M) && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) {
room.giveEffect(habbo, this.getBaseItem().getEffectM(), -1); room.giveEffect(habbo, this.getBaseItem().getEffectM(), -1);
} }
if (this.getBaseItem().getEffectF() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.F) && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) { if (this.getBaseItem().getEffectF() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.F) && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) {
room.giveEffect(habbo, this.getBaseItem().getEffectF(), -1); room.giveEffect(habbo, this.getBaseItem().getEffectF(), -1);
} }
} });
for (Bot bot : oldBots) {
oldBots.forEach(bot -> {
if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) { if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) {
room.giveEffect(bot.getRoomUnit(), nextEffectM, -1); room.giveEffect(bot.getRoomUnit(), finalNextEffectM, -1);
} }
if (this.getBaseItem().getEffectF() > 0 && bot.getGender().equals(HabboGender.F) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) { if (this.getBaseItem().getEffectF() > 0 && bot.getGender().equals(HabboGender.F) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) {
room.giveEffect(bot.getRoomUnit(), nextEffectF, -1); room.giveEffect(bot.getRoomUnit(), finalNextEffectF, -1);
} }
} });
for (Bot bot : newBots) { newBots.forEach(bot -> {
if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) { if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) {
room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectM(), -1); room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectM(), -1);
} }
if (this.getBaseItem().getEffectF() > 0 && bot.getGender().equals(HabboGender.F) && bot.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) { if (this.getBaseItem().getEffectF() > 0 && bot.getGender().equals(HabboGender.F) && bot.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) {
room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectF(), -1); room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectF(), -1);
} }
} });
} }
} }

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.users; package com.eu.habbo.habbohotel.users;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.navigation.DisplayMode; import com.eu.habbo.habbohotel.navigation.DisplayMode;
import com.eu.habbo.habbohotel.navigation.ListMode; import com.eu.habbo.habbohotel.navigation.ListMode;
import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.THashMap;
@ -32,7 +33,7 @@ public class HabboNavigatorWindowSettings {
} }
public HabboNavigatorWindowSettings(ResultSet set) throws SQLException { public HabboNavigatorWindowSettings(ResultSet set) throws SQLException {
this.userId = set.getInt("user_id"); this.userId = set.getInt(DatabaseConstants.USER_ID);
this.x = set.getInt("x"); this.x = set.getInt("x");
this.y = set.getInt("y"); this.y = set.getInt("y");
this.width = set.getInt("width"); this.width = set.getInt("width");

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.users.cache; package com.eu.habbo.habbohotel.users.cache;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -12,6 +13,7 @@ import java.sql.SQLException;
@Slf4j @Slf4j
public class HabboOfferPurchase { public class HabboOfferPurchase {
@Getter
private final int userId; private final int userId;
@Getter @Getter
private final int offerId; private final int offerId;
@ -24,7 +26,7 @@ public class HabboOfferPurchase {
private boolean needsUpdate = false; private boolean needsUpdate = false;
public HabboOfferPurchase(ResultSet set) throws SQLException { public HabboOfferPurchase(ResultSet set) throws SQLException {
this.userId = set.getInt("user_id"); this.userId = set.getInt(DatabaseConstants.USER_ID);
this.offerId = set.getInt("offer_id"); this.offerId = set.getInt("offer_id");
this.state = set.getInt("state"); this.state = set.getInt("state");
this.amount = set.getInt("amount"); this.amount = set.getInt("amount");

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.users.inventory; package com.eu.habbo.habbohotel.users.inventory;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.outgoing.inventory.AvatarEffectActivatedMessageComposer; import com.eu.habbo.messages.outgoing.inventory.AvatarEffectActivatedMessageComposer;
import com.eu.habbo.messages.outgoing.inventory.AvatarEffectAddedMessageComposer; import com.eu.habbo.messages.outgoing.inventory.AvatarEffectAddedMessageComposer;
@ -15,6 +16,8 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION;
@Slf4j @Slf4j
@Getter @Getter
public class EffectsComponent { public class EffectsComponent {
@ -34,7 +37,7 @@ public class EffectsComponent {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
if(habbo.getHabboInfo().getRank().getRoomEffect() > 0) if(habbo.getHabboInfo().getRank().getRoomEffect() > 0)
this.createRankEffect(habbo.getHabboInfo().getRank().getRoomEffect()); this.createRankEffect(habbo.getHabboInfo().getRank().getRoomEffect());
@ -50,12 +53,12 @@ public class EffectsComponent {
if (this.effects.containsKey(effectId)) { if (this.effects.containsKey(effectId)) {
effect = this.effects.get(effectId); effect = this.effects.get(effectId);
if (effect.total <= 99) { if (effect.getTotal() <= 99) {
effect.total++; effect.setTotal(effect.getTotal() + 1);
} }
} else { } else {
effect = new HabboEffect(effectId, this.habbo.getHabboInfo().getId()); effect = new HabboEffect(effectId, this.habbo.getHabboInfo().getId());
effect.duration = duration; effect.setDuration(duration);
effect.insert(); effect.insert();
} }
@ -67,17 +70,17 @@ public class EffectsComponent {
public HabboEffect createRankEffect(int effectId) { public HabboEffect createRankEffect(int effectId) {
HabboEffect rankEffect = new HabboEffect(effectId, habbo.getHabboInfo().getId()); HabboEffect rankEffect = new HabboEffect(effectId, habbo.getHabboInfo().getId());
rankEffect.duration = 0; rankEffect.setDuration(0);
rankEffect.isRankEnable = true; rankEffect.setRankEnable(true);
rankEffect.activationTimestamp = Emulator.getIntUnixTimestamp(); rankEffect.setActivationTimestamp(Emulator.getIntUnixTimestamp());
rankEffect.enabled = true; rankEffect.setEnabled(true);
this.effects.put(effectId, rankEffect); this.effects.put(effectId, rankEffect);
this.activatedEffect = effectId; // enabled by default this.activatedEffect = effectId; // enabled by default
return rankEffect; return rankEffect;
} }
public void addEffect(HabboEffect effect) { public void addEffect(HabboEffect effect) {
this.effects.put(effect.effect, effect); this.effects.put(effect.getEffect(), effect);
this.habbo.getClient().sendResponse(new AvatarEffectAddedMessageComposer(effect)); this.habbo.getClient().sendResponse(new AvatarEffectAddedMessageComposer(effect));
} }
@ -86,16 +89,16 @@ public class EffectsComponent {
synchronized (this.effects) { synchronized (this.effects) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_effects SET duration = ?, activation_timestamp = ?, total = ? WHERE user_id = ? AND effect = ?")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_effects SET duration = ?, activation_timestamp = ?, total = ? WHERE user_id = ? AND effect = ?")) {
this.effects.forEachValue(effect -> { this.effects.forEachValue(effect -> {
if(!effect.isRankEnable) { if(!effect.isRankEnable()) {
try { try {
statement.setInt(1, effect.duration); statement.setInt(1, effect.getDuration());
statement.setInt(2, effect.activationTimestamp); statement.setInt(2, effect.getActivationTimestamp());
statement.setInt(3, effect.total); statement.setInt(3, effect.getTotal());
statement.setInt(4, effect.userId); statement.setInt(4, effect.getUserId());
statement.setInt(5, effect.effect); statement.setInt(5, effect.getEffect());
statement.addBatch(); statement.addBatch();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
return true; return true;
@ -103,7 +106,7 @@ public class EffectsComponent {
statement.executeBatch(); statement.executeBatch();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
this.effects.clear(); this.effects.clear();
@ -119,7 +122,7 @@ public class EffectsComponent {
if (effect != null) { if (effect != null) {
if (effect.isRemaining()) { if (effect.isRemaining()) {
effect.activationTimestamp = Emulator.getIntUnixTimestamp(); effect.setActivationTimestamp(Emulator.getIntUnixTimestamp());
} else { } else {
this.habbo.getClient().sendResponse(new AvatarEffectExpiredMessageComposer(effect)); this.habbo.getClient().sendResponse(new AvatarEffectExpiredMessageComposer(effect));
} }
@ -131,7 +134,7 @@ public class EffectsComponent {
if (effect != null) { if (effect != null) {
if (!effect.isActivated()) { if (!effect.isActivated()) {
this.activateEffect(effect.effect); this.activateEffect(effect.getEffect());
} }
this.activatedEffect = effectId; this.activatedEffect = effectId;
@ -154,75 +157,75 @@ public class EffectsComponent {
return false; return false;
} }
@Getter
@Setter
public static class HabboEffect { public static class HabboEffect {
public int effect; private int effect;
public int userId; private int userId;
public int duration = 86400; private int duration = 86400;
public int activationTimestamp = -1; private int activationTimestamp = -1;
public int total = 1; private int total = 1;
public boolean enabled = false; private boolean enabled = false;
public boolean isRankEnable = false; private boolean isRankEnable = false;
public HabboEffect(ResultSet set) throws SQLException { public HabboEffect(ResultSet set) throws SQLException {
this.effect = set.getInt("effect"); this.setEffect(set.getInt("effect"));
this.userId = set.getInt("user_id"); this.setUserId(set.getInt(DatabaseConstants.USER_ID));
this.duration = set.getInt("duration"); this.setDuration(set.getInt("duration"));
this.activationTimestamp = set.getInt("activation_timestamp"); this.setActivationTimestamp(set.getInt("activation_timestamp"));
this.total = set.getInt("total"); this.setTotal(set.getInt("total"));
} }
public HabboEffect(int effect, int userId) { public HabboEffect(int effect, int userId) {
this.effect = effect; this.setEffect(effect);
this.userId = userId; this.setUserId(userId);
} }
public boolean isActivated() { public boolean isActivated() {
return this.activationTimestamp >= 0; return this.getActivationTimestamp() >= 0;
} }
public boolean isRemaining() { public boolean isRemaining() {
if(this.duration <= 0) if(this.getDuration() <= 0)
return true; return true;
if (this.total > 0) { if (this.getTotal() > 0 && this.getActivationTimestamp() >= 0
if (this.activationTimestamp >= 0) { && Emulator.getIntUnixTimestamp() - this.getActivationTimestamp() >= this.getDuration()) {
if (Emulator.getIntUnixTimestamp() - this.activationTimestamp >= this.duration) { this.setActivationTimestamp(-1);
this.activationTimestamp = -1; this.setTotal(this.getTotal() - 1);
this.total--;
}
}
} }
return this.total > 0; return this.getTotal() > 0;
} }
public int remainingTime() { public int remainingTime() {
if(this.duration <= 0) //permanant if(this.getDuration() <= 0) //permanant
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
return Emulator.getIntUnixTimestamp() - this.activationTimestamp + this.duration; return Emulator.getIntUnixTimestamp() - this.getActivationTimestamp() + this.getDuration();
} }
public void insert() { public void insert() {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_effects (user_id, effect, total, duration) VALUES (?, ?, ?, ?)")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_effects (user_id, effect, total, duration) VALUES (?, ?, ?, ?)")) {
statement.setInt(1, this.userId); statement.setInt(1, this.getUserId());
statement.setInt(2, this.effect); statement.setInt(2, this.getEffect());
statement.setInt(3, this.total); statement.setInt(3, this.getTotal());
statement.setInt(4, this.duration); statement.setInt(4, this.getDuration());
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
public void delete() { public void delete() {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_effects WHERE user_id = ? AND effect = ?")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_effects WHERE user_id = ? AND effect = ?")) {
statement.setInt(1, this.userId); statement.setInt(1, this.getUserId());
statement.setInt(2, this.effect); statement.setInt(2, this.getEffect());
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
} }
} }
} }

View File

@ -81,7 +81,7 @@ public class PetsComponent {
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
break; break;
} }
if (petIterator.value().needsUpdate) if (petIterator.value().isNeedsUpdate())
Emulator.getThreading().run(petIterator.value()); Emulator.getThreading().run(petIterator.value());
} }
} }

View File

@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.users.subscriptions;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.Database; import com.eu.habbo.database.Database;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.achievements.Achievement; import com.eu.habbo.habbohotel.achievements.Achievement;
import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.messenger.Messenger; import com.eu.habbo.habbohotel.messenger.Messenger;
@ -92,7 +93,7 @@ public class SubscriptionHabboClub extends Subscription {
habbo.getClient().sendResponse(new UserRightsMessageComposer(habbo)); habbo.getClient().sendResponse(new UserRightsMessageComposer(habbo));
}, (Emulator.getIntUnixTimestamp() - habbo.getHabboStats().getHcMessageLastModified())); }, (Emulator.getIntUnixTimestamp() - habbo.getHabboStats().getHcMessageLastModified()));
} else { } else {
habbo.getClient().sendResponse(new ScrSendUserInfoComposer(habbo, SubscriptionHabboClub.HABBO_CLUB, ScrSendUserInfoComposer.RESPONSE_TYPE_NORMAL)); habbo.getClient().sendResponse(new ScrSendUserInfoComposer(habbo, Subscription.HABBO_CLUB, ScrSendUserInfoComposer.RESPONSE_TYPE_NORMAL));
habbo.getClient().sendResponse(new UserRightsMessageComposer(habbo)); habbo.getClient().sendResponse(new UserRightsMessageComposer(habbo));
} }
} }
@ -111,7 +112,7 @@ public class SubscriptionHabboClub extends Subscription {
if (amount < 0) { if (amount < 0) {
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getUserId()); Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getUserId());
if (habbo != null && habbo.getClient() != null) { if (habbo != null && habbo.getClient() != null) {
habbo.getClient().sendResponse(new ScrSendUserInfoComposer(habbo, SubscriptionHabboClub.HABBO_CLUB, ScrSendUserInfoComposer.RESPONSE_TYPE_NORMAL)); habbo.getClient().sendResponse(new ScrSendUserInfoComposer(habbo, Subscription.HABBO_CLUB, ScrSendUserInfoComposer.RESPONSE_TYPE_NORMAL));
habbo.getClient().sendResponse(new UserRightsMessageComposer(habbo)); habbo.getClient().sendResponse(new UserRightsMessageComposer(habbo));
} }
} }
@ -130,7 +131,7 @@ public class SubscriptionHabboClub extends Subscription {
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getUserId()); Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getUserId());
if (habbo != null && habbo.getClient() != null) { if (habbo != null && habbo.getClient() != null) {
habbo.getClient().sendResponse(new ScrSendUserInfoComposer(habbo, SubscriptionHabboClub.HABBO_CLUB, ScrSendUserInfoComposer.RESPONSE_TYPE_NORMAL)); habbo.getClient().sendResponse(new ScrSendUserInfoComposer(habbo, Subscription.HABBO_CLUB, ScrSendUserInfoComposer.RESPONSE_TYPE_NORMAL));
habbo.getClient().sendResponse(new UserRightsMessageComposer(habbo)); habbo.getClient().sendResponse(new UserRightsMessageComposer(habbo));
} }
} }
@ -169,7 +170,7 @@ public class SubscriptionHabboClub extends Subscription {
} }
if (habbo != null && habbo.getClient() != null) { if (habbo != null && habbo.getClient() != null) {
habbo.getClient().sendResponse(new ScrSendUserInfoComposer(habbo, SubscriptionHabboClub.HABBO_CLUB, ScrSendUserInfoComposer.RESPONSE_TYPE_NORMAL)); habbo.getClient().sendResponse(new ScrSendUserInfoComposer(habbo, Subscription.HABBO_CLUB, ScrSendUserInfoComposer.RESPONSE_TYPE_NORMAL));
habbo.getClient().sendResponse(new UserRightsMessageComposer(habbo)); habbo.getClient().sendResponse(new UserRightsMessageComposer(habbo));
} }
} }
@ -265,7 +266,7 @@ public class SubscriptionHabboClub extends Subscription {
try (ResultSet set = statement.executeQuery()) { try (ResultSet set = statement.executeQuery()) {
while (set.next()) { while (set.next()) {
try { try {
int userId = set.getInt("user_id"); int userId = set.getInt(DatabaseConstants.USER_ID);
HabboInfo habboInfo = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(userId); HabboInfo habboInfo = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(userId);
HabboStats stats = habboInfo.getHabboStats(); HabboStats stats = habboInfo.getHabboStats();
ScrSendKickbackInfoMessageComposer calculated = calculatePayday(habboInfo); ScrSendKickbackInfoMessageComposer calculated = calculatePayday(habboInfo);
@ -278,7 +279,7 @@ public class SubscriptionHabboClub extends Subscription {
stats.setLastHCPayday(timestampNow); stats.setLastHCPayday(timestampNow);
Emulator.getThreading().run(stats); Emulator.getThreading().run(stats);
} catch (Exception e) { } catch (Exception e) {
log.error("Exception processing HC payday for user #" + set.getInt("user_id"), e); log.error("Exception processing HC payday for user #" + set.getInt(DatabaseConstants.USER_ID), e);
} }
} }
} }
@ -328,18 +329,18 @@ public class SubscriptionHabboClub extends Subscription {
while (set.next()) { while (set.next()) {
try { try {
int logId = set.getInt("id"); int logId = set.getInt("id");
int userId = set.getInt("user_id");
int totalPayout = set.getInt("total_payout"); int totalPayout = set.getInt("total_payout");
String currency = set.getString("currency"); String currency = set.getString("currency");
if (claimPayDay(habbo, totalPayout, currency)) { claimPayDay(habbo, totalPayout, currency);
try (PreparedStatement stm2 = connection.prepareStatement("UPDATE logs_hc_payday SET claimed = 1 WHERE id = ?")) {
stm2.setInt(1, logId); try (PreparedStatement stm2 = connection.prepareStatement("UPDATE logs_hc_payday SET claimed = 1 WHERE id = ?")) {
stm2.execute(); stm2.setInt(1, logId);
} stm2.execute();
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Exception processing HC payday for user #" + set.getInt("user_id"), e); log.error("Exception processing HC payday for user #" + set.getInt(DatabaseConstants.USER_ID), e);
} }
} }
} }
@ -350,7 +351,6 @@ public class SubscriptionHabboClub extends Subscription {
} }
/** /**
*
* Seperated these because Beny shouldn't have tied them to Payday. * Seperated these because Beny shouldn't have tied them to Payday.
*/ */
public static void processClubBadge(Habbo habbo) { public static void processClubBadge(Habbo habbo) {
@ -359,13 +359,14 @@ public class SubscriptionHabboClub extends Subscription {
/** /**
* Issues rewards to user. * Issues rewards to user.
* @param habbo User to reward to *
* @param amount Amount of currency to reward * @param habbo User to reward to
* @param amount Amount of currency to reward
* @param currency Currency string (Can be one of: credits, diamonds, duckets, pixels or a currency ID e.g. 5) * @param currency Currency string (Can be one of: credits, diamonds, duckets, pixels or a currency ID e.g. 5)
* @return Boolean indicating success of the operation * @return Boolean indicating success of the operation
*/ */
public static boolean claimPayDay(Habbo habbo, int amount, String currency) { public static boolean claimPayDay(Habbo habbo, int amount, String currency) {
if(habbo == null) if (habbo == null)
return false; return false;
int pointCurrency; int pointCurrency;
@ -409,16 +410,16 @@ public class SubscriptionHabboClub extends Subscription {
private static void progressAchievement(HabboInfo habboInfo) { private static void progressAchievement(HabboInfo habboInfo) {
HabboStats stats = habboInfo.getHabboStats(); HabboStats stats = habboInfo.getHabboStats();
Achievement achievement = Emulator.getGameEnvironment().getAchievementManager().getAchievement(ACHIEVEMENT_NAME); Achievement achievement = Emulator.getGameEnvironment().getAchievementManager().getAchievement(ACHIEVEMENT_NAME);
if(achievement != null) { if (achievement != null) {
int currentProgress = stats.getAchievementProgress(achievement); int currentProgress = stats.getAchievementProgress(achievement);
if(currentProgress == -1) { if (currentProgress == -1) {
currentProgress = 0; currentProgress = 0;
} }
int progressToSet = (int)Math.ceil(stats.getPastTimeAsClub() / 2678400.0); int progressToSet = (int) Math.ceil(stats.getPastTimeAsClub() / 2678400.0);
int toIncrease = Math.max(progressToSet - currentProgress, 0); int toIncrease = Math.max(progressToSet - currentProgress, 0);
if(toIncrease > 0) { if (toIncrease > 0) {
AchievementManager.progressAchievement(habboInfo.getId(), achievement, toIncrease); AchievementManager.progressAchievement(habboInfo.getId(), achievement, toIncrease);
} }
} }

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.users.subscriptions; package com.eu.habbo.habbohotel.users.subscriptions;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
import lombok.Getter; import lombok.Getter;
@ -67,7 +68,7 @@ public class SubscriptionManager {
Class<? extends Subscription> subClazz = Emulator.getGameEnvironment().getSubscriptionManager().getSubscriptionClass(set.getString("subscription_type")); Class<? extends Subscription> subClazz = Emulator.getGameEnvironment().getSubscriptionManager().getSubscriptionClass(set.getString("subscription_type"));
Constructor<? extends Subscription> c = subClazz.getConstructor(Integer.class, Integer.class, String.class, Integer.class, Integer.class, Boolean.class); Constructor<? extends Subscription> c = subClazz.getConstructor(Integer.class, Integer.class, String.class, Integer.class, Integer.class, Boolean.class);
c.setAccessible(true); c.setAccessible(true);
Subscription subscription = c.newInstance(set.getInt("id"), set.getInt("user_id"), set.getString("subscription_type"), set.getInt("timestamp_start"), set.getInt("duration"), set.getInt("active") == 1); Subscription subscription = c.newInstance(set.getInt("id"), set.getInt(DatabaseConstants.USER_ID), set.getString("subscription_type"), set.getInt("timestamp_start"), set.getInt("duration"), set.getInt("active") == 1);
subscriptions.add(subscription); subscriptions.add(subscription);
} }
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {

View File

@ -10,6 +10,7 @@ import com.eu.habbo.plugin.events.navigator.NavigatorSearchResultEvent;
import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.THashMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class RoomTextSearchEvent extends MessageHandler { public class RoomTextSearchEvent extends MessageHandler {
public final static THashMap<Rank, THashMap<String, ServerMessage>> cachedResults = new THashMap<>(4); public final static THashMap<Rank, THashMap<String, ServerMessage>> cachedResults = new THashMap<>(4);
@ -20,7 +21,7 @@ public class RoomTextSearchEvent extends MessageHandler {
String prefix = ""; String prefix = "";
String query = name; String query = name;
ArrayList<Room> rooms; List<Room> rooms;
ServerMessage message = null; ServerMessage message = null;
if (cachedResults.containsKey(this.client.getHabbo().getHabboInfo().getRank())) { if (cachedResults.containsKey(this.client.getHabbo().getHabboInfo().getRank())) {
@ -33,7 +34,7 @@ public class RoomTextSearchEvent extends MessageHandler {
if (name.startsWith("owner:")) { if (name.startsWith("owner:")) {
query = name.split("owner:")[1]; query = name.split("owner:")[1];
prefix = "owner:"; prefix = "owner:";
rooms = (ArrayList<Room>) Emulator.getGameEnvironment().getRoomManager().getRoomsForHabbo(name); rooms = Emulator.getGameEnvironment().getRoomManager().getRoomsForHabbo(name);
} else if (name.startsWith("tag:")) { } else if (name.startsWith("tag:")) {
query = name.split("tag:")[1]; query = name.split("tag:")[1];
prefix = "tag:"; prefix = "tag:";

View File

@ -22,8 +22,8 @@ public class OpenFlatConnectionEvent extends MessageHandler {
this.client.getHabbo().getHabboInfo().setCurrentRoom(null); this.client.getHabbo().getHabboInfo().setCurrentRoom(null);
} }
if (this.client.getHabbo().getRoomUnit() != null && this.client.getHabbo().getRoomUnit().isTeleporting) { if (this.client.getHabbo().getRoomUnit() != null && this.client.getHabbo().getRoomUnit().isTeleporting()) {
this.client.getHabbo().getRoomUnit().isTeleporting = false; this.client.getHabbo().getRoomUnit().setTeleporting(false);
} }
Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), roomId, password); Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), roomId, password);

View File

@ -17,7 +17,7 @@ public class EnterOneWayDoorEvent extends MessageHandler {
return; return;
if (item instanceof InteractionOneWayGate) { if (item instanceof InteractionOneWayGate) {
if (!item.getExtradata().equals("0") || this.client.getHabbo().getRoomUnit().isTeleporting) if (!item.getExtradata().equals("0") || this.client.getHabbo().getRoomUnit().isTeleporting())
return; return;
item.onClick(this.client, this.client.getHabbo().getHabboInfo().getCurrentRoom(), null); item.onClick(this.client, this.client.getHabbo().getHabboInfo().getCurrentRoom(), null);

View File

@ -16,9 +16,12 @@ import com.eu.habbo.plugin.events.furniture.FurnitureToggleEvent;
import com.eu.habbo.threading.runnables.QueryDeleteHabboItem; import com.eu.habbo.threading.runnables.QueryDeleteHabboItem;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.List;
@Slf4j @Slf4j
public class UseFurnitureEvent extends MessageHandler { public class UseFurnitureEvent extends MessageHandler {
private static final List<String> PET_PRESENTS = List.of("val11_present", "gnome_box", "leprechaun_box", "velociraptor_egg", "pterosaur_egg", "petbox_epic");
@Override @Override
public void handle() { public void handle() {
@ -42,86 +45,11 @@ public class UseFurnitureEvent extends MessageHandler {
if (furnitureToggleEvent.isCancelled()) if (furnitureToggleEvent.isCancelled())
return; return;
/*
if (item.getBaseItem().getName().equalsIgnoreCase("totem_planet")) {
THashSet<HabboItem> items = room.getItemsAt(room.getLayout().getTile(item.getX(), item.getY()));
HabboItem totemLeg = null;
HabboItem totemHead = null;
for (HabboItem totemItem : items) {
if (totemLeg != null && totemHead != null) {
break;
}
if (totemItem.getBaseItem().getName().equalsIgnoreCase("totem_leg")) {
totemLeg = totemItem;
}
if (totemItem.getBaseItem().getName().equalsIgnoreCase("totem_head")) {
totemHead = totemItem;
}
}
if (totemHead != null && totemLeg != null) {
if (item.getExtradata().equals("2")) {
if (totemLeg.getExtradata() == null || totemHead.getExtradata() == null)
return;
if (totemLeg.getExtradata().equals("2") && totemHead.getExtradata().equals("5")) {
room.giveEffect(this.client.getHabbo(), 23, -1);
return;
}
if (totemLeg.getExtradata().equals("10") && totemHead.getExtradata().equals("9")) {
room.giveEffect(this.client.getHabbo(), 26, -1);
return;
}
} else if (item.getExtradata().equals("0")) {
if (totemLeg.getExtradata().equals("7") && totemHead.getExtradata().equals("10")) {
room.giveEffect(this.client.getHabbo(), 24, -1);
return;
}
} else if (item.getExtradata().equals("1")) {
if (totemLeg.getExtradata().equals("9") && totemHead.getExtradata().equals("12")) {
room.giveEffect(this.client.getHabbo(), 25, -1);
return;
}
}
}
}*/
//Do not move to onClick(). Wired could trigger it. //Do not move to onClick(). Wired could trigger it.
if (item instanceof InteractionMonsterPlantSeed) { if (handleMonsterPlantSeed(room, item)) return;
Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId()));
int rarity = 0;
boolean isRare = item.getBaseItem().getName().contains("rare");
if (item.getExtradata().isEmpty() || Integer.parseInt(item.getExtradata()) - 1 < 0) { if (PET_PRESENTS.contains(item.getBaseItem().getName().toLowerCase()) && room.getCurrentPets().size() < Room.MAXIMUM_PETS) {
rarity = isRare ? InteractionMonsterPlantSeed.randomGoldenRarityLevel() : InteractionMonsterPlantSeed.randomRarityLevel();
}
else {
try {
rarity = Integer.parseInt(item.getExtradata()) - 1;
} catch (Exception ignored) {
}
}
MonsterplantPet pet = Emulator.getGameEnvironment().getPetManager().createMonsterplant(room, this.client.getHabbo(), isRare, room.getLayout().getTile(item.getX(), item.getY()), rarity);
room.sendComposer(new RemoveFloorItemComposer(item, true).compose());
room.removeHabboItem(item);
room.updateTile(room.getLayout().getTile(item.getX(), item.getY()));
room.placePet(pet, item.getX(), item.getY(), item.getZ(), item.getRotation());
pet.cycle();
room.sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose());
return;
}
if (
(item.getBaseItem().getName().equalsIgnoreCase("val11_present") ||
item.getBaseItem().getName().equalsIgnoreCase("gnome_box") ||
item.getBaseItem().getName().equalsIgnoreCase("leprechaun_box") ||
item.getBaseItem().getName().equalsIgnoreCase("velociraptor_egg") ||
item.getBaseItem().getName().equalsIgnoreCase("pterosaur_egg") ||
item.getBaseItem().getName().equalsIgnoreCase("petbox_epic")) && room.getCurrentPets().size() < Room.MAXIMUM_PETS) {
this.client.sendResponse(new OpenPetPackageRequestedMessageComposer(item)); this.client.sendResponse(new OpenPetPackageRequestedMessageComposer(item));
return; return;
} }
@ -135,4 +63,35 @@ public class UseFurnitureEvent extends MessageHandler {
log.error("Caught exception", e); log.error("Caught exception", e);
} }
} }
private boolean handleMonsterPlantSeed(Room room, HabboItem item) {
if (item instanceof InteractionMonsterPlantSeed) {
Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId()));
boolean isRare = item.getBaseItem().getName().contains("rare");
int rarity = getRarity(item, isRare);
MonsterplantPet pet = Emulator.getGameEnvironment().getPetManager().createMonsterplant(room, this.client.getHabbo(), isRare, room.getLayout().getTile(item.getX(), item.getY()), rarity);
room.sendComposer(new RemoveFloorItemComposer(item, true).compose());
room.removeHabboItem(item);
room.updateTile(room.getLayout().getTile(item.getX(), item.getY()));
room.placePet(pet, item.getX(), item.getY(), item.getZ());
pet.cycle();
room.sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose());
return true;
}
return false;
}
private int getRarity(HabboItem item, boolean isRare) {
if (item.getExtradata().isEmpty() || Integer.parseInt(item.getExtradata()) - 1 < 0) {
return isRare ? InteractionMonsterPlantSeed.randomGoldenRarityLevel() : InteractionMonsterPlantSeed.randomRarityLevel();
} else {
try {
return Integer.parseInt(item.getExtradata()) - 1;
} catch (Exception ignored) {
return 0;
}
}
}
} }

View File

@ -44,7 +44,7 @@ public class CustomizePetWithFurniEvent extends MessageHandler {
raceType = 0; raceType = 0;
pet.setRace(raceType); pet.setRace(raceType);
pet.needsUpdate = true; pet.setNeedsUpdate(true);
} else if (item.getBaseItem().getName().toLowerCase().startsWith("horse_hairdye")) { } else if (item.getBaseItem().getName().toLowerCase().startsWith("horse_hairdye")) {
int splittedHairdye = Integer.parseInt(item.getBaseItem().getName().toLowerCase().split("_")[2]); int splittedHairdye = Integer.parseInt(item.getBaseItem().getName().toLowerCase().split("_")[2]);
int newHairdye = 48; int newHairdye = 48;
@ -60,7 +60,7 @@ public class CustomizePetWithFurniEvent extends MessageHandler {
} }
((HorsePet) pet).setHairColor(newHairdye); ((HorsePet) pet).setHairColor(newHairdye);
pet.needsUpdate = true; pet.setNeedsUpdate(true);
} else if (item.getBaseItem().getName().toLowerCase().startsWith("horse_hairstyle")) { } else if (item.getBaseItem().getName().toLowerCase().startsWith("horse_hairstyle")) {
int splittedHairstyle = Integer.parseInt(item.getBaseItem().getName().toLowerCase().split("_")[2]); int splittedHairstyle = Integer.parseInt(item.getBaseItem().getName().toLowerCase().split("_")[2]);
int newHairstyle = 100; int newHairstyle = 100;
@ -72,14 +72,14 @@ public class CustomizePetWithFurniEvent extends MessageHandler {
} }
((HorsePet) pet).setHairStyle(newHairstyle); ((HorsePet) pet).setHairStyle(newHairstyle);
pet.needsUpdate = true; pet.setNeedsUpdate(true);
} else if (item.getBaseItem().getName().toLowerCase().startsWith("horse_saddle")) { } else if (item.getBaseItem().getName().toLowerCase().startsWith("horse_saddle")) {
((HorsePet) pet).hasSaddle(true); ((HorsePet) pet).hasSaddle(true);
((HorsePet) pet).setSaddleItemId(item.getBaseItem().getId()); ((HorsePet) pet).setSaddleItemId(item.getBaseItem().getId());
pet.needsUpdate = true; pet.setNeedsUpdate(true);
} }
if (pet.needsUpdate) { if (pet.isNeedsUpdate()) {
Emulator.getThreading().run(pet); Emulator.getThreading().run(pet);
this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetFigureUpdateComposer((HorsePet) pet).compose()); this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetFigureUpdateComposer((HorsePet) pet).compose());
@ -91,10 +91,10 @@ public class CustomizePetWithFurniEvent extends MessageHandler {
} else if (pet instanceof MonsterplantPet) { } else if (pet instanceof MonsterplantPet) {
if (item.getBaseItem().getName().equalsIgnoreCase("mnstr_revival")) { if (item.getBaseItem().getName().equalsIgnoreCase("mnstr_revival")) {
if (((MonsterplantPet) pet).isDead()) { if (((MonsterplantPet) pet).isDead()) {
((MonsterplantPet) pet).setDeathTimestamp(Emulator.getIntUnixTimestamp() + MonsterplantPet.timeToLive); ((MonsterplantPet) pet).setDeathTimestamp(Emulator.getIntUnixTimestamp() + MonsterplantPet.TIME_TO_LIVE);
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, "rev"); pet.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, "rev");
pet.packetUpdate = true; pet.setPacketUpdate(true);
this.client.getHabbo().getHabboInfo().getCurrentRoom().removeHabboItem(item); this.client.getHabbo().getHabboInfo().getCurrentRoom().removeHabboItem(item);
this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RemoveFloorItemComposer(item).compose()); this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RemoveFloorItemComposer(item).compose());
@ -107,7 +107,7 @@ public class CustomizePetWithFurniEvent extends MessageHandler {
} }
} else if (item.getBaseItem().getName().equalsIgnoreCase("mnstr_fert")) { } else if (item.getBaseItem().getName().equalsIgnoreCase("mnstr_fert")) {
if (!((MonsterplantPet) pet).isFullyGrown()) { if (!((MonsterplantPet) pet).isFullyGrown()) {
pet.setCreated(pet.getCreated() - MonsterplantPet.growTime); pet.setCreated(pet.getCreated() - MonsterplantPet.GROW_TIME);
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.cycle(); pet.cycle();
pet.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, "spd"); pet.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, "spd");

View File

@ -28,7 +28,7 @@ public class MovePetEvent extends MessageHandler {
pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.packet.readInt())); pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.packet.readInt()));
pet.getRoomUnit().setPreviousLocationZ(pet.getRoomUnit().getZ()); pet.getRoomUnit().setPreviousLocationZ(pet.getRoomUnit().getZ());
room.sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); room.sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose());
pet.needsUpdate = true; pet.setNeedsUpdate(true);
} }
} }
} }

View File

@ -22,55 +22,53 @@ public class OpenPetPackageEvent extends MessageHandler {
if (room != null) { if (room != null) {
HabboItem item = room.getHabboItem(itemId); HabboItem item = room.getHabboItem(itemId);
if (item != null) { if (item != null && item.getUserId() == this.client.getHabbo().getHabboInfo().getId()) {
if (item.getUserId() == this.client.getHabbo().getHabboInfo().getId()) { if (!name.matches("^[a-zA-Z0-9]*$")) {
if (name.matches("^[a-zA-Z0-9]*$")) { this.client.sendResponse(new PerkAllowancesComposer(itemId, PerkAllowancesComposer.CONTAINS_INVALID_CHARS, name.replaceAll("^[a-zA-Z0-9]*$", "")));
Pet pet = null; return;
}
if (item.getBaseItem().getName().equalsIgnoreCase("val11_present")) { Pet pet = null;
pet = Emulator.getGameEnvironment().getPetManager().createPet(11, name, this.client);
}
if (item.getBaseItem().getName().equalsIgnoreCase("gnome_box")) { if (item.getBaseItem().getName().equalsIgnoreCase("val11_present")) {
pet = Emulator.getGameEnvironment().getPetManager().createGnome(name, room, this.client.getHabbo()); pet = Emulator.getGameEnvironment().getPetManager().createPet(11, name, this.client);
} }
if (item.getBaseItem().getName().equalsIgnoreCase("leprechaun_box")) { if (item.getBaseItem().getName().equalsIgnoreCase("gnome_box")) {
pet = Emulator.getGameEnvironment().getPetManager().createLeprechaun(name, room, this.client.getHabbo()); pet = Emulator.getGameEnvironment().getPetManager().createGnome(name, room, this.client.getHabbo());
} }
if (item.getBaseItem().getName().equalsIgnoreCase("velociraptor_egg")) { if (item.getBaseItem().getName().equalsIgnoreCase("leprechaun_box")) {
pet = Emulator.getGameEnvironment().getPetManager().createPet(34, name, this.client); pet = Emulator.getGameEnvironment().getPetManager().createLeprechaun(name, room, this.client.getHabbo());
} }
if (item.getBaseItem().getName().equalsIgnoreCase("pterosaur_egg")) { if (item.getBaseItem().getName().equalsIgnoreCase("velociraptor_egg")) {
pet = Emulator.getGameEnvironment().getPetManager().createPet(33, name, this.client); pet = Emulator.getGameEnvironment().getPetManager().createPet(34, name, this.client);
} }
if (item.getBaseItem().getName().equalsIgnoreCase("petbox_epic")) { if (item.getBaseItem().getName().equalsIgnoreCase("pterosaur_egg")) {
pet = Emulator.getGameEnvironment().getPetManager().createPet(32, name, this.client); pet = Emulator.getGameEnvironment().getPetManager().createPet(33, name, this.client);
} }
if (pet != null) { if (item.getBaseItem().getName().equalsIgnoreCase("petbox_epic")) {
room.placePet(pet, item.getX(), item.getY(), item.getZ(), item.getRotation()); pet = Emulator.getGameEnvironment().getPetManager().createPet(32, name, this.client);
pet.setUserId(this.client.getHabbo().getHabboInfo().getId()); }
pet.needsUpdate = true;
pet.getRoomUnit().setLocation(room.getLayout().getTile(item.getX(), item.getY())); if (pet != null) {
pet.getRoomUnit().setZ(item.getZ()); room.placePet(pet, item.getX(), item.getY(), item.getZ());
Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); pet.setUserId(this.client.getHabbo().getHabboInfo().getId());
room.removeHabboItem(item); pet.setNeedsUpdate(true);
room.sendComposer(new RemoveFloorItemComposer(item).compose()); pet.getRoomUnit().setLocation(room.getLayout().getTile(item.getX(), item.getY()));
RoomTile tile = room.getLayout().getTile(item.getX(), item.getY()); pet.getRoomUnit().setZ(item.getZ());
room.updateTile(room.getLayout().getTile(item.getX(), item.getY())); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId()));
room.sendComposer(new HeightMapUpdateMessageComposer(tile.getX(), tile.getY(), tile.getZ(), tile.relativeHeight()).compose()); room.removeHabboItem(item);
item.setUserId(0); room.sendComposer(new RemoveFloorItemComposer(item).compose());
} else { RoomTile tile = room.getLayout().getTile(item.getX(), item.getY());
this.client.sendResponse(new PurchaseErrorMessageComposer(PurchaseErrorMessageComposer.SERVER_ERROR)); room.updateTile(room.getLayout().getTile(item.getX(), item.getY()));
} room.sendComposer(new HeightMapUpdateMessageComposer(tile.getX(), tile.getY(), tile.getZ(), tile.relativeHeight()).compose());
} else { item.setUserId(0);
this.client.sendResponse(new PerkAllowancesComposer(itemId, PerkAllowancesComposer.CONTAINS_INVALID_CHARS, name.replaceAll("^[a-zA-Z0-9]*$", ""))); } else {
return; this.client.sendResponse(new PurchaseErrorMessageComposer(PurchaseErrorMessageComposer.SERVER_ERROR));
}
} }
} }
} }

View File

@ -84,7 +84,7 @@ public class PlacePetEvent extends MessageHandler {
} }
pet.setRoomUnit(roomUnit); pet.setRoomUnit(roomUnit);
room.addPet(pet); room.addPet(pet);
pet.needsUpdate = true; pet.setNeedsUpdate(true);
Emulator.getThreading().run(pet); Emulator.getThreading().run(pet);
room.sendComposer(new RoomPetComposer(pet).compose()); room.sendComposer(new RoomPetComposer(pet).compose());
this.client.getHabbo().getInventory().getPetsComponent().removePet(pet); this.client.getHabbo().getInventory().getPetsComponent().removePet(pet);

View File

@ -52,7 +52,7 @@ public class RemoveSaddleFromPetEvent extends MessageHandler {
if (saddleItem == null) return; if (saddleItem == null) return;
horse.hasSaddle(false); horse.hasSaddle(false);
horse.needsUpdate = true; horse.setNeedsUpdate(true);
Emulator.getThreading().run(pet); Emulator.getThreading().run(pet);
this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetFigureUpdateComposer(horse).compose()); this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetFigureUpdateComposer(horse).compose());

View File

@ -20,7 +20,7 @@ public class TogglePetRidingPermissionEvent extends MessageHandler {
return; return;
rideablePet.setAnyoneCanRide(!rideablePet.anyoneCanRide()); rideablePet.setAnyoneCanRide(!rideablePet.anyoneCanRide());
rideablePet.needsUpdate = true; rideablePet.setNeedsUpdate(true);
if (!rideablePet.anyoneCanRide() && rideablePet.getRider() != null && rideablePet.getRider().getHabboInfo().getId() != this.client.getHabbo().getHabboInfo().getId()) { if (!rideablePet.anyoneCanRide() && rideablePet.getRider() != null && rideablePet.getRider().getHabboInfo().getId() != this.client.getHabbo().getHabboInfo().getId()) {
rideablePet.getRider().getHabboInfo().dismountPet(); rideablePet.getRider().getHabboInfo().dismountPet();

View File

@ -34,7 +34,7 @@ public class LookToEvent extends MessageHandler {
if (roomUnit.isWalking() || roomUnit.hasStatus(RoomUnitStatus.MOVE)) if (roomUnit.isWalking() || roomUnit.hasStatus(RoomUnitStatus.MOVE))
return; return;
if (roomUnit.cmdLay || roomUnit.hasStatus(RoomUnitStatus.LAY)) if (roomUnit.isCmdLay() || roomUnit.hasStatus(RoomUnitStatus.LAY))
return; return;
if (roomUnit.isIdle()) if (roomUnit.isIdle())

View File

@ -36,11 +36,11 @@ public class MoveAvatarEvent extends MessageHandler {
RoomUnit roomUnit = this.client.getHabbo().getRoomUnit(); RoomUnit roomUnit = this.client.getHabbo().getRoomUnit();
// If habbo is teleporting, dont calculate a new path // If habbo is teleporting, dont calculate a new path
if (roomUnit.isTeleporting) if (roomUnit.isTeleporting())
return; return;
// If habbo is being kicked dont calculate a new path // If habbo is being kicked dont calculate a new path
if (roomUnit.isKicked) if (roomUnit.isKicked())
return; return;
// If habbo has control (im assuming admin, do something else, but we dont care about this part here) // If habbo has control (im assuming admin, do something else, but we dont care about this part here)
@ -60,101 +60,94 @@ public class MoveAvatarEvent extends MessageHandler {
// Get the room the habbo is in // Get the room the habbo is in
Room room = habbo.getHabboInfo().getCurrentRoom(); Room room = habbo.getHabboInfo().getCurrentRoom();
try { // If our room unit is not nullptr and we are in a room and we can walk, then calculate a new path
// If our room unit is not nullptr and we are in a room and we can walk, then calculate a new path if (roomUnit != null && roomUnit.isInRoom() && roomUnit.canWalk()) {
if (roomUnit != null && roomUnit.isInRoom() && roomUnit.canWalk()) { // If we are not teleporting calcualte a new path
// If we are not teleporting calcualte a new path if (!roomUnit.isCmdTeleport()) {
if (!roomUnit.cmdTeleport) { // Don't calculate a new path if we are on a horse
// Don't calculate a new path if we are on a horse if (habbo.getHabboInfo().getRiding() != null && habbo.getHabboInfo().getRiding().getTask() != null && habbo.getHabboInfo().getRiding().getTask().equals(PetTasks.JUMP))
if (habbo.getHabboInfo().getRiding() != null && habbo.getHabboInfo().getRiding().getTask() != null && habbo.getHabboInfo().getRiding().getTask().equals(PetTasks.JUMP)) return;
return;
// Don't calulcate a new path if are already at the end position // Don't calulcate a new path if are already at the end position
if (x == roomUnit.getX() && y == roomUnit.getY()) if (x == roomUnit.getX() && y == roomUnit.getY())
return; return;
if (room == null || room.getLayout() == null) if (room == null || room.getLayout() == null)
return; return;
// Reset idle status // Reset idle status
if (roomUnit.isIdle()) { if (roomUnit.isIdle()) {
UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false); UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false);
Emulator.getPluginManager().fireEvent(event); Emulator.getPluginManager().fireEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
if (!event.isIdle()) { if (!event.isIdle()) {
if (roomUnit.getRoom() != null) roomUnit.getRoom().unIdle(habbo); if (roomUnit.getRoom() != null) roomUnit.getRoom().unIdle(habbo);
roomUnit.resetIdleTimer(); roomUnit.resetIdleTimer();
}
} }
} }
}
// Get room height map
RoomTile tile = room.getLayout().getTile((short) x, (short) y); // Get room height map
RoomTile tile = room.getLayout().getTile((short) x, (short) y);
// this should never happen, if it does it would be a design flaw
if (tile == null) { // this should never happen, if it does it would be a design flaw
return; if (tile == null) {
} return;
}
// Don't care
if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.LAY)) { // Don't care
if (room.getLayout().getTilesInFront(habbo.getRoomUnit().getCurrentLocation(), habbo.getRoomUnit().getBodyRotation().getValue(), 2).contains(tile)) if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.LAY)) {
return; if (room.getLayout().getTilesInFront(habbo.getRoomUnit().getCurrentLocation(), habbo.getRoomUnit().getBodyRotation().getValue(), 2).contains(tile))
} return;
if (room.canLayAt(tile.getX(), tile.getY())) { }
HabboItem bed = room.getTopItemAt(tile.getX(), tile.getY()); if (room.canLayAt(tile.getX(), tile.getY())) {
HabboItem bed = room.getTopItemAt(tile.getX(), tile.getY());
if (bed != null && bed.getBaseItem().allowLay()) {
room.getLayout().getTile(bed.getX(), bed.getY()); if (bed != null && bed.getBaseItem().allowLay()) {
RoomTile pillow = switch (bed.getRotation()) { room.getLayout().getTile(bed.getX(), bed.getY());
case 0, 4 -> room.getLayout().getTile((short) x, bed.getY()); RoomTile pillow = switch (bed.getRotation()) {
case 2, 8 -> room.getLayout().getTile(bed.getX(), (short) y); case 0, 4 -> room.getLayout().getTile((short) x, bed.getY());
default -> room.getLayout().getTile(bed.getX(), bed.getY()); case 2, 8 -> room.getLayout().getTile(bed.getX(), (short) y);
}; default -> room.getLayout().getTile(bed.getX(), bed.getY());
};
if (pillow != null && room.canLayAt(pillow.getX(), pillow.getY())) {
roomUnit.setGoalLocation(pillow); if (pillow != null && room.canLayAt(pillow.getX(), pillow.getY())) {
return; roomUnit.setGoalLocation(pillow);
} return;
} }
} }
}
THashSet<HabboItem> items = room.getItemsAt(tile);
THashSet<HabboItem> items = room.getItemsAt(tile);
if (items.size() > 0) {
for (HabboItem item : items) { if (items.size() > 0) {
RoomTile overriddenTile = item.getOverrideGoalTile(roomUnit, room, tile); for (HabboItem item : items) {
RoomTile overriddenTile = item.getOverrideGoalTile(roomUnit, room, tile);
if (overriddenTile == null) {
return; // null cancels the entire event if (overriddenTile == null) {
} return; // null cancels the entire event
}
if (!overriddenTile.equals(tile) && overriddenTile.isWalkable()) {
tile = overriddenTile; if (!overriddenTile.equals(tile) && overriddenTile.isWalkable()) {
break; tile = overriddenTile;
} break;
} }
} }
}
// This is where we set the end location and begin finding a path
if (tile.isWalkable() || room.canSitOrLayAt(tile.getX(), tile.getY())) { // This is where we set the end location and begin finding a path
if (roomUnit.getMoveBlockingTask() != null) roomUnit.getMoveBlockingTask().get(); if (tile.isWalkable() || room.canSitOrLayAt(tile.getX(), tile.getY())) {
roomUnit.setGoalLocation(tile);
roomUnit.setGoalLocation(tile); }
} } else {
} else { RoomTile t = room.getLayout().getTile((short) x, (short) y);
RoomTile t = room.getLayout().getTile((short) x, (short) y); room.sendComposer(new RoomUnitOnRollerComposer(roomUnit, t, room).compose());
room.sendComposer(new RoomUnitOnRollerComposer(roomUnit, t, room).compose());
if (habbo.getHabboInfo().getRiding() != null) {
if (habbo.getHabboInfo().getRiding() != null) { room.sendComposer(new RoomUnitOnRollerComposer(habbo.getHabboInfo().getRiding().getRoomUnit(), t, room).compose());
room.sendComposer(new RoomUnitOnRollerComposer(habbo.getHabboInfo().getRiding().getRoomUnit(), t, room).compose());
}
} }
} }
} catch (InterruptedException e) {
log.error("Caught exception", e);
Thread.currentThread().interrupt();
} }
} }
} }

View File

@ -16,9 +16,9 @@ public class AvatarEffectActivatedMessageComposer extends MessageComposer {
@Override @Override
protected ServerMessage composeInternal() { protected ServerMessage composeInternal() {
this.response.init(Outgoing.avatarEffectActivatedMessageComposer); this.response.init(Outgoing.avatarEffectActivatedMessageComposer);
this.response.appendInt(this.effect.effect); //Type this.response.appendInt(this.effect.getEffect()); //Type
this.response.appendInt(this.effect.duration); //Duration this.response.appendInt(this.effect.getDuration()); //Duration
this.response.appendBoolean(this.effect.enabled); //activated this.response.appendBoolean(this.effect.isEnabled()); //activated
return this.response; return this.response;
} }
} }

View File

@ -14,10 +14,10 @@ public class AvatarEffectAddedMessageComposer extends MessageComposer {
@Override @Override
protected ServerMessage composeInternal() { protected ServerMessage composeInternal() {
this.response.init(Outgoing.avatarEffectAddedMessageComposer); this.response.init(Outgoing.avatarEffectAddedMessageComposer);
this.response.appendInt(this.effect.effect); //Type this.response.appendInt(this.effect.getEffect()); //Type
this.response.appendInt(0); //Unknown Costume? this.response.appendInt(0); //Unknown Costume?
this.response.appendInt(effect.duration > 0 ? effect.duration : Integer.MAX_VALUE); //Duration this.response.appendInt(effect.getDuration() > 0 ? effect.getDuration() : Integer.MAX_VALUE); //Duration
this.response.appendBoolean(effect.duration <= 0); //Is active this.response.appendBoolean(effect.getDuration() <= 0); //Is active
return this.response; return this.response;
} }
} }

View File

@ -15,7 +15,7 @@ public class AvatarEffectExpiredMessageComposer extends MessageComposer {
@Override @Override
protected ServerMessage composeInternal() { protected ServerMessage composeInternal() {
this.response.init(Outgoing.avatarEffectExpiredMessageComposer); this.response.init(Outgoing.avatarEffectExpiredMessageComposer);
this.response.appendInt(this.effect.effect); this.response.appendInt(this.effect.getEffect());
return this.response; return this.response;
} }
} }

View File

@ -30,18 +30,18 @@ public class AvatarEffectsMessageComposer extends MessageComposer {
this.response.appendInt(this.effects.size()); this.response.appendInt(this.effects.size());
for (EffectsComponent.HabboEffect effect : effects) { for (EffectsComponent.HabboEffect effect : effects) {
AvatarEffectsMessageComposer.this.response.appendInt(effect.effect); AvatarEffectsMessageComposer.this.response.appendInt(effect.getEffect());
AvatarEffectsMessageComposer.this.response.appendInt(0); AvatarEffectsMessageComposer.this.response.appendInt(0);
AvatarEffectsMessageComposer.this.response.appendInt(effect.duration > 0 ? effect.duration : Integer.MAX_VALUE); AvatarEffectsMessageComposer.this.response.appendInt(effect.getDuration() > 0 ? effect.getDuration() : Integer.MAX_VALUE);
AvatarEffectsMessageComposer.this.response.appendInt((effect.duration > 0 ? (effect.total - (effect.isActivated() ? 1 : 0)) : 0)); AvatarEffectsMessageComposer.this.response.appendInt((effect.getDuration() > 0 ? (effect.getTotal() - (effect.isActivated() ? 1 : 0)) : 0));
if(!effect.isActivated() && effect.duration > 0) { if(!effect.isActivated() && effect.getDuration() > 0) {
AvatarEffectsMessageComposer.this.response.appendInt(0); AvatarEffectsMessageComposer.this.response.appendInt(0);
} }
else { else {
AvatarEffectsMessageComposer.this.response.appendInt(effect.duration > 0 ? (Emulator.getIntUnixTimestamp() - effect.activationTimestamp) + effect.duration : 0); AvatarEffectsMessageComposer.this.response.appendInt(effect.getDuration() > 0 ? (Emulator.getIntUnixTimestamp() - effect.getActivationTimestamp()) + effect.getDuration() : 0);
} }
AvatarEffectsMessageComposer.this.response.appendBoolean(effect.duration <= 0); // is perm AvatarEffectsMessageComposer.this.response.appendBoolean(effect.getDuration() <= 0); // is perm
} }
} }
} }

View File

@ -1,6 +1,7 @@
package com.eu.habbo.messages.outgoing.modtool; package com.eu.habbo.messages.outgoing.modtool;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.modtool.ModToolSanctionItem; import com.eu.habbo.habbohotel.modtool.ModToolSanctionItem;
import com.eu.habbo.habbohotel.modtool.ModToolSanctionLevelItem; import com.eu.habbo.habbohotel.modtool.ModToolSanctionLevelItem;
import com.eu.habbo.habbohotel.modtool.ModToolSanctions; import com.eu.habbo.habbohotel.modtool.ModToolSanctions;
@ -17,6 +18,8 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION;
@Slf4j @Slf4j
@AllArgsConstructor @AllArgsConstructor
public class ModeratorUserInfoComposer extends MessageComposer { public class ModeratorUserInfoComposer extends MessageComposer {
@ -29,21 +32,9 @@ public class ModeratorUserInfoComposer extends MessageComposer {
try { try {
int totalBans = 0; int totalBans = 0;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); totalBans = getTotalBansFromDB(totalBans);
PreparedStatement statement = connection.prepareStatement("SELECT COUNT(*) AS amount FROM bans WHERE user_id = ?")) {
statement.setInt(1, this.set.getInt("user_id"));
try (ResultSet set = statement.executeQuery()) {
if (set.next()) {
totalBans = set.getInt("amount");
}
} catch (SQLException e) {
log.error("Caught SQL exception", e);
}
} catch (SQLException e) {
log.error("Caught SQL exception", e);
}
this.response.appendInt(this.set.getInt("user_id")); this.response.appendInt(this.set.getInt(DatabaseConstants.USER_ID));
this.response.appendString(this.set.getString("username")); this.response.appendString(this.set.getString("username"));
this.response.appendString(this.set.getString("look")); this.response.appendString(this.set.getString("look"));
this.response.appendInt((Emulator.getIntUnixTimestamp() - this.set.getInt("account_created")) / 60); this.response.appendInt((Emulator.getIntUnixTimestamp() - this.set.getInt("account_created")) / 60);
@ -56,7 +47,7 @@ public class ModeratorUserInfoComposer extends MessageComposer {
this.response.appendInt(this.set.getInt("tradelock_amount")); this.response.appendInt(this.set.getInt("tradelock_amount"));
this.response.appendString(""); //Trading lock expiry timestamp this.response.appendString(""); //Trading lock expiry timestamp
this.response.appendString(""); //Last Purchase Timestamp this.response.appendString(""); //Last Purchase Timestamp
this.response.appendInt(this.set.getInt("user_id")); //Personal Identification # this.response.appendInt(this.set.getInt(DatabaseConstants.USER_ID)); //Personal Identification #
this.response.appendInt(0); // Number of account bans this.response.appendInt(0); // Number of account bans
this.response.appendString(this.set.getBoolean("hide_mail") ? "" : this.set.getString("mail")); this.response.appendString(this.set.getBoolean("hide_mail") ? "" : this.set.getString("mail"));
this.response.appendString("Rank (" + this.set.getInt("rank_id") + "): " + this.set.getString("rank_name")); //user_class_txt this.response.appendString("Rank (" + this.set.getInt("rank_id") + "): " + this.set.getString("rank_name")); //user_class_txt
@ -64,10 +55,10 @@ public class ModeratorUserInfoComposer extends MessageComposer {
ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions();
if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) {
THashMap<Integer, ArrayList<ModToolSanctionItem>> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(this.set.getInt("user_id")); THashMap<Integer, ArrayList<ModToolSanctionItem>> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(this.set.getInt(DatabaseConstants.USER_ID));
ArrayList<ModToolSanctionItem> modToolSanctionItems = modToolSanctionItemsHashMap.get(this.set.getInt("user_id")); ArrayList<ModToolSanctionItem> modToolSanctionItems = modToolSanctionItemsHashMap.get(this.set.getInt(DatabaseConstants.USER_ID));
if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) //has sanction if (modToolSanctionItems != null && !modToolSanctionItems.isEmpty()) //has sanction
{ {
ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1);
ModToolSanctionLevelItem modToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.getSanctionLevel()); ModToolSanctionLevelItem modToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.getSanctionLevel());
@ -80,8 +71,26 @@ public class ModeratorUserInfoComposer extends MessageComposer {
return this.response; return this.response;
} catch (SQLException e) { } catch (SQLException e) {
log.error("Caught SQL exception", e); log.error(CAUGHT_SQL_EXCEPTION, e);
} }
return null; return null;
} }
private int getTotalBansFromDB() {
int totalBans = 0;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement("SELECT COUNT(*) AS amount FROM bans WHERE user_id = ?")) {
statement.setInt(1, this.set.getInt(DatabaseConstants.USER_ID));
try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) {
totalBans = resultSet.getInt("amount");
}
} catch (SQLException e) {
log.error(CAUGHT_SQL_EXCEPTION, e);
}
} catch (SQLException e) {
log.error(CAUGHT_SQL_EXCEPTION, e);
}
return totalBans;
}
} }

View File

@ -8,9 +8,9 @@ import com.eu.habbo.messages.outgoing.Outgoing;
import gnu.trove.iterator.TIntObjectIterator; import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.map.TIntObjectMap; import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -42,7 +42,7 @@ public class ItemsComposer extends MessageComposer {
this.response.appendString(set.getValue()); this.response.appendString(set.getValue());
} }
THashSet<HabboItem> items = this.room.getWallItems(); List<HabboItem> items = this.room.getWallItems();
this.response.appendInt(items.size()); this.response.appendInt(items.size());
for (HabboItem item : items) { for (HabboItem item : items) {

View File

@ -56,7 +56,7 @@ public class PetInfoMessageComposer extends MessageComposer {
this.response.appendBoolean(!(this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).isFullyGrown())); //unknown 1 this.response.appendBoolean(!(this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).isFullyGrown())); //unknown 1
this.response.appendBoolean(this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).isDead()); //Dead this.response.appendBoolean(this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).isDead()); //Dead
this.response.appendInt(this.pet instanceof MonsterplantPet ? ((MonsterplantPet) this.pet).getRarity() : 0); this.response.appendInt(this.pet instanceof MonsterplantPet ? ((MonsterplantPet) this.pet).getRarity() : 0);
this.response.appendInt(MonsterplantPet.timeToLive); //Maximum wellbeing this.response.appendInt(MonsterplantPet.TIME_TO_LIVE); //Maximum wellbeing
this.response.appendInt(this.pet instanceof MonsterplantPet ? ((MonsterplantPet) this.pet).remainingTimeToLive() : 0); //Remaining Wellbeing this.response.appendInt(this.pet instanceof MonsterplantPet ? ((MonsterplantPet) this.pet).remainingTimeToLive() : 0); //Remaining Wellbeing
this.response.appendInt(this.pet instanceof MonsterplantPet ? ((MonsterplantPet) this.pet).remainingGrowTime() : 0); this.response.appendInt(this.pet instanceof MonsterplantPet ? ((MonsterplantPet) this.pet).remainingGrowTime() : 0);
this.response.appendBoolean(this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).isPubliclyBreedable()); //Breedable checkbox this.response.appendBoolean(this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).isPubliclyBreedable()); //Breedable checkbox

View File

@ -26,7 +26,7 @@ public class UserUpdateComposer extends MessageComposer {
this.overrideZ = overrideZ; this.overrideZ = overrideZ;
} }
public UserUpdateComposer(THashSet<RoomUnit> roomUnits, boolean value) { public UserUpdateComposer(THashSet<RoomUnit> roomUnits) {
this.roomUnits = roomUnits; this.roomUnits = roomUnits;
} }
@ -50,7 +50,7 @@ public class UserUpdateComposer extends MessageComposer {
this.response.appendInt(roomUnit.getBodyRotation().getValue()); this.response.appendInt(roomUnit.getBodyRotation().getValue());
StringBuilder status = new StringBuilder("/"); StringBuilder status = new StringBuilder("/");
for (Map.Entry<RoomUnitStatus, String> entry : roomUnit.getStatusMap().entrySet()) { for (Map.Entry<RoomUnitStatus, String> entry : roomUnit.getStatus().entrySet()) {
status.append(entry.getKey()).append(" ").append(entry.getValue()).append("/"); status.append(entry.getKey()).append(" ").append(entry.getValue()).append("/");
} }
@ -72,7 +72,7 @@ public class UserUpdateComposer extends MessageComposer {
StringBuilder status = new StringBuilder("/"); StringBuilder status = new StringBuilder("/");
for (Map.Entry<RoomUnitStatus, String> entry : habbo.getRoomUnit().getStatusMap().entrySet()) { for (Map.Entry<RoomUnitStatus, String> entry : habbo.getRoomUnit().getStatus().entrySet()) {
status.append(entry.getKey()).append(" ").append(entry.getValue()).append("/"); status.append(entry.getKey()).append(" ").append(entry.getValue()).append("/");
} }
this.response.appendString(status.toString()); this.response.appendString(status.toString());

View File

@ -5,13 +5,14 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.plugin.events.users.UserEvent; import com.eu.habbo.plugin.events.users.UserEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public abstract class NavigatorRoomsEvent extends UserEvent { public abstract class NavigatorRoomsEvent extends UserEvent {
public final ArrayList<Room> rooms; public final List<Room> rooms;
public NavigatorRoomsEvent(Habbo habbo, ArrayList<Room> rooms) { public NavigatorRoomsEvent(Habbo habbo, List<Room> rooms) {
super(habbo); super(habbo);
this.rooms = rooms; this.rooms = rooms;

View File

@ -4,6 +4,7 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class NavigatorSearchResultEvent extends NavigatorRoomsEvent { public class NavigatorSearchResultEvent extends NavigatorRoomsEvent {
@ -13,7 +14,7 @@ public class NavigatorSearchResultEvent extends NavigatorRoomsEvent {
public final String query; public final String query;
public NavigatorSearchResultEvent(Habbo habbo, String prefix, String query, ArrayList<Room> rooms) { public NavigatorSearchResultEvent(Habbo habbo, String prefix, String query, List<Room> rooms) {
super(habbo, rooms); super(habbo, rooms);
this.prefix = prefix; this.prefix = prefix;

View File

@ -21,8 +21,8 @@ public class OneWayGateActionOne implements Runnable {
RoomTile t = this.room.getLayout().getTileInFront(this.room.getLayout().getTile(this.oneWayGate.getX(), this.oneWayGate.getY()), (this.oneWayGate.getRotation() + 4) % 8); RoomTile t = this.room.getLayout().getTileInFront(this.room.getLayout().getTile(this.oneWayGate.getX(), this.oneWayGate.getY()), (this.oneWayGate.getRotation() + 4) % 8);
if (this.client.getHabbo().getRoomUnit().animateWalk) { if (this.client.getHabbo().getRoomUnit().isAnimateWalk()) {
this.client.getHabbo().getRoomUnit().animateWalk = false; this.client.getHabbo().getRoomUnit().setAnimateWalk(false);
} }
if (t.isWalkable()) { if (t.isWalkable()) {

View File

@ -18,7 +18,7 @@ public class RoomUnitRidePet implements Runnable {
@Override @Override
public void run() { public void run() {
if (this.habbo.getRoomUnit() == null || this.pet.getRoomUnit() == null || this.pet.getRoom() != this.habbo.getHabboInfo().getCurrentRoom() || this.goalTile == null || this.habbo.getRoomUnit().getGoal() != this.goalTile) if (this.habbo.getRoomUnit() == null || this.pet.getRoomUnit() == null || this.pet.getRoom() != this.habbo.getHabboInfo().getCurrentRoom() || this.goalTile == null || this.habbo.getRoomUnit().getGoalLocation() != this.goalTile)
return; return;
if (habbo.getRoomUnit().getCurrentLocation().distance(pet.getRoomUnit().getCurrentLocation()) <= 1) { if (habbo.getRoomUnit().getCurrentLocation().distance(pet.getRoomUnit().getCurrentLocation()) <= 1) {

View File

@ -28,8 +28,8 @@ public class RoomUnitTeleport implements Runnable {
if (roomUnit == null || roomUnit.getRoom() == null || room.getLayout() == null) if (roomUnit == null || roomUnit.getRoom() == null || room.getLayout() == null)
return; return;
if (roomUnit.isLeavingTeleporter) { if (roomUnit.isLeavingTeleporter()) {
roomUnit.isWiredTeleporting = false; roomUnit.setWiredTeleporting(false);
return; return;
} }
@ -54,7 +54,7 @@ public class RoomUnitTeleport implements Runnable {
this.roomUnit.setLocation(newLocation); this.roomUnit.setLocation(newLocation);
//this.room.sendComposer(teleportMessage); //this.room.sendComposer(teleportMessage);
this.roomUnit.statusUpdate(true); this.roomUnit.statusUpdate(true);
roomUnit.isWiredTeleporting = false; roomUnit.setWiredTeleporting(false);
this.room.updateHabbosAt(newLocation.getX(), newLocation.getY()); this.room.updateHabbosAt(newLocation.getX(), newLocation.getY());
this.room.updateBotsAt(newLocation.getX(), newLocation.getY()); this.room.updateBotsAt(newLocation.getX(), newLocation.getY());

View File

@ -19,27 +19,25 @@ public class RoomUnitTeleportWalkToAction implements Runnable {
@Override @Override
public void run() { public void run() {
if (this.habbo.getHabboInfo().getCurrentRoom() == this.room) { if (this.habbo.getHabboInfo().getCurrentRoom() != this.room || this.habboItem.getRoomId() != this.room.getId()) {
if (this.habboItem.getRoomId() == this.room.getId()) { return;
RoomTile tile = HabboItem.getSquareInFront(this.room.getLayout(), this.habboItem);
if (tile != null) {
if (this.habbo.getRoomUnit().getGoal().equals(tile)) {
if (this.habbo.getRoomUnit().getCurrentLocation().equals(tile)) {
try {
this.habboItem.onClick(this.habbo.getClient(), this.room, new Object[]{0});
} catch (Exception e) {
log.error("Caught exception", e);
}
} else {
if (tile.isWalkable()) {
this.habbo.getRoomUnit().setGoalLocation(tile);
Emulator.getThreading().run(this, (long) this.habbo.getRoomUnit().getPath().size() + 2 * 510);
}
}
}
}
}
} }
RoomTile tile = HabboItem.getSquareInFront(this.room.getLayout(), this.habboItem);
if (!this.habbo.getRoomUnit().getGoalLocation().equals(tile)) {
return;
}
if (this.habbo.getRoomUnit().getCurrentLocation().equals(tile)) {
try {
this.habboItem.onClick(this.habbo.getClient(), this.room, new Object[]{0});
} catch (Exception e) {
log.error("Caught exception", e);
}
} else if (tile.isWalkable()) {
this.habbo.getRoomUnit().setGoalLocation(tile);
Emulator.getThreading().run(this, (long) this.habbo.getRoomUnit().getPath().size() + 2 * 510);
}
} }
} }

View File

@ -18,26 +18,29 @@ public class RoomUnitVendingMachineAction implements Runnable {
@Override @Override
public void run() { public void run() {
if (this.habbo.getHabboInfo().getCurrentRoom() == this.room) { if (this.habbo.getHabboInfo().getCurrentRoom() != this.room || this.habboItem.getRoomId() != this.room.getId()) {
if (this.habboItem.getRoomId() == this.room.getId()) { return;
RoomTile tile = HabboItem.getSquareInFront(this.room.getLayout(), this.habboItem); }
if (tile != null) {
if (this.habbo.getRoomUnit().getGoal().equals(tile)) { RoomTile tile = HabboItem.getSquareInFront(this.room.getLayout(), this.habboItem);
if (this.habbo.getRoomUnit().getCurrentLocation().equals(tile)) { if (tile == null) {
try { return;
this.habboItem.onClick(this.habbo.getClient(), this.room, new Object[]{0}); }
} catch (Exception e) {
log.error("Caught exception", e); if (this.habbo.getRoomUnit().getGoalLocation().equals(tile)) {
} if (this.habbo.getRoomUnit().getCurrentLocation().equals(tile)) {
} else { try {
if (this.room.getLayout().getTile(tile.getX(), tile.getY()).isWalkable()) { this.habboItem.onClick(this.habbo.getClient(), this.room, new Object[]{0});
this.habbo.getRoomUnit().setGoalLocation(tile); } catch (Exception e) {
Emulator.getThreading().run(this, (long) this.habbo.getRoomUnit().getPath().size() + 2 * 510); log.error("Caught exception", e);
} }
} } else {
} if (this.room.getLayout().getTile(tile.getX(), tile.getY()).isWalkable()) {
this.habbo.getRoomUnit().setGoalLocation(tile);
Emulator.getThreading().run(this, (long) this.habbo.getRoomUnit().getPath().size() + 2 * 510);
} }
} }
} }
} }
} }

View File

@ -43,7 +43,7 @@ public class RoomUnitWalkToLocation implements Runnable {
return; return;
} }
if (!this.walker.getGoal().equals(this.goalTile) || (this.walker.getPath().size() == 0 && !this.walker.hasStatus(RoomUnitStatus.MOVE))) { if (!this.walker.getGoalLocation().equals(this.goalTile) || (this.walker.getPath().isEmpty() && !this.walker.hasStatus(RoomUnitStatus.MOVE))) {
onFail(); onFail();
return; return;
} }

View File

@ -38,7 +38,7 @@ public class RoomUnitWalkToRoomUnit implements Runnable {
return; return;
} }
if (this.walker.getGoal().equals(this.goalTile)) { // check that the action hasn't been cancelled by changing the goal if (this.walker.getGoalLocation().equals(this.goalTile)) { // check that the action hasn't been cancelled by changing the goal
if (this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance) { if (this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance) {
for (Runnable r : this.targetReached) { for (Runnable r : this.targetReached) {
Emulator.getThreading().run(r); Emulator.getThreading().run(r);

View File

@ -16,7 +16,7 @@ class HopperActionFive implements Runnable {
@Override @Override
public void run() { public void run() {
this.client.getHabbo().getRoomUnit().isTeleporting = false; this.client.getHabbo().getRoomUnit().setTeleporting(false);
RoomTile tile = this.room.getLayout().getTileInFront(this.room.getLayout().getTile(this.currentTeleport.getX(), this.currentTeleport.getY()), this.currentTeleport.getRotation()); RoomTile tile = this.room.getLayout().getTileInFront(this.room.getLayout().getTile(this.currentTeleport.getX(), this.currentTeleport.getY()), this.currentTeleport.getRotation());
if (tile != null) { if (tile != null) {
this.client.getHabbo().getRoomUnit().setGoalLocation(tile); this.client.getHabbo().getRoomUnit().setGoalLocation(tile);

View File

@ -46,7 +46,7 @@ class HopperActionTwo implements Runnable {
} else { } else {
this.teleportOne.setExtradata("0"); this.teleportOne.setExtradata("0");
this.client.getHabbo().getRoomUnit().setCanWalk(true); this.client.getHabbo().getRoomUnit().setCanWalk(true);
this.client.getHabbo().getRoomUnit().isTeleporting = false; this.client.getHabbo().getRoomUnit().setTeleporting(false);
Emulator.getThreading().run(new HopperActionFour(this.teleportOne, this.room, this.client), 500); Emulator.getThreading().run(new HopperActionFour(this.teleportOne, this.room, this.client), 500);
} }

View File

@ -26,8 +26,8 @@ class TeleportActionFive implements Runnable {
public void run() { public void run() {
RoomUnit unit = this.client.getHabbo().getRoomUnit(); RoomUnit unit = this.client.getHabbo().getRoomUnit();
unit.isLeavingTeleporter = false; unit.setLeavingTeleporter(false);
unit.isTeleporting = false; unit.setTeleporting(false);
unit.setCanWalk(true); unit.setCanWalk(true);
if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != this.room) if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != this.room)
@ -45,13 +45,13 @@ class TeleportActionFive implements Runnable {
onSuccess.add(() -> { onSuccess.add(() -> {
unit.setCanLeaveRoomByDoor(true); unit.setCanLeaveRoomByDoor(true);
Emulator.getThreading().run(() -> unit.isLeavingTeleporter = false, 300); Emulator.getThreading().run(() -> unit.setLeavingTeleporter(false), 300);
}); });
unit.setCanLeaveRoomByDoor(false); unit.setCanLeaveRoomByDoor(false);
unit.setGoalLocation(tile); unit.setGoalLocation(tile);
unit.statusUpdate(true); unit.statusUpdate(true);
unit.isLeavingTeleporter = true; unit.setLeavingTeleporter(true);
Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tile, room, onSuccess, onSuccess)); Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tile, room, onSuccess, onSuccess));
} }

View File

@ -23,7 +23,7 @@ class TeleportActionFour implements Runnable {
} }
if(this.client.getHabbo().getRoomUnit() != null) { if(this.client.getHabbo().getRoomUnit() != null) {
this.client.getHabbo().getRoomUnit().isLeavingTeleporter = true; this.client.getHabbo().getRoomUnit().setLeavingTeleporter(true);
} }
Emulator.getThreading().run(new TeleportActionFive(this.currentTeleport, this.room, this.client), 500); Emulator.getThreading().run(new TeleportActionFive(this.currentTeleport, this.room, this.client), 500);