I was getting sick of seeing the same old tutorial being reposted over, and over again. Then seeing people repost the reposts, then the original reposters complaining that it was stolen off them.
Using Robot to take screenshots is reading the output of the screen directly. It can lead to the screenshots being incomplete, and also might cause security issues on certain operating systems in the future (it's the control which is used in java to move the mouse, it's only a matter of time before Mac exclude it. They already change it with their own class)
So, here's a method of taking screenshots by making the client draw directly to a file, instead of drawing to the screen, reading the screen and then outputting a certain part of it to a file.
Step 1
Open client.java
Add this at the top:
Code:
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Calendar;
import javax.imageio.ImageIO;
Declare the following
Code:
public boolean ssQueued = false;
Then, find
Code:
public void processDrawing() {
Below
Add this
Code:
Graphics oG = null;
BufferedImage ssImage = null;
if (ssQueued) {
oG = super.graphics;
ssImage = new BufferedImage(super.getWidth(), super.getHeight(), BufferedImage.TYPE_INT_ARGB);
super.graphics = ssImage.getGraphics();
}
Then below
Code:
if (!loggedIn)
drawLoginScreen(false);
else
drawGameScreen();
Add
Code:
if (ssQueued) {
ssQueued = false;
super.graphics = oG;
try {
if (!new File(signlink.findcachedir(), "Screenshots").isDirectory()) new File(signlink.findcachedir(), "Screenshots").mkdirs();
Calendar c = Calendar.getInstance();
File outFile = new File(signlink.findcachedir(), "Screenshots/"+c.get(Calendar.DAY_OF_MONTH)+"/"+c.get(Calendar.MONTH)+"/"+c.get(Calendar.YEAR)+" "+c.get(Calendar.HOUR_OF_DAY)+":"+c.get(Calendar.MINUTE)+":"+c.get(Calendar.SECOND)+"::"+c.get(Calendar.MILLISECOND)+".png");
ImageIO.write(ssImage, "png", outFile);
pushMessage("Screenshot saved to:", 0, "");
pushMessage(outFile.getAbsolutePath(), 0, "");
} catch (Exception e) {
e.printStackTrace();
pushMessage("Error saving screenshot.", 0, "");
}
super.graphics.drawImage(ssImage, 0, 0, null);
}
You may need to edit signlink, and make findcachedir() public.
Now, people, please stop using Robot to take screenshots.
To add this to your JFrame, make the button set ssQueued in Client to true. Here's how to do it by :: command.
Find
Code:
if (inputString.equals("::clientdrop"))
Above
Code:
if (myPrivilege == 2) {
Add
Code:
if (inputString.equals("::screenshot")) {
inputTaken = true;
inputString = "";
ssQueued = true;
}