Dispose games properly upon room disposal

This commit is contained in:
Alejandro 2019-07-30 17:51:27 +03:00
parent 483e7cad69
commit e2c56e6efe
4 changed files with 32 additions and 13 deletions

View File

@ -17,18 +17,15 @@ public class ReloadRoomCommand extends Command {
@Override
public boolean handle(GameClient gameClient, String[] params) throws Exception {
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom();
if (room != null) {
Collection<Habbo> habbos = new ArrayList<>(room.getHabbos());
Emulator.getGameEnvironment().getRoomManager().unloadRoom(room);
room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId());
ServerMessage message = new ForwardToRoomComposer(room.getId()).compose();
for (Habbo habbo : habbos) {
habbo.getClient().sendResponse(message);
}
Emulator.getThreading().run(() -> {
Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom();
if (room != null) {
Collection<Habbo> habbos = new ArrayList<>(room.getHabbos());
Emulator.getGameEnvironment().getRoomManager().unloadRoom(room);
room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId());
ServerMessage message = new ForwardToRoomComposer(room.getId()).compose();
for (Habbo habbo : habbos) {
habbo.getClient().sendResponse(message);
}
}
}, 100);

View File

@ -223,6 +223,14 @@ public abstract class Game implements Runnable {
}
}
public void dispose() {
for (GameTeam team : this.teams.values()) {
team.clearMembers();
}
this.teams.clear();
this.stop();
}
private void saveScores() {
if (this.room == null)

View File

@ -1,6 +1,9 @@
package com.eu.habbo.habbohotel.games;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.plugin.Event;
import com.eu.habbo.plugin.events.games.GameHabboLeaveEvent;
import gnu.trove.set.hash.THashSet;
public class GameTeam {
@ -65,6 +68,16 @@ public class GameTeam {
}
}
public void clearMembers() {
for (GamePlayer player : this.members) {
player.getHabbo().getHabboInfo().getGamePlayer().reset();
player.getHabbo().getHabboInfo().setCurrentGame(null);
player.getHabbo().getHabboInfo().setGamePlayer(null);
}
this.members.clear();
}
public THashSet<GamePlayer> getMembers() {
return this.members;

View File

@ -853,7 +853,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
for (Game game : this.games) {
game.stop();
game.dispose();
}
this.games.clear();
@ -2130,6 +2130,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public boolean deleteGame(Game game) {
game.stop();
game.dispose();
synchronized (this.games) {
return this.games.remove(game);
}