Skip to content

Commit

Permalink
Improve performance a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Oct 2, 2023
1 parent 0eba0ce commit 1ea7952
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/net/pistonmaster/serverwrecker/AttackManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.protocol.MinecraftProtocol;
import io.netty.channel.EventLoopGroup;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -115,7 +116,7 @@ public CompletableFuture<Void> start(SettingsHolder settingsHolder) {
Collections.shuffle(accounts);
}

Map<SWProxy, Integer> proxyUseMap = new Object2IntOpenHashMap<>();
Object2IntMap<SWProxy> proxyUseMap = new Object2IntOpenHashMap<>();
for (SWProxy proxy : proxies) {
proxyUseMap.put(proxy, 0);
}
Expand Down Expand Up @@ -202,18 +203,18 @@ private MinecraftAccount getAccount(AccountSettings accountSettings, List<Minecr
return accounts.remove(0);
}

private Optional<SWProxy> getProxy(int accountsPerProxy, Map<SWProxy, Integer> proxyUseMap) {
private Optional<SWProxy> getProxy(int accountsPerProxy, Object2IntMap<SWProxy> proxyUseMap) {
if (proxyUseMap.isEmpty()) {
return Optional.empty(); // No proxies available
}

var selectedProxy = proxyUseMap.entrySet().stream()
.filter(entry -> accountsPerProxy == -1 || entry.getValue() < accountsPerProxy)
var selectedProxy = proxyUseMap.object2IntEntrySet().stream()
.filter(entry -> accountsPerProxy == -1 || entry.getIntValue() < accountsPerProxy)
.min(Comparator.comparingInt(Map.Entry::getValue))
.orElseThrow(() -> new IllegalStateException("No proxies available!")); // Should never happen

// Always present
selectedProxy.setValue(selectedProxy.getValue() + 1);
selectedProxy.setValue(selectedProxy.getIntValue() + 1);

return Optional.of(selectedProxy.getKey());
}
Expand Down

0 comments on commit 1ea7952

Please sign in to comment.