Updates and rework to use CScript
This commit is contained in:
@ -7,6 +7,7 @@ import net.runelite.api.ItemID;
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum Ashes {
|
||||
NONE(-1),
|
||||
FIENDISH_ASHES(ItemID.FIENDISH_ASHES),
|
||||
VILE_ASHES(ItemID.VILE_ASHES),
|
||||
MALICIOUS_ASHES(ItemID.MALICIOUS_ASHES),
|
||||
@ -14,4 +15,21 @@ public enum Ashes {
|
||||
INFERNAL_ASHES(ItemID.INFERNAL_ASHES);
|
||||
|
||||
private final int id;
|
||||
|
||||
static Ashes[] allBelow(Ashes ashes) {
|
||||
if (ashes == NONE) return new Ashes[0];
|
||||
|
||||
Ashes[] allBelow = new Ashes[ashes.ordinal()];
|
||||
int i = 0;
|
||||
|
||||
for (Ashes a : Ashes.values()) {
|
||||
if (a == NONE) continue;
|
||||
|
||||
allBelow[i++] = a;
|
||||
|
||||
if (a == ashes) break;
|
||||
}
|
||||
|
||||
return allBelow;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import com.google.inject.Provides;
|
||||
import io.reisub.openosrs.util.Util;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.events.ConfigButtonClicked;
|
||||
import net.runelite.api.events.ItemContainerChanged;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
@ -13,13 +12,10 @@ import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDependency;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.plugins.iutils.game.Game;
|
||||
import net.runelite.client.plugins.iutils.game.InventoryItem;
|
||||
import net.runelite.client.plugins.iutils.iUtils;
|
||||
import org.pf4j.Extension;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -48,12 +44,16 @@ public class Autobones extends Plugin {
|
||||
return configManager.getConfig(Config.class);
|
||||
}
|
||||
|
||||
private int[] itemIds;
|
||||
|
||||
private ScheduledExecutorService executor;
|
||||
|
||||
@Override
|
||||
protected void startUp() {
|
||||
log.info("Starting Chaos Autobones");
|
||||
|
||||
itemIds = parseItemIds();
|
||||
|
||||
executor = Executors.newSingleThreadScheduledExecutor();
|
||||
}
|
||||
|
||||
@ -61,9 +61,19 @@ public class Autobones extends Plugin {
|
||||
protected void shutDown() {
|
||||
log.info("Stopping Chaos Autobones");
|
||||
|
||||
itemIds = null;
|
||||
|
||||
executor.shutdownNow();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Subscribe
|
||||
private void onConfigChanged(ConfigChanged event) {
|
||||
if (event.getGroup().equals("chaosautobones")) {
|
||||
itemIds = parseItemIds();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Subscribe
|
||||
private void onItemContainerChanged(ItemContainerChanged event) {
|
||||
@ -72,7 +82,34 @@ public class Autobones extends Plugin {
|
||||
if (config.bones().getId() == -1 && config.ashes().getId() == -1) return;
|
||||
|
||||
executor.schedule(() -> {
|
||||
game.inventory().withId(config.bones().getId(), config.ashes().getId()).first().interact(0);
|
||||
game.inventory().withId(itemIds).first().interact(0);
|
||||
}, 0, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private int[] parseItemIds() {
|
||||
int[] ids;
|
||||
|
||||
if (config.allBelow()) {
|
||||
Ashes[] allAshes = Ashes.allBelow(config.ashes());
|
||||
Bones[] allBones = Bones.allBelow(config.bones());
|
||||
|
||||
ids = new int[allAshes.length + allBones.length];
|
||||
int i = 0;
|
||||
|
||||
for (Ashes a : allAshes) {
|
||||
ids[i++] = a.getId();
|
||||
}
|
||||
|
||||
for (Bones b : allBones) {
|
||||
ids[i++] = b.getId();
|
||||
}
|
||||
} else {
|
||||
ids = new int[2];
|
||||
|
||||
ids[0] = config.ashes().getId();
|
||||
ids[1] = config.bones().getId();
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
}
|
@ -31,4 +31,21 @@ public enum Bones {
|
||||
SUPERIOR_DRAGON_BONES(ItemID.SUPERIOR_DRAGON_BONES);
|
||||
|
||||
private final int id;
|
||||
|
||||
static Bones[] allBelow(Bones bones) {
|
||||
if (bones == NONE) return new Bones[0];
|
||||
|
||||
Bones[] allBelow = new Bones[bones.ordinal()];
|
||||
int i = 0;
|
||||
|
||||
for (Bones b : Bones.values()) {
|
||||
if (b == NONE) continue;
|
||||
|
||||
allBelow[i++] = b;
|
||||
|
||||
if (b == bones) break;
|
||||
}
|
||||
|
||||
return allBelow;
|
||||
}
|
||||
}
|
||||
|
@ -45,4 +45,12 @@ public interface Config extends net.runelite.client.config.Config {
|
||||
position = 1
|
||||
)
|
||||
default Ashes ashes() { return Ashes.VILE_ASHES; }
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "allBelow",
|
||||
name = "Bury/scatter all below threshold",
|
||||
description = "Bury/scatter all the bones/ashes of lower value including the chosen bones/ashes.",
|
||||
position = 2
|
||||
)
|
||||
default boolean allBelow() { return true; }
|
||||
}
|
Reference in New Issue
Block a user