]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Fixes
authorStephen Seo <seo.disparate@gmail.com>
Thu, 18 Oct 2018 05:47:40 +0000 (14:47 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 18 Oct 2018 05:47:40 +0000 (14:47 +0900)
Acutally fix duplicate ".. entered battle" message bug.
Fix potential crash bug.

src/main/java/com/seodisparate/TurnBasedMinecraft/client/BattleGui.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java

index e42b8e3663eee21674f4094d426eb5f4cf09cf36..631a628a98f032d0dc411cdc7634538020bd7b84 100644 (file)
@@ -1,6 +1,7 @@
 package com.seodisparate.TurnBasedMinecraft.client;
 
 import java.io.IOException;
+import java.util.ConcurrentModificationException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -165,32 +166,44 @@ public class BattleGui extends GuiScreen
         case ATTACK_TARGET:
             info = "Who will you attack?";
             int y = 30;
-            for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideAEntrySet())
+            try
             {
-                if(e.getValue().entity != null)
+                for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideAEntrySet())
                 {
-                    buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), true));
+                    if(e.getValue().entity != null)
+                    {
+                        buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), true));
+                    }
+                    else
+                    {
+                        buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, "Unknown", e.getKey(), true));
+                    }
+                    y += 20;
                 }
-                else
-                {
-                    buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, "Unknown", e.getKey(), true));
-                }
-                y += 20;
+            } catch (ConcurrentModificationException e)
+            {
+                // ignored
             }
             y = 30;
-            for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideBEntrySet())
+            try
             {
-                if(e.getValue().entity != null)
+                for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideBEntrySet())
                 {
-                    buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), false));
+                    if(e.getValue().entity != null)
+                    {
+                        buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), false));
+                    }
+                    else
+                    {
+                        buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, "Unknown", e.getKey(), false));
+                    }
+                    y += 20;
                 }
-                else
-                {
-                    buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, "Unknown", e.getKey(), false));
-                }
-                y += 20;
+            } catch (ConcurrentModificationException e)
+            {
+                // ignored
             }
-            buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width/2 - 40, height - 120, 80, 20, "Cancel"));
+            buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width/2 - 30, height - 120, 60, 20, "Cancel"));
             break;
         case ITEM_ACTION:
             info = "What will you do with an item?";
index abb191002ccf91946e6ac8a6fabcebc27feaeaab..065bcf22e9261a48080c3f6e1308dbb13cdb0046 100644 (file)
@@ -256,11 +256,41 @@ public class Battle
     
     public boolean hasCombatant(int entityID)
     {
+        synchronized(sideAEntryQueue)
+        {
+            for(Combatant c : sideAEntryQueue)
+            {
+                if(c.entity.getEntityId() == entityID)
+                {
+                    return true;
+                }
+            }
+        }
+        synchronized(sideBEntryQueue)
+        {
+            for(Combatant c : sideBEntryQueue)
+            {
+                if(c.entity.getEntityId() == entityID)
+                {
+                    return true;
+                }
+            }
+        }
         return sideA.containsKey(entityID) || sideB.containsKey(entityID);
     }
     
     public boolean hasCombatantInSideA(int entityID)
     {
+        synchronized(sideAEntryQueue)
+        {
+            for(Combatant c : sideAEntryQueue)
+            {
+                if(c.entity.getEntityId() == entityID)
+                {
+                    return true;
+                }
+            }
+        }
         return sideA.containsKey(entityID);
     }
     
@@ -775,7 +805,7 @@ public class Battle
                 {
                     turnOrderQueue.add(c);
                 }
-                update(0);
+                return update(0);
             }
             else
             {