Skip to content

Instantly share code, notes, and snippets.

Created March 3, 2016 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c55ff4c02d1d5f7585d7 to your computer and use it in GitHub Desktop.
Save anonymous/c55ff4c02d1d5f7585d7 to your computer and use it in GitHub Desktop.
AFK Script
package scripts.AFK_Script;
import javax.swing.*;
public class AFKGUI extends JFrame {
public AFKGUI(String title) {
super(title);
setResizable(false);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (UnsupportedLookAndFeelException | ClassNotFoundException | IllegalAccessException | InstantiationException e) {
e.printStackTrace();
}
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
hourSpinner = new JSpinner();
startButton = new JButton();
jPanel1 = new JPanel();
jLabel1 = new JLabel();
startButton.setText("Start");
startButton.addActionListener(e -> {
Var.hours = Integer.parseInt(hourSpinner.getValue().toString());
setVisible(false);
});
jPanel1.setBorder(BorderFactory.createTitledBorder("Settings"));
jLabel1.setText("Hours to remain logged in for");
jLabel1.setToolTipText("");
hourSpinner.setModel(new SpinnerNumberModel(17, 1, 120, 1));
GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(hourSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(hourSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
.addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(startButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(startButton)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}
private JSpinner hourSpinner;
private JLabel jLabel1;
private JPanel jPanel1;
private JButton startButton;
}
package scripts.AFK_Script;
import org.tribot.api.util.abc.ABCUtil;
import org.tribot.script.ScriptManifest;
import org.tribot.script.interfaces.Painting;
import org.tribot.script.interfaces.Starting;
import java.awt.*;
@ScriptManifest(
version = 0.001,
authors = "Flamo353",
name = "(F) AFK Script",
category = "Tools",
description = "Script will AFK for the amount of hours specified in the GUI."
)
public class AFKScript extends LoopingScript implements Starting, Painting {
private Painter painter = new Painter(4, 35, 15, this);
private AFKGUI gui = new AFKGUI("AFK Script");
private ABCUtil abc = new ABCUtil();
@Override
public void onStart() {
gui.setVisible(true);
setAIAntibanState(true);
}
@Override
public boolean onLoop() {
return gui.isVisible() || !gui.isVisible() && getRunningTime() < Var.hours * 3600000;
}
@Override
public void onPaint(Graphics g) {
if (!gui.isVisible()) {
painter.drawTo(g);
}
}
}
package scripts.AFK_Script;
import org.tribot.api.General;
import org.tribot.script.Script;
public abstract class LoopingScript extends Script {
@Override
public void run() {
while (onLoop()) {
sleep(General.random(100, 200));
}
}
public abstract boolean onLoop();
}
package scripts.AFK_Script;
import org.tribot.api.Timing;
import java.awt.*;
public class Painter {
private final RenderingHints antialiasing = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
private final Color TRANSLUCENT_BLACK = new Color(0, 0, 0, 140);
private AFKScript afkScript;
private int baseX;
private int baseY;
private int spacing;
private int rows;
public Painter(int baseX, int baseY, int spacing, AFKScript afkScript) {
this.baseX = baseX;
this.baseY = baseY;
this.spacing = spacing;
this.afkScript = afkScript;
}
public void drawTo(Graphics g) {
//add antialiasing
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHints(antialiasing);
//set statistics
long timeElapsed = afkScript.getRunningTime();
String[] statistics = new String[] {
"Time Elapsed: " + Timing.msToString(timeElapsed),
"Time Remaining: " + Timing.msToString(Var.hours * 3600000 - timeElapsed),
"Hours set: " + Var.hours
};
//draw background
g2d.setColor(TRANSLUCENT_BLACK);
g2d.fillRect(baseX, baseY - spacing, 150, spacing * statistics.length + 6); //got lazy
g2d.setColor(Color.WHITE);
//draw statistics
for (String s : statistics) {
g2d.drawString(s, baseX, nextRow());
}
resetRows();
}
private int nextRow() {
rows++;
return baseY + (rows - 1) * spacing;
}
private void resetRows() {
rows = 0;
}
}
package scripts.AFK_Script;
public class Var {
public static int hours;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment