Skip to content

Commit

Permalink
waitFor bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
1Ridav committed May 18, 2018
1 parent e049eb1 commit ddcb686
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/main/java/bot/penguee/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void mouseClick(MatrixPosition mp, int button_mask) throws AWTException {
public void mouseClick(MatrixPosition mp, int button_mask, int sleepTime) throws AWTException {
mouseClick(mp.x, mp.y, button_mask, sleepTime);
}

public void mouseWheel(int wheel) {
robot.mouseWheel(wheel);
}
Expand Down Expand Up @@ -193,6 +193,7 @@ public boolean waitFor(String fragName, int time, int delay, MatrixPosition mp1,
throws FragmentNotLoadedException, ScreenNotGrabbedException, Exception {
long timeStop = System.currentTimeMillis() + time;
MatrixPosition[] searchRectBackup = screen.getSearchRect();
boolean searchInRegionBackup = screen.getSearchInRegion();
searchRect(mp1, mp2);
boolean result = false;

Expand All @@ -204,7 +205,10 @@ public boolean waitFor(String fragName, int time, int delay, MatrixPosition mp1,
}
sleep(delay);
}
searchRect(searchRectBackup[0], searchRectBackup[1]);
if (searchInRegionBackup)
searchRect(searchRectBackup[0], searchRectBackup[1]);
else
searchRect();
return result;
}

Expand Down Expand Up @@ -291,11 +295,11 @@ public void print(String text) throws AWTException {
write(text);
paste();
}

public void writeClipboard(String text) {
write(text);
}

public String readClipboard() {
return read();
}
Expand Down Expand Up @@ -384,24 +388,22 @@ private void write(String text) {
Clipboard clipboard = getSystemClipboard();
clipboard.setContents(new StringSelection(text), null);
}

private String read(){
try {
return (String)getSystemClipboard().getData(DataFlavor.stringFlavor);
} catch (HeadlessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedFlavorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}



private String read() {
try {
return (String) getSystemClipboard().getData(DataFlavor.stringFlavor);
} catch (HeadlessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedFlavorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}

private void paste() throws AWTException {
keyPress(KeyEvent.VK_CONTROL, KeyEvent.VK_V);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/bot/penguee/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public void setSearchRect() {
public MatrixPosition[] getSearchRect() {
return new MatrixPosition[] {searchRectPos1, searchRectPos2};
}
public boolean getSearchInRegion() {
return searchInRegion;
}

public MatrixPosition find(Frag smallFragment) throws ScreenNotGrabbedException {
MatrixPosition cachedPos = null;
Expand Down

0 comments on commit ddcb686

Please sign in to comment.