Created
April 6, 2013 14:08
-
-
Save phl0w/5326237 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.powerbot.core.script.ActiveScript; | |
| import org.powerbot.core.script.job.Task; | |
| import org.powerbot.core.script.job.state.Node; | |
| import org.powerbot.core.script.job.state.Tree; | |
| import org.powerbot.core.script.util.Timer; | |
| import org.powerbot.game.api.Manifest; | |
| import org.powerbot.game.api.methods.Game; | |
| import org.powerbot.game.api.methods.Tabs; | |
| import org.powerbot.game.api.methods.Widgets; | |
| import org.powerbot.game.api.methods.input.Keyboard; | |
| import org.powerbot.game.api.methods.interactive.Players; | |
| import org.powerbot.game.api.wrappers.widget.WidgetChild; | |
| import java.util.ArrayList; | |
| @Manifest(name = "ClanChat Destroyer", authors = {"_phl0w"}, version = 1.0d, description = "Destroys clanchats") | |
| public class ClanChatDestroyer extends ActiveScript { | |
| private static String status = "n/a"; | |
| private static String text = "test"; | |
| private static String currentCc = ""; | |
| private static final ArrayList<Node> nodes = new ArrayList<Node>(); | |
| private static final ArrayList<String> clans = new ArrayList<String>(); | |
| private static final ArrayList<String> names = new ArrayList<String>(); | |
| private final Tree jobs = new Tree(new Node[]{new JoinCC(), new LoadNames(), new AddNames(), new RemoveOffline()}); | |
| @Override | |
| public int loop() { | |
| final Node job = jobs.state(); | |
| if (job != null) { | |
| getContainer().submit(job); | |
| jobs.set(job); | |
| job.join(); | |
| } | |
| log.info("loop"); | |
| return 300; | |
| } | |
| public void onStart() { | |
| if (Game.isLoggedIn()) { | |
| status = "Starting up!"; | |
| clans.add("redditfc"); | |
| } else { | |
| stop(); | |
| } | |
| } | |
| public void onStop() { | |
| } | |
| private class JoinCC extends Node { | |
| @Override | |
| public boolean activate() { | |
| return (clans.size() > 0 || !currentCc.equals("")) && names.size() == 0; | |
| } | |
| @Override | |
| public void execute() { | |
| if (Tabs.FRIENDS_CHAT.isOpen()) { | |
| if (Widgets.get(1109, 1).getText().equals("Talking in: Not in chat")) { | |
| currentCc = clans.get(0); | |
| if (!Widgets.get(752, 4).visible()) { | |
| if (Widgets.get(1109, 1).getText().contains("Not in chat")) { | |
| if (Widgets.get(1109, 27).click(true)) { | |
| Task.sleep(400); | |
| } | |
| } | |
| } else { | |
| System.out.println("we suppose to be sending text right nao"); | |
| Keyboard.sendText(currentCc, true); | |
| waitFor(new Condition() { | |
| @Override | |
| public boolean validate() { | |
| return Widgets.get(1109, 1).getText().contains("Talking in"); | |
| } | |
| }, 2000); | |
| clans.remove(currentCc); | |
| currentCc = ""; | |
| } | |
| } else { | |
| log.info("Text"); | |
| } | |
| } else { | |
| Tabs.FRIENDS_CHAT.open(); | |
| } | |
| } | |
| } | |
| private class LoadNames extends Node { | |
| @Override | |
| public boolean activate() { | |
| return names.size() == 0 && Widgets.get(1109, 1).getText().contains("Talking in"); | |
| } | |
| @Override | |
| public void execute() { | |
| if (!Tabs.FRIENDS_CHAT.isOpen()) { | |
| Tabs.FRIENDS_CHAT.open(); | |
| } else { | |
| for (final WidgetChild users : Widgets.get(1109, 5).getChildren()) { | |
| final String user = users.getText(); | |
| if (!names.contains(user) && !user.toLowerCase().contains("mod") && !user.equals(Players.getLocal().getName())) { | |
| names.add(users.getText()); | |
| } | |
| } | |
| if (Widgets.get(1109, 27).click(true)) { | |
| Task.sleep(300, 400); | |
| } | |
| } | |
| log.info("Found: " + names.size() + " users."); | |
| } | |
| } | |
| private class AddNames extends Node { | |
| @Override | |
| public boolean activate() { | |
| return names.size() > 0; | |
| } | |
| @Override | |
| public void execute() { | |
| if (!Tabs.FRIENDS.isOpen()) { | |
| Tabs.FRIENDS.open(); | |
| } else { | |
| for (final String name : names) { | |
| if (Widgets.get(752, 4).isOnScreen()) { | |
| Keyboard.sendText(name, true); | |
| names.remove(name); | |
| } else { | |
| if (Widgets.get(550, 25).click(true)) { | |
| waitFor(new Condition() { | |
| @Override | |
| public boolean validate() { | |
| return Widgets.get(752, 4).isOnScreen(); | |
| } | |
| }, 1000); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| private class RemoveOffline extends Node { | |
| @Override | |
| public boolean activate() { | |
| return names.size() == 0 && Tabs.FRIENDS.isOpen() && Widgets.get(550, 6).getChildren().length > 0; | |
| } | |
| @Override | |
| public void execute() { | |
| final ArrayList<Integer> indexes = new ArrayList<Integer>(); | |
| for (int i = 0; i < Widgets.get(550, 5).getChildren().length; i++) { | |
| if (Widgets.get(550, 5).getChild(i).getText().equals("Offline")) { | |
| indexes.add(i); | |
| } | |
| } | |
| if (indexes.size() > 0) { | |
| for (final WidgetChild c : Widgets.get(550, 6).getChildren()) { | |
| if (indexes.contains(c.getIndex())) { | |
| if (c.interact("Delete")) { | |
| Task.sleep(10, 15); | |
| } | |
| indexes.remove(c.getIndex()); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| private boolean waitFor(final Condition c, final long timeout) { | |
| final Timer t = new Timer(timeout); | |
| while (t.isRunning() && !c.validate()) { | |
| Task.sleep(50, 100); | |
| } | |
| return c.validate(); | |
| } | |
| private interface Condition { | |
| public boolean validate(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment