Merge pull request #72 from duckietm/main

Sync to DEV
This commit is contained in:
DuckieTM
2026-04-08 15:48:56 +02:00
committed by GitHub
4 changed files with 68 additions and 87 deletions
@@ -775,6 +775,15 @@ public class RoomManager {
habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]);
} }
if (habbo.getRoomUnit().getCurrentLocation() == null) {
LOGGER.warn("Failed to resolve a valid door tile for room {} ({}) while {} was entering; sending user back to hotel view",
room.getId(), room.getName(), habbo.getHabboInfo().getUsername());
habbo.getHabboInfo().setLoadingRoom(0);
habbo.getHabboInfo().setCurrentRoom(null);
habbo.getClient().sendResponse(new HotelViewComposer());
return;
}
habbo.getRoomUnit().setPathFinderRoom(room); habbo.getRoomUnit().setPathFinderRoom(room);
habbo.getRoomUnit().resetIdleTimer(); habbo.getRoomUnit().resetIdleTimer();
@@ -410,11 +410,11 @@ public class RoomUnit {
} }
public short getX() { public short getX() {
return this.currentLocation.x; return this.currentLocation == null ? 0 : this.currentLocation.x;
} }
public short getY() { public short getY() {
return this.currentLocation.y; return this.currentLocation == null ? 0 : this.currentLocation.y;
} }
public double getZ() { public double getZ() {
@@ -597,6 +597,7 @@ public class RoomUnit {
} }
public boolean isAtGoal() { public boolean isAtGoal() {
if (this.currentLocation == null) return true;
return this.currentLocation.equals(this.goalLocation); return this.currentLocation.equals(this.goalLocation);
} }
@@ -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.SqlQueries;
import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInventory; import com.eu.habbo.habbohotel.users.HabboInventory;
@@ -9,7 +10,6 @@ import com.eu.habbo.plugin.events.inventory.InventoryItemAddedEvent;
import com.eu.habbo.plugin.events.inventory.InventoryItemRemovedEvent; import com.eu.habbo.plugin.events.inventory.InventoryItemRemovedEvent;
import com.eu.habbo.plugin.events.inventory.InventoryItemsAddedEvent; import com.eu.habbo.plugin.events.inventory.InventoryItemsAddedEvent;
import gnu.trove.TCollections; import gnu.trove.TCollections;
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.map.hash.TIntObjectHashMap; import gnu.trove.map.hash.TIntObjectHashMap;
@@ -18,11 +18,9 @@ import gnu.trove.set.hash.THashSet;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.NoSuchElementException; import java.util.ArrayList;
import java.util.List;
public class ItemsComponent { public class ItemsComponent {
private static final Logger LOGGER = LoggerFactory.getLogger(ItemsComponent.class); private static final Logger LOGGER = LoggerFactory.getLogger(ItemsComponent.class);
@@ -39,25 +37,23 @@ public class ItemsComponent {
public static THashMap<Integer, HabboItem> loadItems(Habbo habbo) { public static THashMap<Integer, HabboItem> loadItems(Habbo habbo) {
THashMap<Integer, HabboItem> itemsList = new THashMap<>(); THashMap<Integer, HabboItem> itemsList = new THashMap<>();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM items WHERE room_id = ? AND user_id = ?")) { try {
statement.setInt(1, 0); SqlQueries.forEach(
statement.setInt(2, habbo.getHabboInfo().getId()); "SELECT * FROM items WHERE room_id = ? AND user_id = ?",
try (ResultSet set = statement.executeQuery()) { rs -> {
while (set.next()) { try {
try { HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(rs);
HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set); if (item != null) {
itemsList.put(rs.getInt("id"), item);
if (item != null) { } else {
itemsList.put(set.getInt("id"), item); LOGGER.error("Failed to load HabboItem: {}", rs.getInt("id"));
} else { }
LOGGER.error("Failed to load HabboItem: {}", set.getInt("id")); } catch (SQLException e) {
LOGGER.error("Caught SQL exception", e);
} }
} catch (SQLException e) { },
LOGGER.error("Caught SQL exception", e); 0, habbo.getHabboInfo().getId());
} } catch (SqlQueries.DataAccessException e) {
}
}
} catch (SQLException e) {
LOGGER.error("Caught SQL exception", e); LOGGER.error("Caught SQL exception", e);
} }
@@ -151,70 +147,45 @@ public class ItemsComponent {
public void dispose() { public void dispose() {
synchronized (this.items) { synchronized (this.items) {
TIntObjectIterator<HabboItem> items = this.items.iterator();
if (items == null) {
LOGGER.error("Items is NULL!");
return;
}
if (!this.items.isEmpty()) { if (!this.items.isEmpty()) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { List<HabboItem> updates = new ArrayList<>();
try (PreparedStatement updateStmt = connection.prepareStatement( List<HabboItem> deletes = new ArrayList<>();
"UPDATE items SET user_id = ?, room_id = ?, wall_pos = ?, x = ?, y = ?, z = ?, rot = ?, extra_data = ?, limited_data = ? WHERE id = ?")) { for (HabboItem item : this.items.valueCollection()) {
try (PreparedStatement deleteStmt = connection.prepareStatement( if (item.needsDelete()) {
"DELETE FROM items WHERE id = ?")) { deletes.add(item);
item.needsUpdate(false);
int updateCount = 0; item.needsDelete(false);
int deleteCount = 0; } else if (item.needsUpdate()) {
updates.add(item);
for (int i = this.items.size(); i-- > 0; ) { item.needsUpdate(false);
try {
items.advance();
} catch (NoSuchElementException e) {
break;
}
HabboItem item = items.value();
if (item.needsDelete()) {
deleteStmt.setInt(1, item.getId());
deleteStmt.addBatch();
deleteCount++;
item.needsUpdate(false);
item.needsDelete(false);
} else if (item.needsUpdate()) {
updateStmt.setInt(1, item.getUserId());
updateStmt.setInt(2, item.getRoomId());
updateStmt.setString(3, item.getWallPosition());
updateStmt.setInt(4, item.getX());
updateStmt.setInt(5, item.getY());
updateStmt.setDouble(6, item.getZ());
updateStmt.setInt(7, item.getRotation());
updateStmt.setString(8, item.getExtradata());
updateStmt.setString(9, item.getLimitedStack() + ":" + item.getLimitedSells());
updateStmt.setInt(10, item.getId());
updateStmt.addBatch();
updateCount++;
item.needsUpdate(false);
}
if (updateCount > 0 && updateCount % 100 == 0) {
updateStmt.executeBatch();
}
if (deleteCount > 0 && deleteCount % 100 == 0) {
deleteStmt.executeBatch();
}
}
if (deleteCount % 100 != 0) {
deleteStmt.executeBatch();
}
if (updateCount % 100 != 0) {
updateStmt.executeBatch();
}
}
} }
} catch (SQLException e) { }
try {
if (!deletes.isEmpty()) {
SqlQueries.batchUpdate(
"DELETE FROM items WHERE id = ?",
deletes,
(ps, item) -> ps.setInt(1, item.getId()));
}
if (!updates.isEmpty()) {
SqlQueries.batchUpdate(
"UPDATE items SET user_id = ?, room_id = ?, wall_pos = ?, x = ?, y = ?, z = ?, rot = ?, extra_data = ?, limited_data = ? WHERE id = ?",
updates,
(ps, item) -> {
ps.setInt(1, item.getUserId());
ps.setInt(2, item.getRoomId());
ps.setString(3, item.getWallPosition());
ps.setInt(4, item.getX());
ps.setInt(5, item.getY());
ps.setDouble(6, item.getZ());
ps.setInt(7, item.getRotation());
ps.setString(8, item.getExtradata());
ps.setString(9, item.getLimitedStack() + ":" + item.getLimitedSells());
ps.setInt(10, item.getId());
});
}
} catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception during batch item save", e); LOGGER.error("Caught SQL exception during batch item save", e);
} }
} }