Skip to content

Commit

Permalink
Add automatic respawning
Browse files Browse the repository at this point in the history
  • Loading branch information
Moudoux committed Jun 4, 2017
1 parent 49f5eb6 commit c67dc45
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/java/me/alexander/mcbot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket;
import com.github.steveice10.packetlib.Client;
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
Expand Down Expand Up @@ -75,6 +76,11 @@ public void packetReceived(PacketReceivedEvent event) {
} else if (event.<ServerChatPacket>getPacket().getType().equals(MessageType.SYSTEM)) {
logger.info(event.getPacket());
}
} else if (event.getPacket() instanceof ServerPlayerHealthPacket) {
ServerPlayerHealthPacket health = (ServerPlayerHealthPacket) event.getPacket();
if (health.getHealth() <= 0.0F) {
respawnBot();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/alexander/mcbot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void main(String[] args) {
}
String username = args[0], password = args.length == 1 ? "" : args[1];
final Bot b = new Bot(username, password);
b.connect("");
b.connect("localhost:25565");
b.addListener(new SessionAdapter() {
@Override
public void packetReceived(PacketReceivedEvent event) {
Expand Down
Binary file modified target/classes/me/alexander/mcbot/Bot$1.class
Binary file not shown.
Binary file modified target/classes/me/alexander/mcbot/Bot.class
Binary file not shown.
Binary file modified target/classes/me/alexander/mcbot/Main.class
Binary file not shown.

0 comments on commit c67dc45

Please sign in to comment.