From 016fb611af6fabaedfe4872eb634b9eab1db85d9 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 4 Jun 2023 23:58:39 -0500 Subject: [PATCH] Need a lock on the list as we update it between threads --- sig/App.java | 118 ++++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/sig/App.java b/sig/App.java index eae5067..1dfb6dc 100644 --- a/sig/App.java +++ b/sig/App.java @@ -394,67 +394,69 @@ class Server @Override public void run() { while (true){ - for (String command:commandQueue){ - switch (command){ - case "FOLLOW":{ - PressKeyWithModifier(KeyEvent.VK_CONTROL,KeyEvent.VK_7); - }break; - case "FORWARD":{ - r.keyPress(KeyEvent.VK_W); - r.delay(1000); - r.keyRelease(KeyEvent.VK_W); - }break; - case "BACKWARD":{ - r.keyPress(KeyEvent.VK_S); - r.delay(1000); - r.keyRelease(KeyEvent.VK_S); - }break; - case "LEFT":{ - r.keyPress(KeyEvent.VK_Q); - r.delay(1000); - r.keyRelease(KeyEvent.VK_Q); - }break; - case "RIGHT":{ - r.keyPress(KeyEvent.VK_E); - r.delay(1000); - r.keyRelease(KeyEvent.VK_E); - }break; - case "FIGHT":{ - fighting=true; - fightingaoe=false; - System.out.println("Fight mode: "+fighting); - }break; - case "FIGHTAOE":{ - fighting=fightingaoe=true; - System.out.println("Fight mode: "+fighting); - }break; - case "CHILL":{ - fighting=false; - System.out.println("Fight mode: "+fighting); - }break; - case "PASS":{ - System.out.println("Mythra's Health: "+GetMythraHealth()+"%"); - System.out.println("Aya's Health: "+GetAyaHealth()+"%"); - System.out.println("Target's Health: "+GetTargetHealth()+"%"); - }break; - case "SPRINT":{ - if (nextActionTimer==0){ - PressKey(KeyEvent.VK_N); - r.delay(100); - PressKey(KeyEvent.VK_N); - } else { - queueUpSprint=true; + synchronized (commandQueue){ + commandQueue.forEach((command)->{ + switch (command){ + case "FOLLOW":{ + PressKeyWithModifier(KeyEvent.VK_CONTROL,KeyEvent.VK_7); + }break; + case "FORWARD":{ + r.keyPress(KeyEvent.VK_W); + r.delay(1000); + r.keyRelease(KeyEvent.VK_W); + }break; + case "BACKWARD":{ + r.keyPress(KeyEvent.VK_S); + r.delay(1000); + r.keyRelease(KeyEvent.VK_S); + }break; + case "LEFT":{ + r.keyPress(KeyEvent.VK_Q); + r.delay(1000); + r.keyRelease(KeyEvent.VK_Q); + }break; + case "RIGHT":{ + r.keyPress(KeyEvent.VK_E); + r.delay(1000); + r.keyRelease(KeyEvent.VK_E); + }break; + case "FIGHT":{ + fighting=true; + fightingaoe=false; + System.out.println("Fight mode: "+fighting); + }break; + case "FIGHTAOE":{ + fighting=fightingaoe=true; + System.out.println("Fight mode: "+fighting); + }break; + case "CHILL":{ + fighting=false; + System.out.println("Fight mode: "+fighting); + }break; + case "PASS":{ + System.out.println("Mythra's Health: "+GetMythraHealth()+"%"); + System.out.println("Aya's Health: "+GetAyaHealth()+"%"); + System.out.println("Target's Health: "+GetTargetHealth()+"%"); + }break; + case "SPRINT":{ + if (nextActionTimer==0){ + PressKey(KeyEvent.VK_N); + r.delay(100); + PressKey(KeyEvent.VK_N); + } else { + queueUpSprint=true; + } + }break; + case "UPDATE":{ + + }break; + default:{ + System.out.println("Unknown command: "+command); } - }break; - case "UPDATE":{ - - }break; - default:{ - System.out.println("Unknown command: "+command); } - } + }); + commandQueue.clear(); } - commandQueue.clear(); if (queueUpSprint&&nextActionTimer==0){ PressKey(KeyEvent.VK_N);