Skip to content

Commit afb0d24

Browse files
committed
sort checksum arrays before comparing
1 parent 337d4c0 commit afb0d24

File tree

1 file changed

+6
-15
lines changed
  • src/main/java/pro/cloudnode/smp/bankaccounts

1 file changed

+6
-15
lines changed

src/main/java/pro/cloudnode/smp/bankaccounts/POS.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Optional;
3131
import java.util.UUID;
3232
import java.util.logging.Level;
33-
import java.util.stream.IntStream;
3433
import java.util.zip.CRC32;
3534

3635
public final class POS {
@@ -374,26 +373,18 @@ public static void openBuyGui(final @NotNull Player player, final @NotNull Chest
374373
return Arrays.stream(items).sorted(Comparator.comparing(ItemStack::translationKey)).sorted(Comparator.comparing(ItemStack::getAmount)).map(POS::checksum).toArray(String[]::new);
375374
}
376375

377-
/**
378-
* Verify checksum
379-
*
380-
* @param item The item to verify
381-
* @param checksum The checksum to verify against
382-
*/
383-
public static boolean verifyChecksum(final @NotNull ItemStack item, final @NotNull String checksum) {
384-
return checksum(item).equals(checksum);
385-
}
386-
387376
/**
388377
* Verify checksums
389378
*
390379
* @param items The items to verify
391380
* @param checksums The checksums to verify against
392381
*/
393382
public static boolean verifyChecksum(final @NotNull ItemStack @NotNull [] items, final @NotNull String @NotNull [] checksums) {
394-
if (items.length != checksums.length)
395-
throw new IllegalArgumentException("The number of items and checksums must be the same.");
396-
397-
return IntStream.range(0, items.length).allMatch(i -> verifyChecksum(items[i], checksums[i]));
383+
if (items.length != checksums.length) return false;
384+
final @NotNull String @NotNull [] itemChecksums = checksum(items);
385+
return Arrays.equals(
386+
Arrays.stream(itemChecksums).sorted().toArray(String[]::new),
387+
Arrays.stream(checksums).sorted().toArray(String[]::new)
388+
);
398389
}
399390
}

0 commit comments

Comments
 (0)