]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Minor improvements/fixes
authorStephen Seo <seo.disparate@gmail.com>
Sat, 27 Oct 2018 04:58:19 +0000 (13:58 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sat, 27 Oct 2018 07:26:39 +0000 (16:26 +0900)
src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleUpdater.java

index 8b888d078bcb3bf9b8315a12aefcda1ce207616c..496028d5dc1ac354f3577b39f615b35716447497 100644 (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)
index eada49fee70bba85654ef72a5220ded48ed9b7c8..32eda1af85916e279e65190328d21272f12f7410 100644 (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();
                     }