Skip to content

Commit

Permalink
Implement better id system for protocol versions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed May 6, 2024
1 parent cc702a1 commit 7336e65
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
10 changes: 9 additions & 1 deletion server/src/main/java/com/soulfiremc/server/AttackManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.soulfiremc.settings.account.MinecraftAccount;
import com.soulfiremc.settings.proxy.SFProxy;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionType;
import io.netty.channel.EventLoopGroup;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
Expand Down Expand Up @@ -176,7 +177,14 @@ public CompletableFuture<?> start() {
SFNettyHelper.createEventLoopGroup(0, "Attack-%d".formatted(id));

var protocolVersion =
settingsHolder.get(BotSettings.PROTOCOL_VERSION, ProtocolVersion::getClosest);
settingsHolder.get(BotSettings.PROTOCOL_VERSION, s -> {
var split = s.split("\\|");
if (split.length == 1) {
return ProtocolVersion.getClosest(split[0]);
}

return ProtocolVersion.getProtocol(VersionType.valueOf(split[0]), Integer.parseInt(split[1]));
});
var isBedrock = SFVersionConstants.isBedrock(protocolVersion);
var targetAddress = ResolveUtil.resolveAddress(isBedrock, settingsHolder);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* SoulFire
* Copyright (C) 2024 AlexProgrammerDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.soulfiremc.server.protocol.bot.state;

import com.soulfiremc.server.data.ResourceKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public class BotSettings implements SettingsObject {

private static ComboProperty.ComboOption[] getProtocolVersionOptions() {
return ProtocolVersionList.getProtocolsNewToOld().stream()
.map(version -> new ComboProperty.ComboOption(version.getName(), version.toString()))
.map(version -> new ComboProperty.ComboOption("%s|%d".formatted(version.getVersionType().name(), version.getOriginalVersion()), version.getName()))
.toArray(ComboProperty.ComboOption[]::new);
}

Expand Down

0 comments on commit 7336e65

Please sign in to comment.