├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── icon.png ├── images ├── buys.png ├── card.png ├── customize.png ├── demo.gif ├── editor.png ├── favorites.png ├── flipping.png ├── flippingtabpic.png ├── flips.png ├── lookup.png ├── manual.png ├── multiacc.png ├── offers.png ├── recipeCreation.png ├── recipeCreationStep.png ├── statCard.png ├── stats.png ├── statscard.png ├── statstab.png ├── timer.png ├── times.png └── viewRecipes.png ├── runelite-plugin.properties ├── settings.gradle └── src ├── main ├── java │ └── com │ │ └── flippingutilities │ │ ├── FlippingConfig.java │ │ ├── controller │ │ ├── ApiAuthHandler.java │ │ ├── ApiRequestHandler.java │ │ ├── DataHandler.java │ │ ├── FlippingItemHandler.java │ │ ├── FlippingPlugin.java │ │ ├── GameUiChangesHandler.java │ │ ├── NewOfferEventPipelineHandler.java │ │ ├── OptionHandler.java │ │ └── RecipeHandler.java │ │ ├── db │ │ └── TradePersister.java │ │ ├── jobs │ │ ├── CacheUpdaterJob.java │ │ ├── SlotSenderJob.java │ │ └── WikiDataFetcherJob.java │ │ ├── model │ │ ├── AccountData.java │ │ ├── AccountWideData.java │ │ ├── BackupCheckpoints.java │ │ ├── Flip.java │ │ ├── FlippingItem.java │ │ ├── HistoryManager.java │ │ ├── OfferEvent.java │ │ ├── Option.java │ │ ├── PartialOffer.java │ │ ├── RecipeFlip.java │ │ ├── RecipeFlipGroup.java │ │ └── Section.java │ │ ├── ui │ │ ├── MasterPanel.java │ │ ├── flipping │ │ │ ├── CustomizationPanel.java │ │ │ ├── FlippingItemPanel.java │ │ │ └── FlippingPanel.java │ │ ├── gehistorytab │ │ │ ├── GeHistoryTabOfferPanel.java │ │ │ ├── GeHistoryTabPanel.java │ │ │ └── MatchingOffersPanel.java │ │ ├── login │ │ │ ├── LoggedInPanel.java │ │ │ └── LoginPanel.java │ │ ├── offereditor │ │ │ ├── AbstractOfferEditorPanel.java │ │ │ ├── OfferEditorContainerPanel.java │ │ │ ├── OptionPanel.java │ │ │ ├── PriceEditorPanel.java │ │ │ └── QuantityEditorPanel.java │ │ ├── recipeflips │ │ │ ├── RecipeFlipCreationPanel.java │ │ │ ├── RecipeItemHeaderPanel.java │ │ │ └── RecipeOfferSelectionPanel.java │ │ ├── settings │ │ │ └── SettingsPanel.java │ │ ├── slots │ │ │ ├── SlotPanel.java │ │ │ └── SlotsPanel.java │ │ ├── statistics │ │ │ ├── StatsPanel.java │ │ │ ├── items │ │ │ │ ├── FlipPanel.java │ │ │ │ ├── FlippingItemContainerPanel.java │ │ │ │ ├── FlippingItemPanel.java │ │ │ │ └── OfferPanel.java │ │ │ └── recipes │ │ │ │ ├── RecipeFlipGroupPanel.java │ │ │ │ ├── RecipeFlipPanel.java │ │ │ │ └── RecipeGroupContainerPanel.java │ │ ├── uiutilities │ │ │ ├── CustomColors.java │ │ │ ├── CustomFonts.java │ │ │ ├── CustomSpriteIds.java │ │ │ ├── FastTabGroup.java │ │ │ ├── GeSpriteLoader.java │ │ │ ├── Icons.java │ │ │ ├── Paginator.java │ │ │ ├── QuickLookPanel.java │ │ │ ├── TimeFormatters.java │ │ │ ├── UIUtilities.java │ │ │ └── WidgetConstants.java │ │ └── widgets │ │ │ ├── OfferEditor.java │ │ │ ├── QuickLookTooltip.java │ │ │ ├── SlotActivityTimer.java │ │ │ └── SlotStateDrawer.java │ │ └── utilities │ │ ├── AccountSlotsUpdate.java │ │ ├── Constants.java │ │ ├── GeHistoryTabExtractor.java │ │ ├── GeTax.java │ │ ├── InvalidOptionException.java │ │ ├── Jwt.java │ │ ├── ListUtils.java │ │ ├── MathUtils.java │ │ ├── OsrsAccount.java │ │ ├── PotionDose.java │ │ ├── PotionGroup.java │ │ ├── Recipe.java │ │ ├── RecipeItem.java │ │ ├── SORT.java │ │ ├── Searchable.java │ │ ├── SlotInfo.java │ │ ├── SlotPredictedState.java │ │ ├── SlotState.java │ │ ├── TokenResponse.java │ │ ├── User.java │ │ ├── WikiDataSource.java │ │ ├── WikiItemMargins.java │ │ ├── WikiRequest.java │ │ └── WikiRequestWrapper.java └── resources │ ├── blackdot.png │ ├── construction.png │ ├── deleteButton.png │ ├── delete_icon.png │ ├── discord-alch.png │ ├── discord-cheese.png │ ├── discord.png │ ├── discordon.png │ ├── download.png │ ├── flash-cheese.png │ ├── ge-sprites │ ├── blue │ │ ├── border_offer_bottom.png │ │ ├── border_offer_corner_bottom_left.png │ │ ├── border_offer_corner_bottom_right.png │ │ ├── border_offer_corner_top_left.png │ │ ├── border_offer_corner_top_right.png │ │ ├── border_offer_horizontal.png │ │ ├── border_offer_intersection_left.png │ │ ├── border_offer_intersection_right.png │ │ ├── border_offer_left.png │ │ ├── border_offer_right.png │ │ ├── border_offer_top.png │ │ └── selected_item_box.png │ ├── green │ │ ├── border_offer_bottom.png │ │ ├── border_offer_corner_bottom_left.png │ │ ├── border_offer_corner_bottom_right.png │ │ ├── border_offer_corner_top_left.png │ │ ├── border_offer_corner_top_right.png │ │ ├── border_offer_horizontal.png │ │ ├── border_offer_intersection_left.png │ │ ├── border_offer_intersection_right.png │ │ ├── border_offer_left.png │ │ ├── border_offer_right.png │ │ ├── border_offer_top.png │ │ └── selected_item_box.png │ └── red │ │ ├── border_offer_bottom.png │ │ ├── border_offer_corner_bottom_left.png │ │ ├── border_offer_corner_bottom_right.png │ │ ├── border_offer_corner_top_left.png │ │ ├── border_offer_corner_top_right.png │ │ ├── border_offer_horizontal.png │ │ ├── border_offer_intersection_left.png │ │ ├── border_offer_intersection_right.png │ │ ├── border_offer_left.png │ │ ├── border_offer_right.png │ │ ├── border_offer_top.png │ │ └── selected_item_box.png │ ├── github-alch.png │ ├── github-cheese.png │ ├── github.png │ ├── githubon.png │ ├── gnome.png │ ├── graph_icon_green.png │ ├── graph_icon_small.png │ ├── graydot.png │ ├── greendot.png │ ├── heart.png │ ├── help.png │ ├── highlightDeleteButton.png │ ├── information.png │ ├── key.png │ ├── left-arrow-large.png │ ├── left-arrow.png │ ├── magnifying-glass.png │ ├── open_arrow.png │ ├── plus.png │ ├── priceeditorpic.png │ ├── quantityeditorpic.png │ ├── question-mark.png │ ├── recipehelp.png │ ├── reddot.png │ ├── refresh.png │ ├── reset.png │ ├── right-arrow-large.png │ ├── right-arrow.png │ ├── search.png │ ├── settings_icon.png │ ├── small_open_arrow.png │ ├── sort.png │ ├── star-gold.png │ ├── star_off_white.png │ ├── template.png │ ├── toggle_on.png │ ├── trash.png │ ├── trashicon.png │ ├── twitter-alch.png │ ├── twitter.png │ ├── twitteron.png │ ├── user-alch.png │ ├── user-cheese.png │ └── user-loggedin.png └── test └── java └── com └── flippingutilities ├── FlippingPluginTest.java ├── GeTaxTest.java ├── HistoryManagerTest.java ├── PluginRunner.java ├── TestRunner.java └── Utils.java /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build 3 | .idea/ 4 | out/ 5 | src/.idea/ 6 | bin/ 7 | .settings/ 8 | .classpath 9 | .project -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.compile.nullAnalysis.mode": "automatic", 3 | "java.configuration.updateBuildConfiguration": "automatic", 4 | "java.debug.settings.vmArgs": "-ea", 5 | "java.test.config": { 6 | "name": "SkipTests", 7 | "vmArgs": ["-ea"] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2020, Belieal 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | 2 | plugins { 3 | id 'java' 4 | } 5 | 6 | repositories { 7 | maven { 8 | url = 'http://repo.runelite.net' 9 | } 10 | mavenCentral() 11 | } 12 | 13 | def runeLiteVersion = '1.10.31' 14 | 15 | dependencies { 16 | compileOnly group: 'net.runelite', name:'client', version: runeLiteVersion 17 | compileOnly 'org.projectlombok:lombok:1.18.4' 18 | annotationProcessor 'org.projectlombok:lombok:1.18.4' 19 | 20 | implementation "org.apache.commons:commons-csv:1.4" 21 | 22 | testImplementation 'junit:junit:4.12' 23 | testImplementation 'org.slf4j:slf4j-simple:1.7.12' 24 | testImplementation group: 'net.runelite', name:'client', version: runeLiteVersion, { 25 | exclude group: 'ch.qos.logback', module: 'logback-classic' 26 | } 27 | } 28 | 29 | group = 'com.flippingutilities' 30 | version = '1.4.1' 31 | sourceCompatibility = '1.8' 32 | 33 | tasks.withType(JavaCompile) { 34 | options.encoding = 'UTF-8' 35 | } 36 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/icon.png -------------------------------------------------------------------------------- /images/buys.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/buys.png -------------------------------------------------------------------------------- /images/card.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/card.png -------------------------------------------------------------------------------- /images/customize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/customize.png -------------------------------------------------------------------------------- /images/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/demo.gif -------------------------------------------------------------------------------- /images/editor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/editor.png -------------------------------------------------------------------------------- /images/favorites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/favorites.png -------------------------------------------------------------------------------- /images/flipping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/flipping.png -------------------------------------------------------------------------------- /images/flippingtabpic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/flippingtabpic.png -------------------------------------------------------------------------------- /images/flips.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/flips.png -------------------------------------------------------------------------------- /images/lookup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/lookup.png -------------------------------------------------------------------------------- /images/manual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/manual.png -------------------------------------------------------------------------------- /images/multiacc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/multiacc.png -------------------------------------------------------------------------------- /images/offers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/offers.png -------------------------------------------------------------------------------- /images/recipeCreation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/recipeCreation.png -------------------------------------------------------------------------------- /images/recipeCreationStep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/recipeCreationStep.png -------------------------------------------------------------------------------- /images/statCard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/statCard.png -------------------------------------------------------------------------------- /images/stats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/stats.png -------------------------------------------------------------------------------- /images/statscard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/statscard.png -------------------------------------------------------------------------------- /images/statstab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/statstab.png -------------------------------------------------------------------------------- /images/timer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/timer.png -------------------------------------------------------------------------------- /images/times.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/times.png -------------------------------------------------------------------------------- /images/viewRecipes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flipping-Utilities/rl-plugin/5a14f011ffb89bdcf562d0f70ecd93f52d8678aa/images/viewRecipes.png -------------------------------------------------------------------------------- /runelite-plugin.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2020, Belieal 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this 9 | # list of conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation 13 | # and/or other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | displayName=Flipping Utilities 27 | author=Beliael,Gamersriseup,Anyny0 28 | support=https://github.com/Flipping-Utilities/rl-plugin 29 | description=Profit tracking, margin displays, statistics, and more. 30 | tags=flipping, utilities, grandexchange, ge, flip, profit 31 | plugins=com.flippingutilities.controller.FlippingPlugin -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Belieal 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | rootProject.name = 'flippingutilities' 28 | -------------------------------------------------------------------------------- /src/main/java/com/flippingutilities/FlippingConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Belieal 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | package com.flippingutilities; 28 | 29 | import com.flippingutilities.controller.FlippingPlugin; 30 | import com.flippingutilities.ui.uiutilities.CustomColors; 31 | import net.runelite.client.config.Config; 32 | import net.runelite.client.config.ConfigGroup; 33 | import net.runelite.client.config.ConfigItem; 34 | import net.runelite.client.config.Units; 35 | import net.runelite.client.ui.ColorScheme; 36 | 37 | import java.awt.*; 38 | 39 | @ConfigGroup(FlippingPlugin.CONFIG_GROUP) 40 | public interface FlippingConfig extends Config 41 | { 42 | @ConfigItem( 43 | keyName = "roiGradientMax", 44 | name = "Set ROI gradient range limit", 45 | description = "Set the limit of the range before the gradient is bright green" 46 | ) 47 | @Units(Units.PERCENT) 48 | default int roiGradientMax() 49 | { 50 | return 2; 51 | } 52 | 53 | @ConfigItem( 54 | keyName = "marginCheckLoss", 55 | name = "Account for margin check loss", 56 | description = "Subtract the loss from margin checking the item when calculating the total profit" 57 | ) 58 | default boolean marginCheckLoss() 59 | { 60 | return true; 61 | } 62 | 63 | @ConfigItem( 64 | keyName = "twelveHourFormat", 65 | name = "12 hour format", 66 | description = "Shows times in a 12 hour format (AM/PM)" 67 | ) 68 | default boolean twelveHourFormat() 69 | { 70 | return true; 71 | } 72 | 73 | @ConfigItem( 74 | keyName = "remainingGELimitProfit", 75 | name = "Calculate potential profit from remaining GE limit", 76 | description = "If unchecked, the potential profit will be calculated from total GE limit" 77 | ) 78 | default boolean geLimitProfit() 79 | { 80 | return false; 81 | } 82 | 83 | @ConfigItem( 84 | keyName = "tradeStagnationTime", 85 | name = "Set trade stagnation time", 86 | description = "Set how long before the offer slot activity timer indicates that a trade has become stagnant" 87 | ) 88 | @Units(Units.MINUTES) 89 | default int tradeStagnationTime() 90 | { 91 | return 15; 92 | } 93 | 94 | @ConfigItem( 95 | keyName = "slotTimersEnabled", 96 | name = "toggle slot timers", 97 | description = "Have a timer on active GE slots that will show the last time an offer came for the slot. This is useful" + 98 | "for knowing whether you should change your offer's price" 99 | ) 100 | default boolean slotTimersEnabled() 101 | { 102 | return true; 103 | } 104 | 105 | @ConfigItem( 106 | keyName = "verboseView", 107 | name = "toggle verbose view", 108 | description = "show items in the flipping tab with all their tracked info like buy/sell price, roi, potential" + 109 | "profit, etc" 110 | ) 111 | default boolean verboseViewEnabled() { return true; } 112 | 113 | @ConfigItem( 114 | keyName = "slotTimerBuyTextColor", 115 | name = "slot timer buy text color", 116 | description = "the color of the buy text on the slot timers" 117 | ) 118 | default Color slotTimerBuyColor() { 119 | return ColorScheme.GRAND_EXCHANGE_LIMIT; 120 | } 121 | 122 | @ConfigItem( 123 | keyName = "slotTimerSellTextColor", 124 | name = "slot timer sell text color", 125 | description = "the color of the sell text on the slot timers" 126 | ) 127 | default Color slotTimerSellColor() { 128 | return ColorScheme.GRAND_EXCHANGE_ALCH; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/com/flippingutilities/controller/FlippingItemHandler.java: -------------------------------------------------------------------------------- 1 | package com.flippingutilities.controller; 2 | 3 | import com.flippingutilities.model.AccountData; 4 | import com.flippingutilities.model.FlippingItem; 5 | import com.flippingutilities.model.OfferEvent; 6 | import com.flippingutilities.model.PartialOffer; 7 | import com.flippingutilities.utilities.SORT; 8 | 9 | import java.time.Instant; 10 | import java.time.temporal.ChronoUnit; 11 | import java.util.*; 12 | import java.util.stream.Collectors; 13 | 14 | public class FlippingItemHandler { 15 | FlippingPlugin plugin; 16 | 17 | FlippingItemHandler(FlippingPlugin plugin) { 18 | this.plugin = plugin; 19 | } 20 | 21 | public List sortItems(List items, SORT selectedSort, Instant startOfInterval) 22 | { 23 | List result = new ArrayList<>(items); 24 | 25 | if (selectedSort == null || result.isEmpty()) { 26 | return result; 27 | } 28 | 29 | switch (selectedSort) { 30 | case TIME: 31 | result.sort(Comparator.comparing(FlippingItem::getLatestActivityTime)); 32 | break; 33 | 34 | case TOTAL_PROFIT: 35 | result.sort(Comparator.comparing(item -> { 36 | Map offerIdToPartialOffer = plugin.getOfferIdToPartialOffer(item.getItemId()); 37 | ArrayList intervalHistory = item.getIntervalHistory(startOfInterval); 38 | List adjustedOffers = FlippingItem.getPartialOfferAdjustedView(intervalHistory, offerIdToPartialOffer); 39 | return FlippingItem.getProfit(adjustedOffers); 40 | })); 41 | break; 42 | 43 | case PROFIT_EACH: 44 | result.sort(Comparator.comparing(item -> { 45 | Map offerIdToPartialOffer = plugin.getOfferIdToPartialOffer(item.getItemId()); 46 | ArrayList intervalHistory = item.getIntervalHistory(startOfInterval); 47 | List adjustedOffers = FlippingItem.getPartialOfferAdjustedView(intervalHistory, offerIdToPartialOffer); 48 | long quantity = FlippingItem.countFlipQuantity(adjustedOffers); 49 | if (quantity == 0) { 50 | return Long.MIN_VALUE; 51 | } 52 | 53 | long profit = FlippingItem.getProfit(adjustedOffers); 54 | return profit / quantity; 55 | })); 56 | break; 57 | case ROI: 58 | result.sort(Comparator.comparing(item -> { 59 | Map offerIdToPartialOffer = plugin.getOfferIdToPartialOffer(item.getItemId()); 60 | List intervalHistory = item.getIntervalHistory(startOfInterval); 61 | List adjustedOffers = FlippingItem.getPartialOfferAdjustedView(intervalHistory, offerIdToPartialOffer); 62 | 63 | long profit = FlippingItem.getProfit(adjustedOffers); 64 | long expense = FlippingItem.getValueOfMatchedOffers(adjustedOffers, true); 65 | if (expense == 0) { 66 | return Float.MIN_VALUE; 67 | } 68 | 69 | return (float) profit / expense * 100; 70 | })); 71 | break; 72 | case FLIP_COUNT: 73 | result.sort(Comparator.comparing( 74 | item -> { 75 | Map offerIdToPartialOffer = plugin.getOfferIdToPartialOffer(item.getItemId()); 76 | List intervalHistory = item.getIntervalHistory(startOfInterval); 77 | List adjustedOffers = FlippingItem.getPartialOfferAdjustedView(intervalHistory, offerIdToPartialOffer); 78 | return FlippingItem.countFlipQuantity(adjustedOffers); 79 | })); 80 | break; 81 | } 82 | Collections.reverse(result); 83 | return result; 84 | } 85 | 86 | public void deleteRemovedItems(List currItems) { 87 | currItems.removeIf((item) -> 88 | { 89 | if (item.getGeLimitResetTime() != null) { 90 | Instant startOfRefresh = item.getGeLimitResetTime().minus(4, ChronoUnit.HOURS); 91 | 92 | return !item.getValidFlippingPanelItem() && !item.hasValidOffers() 93 | && (!Instant.now().isAfter(item.getGeLimitResetTime()) || item.getGeLimitResetTime().isBefore(startOfRefresh)); 94 | } 95 | return !item.getValidFlippingPanelItem() && !item.hasValidOffers(); 96 | }); 97 | } 98 | 99 | /** 100 | * creates a view of an "account wide tradelist". An account wide tradelist is just a reflection of the flipping 101 | * items currently in each of the account's tradelists. It does this by merging the flipping items of the same type 102 | * from each account's trade list into one flipping item. 103 | */ 104 | List createAccountWideFlippingItemList(Collection allAccountData) { 105 | //take all flipping items from the account cache, regardless of account, and segregate them based on item name. 106 | Map> groupedItems = allAccountData.stream(). 107 | flatMap(accountData -> accountData.getTrades().stream()). 108 | map(FlippingItem::clone). 109 | collect(Collectors.groupingBy(FlippingItem::getItemId)); 110 | 111 | //take every list containing flipping items of the same type and reduce it to one merged flipping item and put that 112 | //item in a final merged list 113 | List mergedItems = groupedItems.values().stream(). 114 | map(list -> list.stream().reduce(FlippingItem::merge)).filter(Optional::isPresent).map(Optional::get). 115 | collect(Collectors.toList()); 116 | 117 | mergedItems.sort(Collections.reverseOrder(Comparator.comparing(FlippingItem::getLatestActivityTime))); 118 | 119 | return mergedItems; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/com/flippingutilities/jobs/CacheUpdaterJob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Belieal 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | package com.flippingutilities.jobs; 28 | 29 | import com.flippingutilities.db.TradePersister; 30 | import lombok.extern.slf4j.Slf4j; 31 | 32 | import java.io.IOException; 33 | import java.nio.file.*; 34 | import java.util.ArrayList; 35 | import java.util.HashMap; 36 | import java.util.List; 37 | import java.util.Map; 38 | import java.util.concurrent.Executors; 39 | import java.util.concurrent.Future; 40 | import java.util.concurrent.ScheduledExecutorService; 41 | import java.util.concurrent.TimeUnit; 42 | import java.util.function.Consumer; 43 | 44 | /** 45 | * Updates the cache in real time as files are changed in the directory being monitored. It monitors the directory 46 | * where the accounts' data is stored and fires any registered callbacks when it detects a change for an account. 47 | * The reason it accepts callbacks is so that this class is not tied to any specific component's way of handling a file 48 | * change. This decoupling allows the cache updater to be used easily by any component that wishes to fire an action 49 | * when a file for an account is changed. 50 | */ 51 | @Slf4j 52 | public class CacheUpdaterJob 53 | { 54 | ScheduledExecutorService executor; 55 | 56 | List> subscribers = new ArrayList<>(); 57 | 58 | boolean isBeingShutdownByClient = false; 59 | 60 | Future realTimeUpdateTask; 61 | 62 | Map lastEvents = new HashMap<>(); 63 | 64 | int requiredMinMsSinceLastUpdate = 5; 65 | int failureCount; 66 | int failureThreshold = 2; 67 | 68 | 69 | public CacheUpdaterJob() 70 | { 71 | this.executor = Executors.newSingleThreadScheduledExecutor(); 72 | } 73 | 74 | public void subscribe(Consumer callback) 75 | { 76 | subscribers.add(callback); 77 | } 78 | 79 | public void start() 80 | { 81 | realTimeUpdateTask = executor.schedule(this::updateCacheRealTime, 1000, TimeUnit.MILLISECONDS); 82 | } 83 | 84 | public void stop() 85 | { 86 | isBeingShutdownByClient = true; 87 | realTimeUpdateTask.cancel(true); 88 | } 89 | 90 | public void updateCacheRealTime() 91 | { 92 | try 93 | { 94 | log.info("starting cache updator job!"); 95 | WatchService watchService = FileSystems.getDefault().newWatchService(); 96 | 97 | Path path = TradePersister.PARENT_DIRECTORY.toPath(); 98 | 99 | path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY); 100 | 101 | WatchKey key; 102 | while ((key = watchService.take()) != null) 103 | { 104 | for (WatchEvent event : key.pollEvents()) 105 | { 106 | log.info("change in directory for {} with event: {}", event.context(), event.kind()); 107 | if (!isDuplicateEvent(event.context().toString())) 108 | { 109 | log.info("not duplicate event, firing callbacks"); 110 | subscribers.forEach(subscriber -> subscriber.accept(event.context().toString())); 111 | } 112 | else 113 | { 114 | log.info("duplicate event, not firing callbacks"); 115 | } 116 | 117 | } 118 | //put the key back in the queue so we can take out more events when they occur 119 | key.reset(); 120 | failureCount = 0; 121 | } 122 | } 123 | 124 | catch (IOException | InterruptedException e) 125 | { 126 | if (!isBeingShutdownByClient) 127 | { 128 | log.info("exception in updateCacheRealTime, Error = {}", e); 129 | onUnexpectedError(); 130 | } 131 | 132 | else 133 | { 134 | onClientShutdown(); 135 | } 136 | } 137 | 138 | catch (Exception e) 139 | { 140 | log.info("unknown exception in updateCacheRealTime, task is going to stop. Error = {}", e); 141 | } 142 | } 143 | 144 | private void onUnexpectedError() 145 | { 146 | log.info("Failure number: {} Error not caused by client shutdown", failureCount); 147 | failureCount++; 148 | if (failureCount > failureThreshold) 149 | { 150 | log.info("number of failures exceeds failure threshold, not scheduling task again"); 151 | return; 152 | } 153 | 154 | else 155 | { 156 | log.info("failure count below threshold, scheduling task again"); 157 | realTimeUpdateTask = executor.schedule(this::updateCacheRealTime, 1000, TimeUnit.MILLISECONDS); 158 | } 159 | } 160 | 161 | private void onClientShutdown() 162 | { 163 | log.info("shutting down cache updater due to the client shutdown"); 164 | } 165 | 166 | private boolean isDuplicateEvent(String fileName) 167 | { 168 | long lastModified = TradePersister.lastModified(fileName); 169 | if (lastEvents.containsKey(fileName)) 170 | { 171 | long prevModificationTime = lastEvents.get(fileName); 172 | long diffSinceLastModification = Math.abs(lastModified - prevModificationTime); 173 | if (diffSinceLastModification < requiredMinMsSinceLastUpdate) 174 | { 175 | return true; 176 | } 177 | else 178 | { 179 | lastEvents.put(fileName, lastModified); 180 | return false; 181 | } 182 | } 183 | else 184 | { 185 | lastEvents.put(fileName, lastModified); 186 | return false; 187 | } 188 | } 189 | } -------------------------------------------------------------------------------- /src/main/java/com/flippingutilities/jobs/WikiDataFetcherJob.java: -------------------------------------------------------------------------------- 1 | package com.flippingutilities.jobs; 2 | 3 | import com.flippingutilities.controller.FlippingPlugin; 4 | import com.flippingutilities.utilities.WikiDataSource; 5 | import com.flippingutilities.utilities.WikiRequest; 6 | import com.flippingutilities.utilities.WikiRequestWrapper; 7 | import com.google.gson.JsonSyntaxException; 8 | import lombok.extern.slf4j.Slf4j; 9 | import net.runelite.api.WorldType; 10 | import okhttp3.*; 11 | 12 | import java.io.IOException; 13 | import java.time.Instant; 14 | import java.time.temporal.ChronoUnit; 15 | import java.util.ArrayList; 16 | import java.util.EnumSet; 17 | import java.util.List; 18 | import java.util.concurrent.Executors; 19 | import java.util.concurrent.Future; 20 | import java.util.concurrent.ScheduledExecutorService; 21 | import java.util.concurrent.TimeUnit; 22 | import java.util.function.BiConsumer; 23 | 24 | /** 25 | * Responsible for handling all of the requests for wiki realtime data and ensuring too many requests aren't being made. 26 | */ 27 | @Slf4j 28 | public class WikiDataFetcherJob { 29 | public static int requestInterval = 60; //seconds 30 | static final String API = "https://prices.runescape.wiki/api/v1/osrs/latest"; 31 | static final String DEADMAN_API = "https://prices.runescape.wiki/api/v1/dmm/latest"; 32 | FlippingPlugin plugin; 33 | ScheduledExecutorService executor; 34 | OkHttpClient httpClient; 35 | List> subscribers = new ArrayList<>(); 36 | Future wikiDataFetchTask; 37 | Instant timeOfLastRequestCompletion; 38 | boolean inFlightRequest = false; 39 | String apiUrl = API; 40 | 41 | 42 | public WikiDataFetcherJob(FlippingPlugin plugin, OkHttpClient httpClient) { 43 | this.plugin = plugin; 44 | this.httpClient = httpClient; 45 | this.executor = Executors.newSingleThreadScheduledExecutor(); 46 | } 47 | 48 | public void subscribe(BiConsumer subscriber) { 49 | subscribers.add(subscriber); 50 | } 51 | 52 | public void start() { 53 | wikiDataFetchTask = executor.scheduleAtFixedRate(() -> this.attemptToFetchWikiData(false), 5,1, TimeUnit.SECONDS); 54 | log.info("started wiki fetching job"); 55 | } 56 | 57 | public void stop() { 58 | if (!wikiDataFetchTask.isCancelled() && !wikiDataFetchTask.isCancelled()) { 59 | wikiDataFetchTask.cancel(true); 60 | log.info("shut down wiki fetching job"); 61 | } 62 | } 63 | 64 | public void onWorldSwitch(EnumSet worldType) { 65 | if (worldType.contains(WorldType.DEADMAN)) { 66 | log.info("Switching to requesting deadman api"); 67 | apiUrl = DEADMAN_API; 68 | } 69 | else { 70 | apiUrl = API; 71 | } 72 | 73 | attemptToFetchWikiData(true); 74 | } 75 | 76 | private WikiDataSource getWikiDataSourceType() { 77 | if (apiUrl.equals(DEADMAN_API)) { 78 | return WikiDataSource.DMM; 79 | } 80 | return WikiDataSource.REGULAR; 81 | } 82 | 83 | 84 | //only problem with this is that then master panel will be visible even if they have opened and then closed flipping utils 85 | //as long as they haven't opened another plugin. But if they have another plugin open or they haven't opened flipping utils 86 | //then masterpanel.isVisible() will correctly return false. 87 | private boolean shouldFetch() { 88 | boolean lastRequestOldEnough = timeOfLastRequestCompletion == null || Instant.now().minus(requestInterval, ChronoUnit.SECONDS).isAfter(timeOfLastRequestCompletion); 89 | //for the purpose of SlotStateDrawer, we need wiki data even if the master panel is not visible, but only 90 | //if the user is premium. 91 | return (plugin.getMasterPanel().isVisible() || plugin.getApiAuthHandler().isPremium()) && !inFlightRequest && lastRequestOldEnough; 92 | } 93 | 94 | public void attemptToFetchWikiData(boolean force) { 95 | if (!force && !shouldFetch()) { 96 | return; 97 | } 98 | inFlightRequest = true; 99 | Request request = new Request.Builder().header("User-Agent", "FlippingUtilities").url(apiUrl).build(); 100 | httpClient.newCall(request).enqueue(new Callback() { 101 | @Override 102 | public void onFailure(Call call, IOException e) { 103 | timeOfLastRequestCompletion = Instant.now(); 104 | inFlightRequest = false; 105 | } 106 | 107 | @Override 108 | public void onResponse(Call call, Response response) throws IOException { 109 | try (ResponseBody responseBody = response.body()) { 110 | if (!response.isSuccessful()) { 111 | timeOfLastRequestCompletion = Instant.now(); 112 | inFlightRequest = false; 113 | return; 114 | } 115 | try { 116 | timeOfLastRequestCompletion = Instant.now(); 117 | inFlightRequest = false; 118 | WikiRequest wikiRequest = plugin.gson.fromJson(responseBody.string(), WikiRequest.class); 119 | WikiRequestWrapper wikiRequestWrapper = new WikiRequestWrapper(wikiRequest, getWikiDataSourceType()); 120 | subscribers.forEach(subscriber -> subscriber.accept(wikiRequestWrapper, timeOfLastRequestCompletion)); 121 | } 122 | catch (JsonSyntaxException e) { } 123 | } 124 | } 125 | }); 126 | } 127 | } 128 | 129 | -------------------------------------------------------------------------------- /src/main/java/com/flippingutilities/model/AccountData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Belieal 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | package com.flippingutilities.model; 28 | 29 | import com.flippingutilities.controller.FlippingPlugin; 30 | import com.flippingutilities.ui.widgets.SlotActivityTimer; 31 | import lombok.Data; 32 | import lombok.extern.slf4j.Slf4j; 33 | import net.runelite.client.game.ItemManager; 34 | import net.runelite.client.game.ItemStats; 35 | 36 | import java.time.Instant; 37 | import java.util.ArrayList; 38 | import java.util.HashMap; 39 | import java.util.List; 40 | import java.util.Map; 41 | import java.util.stream.Collectors; 42 | 43 | @Slf4j 44 | @Data 45 | public class AccountData { 46 | private Map lastOffers = new HashMap<>(); 47 | private List trades = new ArrayList<>(); 48 | private Instant sessionStartTime = Instant.now(); 49 | private long accumulatedSessionTimeMillis = 0; 50 | private Instant lastSessionTimeUpdate; 51 | private List slotTimers; 52 | private List recipeFlipGroups = new ArrayList<>(); 53 | private Instant lastStoredAt = Instant.EPOCH; 54 | private Instant lastModifiedAt = Instant.now(); 55 | 56 | /** 57 | * Resets all session related data associated with an account. This is called when the plugin first starts 58 | * as that's when a new session is "started" and when a user wants to start a new session for an account. 59 | */ 60 | public void startNewSession() { 61 | sessionStartTime = Instant.now(); 62 | accumulatedSessionTimeMillis = 0; 63 | lastSessionTimeUpdate = null; 64 | } 65 | 66 | /** 67 | * Over time as we delete/add fields, we need to make sure the fields are set properly the first time the user 68 | * loads their trades after the new update. This method serves as a way to sanitize the data. It also ensures 69 | * that the FlippingItems have their non persisted fields set from history. 70 | */ 71 | public void prepareForUse(FlippingPlugin plugin) { 72 | fixIncorrectItemNames(plugin.getItemManager()); 73 | 74 | Map hydratedOffers = new HashMap<>(); 75 | 76 | for (FlippingItem item : trades) { 77 | //in case ge limits have been updated 78 | int tradeItemId = item.getItemId(); 79 | ItemStats itemStats = plugin.getItemManager().getItemStats(tradeItemId); 80 | int geLimit = itemStats != null ? itemStats.getGeLimit() : 0; 81 | 82 | item.hydrate(geLimit); 83 | item.getHistory().getCompressedOfferEvents().forEach(o -> hydratedOffers.put(o.getUuid(), o)); 84 | } 85 | 86 | hydratePartialOffers(hydratedOffers); 87 | hydrateSlotTimers(plugin); 88 | } 89 | 90 | private void hydrateSlotTimers(FlippingPlugin plugin) { 91 | if (slotTimers == null) { 92 | slotTimers = setupSlotTimers(plugin); 93 | } else { 94 | slotTimers.forEach(timer -> { 95 | timer.setClient(plugin.getClient()); 96 | timer.setPlugin(plugin); 97 | }); 98 | } 99 | } 100 | 101 | private void hydratePartialOffers(Map hydratedOffers) { 102 | List partialOffers = recipeFlipGroups.stream().flatMap(rfg -> rfg.getPartialOffers().stream()).collect(Collectors.toList()); 103 | partialOffers.forEach(po -> { 104 | OfferEvent o = hydratedOffers.get(po.offer.getUuid()); 105 | if (o == null) { 106 | log.warn("partial offer references deleted offer event, this should not happen!"); 107 | return; 108 | } 109 | po.hydrateUnderlyingOfferEvent(o.getMadeBy(), o.getItemName()); 110 | }); 111 | } 112 | 113 | /** 114 | * When a user is an f2p world and recieves events for members items (cause they were already in the GE), 115 | * the item manager retrieves the item's name as "Members object". The item manager returns the correct 116 | * name when the user is on a member's world or logged out. As such, this method is called when the plugin starts 117 | * and whenever the user logs into a members world to clean up any "Members object" item names. 118 | */ 119 | public void fixIncorrectItemNames(ItemManager itemManager) { 120 | trades.forEach(item -> { 121 | if (item.getItemName().equals("Members object")) { 122 | String actualName = itemManager.getItemComposition(item.getItemId()).getName(); 123 | item.setItemName(actualName); 124 | } 125 | }); 126 | } 127 | 128 | private List setupSlotTimers(FlippingPlugin plugin) { 129 | ArrayList slotTimers = new ArrayList<>(); 130 | for (int slotIndex = 0; slotIndex < 8; slotIndex++) { 131 | slotTimers.add(new SlotActivityTimer(plugin, plugin.getClient(), slotIndex)); 132 | } 133 | return slotTimers; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/flippingutilities/model/AccountWideData.java: -------------------------------------------------------------------------------- 1 | package com.flippingutilities.model; 2 | 3 | import lombok.Data; 4 | import lombok.extern.slf4j.Slf4j; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | @Data 10 | @Slf4j 11 | public class AccountWideData { 12 | List