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() public int getSize()
{ {
int size = sideA.size() + sideB.size();
synchronized(sideAEntryQueue) synchronized(sideAEntryQueue)
{ {
synchronized(sideBEntryQueue) size += sideAEntryQueue.size();
{
return sideA.size() + sideB.size() + sideAEntryQueue.size() + sideBEntryQueue.size();
}
} }
synchronized(sideBEntryQueue)
{
size += sideBEntryQueue.size();
}
return size;
} }
protected void notifyPlayersBattleInfo() protected void notifyPlayersBattleInfo()
@ -552,17 +555,7 @@ public class Battle
protected void sendMessageToAllPlayers(PacketBattleMessage.MessageType type, int from, int to, int amount) protected void sendMessageToAllPlayers(PacketBattleMessage.MessageType type, int from, int to, int amount)
{ {
if(!isServer) sendMessageToAllPlayers(type, from, to, amount, new String());
{
return;
}
for(Combatant p : players.values())
{
if(p.entity.isEntityAlive())
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketBattleMessage(type, from, to, amount), (EntityPlayerMP)p.entity);
}
}
} }
protected void sendMessageToAllPlayers(PacketBattleMessage.MessageType type, int from, int to, int amount, String custom) 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()); UpdateRunnable updateRunnable = new UpdateRunnable(entry.getValue());
Thread updateThread = new Thread(updateRunnable); Thread updateThread = new Thread(updateRunnable);
updateThread.start(); updateThread.start();
try try { updateThread.join(2000); } catch(InterruptedException e){ /* exception ignored */ }
{
updateThread.join(10000);
} catch(InterruptedException e){ /* exception ignored */ }
if(!updateRunnable.isFinished()) if(!updateRunnable.isFinished())
{ {
// TODO this is an ugly fix to a still-not-found freeze bug in Battle.update() TurnBasedMinecraftMod.logger.warn("Battle (" + entry.getValue().getId() + "; " + entry.getValue().debugLog + ") update hanged for 2 seconds!");
TurnBasedMinecraftMod.logger.error("Battle (" + entry.getValue().getId() + "; " + entry.getValue().debugLog + ") update timed out!"); try { updateThread.join(2000); } catch(InterruptedException e){ /* exception ignored */ }
updateThread.stop(); 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(); iter.remove();
} }