Everything posted by Botre
-
When your training agility but you get an acceptance letter from Hogwarts
lelel
- rip frostbug
- Veteran
-
Veteran
- Check if item is visible (not blocked by walls etc)
tricky I would suggest you post the problem you are trying to solve with this specific visibility check instead- Best website evur
- [Snippet] Functional operators for Filter & Functional classes (negate, chain, and, or, ...)
Chain, negate, combine, ... Filter Example: public static void main(String[] args) { Filter<String> IS_EMPTY = s -> s.isEmpty(); Filter<String> CONTAINS_O = s -> s.contains("o"); String a = ""; String b = "osbot"; // Check if empty System.out.println(IS_EMPTY.match(a)); //true System.out.println(IS_EMPTY.match(b)); //false //Check if NOT empty System.out.println(FilterOperation.negate(IS_EMPTY).match(a)); //false System.out.println(FilterOperation.negate(IS_EMPTY).match(b)); //true // Check if empty OR contains o System.out.println(FilterOperation.or(IS_EMPTY, CONTAINS_O).match(a)); //true System.out.println(FilterOperation.or(IS_EMPTY, CONTAINS_O).match(b)); //true // Check if empty AND contains o System.out.println(FilterOperation.and(IS_EMPTY, CONTAINS_O).match(a)); //false System.out.println(FilterOperation.and(IS_EMPTY, CONTAINS_O).match(b)); //false } Filter Operations: package org.botre.functional; import org.osbot.rs07.api.filter.Filter; public final class FilterOperation { private FilterOperation() { } /** * Returns a filter that represents the logical negation of the supplied filter. * * @return a filter that represents the logical negation of the supplied filter */ public static final <T> Filter<T> negate(Filter<? super T> filter) { return e -> !filter.match(e); } /** * Returns a filter that represents a short-circuiting logical AND of the supplied filters. * * @return a filter that represents a short-circuiting logical AND of the supplied filters */ @SafeVarargs public static final <T> Filter<T> and(Filter<? super T>... filters) { if(filters.length < 1) throw new IllegalArgumentException(); return new Filter<T>() { @Override public boolean match(T e) { for (Filter<? super T> filter : filters) if(!filter.match(e)) return false; return true; } }; } /** * Returns a composed filter that represents a short-circuiting logical OR of the supplied filters. * * @return a composed filter that represents a short-circuiting logical OR of the supplied filters */ @SafeVarargs public static final <T> Filter<T> or(Filter<? super T>... filters) { if(filters.length < 1) throw new IllegalArgumentException(); return new Filter<T>() { @Override public boolean match(T e) { for (Filter<? super T> filter : filters) if(filter.match(e)) return true; return false; } }; } } Functional Operations: package org.botre.functional; import java.util.function.BooleanSupplier; import java.util.function.Predicate; public final class FunctionalOperation { private FunctionalOperation() { } /** * Returns a composed boolean supplier that represents a short-circuiting logical AND of the supplied boolean suppliers. * * @return a composed boolean supplier that represents a short-circuiting logical AND of the supplied boolean suppliers */ public static final BooleanSupplier and(BooleanSupplier... suppliers) { if(suppliers.length < 1) throw new IllegalArgumentException(); return () -> { for (BooleanSupplier s : suppliers) if(!s.getAsBoolean()) return false; return true; }; } /** * Returns a composed boolean supplier that represents a short-circuiting logical OR of the supplied boolean suppliers. * * @return a composed boolean supplier that represents a short-circuiting logical OR of the supplied boolean suppliers */ public static final BooleanSupplier or(BooleanSupplier... suppliers) { if(suppliers.length < 1) throw new IllegalArgumentException(); return () -> { for (BooleanSupplier s : suppliers) if(s.getAsBoolean()) return true; return false; }; } /** * Returns a composed predicate that represents a short-circuiting logical AND of the supplied predicates. * * @return a composed predicate that represents a short-circuiting logical AND of the supplied predicates */ @SafeVarargs public static final <T> Predicate<T> and(Predicate<T>... predicates) { if(predicates.length < 1) throw new IllegalArgumentException(); Predicate<T> result = predicates[0]; for (int i = 1; i < predicates.length; i++) { result = result.and(predicates[i]); } return result; } /** * Returns a composed predicate that represents a short-circuiting logical OR of the supplied predicates. * * @return a composed predicate that represents a short-circuiting logical OR of the supplied predicates */ @SafeVarargs public static final <T> Predicate<T> or(Predicate<T>... predicates) { if(predicates.length < 1) throw new IllegalArgumentException(); Predicate<T> result = predicates[0]; for (int i = 1; i < predicates.length; i++) { result = result.or(predicates[i]); } return result; } }- @Dbuffed.
- [Snippet] How to negate/invert a Filter
A very basic snippet, I keep seeing people rewriting negations manually way too often. Allows to you create inversions/negations of filters. Example final Filter<String> IS_EMPTY = s -> s.isEmpty(); final Filter<String> IS_NOT_EMPTY = negate(IS_EMPTY); Snippet /** * Returns a filter that represents the logical negation of the supplied filter. * * @return a filter that represents the logical negation of the supplied filter */ public static final <T> Filter<T> negate(Filter<T> filter) { return e -> !filter.match(e); }- Gfx Battle - Help us pick a theme.
Boge- :feels:
Some dark ones in there- Putting conditionalsleep in a method
Use a BooleanSupplier instead of a plain boolean ^^ https://docs.oracle.com/javase/8/docs/api/java/util/function/BooleanSupplier.html- [Snippet / WIP] Auto<T>: auto supply and verify a value
WIP. Automatically check and updates a value, which is one of the most common tasks of a script. Can also be used for caching data and verifying its integrity. Example package org.botre.util; import java.util.function.Predicate; import org.botre.functional.FiPr; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "Botre", info = "", logo = "", name = "AutoExample", version = 0) public class AutoExample extends Script { public Predicate<NPC> VALIDATOR = npc -> npc != null && npc.exists() && npc.getName().equals("Man") && (npc.getInteracting() == null || npc.getInteracting().equals(myPlayer())) && getMap().canReach(npc.getPosition()); private Auto<NPC> target = new Auto<NPC>(() -> getNpcs().closest(FiPr.adapt(VALIDATOR.and(npc -> !npc.isUnderAttack()))), VALIDATOR); @Override public int onLoop() throws InterruptedException { if(!getCombat().isFighting() && target.validate()) { target.get().interact("Attack"); } return 500; } } Snippet: package org.botre.util; import java.util.Optional; import java.util.function.Predicate; import java.util.function.Supplier; public class Auto<T> { private Optional<T> optional; private Supplier<T> supplier; private Predicate<T> validator; public Auto(T value, Supplier<T> supplier, Predicate<T> validator) { this.optional = Optional.ofNullable(value); this.supplier = supplier; this.validator = validator; } public Auto(Supplier<T> supplier, Predicate<T> validator) { this(null, supplier, validator); } public T get() { return optional.get(); } public void supply() { optional = Optional.ofNullable(supplier.get()); } public boolean validate() { if(!optional.isPresent() || !validator.test(optional.get())) supply(); else return true; return optional.isPresent() && validator.test(optional.get()); } }- AutoHotKey-Like Vertical Dropping/Custom Dropping
No. I'm pretty sure ItemContainer's interact(slot, action) method does try to define an Item internally, probably similarly to the way you do it. So he should be fine ^^ PS: here's an old snippet of mine if you're looking for alternative patterns :p http://osbot.org/forum/topic/68138-using-certain-slots-help/?p=750312- Jagex you won. I will stop botting/playing rs
You win some, you lose some. There would be no value in botting if it were riskless.- [Snippet] Throwable decorator with system and memory information
Indeed x) You can decorate strategically or just go all-in, I prefer the former approach so I don't get hugely verbose traces every time I forget a simple null check :p I personally use them mostly to decorate IOException and its sub-classes and Swing-related exceptions.- [Snippet] Throwable decorator with system and memory information
Luckily enough I rarely have to rely on this information When it's usefull it tends to be very usefull and often ends up saving quite a lot of time though :p- AfrostBug
- .
Good job! The buttons seem a bit supersized though x) I like the text balloons, how did you manage to do that in Swing?- [Snippet] Throwable decorator with system and memory information
Useful to spot nasty jvm, system and memory-specific issues (outdated java, exotic operating system, incorrect memory allocation, etc...). I personally only decorate critical / fatal exceptions with this. There's no point in casually wrapping it around everything (unless you really love verbose stack traces). Example: public class Test { public static void main(String[] args) { try { System.out.println(1/0); } catch (Exception e) { ThrowableDecorator.withSystemAndMemoryInformation(e).printStackTrace(); } } } Snippet: public final class ThrowableDecorator { private ThrowableDecorator() { } public static final Throwable withSystemAndMemoryInformation(Throwable throwable) { StringBuilder sb = new StringBuilder(); //System sb.append("\n\tSystem information:"); System.getProperties().entrySet().forEach(entry -> sb.append("\n\t\t" + entry.getKey().toString() + ": " + entry.getValue().toString())); //Memory sb.append("\n\tMemory information:"); sb.append("\n\t\tAvailable processors (cores): " + Runtime.getRuntime().availableProcessors()); sb.append("\n\t\tFree memory (bytes): " + Runtime.getRuntime().freeMemory()); sb.append("\n\t\tMaximum memory (bytes): " + Runtime.getRuntime().maxMemory()); sb.append("\n\t\tTotal memory (bytes): " + Runtime.getRuntime().totalMemory()); return new Throwable(sb.toString(), throwable); } } Example trace: java.lang.Throwable: System information: java.runtime.name: Java(TM) SE Runtime Environment sun.boot.library.path: C:\Program Files\Java\jre1.8.0_77\bin java.vm.version: 25.77-b03 java.vm.vendor: Oracle Corporation java.vendor.url: http://java.oracle.com/ path.separator: ; java.vm.name: Java HotSpot(TM) 64-Bit Server VM file.encoding.pkg: sun.io user.country: GB user.script: sun.java.launcher: SUN_STANDARD sun.os.patch.level: java.vm.specification.name: Java Virtual Machine Specification user.dir: ***** java.runtime.version: 1.8.0_77-b03 java.awt.graphicsenv: sun.awt.Win32GraphicsEnvironment java.endorsed.dirs: C:\Program Files\Java\jre1.8.0_77\lib\endorsed os.arch: amd64 java.io.tmpdir: ***** line.separator: java.vm.specification.vendor: Oracle Corporation user.variant: os.name: Windows 10 sun.jnu.encoding: ****** java.library.path: ***** java.specification.name: Java Platform API Specification java.class.version: 52.0 sun.management.compiler: HotSpot 64-Bit Tiered Compilers os.version: 10.0 user.home:***** user.timezone: java.awt.printerjob: sun.awt.windows.WPrinterJob file.encoding: Cp1252 java.specification.version: 1.8 java.class.path: ***** user.name: bjorn java.vm.specification.version: 1.8 sun.java.command: org.botre.exception.Test java.home: C:\Program Files\Java\jre1.8.0_77 sun.arch.data.model: 64 user.language: en java.specification.vendor: Oracle Corporation awt.toolkit: sun.awt.windows.WToolkit java.vm.info: mixed mode java.version: 1.8.0_77 java.ext.dirs: ***** java.vendor: Oracle Corporation file.separator: \ java.vendor.url.bug: http://bugreport.sun.com/bugreport/ sun.io.unicode.encoding: UnicodeLittle sun.cpu.endian: little sun.desktop: windows sun.cpu.isalist: amd64 Memory information: Available processors (cores): 4 Free memory (bytes): 253398816 Maximum memory (bytes): 3795845120 Total memory (bytes): 257425408 at org.botre.exception.ThrowableDecorator.withSystemAndMemoryInformation(ThrowableDecorator.java:21) at org.botre.exception.Test.main(Test.java:9) Caused by: java.lang.ArithmeticException: / by zero at org.botre.exception.Test.main(Test.java:7)- [Stable] OSBot 2.4.48 - Bug Fixes
- Botre NMZ: Overloads | Absorptions | Prayer | Special Attacks | Powerups
Will be applying for SDN approval shortly! I shall contact you all for testing once this script reaches BETA- Botre Pest Control: Prioritization | Prayer | Special Attacks | Autocasting
Will be applying for SDN approval shortly!- [Snippet] Swing Carousel Panel
Updated to support autoscrolling- [Snippet] Event Decorators: time out & break condition decorations
Updated to use BooleanSupplier instead of Predicate, also added parameter checking for timeout decorator. - Check if item is visible (not blocked by walls etc)