use of me.earth.earthhack.api.setting.Setting in project 3arthh4ck by 3arthqu4ke.
the class ListenerMotion method stack.
private boolean stack() {
ItemStack drag = mc.player.inventory.getItemStack();
if (drag.isEmpty()) {
Map<Item, SettingMap> pref = new HashMap<>();
Map<Item, Map<Integer, Integer>> corresponding = new HashMap<>();
for (int i = 44; i > 8; i--) {
ItemStack stack = InventoryUtil.get(i);
if (stack.isEmpty()) {
continue;
}
Item item = stack.getItem();
Map<Integer, Integer> corr = corresponding.get(item);
if (corr != null) {
if (stack.getCount() >= stack.getMaxStackSize() || corr.containsKey(stack.getCount())) {
continue;
}
corr.put(i, stack.getCount());
} else {
SettingMap map = pref.get(item);
if (map == null) {
Setting<Integer> setting = getSetting(stack);
if (setting == null) {
corr = new HashMap<>();
if (stack.getCount() != stack.getMaxStackSize()) {
corr.put(i, stack.getCount());
}
corresponding.put(item, corr);
continue;
}
map = new SettingMap(setting, new HashMap<>());
pref.put(stack.getItem(), map);
}
map.getMap().put(i, stack.getCount());
}
}
Map<Integer, Map.Entry<Integer, Integer>> best = new TreeMap<>();
for (Map.Entry<Item, SettingMap> entry : pref.entrySet()) {
SettingMap map = entry.getValue();
if (map.getMap().size() < 2 || map.getSetting().getValue() == 0) {
continue;
}
ItemStack deprec = new ItemStack(entry.getKey());
int max = map.getSetting().getValue() * deprec.getMaxStackSize();
int s = 0;
int total = 0;
int fullStacks = 0;
for (int stackCount : map.getMap().values()) {
if (stackCount == deprec.getMaxStackSize()) {
fullStacks++;
}
total += stackCount;
s++;
}
boolean smart = module.smartStack.getValue();
if (total > max && !smart || fullStacks >= map.getSetting().getValue()) {
continue;
}
int m = map.getSetting().getValue();
Map<Integer, Integer> sMap = CollectionUtil.sortByValue(map.getMap());
if (findBest(sMap, entry.getKey(), best, smart, s, m)) {
return true;
}
}
Map.Entry<Integer, Integer> b = best.values().stream().findFirst().orElse(null);
if (b != null) {
click(b.getValue(), b.getKey());
return true;
}
for (Map.Entry<Item, Map<Integer, Integer>> entry : corresponding.entrySet()) {
Map<Integer, Integer> map = entry.getValue();
if (map.size() < 2) {
continue;
}
Map<Integer, Integer> sort = CollectionUtil.sortByValue(map);
if (findBest(sort, entry.getKey(), best, false, 0, 0)) {
return true;
}
}
b = best.values().stream().findFirst().orElse(null);
if (b != null) {
click(b.getValue(), b.getKey());
return true;
}
} else if (module.stackDrag.getValue()) {
Setting<Integer> setting = getSetting(drag);
if (setting != null && setting.getValue() == 0) {
return false;
}
for (int i = 44; i > 8; i--) {
ItemStack stack = InventoryUtil.get(i);
if (InventoryUtil.canStack(stack, drag) && stack.getCount() + drag.getCount() <= stack.getMaxStackSize()) {
int finalI = i;
Item item = stack.getItem();
Locks.acquire(Locks.WINDOW_CLICK_LOCK, () -> {
if (InventoryUtil.get(finalI).getItem() == item) {
InventoryUtil.click(finalI);
}
});
module.timer.reset();
return true;
}
}
}
return false;
}
use of me.earth.earthhack.api.setting.Setting in project 3arthh4ck by 3arthqu4ke.
the class Suicide method onEnable.
@Override
protected void onEnable() {
pos = null;
placed.clear();
if (ask.getValue()) {
displaying = true;
GuiScreen current = mc.currentScreen;
mc.displayGuiScreen(new YesNoNonPausing((r, id) -> {
mc.displayGuiScreen(current);
if (r) {
displaying = false;
} else {
this.disable();
}
}, TextColor.RED + "Do you want to kill yourself? (recommended)", "If you don't want to get asked again," + " turn off the \"Ask\" Setting.", 1337));
return;
}
displaying = false;
if (mode.getValue() == SuicideMode.Command) {
NetworkUtil.sendPacketNoEvent(new CPacketChatMessage("/kill"));
this.disable();
}
}
use of me.earth.earthhack.api.setting.Setting in project 3arthh4ck by 3arthqu4ke.
the class ResetCommand method execute.
@Override
public void execute(String[] args) {
if (args.length < 2) {
ChatUtil.sendMessage("Use this command to reset Modules and Settings.");
return;
}
Module module = Managers.MODULES.getObject(args[1]);
if (module == null) {
ChatUtil.sendMessage(TextColor.RED + "Module " + TextColor.WHITE + args[1] + TextColor.RED + " not found!");
return;
}
if (args.length == 2) {
Scheduler.getInstance().schedule(() -> {
GuiScreen previous = mc.currentScreen;
mc.displayGuiScreen(new YesNoNonPausing((result, id) -> {
mc.displayGuiScreen(previous);
if (!result) {
return;
}
for (Setting<?> setting : module.getSettings()) {
setting.reset();
}
ChatUtil.sendMessage(TextColor.GREEN + "Module " + TextColor.WHITE + module.getName() + TextColor.GREEN + " has been reset.");
}, "Do you really want to reset the Module " + module.getName() + "?", "", 1337));
});
} else {
List<Setting<?>> settings = new ArrayList<>(args.length - 2);
for (int i = 2; i < args.length; i++) {
Setting<?> setting = module.getSetting(args[i]);
if (setting != null) {
settings.add(setting);
} else {
ChatUtil.sendMessage(TextColor.RED + "Could not find Setting " + TextColor.WHITE + args[i] + TextColor.RED + " in module " + TextColor.WHITE + module.getName() + TextColor.RED + ".");
}
}
if (settings.isEmpty()) {
return;
}
StringBuilder settingString = new StringBuilder(TextColor.RED);
settingString.append("Do you really want to reset the Setting");
if (settings.size() > 1) {
settingString.append("s ");
} else {
settingString.append(" ");
}
settingString.append(TextColor.WHITE);
Iterator<Setting<?>> itr = settings.iterator();
while (itr.hasNext()) {
Setting<?> s = itr.next();
settingString.append(s.getName());
if (itr.hasNext()) {
settingString.append(TextColor.RED).append(", ").append(TextColor.WHITE);
}
}
settingString.append(TextColor.RED).append(" in the module ").append(TextColor.WHITE).append(module.getName()).append(TextColor.RED).append("?");
Scheduler.getInstance().schedule(() -> {
GuiScreen previous = mc.currentScreen;
mc.displayGuiScreen(new YesNoNonPausing((result, id) -> {
mc.displayGuiScreen(previous);
if (!result) {
return;
}
for (Setting<?> setting : settings) {
setting.reset();
ChatUtil.sendMessage(TextColor.RED + "Reset " + module.getName() + TextColor.RED + " - " + TextColor.WHITE + setting.getName() + TextColor.RED + ".");
}
}, settingString.toString(), "", 1337));
});
}
}
use of me.earth.earthhack.api.setting.Setting in project 3arthh4ck by 3arthqu4ke.
the class ModuleCommand method onTabComplete.
@Override
public Completer onTabComplete(Completer completer) {
String[] args = completer.getArgs();
if (args.length > 0) {
Module module = getModule(args[0]);
if (module instanceof CustomCommandModule) {
switch(((CustomCommandModule) module).complete(completer)) {
case RETURN:
return completer;
case SUPER:
return super.onTabComplete(completer);
default:
}
}
}
if (completer.isSame()) {
Module module = getModule(args[0]);
if (module == null) {
return super.onTabComplete(completer);
}
if (args.length == 1) {
return completer;
} else if (args.length == 2) {
Optional<Setting<?>> first = module.getSettings().stream().findFirst();
if (!first.isPresent()) {
return completer;
}
if (module instanceof CustomCommandModule) {
String[] custom = ((CustomCommandModule) module).getArgs();
if (custom != null && custom.length > 0) {
boolean found = false;
for (String s : custom) {
if (found) {
completer.setResult(Commands.getPrefix() + args[0] + " " + s);
return completer;
}
if (args[1].equalsIgnoreCase(s)) {
found = true;
}
}
}
}
Setting<?> setting = module.getSetting(args[1]);
if (setting == null) {
completer.setResult(Commands.getPrefix() + args[0] + " " + getEscapedName(first.get().getName()));
return completer;
}
boolean found = false;
for (Setting<?> s : module.getSettings()) {
if (found) {
completer.setResult(Commands.getPrefix() + args[0] + " " + getEscapedName(s.getName()));
return completer;
}
if (s.equals(setting)) {
found = true;
}
}
if (module instanceof CustomCommandModule) {
String[] custom = ((CustomCommandModule) module).getArgs();
if (custom != null && custom.length > 0) {
completer.setResult(Commands.getPrefix() + args[0] + " " + custom[0]);
return completer;
}
}
completer.setResult(Commands.getPrefix() + args[0] + " " + getEscapedName(first.get().getName()));
} else {
if (module instanceof CustomCommandModule) {
String[] custom = ((CustomCommandModule) module).getArgs();
if (custom != null && custom.length > 0) {
for (String s : custom) {
if (args[1].equalsIgnoreCase(s)) {
return completer;
}
}
}
}
Setting<?> setting = module.getSetting(args[2]);
if (setting != null) {
completer.setResult(Commands.getPrefix() + args[0] + " " + Completer.nextValueInSetting(setting, args[args.length - 1]));
}
}
return completer;
}
if (args.length == 2) {
Module module = getModule(args[0]);
if (module == null) {
return completer;
}
Setting<?> setting = CommandUtil.getNameableStartingWith(args[1], module.getSettings());
if (setting == null) {
return completer;
}
return completer.setResult(Commands.getPrefix() + args[0] + " " + getEscapedName(setting.getName()));
}
return super.onTabComplete(completer);
}
use of me.earth.earthhack.api.setting.Setting in project 3arthh4ck by 3arthqu4ke.
the class ListenerTick method doSingleMend.
@SuppressWarnings("unchecked")
private void doSingleMend(ItemStack dragIn, int mendBlock) {
boolean allBlocked = true;
for (SingleMendingSlot singleMendingSlot : module.singleMendingSlots) {
allBlocked = allBlocked && singleMendingSlot.isBlocked();
}
if (allBlocked) {
module.unblockMendingSlots();
}
List<DamageStack> stacks = new ArrayList<>(4);
for (int i = 5; i < 9; i++) {
ItemStack stack = mc.player.inventoryContainer.getSlot(i).getStack();
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.MENDING, stack) != 0) {
float percent = DamageUtil.getPercent(stack);
stacks.add(new DamageStack(stack, percent, i));
}
}
// Most damaged will be first, all others will be taken off.
stacks.sort(Comparator.reverseOrder());
if (stacks.size() <= 0) {
int bestSlot = -1;
MutableWrapper<Float> lowest = new MutableWrapper<>(Float.MAX_VALUE);
MutableWrapper<ItemStack> bestStack = new MutableWrapper<>(ItemStack.EMPTY);
for (SingleMendingSlot singleMendingSlot : module.singleMendingSlots) {
if (!singleMendingSlot.isBlocked()) {
int slot = AutoArmor.iterateItems(XCARRY.isEnabled(), module.queuedSlots, stack -> {
if (AutoArmor.getSlot(stack) == singleMendingSlot.getSlot()) {
float percent = DamageUtil.getPercent(stack);
if (percent < lowest.get()) {
bestStack.set(stack);
lowest.set(percent);
return true;
}
}
return false;
});
bestSlot = slot == -1 ? bestSlot : slot;
}
}
if (bestSlot != -1) {
EntityEquipmentSlot equipmentSlot = AutoArmor.getSlot(bestStack.get());
if (equipmentSlot != null) {
int slot = AutoArmor.fromEquipment(equipmentSlot);
if (bestSlot != -2) {
module.queueClick(bestSlot, bestStack.get(), dragIn, slot).setDoubleClick(module.doubleClicks.getValue());
}
module.queueClick(slot, InventoryUtil.get(slot), bestStack.get());
}
} else if (!allBlocked) {
module.unblockMendingSlots();
}
} else if (stacks.size() == 1) {
DamageStack stack = stacks.get(0);
SingleMendingSlot mendingSlot = Arrays.stream(module.singleMendingSlots).filter(s -> s.getSlot() == AutoArmor.getSlot(stack.getStack())).findFirst().orElse(null);
if (mendingSlot != null && stack.getDamage() > ((Setting<Integer>) module.damages[stack.getSlot() - 5]).getValue()) {
MutableWrapper<ItemStack> drag = new MutableWrapper<>(dragIn);
checkDamageStack(stack, mendBlock, drag);
mendingSlot.setBlocked(true);
}
} else {
MutableWrapper<ItemStack> drag = new MutableWrapper<>(dragIn);
boolean skipFirst = true;
for (DamageStack stack : stacks) {
if (skipFirst) {
skipFirst = false;
continue;
}
if (checkDamageStack(stack, mendBlock, drag)) {
return;
}
}
}
}
Aggregations