Minor improvements/fixes

This commit is contained in:
Stephen Seo 2018-10-27 13:58:19 +09:00
parent ded3584390
commit 1f4d107870
2 changed files with 23 additions and 23 deletions

View file

@ -528,13 +528,16 @@ public class Battle
public int getSize()
{
int size = sideA.size() + sideB.size();
synchronized(sideAEntryQueue)
{
synchronized(sideBEntryQueue)
{
return sideA.size() + sideB.size() + sideAEntryQueue.size() + sideBEntryQueue.size();
}
size += sideAEntryQueue.size();
}
synchronized(sideBEntryQueue)
{
size += sideBEntryQueue.size();
}
return size;
}
protected void notifyPlayersBattleInfo()
@ -552,17 +555,7 @@ public class Battle
protected void sendMessageToAllPlayers(PacketBattleMessage.MessageType type, int from, int to, int amount)
{
if(!isServer)
{
return;
}
for(Combatant p : players.values())
{
if(p.entity.isEntityAlive())
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketBattleMessage(type, from, to, amount), (EntityPlayerMP)p.entity);
}
}
sendMessageToAllPlayers(type, from, to, amount, new String());
}
protected void sendMessageToAllPlayers(PacketBattleMessage.MessageType type, int from, int to, int amount, String custom)

View file

@ -57,17 +57,24 @@ public class BattleUpdater implements Runnable
UpdateRunnable updateRunnable = new UpdateRunnable(entry.getValue());
Thread updateThread = new Thread(updateRunnable);
updateThread.start();
try
{
updateThread.join(10000);
} catch(InterruptedException e){ /* exception ignored */ }
try { updateThread.join(2000); } catch(InterruptedException e){ /* exception ignored */ }
if(!updateRunnable.isFinished())
{
// TODO this is an ugly fix to a still-not-found freeze bug in Battle.update()
TurnBasedMinecraftMod.logger.error("Battle (" + entry.getValue().getId() + "; " + entry.getValue().debugLog + ") update timed out!");
updateThread.stop();
TurnBasedMinecraftMod.logger.warn("Battle (" + entry.getValue().getId() + "; " + entry.getValue().debugLog + ") update hanged for 2 seconds!");
try { updateThread.join(2000); } catch(InterruptedException e){ /* exception ignored */ }
if(!updateRunnable.isFinished())
{
TurnBasedMinecraftMod.logger.warn("Battle (" + entry.getValue().getId() + "; " + entry.getValue().debugLog + ") update hanged for 4 seconds!");
try { updateThread.join(4000); } catch(InterruptedException e){ /* exception ignored */ }
if(!updateRunnable.isFinished())
{
// TODO this is an ugly fix to a still-not-found freeze bug in Battle.update()
TurnBasedMinecraftMod.logger.error("Battle (" + entry.getValue().getId() + "; " + entry.getValue().debugLog + ") update timed out!");
updateThread.stop();
}
}
}
else if(updateRunnable.isBattleFinished())
if(updateRunnable.isFinished() && updateRunnable.isBattleFinished())
{
iter.remove();
}