You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-20 23:36:19 +00:00
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+41
-70
@@ -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 = ?")) {
|
|
||||||
statement.setInt(1, 0);
|
|
||||||
statement.setInt(2, habbo.getHabboInfo().getId());
|
|
||||||
try (ResultSet set = statement.executeQuery()) {
|
|
||||||
while (set.next()) {
|
|
||||||
try {
|
try {
|
||||||
HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set);
|
SqlQueries.forEach(
|
||||||
|
"SELECT * FROM items WHERE room_id = ? AND user_id = ?",
|
||||||
|
rs -> {
|
||||||
|
try {
|
||||||
|
HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(rs);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
itemsList.put(set.getInt("id"), item);
|
itemsList.put(rs.getInt("id"), item);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("Failed to load HabboItem: {}", set.getInt("id"));
|
LOGGER.error("Failed to load HabboItem: {}", rs.getInt("id"));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.error("Caught SQL exception", e);
|
LOGGER.error("Caught SQL exception", e);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
0, habbo.getHabboInfo().getId());
|
||||||
} catch (SQLException e) {
|
} catch (SqlQueries.DataAccessException 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(
|
|
||||||
"DELETE FROM items WHERE id = ?")) {
|
|
||||||
|
|
||||||
int updateCount = 0;
|
|
||||||
int deleteCount = 0;
|
|
||||||
|
|
||||||
for (int i = this.items.size(); i-- > 0; ) {
|
|
||||||
try {
|
|
||||||
items.advance();
|
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
HabboItem item = items.value();
|
|
||||||
if (item.needsDelete()) {
|
if (item.needsDelete()) {
|
||||||
deleteStmt.setInt(1, item.getId());
|
deletes.add(item);
|
||||||
deleteStmt.addBatch();
|
|
||||||
deleteCount++;
|
|
||||||
item.needsUpdate(false);
|
item.needsUpdate(false);
|
||||||
item.needsDelete(false);
|
item.needsDelete(false);
|
||||||
} else if (item.needsUpdate()) {
|
} else if (item.needsUpdate()) {
|
||||||
updateStmt.setInt(1, item.getUserId());
|
updates.add(item);
|
||||||
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);
|
item.needsUpdate(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateCount > 0 && updateCount % 100 == 0) {
|
|
||||||
updateStmt.executeBatch();
|
|
||||||
}
|
|
||||||
if (deleteCount > 0 && deleteCount % 100 == 0) {
|
|
||||||
deleteStmt.executeBatch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleteCount % 100 != 0) {
|
try {
|
||||||
deleteStmt.executeBatch();
|
if (!deletes.isEmpty()) {
|
||||||
|
SqlQueries.batchUpdate(
|
||||||
|
"DELETE FROM items WHERE id = ?",
|
||||||
|
deletes,
|
||||||
|
(ps, item) -> ps.setInt(1, item.getId()));
|
||||||
}
|
}
|
||||||
if (updateCount % 100 != 0) {
|
if (!updates.isEmpty()) {
|
||||||
updateStmt.executeBatch();
|
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) {
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
LOGGER.error("Caught SQL exception during batch item save", e);
|
LOGGER.error("Caught SQL exception during batch item save", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user