Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Sep 19, 2023
2 parents 373845b + 1e097b2 commit ba55546
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 29 deletions.
23 changes: 17 additions & 6 deletions CLI_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| `-a`, `--amount` | `1` | Amount of bots to connect to the server |
| `--min-join-delay` | `1000` | The minimum delay between bot connections, in milliseconds |
| `--max-join-delay` | `3000` | The maximum delay between bot connections, in milliseconds |
| `-mc`, `--mc-version` | `1.20` | Minecraft version of the server to connect to |
| `-mc`, `--mc-version` | `1.20/1.20.1` | Minecraft version of the server to connect to |
| `--read-timeout` | `30` | Bot read timeout |
| `--write-timeout` | `0` | Bot write timeout |
| `--connect-timeout` | `30` | Bot connect timeout |
Expand All @@ -26,9 +26,8 @@
| `--profile-file` | `null` | File to load a profile from |
| `-h`, `--help` | `false` | Show this help message and exit. |
| `-V`, `--version` | `false` | Print version information and exit. |
| `--auto-reconnect` | `true` | Reconnect bots after being disconnected |
| `--reconnect-min-delay` | `1` | Minimum delay between reconnects |
| `--reconnect-max-delay` | `5` | Maximum delay between reconnects |
| `--send-client-brand` | `true` | Send client brand |
| `--client-brand` | `vanilla` | Client brand |
| `--send-client-settings` | `true` | Send client settings |
| `--client-locale` | `en_gb` | Client locale |
| `--render-distance` | `8` | Render distance |
Expand All @@ -44,8 +43,9 @@
| `--hand-preference` | `RIGHT_HAND` | Hand preference |
| `--text-filtering-enabled` | `true` | Text filtering enabled |
| `--allows-listing` | `true` | Allows listing |
| `--send-client-brand` | `true` | Send client brand |
| `--client-brand` | `vanilla` | Client brand |
| `--auto-reconnect` | `true` | Reconnect bots after being disconnected |
| `--reconnect-min-delay` | `1` | Minimum delay between reconnects |
| `--reconnect-max-delay` | `5` | Maximum delay between reconnects |
| `--auto-register` | `false` | Make bots run the /register and /login command after joining |
| `--register-command` | `/register %password% %password%` | Command to be executed to register |
| `--login-command` | `/login %password%` | Command to be executed to log in |
Expand All @@ -54,9 +54,20 @@
| `--auto-respawn` | `true` | Respawn bots after death |
| `--respawn-min-delay` | `1` | Minimum delay between respawns |
| `--respawn-max-delay` | `3` | Maximum delay between respawns |
| `--auto-totem` | `true` | Do auto totem? |
| `--totem-min-delay` | `1` | Minimum delay between using totems |
| `--totem-max-delay` | `2` | Maximum delay between using totems |
| `--auto-jump` | `false` | Do auto jump? |
| `--jump-min-delay` | `2` | Minimum delay between jumps |
| `--jump-max-delay` | `5` | Maximum delay between jumps |
| `--auto-armor` | `true` | Do auto armor? |
| `--armor-min-delay` | `1` | Minimum delay between putting on armor |
| `--armor-max-delay` | `2` | Maximum delay between putting on armor |
| `--auto-eat` | `true` | Do auto eat? |
| `--eat-min-delay` | `1` | Minimum delay between eating |
| `--eat-max-delay` | `2` | Maximum delay between eating |
| `--log-chat` | `true` | Log chat to terminal |
| `--chat-interval` | `2` | Minimum delay between logging chat |
| `--server-list-bypass` | `false` | Do server list bypass? |
| `--server-list-bypass-min-delay` | `1` | Minimum join delay after pinging the server |
| `--server-list-bypass-max-delay` | `3` | Maximum join delay after pinging the server |
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
application
idea
id("sw.shadow-conventions")
id("edu.sc.seis.launch4j") version "3.0.4"
id("edu.sc.seis.launch4j") version "3.0.5"
id("com.google.protobuf") version "0.9.4"
}

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pluginManagement {
id("org.cadixdev.licenser") version "0.6.1"
id("net.kyori.indra") version "3.1.3"
id("net.kyori.indra.git") version "3.1.3"
id("net.kyori.blossom") version "2.0.1"
id("net.kyori.blossom") version "2.1.0"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.pistonmaster.serverwrecker.addons.*;
import net.pistonmaster.serverwrecker.api.ServerWreckerAPI;
import net.pistonmaster.serverwrecker.api.event.lifecycle.CommandManagerInitEvent;
import net.pistonmaster.serverwrecker.cli.SWCommandDefinition;
import net.pistonmaster.serverwrecker.common.OperationMode;
import net.pistonmaster.serverwrecker.grpc.RPCClient;
import net.pistonmaster.serverwrecker.gui.GUIManager;
Expand All @@ -33,7 +34,7 @@
import java.awt.*;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.Set;
import java.util.List;

public class ServerWreckerBootstrap {
static {
Expand Down Expand Up @@ -76,7 +77,7 @@ public static void main(String[] args) {
}

private static void loadInternalAddons() {
Set<InternalAddon> addons = Set.of(
List<InternalAddon> addons = List.of(
new BotTicker(), new ClientBrand(), new ClientSettings(),
new AutoReconnect(), new AutoRegister(), new AutoRespawn(),
new AutoTotem(), new AutoJump(), new AutoArmor(), new AutoEat(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ public void loadFromString(String file, AuthType authType) {
throw new IllegalArgumentException("Invalid JSON!");
}
} else {
String[] accountLines = file.split("\n");

Arrays.stream(accountLines)
file.lines()
.filter(line -> !line.isBlank())
.distinct()
.map(account -> fromString(account, authType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
*/
package net.pistonmaster.serverwrecker;
package net.pistonmaster.serverwrecker.cli;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.pistonmaster.serverwrecker.ServerWrecker;
import net.pistonmaster.serverwrecker.auth.AccountSettings;
import net.pistonmaster.serverwrecker.auth.AuthType;
import net.pistonmaster.serverwrecker.builddata.BuildData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public record BlockShapeType(int id, List<BlockShape> blockShapes) {
throw new IllegalStateException("blockshapes.txt not found!");
}

String[] lines = new String(inputStream.readAllBytes()).split("\n");

for (String line : lines) {
new String(inputStream.readAllBytes()).lines().forEach(line -> {
String[] parts = line.split("\\|");

int id = Integer.parseInt(parts[0]);
Expand All @@ -58,7 +56,7 @@ public record BlockShapeType(int id, List<BlockShape> blockShapes) {
}

VALUES.add(new BlockShapeType(id, blockShapes));
}
});
} catch (IOException e) {
throw new IllegalStateException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public class BlockStateLoader {
throw new IllegalStateException("blockstates.txt not found!");
}

String[] lines = new String(inputStream.readAllBytes()).split("\n");

for (String line : lines) {
new String(inputStream.readAllBytes()).lines().forEach(line -> {
String[] parts = line.split("\\|");
String name = parts[0];

Expand All @@ -55,7 +53,7 @@ public class BlockStateLoader {
}

BLOCK_SHAPES.put(name, blockShapeTypes);
}
});
} catch (IOException e) {
throw new IllegalStateException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import net.pistonmaster.serverwrecker.pathfinding.graph.ProjectedInventory;
import net.pistonmaster.serverwrecker.protocol.bot.block.BlockStateMeta;
import net.pistonmaster.serverwrecker.protocol.bot.container.ContainerSlot;
import net.pistonmaster.serverwrecker.protocol.bot.container.PlayerInventoryContainer;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;
Expand All @@ -43,7 +42,7 @@ public class Costs {
private Costs() {
}

public static Optional<BlockMiningCosts> calculateBlockCost(ProjectedInventory inventory, BlockStateMeta blockStateMeta) {
public static Optional<BlockMiningCosts> calculateBlockBreakCost(ProjectedInventory inventory, BlockStateMeta blockStateMeta) {
BlockType blockType = blockStateMeta.blockType();

// Don't try to find a way to dig bedrock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public record PlayerMovement(BotEntityState previousEntityState, MovementDirecti
// Optional.of() takes a few milliseconds, so we'll just cache it
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private static final Optional<ActionCosts> EMPTY_COST = Optional.of(new ActionCosts(0, Collections.emptyList()));
private static final boolean ALLOW_BLOCK_ACTIONS = false;

private static Vector3i applyDirection(Vector3i pos, MovementDirection direction) {
return switch (direction) {
Expand Down Expand Up @@ -216,7 +217,11 @@ private Optional<ActionCosts> requireFreeBlock(Vector3i block, ProjectedLevelSta
return EMPTY_COST;
}

Optional<Costs.BlockMiningCosts> blockMiningCosts = Costs.calculateBlockCost(inventory, blockStateMeta);
if (!ALLOW_BLOCK_ACTIONS) {
return Optional.empty();
}

Optional<Costs.BlockMiningCosts> blockMiningCosts = Costs.calculateBlockBreakCost(inventory, blockStateMeta);

// No way to break block
if (blockMiningCosts.isEmpty()) {
Expand Down Expand Up @@ -259,6 +264,10 @@ private Optional<ActionCosts> requireSolidBlock(Vector3i block, ProjectedLevelSt

// Block with a current state that has no collision (Like air, grass, open fence)
if (blockShapeType.hasNoCollisions()) {
if (!ALLOW_BLOCK_ACTIONS) {
return Optional.empty();
}

// Could destroy and place block here, but that's too much work
return Optional.empty();
}
Expand All @@ -269,7 +278,7 @@ private Optional<ActionCosts> requireSolidBlock(Vector3i block, ProjectedLevelSt
return Optional.empty();
}

return Optional.of(new ActionCosts(0, Collections.emptyList()));
return EMPTY_COST;
}

private BlockStateMeta getBlockShapeType(ProjectedLevelState level, Vector3i block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public void loadFromFile(Path file, ProxyType proxyType) throws IOException {
public void loadFromString(String file, ProxyType proxyType) {
List<SWProxy> newProxies = new ArrayList<>();

String[] proxyLines = file.split("\n");

Arrays.stream(proxyLines)
file.lines()
.filter(line -> !line.isBlank())
.distinct()
.map(line -> fromString(line, proxyType))
Expand Down

0 comments on commit ba55546

Please sign in to comment.