├── .gitignore ├── .travis.yml ├── Cargo.toml ├── README.md ├── build.gradle ├── eclipse-format.xml ├── lib ├── guava-18.0.jar ├── hamcrest-core-1.3.jar ├── javassist.jar ├── jna.jar ├── jruby-complete-9.0.0.0.pre2.jar ├── json-simple-1.1.1.jar ├── junit-4.12.jar ├── lombok.jar ├── mcprotocollib-1.8.8-20151124.020436-29.jar └── reflections-0.9.10.jar ├── phasebot.dll ├── res └── scripts │ ├── LAA.s │ ├── LAB.s │ ├── LAC.s │ ├── LAD.s │ ├── args.s │ ├── blocktest.s │ ├── buildline.s │ ├── busybeaver.s │ ├── la.s │ ├── placetest.s │ ├── scriptA.s │ ├── scriptB.s │ ├── scriptC.s │ ├── scriptD.s │ ├── scriptH.s │ ├── shelteredline.s │ ├── stalk.s │ ├── talk.s │ ├── testdig.s │ └── testtalk.s ├── rust.sh └── src ├── phasebot.rs └── xyz └── jadonfowler └── phasebot ├── Bot.java ├── ChatMessage.java ├── PacketHandler.java ├── PhaseBot.java ├── SaltyFile.java ├── cmd ├── Command.java ├── CommandManager.java ├── chat │ ├── EntityCommand.java │ ├── InventoryCommand.java │ ├── JavaScriptCommand.java │ ├── MessageCommand.java │ ├── PauseTaskCommand.java │ ├── ReloadCommand.java │ ├── RubyCommand.java │ ├── SayCommand.java │ ├── SlapCommand.java │ ├── SpamCommand.java │ ├── SudoCommand.java │ ├── UUIDCommand.java │ └── WelcomeCommand.java ├── fun │ ├── DerpCommand.java │ └── SwingCommand.java ├── inv │ └── SlotCommand.java └── position │ ├── ArcMoveCommand.java │ ├── ClosestBlockCommand.java │ ├── DigCommand.java │ ├── FallCommand.java │ ├── FollowCommand.java │ ├── GetBlockCommand.java │ ├── GetCloseToCommand.java │ ├── GetTypeCommand.java │ ├── JumpCommand.java │ ├── LookCommand.java │ ├── MoveCommand.java │ ├── PathfindCommand.java │ ├── PatrolCommand.java │ ├── PlaceBlockCommand.java │ ├── SetCommand.java │ └── TeleportCommand.java ├── entity ├── Entity.java └── Player.java ├── gui ├── ConsoleGui.java └── map │ └── MapGui.java ├── inventory └── Inventory.java ├── jna └── NativeInterface.java ├── pathfind ├── AStar.java ├── PathingResult.java └── Tile.java ├── script └── Script.java ├── test └── ConnectionTest.java ├── util ├── NameFetcher.java ├── UUIDFetcher.java └── Vector3d.java └── world ├── Block.java ├── ChunkColumn.java ├── MaterialLoader.java ├── ToolStrength.java └── material ├── BlockType.java ├── ItemType.java └── Material.java /.gitignore: -------------------------------------------------------------------------------- 1 | #Idea IntelliJ 2 | *.iml 3 | *.ipr 4 | *.iws 5 | 6 | #Eclipse 7 | *.classpath 8 | *.project 9 | /.settings 10 | /bin/ 11 | 12 | #Gradle 13 | /.gradle 14 | /build 15 | 16 | #Rust 17 | Cargo.lock 18 | target -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | script: gradle test -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "phasebot" 3 | version = "1.0.2" 4 | authors = ["phase "] 5 | 6 | [lib] 7 | name = "phasebot" 8 | crate-type = ["dylib"] 9 | 10 | [dependencies] 11 | lazy_static = "0.1.*" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #PhaseBot 2 | 3 | [![Join the chat at https://gitter.im/phase/PhaseBot](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/phase/PhaseBot?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | [![Issues in progress](https://badge.waffle.io/phase/PhaseBot.png?label=in%20progress&title=In%20Progress)](https://waffle.io/phase/PhaseBot) 5 | [![Build Status](https://travis-ci.org/phase/PhaseBot.svg)](https://travis-ci.org/phase/PhaseBot) 6 | [![volkswagen status](https://auchenberg.github.io/volkswagen/volkswargen_ci.svg?v=1)](https://github.com/auchenberg/volkswagen) 7 | 8 | A Minecraft bot that does various tasks 9 | 10 | [![Throughput Graph](https://graphs.waffle.io/phase/PhaseBot/throughput.svg)](https://waffle.io/phase/PhaseBot/metrics) 11 | 12 | ## Building 13 | Just compiling the code: 14 | ``` 15 | gradle build 16 | ``` 17 | 18 | Creating a **runnable jar** (*may take ~20 minutes*): 19 | ``` 20 | gradle fatJar 21 | ``` 22 | 23 | ## Current Features 24 | You can check the [waffle](https://waffle.io/phase/PhaseBot) to see what I'm working on. 25 | * Connecting to servers (1.8.X) 26 | * Reading chat commands 27 | * Complete Console w/ features 28 | * Parsing JavaScript & Ruby code 29 | * Script Engine to interact with the bot 30 | * Movement/Pathfinding (A*) 31 | * Looking 32 | * Loading entities and handling entity movement 33 | * Loading chunks and handling block changes 34 | * Changing Slot 35 | * Breaking/Placing Blocks 36 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'application' 3 | 4 | mainClassName = 'xyz.jadonfowler.phasebot.PhaseBot' 5 | 6 | sourceSets { 7 | main { 8 | java { 9 | srcDir 'src' 10 | exclude '**/*Test.java' 11 | } 12 | resources { 13 | srcDir 'res' 14 | } 15 | } 16 | test { 17 | java { 18 | srcDir 'src' 19 | include '**/*Test.java' 20 | } 21 | } 22 | } 23 | 24 | task fatJar(type: Jar) { 25 | manifest { 26 | attributes 'Implementation-Title': 'PhaseBot', 27 | 'Implementation-Version': '1.0.2', 28 | 'Main-Class': 'xyz.jadonfowler.phasebot.PhaseBot' 29 | } 30 | baseName = project.name + '-' + manifest.attributes['Implementation-Version'] 31 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 32 | with jar 33 | } 34 | 35 | repositories { 36 | mavenCentral() 37 | } 38 | 39 | dependencies { 40 | testCompile 'junit:junit:4.11' 41 | compile fileTree(dir: 'lib', include: ['*.jar']) 42 | } 43 | 44 | test { 45 | testLogging { 46 | events "passed", "skipped", "failed", "standardOut", "standardError" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /eclipse-format.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | -------------------------------------------------------------------------------- /lib/guava-18.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phase/PhaseBot/cc4302c642582ffe2dea2689483dbc69d87a623f/lib/guava-18.0.jar -------------------------------------------------------------------------------- /lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phase/PhaseBot/cc4302c642582ffe2dea2689483dbc69d87a623f/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /lib/javassist.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phase/PhaseBot/cc4302c642582ffe2dea2689483dbc69d87a623f/lib/javassist.jar -------------------------------------------------------------------------------- /lib/jna.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phase/PhaseBot/cc4302c642582ffe2dea2689483dbc69d87a623f/lib/jna.jar -------------------------------------------------------------------------------- /lib/jruby-complete-9.0.0.0.pre2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phase/PhaseBot/cc4302c642582ffe2dea2689483dbc69d87a623f/lib/jruby-complete-9.0.0.0.pre2.jar -------------------------------------------------------------------------------- /lib/json-simple-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phase/PhaseBot/cc4302c642582ffe2dea2689483dbc69d87a623f/lib/json-simple-1.1.1.jar -------------------------------------------------------------------------------- /lib/junit-4.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phase/PhaseBot/cc4302c642582ffe2dea2689483dbc69d87a623f/lib/junit-4.12.jar -------------------------------------------------------------------------------- /lib/lombok.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phase/PhaseBot/cc4302c642582ffe2dea2689483dbc69d87a623f/lib/lombok.jar -------------------------------------------------------------------------------- /lib/mcprotocollib-1.8.8-20151124.020436-29.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phase/PhaseBot/cc4302c642582ffe2dea2689483dbc69d87a623f/lib/mcprotocollib-1.8.8-20151124.020436-29.jar -------------------------------------------------------------------------------- /lib/reflections-0.9.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phase/PhaseBot/cc4302c642582ffe2dea2689483dbc69d87a623f/lib/reflections-0.9.10.jar -------------------------------------------------------------------------------- /phasebot.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phase/PhaseBot/cc4302c642582ffe2dea2689483dbc69d87a623f/phasebot.dll -------------------------------------------------------------------------------- /res/scripts/LAA.s: -------------------------------------------------------------------------------- 1 | getblock 0 -1 0 2 | gettype @block 3 | .ifeq 5 @type wool 4 | dig 0 -1 0 5 | slot 1 6 | place 0 -1 0 7 | move 0 0 1 8 | LAB 9 | .ifeq 5 @type stone 10 | dig 0 -1 0 11 | slot 0 12 | place 0 -1 0 13 | move 0 0 -1 14 | LAD -------------------------------------------------------------------------------- /res/scripts/LAB.s: -------------------------------------------------------------------------------- 1 | getblock 0 -1 0 2 | gettype @block 3 | .ifeq 5 @type wool 4 | dig 0 -1 0 5 | slot 1 6 | place 0 -1 0 7 | move -1 0 0 8 | LAC 9 | .ifeq 5 @type stone 10 | dig 0 -1 0 11 | slot 0 12 | place 0 -1 0 13 | move 1 0 0 14 | LAA -------------------------------------------------------------------------------- /res/scripts/LAC.s: -------------------------------------------------------------------------------- 1 | getblock 0 -1 0 2 | gettype @block 3 | .ifeq 5 @type wool 4 | dig 0 -1 0 5 | slot 1 6 | place 0 -1 0 7 | move 0 0 -1 8 | LAD 9 | .ifeq 5 @type stone 10 | dig 0 -1 0 11 | slot 0 12 | place 0 -1 0 13 | move 0 0 1 14 | LAB -------------------------------------------------------------------------------- /res/scripts/LAD.s: -------------------------------------------------------------------------------- 1 | getblock 0 -1 0 2 | gettype @block 3 | .ifeq 5 @type wool 4 | dig 0 -1 0 5 | slot 1 6 | place 0 -1 0 7 | move 1 0 0 8 | LAA 9 | .ifeq 5 @type stone 10 | dig 0 -1 0 11 | slot 0 12 | place 0 -1 0 13 | move -1 0 0 14 | LAC -------------------------------------------------------------------------------- /res/scripts/args.s: -------------------------------------------------------------------------------- 1 | .val @derp = savage 2 | say @derp -------------------------------------------------------------------------------- /res/scripts/blocktest.s: -------------------------------------------------------------------------------- 1 | getblock @a0 @a1 @a2 2 | gettype @block 3 | say /msg phase @type 4 | -------------------------------------------------------------------------------- /res/scripts/buildline.s: -------------------------------------------------------------------------------- 1 | .for 2 30 2 | place 0 0 0 3 | move 0 0 1 -------------------------------------------------------------------------------- /res/scripts/busybeaver.s: -------------------------------------------------------------------------------- 1 | slot 0 2 | sudo /i wool 3 | slot 1 4 | sudo /i stone 5 | scriptA -------------------------------------------------------------------------------- /res/scripts/la.s: -------------------------------------------------------------------------------- 1 | say Langton's Ant! 2 | slot 0 3 | sudo /i wool 4 | slot 1 5 | sudo /i stone 6 | LAA -------------------------------------------------------------------------------- /res/scripts/placetest.s: -------------------------------------------------------------------------------- 1 | place 1 0 1 2 | place 1 1 1 3 | place 0 0 1 4 | place 0 1 1 5 | place -1 0 1 6 | place -1 1 1 -------------------------------------------------------------------------------- /res/scripts/scriptA.s: -------------------------------------------------------------------------------- 1 | getblock 0 -1 0 2 | gettype @block 3 | .ifeq 4 @type wool 4 | dig 0 -1 0 5 | slot 1 6 | place 0 -1 0 7 | move 0 0 -1 8 | .ifeq 1 @type stone 9 | move 0 0 1 10 | scriptB -------------------------------------------------------------------------------- /res/scripts/scriptB.s: -------------------------------------------------------------------------------- 1 | getblock 0 -1 0 2 | gettype @block 3 | .ifeq 5 @type wool 4 | dig 0 -1 0 5 | slot 1 6 | place 0 -1 0 7 | move 0 0 1 8 | scriptA 9 | .ifeq 5 @type stone 10 | dig 0 -1 0 11 | slot 0 12 | place 0 -1 0 13 | move 0 0 1 14 | scriptC -------------------------------------------------------------------------------- /res/scripts/scriptC.s: -------------------------------------------------------------------------------- 1 | getblock 0 -1 0 2 | gettype @block 3 | .ifeq 5 @type wool 4 | dig 0 -1 0 5 | slot 1 6 | place 0 -1 0 7 | move 0 0 -1 8 | scriptH 9 | .ifeq 2 @type stone 10 | move 0 0 1 11 | scriptD -------------------------------------------------------------------------------- /res/scripts/scriptD.s: -------------------------------------------------------------------------------- 1 | getblock 0 -1 0 2 | gettype @block 3 | .ifeq 5 @type wool 4 | dig 0 -1 0 5 | slot 1 6 | place 0 -1 0 7 | move 0 0 -1 8 | scriptD 9 | .ifeq 5 @type stone 10 | dig 0 -1 0 11 | slot 0 12 | place 0 -1 0 13 | move 0 0 -1 14 | scriptA -------------------------------------------------------------------------------- /res/scripts/scriptH.s: -------------------------------------------------------------------------------- 1 | say Halt! -------------------------------------------------------------------------------- /res/scripts/shelteredline.s: -------------------------------------------------------------------------------- 1 | sudo /clear 2 | look 0 0 3 | slot 0 4 | sudo /i stone 64 5 | slot 1 6 | sudo /i redstone 64 7 | .for 14 10 8 | dig 0 0 1 9 | dig 0 1 1 10 | dig 1 0 1 11 | dig 1 1 1 12 | dig -1 0 1 13 | dig -1 1 1 14 | slot 0 15 | place 1 0 1 16 | place 1 1 1 17 | place -1 0 1 18 | place -1 1 1 19 | slot 1 20 | place 0 0 1 21 | move 0 0 1 -------------------------------------------------------------------------------- /res/scripts/stalk.s: -------------------------------------------------------------------------------- 1 | .loop 2 2 | tp @a0 3 | .sleep 500 -------------------------------------------------------------------------------- /res/scripts/talk.s: -------------------------------------------------------------------------------- 1 | .for 1 3 2 | msg Phasesaber @i -------------------------------------------------------------------------------- /res/scripts/testdig.s: -------------------------------------------------------------------------------- 1 | .for 2 5 2 | dig 0 1 .i 3 | dig 0 0 .i 4 | .for 2 5 5 | dig 1 1 .i 6 | dig 1 0 .i 7 | .for 2 5 8 | dig -1 1 .i 9 | dig -1 0 .i -------------------------------------------------------------------------------- /res/scripts/testtalk.s: -------------------------------------------------------------------------------- 1 | msg Phasesaber testdifferet -------------------------------------------------------------------------------- /rust.sh: -------------------------------------------------------------------------------- 1 | #Script to build Rust lib and move it to res/lib/ 2 | cargo build 3 | mv target/debug/phasebot.dll ./ -------------------------------------------------------------------------------- /src/phasebot.rs: -------------------------------------------------------------------------------- 1 | #![crate_type = "dylib"] 2 | 3 | #[macro_use] 4 | extern crate lazy_static; 5 | 6 | use std::sync::Mutex; 7 | use std::collections::HashSet; 8 | 9 | #[repr(C)] 10 | pub struct Vec3d { 11 | x: f64, 12 | y: f64, 13 | z: f64, 14 | } 15 | 16 | #[derive(Eq, PartialEq, Hash)] 17 | struct Chunk { 18 | x: i32, 19 | y: i32, 20 | z: i32, 21 | blocks: [[[i32; 16]; 16]; 16], 22 | } 23 | 24 | lazy_static! { 25 | static ref CHUNKS: Mutex> = Mutex::new(HashSet::new()); 26 | } 27 | 28 | #[no_mangle] 29 | pub extern fn add_chunk(cx: i32, cy: i32, cz: i32, c_blocks: [[[i32; 16]; 16]; 16]) { 30 | CHUNKS.lock().unwrap().insert(Chunk {x: cx, y: cy, z: cz, blocks: c_blocks}); 31 | } 32 | 33 | #[no_mangle] 34 | pub extern fn update_block(x: i32, y: i32, z: i32, id: i32) { 35 | let cx: i32 = x / 16; 36 | let cy: i32 = y / 16; 37 | let cz: i32 = z / 16; 38 | 39 | let rx: i32 = if x > 0 { x % 16 } else { 16 + (x % 16) }; 40 | let ry: i32 = if y > 0 { y % 16 } else { 16 + (y % 16) }; 41 | let rz: i32 = if z > 0 { z % 16 } else { 16 + (z % 16) }; 42 | 43 | for c in CHUNKS.lock().unwrap().iter() { 44 | if c.x == cx && c.y == cy && c.z == cz { 45 | c.blocks[rx as usize][ry as usize][rz as usize] = id; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/xyz/jadonfowler/phasebot/Bot.java: -------------------------------------------------------------------------------- 1 | package xyz.jadonfowler.phasebot; 2 | 3 | import java.net.*; 4 | import java.util.*; 5 | import lombok.*; 6 | import org.spacehq.mc.protocol.data.game.*; 7 | import org.spacehq.mc.protocol.data.game.values.*; 8 | import org.spacehq.mc.protocol.data.game.values.entity.player.*; 9 | import org.spacehq.mc.protocol.packet.ingame.client.*; 10 | import org.spacehq.mc.protocol.packet.ingame.client.player.*; 11 | import org.spacehq.packetlib.*; 12 | import xyz.jadonfowler.phasebot.entity.*; 13 | import xyz.jadonfowler.phasebot.inventory.*; 14 | import xyz.jadonfowler.phasebot.pathfind.*; 15 | import xyz.jadonfowler.phasebot.util.*; 16 | import xyz.jadonfowler.phasebot.world.*; 17 | import xyz.jadonfowler.phasebot.world.material.*; 18 | 19 | public class Bot { 20 | 21 | @Getter @Setter private String username; 22 | @Getter @Setter private String host; 23 | @Getter @Setter private int port; 24 | @Getter @Setter private Proxy proxy = Proxy.NO_PROXY; 25 | @Getter public Vector3d pos; 26 | @Getter public float pitch = 0; 27 | @Getter public float yaw = 0; 28 | @Getter public int entityId = 0; 29 | public boolean isDerp = false; 30 | @Getter @Setter private boolean interuptMoveAlong = false; 31 | @Getter @Setter private Client client; 32 | @Getter @Setter public Inventory inventory; 33 | public Vector3d[] positions; // Do we still need this? 34 | // Variables 35 | @Getter private HashMap variables = new HashMap(); 36 | 37 | public Bot(String username, String host, int port, Proxy proxy) { 38 | this.username = username; 39 | this.host = host; 40 | this.port = port; 41 | this.proxy = proxy; 42 | this.positions = new Vector3d[4]; 43 | this.pos = new Vector3d(0, 0, 0); 44 | variables.put("host", host); 45 | } 46 | 47 | public void runCommand(final String s, boolean newThread) { 48 | if (newThread) { 49 | new Thread(new Runnable() { 50 | 51 | public void run() { 52 | if (client.getSession() != null && client.getSession().isConnected()) 53 | PhaseBot.getCommandManager().performCommand(s, s.split(" "), client.getSession()); 54 | } 55 | }).start(); 56 | } 57 | else { 58 | if (client.getSession() != null && client.getSession().isConnected()) 59 | PhaseBot.getCommandManager().performCommand(s, s.split(" "), client.getSession()); 60 | } 61 | } 62 | 63 | public void runCommand(String s) { 64 | runCommand(s, false); 65 | } 66 | 67 | public void derp(final Session s) { 68 | new Thread(new Runnable() { 69 | 70 | public void run() { 71 | while (isDerp) { 72 | look((PhaseBot.random.nextFloat() * 10000) % 180, ((PhaseBot.random.nextFloat() * 10000) % 180)); 73 | swing(); 74 | // jump(0, 1, 0); 75 | try { 76 | Thread.sleep(40); 77 | } 78 | catch (InterruptedException e) {} 79 | } 80 | } 81 | }).start(); 82 | } 83 | 84 | public void look(float yaw, float pitch) { 85 | client.getSession().send(new ClientPlayerPositionRotationPacket(false, pos.x, pos.y, pos.z, yaw, pitch)); 86 | } 87 | 88 | public void swing() { 89 | client.getSession().send(new ClientSwingArmPacket()); 90 | } 91 | 92 | public void centerPosition() { 93 | // return; 94 | double dx = pos.x > 0 ? Math.floor(pos.x) + 0.5d : Math.round(pos.x) - 0.5d; 95 | double dy = Math.floor(pos.y); 96 | double dz = pos.z > 0 ? Math.floor(pos.z) + 0.5d : Math.round(pos.z) - 0.5d; 97 | client.getSession().send(new ClientPlayerPositionRotationPacket(false, dx, dy, dz, yaw, pitch)); 98 | } 99 | 100 | public void fall() { 101 | while (Block.getBlock(pos.x, pos.y - 1, pos.z).getMaterial() == Material.getMaterial(0)) 102 | move(0, -1, 0); 103 | } 104 | 105 | public void jump(double x, double y, double z) { 106 | if (y > 0) move(0, Math.abs(y), 0); 107 | move(x, 0, z); 108 | fall(); 109 | centerPosition(); 110 | } 111 | 112 | public void moveTo(Entity e) { 113 | moveTo((int) Math.floor(e.x), (int) Math.floor(e.y), (int) Math.floor(e.z)); 114 | } 115 | 116 | public void moveTo(double tx, double ty, double tz) { 117 | moveTo(new Vector3d(tx, ty, tz)); 118 | } 119 | 120 | public void moveTo(Vector3d to) { 121 | Vector3d v = new Vector3d(to.x - pos.x, to.y - pos.y, to.z - pos.z).floor(); 122 | jump(v.x, v.y, v.z); 123 | } 124 | 125 | public boolean pathing = false; 126 | 127 | public void moveAlong(ArrayList tiles) { 128 | interuptMoveAlong = false; 129 | pathing = true; 130 | final Iterator itr = tiles.iterator(); 131 | final Vector3d start = pos.clone(); 132 | itr.next(); 133 | new Thread(new Runnable() { 134 | 135 | public void run() { 136 | try { 137 | while (itr.hasNext()) { 138 | if (interuptMoveAlong) { 139 | PhaseBot.getConsole().println("Block changed! Rerouting path..."); 140 | PhaseBot.getCommandManager().performLastCommand(); 141 | interuptMoveAlong = false; 142 | return; 143 | } 144 | Tile t = itr.next(); 145 | Vector3d v = t.getLocation(start.clone()).clone().add(new Vector3d(0.5, 0, 0.5)); 146 | moveTo(v); 147 | } 148 | pathing = false; 149 | } 150 | catch (Exception e) { 151 | e.printStackTrace(); 152 | } 153 | } 154 | }).start(); 155 | } 156 | 157 | public void moveAlongArc(double rx, double ry, double rz) { 158 | // Get absolute cords 159 | final double tx = pos.x - rx; 160 | final double ty = pos.y - ry; 161 | final double tz = pos.z - rz; 162 | final double fx = pos.x; 163 | final double fy = pos.y; 164 | final double fz = pos.z; 165 | int[] angles = { 30, 45, 60 }; 166 | for (int t : angles) { 167 | /* @formatter:off 168 | * rz = sin(to.z > from.z ? -t : t) * (to.z - from.z) 169 | * rx = cos(to.x > from.x ? -t : t) * (to.x - from.x) 170 | * ry = tan(to.y < from.y ? -t : t) * (to.y - from.y) 171 | * @formatter:on 172 | */ 173 | double arx = Math.cos(tx > fx ? -t : t) * (tx - fx); 174 | double ary = Math.tan(ty < fy ? -t : t) * (ty - fy); 175 | double arz = Math.sin(tz > fz ? -t : t) * (tz - fz); 176 | // PhaseBot.getConsole().println("ARC: " + arx + " " + ary + " " + 177 | // arz); 178 | move(arx, ary, arz); 179 | try { 180 | Thread.sleep(100); 181 | } 182 | catch (InterruptedException e) { 183 | e.printStackTrace(); 184 | } 185 | } 186 | moveTo(tx, ty, tz); 187 | } 188 | 189 | public void move(double rx, double ry, double rz) { 190 | if (isDiagonal(rx, ry, rz)) { 191 | moveDiagonal(rx, ry, rz); 192 | return; 193 | } 194 | // PhaseBot.getConsole().println("m: " + rx + " " + ry + " " + rz); 195 | double l = (pos.x + rx) - pos.x; 196 | double w = (pos.z + rz) - pos.z; 197 | double h = (pos.y + ry) - pos.y; 198 | double c = Math.sqrt(l * l + w * w); 199 | double a1 = -Math.asin(l / c) / Math.PI * 180; 200 | double a2 = Math.acos(w / c) / Math.PI * 180; 201 | if (a2 > 90) yaw = (float) (180 - a1); 202 | else yaw = (float) a1; 203 | if (rx == 0 && rz == 0) yaw = 0; 204 | pitch = (float) Math.atan((h / c)); 205 | // PhaseBot.getConsole().println("p: " + pitch + " y:" + yaw); 206 | int numberOfSteps = (int) ((int) 2.0 207 | * Math.floor(Math.sqrt(Math.pow(rx, 2) + Math.pow(ry, 2) + Math.pow(rz, 2)))); 208 | double sx = rx / numberOfSteps; 209 | double sy = ry / numberOfSteps; 210 | double sz = rz / numberOfSteps; 211 | // PhaseBot.getConsole().println("s: " + sx + " " + sy + " " + sz + " : 212 | // " + 213 | // numberOfSteps); 214 | for (int i = 0; i < numberOfSteps; i++) { 215 | pos.x += sx; 216 | pos.y += sy; 217 | pos.z += sz; 218 | // PhaseBot.getConsole().println("Moving " + pos); 219 | client.getSession().send(new ClientPlayerPositionRotationPacket(false, pos.x, pos.y, pos.z, yaw, pitch)); 220 | try { 221 | Thread.sleep(100); 222 | } 223 | catch (InterruptedException e) { 224 | e.printStackTrace(); 225 | } 226 | } 227 | centerPosition(); 228 | } 229 | 230 | private void moveDiagonal(double x, double y, double z) { 231 | pos.x += x; 232 | pos.y += y; 233 | pos.z += z; 234 | centerPosition(); 235 | try { 236 | Thread.sleep(0); 237 | } 238 | catch (InterruptedException e) { 239 | e.printStackTrace(); 240 | } 241 | } 242 | 243 | private boolean isDiagonal(double x, double y, double z) { 244 | if ((x == 1 && z == 1 && y == 0) || (x == 1 && z == -1 && y == 0) || (x == -1 && z == 1 && y == 0) 245 | || (x == -1 && z == -1 && y == 0)) 246 | return true; 247 | return false; 248 | } 249 | 250 | public void breakBlockAbsolute(Vector3d a) { 251 | Vector3d r = absoluteToRelative(a); 252 | breakBlock(r.x, r.y, r.z); 253 | } 254 | 255 | public void breakBlock(double rx, double ry, double rz) { 256 | final Position p = new Position((int) Math.floor(pos.x + rx), (int) Math.floor(pos.y + ry), 257 | (int) Math.floor(pos.z + rz)); 258 | // PhaseBot.getConsole().println("Digging at: " + p.getX() + " " + 259 | // p.getY() + " " + p.getZ()); 260 | client.getSession().send(new ClientPlayerActionPacket(PlayerAction.START_DIGGING, p, Face.TOP)); 261 | swing(); 262 | // if(!(gamemode == GameMode.CREATIVE)) 263 | BlockType block = Block.getBlock(relativeToAbsolute(new Vector3d(rx, ry, rz))).getMaterial().toBlock(); 264 | try { 265 | double waitTime = ToolStrength.getWaitTime(Material.getMaterial(inventory.getHeldItem().getId()).toItem(), 266 | block, false, true); 267 | PhaseBot.getConsole().println("Block wait time: " + waitTime); 268 | Thread.sleep((int) waitTime); 269 | PhaseBot.getConsole().println(" done"); 270 | client.getSession().send(new ClientPlayerActionPacket(PlayerAction.FINISH_DIGGING, p, Face.TOP)); 271 | } 272 | catch (InterruptedException e) { 273 | e.printStackTrace(); 274 | } 275 | } 276 | 277 | public void say(String s) { 278 | client.getSession().send(new ClientChatPacket(s)); 279 | } 280 | 281 | public Vector3d relativeToAbsolute(Vector3d d) { 282 | return new Vector3d(pos.x + d.x, pos.y + d.y, pos.z + d.z); 283 | } 284 | 285 | public Vector3d absoluteToRelative(Vector3d a) { 286 | return new Vector3d(pos.x - a.x, pos.y - a.y, pos.z - a.z); 287 | } 288 | 289 | public Face getPlaceFace(Vector3d d) { 290 | for (int x = -1; x < 2; x++) { 291 | for (int y = -1; y < 2; y++) { 292 | for (int z = -1; z < 2; z++) { 293 | Block b = Block.getBlock(new Vector3d(x + d.x, y + d.y, z + d.z)); 294 | if (b.getMaterial() != Material.getMaterial(0)) { 295 | if ((x == -1 && z == 0 && y == 0)) return Face.WEST; 296 | else if ((x == 1 && z == 0 && y == 0)) return Face.EAST; 297 | else if ((x == 0 && z == 0 && y == 1)) return Face.BOTTOM; 298 | else if ((x == 0 && z == 0 && y == -1)) return Face.TOP; 299 | else if ((x == 0 && z == 1 && y == 0)) return Face.SOUTH; 300 | else if ((x == 0 && z == -1 && y == 0)) return Face.NORTH; 301 | } 302 | } 303 | } 304 | } 305 | return Face.INVALID; 306 | } 307 | 308 | public void placeBlockAbsolute(Vector3d location) { 309 | placeBlock(absoluteToRelative(location)); 310 | } 311 | 312 | public void placeBlock(Vector3d location) { 313 | Face face = Face.INVALID; 314 | Vector3d blockLocation = null; 315 | float cursorX = 0, cursorY = 0, cursorZ = 0; 316 | getBlock: for (int x = -1; x < 2; x++) { 317 | for (int y = -1; y < 2; y++) { 318 | for (int z = -1; z < 2; z++) { 319 | Block b = Block.getBlock(new Vector3d(x + location.x, y + location.y, z + location.z)); 320 | if (b.getMaterial() != Material.getMaterial(0)) { 321 | if ((x == 0 && z == 0 && y == -1)) { 322 | face = Face.TOP; 323 | blockLocation = b.getPos(); 324 | break getBlock; 325 | } 326 | else if ((x == -1 && z == 0 && y == 0)) { 327 | face = Face.SOUTH; 328 | blockLocation = b.getPos(); 329 | break getBlock; 330 | } 331 | else if ((x == 1 && z == 0 && y == 0)) { 332 | face = Face.NORTH; 333 | blockLocation = b.getPos(); 334 | break getBlock; 335 | } 336 | else if ((x == 0 && z == 0 && y == 1)) { 337 | face = Face.BOTTOM; 338 | blockLocation = b.getPos(); 339 | break getBlock; 340 | } 341 | else if ((x == 0 && z == 1 && y == 0)) { 342 | face = Face.EAST; 343 | blockLocation = b.getPos(); 344 | break getBlock; 345 | } 346 | else if ((x == 0 && z == -1 && y == 0)) { 347 | face = Face.WEST; 348 | blockLocation = b.getPos(); 349 | break getBlock; 350 | } 351 | } 352 | } 353 | } 354 | } 355 | if (face == Face.INVALID) { 356 | PhaseBot.getConsole().println("Block cannot be place at " + location + "."); 357 | return; 358 | } 359 | // $20 says this doesn't matter, thanks Mojang 360 | switch (face) { 361 | case TOP: 362 | look(0, 90); 363 | // cursorX = 8; 364 | // cursorZ = 8; 365 | cursorX = 0; 366 | cursorY = 0; 367 | cursorZ = 0; 368 | break; 369 | case BOTTOM: 370 | look(0, -90); 371 | cursorX = 8; 372 | cursorY = 16; 373 | cursorZ = 8; 374 | break; 375 | case NORTH: 376 | look(0, 0); 377 | cursorX = 8; 378 | cursorY = 8; 379 | break; 380 | case SOUTH: 381 | look(180, 0); 382 | cursorX = 8; 383 | cursorY = 8; 384 | cursorZ = 16; 385 | break; 386 | case EAST: 387 | look(90, 0); 388 | cursorX = 16; 389 | cursorY = 8; 390 | cursorZ = 8; 391 | break; 392 | case WEST: 393 | look(-90, 0); 394 | cursorX = 8; 395 | cursorZ = 0; 396 | break; 397 | case INVALID: 398 | default: 399 | return; 400 | } 401 | blockLocation = blockLocation.floor(); 402 | // PhaseBot.getConsole().println(face + " " + cursorX + " " + cursorY + 403 | // " " + cursorZ + " :: " + blockLocation); 404 | client.getSession().send(new ClientPlayerPlaceBlockPacket(Vector3d.toPosition(blockLocation), face, 405 | inventory.getHeldItem(), cursorX, cursorY, cursorZ)); 406 | try { 407 | if (Material.getMaterial(inventory.getHeldItem().getId()) instanceof BlockType) 408 | ChunkColumn.setBlock(Vector3d.toPosition(location), inventory.getHeldItem().getId()); 409 | } 410 | catch (Exception e) { 411 | // Silently catch because that's good software design 412 | } 413 | } 414 | 415 | public void setSlot(int i) { 416 | // PhaseBot.getConsole().println("Changing slot to " + i); 417 | client.getSession().send(new ClientChangeHeldItemPacket(i)); 418 | inventory.setHeldSlot(i); 419 | // Fucking Mojang is fucking stupid because they don't update a 420 | // Player's slot until they move. THANKS DUMBASSES 421 | look(yaw, pitch); 422 | } 423 | 424 | public void getCloseToAbsolute(Vector3d a) { 425 | getCloseTo(absoluteToRelative(a)); 426 | } 427 | 428 | public void getCloseTo(Vector3d r) { 429 | double tx = pos.x + r.x; 430 | double ty = pos.y + r.y; 431 | double tz = pos.z + r.z; 432 | double distance = Math.sqrt(Math.pow(pos.x - tx, 2) + Math.pow(pos.y - ty, 2) + Math.pow(pos.z - tz, 2)); 433 | if (distance > 4) { 434 | move(r.x, r.y, r.z); 435 | /* 436 | * @formatter:off 437 | * try { 438 | System.out.println(tx + " " + ty + " " + tz); 439 | AStar path = new AStar(new Vector3d(pos.x, pos.y, pos.z), new Vector3d(tx, ty, tz), 100); 440 | ArrayList route = path.iterate(); 441 | PathingResult result = path.getPathingResult(); 442 | switch (result) { 443 | case SUCCESS: 444 | // Path was successful. Do something here. 445 | PhaseBot.getBot().moveAlong(route); 446 | break; 447 | case NO_PATH: 448 | default: 449 | break; 450 | } 451 | } 452 | catch (Exception e) { 453 | e.printStackTrace(); 454 | } 455 | @formatter:on 456 | */ 457 | } 458 | } 459 | 460 | public void openChest() { 461 | // client.getSession().send(new Client); 462 | } 463 | 464 | public double getRelativeDistanceAway(Vector3d r) { 465 | return getDistanceAway(relativeToAbsolute(r)); 466 | } 467 | 468 | public double getDistanceAway(Vector3d l) { 469 | return Math.sqrt(Math.pow(pos.x - l.x, 2) + Math.pow(pos.y - l.y, 2) + Math.pow(pos.z - l.z, 2)); 470 | } 471 | 472 | public Block getClosestBlock(Material material, int range) { 473 | ArrayList matches = new ArrayList(); 474 | for (int x = 0; x < range; x++) { 475 | for (int y = 0; y < range; y++) { 476 | for (int z = 0; z < range; z++) { 477 | Block b; // cache 478 | if ((b = Block.getBlock(pos.x + x, pos.y + x, pos.z + z)).getMaterial() == material) { 479 | matches.add(b); 480 | } 481 | } 482 | } 483 | } 484 | double shortestDistance = range; 485 | Block best = null; 486 | for (Block g : matches) { 487 | if (shortestDistance == range) { 488 | best = g; 489 | shortestDistance = getDistanceAway(g.getPos()); 490 | } 491 | else { 492 | double d; // cache 493 | if ((d = getDistanceAway(g.getPos())) < shortestDistance) { 494 | best = g; 495 | shortestDistance = d; 496 | } 497 | } 498 | } 499 | System.out.println(best.getPos()); 500 | return best; 501 | } 502 | } -------------------------------------------------------------------------------- /src/xyz/jadonfowler/phasebot/ChatMessage.java: -------------------------------------------------------------------------------- 1 | package xyz.jadonfowler.phasebot; 2 | 3 | import lombok.*; 4 | 5 | public class ChatMessage { 6 | 7 | @Getter @Setter private String message = null; 8 | @Getter @Setter private String sender = null; 9 | @Getter private String command = null; 10 | 11 | public ChatMessage(String full) { 12 | try { 13 | //PhaseBot.getConsole().println(full); 14 | if (full.matches("\\[(.*)\\](.*): (.*)")) { 15 | sender = full.split("]")[1].split(": ")[0]; 16 | message = full.split(": ")[1]; 17 | } 18 | else if (full.matches("\\[\\[(.*)\\](.*) -> me\\] (.*)")) { 19 | sender = full.split("]")[1].split(" ")[0]; 20 | // private messages don't need to put prefix 21 | message = PhaseBot.getPrefix() + full.split("] ")[1]; 22 | } 23 | else if (full.matches("<(.+)> (.+)")) { 24 | sender = full.split("<")[1].split(">")[0]; 25 | message = full.split("> ")[1]; 26 | //PhaseBot.getConsole().println(sender + ": " + message); 27 | } 28 | 29 | if (message != null && message.startsWith(PhaseBot.getPrefix())) 30 | command = message.replaceFirst(PhaseBot.getPrefix(), "").split(" ")[0]; 31 | } 32 | catch (Exception e) {} 33 | } 34 | 35 | public boolean isCommand() { 36 | return command != null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/xyz/jadonfowler/phasebot/PacketHandler.java: -------------------------------------------------------------------------------- 1 | package xyz.jadonfowler.phasebot; 2 | 3 | import java.awt.*; 4 | import java.util.*; 5 | import org.spacehq.mc.protocol.data.game.*; 6 | import org.spacehq.mc.protocol.data.game.values.*; 7 | import org.spacehq.mc.protocol.data.game.values.world.block.*; 8 | import org.spacehq.mc.protocol.data.message.*; 9 | import org.spacehq.mc.protocol.packet.ingame.client.*; 10 | import org.spacehq.mc.protocol.packet.ingame.client.player.*; 11 | import org.spacehq.mc.protocol.packet.ingame.server.*; 12 | import org.spacehq.mc.protocol.packet.ingame.server.entity.*; 13 | import org.spacehq.mc.protocol.packet.ingame.server.entity.player.*; 14 | import org.spacehq.mc.protocol.packet.ingame.server.entity.spawn.*; 15 | import org.spacehq.mc.protocol.packet.ingame.server.window.*; 16 | import org.spacehq.mc.protocol.packet.ingame.server.world.*; 17 | import org.spacehq.packetlib.event.session.*; 18 | import xyz.jadonfowler.phasebot.entity.*; 19 | import xyz.jadonfowler.phasebot.inventory.*; 20 | import xyz.jadonfowler.phasebot.script.*; 21 | import xyz.jadonfowler.phasebot.world.*; 22 | 23 | public class PacketHandler extends SessionAdapter { 24 | @Override public void packetReceived(PacketReceivedEvent event) { 25 | if (event.getPacket() instanceof ServerJoinGamePacket) { 26 | event.getSession().send(new ClientChatPacket("PhaseBot has joined the game.")); 27 | PhaseBot.getBot().entityId = event. getPacket().getEntityId(); 28 | } 29 | else if (event.getPacket() instanceof ServerPlayerPositionRotationPacket) { 30 | PhaseBot.getBot().pos.x = event. getPacket().getX(); 31 | PhaseBot.getBot().pos.y = event. getPacket().getY(); 32 | PhaseBot.getBot().pos.z = event. getPacket().getZ(); 33 | PhaseBot.getBot().pitch = event. getPacket().getPitch(); 34 | PhaseBot.getBot().yaw = event. getPacket().getYaw(); 35 | PhaseBot.getConsole().println("My Position: " + PhaseBot.getBot().pos.x + "," + PhaseBot.getBot().pos.y 36 | + "," + PhaseBot.getBot().pos.z); 37 | event.getSession().send(new ClientPlayerPositionRotationPacket(false, PhaseBot.getBot().pos.x, 38 | PhaseBot.getBot().pos.y, PhaseBot.getBot().pos.z, PhaseBot.getBot().pitch, PhaseBot.getBot().yaw)); 39 | } 40 | else if (event.getPacket() instanceof ServerSpawnObjectPacket) { 41 | int entityId = event. getPacket().getEntityId(); 42 | double x = event. getPacket().getX(); 43 | double y = event. getPacket().getY(); 44 | double z = event. getPacket().getZ(); 45 | String type = event. getPacket().getType().toString(); 46 | new Entity(entityId, type, x, y, z); 47 | } 48 | else if (event.getPacket() instanceof ServerSpawnPlayerPacket) { 49 | int entityId = event. getPacket().getEntityId(); 50 | double x = event. getPacket().getX(); 51 | double y = event. getPacket().getY(); 52 | double z = event. getPacket().getZ(); 53 | UUID u = event. getPacket().getUUID(); 54 | new Player(entityId, u, x, y, z); 55 | } 56 | else if (event.getPacket() instanceof ServerSpawnMobPacket) { 57 | int entityId = event. getPacket().getEntityId(); 58 | double x = event. getPacket().getX(); 59 | double y = event. getPacket().getY(); 60 | double z = event. getPacket().getZ(); 61 | String type = event. getPacket().getType().toString(); 62 | new Entity(entityId, type, x, y, z); 63 | } 64 | else if (event.getPacket() instanceof ServerDestroyEntitiesPacket) { 65 | for (int i : event. getPacket().getEntityIds()) { 66 | if (Entity.getEntities().containsKey(i)) { 67 | Entity e = Entity.byId(i); 68 | if (e instanceof Player) Player.players.remove((Player) e); 69 | e.remove(); 70 | } 71 | } 72 | } 73 | else if (event.getPacket() instanceof ServerUpdateHealthPacket) { 74 | if (event. getPacket().getHealth() <= 0) { 75 | event.getSession().send(new ClientRequestPacket(ClientRequest.RESPAWN)); 76 | } 77 | } 78 | else if (event.getPacket() instanceof ServerEntityPositionRotationPacket) { 79 | ServerEntityMovementPacket p = event. getPacket(); 80 | int id = p.getEntityId(); 81 | Entity e = Entity.byId(id); 82 | e.x += p.getMovementX(); 83 | e.y += p.getMovementY(); 84 | e.z += p.getMovementZ(); 85 | e.pitch = p.getPitch(); 86 | e.yaw = p.getYaw(); 87 | } 88 | else if (event.getPacket() instanceof ServerEntityTeleportPacket) { 89 | ServerEntityTeleportPacket p = event. getPacket(); 90 | int id = p.getEntityId(); 91 | Entity e = Entity.byId(id); 92 | e.x = p.getX(); 93 | e.y = p.getY(); 94 | e.z = p.getZ(); 95 | e.pitch = p.getPitch(); 96 | e.yaw = p.getYaw(); 97 | } 98 | else if (event.getPacket() instanceof ServerChunkDataPacket) { 99 | ServerChunkDataPacket p = event. getPacket(); 100 | new ChunkColumn(p.getX(), p.getZ(), p.getChunks()); 101 | } 102 | else if (event.getPacket() instanceof ServerMultiChunkDataPacket) { 103 | for (int i = 0; i < event. getPacket().getColumns(); i++) { 104 | int chunkX = event. getPacket().getX(i); 105 | int chunkZ = event. getPacket().getZ(i); 106 | new ChunkColumn(chunkX, chunkZ, event. getPacket().getChunks(i)); 107 | } 108 | } 109 | else if (event.getPacket() instanceof ServerMultiBlockChangePacket) { 110 | ServerMultiBlockChangePacket packet = event. getPacket(); 111 | for (BlockChangeRecord r : packet.getRecords()) { 112 | Position p = r.getPosition(); 113 | int id = r.getId(); 114 | ChunkColumn.setBlock(p, id >> 4); 115 | PhaseBot.getBot().setInteruptMoveAlong(true); 116 | } 117 | } 118 | else if (event.getPacket() instanceof ServerBlockChangePacket) { 119 | Position p = event. getPacket().getRecord().getPosition(); 120 | int id = event. getPacket().getRecord().getId(); 121 | ChunkColumn.setBlock(p, id >> 4); 122 | PhaseBot.getBot().setInteruptMoveAlong(true); 123 | } 124 | else if (event.getPacket() instanceof ServerWindowItemsPacket) { 125 | ServerWindowItemsPacket p = event. getPacket(); 126 | if (p.getWindowId() == 0) {// Player's inventory 127 | PhaseBot.getBot().setInventory(new Inventory(p.getItems())); 128 | PhaseBot.getConsole().println("Inventory recieved!"); 129 | } 130 | } 131 | else if (event.getPacket() instanceof ServerSetSlotPacket) { 132 | ServerSetSlotPacket p = event. getPacket(); 133 | if (p.getWindowId() == 0) {// Player's Inventory 134 | PhaseBot.getBot().getInventory().setItem(p.getSlot(), p.getItem()); 135 | // if(p.getItem() != null) 136 | // PhaseBot.getConsole().println("Inventory Slot #" + 137 | // p.getSlot() + " change to " + p.getItem().getId()); 138 | } 139 | } 140 | else if (event.getPacket() instanceof ServerChatPacket) { 141 | Message message = event. getPacket().getMessage(); 142 | try { 143 | String t = message.getFullText(); 144 | PhaseBot.getConsole().addChatMessage(t); 145 | ChatMessage m = new ChatMessage(t); 146 | if (!m.isCommand()) return; 147 | if (!Arrays.asList(PhaseBot.getOwners()).contains(m.getSender())) { 148 | event.getSession().send(new ClientChatPacket("/msg " + m.getSender() + " You are not my master!")); 149 | return; 150 | } 151 | if (m.getMessage().startsWith(PhaseBot.getPrefix())) { 152 | String command = m.getMessage().replaceFirst(PhaseBot.getPrefix(), ""); 153 | command = Script.replaceVariables(command); 154 | PhaseBot.getBot().runCommand(command, true); 155 | } 156 | } 157 | catch (Exception e) { 158 | e.printStackTrace(); 159 | } 160 | } 161 | } 162 | 163 | @Override public void disconnected(DisconnectedEvent event) { 164 | PhaseBot.getConsole().println("Disconnected: " + Message.fromString(event.getReason()).getFullText(), false, 165 | Color.RED); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/xyz/jadonfowler/phasebot/PhaseBot.java: -------------------------------------------------------------------------------- 1 | package xyz.jadonfowler.phasebot; 2 | 3 | import java.awt.*; 4 | import java.awt.event.*; 5 | import java.io.*; 6 | import java.net.*; 7 | import java.util.*; 8 | import javax.swing.*; 9 | import org.reflections.*; 10 | import org.spacehq.mc.auth.data.*; 11 | import org.spacehq.mc.protocol.*; 12 | import org.spacehq.mc.protocol.data.*; 13 | import org.spacehq.mc.protocol.data.status.*; 14 | import org.spacehq.mc.protocol.data.status.handler.*; 15 | import org.spacehq.packetlib.*; 16 | import org.spacehq.packetlib.tcp.*; 17 | import com.sun.jna.*; 18 | import lombok.*; 19 | import xyz.jadonfowler.phasebot.cmd.*; 20 | import xyz.jadonfowler.phasebot.gui.*; 21 | import xyz.jadonfowler.phasebot.gui.map.*; 22 | import xyz.jadonfowler.phasebot.jna.*; 23 | import xyz.jadonfowler.phasebot.script.*; 24 | import xyz.jadonfowler.phasebot.world.*; 25 | 26 | public class PhaseBot { 27 | 28 | @Getter @Setter private static String prefix = "."; 29 | @Getter private static String[] owners = { "Phase", "Voltz" }; 30 | private static String USERNAME = "username"; 31 | // Build Server // 32 | public static String HOST = "mc.openredstone.org"; 33 | private static int PORT = 25569; 34 | // ------------ // 35 | private static Proxy PROXY = Proxy.NO_PROXY; 36 | private static boolean VERIFY_USERS = true; 37 | private static OS operatingSystem = null; 38 | public static Random random = new Random(); 39 | public static ArrayList commands = new ArrayList(); 40 | private static CommandManager manager = null; 41 | public static ArrayList