mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-27 00:40:52 +01:00
Fix jukebox disc adding/removing
This commit is contained in:
parent
8e54b357e1
commit
99168d57a5
@ -13,7 +13,6 @@ import java.sql.SQLException;
|
||||
|
||||
public class InteractionMusicDisc extends HabboItem {
|
||||
private int songId;
|
||||
private boolean inQueue;
|
||||
|
||||
public InteractionMusicDisc(ResultSet set, Item baseItem) throws SQLException {
|
||||
super(set, baseItem);
|
||||
@ -74,21 +73,13 @@ public class InteractionMusicDisc extends HabboItem {
|
||||
public void onPlace(Room room) {
|
||||
super.onPlace(room);
|
||||
|
||||
room.sendComposer(new JukeBoxMySongsComposer(room.getTraxManager().myList()).compose());
|
||||
room.getTraxManager().sendUpdatedSongList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickUp(Room room) {
|
||||
super.onPickUp(room);
|
||||
|
||||
room.getTraxManager().removeSong(this.getId());
|
||||
}
|
||||
|
||||
public boolean inQueue() {
|
||||
return this.inQueue;
|
||||
}
|
||||
|
||||
public void inQueue(boolean inQueue) {
|
||||
this.inQueue = inQueue;
|
||||
room.getTraxManager().sendUpdatedSongList();
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,15 @@ package com.eu.habbo.habbohotel.rooms;
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.core.Disposable;
|
||||
import com.eu.habbo.habbohotel.achievements.AchievementManager;
|
||||
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
||||
import com.eu.habbo.habbohotel.items.SoundTrack;
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionJukeBox;
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionMusicDisc;
|
||||
import com.eu.habbo.habbohotel.users.Habbo;
|
||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||
import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer;
|
||||
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
|
||||
import com.eu.habbo.messages.outgoing.inventory.RemoveHabboItemComposer;
|
||||
import com.eu.habbo.messages.outgoing.rooms.items.jukebox.JukeBoxMySongsComposer;
|
||||
import com.eu.habbo.messages.outgoing.rooms.items.jukebox.JukeBoxNowPlayingMessageComposer;
|
||||
import com.eu.habbo.messages.outgoing.rooms.items.jukebox.JukeBoxPlayListComposer;
|
||||
@ -18,6 +22,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TraxManager implements Disposable {
|
||||
private final Room room;
|
||||
@ -38,8 +43,18 @@ public class TraxManager implements Disposable {
|
||||
statement.setInt(1, this.room.getId());
|
||||
try (ResultSet set = statement.executeQuery()) {
|
||||
while (set.next()) {
|
||||
HabboItem musicDisc = this.room.getHabboItem(set.getInt("item_id"));
|
||||
if (musicDisc instanceof InteractionMusicDisc) {
|
||||
HabboItem musicDisc = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set.getInt("item_id"));
|
||||
|
||||
if (!(musicDisc instanceof InteractionMusicDisc) || musicDisc.getRoomId() != -1) {
|
||||
try (PreparedStatement stmt = connection.prepareStatement("DELETE FROM room_trax_playlist WHERE room_id = ? AND item_id = ? LIMIT 1")) {
|
||||
stmt.setInt(1, this.room.getId());
|
||||
stmt.setInt(2, musicDisc.getId());
|
||||
stmt.execute();
|
||||
} catch (SQLException e) {
|
||||
Emulator.getLogging().logSQLException(e);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
SoundTrack track = Emulator.getGameEnvironment().getItemManager().getSoundTrack(((InteractionMusicDisc) musicDisc).getSongId());
|
||||
|
||||
if (track != null) {
|
||||
@ -128,19 +143,16 @@ public class TraxManager implements Disposable {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addSong(int itemId) {
|
||||
HabboItem musicDisc = this.room.getHabboItem(itemId);
|
||||
|
||||
if (musicDisc instanceof InteractionMusicDisc) {
|
||||
SoundTrack track = Emulator.getGameEnvironment().getItemManager().getSoundTrack(((InteractionMusicDisc) musicDisc).getSongId());
|
||||
public void addSong(InteractionMusicDisc musicDisc, Habbo habbo) {
|
||||
SoundTrack track = Emulator.getGameEnvironment().getItemManager().getSoundTrack(musicDisc.getSongId());
|
||||
|
||||
if (track != null) {
|
||||
this.totalLength += track.getLength();
|
||||
this.songs.add((InteractionMusicDisc) musicDisc);
|
||||
this.songs.add(musicDisc);
|
||||
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_trax_playlist (room_id, item_id) VALUES (?, ?)")) {
|
||||
statement.setInt(1, this.room.getId());
|
||||
statement.setInt(2, itemId);
|
||||
statement.setInt(2, musicDisc.getId());
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
Emulator.getLogging().logSQLException(e);
|
||||
@ -148,9 +160,15 @@ public class TraxManager implements Disposable {
|
||||
}
|
||||
|
||||
this.room.sendComposer(new JukeBoxPlayListComposer(this.songs, this.totalLength).compose());
|
||||
this.room.sendComposer(new JukeBoxMySongsComposer(this.myList()).compose());
|
||||
}
|
||||
|
||||
musicDisc.setRoomId(-1);
|
||||
musicDisc.needsUpdate(true);
|
||||
|
||||
habbo.getInventory().getItemsComponent().removeHabboItem(musicDisc);
|
||||
habbo.getClient().sendResponse(new RemoveHabboItemComposer(musicDisc.getGiftAdjustedId()));
|
||||
}
|
||||
|
||||
this.sendUpdatedSongList();
|
||||
}
|
||||
|
||||
public void removeSong(int itemId) {
|
||||
@ -174,8 +192,34 @@ public class TraxManager implements Disposable {
|
||||
}
|
||||
|
||||
this.room.sendComposer(new JukeBoxPlayListComposer(this.songs, this.totalLength).compose());
|
||||
|
||||
musicDisc.setRoomId(0);
|
||||
musicDisc.needsUpdate(true);
|
||||
|
||||
Habbo owner = Emulator.getGameEnvironment().getHabboManager().getHabbo(musicDisc.getUserId());
|
||||
|
||||
if (owner != null) {
|
||||
owner.getInventory().getItemsComponent().addItem(musicDisc);
|
||||
|
||||
GameClient client = owner.getClient();
|
||||
if (client != null) {
|
||||
client.sendResponse(new AddHabboItemComposer(musicDisc));
|
||||
client.sendResponse(new InventoryRefreshComposer());
|
||||
}
|
||||
this.room.sendComposer(new JukeBoxMySongsComposer(this.myList()).compose());
|
||||
}
|
||||
}
|
||||
|
||||
this.sendUpdatedSongList();
|
||||
}
|
||||
|
||||
public void sendUpdatedSongList() {
|
||||
this.room.getHabbos().forEach(h -> {
|
||||
GameClient client = h.getClient();
|
||||
|
||||
if (client != null) {
|
||||
client.sendResponse(new JukeBoxMySongsComposer(this.myList(h)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int timePlaying() {
|
||||
@ -208,16 +252,11 @@ public class TraxManager implements Disposable {
|
||||
return trax;
|
||||
}
|
||||
|
||||
public List<InteractionMusicDisc> myList() {
|
||||
List<InteractionMusicDisc> trax = new ArrayList<>();
|
||||
|
||||
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionMusicDisc.class)) {
|
||||
if (!this.songs.contains(item)) {
|
||||
trax.add((InteractionMusicDisc) item);
|
||||
}
|
||||
}
|
||||
|
||||
return trax;
|
||||
public List<InteractionMusicDisc> myList(Habbo habbo) {
|
||||
return habbo.getInventory().getItemsComponent().getItems().valueCollection().stream()
|
||||
.filter(i -> i instanceof InteractionMusicDisc && i.getRoomId() == 0)
|
||||
.map(i -> (InteractionMusicDisc) i)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public InteractionMusicDisc fromItemId(int itemId) {
|
||||
|
@ -2,26 +2,25 @@ package com.eu.habbo.messages.incoming.rooms.items.jukebox;
|
||||
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionMusicDisc;
|
||||
import com.eu.habbo.habbohotel.rooms.Room;
|
||||
import com.eu.habbo.habbohotel.users.Habbo;
|
||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||
|
||||
public class JukeBoxAddSoundTrackEvent extends MessageHandler {
|
||||
@Override
|
||||
public void handle() throws Exception {
|
||||
if (!this.client.getHabbo().getHabboInfo().getCurrentRoom().hasRights(this.client.getHabbo())) return;
|
||||
|
||||
int itemId = this.packet.readInt();
|
||||
int unknown = this.packet.readInt();
|
||||
|
||||
Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom();
|
||||
Habbo habbo = this.client.getHabbo();
|
||||
|
||||
if (room != null) {
|
||||
HabboItem item = room.getHabboItem(itemId);
|
||||
if (habbo != null) {
|
||||
HabboItem item = habbo.getInventory().getItemsComponent().getHabboItem(itemId);
|
||||
|
||||
if (item instanceof InteractionMusicDisc) {
|
||||
|
||||
|
||||
if (this.client.getHabbo().getHabboInfo().getCurrentRoom().hasRights(this.client.getHabbo())) {
|
||||
this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager().addSong(itemId);
|
||||
}
|
||||
if (item != null && item instanceof InteractionMusicDisc && item.getRoomId() == 0) {
|
||||
this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager().addSong((InteractionMusicDisc) item, habbo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public class JukeBoxEventOne extends MessageHandler {
|
||||
public void handle() throws Exception {
|
||||
TraxManager traxManager = this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager();
|
||||
this.client.sendResponse(new JukeBoxPlayListComposer(traxManager.getSongs(), traxManager.totalLength()));
|
||||
this.client.sendResponse(new JukeBoxMySongsComposer(traxManager.myList()));
|
||||
this.client.sendResponse(new JukeBoxMySongsComposer(traxManager.myList(this.client.getHabbo())));
|
||||
this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager().updateCurrentPlayingSong(this.client.getHabbo());
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public class JukeBoxEventTwo extends MessageHandler {
|
||||
public void handle() throws Exception {
|
||||
TraxManager traxManager = this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager();
|
||||
this.client.sendResponse(new JukeBoxPlayListComposer(traxManager.getSongs(), traxManager.totalLength()));
|
||||
this.client.sendResponse(new JukeBoxMySongsComposer(traxManager.myList()));
|
||||
this.client.sendResponse(new JukeBoxMySongsComposer(traxManager.myList(this.client.getHabbo())));
|
||||
this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager().updateCurrentPlayingSong(this.client.getHabbo());
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public class JukeBoxRequestPlayListEvent extends MessageHandler {
|
||||
public void handle() throws Exception {
|
||||
TraxManager traxManager = this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager();
|
||||
this.client.sendResponse(new JukeBoxPlayListComposer(traxManager.getSongs(), traxManager.totalLength()));
|
||||
this.client.sendResponse(new JukeBoxMySongsComposer(traxManager.myList()));
|
||||
this.client.sendResponse(new JukeBoxMySongsComposer(traxManager.myList(this.client.getHabbo())));
|
||||
this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager().updateCurrentPlayingSong(this.client.getHabbo());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user