From 1f4d10787081b099aafe790549a4c688a5aa3996 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Sat, 27 Oct 2018 13:58:19 +0900 Subject: [PATCH] Minor improvements/fixes --- .../TurnBasedMinecraft/common/Battle.java | 23 +++++++------------ .../common/BattleUpdater.java | 23 ++++++++++++------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java index 8b888d0..496028d 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java @@ -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) diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleUpdater.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleUpdater.java index eada49f..32eda1a 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleUpdater.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleUpdater.java @@ -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(); }