since 6 Months i am working with Smartfox for a project of mine.
Till now i was able to solve every problem with checking the Forum or Documentation.
But today i gave up after a sleepless night, and i hope you can help me now.
I want to use the TaskScheduler for starting a RoundTimer. In my Game each Player of a match has 60Second to make his turn. For this i am using the following code
Code: Select all
ScheduledFuture<?> playerTurnTimer;
PlayerTurnTimeoutHandler playerTurnTimeoutHandler;
/**
* Private timer class for the player turn
*/
private class PlayerTurnTimeoutHandler implements Runnable {
public void run() {
try {
AutomizeTurnForPlayer();
} catch (Exception e){
game.trace(ExtensionLogLevel.ERROR, "MatchRound:PlayerTurnTimeoutHandler:run");
game.trace(ExtensionLogLevel.ERROR, e.toString());
} finally {
playerTurnTimer.cancel(true);
}
}
public void init(EnumsUtil.GAME_MODE _gameMode, List<EnumsUtil.GAME_RULE> _rules) {
//prepare the timer for the turns
playerTurnTimeoutHandler = new PlayerTurnTimeoutHandler();
.......
}
/**
* Method to activate the turn timer for the user
*/
public void activateTurnTimer() {
SmartFoxServer sfs = SmartFoxServer.getInstance();
//activate the timer for the user
game.trace("Activate the timer for user:"+activeMatchPlayer.getUser().getName()+" about "+(activeMatchPlayer.getTurnTime()+calculatedDelay)+" Milliseconds");
playerTurnTimer = sfs.getTaskScheduler().schedule(playerTurnTimeoutHandler, activeMatchPlayer.getTurnTime()+calculatedDelay, TimeUnit.MILLISECONDS);
}
i implemented this code into a Class which is working together with a SFSExtension which is used as an extension for a room.
my problem now is that the timer is working randomly one or two times, and then he says he is starting it, but it never finishs.
in generall he was never doing it more then two times. and i dont understand why.
i checked several forum threads about the TaskScheduler and also checked out the Documentation and Example on the Tutorial Page.
what am i doing wrong?
Kind regards
Gardosen