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 @Override
public boolean handle(GameClient gameClient, String[] params) throws Exception { public boolean handle(GameClient gameClient, String[] params) throws Exception {
Emulator.getThreading().run(new Runnable() { Emulator.getThreading().run(() -> {
@Override Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom();
public void run() { if (room != null) {
Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); Collection<Habbo> habbos = new ArrayList<>(room.getHabbos());
if (room != null) { Emulator.getGameEnvironment().getRoomManager().unloadRoom(room);
Collection<Habbo> habbos = new ArrayList<>(room.getHabbos()); room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId());
Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); ServerMessage message = new ForwardToRoomComposer(room.getId()).compose();
room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId()); for (Habbo habbo : habbos) {
ServerMessage message = new ForwardToRoomComposer(room.getId()).compose(); habbo.getClient().sendResponse(message);
for (Habbo habbo : habbos) {
habbo.getClient().sendResponse(message);
}
} }
} }
}, 100); }, 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() { private void saveScores() {
if (this.room == null) if (this.room == null)

View File

@ -1,6 +1,9 @@
package com.eu.habbo.habbohotel.games; package com.eu.habbo.habbohotel.games;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.users.Habbo; 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; import gnu.trove.set.hash.THashSet;
public class GameTeam { 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() { public THashSet<GamePlayer> getMembers() {
return this.members; return this.members;

View File

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