File tree Expand file tree Collapse file tree
src/main/java/technobot/handlers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99import technobot .data .cache .Config ;
1010import technobot .data .cache .Item ;
1111
12- import java .util .HashMap ;
13- import java .util .Map ;
14- import java .util .TimerTask ;
12+ import java .util .*;
1513import java .util .concurrent .Executors ;
1614import java .util .concurrent .ScheduledExecutorService ;
1715import java .util .concurrent .ScheduledFuture ;
@@ -231,21 +229,17 @@ public Item getItemByID(String uuid) {
231229 * @return the name of the item that most closely matches the input. Null if no match at all.
232230 */
233231 public String findClosestItem (String input ) {
234- int value = Integer .MAX_VALUE ;
235- int longest = 0 ;
236- String itemName = null ;
232+ String closestMatch = null ;
233+ double bestValue = 0 ;
237234 for (String name : config .getShop ().keySet ()) {
238- int temp = StringUtils .getLevenshteinDistance (input , name );
239- if (temp < value ) {
240- value = temp ;
241- itemName = name ;
242- }
243- if (name .length () > longest ) {
244- longest = name .length ();
235+ if (name .contains (input )) {
236+ double result = StringUtils .getJaroWinklerDistance (name , input );
237+ if (result >= bestValue ) {
238+ closestMatch = name ;
239+ }
245240 }
246241 }
247- if (itemName != null && value >= longest ) return null ;
248- return itemName ;
242+ return closestMatch ;
249243 }
250244
251245 /**
You can’t perform that action at this time.
0 commit comments