Could anyone share some improvements I can make to this script?
public class Main extends Script {
GUI gui = new GUI();
private NPC monster;
private long startTime;
public enum State {
splash,
splashAlch
}
@Override
public int onLoop() throws InterruptedException {
if (Settings.started) {
if (!Settings.monsterName.isEmpty() && Settings.monsterName != null) {
monster = npcs.closest(Settings.monsterName);
} else {
log("Enter a real monster name.");
stop();
}
if (!magic.canCast(Settings.spellToCast)) {
log("Cant cast spell");
stop();
}
switch (getState()) {
case splash:
if (monster != null && monster.isVisible()) {
if (magic.castSpellOnEntity(Settings.spellToCast, monster)) {
new ConditionalSleep(3000) {
@Override
public boolean condition() throws InterruptedException {
return myPlayer().isAnimating();
}
}.sleep();
new ConditionalSleep(3000) {
@Override
public boolean condition() throws InterruptedException {
return !myPlayer().isAnimating();
}
}.sleep();
}
} else {
camera.toEntity(monster);
}
break;
case splashAlch:
if (monster != null && monster.isVisible()) {
if (magic.castSpellOnEntity(Settings.spellToCast, monster)) {
sleep(random(150, 400));
if (magic.canCast(Spells.NormalSpells.HIGH_LEVEL_ALCHEMY)) {
if (magic.castSpell(Spells.NormalSpells.HIGH_LEVEL_ALCHEMY)) {
new ConditionalSleep(2000) {
@Override
public boolean condition() throws InterruptedException {
return tabs.getOpen().equals(Tab.INVENTORY);
}
}.sleep();
sleep(random(50, 150));
if (mouse.click(inventory.getMouseDestination(inventory.getSlot(Settings.alchName)), false)) {
new ConditionalSleep(3000) {
@Override
public boolean condition() throws InterruptedException {
return tabs.getOpen().equals(Tab.MAGIC);
}
}.sleep();
sleep(random(150, 400));
}
}
} else {
log("Can't cast High Alchemy");
stop();
}
}
}
break;
}
}
return 120;
}
public State getState() {
return ((skills.getDynamic(Skill.MAGIC) >= 55) && Settings.alch) ? State.splashAlch : State.splash;
}
@Override
public void onStart() throws InterruptedException {
log("Nimmogel's 1-99 Magic has started :D");
gui.createGui();
experienceTracker.start(Skill.MAGIC);
Methods methods = new Methods(this);
Settings.spellToCast = methods.spellToCastFinder();
startTime = System.currentTimeMillis();
}
public void onMessage(Message message) throws InterruptedException {
String text = message.getMessage().toLowerCase();
if (text.contains("advanced a")) {
Methods methods = new Methods(this);
Settings.spellToCast = methods.spellToCastFinder();
}
}
@Override
public void onExit() throws InterruptedException {
log("Bye :D");
if (gui !=null) {
gui.setVisible(false);
gui.dispose();
}
}
@Override
public void onPaint(Graphics2D g) {
long runTime = System.currentTimeMillis() - startTime;
long tillNextLevel = experienceTracker.getTimeToLevel(Skill.MAGIC);
long second = runTime / 1000L % 60L;
long minute = runTime / 60000L % 60L;
long hour = runTime / 3600000L % 24L;
long secondX = tillNextLevel / 1000L % 60L;
long minuteX = tillNextLevel / 60000L % 60L;
long hourX = tillNextLevel / 3600000L % 24L;
g.setColor(Color.WHITE);
g.drawString("Time running: " + String.format("%d:%02d:%02d", hour, minute, second), 300, 285);
g.drawString("EXP: " + experienceTracker.getGainedXP(Skill.MAGIC) + " (" + experienceTracker.getGainedXPPerHour(Skill.MAGIC) + "/hr)", 300, 300);
g.drawString("Level: " + skills.getDynamic(Skill.MAGIC) + "(" + String.format("%02d:%02d:%02d", hourX, minuteX, secondX) + ")", 300, 315);
}
}