Fix timers running twice

This commit is contained in:
Beny 2019-05-24 12:12:22 +01:00
parent ca3cdb8bc7
commit f89a0b318d

View File

@ -29,6 +29,7 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
private int timeNow = 0; private int timeNow = 0;
private boolean isRunning = false; private boolean isRunning = false;
private boolean isPaused = false; private boolean isPaused = false;
private boolean threadActive = false;
public InteractionGameTimer(ResultSet set, Item baseItem) throws SQLException public InteractionGameTimer(ResultSet set, Item baseItem) throws SQLException
{ {
@ -59,15 +60,20 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
super.run(); super.run();
} }
if(this.getRoomId() == 0) if(this.getRoomId() == 0) {
this.threadActive = false;
return; return;
}
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if(room == null || !this.isRunning || this.isPaused) if(room == null || !this.isRunning || this.isPaused) {
this.threadActive = false;
return; return;
}
if(this.timeNow > 0) { if(this.timeNow > 0) {
this.threadActive = true;
Emulator.getThreading().run(this, 1000); Emulator.getThreading().run(this, 1000);
this.timeNow--; this.timeNow--;
room.updateItem(this); room.updateItem(this);
@ -75,6 +81,7 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
else { else {
this.isRunning = false; this.isRunning = false;
this.isPaused = false; this.isPaused = false;
this.threadActive = false;
endGamesIfLastTimer(room); endGamesIfLastTimer(room);
} }
} }
@ -178,8 +185,11 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
room.updateItem(this); room.updateItem(this);
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[] { }); WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[] { });
if(!this.threadActive) {
this.threadActive = true;
Emulator.getThreading().run(this); Emulator.getThreading().run(this);
} }
}
else if(client != null) else if(client != null)
{ {
if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER))) if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER)))
@ -217,9 +227,13 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
this.isRunning = true; this.isRunning = true;
timeNow = this.baseTime; timeNow = this.baseTime;
room.updateItem(this); room.updateItem(this);
if(!this.threadActive) {
this.threadActive = true;
Emulator.getThreading().run(this); Emulator.getThreading().run(this);
} }
} }
}
if(!this.isRunning) { if(!this.isRunning) {
endGamesIfLastTimer(room); endGamesIfLastTimer(room);
@ -233,8 +247,12 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
this.isRunning = true; this.isRunning = true;
timeNow = this.baseTime; timeNow = this.baseTime;
room.updateItem(this); room.updateItem(this);
if(!this.threadActive) {
this.threadActive = true;
Emulator.getThreading().run(this); Emulator.getThreading().run(this);
} }
}
break; break;
case 2: case 2: