diff --git a/LICENSE.txt b/LICENSE.txt index 6412abd4..ff34e2af 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (C) 2012 Steveice10 +Copyright (C) 2013 Steveice10 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index c27b52aa..dca2e3a6 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,28 @@ -

mc-protocol-lib

+

MCProtocolLib

========== -About mc-protocol-lib +About MCProtocolLib -------- -mc-protocol-lib is a simple library for communicating with a Minecraft client/server. It aims to allow people to make custom bots, clients, or servers for Minecraft easily. +MCProtocolLib is a simple library for communicating with a Minecraft client/server. It aims to allow people to make custom bots, clients, or servers for Minecraft easily. +The library is split into two packages, ch.spacebase.mc.auth and ch.spacebase.mc.protocol. The auth package contains some classes to work with Mojang's auth servers and the protocol package contains the protocol library. -Server List Ping +Example Code -------- -When you receive a server list ping packet when listening to a server, respond by calling connection.disconnect(Util.formatPingResponse(motd, players, maxplayers)); - -When you are sending a ping request, do the following: - connection.send(new PacketServerPing()); - connection.send(Util.prepareClientPingData(connection.getHost(), connection.getPort())); - - -Chat Bot Example --------- - -See ch.spacebase.mcprotocol.example.ChatBot +See ch.spacebase.mc.protocol.test.Test. Building the Source -------- -mc-protocol-lib uses Maven to manage dependencies. Simply run 'mvn clean install' in the source's directory. +MCProtocolLib uses Maven to manage dependencies. Simply run 'mvn clean install' in the source's directory. License --------- -mc-protocol-lib is licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.html). +MCProtocolLib is licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.html). diff --git a/pom.xml b/pom.xml index a707b145..5ffab6ac 100644 --- a/pom.xml +++ b/pom.xml @@ -1,13 +1,15 @@ - + + 4.0.0 ch.spacebase - mc-protocol-lib - dev-SNAPSHOT + mcprotocollib + 1.7.2-SNAPSHOT jar - mc-protocol-lib + MCProtocolLib A library for communicating with a Minecraft client or server. - http://github.com/Steveice10/mc-protocol-lib/ + http://github.com/Steveice10/MCProtocolLib/ @@ -18,9 +20,9 @@ - scm:git:git@github.com:Steveice10/mc-protocol-lib.git - scm:git:git@github.com:Steveice10/mc-protocol-lib.git - git@github.com:Steveice10/mc-protocol-lib/ + scm:git:git@github.com:Steveice10/MCProtocolLib.git + scm:git:git@github.com:Steveice10/MCProtocolLib.git + git@github.com:Steveice10/MCProtocolLib/ @@ -36,24 +38,47 @@ - - - steveice10 - Steveice10 - Steveice10@gmail.com - - + + + steveice10 + Steveice10 + Steveice10@gmail.com + + + + + + spacebase-releases + http://repo.spacebase.ch/content/repositories/release/ + + + spacebase-snapshots + http://repo.spacebase.ch/content/repositories/snapshots/ + + UTF-8 - + - org.bouncycastle - bcprov-jdk15on - 1.47 + ch.spacebase + opennbt + 1.2 + compile + + + ch.spacebase + packetlib + 1.0-SNAPSHOT + compile + + + com.google.code.gson + gson + 2.2.4 @@ -86,16 +111,16 @@ - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + diff --git a/src/main/java/ch/spacebase/mc/auth/AuthenticationService.java b/src/main/java/ch/spacebase/mc/auth/AuthenticationService.java new file mode 100644 index 00000000..2b720bb7 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/AuthenticationService.java @@ -0,0 +1,141 @@ +package ch.spacebase.mc.auth; + +import ch.spacebase.mc.auth.SessionService; +import ch.spacebase.mc.auth.UserAuthentication; +import ch.spacebase.mc.auth.exceptions.AuthenticationException; +import ch.spacebase.mc.auth.exceptions.AuthenticationUnavailableException; +import ch.spacebase.mc.auth.exceptions.InvalidCredentialsException; +import ch.spacebase.mc.auth.exceptions.UserMigratedException; +import ch.spacebase.mc.auth.response.Response; +import ch.spacebase.mc.util.IOUtils; + +import com.google.gson.Gson; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +public class AuthenticationService { + + private String clientToken; + private Gson gson = new Gson(); + + public AuthenticationService(String clientToken) { + this.clientToken = clientToken; + } + + public UserAuthentication createUserAuthentication() { + return new UserAuthentication(this); + } + + public SessionService createMinecraftSessionService() { + return new SessionService(this); + } + + public String getClientToken() { + return this.clientToken; + } + + public T makeRequest(URL url, Object input, Class clazz) throws AuthenticationException { + try { + String jsonString = input == null ? this.performGetRequest(url) : this.performPostRequest(url, this.gson.toJson(input), "application/json"); + T result = this.gson.fromJson(jsonString, clazz); + if(result == null) { + return null; + } else if(result.getError() != null && !result.getError().equals("")) { + if(result.getCause() != null && result.getCause().equals("UserMigratedException")) { + throw new UserMigratedException(result.getErrorMessage()); + } else if(result.getError().equals("ForbiddenOperationException")) { + throw new InvalidCredentialsException(result.getErrorMessage()); + } else { + throw new AuthenticationException(result.getErrorMessage()); + } + } else { + return result; + } + } catch(Exception e) { + throw new AuthenticationUnavailableException("Could not make request to auth server.", e); + } + } + + private HttpURLConnection createUrlConnection(URL url) throws IOException { + if(url == null) { + throw new IllegalArgumentException("URL cannot be null."); + } + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setConnectTimeout(15000); + connection.setReadTimeout(15000); + connection.setUseCaches(false); + return connection; + } + + private String performPostRequest(URL url, String post, String type) throws IOException { + if(url == null) { + throw new IllegalArgumentException("URL cannot be null."); + } + + if(post == null) { + throw new IllegalArgumentException("Post cannot be null."); + } + + if(type == null) { + throw new IllegalArgumentException("Type cannot be null."); + } + + HttpURLConnection connection = this.createUrlConnection(url); + byte[] bytes = post.getBytes("UTF-8"); + connection.setRequestProperty("Content-Type", type + "; charset=utf-8"); + connection.setRequestProperty("Content-Length", "" + bytes.length); + connection.setDoOutput(true); + OutputStream outputStream = null; + try { + outputStream = connection.getOutputStream(); + outputStream.write(bytes); + } finally { + IOUtils.closeQuietly(outputStream); + } + + InputStream inputStream = null; + try { + inputStream = connection.getInputStream(); + return IOUtils.toString(inputStream, "UTF-8"); + } catch(IOException e) { + IOUtils.closeQuietly(inputStream); + inputStream = connection.getErrorStream(); + if(inputStream == null) { + throw e; + } + + return IOUtils.toString(inputStream,"UTF-8"); + } finally { + IOUtils.closeQuietly(inputStream); + } + } + + private String performGetRequest(URL url) throws IOException { + if(url == null) { + throw new IllegalArgumentException("URL cannot be null."); + } + + HttpURLConnection connection = this.createUrlConnection(url); + InputStream inputStream = null; + try { + inputStream = connection.getInputStream(); + return IOUtils.toString(inputStream, "UTF-8"); + } catch(IOException e) { + IOUtils.closeQuietly(inputStream); + inputStream = connection.getErrorStream(); + if(inputStream == null) { + throw e; + } + + return IOUtils.toString(inputStream, "UTF-8"); + } finally { + IOUtils.closeQuietly(inputStream); + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/GameProfile.java b/src/main/java/ch/spacebase/mc/auth/GameProfile.java new file mode 100644 index 00000000..bd1fa030 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/GameProfile.java @@ -0,0 +1,53 @@ +package ch.spacebase.mc.auth; + +public class GameProfile { + + private String id; + private String name; + + public GameProfile(String id, String name) { + if((id == null || id.equals("")) && (name == null || name.equals(""))) { + throw new IllegalArgumentException("Name and ID cannot both be blank"); + } else { + this.id = id; + this.name = name; + } + } + + public String getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public boolean isComplete() { + return this.id != null && !this.id.equals("") && this.name != null && !this.name.equals(""); + } + + @Override + public boolean equals(Object o) { + if(this == o) { + return true; + } else if(o != null && this.getClass() == o.getClass()) { + GameProfile that = (GameProfile) o; + return !this.id.equals(that.id) ? false : this.name.equals(that.name); + } else { + return false; + } + } + + @Override + public int hashCode() { + int result = this.id.hashCode(); + result = 31 * result + this.name.hashCode(); + return result; + } + + @Override + public String toString() { + return "GameProfile{id=\'" + this.id + '\'' + ", name=\'" + this.name + '\'' + '}'; + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/SessionService.java b/src/main/java/ch/spacebase/mc/auth/SessionService.java new file mode 100644 index 00000000..85396aad --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/SessionService.java @@ -0,0 +1,51 @@ +package ch.spacebase.mc.auth; + +import ch.spacebase.mc.auth.AuthenticationService; +import ch.spacebase.mc.auth.exceptions.AuthenticationException; +import ch.spacebase.mc.auth.exceptions.AuthenticationUnavailableException; +import ch.spacebase.mc.auth.request.JoinServerRequest; +import ch.spacebase.mc.auth.response.HasJoinedResponse; +import ch.spacebase.mc.auth.response.Response; +import ch.spacebase.mc.util.URLUtils; + +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +public class SessionService { + + private static final String BASE_URL = "https://sessionserver.mojang.com/session/minecraft/"; + private static final URL JOIN_URL = URLUtils.constantURL(BASE_URL + "join"); + private static final URL CHECK_URL = URLUtils.constantURL(BASE_URL + "hasJoined"); + + private AuthenticationService authService; + + protected SessionService(AuthenticationService authService) { + this.authService = authService; + } + + public void joinServer(GameProfile profile, String authenticationToken, String serverId) throws AuthenticationException { + JoinServerRequest request = new JoinServerRequest(authenticationToken, profile.getId(), serverId); + this.getAuthenticationService().makeRequest(JOIN_URL, request, Response.class); + } + + public GameProfile hasJoinedServer(GameProfile user, String serverId) throws AuthenticationUnavailableException { + Map arguments = new HashMap(); + arguments.put("username", user.getName()); + arguments.put("serverId", serverId); + URL url = URLUtils.concatenateURL(CHECK_URL, URLUtils.buildQuery(arguments)); + try { + HasJoinedResponse e = this.getAuthenticationService().makeRequest(url, null, HasJoinedResponse.class); + return e != null && e.getId() != null ? new GameProfile(e.getId(), user.getName()) : null; + } catch(AuthenticationUnavailableException var6) { + throw var6; + } catch(AuthenticationException var7) { + return null; + } + } + + public AuthenticationService getAuthenticationService() { + return this.authService; + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/UserAuthentication.java b/src/main/java/ch/spacebase/mc/auth/UserAuthentication.java new file mode 100644 index 00000000..d0f306b2 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/UserAuthentication.java @@ -0,0 +1,264 @@ +package ch.spacebase.mc.auth; + +import ch.spacebase.mc.auth.AuthenticationService; +import ch.spacebase.mc.auth.exceptions.AuthenticationException; +import ch.spacebase.mc.auth.exceptions.InvalidCredentialsException; +import ch.spacebase.mc.auth.request.AuthenticationRequest; +import ch.spacebase.mc.auth.request.RefreshRequest; +import ch.spacebase.mc.auth.response.AuthenticationResponse; +import ch.spacebase.mc.auth.response.RefreshResponse; +import ch.spacebase.mc.auth.response.User; +import ch.spacebase.mc.util.URLUtils; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +public class UserAuthentication { + + private static final String BASE_URL = "https://authserver.mojang.com/"; + private static final URL ROUTE_AUTHENTICATE = URLUtils.constantURL(BASE_URL + "authenticate"); + private static final URL ROUTE_REFRESH = URLUtils.constantURL(BASE_URL + "refresh"); + private static final String STORAGE_KEY_PROFILE_NAME = "displayName"; + private static final String STORAGE_KEY_PROFILE_ID = "uuid"; + private static final String STORAGE_KEY_USER_NAME = "username"; + private static final String STORAGE_KEY_USER_ID = "userid"; + private static final String STORAGE_KEY_ACCESS_TOKEN = "accessToken"; + + private AuthenticationService authService; + private Map userProperties = new HashMap(); + private String userId; + private String username; + private String password; + private String accessToken; + private boolean isOnline; + private List profiles = new ArrayList(); + private GameProfile selectedProfile; + + public UserAuthentication(AuthenticationService authService) { + if(authService == null) { + throw new IllegalArgumentException("AuthService cannot be null."); + } + this.authService = authService; + } + + public AuthenticationService getAuthenticationService() { + return this.authService; + } + + public String getUserID() { + return this.userId; + } + + public String getAccessToken() { + return this.accessToken; + } + + public List getAvailableProfiles() { + return this.profiles; + } + + public GameProfile getSelectedProfile() { + return this.selectedProfile; + } + + public Map getUserProperties() { + return this.isLoggedIn() ? Collections.unmodifiableMap(this.userProperties) : Collections.unmodifiableMap(new HashMap()); + } + + public boolean isLoggedIn() { + return this.accessToken != null && !this.accessToken.equals(""); + } + + public boolean canPlayOnline() { + return this.isLoggedIn() && this.getSelectedProfile() != null && this.isOnline; + } + + public boolean canLogIn() { + return !this.canPlayOnline() && this.username != null && !this.username.equals("") && ((this.password != null && !this.password.equals("")) || (this.accessToken != null && !this.accessToken.equals(""))); + } + + public void setUsername(String username) { + if(this.isLoggedIn() && this.canPlayOnline()) { + throw new IllegalStateException("Cannot change username whilst logged in & online"); + } else { + this.username = username; + } + } + + public void setPassword(String password) { + if(this.isLoggedIn() && this.canPlayOnline() && this.password != null && !this.password.equals("")) { + throw new IllegalStateException("Cannot set password whilst logged in & online"); + } else { + this.password = password; + } + } + + public void loadFromStorage(Map credentials) { + this.logOut(); + this.setUsername(credentials.get(STORAGE_KEY_USER_NAME)); + if(credentials.containsKey(STORAGE_KEY_USER_ID)) { + this.userId = credentials.get(STORAGE_KEY_USER_ID); + } else { + this.userId = this.username; + } + + if(credentials.containsKey(STORAGE_KEY_PROFILE_NAME) && credentials.containsKey(STORAGE_KEY_PROFILE_ID)) { + this.selectedProfile = new GameProfile(credentials.get(STORAGE_KEY_PROFILE_ID), credentials.get(STORAGE_KEY_PROFILE_NAME)); + } + + this.accessToken = credentials.get(STORAGE_KEY_ACCESS_TOKEN); + } + + public Map saveForStorage() { + Map result = new HashMap(); + if(this.username != null) { + result.put(STORAGE_KEY_USER_NAME, this.username); + } + + if(this.getUserID() != null) { + result.put(STORAGE_KEY_USER_ID, this.userId); + } + + if(this.selectedProfile != null) { + result.put(STORAGE_KEY_PROFILE_NAME, this.selectedProfile.getName()); + result.put(STORAGE_KEY_PROFILE_ID, this.selectedProfile.getId()); + } + + if(this.accessToken != null && !this.accessToken.equals("")) { + result.put(STORAGE_KEY_ACCESS_TOKEN, this.accessToken); + } + + return result; + } + + public void logIn() throws AuthenticationException { + if(this.username == null || this.username.equals("")) { + throw new InvalidCredentialsException("Invalid username"); + } else { + if(this.accessToken != null && !this.accessToken.equals("")) { + this.logInWithToken(); + } else { + if(this.password == null || this.password.equals("")) { + throw new InvalidCredentialsException("Invalid password"); + } + + this.logInWithPassword(); + } + } + } + + protected void logInWithPassword() throws AuthenticationException { + if(this.username == null || this.username.equals("")) { + throw new InvalidCredentialsException("Invalid username"); + } else if(this.password == null || this.password.equals("")) { + throw new InvalidCredentialsException("Invalid password"); + } else { + AuthenticationRequest request = new AuthenticationRequest(this, this.username, this.password); + AuthenticationResponse response = this.authService.makeRequest(ROUTE_AUTHENTICATE, request, AuthenticationResponse.class); + if(!response.getClientToken().equals(this.getAuthenticationService().getClientToken())) { + throw new AuthenticationException("Server requested we change our client token. Don\'t know how to handle this!"); + } else { + if(response.getUser() != null && response.getUser().getId() != null) { + this.userId = response.getUser().getId(); + } else { + this.userId = this.username; + } + + this.isOnline = true; + this.accessToken = response.getAccessToken(); + this.profiles = Arrays.asList(response.getAvailableProfiles()); + this.selectedProfile = response.getSelectedProfile(); + this.userProperties.clear(); + if(response.getUser() != null && response.getUser().getProperties() != null) { + Iterator it = response.getUser().getProperties().iterator(); + while(it.hasNext()) { + User.Property property = it.next(); + this.userProperties.put(property.getKey(), property.getValue()); + } + } + } + } + } + + protected void logInWithToken() throws AuthenticationException { + if(this.userId == null || this.userId.equals("")) { + if(this.username == null || this.username.equals("")) { + throw new InvalidCredentialsException("Invalid uuid & username"); + } + + this.userId = this.username; + } + + if(this.accessToken == null || this.accessToken.equals("")) { + throw new InvalidCredentialsException("Invalid access token"); + } else { + RefreshRequest request = new RefreshRequest(this); + RefreshResponse response = this.getAuthenticationService().makeRequest(ROUTE_REFRESH, request, RefreshResponse.class); + if(!response.getClientToken().equals(this.getAuthenticationService().getClientToken())) { + throw new AuthenticationException("Server requested we change our client token. Don\'t know how to handle this!"); + } else { + if(response.getUser() != null && response.getUser().getId() != null) { + this.userId = response.getUser().getId(); + } else { + this.userId = this.username; + } + + this.isOnline = true; + this.accessToken = response.getAccessToken(); + this.profiles = Arrays.asList(response.getAvailableProfiles()); + this.selectedProfile = response.getSelectedProfile(); + this.userProperties.clear(); + if(response.getUser() != null && response.getUser().getProperties() != null) { + Iterator it = response.getUser().getProperties().iterator(); + while(it.hasNext()) { + User.Property property = it.next(); + this.userProperties.put(property.getKey(), property.getValue()); + } + } + + } + } + } + + public void logOut() { + this.password = null; + this.userId = null; + this.selectedProfile = null; + this.userProperties.clear(); + this.accessToken = null; + this.profiles = null; + this.isOnline = false; + } + + public void selectGameProfile(GameProfile profile) throws AuthenticationException { + if(!this.isLoggedIn()) { + throw new AuthenticationException("Cannot change game profile whilst not logged in"); + } else if(this.getSelectedProfile() != null) { + throw new AuthenticationException("Cannot change game profile. You must log out and back in."); + } else if(profile != null && this.profiles.contains(profile)) { + RefreshRequest request = new RefreshRequest(this, profile); + RefreshResponse response = this.getAuthenticationService().makeRequest(ROUTE_REFRESH, request, RefreshResponse.class); + if(!response.getClientToken().equals(this.getAuthenticationService().getClientToken())) { + throw new AuthenticationException("Server requested we change our client token. Don\'t know how to handle this!"); + } else { + this.isOnline = true; + this.accessToken = response.getAccessToken(); + this.selectedProfile = response.getSelectedProfile(); + } + } else { + throw new IllegalArgumentException("Invalid profile \'" + profile + "\'"); + } + } + + @Override + public String toString() { + return "AuthenticationService{profiles=" + this.profiles + ", selectedProfile=" + this.getSelectedProfile() + ", username=" + this.username + ", isLoggedIn=" + this.isLoggedIn() + ", canPlayOnline=" + this.canPlayOnline() + ", accessToken=" + this.accessToken + ", clientToken=" + this.authService.getClientToken() + "}"; + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/exceptions/AuthenticationException.java b/src/main/java/ch/spacebase/mc/auth/exceptions/AuthenticationException.java new file mode 100644 index 00000000..c9fc7b5f --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/exceptions/AuthenticationException.java @@ -0,0 +1,22 @@ +package ch.spacebase.mc.auth.exceptions; + +public class AuthenticationException extends Exception { + + private static final long serialVersionUID = 1L; + + public AuthenticationException() { + } + + public AuthenticationException(String message) { + super(message); + } + + public AuthenticationException(String message, Throwable cause) { + super(message, cause); + } + + public AuthenticationException(Throwable cause) { + super(cause); + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/exceptions/AuthenticationUnavailableException.java b/src/main/java/ch/spacebase/mc/auth/exceptions/AuthenticationUnavailableException.java new file mode 100644 index 00000000..ecbfe7e2 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/exceptions/AuthenticationUnavailableException.java @@ -0,0 +1,23 @@ +package ch.spacebase.mc.auth.exceptions; + +import ch.spacebase.mc.auth.exceptions.AuthenticationException; + +public class AuthenticationUnavailableException extends AuthenticationException { + + private static final long serialVersionUID = 1L; + + public AuthenticationUnavailableException() { + } + + public AuthenticationUnavailableException(String message) { + super(message); + } + + public AuthenticationUnavailableException(String message, Throwable cause) { + super(message, cause); + } + + public AuthenticationUnavailableException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/ch/spacebase/mc/auth/exceptions/InvalidCredentialsException.java b/src/main/java/ch/spacebase/mc/auth/exceptions/InvalidCredentialsException.java new file mode 100644 index 00000000..94c477cb --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/exceptions/InvalidCredentialsException.java @@ -0,0 +1,23 @@ +package ch.spacebase.mc.auth.exceptions; + +import ch.spacebase.mc.auth.exceptions.AuthenticationException; + +public class InvalidCredentialsException extends AuthenticationException { + + private static final long serialVersionUID = 1L; + + public InvalidCredentialsException() { + } + + public InvalidCredentialsException(String message) { + super(message); + } + + public InvalidCredentialsException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidCredentialsException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/ch/spacebase/mc/auth/exceptions/UserMigratedException.java b/src/main/java/ch/spacebase/mc/auth/exceptions/UserMigratedException.java new file mode 100644 index 00000000..737b13ab --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/exceptions/UserMigratedException.java @@ -0,0 +1,23 @@ +package ch.spacebase.mc.auth.exceptions; + +import ch.spacebase.mc.auth.exceptions.InvalidCredentialsException; + +public class UserMigratedException extends InvalidCredentialsException { + + private static final long serialVersionUID = 1L; + + public UserMigratedException() { + } + + public UserMigratedException(String message) { + super(message); + } + + public UserMigratedException(String message, Throwable cause) { + super(message, cause); + } + + public UserMigratedException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/ch/spacebase/mc/auth/request/Agent.java b/src/main/java/ch/spacebase/mc/auth/request/Agent.java new file mode 100644 index 00000000..ab69eed2 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/request/Agent.java @@ -0,0 +1,25 @@ +package ch.spacebase.mc.auth.request; + +public class Agent { + + private String name; + private int version; + + public Agent(String name, int version) { + this.name = name; + this.version = version; + } + + public String getName() { + return this.name; + } + + public int getVersion() { + return this.version; + } + + public String toString() { + return "Agent{name=\'" + this.name + '\'' + ", version=" + this.version + '}'; + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/request/AuthenticationRequest.java b/src/main/java/ch/spacebase/mc/auth/request/AuthenticationRequest.java new file mode 100644 index 00000000..2fa59bce --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/request/AuthenticationRequest.java @@ -0,0 +1,21 @@ +package ch.spacebase.mc.auth.request; + +import ch.spacebase.mc.auth.UserAuthentication; + +@SuppressWarnings("unused") +public class AuthenticationRequest { + + private Agent agent; + private String username; + private String password; + private String clientToken; + private boolean requestUser = true; + + public AuthenticationRequest(UserAuthentication auth, String username, String password) { + this.agent = new Agent("Minecraft", 1); + this.username = username; + this.clientToken = auth.getAuthenticationService().getClientToken(); + this.password = password; + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/request/JoinServerRequest.java b/src/main/java/ch/spacebase/mc/auth/request/JoinServerRequest.java new file mode 100644 index 00000000..e0545ce5 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/request/JoinServerRequest.java @@ -0,0 +1,16 @@ +package ch.spacebase.mc.auth.request; + +@SuppressWarnings("unused") +public class JoinServerRequest { + + private String accessToken; + private String selectedProfile; + private String serverId; + + public JoinServerRequest(String accessToken, String id, String serverId) { + this.accessToken = accessToken; + this.selectedProfile = id; + this.serverId = serverId; + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/request/RefreshRequest.java b/src/main/java/ch/spacebase/mc/auth/request/RefreshRequest.java new file mode 100644 index 00000000..e5b05470 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/request/RefreshRequest.java @@ -0,0 +1,25 @@ +package ch.spacebase.mc.auth.request; + +import ch.spacebase.mc.auth.GameProfile; +import ch.spacebase.mc.auth.UserAuthentication; + +@SuppressWarnings("unused") +public class RefreshRequest { + + private String clientToken; + private String accessToken; + private GameProfile selectedProfile; + private boolean requestUser; + + public RefreshRequest(UserAuthentication authService) { + this(authService, null); + } + + public RefreshRequest(UserAuthentication authService, GameProfile profile) { + this.requestUser = true; + this.clientToken = authService.getAuthenticationService().getClientToken(); + this.accessToken = authService.getAccessToken(); + this.selectedProfile = profile; + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/response/AuthenticationResponse.java b/src/main/java/ch/spacebase/mc/auth/response/AuthenticationResponse.java new file mode 100644 index 00000000..44bd68c0 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/response/AuthenticationResponse.java @@ -0,0 +1,35 @@ +package ch.spacebase.mc.auth.response; + +import ch.spacebase.mc.auth.GameProfile; +import ch.spacebase.mc.auth.response.Response; +import ch.spacebase.mc.auth.response.User; + +public class AuthenticationResponse extends Response { + + private String accessToken; + private String clientToken; + private GameProfile selectedProfile; + private GameProfile[] availableProfiles; + private User user; + + public String getAccessToken() { + return this.accessToken; + } + + public String getClientToken() { + return this.clientToken; + } + + public GameProfile[] getAvailableProfiles() { + return this.availableProfiles; + } + + public GameProfile getSelectedProfile() { + return this.selectedProfile; + } + + public User getUser() { + return this.user; + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/response/HasJoinedResponse.java b/src/main/java/ch/spacebase/mc/auth/response/HasJoinedResponse.java new file mode 100644 index 00000000..c749d855 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/response/HasJoinedResponse.java @@ -0,0 +1,13 @@ +package ch.spacebase.mc.auth.response; + +import ch.spacebase.mc.auth.response.Response; + +public class HasJoinedResponse extends Response { + + private String id; + + public String getId() { + return this.id; + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/response/RefreshResponse.java b/src/main/java/ch/spacebase/mc/auth/response/RefreshResponse.java new file mode 100644 index 00000000..124a413c --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/response/RefreshResponse.java @@ -0,0 +1,35 @@ +package ch.spacebase.mc.auth.response; + +import ch.spacebase.mc.auth.GameProfile; +import ch.spacebase.mc.auth.response.Response; +import ch.spacebase.mc.auth.response.User; + +public class RefreshResponse extends Response { + + private String accessToken; + private String clientToken; + private GameProfile selectedProfile; + private GameProfile[] availableProfiles; + private User user; + + public String getAccessToken() { + return this.accessToken; + } + + public String getClientToken() { + return this.clientToken; + } + + public GameProfile[] getAvailableProfiles() { + return this.availableProfiles; + } + + public GameProfile getSelectedProfile() { + return this.selectedProfile; + } + + public User getUser() { + return this.user; + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/response/Response.java b/src/main/java/ch/spacebase/mc/auth/response/Response.java new file mode 100644 index 00000000..4b7bd6a1 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/response/Response.java @@ -0,0 +1,21 @@ +package ch.spacebase.mc.auth.response; + +public class Response { + + private String error; + private String errorMessage; + private String cause; + + public String getError() { + return this.error; + } + + public String getCause() { + return this.cause; + } + + public String getErrorMessage() { + return this.errorMessage; + } + +} diff --git a/src/main/java/ch/spacebase/mc/auth/response/User.java b/src/main/java/ch/spacebase/mc/auth/response/User.java new file mode 100644 index 00000000..e1fd19f6 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/auth/response/User.java @@ -0,0 +1,31 @@ +package ch.spacebase.mc.auth.response; + +import java.util.List; + +public class User { + + private String id; + private List properties; + + public String getId() { + return this.id; + } + + public List getProperties() { + return this.properties; + } + + public class Property { + private String name; + private String value; + + public String getKey() { + return this.name; + } + + public String getValue() { + return this.value; + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/ClientListener.java b/src/main/java/ch/spacebase/mc/protocol/ClientListener.java new file mode 100644 index 00000000..1d1db795 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/ClientListener.java @@ -0,0 +1,133 @@ +package ch.spacebase.mc.protocol; + +import java.math.BigInteger; + +import javax.crypto.SecretKey; + +import ch.spacebase.mc.auth.AuthenticationService; +import ch.spacebase.mc.auth.GameProfile; +import ch.spacebase.mc.auth.exceptions.AuthenticationException; +import ch.spacebase.mc.auth.exceptions.AuthenticationUnavailableException; +import ch.spacebase.mc.auth.exceptions.InvalidCredentialsException; +import ch.spacebase.mc.protocol.data.status.ServerStatusInfo; +import ch.spacebase.mc.protocol.data.status.handler.ServerInfoHandler; +import ch.spacebase.mc.protocol.data.status.handler.ServerPingTimeHandler; +import ch.spacebase.mc.protocol.packet.handshake.client.HandshakePacket; +import ch.spacebase.mc.protocol.packet.ingame.client.ClientKeepAlivePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerDisconnectPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerKeepAlivePacket; +import ch.spacebase.mc.protocol.packet.login.client.EncryptionResponsePacket; +import ch.spacebase.mc.protocol.packet.login.client.LoginStartPacket; +import ch.spacebase.mc.protocol.packet.login.server.EncryptionRequestPacket; +import ch.spacebase.mc.protocol.packet.login.server.LoginDisconnectPacket; +import ch.spacebase.mc.protocol.packet.login.server.LoginSuccessPacket; +import ch.spacebase.mc.protocol.packet.status.client.StatusPingPacket; +import ch.spacebase.mc.protocol.packet.status.client.StatusQueryPacket; +import ch.spacebase.mc.protocol.packet.status.server.StatusPongPacket; +import ch.spacebase.mc.protocol.packet.status.server.StatusResponsePacket; +import ch.spacebase.mc.util.CryptUtil; +import ch.spacebase.packetlib.event.session.ConnectedEvent; +import ch.spacebase.packetlib.event.session.PacketReceivedEvent; +import ch.spacebase.packetlib.event.session.PacketSentEvent; +import ch.spacebase.packetlib.event.session.SessionAdapter; + +public class ClientListener extends SessionAdapter { + + private SecretKey key; + private String accessToken; + private String clientToken; + + public ClientListener(String accessToken, String clientToken) { + this.accessToken = accessToken; + this.clientToken = clientToken; + } + + @Override + public void packetReceived(PacketReceivedEvent event) { + MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol(); + if(protocol.getMode() == ProtocolMode.LOGIN) { + if(event.getPacket() instanceof EncryptionRequestPacket) { + EncryptionRequestPacket packet = event.getPacket(); + this.key = CryptUtil.generateSharedKey(); + + GameProfile profile = event.getSession().getFlag(ProtocolConstants.PROFILE_KEY); + String serverHash = new BigInteger(CryptUtil.getServerIdHash(packet.getServerId(), packet.getPublicKey(), this.key)).toString(16); + try { + new AuthenticationService(this.clientToken).createMinecraftSessionService().joinServer(profile, this.accessToken, serverHash); + } catch(AuthenticationUnavailableException e) { + event.getSession().disconnect("Login failed: Authentication service unavailable."); + return; + } catch(InvalidCredentialsException e) { + event.getSession().disconnect("Login failed: Invalid login session."); + return; + } catch(AuthenticationException e) { + event.getSession().disconnect("Login failed: Authentication error: " + e.getMessage()); + return; + } + + event.getSession().send(new EncryptionResponsePacket(this.key, packet.getPublicKey(), packet.getVerifyToken())); + } else if(event.getPacket() instanceof LoginSuccessPacket) { + LoginSuccessPacket packet = event.getPacket(); + event.getSession().setFlag(ProtocolConstants.PROFILE_KEY, new GameProfile(packet.getPlayerId(), packet.getUsername())); + protocol.setMode(ProtocolMode.GAME, true, event.getSession()); + } else if(event.getPacket() instanceof LoginDisconnectPacket) { + LoginDisconnectPacket packet = event.getPacket(); + event.getSession().disconnect(packet.getReason().toString()); + } + } + + if(protocol.getMode() == ProtocolMode.STATUS) { + if(event.getPacket() instanceof StatusResponsePacket) { + ServerStatusInfo info = event.getPacket().getInfo(); + ServerInfoHandler handler = event.getSession().getFlag(ProtocolConstants.SERVER_INFO_HANDLER_KEY); + if(handler != null) { + handler.handle(info); + } + + event.getSession().send(new StatusPingPacket(System.nanoTime() / 1000000)); + } else if(event.getPacket() instanceof StatusPongPacket) { + long time = System.nanoTime() / 1000000 - event.getPacket().getPingTime(); + ServerPingTimeHandler handler = event.getSession().getFlag(ProtocolConstants.SERVER_PING_TIME_HANDLER_KEY); + if(handler != null) { + handler.handle(time); + } + + event.getSession().disconnect("Finished"); + } + } + + if(protocol.getMode() == ProtocolMode.GAME) { + if(event.getPacket() instanceof ServerKeepAlivePacket) { + event.getSession().send(new ClientKeepAlivePacket(event.getPacket().getPingId())); + } else if(event.getPacket() instanceof ServerDisconnectPacket) { + event.getSession().disconnect(event.getPacket().getReason().toString()); + } + } + } + + @Override + public void packetSent(PacketSentEvent event) { + MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol(); + if(protocol.getMode() == ProtocolMode.LOGIN && event.getPacket() instanceof EncryptionResponsePacket) { + protocol.enableEncryption(this.key); + } + } + + @Override + public void connected(ConnectedEvent event) { + MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol(); + if(protocol.getMode() == ProtocolMode.LOGIN) { + GameProfile profile = event.getSession().getFlag(ProtocolConstants.PROFILE_KEY); + protocol.setMode(ProtocolMode.HANDSHAKE, true, event.getSession()); + event.getSession().send(new HandshakePacket(ProtocolConstants.PROTOCOL_VERSION, event.getSession().getHost(), event.getSession().getPort(), 2)); + protocol.setMode(ProtocolMode.LOGIN, true, event.getSession()); + event.getSession().send(new LoginStartPacket(profile != null ? profile.getName() : "")); + } else if(protocol.getMode() == ProtocolMode.STATUS) { + protocol.setMode(ProtocolMode.HANDSHAKE, true, event.getSession()); + event.getSession().send(new HandshakePacket(ProtocolConstants.PROTOCOL_VERSION, event.getSession().getHost(), event.getSession().getPort(), 1)); + protocol.setMode(ProtocolMode.STATUS, true, event.getSession()); + event.getSession().send(new StatusQueryPacket()); + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/MinecraftProtocol.java b/src/main/java/ch/spacebase/mc/protocol/MinecraftProtocol.java new file mode 100644 index 00000000..447ec2e8 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/MinecraftProtocol.java @@ -0,0 +1,461 @@ +package ch.spacebase.mc.protocol; + +import java.security.GeneralSecurityException; +import java.security.Key; +import java.util.UUID; + +import ch.spacebase.mc.auth.AuthenticationService; +import ch.spacebase.mc.auth.GameProfile; +import ch.spacebase.mc.auth.UserAuthentication; +import ch.spacebase.mc.auth.exceptions.AuthenticationException; +import ch.spacebase.mc.protocol.packet.handshake.client.HandshakePacket; +import ch.spacebase.mc.protocol.packet.ingame.client.ClientChatPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.ClientKeepAlivePacket; +import ch.spacebase.mc.protocol.packet.ingame.client.ClientPluginMessagePacket; +import ch.spacebase.mc.protocol.packet.ingame.client.ClientRequestPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.ClientSettingsPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.ClientTabCompletePacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.ClientAnimationPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.ClientEntityActionPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.ClientEntityInteractPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.player.ClientChangeHeldItemPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.player.ClientPlayerAbilitiesPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.player.ClientPlayerDigPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.player.ClientPlayerMovementPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.player.ClientPlayerPlaceBlockPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.player.ClientPlayerPositionPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.player.ClientPlayerPositionRotationPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.player.ClientPlayerRotationPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.entity.player.ClientSteerVehiclePacket; +import ch.spacebase.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.window.ClientConfirmTransactionPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.window.ClientCreativeInventoryActionPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.window.ClientEnchantItemPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.window.ClientWindowActionPacket; +import ch.spacebase.mc.protocol.packet.ingame.client.world.ClientUpdateSignPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerChatPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerDisconnectPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerJoinGamePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerKeepAlivePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerPlayerListEntryPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerPluginMessagePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerRespawnPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerStatisticsPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerTabCompletePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerAnimationPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerCollectItemPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerDestroyEntitiesPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityAttachPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityEffectPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityEquipmentPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityMovementPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.ServerRemoveEffectPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.player.ServerChangeHeldItemPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.player.ServerPlayerUseBedPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.player.ServerSetExperiencePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.player.ServerUpdateHealthPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnGlobalEntityPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.scoreboard.ServerScoreboardObjectivePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.window.ServerCloseWindowPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.window.ServerConfirmTransactionPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.window.ServerWindowPropertyPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerBlockBreakAnimPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerBlockValuePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerExplosionPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerMapDataPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerMultiBlockChangePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerMultiChunkDataPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerOpenTileEntityEditorPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerPlayEffectPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerUpdateSignPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerSpawnParticlePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerSpawnPositionPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerUpdateTileEntityPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket; +import ch.spacebase.mc.protocol.packet.login.client.EncryptionResponsePacket; +import ch.spacebase.mc.protocol.packet.login.client.LoginStartPacket; +import ch.spacebase.mc.protocol.packet.login.server.EncryptionRequestPacket; +import ch.spacebase.mc.protocol.packet.login.server.LoginDisconnectPacket; +import ch.spacebase.mc.protocol.packet.login.server.LoginSuccessPacket; +import ch.spacebase.mc.protocol.packet.status.client.StatusPingPacket; +import ch.spacebase.mc.protocol.packet.status.client.StatusQueryPacket; +import ch.spacebase.mc.protocol.packet.status.server.StatusPongPacket; +import ch.spacebase.mc.protocol.packet.status.server.StatusResponsePacket; +import ch.spacebase.packetlib.Client; +import ch.spacebase.packetlib.Server; +import ch.spacebase.packetlib.Session; +import ch.spacebase.packetlib.crypt.AESEncryption; +import ch.spacebase.packetlib.crypt.PacketEncryption; +import ch.spacebase.packetlib.packet.PacketProtocol; + +public class MinecraftProtocol extends PacketProtocol { + + private ProtocolMode mode = ProtocolMode.HANDSHAKE; + private AESEncryption encrypt = null; + + private GameProfile profile = null; + private ClientListener clientListener = null; + + @SuppressWarnings("unused") + private MinecraftProtocol() { + } + + public MinecraftProtocol(ProtocolMode mode) { + if(mode != ProtocolMode.LOGIN && mode != ProtocolMode.STATUS) { + throw new IllegalArgumentException("Only login and status modes are permitted."); + } + + this.mode = mode; + if(mode == ProtocolMode.LOGIN) { + this.profile = new GameProfile("", "Player"); + } + + this.clientListener = new ClientListener("", UUID.randomUUID().toString()); + } + + public MinecraftProtocol(String username) { + this(ProtocolMode.LOGIN); + this.profile = new GameProfile("", username); + this.clientListener = new ClientListener("", UUID.randomUUID().toString()); + } + + public MinecraftProtocol(String username, String password) throws AuthenticationException { + this(ProtocolMode.LOGIN); + String clientToken = UUID.randomUUID().toString(); + UserAuthentication auth = new AuthenticationService(clientToken).createUserAuthentication(); + auth.setUsername(username); + auth.setPassword(password); + auth.logIn(); + this.profile = auth.getSelectedProfile(); + this.clientListener = new ClientListener(auth.getAccessToken(), clientToken); + } + + @Override + public PacketEncryption getEncryption() { + return this.encrypt; + } + + @Override + public void newClientSession(Client client, Session session) { + if(this.profile != null) { + session.setFlag(ProtocolConstants.PROFILE_KEY, this.profile); + } + + this.setMode(this.mode, true, session); + session.addListener(this.clientListener); + } + + @Override + public void newServerSession(Server server, Session session) { + this.setMode(ProtocolMode.HANDSHAKE, false, session); + session.addListener(new ServerListener()); + } + + protected void enableEncryption(Key key) { + try { + this.encrypt = new AESEncryption(key); + } catch(GeneralSecurityException e) { + System.err.println("Could not enable protocol encryption!"); + e.printStackTrace(); + } + } + + public ProtocolMode getMode() { + return this.mode; + } + + protected void setMode(ProtocolMode mode, boolean client, Session session) { + this.clearPackets(); + switch(mode) { + case HANDSHAKE: + if(client) { + this.initClientHandshake(session); + } else { + this.initServerHandshake(session); + } + + break; + case LOGIN: + if(client) { + this.initClientLogin(session); + } else { + this.initServerLogin(session); + } + + break; + case GAME: + if(client) { + this.initClientGame(session); + } else { + this.initServerGame(session); + } + + break; + case STATUS: + if(client) { + this.initClientStatus(session); + } else { + this.initServerStatus(session); + } + + break; + } + + this.mode = mode; + } + + private void initClientHandshake(Session session) { + this.registerOutgoing(0, HandshakePacket.class); + } + + private void initServerHandshake(Session session) { + this.registerIncoming(0, HandshakePacket.class); + } + + private void initClientLogin(Session session) { + this.registerIncoming(0, LoginDisconnectPacket.class); + this.registerIncoming(1, EncryptionRequestPacket.class); + this.registerIncoming(2, LoginSuccessPacket.class); + + this.registerOutgoing(0, LoginStartPacket.class); + this.registerOutgoing(1, EncryptionResponsePacket.class); + } + + private void initServerLogin(Session session) { + this.registerIncoming(0, LoginStartPacket.class); + this.registerIncoming(1, EncryptionResponsePacket.class); + + this.registerOutgoing(0, LoginDisconnectPacket.class); + this.registerOutgoing(1, EncryptionRequestPacket.class); + this.registerOutgoing(2, LoginSuccessPacket.class); + } + + private void initClientGame(Session session) { + this.registerIncoming(0, ServerKeepAlivePacket.class); + this.registerIncoming(1, ServerJoinGamePacket.class); + this.registerIncoming(2, ServerChatPacket.class); + this.registerIncoming(3, ServerUpdateTimePacket.class); + this.registerIncoming(4, ServerEntityEquipmentPacket.class); + this.registerIncoming(5, ServerSpawnPositionPacket.class); + this.registerIncoming(6, ServerUpdateHealthPacket.class); + this.registerIncoming(7, ServerRespawnPacket.class); + this.registerIncoming(8, ServerPlayerPositionRotationPacket.class); + this.registerIncoming(9, ServerChangeHeldItemPacket.class); + this.registerIncoming(10, ServerPlayerUseBedPacket.class); + this.registerIncoming(11, ServerAnimationPacket.class); + this.registerIncoming(12, ServerSpawnPlayerPacket.class); + this.registerIncoming(13, ServerCollectItemPacket.class); + this.registerIncoming(14, ServerSpawnObjectPacket.class); + this.registerIncoming(15, ServerSpawnMobPacket.class); + this.registerIncoming(16, ServerSpawnPaintingPacket.class); + this.registerIncoming(17, ServerSpawnExpOrbPacket.class); + this.registerIncoming(18, ServerEntityVelocityPacket.class); + this.registerIncoming(19, ServerDestroyEntitiesPacket.class); + this.registerIncoming(20, ServerEntityMovementPacket.class); + this.registerIncoming(21, ServerEntityPositionPacket.class); + this.registerIncoming(22, ServerEntityRotationPacket.class); + this.registerIncoming(23, ServerEntityPositionRotationPacket.class); + this.registerIncoming(24, ServerEntityTeleportPacket.class); + this.registerIncoming(25, ServerEntityHeadLookPacket.class); + this.registerIncoming(26, ServerEntityStatusPacket.class); + this.registerIncoming(27, ServerEntityAttachPacket.class); + this.registerIncoming(28, ServerEntityMetadataPacket.class); + this.registerIncoming(29, ServerEntityEffectPacket.class); + this.registerIncoming(30, ServerRemoveEffectPacket.class); + this.registerIncoming(31, ServerSetExperiencePacket.class); + this.registerIncoming(32, ServerEntityPropertiesPacket.class); + this.registerIncoming(33, ServerChunkDataPacket.class); + this.registerIncoming(34, ServerMultiBlockChangePacket.class); + this.registerIncoming(35, ServerBlockChangePacket.class); + this.registerIncoming(36, ServerBlockValuePacket.class); + this.registerIncoming(37, ServerBlockBreakAnimPacket.class); + this.registerIncoming(38, ServerMultiChunkDataPacket.class); + this.registerIncoming(39, ServerExplosionPacket.class); + this.registerIncoming(40, ServerPlayEffectPacket.class); + this.registerIncoming(41, ServerPlaySoundPacket.class); + this.registerIncoming(42, ServerSpawnParticlePacket.class); + this.registerIncoming(43, ServerNotifyClientPacket.class); + this.registerIncoming(44, ServerSpawnGlobalEntityPacket.class); + this.registerIncoming(45, ServerOpenWindowPacket.class); + this.registerIncoming(46, ServerCloseWindowPacket.class); + this.registerIncoming(47, ServerSetSlotPacket.class); + this.registerIncoming(48, ServerWindowItemsPacket.class); + this.registerIncoming(49, ServerWindowPropertyPacket.class); + this.registerIncoming(50, ServerConfirmTransactionPacket.class); + this.registerIncoming(51, ServerUpdateSignPacket.class); + this.registerIncoming(52, ServerMapDataPacket.class); + this.registerIncoming(53, ServerUpdateTileEntityPacket.class); + this.registerIncoming(54, ServerOpenTileEntityEditorPacket.class); + this.registerIncoming(55, ServerStatisticsPacket.class); + this.registerIncoming(56, ServerPlayerListEntryPacket.class); + this.registerIncoming(57, ServerPlayerAbilitiesPacket.class); + this.registerIncoming(58, ServerTabCompletePacket.class); + this.registerIncoming(59, ServerScoreboardObjectivePacket.class); + this.registerIncoming(60, ServerUpdateScorePacket.class); + this.registerIncoming(61, ServerDisplayScoreboardPacket.class); + this.registerIncoming(62, ServerTeamPacket.class); + this.registerIncoming(63, ServerPluginMessagePacket.class); + this.registerIncoming(64, ServerDisconnectPacket.class); + + this.registerOutgoing(0, ClientKeepAlivePacket.class); + this.registerOutgoing(1, ClientChatPacket.class); + this.registerOutgoing(2, ClientEntityInteractPacket.class); + this.registerOutgoing(3, ClientPlayerMovementPacket.class); + this.registerOutgoing(4, ClientPlayerPositionPacket.class); + this.registerOutgoing(5, ClientPlayerRotationPacket.class); + this.registerOutgoing(6, ClientPlayerPositionRotationPacket.class); + this.registerOutgoing(7, ClientPlayerDigPacket.class); + this.registerOutgoing(8, ClientPlayerPlaceBlockPacket.class); + this.registerOutgoing(9, ClientChangeHeldItemPacket.class); + this.registerOutgoing(10, ClientAnimationPacket.class); + this.registerOutgoing(11, ClientEntityActionPacket.class); + this.registerOutgoing(12, ClientSteerVehiclePacket.class); + this.registerOutgoing(13, ClientCloseWindowPacket.class); + this.registerOutgoing(14, ClientWindowActionPacket.class); + this.registerOutgoing(15, ClientConfirmTransactionPacket.class); + this.registerOutgoing(16, ClientCreativeInventoryActionPacket.class); + this.registerOutgoing(17, ClientEnchantItemPacket.class); + this.registerOutgoing(18, ClientUpdateSignPacket.class); + this.registerOutgoing(19, ClientPlayerAbilitiesPacket.class); + this.registerOutgoing(20, ClientTabCompletePacket.class); + this.registerOutgoing(21, ClientSettingsPacket.class); + this.registerOutgoing(22, ClientRequestPacket.class); + this.registerOutgoing(23, ClientPluginMessagePacket.class); + } + + private void initServerGame(Session session) { + this.registerIncoming(0, ClientKeepAlivePacket.class); + this.registerIncoming(1, ClientChatPacket.class); + this.registerIncoming(2, ClientEntityInteractPacket.class); + this.registerIncoming(3, ClientPlayerMovementPacket.class); + this.registerIncoming(4, ClientPlayerPositionPacket.class); + this.registerIncoming(5, ClientPlayerRotationPacket.class); + this.registerIncoming(6, ClientPlayerPositionRotationPacket.class); + this.registerIncoming(7, ClientPlayerDigPacket.class); + this.registerIncoming(8, ClientPlayerPlaceBlockPacket.class); + this.registerIncoming(9, ClientChangeHeldItemPacket.class); + this.registerIncoming(10, ClientAnimationPacket.class); + this.registerIncoming(11, ClientEntityActionPacket.class); + this.registerIncoming(12, ClientSteerVehiclePacket.class); + this.registerIncoming(13, ClientCloseWindowPacket.class); + this.registerIncoming(14, ClientWindowActionPacket.class); + this.registerIncoming(15, ClientConfirmTransactionPacket.class); + this.registerIncoming(16, ClientCreativeInventoryActionPacket.class); + this.registerIncoming(17, ClientEnchantItemPacket.class); + this.registerIncoming(18, ClientUpdateSignPacket.class); + this.registerIncoming(19, ClientPlayerAbilitiesPacket.class); + this.registerIncoming(20, ClientTabCompletePacket.class); + this.registerIncoming(21, ClientSettingsPacket.class); + this.registerIncoming(22, ClientRequestPacket.class); + this.registerIncoming(23, ClientPluginMessagePacket.class); + + this.registerOutgoing(0, ServerKeepAlivePacket.class); + this.registerOutgoing(1, ServerJoinGamePacket.class); + this.registerOutgoing(2, ServerChatPacket.class); + this.registerOutgoing(3, ServerUpdateTimePacket.class); + this.registerOutgoing(4, ServerEntityEquipmentPacket.class); + this.registerOutgoing(5, ServerSpawnPositionPacket.class); + this.registerOutgoing(6, ServerUpdateHealthPacket.class); + this.registerOutgoing(7, ServerRespawnPacket.class); + this.registerOutgoing(8, ServerPlayerPositionRotationPacket.class); + this.registerOutgoing(9, ServerChangeHeldItemPacket.class); + this.registerOutgoing(10, ServerPlayerUseBedPacket.class); + this.registerOutgoing(11, ServerAnimationPacket.class); + this.registerOutgoing(12, ServerSpawnPlayerPacket.class); + this.registerOutgoing(13, ServerCollectItemPacket.class); + this.registerOutgoing(14, ServerSpawnObjectPacket.class); + this.registerOutgoing(15, ServerSpawnMobPacket.class); + this.registerOutgoing(16, ServerSpawnPaintingPacket.class); + this.registerOutgoing(17, ServerSpawnExpOrbPacket.class); + this.registerOutgoing(18, ServerEntityVelocityPacket.class); + this.registerOutgoing(19, ServerDestroyEntitiesPacket.class); + this.registerOutgoing(20, ServerEntityMovementPacket.class); + this.registerOutgoing(21, ServerEntityPositionPacket.class); + this.registerOutgoing(22, ServerEntityRotationPacket.class); + this.registerOutgoing(23, ServerEntityPositionRotationPacket.class); + this.registerOutgoing(24, ServerEntityTeleportPacket.class); + this.registerOutgoing(25, ServerEntityHeadLookPacket.class); + this.registerOutgoing(26, ServerEntityStatusPacket.class); + this.registerOutgoing(27, ServerEntityAttachPacket.class); + this.registerOutgoing(28, ServerEntityMetadataPacket.class); + this.registerOutgoing(29, ServerEntityEffectPacket.class); + this.registerOutgoing(30, ServerRemoveEffectPacket.class); + this.registerOutgoing(31, ServerSetExperiencePacket.class); + this.registerOutgoing(32, ServerEntityPropertiesPacket.class); + this.registerOutgoing(33, ServerChunkDataPacket.class); + this.registerOutgoing(34, ServerMultiBlockChangePacket.class); + this.registerOutgoing(35, ServerBlockChangePacket.class); + this.registerOutgoing(36, ServerBlockValuePacket.class); + this.registerOutgoing(37, ServerBlockBreakAnimPacket.class); + this.registerOutgoing(38, ServerMultiChunkDataPacket.class); + this.registerOutgoing(39, ServerExplosionPacket.class); + this.registerOutgoing(40, ServerPlayEffectPacket.class); + this.registerOutgoing(41, ServerPlaySoundPacket.class); + this.registerOutgoing(42, ServerSpawnParticlePacket.class); + this.registerOutgoing(43, ServerNotifyClientPacket.class); + this.registerOutgoing(44, ServerSpawnGlobalEntityPacket.class); + this.registerOutgoing(45, ServerOpenWindowPacket.class); + this.registerOutgoing(46, ServerCloseWindowPacket.class); + this.registerOutgoing(47, ServerSetSlotPacket.class); + this.registerOutgoing(48, ServerWindowItemsPacket.class); + this.registerOutgoing(49, ServerWindowPropertyPacket.class); + this.registerOutgoing(50, ServerConfirmTransactionPacket.class); + this.registerOutgoing(51, ServerUpdateSignPacket.class); + this.registerOutgoing(52, ServerMapDataPacket.class); + this.registerOutgoing(53, ServerUpdateTileEntityPacket.class); + this.registerOutgoing(54, ServerOpenTileEntityEditorPacket.class); + this.registerOutgoing(55, ServerStatisticsPacket.class); + this.registerOutgoing(56, ServerPlayerListEntryPacket.class); + this.registerOutgoing(57, ServerPlayerAbilitiesPacket.class); + this.registerOutgoing(58, ServerTabCompletePacket.class); + this.registerOutgoing(59, ServerScoreboardObjectivePacket.class); + this.registerOutgoing(60, ServerUpdateScorePacket.class); + this.registerOutgoing(61, ServerDisplayScoreboardPacket.class); + this.registerOutgoing(62, ServerTeamPacket.class); + this.registerOutgoing(63, ServerPluginMessagePacket.class); + this.registerOutgoing(64, ServerDisconnectPacket.class); + } + + private void initClientStatus(Session session) { + this.registerIncoming(0, StatusResponsePacket.class); + this.registerIncoming(1, StatusPongPacket.class); + + this.registerOutgoing(0, StatusQueryPacket.class); + this.registerOutgoing(1, StatusPingPacket.class); + } + + private void initServerStatus(Session session) { + this.registerIncoming(0, StatusQueryPacket.class); + this.registerIncoming(1, StatusPingPacket.class); + + this.registerOutgoing(0, StatusResponsePacket.class); + this.registerOutgoing(1, StatusPongPacket.class); + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/ProtocolConstants.java b/src/main/java/ch/spacebase/mc/protocol/ProtocolConstants.java new file mode 100644 index 00000000..dd3db965 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/ProtocolConstants.java @@ -0,0 +1,22 @@ +package ch.spacebase.mc.protocol; + +public class ProtocolConstants { + + // General Constants + public static final String GAME_VERSION = "1.7.2"; + public static final int PROTOCOL_VERSION = 4; + + // General Key Constants + public static final String PROFILE_KEY = "profile"; + + // Client Key Constants + public static final String PING_KEY = "ping"; + public static final String SERVER_INFO_HANDLER_KEY = "server-info-handler"; + public static final String SERVER_PING_TIME_HANDLER_KEY = "server-ping-time-handler"; + + // Server Key Constants + public static final String VERIFY_USERS_KEY = "verify-users"; + public static final String SERVER_INFO_BUILDER_KEY = "info-builder"; + public static final String SERVER_LOGIN_HANDLER_KEY = "login-handler"; + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/ProtocolMode.java b/src/main/java/ch/spacebase/mc/protocol/ProtocolMode.java new file mode 100644 index 00000000..282c5647 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/ProtocolMode.java @@ -0,0 +1,8 @@ +package ch.spacebase.mc.protocol; + +public enum ProtocolMode { + HANDSHAKE, + LOGIN, + GAME, + STATUS; +} diff --git a/src/main/java/ch/spacebase/mc/protocol/ServerListener.java b/src/main/java/ch/spacebase/mc/protocol/ServerListener.java new file mode 100644 index 00000000..84141145 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/ServerListener.java @@ -0,0 +1,157 @@ +package ch.spacebase.mc.protocol; + +import java.math.BigInteger; +import java.security.KeyPair; +import java.security.PrivateKey; +import java.util.Arrays; +import java.util.Random; +import java.util.UUID; + +import javax.crypto.SecretKey; + +import ch.spacebase.mc.auth.AuthenticationService; +import ch.spacebase.mc.auth.GameProfile; +import ch.spacebase.mc.auth.SessionService; +import ch.spacebase.mc.auth.exceptions.AuthenticationUnavailableException; +import ch.spacebase.mc.protocol.data.status.ServerStatusInfo; +import ch.spacebase.mc.protocol.data.status.handler.ServerInfoBuilder; +import ch.spacebase.mc.protocol.packet.handshake.client.HandshakePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerDisconnectPacket; +import ch.spacebase.mc.protocol.packet.login.client.EncryptionResponsePacket; +import ch.spacebase.mc.protocol.packet.login.client.LoginStartPacket; +import ch.spacebase.mc.protocol.packet.login.server.EncryptionRequestPacket; +import ch.spacebase.mc.protocol.packet.login.server.LoginDisconnectPacket; +import ch.spacebase.mc.protocol.packet.login.server.LoginSuccessPacket; +import ch.spacebase.mc.protocol.packet.status.client.StatusPingPacket; +import ch.spacebase.mc.protocol.packet.status.client.StatusQueryPacket; +import ch.spacebase.mc.protocol.packet.status.server.StatusPongPacket; +import ch.spacebase.mc.protocol.packet.status.server.StatusResponsePacket; +import ch.spacebase.mc.util.CryptUtil; +import ch.spacebase.packetlib.Session; +import ch.spacebase.packetlib.event.session.DisconnectingEvent; +import ch.spacebase.packetlib.event.session.PacketReceivedEvent; +import ch.spacebase.packetlib.event.session.SessionAdapter; + +public class ServerListener extends SessionAdapter { + + private static KeyPair pair = CryptUtil.generateKeyPair(); + + private byte verifyToken[] = new byte[4]; + private String serverId = ""; + private String username = ""; + + public ServerListener() { + new Random().nextBytes(this.verifyToken); + } + + @Override + public void packetReceived(PacketReceivedEvent event) { + MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol(); + if(protocol.getMode() == ProtocolMode.HANDSHAKE) { + if(event.getPacket() instanceof HandshakePacket) { + HandshakePacket packet = event.getPacket(); + switch(packet.getIntent()) { + case 1: + protocol.setMode(ProtocolMode.STATUS, false, event.getSession()); + break; + case 2: + protocol.setMode(ProtocolMode.LOGIN, false, event.getSession()); + if(packet.getProtocolVersion() > ProtocolConstants.PROTOCOL_VERSION) { + event.getSession().disconnect("Outdated server! I'm still on " + ProtocolConstants.GAME_VERSION + "."); + } else if(packet.getProtocolVersion() < ProtocolConstants.PROTOCOL_VERSION) { + event.getSession().disconnect("Outdated client! Please use " + ProtocolConstants.GAME_VERSION + "."); + } + + break; + default: + throw new UnsupportedOperationException("Invalid client intent: " + packet.getIntent()); + } + } + } + + if(protocol.getMode() == ProtocolMode.LOGIN) { + if(event.getPacket() instanceof LoginStartPacket) { + this.username = event.getPacket().getUsername(); + boolean verify = event.getSession().getFlag(ProtocolConstants.VERIFY_USERS_KEY); + if(verify) { + event.getSession().send(new EncryptionRequestPacket(this.serverId, pair.getPublic(), this.verifyToken)); + } else { + event.getSession().send(new LoginSuccessPacket("", this.username)); + event.getSession().setFlag(ProtocolConstants.PROFILE_KEY, new GameProfile("", this.username)); + protocol.setMode(ProtocolMode.GAME, false, event.getSession()); + ServerLoginHandler handler = event.getSession().getFlag(ProtocolConstants.SERVER_LOGIN_HANDLER_KEY); + if(handler != null) { + handler.loggedIn(event.getSession()); + } + } + } else if(event.getPacket() instanceof EncryptionResponsePacket) { + EncryptionResponsePacket packet = event.getPacket(); + PrivateKey privateKey = pair.getPrivate(); + if(!Arrays.equals(this.verifyToken, packet.getVerifyToken(privateKey))) { + throw new IllegalStateException("Invalid nonce!"); + } else { + SecretKey key = packet.getSecretKey(privateKey); + protocol.enableEncryption(key); + new UserAuthThread(event.getSession(), key).start(); + } + } + } + + if(protocol.getMode() == ProtocolMode.STATUS) { + if(event.getPacket() instanceof StatusQueryPacket) { + ServerInfoBuilder builder = event.getSession().getFlag(ProtocolConstants.SERVER_INFO_BUILDER_KEY); + if(builder == null) { + event.getSession().disconnect("No server info builder set."); + } + + ServerStatusInfo info = builder.buildInfo(); + event.getSession().send(new StatusResponsePacket(info)); + } else if(event.getPacket() instanceof StatusPingPacket) { + event.getSession().send(new StatusPongPacket(event.getPacket().getPingTime())); + } + } + } + + @Override + public void disconnecting(DisconnectingEvent event) { + MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol(); + if(protocol.getMode() == ProtocolMode.LOGIN) { + event.getSession().send(new LoginDisconnectPacket(event.getReason())); + } else if(protocol.getMode() == ProtocolMode.GAME) { + event.getSession().send(new ServerDisconnectPacket(event.getReason())); + } + } + + private class UserAuthThread extends Thread { + private Session session; + private SecretKey key; + + public UserAuthThread(Session session, SecretKey key) { + this.key = key; + this.session = session; + } + + public void run() { + MinecraftProtocol protocol = (MinecraftProtocol) this.session.getPacketProtocol(); + try { + String serverHash = new BigInteger(CryptUtil.getServerIdHash(serverId, pair.getPublic(), this.key)).toString(16); + SessionService service = new AuthenticationService(UUID.randomUUID().toString()).createMinecraftSessionService(); + GameProfile profile = service.hasJoinedServer(new GameProfile(null, username), serverHash); + if(profile != null) { + this.session.send(new LoginSuccessPacket(profile.getId(), profile.getName())); + this.session.setFlag(ProtocolConstants.PROFILE_KEY, profile); + protocol.setMode(ProtocolMode.GAME, false, this.session); + ServerLoginHandler handler = this.session.getFlag(ProtocolConstants.SERVER_LOGIN_HANDLER_KEY); + if(handler != null) { + handler.loggedIn(this.session); + } + } else { + this.session.disconnect("Failed to verify username!"); + } + } catch(AuthenticationUnavailableException e) { + this.session.disconnect("Authentication servers are down. Please try again later, sorry!"); + } + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/ServerLoginHandler.java b/src/main/java/ch/spacebase/mc/protocol/ServerLoginHandler.java new file mode 100644 index 00000000..ce67ad5b --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/ServerLoginHandler.java @@ -0,0 +1,9 @@ +package ch.spacebase.mc.protocol; + +import ch.spacebase.packetlib.Session; + +public interface ServerLoginHandler { + + public void loggedIn(Session session); + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/game/Attribute.java b/src/main/java/ch/spacebase/mc/protocol/data/game/Attribute.java new file mode 100644 index 00000000..4a8d0cd4 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/game/Attribute.java @@ -0,0 +1,34 @@ +package ch.spacebase.mc.protocol.data.game; + +import java.util.ArrayList; +import java.util.List; + +public class Attribute { + + private String key; + private double value; + private List modifiers; + + public Attribute(String key, double value) { + this(key, value, new ArrayList()); + } + + public Attribute(String key, double value, List modifiers) { + this.key = key; + this.value = value; + this.modifiers = modifiers; + } + + public String getKey() { + return this.key; + } + + public double getValue() { + return this.value; + } + + public List getModifiers() { + return this.modifiers; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/game/AttributeModifier.java b/src/main/java/ch/spacebase/mc/protocol/data/game/AttributeModifier.java new file mode 100644 index 00000000..7d1cba82 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/game/AttributeModifier.java @@ -0,0 +1,50 @@ +package ch.spacebase.mc.protocol.data.game; + +import java.util.UUID; + +public class AttributeModifier { + + private UUID uuid; + private double amount; + private int operation; + + public AttributeModifier(UUID uuid, double amount, int operation) { + this.uuid = uuid; + this.amount = amount; + this.operation = operation; + } + + public UUID getUUID() { + return this.uuid; + } + + public double getAmount() { + return this.amount; + } + + public int getOperation() { + return this.operation; + } + + public static class Operations { + public static final int ADD = 0; + public static final int ADD_MULTIPLIED = 1; + public static final int MULTIPLY = 2; + } + + public static class UUIDs { + public static final UUID CREATURE_FLEE_SPEED_BONUS = UUID.fromString("E199AD21-BA8A-4C53-8D13-6182D5C69D3A"); + public static final UUID ENDERMAN_ATTACK_SPEED_BOOST = UUID.fromString("020E0DFB-87AE-4653-9556-831010E291A0"); + public static final UUID SPRINT_SPEED_BOOST = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D"); + public static final UUID PIGZOMBIE_ATTACK_SPEED_BOOST = UUID.fromString("49455A49-7EC5-45BA-B886-3B90B23A1718"); + public static final UUID WITCH_DRINKING_SPEED_PENALTY = UUID.fromString("5CD17E52-A79A-43D3-A529-90FDE04B181E"); + public static final UUID ZOMBIE_BABY_SPEED_BOOST = UUID.fromString("B9766B59-9566-4402-BC1F-2EE2A276D836"); + public static final UUID ITEM_MODIFIER = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"); + public static final UUID SPEED_POTION_MODIFIER = UUID.fromString("91AEAA56-376B-4498-935B-2F7F68070635"); + public static final UUID HEALTH_BOOST_POTION_MODIFIER = UUID.fromString("5D6F0BA2-1186-46AC-B896-C61C5CEE99CC"); + public static final UUID SLOW_POTION_MODIFIER = UUID.fromString("7107DE5E-7CE8-4030-940E-514C1F160890"); + public static final UUID STRENGTH_POTION_MODIFIER = UUID.fromString("648D7064-6A60-4F59-8ABE-C2C23A6DD7A9"); + public static final UUID WEAKNESS_POTION_MODIFIER = UUID.fromString("22653B89-116E-49DC-9B6B-9971489B5BE5"); + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/game/BlockChangeRecord.java b/src/main/java/ch/spacebase/mc/protocol/data/game/BlockChangeRecord.java new file mode 100644 index 00000000..1de16ff7 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/game/BlockChangeRecord.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.data.game; + +public class BlockChangeRecord { + + private int x; + private int y; + private int z; + private int id; + private int metadata; + + public BlockChangeRecord(int x, int y, int z, int id, int metadata) { + this.x = x; + this.y = y; + this.z = z; + this.id = id; + this.metadata = metadata; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public int getId() { + return this.id; + } + + public int getMetadata() { + return this.metadata; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/game/Chunk.java b/src/main/java/ch/spacebase/mc/protocol/data/game/Chunk.java new file mode 100644 index 00000000..4e3664d6 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/game/Chunk.java @@ -0,0 +1,66 @@ +package ch.spacebase.mc.protocol.data.game; + +public class Chunk { + + private int x; + private int z; + + private byte blocks[]; + private NibbleArray metadata; + private NibbleArray blocklight; + private NibbleArray skylight; + private NibbleArray extendedBlocks; + + public Chunk(int x, int z, byte blocks[], NibbleArray metadata, NibbleArray blocklight, NibbleArray skylight, NibbleArray extendedBlocks) { + this.x = x; + this.z = z; + this.blocks = blocks; + this.metadata = metadata; + this.blocklight = blocklight; + this.skylight = skylight; + this.extendedBlocks = extendedBlocks; + } + + public int getX() { + return this.x; + } + + public int getZ() { + return this.z; + } + + public byte[] getBlocks() { + return this.blocks; + } + + public NibbleArray getMetadata() { + return this.metadata; + } + + public NibbleArray getBlockLight() { + return this.blocklight; + } + + public NibbleArray getSkyLight() { + return this.skylight; + } + + public NibbleArray getExtendedBlocks() { + return this.extendedBlocks; + } + + public void deleteExtendedBlocks() { + this.extendedBlocks = null; + } + + public boolean isEmpty() { + for(byte block : this.blocks) { + if(block != 0) { + return false; + } + } + + return true; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/game/Coordinates.java b/src/main/java/ch/spacebase/mc/protocol/data/game/Coordinates.java new file mode 100644 index 00000000..0074382a --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/game/Coordinates.java @@ -0,0 +1,27 @@ +package ch.spacebase.mc.protocol.data.game; + +public class Coordinates { + + private int x; + private int y; + private int z; + + public Coordinates(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/game/DefaultAttribute.java b/src/main/java/ch/spacebase/mc/protocol/data/game/DefaultAttribute.java new file mode 100644 index 00000000..849ca372 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/game/DefaultAttribute.java @@ -0,0 +1,41 @@ +package ch.spacebase.mc.protocol.data.game; + +public class DefaultAttribute { + + public static final DefaultAttribute MAX_HEALTH = new DefaultAttribute("generic.maxHealth", 20, 0, Double.MAX_VALUE); + public static final DefaultAttribute FOLLOW_RANGE = new DefaultAttribute("generic.followRange", 32, 0, 2048); + public static final DefaultAttribute KNOCKBACK_RESISTANCE = new DefaultAttribute("generic.knockbackResistance", 0, 0, 1); + public static final DefaultAttribute MOVEMENT_SPEED = new DefaultAttribute("generic.movementSpeed", 0.699999988079071, 0, Double.MAX_VALUE); + public static final DefaultAttribute ATTACK_DAMAGE = new DefaultAttribute("generic.attackStrength", 2, 0, Double.MAX_VALUE); + public static final DefaultAttribute HORSE_JUMP_STRENGTH = new DefaultAttribute("generic.maxHealth", 0.7, 0, 2); + public static final DefaultAttribute ZOMBIE_SPAWN_REINFORCEMENTS_CHANCE = new DefaultAttribute("generic.maxHealth", 0, 0, 1); + + private String key; + private double def; + private double min; + private double max; + + private DefaultAttribute(String key, double def, double min, double max) { + this.key = key; + this.def = def; + this.min = min; + this.max = max; + } + + public String getKey() { + return this.key; + } + + public double getDefault() { + return this.def; + } + + public double getMin() { + return this.min; + } + + public double getMax() { + return this.max; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/game/EntityMetadata.java b/src/main/java/ch/spacebase/mc/protocol/data/game/EntityMetadata.java new file mode 100644 index 00000000..7883cc36 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/game/EntityMetadata.java @@ -0,0 +1,37 @@ +package ch.spacebase.mc.protocol.data.game; + +public class EntityMetadata { + + private int id; + private Type type; + private Object value; + + public EntityMetadata(int id, Type type, Object value) { + this.id = id; + this.type = type; + this.value = value; + } + + public int getId() { + return this.id; + } + + public Type getType() { + return this.type; + } + + public Object getValue() { + return this.value; + } + + public static enum Type { + BYTE, + SHORT, + INT, + FLOAT, + STRING, + ITEM, + COORDINATES; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/game/ItemStack.java b/src/main/java/ch/spacebase/mc/protocol/data/game/ItemStack.java new file mode 100644 index 00000000..f4c83c60 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/game/ItemStack.java @@ -0,0 +1,47 @@ +package ch.spacebase.mc.protocol.data.game; + +import ch.spacebase.opennbt.tag.CompoundTag; + +public class ItemStack { + + private int id; + private int amount; + private int data; + private CompoundTag nbt; + + public ItemStack(int id) { + this(id, 1); + } + + public ItemStack(int id, int amount) { + this(id, amount, 0); + } + + public ItemStack(int id, int amount, int data) { + this(id, amount, data, null); + } + + public ItemStack(int id, int amount, int data, CompoundTag nbt) { + this.id = id; + this.amount = amount; + this.data = data; + this.nbt = nbt; + } + + public int getId() { + return this.id; + } + + public int getAmount() { + return this.amount; + } + + public int getData() { + return this.data; + } + + public CompoundTag getNBT() { + return this.nbt; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/game/NibbleArray.java b/src/main/java/ch/spacebase/mc/protocol/data/game/NibbleArray.java new file mode 100644 index 00000000..3176a9c0 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/game/NibbleArray.java @@ -0,0 +1,49 @@ +package ch.spacebase.mc.protocol.data.game; + +public class NibbleArray { + + private byte[] data; + + public NibbleArray(int size) { + this.data = new byte[size >> 1]; + } + + public NibbleArray(byte[] array) { + this.data = array; + } + + public byte[] getData() { + return this.data; + } + + public int get(int x, int y, int z) { + int key = y << 8 | z << 4 | x; + int index = key >> 1; + int part = key & 1; + return part == 0 ? this.data[index] & 15 : this.data[index] >> 4 & 15; + } + + public void set(int x, int y, int z, int val) { + int key = y << 8 | z << 4 | x; + int index = key >> 1; + int part = key & 1; + if(part == 0) { + this.data[index] = (byte) (this.data[index] & 240 | val & 15); + } else { + this.data[index] = (byte) (this.data[index] & 15 | (val & 15) << 4); + } + } + + public void fill(int val) { + for(int index = 0; index < this.data.length << 1; index++) { + int ind = index >> 1; + int part = index & 1; + if(part == 0) { + this.data[ind] = (byte) (this.data[ind] & 240 | val & 15); + } else { + this.data[ind] = (byte) (this.data[ind] & 15 | (val & 15) << 4); + } + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/status/PlayerInfo.java b/src/main/java/ch/spacebase/mc/protocol/data/status/PlayerInfo.java new file mode 100644 index 00000000..3043dbfd --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/status/PlayerInfo.java @@ -0,0 +1,29 @@ +package ch.spacebase.mc.protocol.data.status; + +import ch.spacebase.mc.auth.GameProfile; + +public class PlayerInfo { + + private int max; + private int online; + private GameProfile players[]; + + public PlayerInfo(int max, int online, GameProfile players[]) { + this.max = max; + this.online = online; + this.players = players; + } + + public int getMaxPlayers() { + return this.max; + } + + public int getOnlinePlayers() { + return this.online; + } + + public GameProfile[] getPlayers() { + return this.players; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/status/ServerStatusInfo.java b/src/main/java/ch/spacebase/mc/protocol/data/status/ServerStatusInfo.java new file mode 100644 index 00000000..849467dd --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/status/ServerStatusInfo.java @@ -0,0 +1,37 @@ +package ch.spacebase.mc.protocol.data.status; + +import java.awt.image.BufferedImage; + +import ch.spacebase.mc.util.message.Message; + +public class ServerStatusInfo { + + private VersionInfo version; + private PlayerInfo players; + private Message description; + private BufferedImage icon; + + public ServerStatusInfo(VersionInfo version, PlayerInfo players, Message description, BufferedImage icon) { + this.version = version; + this.players = players; + this.description = description; + this.icon = icon; + } + + public VersionInfo getVersionInfo() { + return this.version; + } + + public PlayerInfo getPlayerInfo() { + return this.players; + } + + public Message getDescription() { + return this.description; + } + + public BufferedImage getIcon() { + return this.icon; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/status/VersionInfo.java b/src/main/java/ch/spacebase/mc/protocol/data/status/VersionInfo.java new file mode 100644 index 00000000..991afb99 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/status/VersionInfo.java @@ -0,0 +1,21 @@ +package ch.spacebase.mc.protocol.data.status; + +public class VersionInfo { + + private String name; + private int protocol; + + public VersionInfo(String name, int protocol) { + this.name = name; + this.protocol = protocol; + } + + public String getVersionName() { + return this.name; + } + + public int getProtocolVersion() { + return this.protocol; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/status/handler/ServerInfoBuilder.java b/src/main/java/ch/spacebase/mc/protocol/data/status/handler/ServerInfoBuilder.java new file mode 100644 index 00000000..49855b40 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/status/handler/ServerInfoBuilder.java @@ -0,0 +1,9 @@ +package ch.spacebase.mc.protocol.data.status.handler; + +import ch.spacebase.mc.protocol.data.status.ServerStatusInfo; + +public interface ServerInfoBuilder { + + public ServerStatusInfo buildInfo(); + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/status/handler/ServerInfoHandler.java b/src/main/java/ch/spacebase/mc/protocol/data/status/handler/ServerInfoHandler.java new file mode 100644 index 00000000..4705233f --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/status/handler/ServerInfoHandler.java @@ -0,0 +1,10 @@ +package ch.spacebase.mc.protocol.data.status.handler; + +import ch.spacebase.mc.protocol.data.status.ServerStatusInfo; + + +public interface ServerInfoHandler { + + public void handle(ServerStatusInfo info); + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/data/status/handler/ServerPingTimeHandler.java b/src/main/java/ch/spacebase/mc/protocol/data/status/handler/ServerPingTimeHandler.java new file mode 100644 index 00000000..19f5ae0b --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/data/status/handler/ServerPingTimeHandler.java @@ -0,0 +1,7 @@ +package ch.spacebase.mc.protocol.data.status.handler; + +public interface ServerPingTimeHandler { + + public void handle(long pingTime); + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/handshake/client/HandshakePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/handshake/client/HandshakePacket.java new file mode 100644 index 00000000..88056dc7 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/handshake/client/HandshakePacket.java @@ -0,0 +1,63 @@ +package ch.spacebase.mc.protocol.packet.handshake.client; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class HandshakePacket implements Packet { + + private int protocolVersion; + private String hostname; + private int port; + private int intent; + + public HandshakePacket() { + } + + public HandshakePacket(int protocolVersion, String hostname, int port, int nextState) { + this.protocolVersion = protocolVersion; + this.hostname = hostname; + this.port = port; + this.intent = nextState; + } + + public int getProtocolVersion() { + return this.protocolVersion; + } + + public String getHostName() { + return this.hostname; + } + + public int getPort() { + return this.port; + } + + public int getIntent() { + return this.intent; + } + + @Override + public void read(NetInput in) throws IOException { + this.protocolVersion = in.readVarInt(); + this.hostname = in.readString(); + this.port = in.readUnsignedShort(); + this.intent = in.readVarInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeVarInt(this.protocolVersion); + out.writeString(this.hostname); + out.writeShort(this.port); + out.writeVarInt(this.intent); + } + + @Override + public boolean isPriority() { + return true; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientChatPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientChatPacket.java new file mode 100644 index 00000000..384092d2 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientChatPacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.ingame.client; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientChatPacket implements Packet { + + private String message; + + public ClientChatPacket() { + } + + public ClientChatPacket(String message) { + this.message = message; + } + + public String getMessage() { + return this.message; + } + + @Override + public void read(NetInput in) throws IOException { + this.message = in.readString(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.message); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientKeepAlivePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientKeepAlivePacket.java new file mode 100644 index 00000000..4d3330ec --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientKeepAlivePacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.ingame.client; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientKeepAlivePacket implements Packet { + + private int id; + + public ClientKeepAlivePacket() { + } + + public ClientKeepAlivePacket(int id) { + this.id = id; + } + + public int getPingId() { + return this.id; + } + + @Override + public void read(NetInput in) throws IOException { + this.id = in.readInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.id); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientPluginMessagePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientPluginMessagePacket.java new file mode 100644 index 00000000..0abc9cc5 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientPluginMessagePacket.java @@ -0,0 +1,48 @@ +package ch.spacebase.mc.protocol.packet.ingame.client; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientPluginMessagePacket implements Packet { + + private String channel; + private byte data[]; + + public ClientPluginMessagePacket() { + } + + public ClientPluginMessagePacket(String channel, byte data[]) { + this.channel = channel; + this.data = data; + } + + public String getChannel() { + return this.channel; + } + + public byte[] getData() { + return this.data; + } + + @Override + public void read(NetInput in) throws IOException { + this.channel = in.readString(); + this.data = in.readBytes(in.readShort()); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.channel); + out.writeShort(this.data.length); + out.writeBytes(this.data); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientRequestPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientRequestPacket.java new file mode 100644 index 00000000..d34978a2 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientRequestPacket.java @@ -0,0 +1,45 @@ +package ch.spacebase.mc.protocol.packet.ingame.client; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientRequestPacket implements Packet { + + private Request request; + + public ClientRequestPacket() { + } + + public ClientRequestPacket(Request request) { + this.request = request; + } + + public Request getRequest() { + return this.request; + } + + @Override + public void read(NetInput in) throws IOException { + this.request = Request.values()[in.readByte()]; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.request.ordinal()); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Request { + RESPAWN, + STATS, + OPEN_INVENTORY_ACHIEVEMENT; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientSettingsPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientSettingsPacket.java new file mode 100644 index 00000000..822c783e --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientSettingsPacket.java @@ -0,0 +1,92 @@ +package ch.spacebase.mc.protocol.packet.ingame.client; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientSettingsPacket implements Packet { + + private String locale; + private int renderDistance; + private ChatVisibility chatVisibility; + private boolean chatColors; + private Difficulty difficulty; + private boolean capes; + + public ClientSettingsPacket() { + } + + public ClientSettingsPacket(String locale, int renderDistance, ChatVisibility chatVisibility, boolean chatColors, Difficulty difficulty, boolean capes) { + this.locale = locale; + this.renderDistance = renderDistance; + this.chatVisibility = chatVisibility; + this.chatColors = chatColors; + this.difficulty = difficulty; + this.capes = capes; + } + + public String getLocale() { + return this.locale; + } + + public int getRenderDistance() { + return this.renderDistance; + } + + public ChatVisibility getChatVisibility() { + return this.chatVisibility; + } + + public boolean getUseChatColors() { + return this.chatColors; + } + + public Difficulty getDifficulty() { + return this.difficulty; + } + + public boolean getShowCapes() { + return this.capes; + } + + @Override + public void read(NetInput in) throws IOException { + this.locale = in.readString(); + this.renderDistance = in.readByte(); + this.chatVisibility = ChatVisibility.values()[in.readByte()]; + this.chatColors = in.readBoolean(); + this.difficulty = Difficulty.values()[in.readByte()]; + this.capes = in.readBoolean(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.locale); + out.writeByte(this.renderDistance); + out.writeByte(this.chatVisibility.ordinal()); + out.writeBoolean(this.chatColors); + out.writeByte(this.difficulty.ordinal()); + out.writeBoolean(this.capes); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum ChatVisibility { + FULL, + SYSTEM, + HIDDEN; + } + + public static enum Difficulty { + PEACEFUL, + EASY, + NORMAL, + HARD; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientTabCompletePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientTabCompletePacket.java new file mode 100644 index 00000000..aed89f5d --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/ClientTabCompletePacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.ingame.client; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientTabCompletePacket implements Packet { + + private String text; + + public ClientTabCompletePacket() { + } + + public ClientTabCompletePacket(String text) { + this.text = text; + } + + public String getText() { + return this.text; + } + + @Override + public void read(NetInput in) throws IOException { + this.text = in.readString(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.text); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/ClientAnimationPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/ClientAnimationPacket.java new file mode 100644 index 00000000..93af183f --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/ClientAnimationPacket.java @@ -0,0 +1,51 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientAnimationPacket implements Packet { + + private int entityId; + private Animation animation; + + public ClientAnimationPacket() { + } + + public ClientAnimationPacket(int entityId, Animation animation) { + this.entityId = entityId; + this.animation = animation; + } + + public int getEntityId() { + return this.entityId; + } + + public Animation getAnimation() { + return this.animation; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.animation = Animation.values()[in.readByte()]; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeByte(this.animation.ordinal()); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Animation { + SWING_ARM; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/ClientEntityActionPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/ClientEntityActionPacket.java new file mode 100644 index 00000000..13cf3504 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/ClientEntityActionPacket.java @@ -0,0 +1,67 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientEntityActionPacket implements Packet { + + private int entityId; + private Action action; + private int jumpBoost; + + public ClientEntityActionPacket() { + } + + public ClientEntityActionPacket(int entityId, Action action) { + this(entityId, action, 0); + } + + public ClientEntityActionPacket(int entityId, Action action, int jumpBoost) { + this.entityId = entityId; + this.action = action; + this.jumpBoost = jumpBoost; + } + + public int getEntityId() { + return this.entityId; + } + + public Action getAction() { + return this.action; + } + + public int getJumpBoost() { + return this.jumpBoost; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.action = Action.values()[in.readByte()]; + this.jumpBoost = in.readInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeByte(this.action.ordinal()); + out.writeInt(this.jumpBoost); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Action { + CROUCH, + UNCROUCH, + LEAVE_BED, + START_SPRINTING, + STOP_SPRINTING; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/ClientEntityInteractPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/ClientEntityInteractPacket.java new file mode 100644 index 00000000..3a05a6c6 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/ClientEntityInteractPacket.java @@ -0,0 +1,52 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientEntityInteractPacket implements Packet { + + private int entityId; + private Action action; + + public ClientEntityInteractPacket() { + } + + public ClientEntityInteractPacket(int entityId, Action action) { + this.entityId = entityId; + this.action = action; + } + + public int getEntityId() { + return this.entityId; + } + + public Action getAction() { + return this.action; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.action = Action.values()[in.readByte()]; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeByte(this.action.ordinal()); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Action { + INTERACT, + ATTACK; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientChangeHeldItemPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientChangeHeldItemPacket.java new file mode 100644 index 00000000..9fa3d69e --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientChangeHeldItemPacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity.player; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientChangeHeldItemPacket implements Packet { + + private int slot; + + public ClientChangeHeldItemPacket() { + } + + public ClientChangeHeldItemPacket(int slot) { + this.slot = slot; + } + + public int getSlot() { + return this.slot; + } + + @Override + public void read(NetInput in) throws IOException { + this.slot = in.readShort(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeShort(this.slot); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerAbilitiesPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerAbilitiesPacket.java new file mode 100644 index 00000000..7b3af585 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerAbilitiesPacket.java @@ -0,0 +1,94 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity.player; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientPlayerAbilitiesPacket implements Packet { + + private boolean invincible; + private boolean canFly; + private boolean flying; + private boolean creative; + private float flySpeed; + private float walkSpeed; + + public ClientPlayerAbilitiesPacket() { + } + + public ClientPlayerAbilitiesPacket(boolean invincible, boolean canFly, boolean flying, boolean creative, float flySpeed, float walkSpeed) { + this.invincible = invincible; + this.canFly = canFly; + this.flying = flying; + this.creative = creative; + this.flySpeed = flySpeed; + this.walkSpeed = walkSpeed; + } + + public boolean getInvincible() { + return this.invincible; + } + + public boolean getCanFly() { + return this.canFly; + } + + public boolean getFlying() { + return this.flying; + } + + public boolean getCreative() { + return this.creative; + } + + public float getFlySpeed() { + return this.flySpeed; + } + + public float getWalkSpeed() { + return this.walkSpeed; + } + + @Override + public void read(NetInput in) throws IOException { + byte flags = in.readByte(); + this.invincible = (flags & 1) > 0; + this.canFly = (flags & 2) > 0; + this.flying = (flags & 4) > 0; + this.creative = (flags & 8) > 0; + this.flySpeed = in.readFloat(); + this.walkSpeed = in.readFloat(); + } + + @Override + public void write(NetOutput out) throws IOException { + byte flags = 0; + if(this.invincible) { + flags = (byte) (flags | 1); + } + + if(this.canFly) { + flags = (byte) (flags | 2); + } + + if(this.flying) { + flags = (byte) (flags | 4); + } + + if(this.creative) { + flags = (byte) (flags | 8); + } + + out.writeByte(flags); + out.writeFloat(this.flySpeed); + out.writeFloat(this.walkSpeed); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerDigPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerDigPacket.java new file mode 100644 index 00000000..945a01ae --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerDigPacket.java @@ -0,0 +1,89 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity.player; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientPlayerDigPacket implements Packet { + + private Status status; + private int x; + private int y; + private int z; + private Face face; + + public ClientPlayerDigPacket() { + } + + public ClientPlayerDigPacket(Status status, int x, int y, int z, Face face) { + this.status = status; + this.x = x; + this.y = y; + this.z = z; + this.face = face; + } + + public Status getStatus() { + return this.status; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public Face getFace() { + return this.face; + } + + @Override + public void read(NetInput in) throws IOException { + this.status = Status.values()[in.readUnsignedByte()]; + this.x = in.readInt(); + this.y = in.readUnsignedByte(); + this.z = in.readInt(); + this.face = Face.values()[in.readUnsignedByte()]; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.status.ordinal()); + out.writeInt(this.x); + out.writeByte(this.y); + out.writeInt(this.z); + out.writeByte(this.face.ordinal()); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Status { + START_DIGGING, + CANCEL_DIGGING, + FINISH_DIGGING, + DROP_ITEM_STACK, + DROP_ITEM, + SHOOT_ARROW_OR_FINISH_EATING; + } + + public static enum Face { + BOTTOM, + TOP, + EAST, + WEST, + NORTH, + SOUTH; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerMovementPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerMovementPacket.java new file mode 100644 index 00000000..563d970c --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerMovementPacket.java @@ -0,0 +1,96 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity.player; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientPlayerMovementPacket implements Packet { + + protected double x; + protected double stance; + protected double y; + protected double z; + protected double yaw; + protected double pitch; + protected boolean onGround; + + protected boolean pos = false; + protected boolean rot = false; + + public ClientPlayerMovementPacket() { + } + + public ClientPlayerMovementPacket(boolean onGround) { + this.onGround = onGround; + } + + public double getX() { + return this.x; + } + + public double getStance() { + return this.stance; + } + + public double getY() { + return this.y; + } + + public double getZ() { + return this.z; + } + + public double getYaw() { + return this.yaw; + } + + public double getPitch() { + return this.pitch; + } + + public boolean isOnGround() { + return this.onGround; + } + + @Override + public void read(NetInput in) throws IOException { + if(this.pos) { + this.x = in.readDouble(); + this.stance = in.readDouble(); + this.y = in.readDouble(); + this.z = in.readDouble(); + } + + if(this.rot) { + this.yaw = in.readDouble(); + this.pitch = in.readDouble(); + } + + this.onGround = in.readBoolean(); + } + + @Override + public void write(NetOutput out) throws IOException { + if(this.pos) { + out.writeDouble(this.x); + out.writeDouble(this.stance); + out.writeDouble(this.y); + out.writeDouble(this.z); + } + + if(this.rot) { + out.writeDouble(this.yaw); + out.writeDouble(this.pitch); + } + + out.writeBoolean(this.onGround); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerPlaceBlockPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerPlaceBlockPacket.java new file mode 100644 index 00000000..a5fe6a33 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerPlaceBlockPacket.java @@ -0,0 +1,106 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity.player; + +import java.io.IOException; + +import ch.spacebase.mc.protocol.data.game.ItemStack; +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientPlayerPlaceBlockPacket implements Packet { + + private int x; + private int y; + private int z; + private Face face; + private ItemStack held; + private float cursorX; + private float cursorY; + private float cursorZ; + + public ClientPlayerPlaceBlockPacket() { + } + + public ClientPlayerPlaceBlockPacket(int x, int y, int z, Face face, ItemStack held, float cursorX, float cursorY, float cursorZ) { + this.x = x; + this.y = y; + this.z = z; + this.face = face; + this.held = held; + this.cursorX = cursorX; + this.cursorY = cursorY; + this.cursorZ = cursorZ; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public Face getFace() { + return this.face; + } + + public ItemStack getHeldItem() { + return this.held; + } + + public float getCursorX() { + return this.cursorX; + } + + public float getCursorY() { + return this.cursorY; + } + + public float getCursorZ() { + return this.cursorZ; + } + + @Override + public void read(NetInput in) throws IOException { + this.x = in.readInt(); + this.y = in.readUnsignedByte(); + this.z = in.readInt(); + this.face = Face.values()[in.readUnsignedByte()]; + this.held = NetUtil.readItem(in); + this.cursorX = in.readByte() / 16f; + this.cursorY = in.readByte() / 16f; + this.cursorZ = in.readByte() / 16f; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.x); + out.writeByte(this.y); + out.writeInt(this.z); + out.writeByte(this.face.ordinal()); + NetUtil.writeItem(out, this.held); + out.writeByte((int) (this.cursorX * 16)); + out.writeByte((int) (this.cursorY * 16)); + out.writeByte((int) (this.cursorZ * 16)); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Face { + BOTTOM, + TOP, + EAST, + WEST, + NORTH, + SOUTH; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerPositionPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerPositionPacket.java new file mode 100644 index 00000000..58aeba76 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerPositionPacket.java @@ -0,0 +1,18 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity.player; + +public class ClientPlayerPositionPacket extends ClientPlayerMovementPacket { + + public ClientPlayerPositionPacket() { + this.pos = true; + } + + public ClientPlayerPositionPacket(boolean onGround, double x, double stance, double y, double z) { + super(onGround); + this.pos = true; + this.x = x; + this.stance = stance; + this.y = y; + this.z = z; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerPositionRotationPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerPositionRotationPacket.java new file mode 100644 index 00000000..27746b83 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerPositionRotationPacket.java @@ -0,0 +1,22 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity.player; + +public class ClientPlayerPositionRotationPacket extends ClientPlayerMovementPacket { + + public ClientPlayerPositionRotationPacket() { + this.pos = true; + this.rot = true; + } + + public ClientPlayerPositionRotationPacket(boolean onGround, double x, double stance, double y, double z, double yaw, double pitch) { + super(onGround); + this.pos = true; + this.rot = true; + this.x = x; + this.stance = stance; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerRotationPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerRotationPacket.java new file mode 100644 index 00000000..79a71e91 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientPlayerRotationPacket.java @@ -0,0 +1,16 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity.player; + +public class ClientPlayerRotationPacket extends ClientPlayerMovementPacket { + + public ClientPlayerRotationPacket() { + this.rot = true; + } + + public ClientPlayerRotationPacket(boolean onGround, double yaw, double pitch) { + super(onGround); + this.rot = true; + this.yaw = yaw; + this.pitch = pitch; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientSteerVehiclePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientSteerVehiclePacket.java new file mode 100644 index 00000000..45812828 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/entity/player/ClientSteerVehiclePacket.java @@ -0,0 +1,63 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.entity.player; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientSteerVehiclePacket implements Packet { + + private float sideways; + private float forward; + private boolean jump; + private boolean dismount; + + public ClientSteerVehiclePacket() { + } + + public ClientSteerVehiclePacket(float sideways, float forward, boolean jump, boolean dismount) { + this.sideways = sideways; + this.forward = forward; + this.jump = jump; + this.dismount = dismount; + } + + public float getSideways() { + return this.sideways; + } + + public float getForward() { + return this.forward; + } + + public boolean getJumping() { + return this.jump; + } + + public boolean getDismounting() { + return this.dismount; + } + + @Override + public void read(NetInput in) throws IOException { + this.sideways = in.readFloat(); + this.forward = in.readFloat(); + this.jump = in.readBoolean(); + this.dismount = in.readBoolean(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeFloat(this.sideways); + out.writeFloat(this.forward); + out.writeBoolean(this.jump); + out.writeBoolean(this.dismount); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientCloseWindowPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientCloseWindowPacket.java new file mode 100644 index 00000000..c7d1290e --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientCloseWindowPacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.window; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientCloseWindowPacket implements Packet { + + private int windowId; + + public ClientCloseWindowPacket() { + } + + public ClientCloseWindowPacket(int windowId) { + this.windowId = windowId; + } + + public int getWindowId() { + return this.windowId; + } + + @Override + public void read(NetInput in) throws IOException { + this.windowId = in.readByte(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.windowId); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientConfirmTransactionPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientConfirmTransactionPacket.java new file mode 100644 index 00000000..5421df62 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientConfirmTransactionPacket.java @@ -0,0 +1,55 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.window; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientConfirmTransactionPacket implements Packet { + + private int windowId; + private int actionId; + private boolean accepted; + + public ClientConfirmTransactionPacket() { + } + + public ClientConfirmTransactionPacket(int windowId, int actionId, boolean accepted) { + this.windowId = windowId; + this.actionId = actionId; + this.accepted = accepted; + } + + public int getWindowId() { + return this.windowId; + } + + public int getActionId() { + return this.actionId; + } + + public boolean getAccepted() { + return this.accepted; + } + + @Override + public void read(NetInput in) throws IOException { + this.windowId = in.readByte(); + this.actionId = in.readShort(); + this.accepted = in.readBoolean(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.windowId); + out.writeShort(this.actionId); + out.writeBoolean(this.accepted); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientCreativeInventoryActionPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientCreativeInventoryActionPacket.java new file mode 100644 index 00000000..dbb9891d --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientCreativeInventoryActionPacket.java @@ -0,0 +1,49 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.window; + +import java.io.IOException; + +import ch.spacebase.mc.protocol.data.game.ItemStack; +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientCreativeInventoryActionPacket implements Packet { + + private int slot; + private ItemStack clicked; + + public ClientCreativeInventoryActionPacket() { + } + + public ClientCreativeInventoryActionPacket(int slot, ItemStack clicked) { + this.slot = slot; + this.clicked = clicked; + } + + public int getSlot() { + return this.slot; + } + + public ItemStack getClickedItem() { + return this.clicked; + } + + @Override + public void read(NetInput in) throws IOException { + this.slot = in.readShort(); + this.clicked = NetUtil.readItem(in); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeShort(this.slot); + NetUtil.writeItem(out, this.clicked); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientEnchantItemPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientEnchantItemPacket.java new file mode 100644 index 00000000..b6628cc0 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientEnchantItemPacket.java @@ -0,0 +1,47 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.window; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientEnchantItemPacket implements Packet { + + private int windowId; + private int enchantment; + + public ClientEnchantItemPacket() { + } + + public ClientEnchantItemPacket(int windowId, int enchantment) { + this.windowId = windowId; + this.enchantment = enchantment; + } + + public int getWindowId() { + return this.windowId; + } + + public int getEnchantment() { + return this.enchantment; + } + + @Override + public void read(NetInput in) throws IOException { + this.windowId = in.readByte(); + this.enchantment = in.readByte(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.windowId); + out.writeByte(this.enchantment); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientWindowActionPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientWindowActionPacket.java new file mode 100644 index 00000000..1060570a --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/window/ClientWindowActionPacket.java @@ -0,0 +1,296 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.window; + +import java.io.IOException; + +import ch.spacebase.mc.protocol.data.game.ItemStack; +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientWindowActionPacket implements Packet { + + private int windowId; + private int slot; + private ActionParam param; + private int actionId; + private Action action; + private ItemStack clicked; + + public ClientWindowActionPacket() { + } + + public ClientWindowActionPacket(int windowId, int actionId, int slot, ItemStack clicked, Action action, ActionParam param) { + this.windowId = windowId; + this.actionId = actionId; + this.slot = slot; + this.clicked = clicked; + this.action = action; + this.param = param; + } + + public int getWindowId() { + return this.windowId; + } + + public int getActionId() { + return this.actionId; + } + + public int getSlot() { + return this.slot; + } + + public ItemStack getClickedItem() { + return this.clicked; + } + + public Action getAction() { + return this.action; + } + + public ActionParam getParam() { + return this.param; + } + + @Override + public void read(NetInput in) throws IOException { + this.windowId = in.readByte(); + this.slot = in.readShort(); + byte param = in.readByte(); + this.actionId = in.readShort(); + byte id = in.readByte(); + this.action = Action.values()[id]; + this.clicked = NetUtil.readItem(in); + this.param = this.valueToParam(param); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.windowId); + out.writeShort(this.slot); + out.writeByte(this.paramToValue(this.param)); + out.writeShort(this.actionId); + out.writeByte(this.action.ordinal()); + NetUtil.writeItem(out, this.clicked); + } + + @Override + public boolean isPriority() { + return false; + } + + private byte paramToValue(ActionParam param) throws IOException { + if(param == ClickItemParam.LEFT_CLICK) { + return 0; + } else if(param == ClickItemParam.RIGHT_CLICK) { + return 1; + } + + if(param == ShiftClickItemParam.LEFT_CLICK) { + return 0; + } else if(param == ShiftClickItemParam.RIGHT_CLICK) { + return 1; + } + + if(param == MoveToHotbarParam.SLOT_1) { + return 0; + } else if(param == MoveToHotbarParam.SLOT_2) { + return 1; + } else if(param == MoveToHotbarParam.SLOT_3) { + return 2; + } else if(param == MoveToHotbarParam.SLOT_4) { + return 3; + } else if(param == MoveToHotbarParam.SLOT_5) { + return 4; + } else if(param == MoveToHotbarParam.SLOT_6) { + return 5; + } else if(param == MoveToHotbarParam.SLOT_7) { + return 6; + } else if(param == MoveToHotbarParam.SLOT_8) { + return 7; + } else if(param == MoveToHotbarParam.SLOT_9) { + return 8; + } + + if(param == CreativeGrabParam.GRAB) { + return 2; + } + + if(param == DropItemParam.DROP_FROM_SELECTED) { + return 0; + } else if(param == DropItemParam.DROP_SELECTED_STACK) { + return 1; + } else if(param == DropItemParam.LEFT_CLICK_OUTSIDE_NOT_HOLDING) { + return 0; + } else if(param == DropItemParam.RIGHT_CLICK_OUTSIDE_NOT_HOLDING) { + return 1; + } + + if(param == SpreadItemParam.LEFT_MOUSE_BEGIN_DRAG) { + return 0; + } else if(param == SpreadItemParam.LEFT_MOUSE_ADD_SLOT) { + return 1; + } else if(param == SpreadItemParam.LEFT_MOUSE_END_DRAG) { + return 2; + } else if(param == SpreadItemParam.RIGHT_MOUSE_BEGIN_DRAG) { + return 4; + } else if(param == SpreadItemParam.RIGHT_MOUSE_ADD_SLOT) { + return 5; + } else if(param == SpreadItemParam.RIGHT_MOUSE_END_DRAG) { + return 6; + } + + if(param == FillStackParam.FILL) { + return 0; + } + + throw new IOException("Unmapped action param: " + param); + } + + private ActionParam valueToParam(byte value) throws IOException { + if(this.action == Action.CLICK_ITEM) { + if(value == 0) { + return ClickItemParam.LEFT_CLICK; + } else if(value == 1) { + return ClickItemParam.RIGHT_CLICK; + } + } + + if(this.action == Action.SHIFT_CLICK_ITEM) { + if(value == 0) { + return ShiftClickItemParam.LEFT_CLICK; + } else if(value == 1) { + return ShiftClickItemParam.RIGHT_CLICK; + } + } + + if(this.action == Action.MOVE_TO_HOTBAR_SLOT) { + if(value == 0) { + return MoveToHotbarParam.SLOT_1; + } else if(value == 1) { + return MoveToHotbarParam.SLOT_2; + } else if(value == 2) { + return MoveToHotbarParam.SLOT_3; + } else if(value == 3) { + return MoveToHotbarParam.SLOT_4; + } else if(value == 4) { + return MoveToHotbarParam.SLOT_5; + } else if(value == 5) { + return MoveToHotbarParam.SLOT_6; + } else if(value == 6) { + return MoveToHotbarParam.SLOT_7; + } else if(value == 7) { + return MoveToHotbarParam.SLOT_8; + } else if(value == 8) { + return MoveToHotbarParam.SLOT_9; + } + } + + if(this.action == Action.CREATIVE_GRAB_MAX_STACK) { + if(value == 2) { + return CreativeGrabParam.GRAB; + } + } + + if(this.action == Action.DROP_ITEM) { + if(this.slot == -999) { + if(value == 0) { + return DropItemParam.LEFT_CLICK_OUTSIDE_NOT_HOLDING; + } else if(value == 1) { + return DropItemParam.RIGHT_CLICK_OUTSIDE_NOT_HOLDING; + } + } else { + if(value == 0) { + return DropItemParam.DROP_FROM_SELECTED; + } else if(value == 1) { + return DropItemParam.DROP_SELECTED_STACK; + } + } + } + + if(this.action == Action.SPREAD_ITEM) { + if(value == 0) { + return SpreadItemParam.LEFT_MOUSE_BEGIN_DRAG; + } else if(value == 1) { + return SpreadItemParam.LEFT_MOUSE_ADD_SLOT; + } else if(value == 2) { + return SpreadItemParam.LEFT_MOUSE_END_DRAG; + } else if(value == 4) { + return SpreadItemParam.RIGHT_MOUSE_BEGIN_DRAG; + } else if(value == 5) { + return SpreadItemParam.RIGHT_MOUSE_ADD_SLOT; + } else if(value == 6) { + return SpreadItemParam.RIGHT_MOUSE_END_DRAG; + } + } + + if(this.action == Action.FILL_STACK) { + if(value == 0) { + return FillStackParam.FILL; + } + } + + throw new IOException("Unknown action param value: " + value); + } + + public static enum Action { + CLICK_ITEM, + SHIFT_CLICK_ITEM, + MOVE_TO_HOTBAR_SLOT, + CREATIVE_GRAB_MAX_STACK, + DROP_ITEM, + SPREAD_ITEM, + FILL_STACK; + } + + public static interface ActionParam { + } + + public static enum ClickItemParam implements ActionParam { + LEFT_CLICK, + RIGHT_CLICK; + } + + public static enum ShiftClickItemParam implements ActionParam { + LEFT_CLICK, + RIGHT_CLICK; + } + + public static enum MoveToHotbarParam implements ActionParam { + SLOT_1, + SLOT_2, + SLOT_3, + SLOT_4, + SLOT_5, + SLOT_6, + SLOT_7, + SLOT_8, + SLOT_9; + } + + public static enum CreativeGrabParam implements ActionParam { + GRAB; + } + + public static enum DropItemParam implements ActionParam { + DROP_FROM_SELECTED, + DROP_SELECTED_STACK, + LEFT_CLICK_OUTSIDE_NOT_HOLDING, + RIGHT_CLICK_OUTSIDE_NOT_HOLDING; + } + + public static enum SpreadItemParam implements ActionParam { + LEFT_MOUSE_BEGIN_DRAG, + LEFT_MOUSE_ADD_SLOT, + LEFT_MOUSE_END_DRAG, + RIGHT_MOUSE_BEGIN_DRAG, + RIGHT_MOUSE_ADD_SLOT, + RIGHT_MOUSE_END_DRAG; + } + + public static enum FillStackParam implements ActionParam { + FILL; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/world/ClientUpdateSignPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/world/ClientUpdateSignPacket.java new file mode 100644 index 00000000..52940e6d --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/client/world/ClientUpdateSignPacket.java @@ -0,0 +1,72 @@ +package ch.spacebase.mc.protocol.packet.ingame.client.world; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ClientUpdateSignPacket implements Packet { + + private int x; + private int y; + private int z; + private String lines[]; + + public ClientUpdateSignPacket() { + } + + public ClientUpdateSignPacket(int x, int y, int z, String lines[]) { + if(lines.length != 4) { + throw new IllegalArgumentException("Lines must contain exactly 4 strings!"); + } + + this.x = x; + this.y = y; + this.z = z; + this.lines = lines; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public String[] getLines() { + return this.lines; + } + + @Override + public void read(NetInput in) throws IOException { + this.x = in.readInt(); + this.y = in.readShort(); + this.z = in.readInt(); + this.lines = new String[4]; + for(int count = 0; count < this.lines.length; count++) { + this.lines[count] = in.readString(); + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.x); + out.writeShort(this.y); + out.writeInt(this.z); + for(String line : this.lines) { + out.writeString(line); + } + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerChatPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerChatPacket.java new file mode 100644 index 00000000..63c5d697 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerChatPacket.java @@ -0,0 +1,48 @@ +package ch.spacebase.mc.protocol.packet.ingame.server; + +import java.io.IOException; + +import ch.spacebase.mc.util.message.Message; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerChatPacket implements Packet { + + private Message message; + + public ServerChatPacket() { + } + + public ServerChatPacket(String message) { + this(new Message(message)); + } + + public ServerChatPacket(Message message) { + this.message = message; + } + + public String getRawMessage() { + return this.message.getRawText(); + } + + public Message getMessage() { + return this.message; + } + + @Override + public void read(NetInput in) throws IOException { + this.message = new Message(in.readString(), true); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.message.toString()); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerDisconnectPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerDisconnectPacket.java new file mode 100644 index 00000000..423ef247 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerDisconnectPacket.java @@ -0,0 +1,48 @@ +package ch.spacebase.mc.protocol.packet.ingame.server; + +import java.io.IOException; + +import ch.spacebase.mc.util.message.Message; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerDisconnectPacket implements Packet { + + private Message message; + + public ServerDisconnectPacket() { + } + + public ServerDisconnectPacket(String message) { + this(new Message(message)); + } + + public ServerDisconnectPacket(Message message) { + this.message = message; + } + + public String getRawReason() { + return this.message.getRawText(); + } + + public Message getReason() { + return this.message; + } + + @Override + public void read(NetInput in) throws IOException { + this.message = new Message(in.readString(), true); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.message.toString()); + } + + @Override + public boolean isPriority() { + return true; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerJoinGamePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerJoinGamePacket.java new file mode 100644 index 00000000..47b64272 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerJoinGamePacket.java @@ -0,0 +1,149 @@ +package ch.spacebase.mc.protocol.packet.ingame.server; + +import java.io.IOException; + +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerJoinGamePacket implements Packet { + + private int entityId; + private boolean hardcore; + private GameMode gamemode; + private int dimension; + private Difficulty difficulty; + private int maxPlayers; + private WorldType worldType; + + public ServerJoinGamePacket() { + } + + public ServerJoinGamePacket(int entityId, boolean hardcore, GameMode gamemode, int dimension, Difficulty difficulty, int maxPlayers, WorldType worldType) { + this.entityId = entityId; + this.hardcore = hardcore; + this.gamemode = gamemode; + this.dimension = dimension; + this.difficulty = difficulty; + this.maxPlayers = maxPlayers; + this.worldType = worldType; + } + + public int getEntityId() { + return this.entityId; + } + + public boolean getHardcore() { + return this.hardcore; + } + + public GameMode getGameMode() { + return this.gamemode; + } + + public int getDimension() { + return this.dimension; + } + + public Difficulty getDifficulty() { + return this.difficulty; + } + + public int getMaxPlayers() { + return this.maxPlayers; + } + + public WorldType getWorldType() { + return this.worldType; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + int gamemode = in.readUnsignedByte(); + this.hardcore = (gamemode & 8) == 8; + gamemode = gamemode & -9; + this.gamemode = GameMode.values()[gamemode]; + this.dimension = in.readByte(); + this.difficulty = Difficulty.values()[in.readUnsignedByte()]; + this.maxPlayers = in.readUnsignedByte(); + this.worldType = nameToType(in.readString()); + // Unfortunately this is needed to check whether to read skylight values in chunk data packets. + NetUtil.hasSky = this.dimension != -1 && this.dimension != 1; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + int gamemode = this.gamemode.ordinal(); + if(this.hardcore) { + gamemode |= 8; + } + + out.writeByte(gamemode); + out.writeByte(this.dimension); + out.writeByte(this.difficulty.ordinal()); + out.writeByte(this.maxPlayers); + out.writeString(typeToName(this.worldType)); + } + + @Override + public boolean isPriority() { + return false; + } + + private static String typeToName(WorldType type) throws IOException { + if(type == WorldType.DEFAULT) { + return "default"; + } else if(type == WorldType.FLAT) { + return "flat"; + } else if(type == WorldType.LARGE_BIOMES) { + return "largeBiomes"; + } else if(type == WorldType.AMPLIFIED) { + return "amplified"; + } else if(type == WorldType.DEFAULT_1_1) { + return "default_1_1"; + } else { + throw new IOException("Unmapped world type: " + type); + } + } + + private static WorldType nameToType(String name) throws IOException { + if(name.equals("default")) { + return WorldType.DEFAULT; + } else if(name.equals("flat")) { + return WorldType.FLAT; + } else if(name.equals("largeBiomes")) { + return WorldType.LARGE_BIOMES; + } else if(name.equals("amplified")) { + return WorldType.AMPLIFIED; + } else if(name.equals("default_1_1")) { + return WorldType.DEFAULT_1_1; + } else { + throw new IOException("Unknown world type: " + name); + } + } + + public static enum GameMode { + SURVIVAL, + CREATIVE, + ADVENTURE; + } + + public static enum Difficulty { + PEACEFUL, + EASY, + NORMAL, + HARD; + } + + public static enum WorldType { + DEFAULT, + FLAT, + LARGE_BIOMES, + AMPLIFIED, + DEFAULT_1_1; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerKeepAlivePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerKeepAlivePacket.java new file mode 100644 index 00000000..8f1fdccc --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerKeepAlivePacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.ingame.server; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerKeepAlivePacket implements Packet { + + private int id; + + public ServerKeepAlivePacket() { + } + + public ServerKeepAlivePacket(int id) { + this.id = id; + } + + public int getPingId() { + return this.id; + } + + @Override + public void read(NetInput in) throws IOException { + this.id = in.readInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.id); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerPlayerListEntryPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerPlayerListEntryPacket.java new file mode 100644 index 00000000..b899f0bb --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerPlayerListEntryPacket.java @@ -0,0 +1,55 @@ +package ch.spacebase.mc.protocol.packet.ingame.server; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerPlayerListEntryPacket implements Packet { + + private String name; + private boolean online; + private int ping; + + public ServerPlayerListEntryPacket() { + } + + public ServerPlayerListEntryPacket(String name, boolean online, int ping) { + this.name = name; + this.online = online; + this.ping = ping; + } + + public String getName() { + return this.name; + } + + public boolean getOnline() { + return this.online; + } + + public int getPing() { + return this.ping; + } + + @Override + public void read(NetInput in) throws IOException { + this.name = in.readString(); + this.online = in.readBoolean(); + this.ping = in.readShort(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.name); + out.writeBoolean(this.online); + out.writeShort(this.ping); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerPluginMessagePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerPluginMessagePacket.java new file mode 100644 index 00000000..8586e695 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerPluginMessagePacket.java @@ -0,0 +1,48 @@ +package ch.spacebase.mc.protocol.packet.ingame.server; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerPluginMessagePacket implements Packet { + + private String channel; + private byte data[]; + + public ServerPluginMessagePacket() { + } + + public ServerPluginMessagePacket(String channel, byte data[]) { + this.channel = channel; + this.data = data; + } + + public String getChannel() { + return this.channel; + } + + public byte[] getData() { + return this.data; + } + + @Override + public void read(NetInput in) throws IOException { + this.channel = in.readString(); + this.data = in.readBytes(in.readShort()); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.channel); + out.writeShort(this.data.length); + out.writeBytes(this.data); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerRespawnPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerRespawnPacket.java new file mode 100644 index 00000000..2da38fbe --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerRespawnPacket.java @@ -0,0 +1,119 @@ +package ch.spacebase.mc.protocol.packet.ingame.server; + +import java.io.IOException; + +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerRespawnPacket implements Packet { + + private int dimension; + private Difficulty difficulty; + private GameMode gamemode; + private WorldType worldType; + + public ServerRespawnPacket() { + } + + public ServerRespawnPacket(int dimension, Difficulty difficulty, GameMode gamemode, WorldType worldType) { + this.dimension = dimension; + this.difficulty = difficulty; + this.gamemode = gamemode; + this.worldType = worldType; + } + + public int getDimension() { + return this.dimension; + } + + public Difficulty getDifficulty() { + return this.difficulty; + } + + public GameMode getGameMode() { + return this.gamemode; + } + + public WorldType getWorldType() { + return this.worldType; + } + + @Override + public void read(NetInput in) throws IOException { + this.dimension = in.readInt(); + this.difficulty = Difficulty.values()[in.readUnsignedByte()]; + this.gamemode = GameMode.values()[in.readUnsignedByte()]; + this.worldType = nameToType(in.readString()); + // Unfortunately this is needed to check whether to read skylight values in chunk data packets. + NetUtil.hasSky = this.dimension != -1 && this.dimension != 1; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.dimension); + out.writeByte(this.difficulty.ordinal()); + out.writeByte(this.gamemode.ordinal()); + out.writeString(typeToName(this.worldType)); + } + + @Override + public boolean isPriority() { + return false; + } + + private static String typeToName(WorldType type) throws IOException { + if(type == WorldType.DEFAULT) { + return "default"; + } else if(type == WorldType.FLAT) { + return "flat"; + } else if(type == WorldType.LARGE_BIOMES) { + return "largeBiomes"; + } else if(type == WorldType.AMPLIFIED) { + return "amplified"; + } else if(type == WorldType.DEFAULT_1_1) { + return "default_1_1"; + } else { + throw new IOException("Unmapped world type: " + type); + } + } + + private static WorldType nameToType(String name) throws IOException { + if(name.equals("default")) { + return WorldType.DEFAULT; + } else if(name.equals("flat")) { + return WorldType.FLAT; + } else if(name.equals("largeBiomes")) { + return WorldType.LARGE_BIOMES; + } else if(name.equals("amplified")) { + return WorldType.AMPLIFIED; + } else if(name.equals("default_1_1")) { + return WorldType.DEFAULT_1_1; + } else { + throw new IOException("Unknown world type: " + name); + } + } + + public static enum GameMode { + SURVIVAL, + CREATIVE, + ADVENTURE; + } + + public static enum Difficulty { + PEACEFUL, + EASY, + NORMAL, + HARD; + } + + public static enum WorldType { + DEFAULT, + FLAT, + LARGE_BIOMES, + AMPLIFIED, + DEFAULT_1_1; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerStatisticsPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerStatisticsPacket.java new file mode 100644 index 00000000..f557ec36 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerStatisticsPacket.java @@ -0,0 +1,129 @@ +package ch.spacebase.mc.protocol.packet.ingame.server; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerStatisticsPacket implements Packet { + + private Map statistics = new HashMap(); + + public ServerStatisticsPacket() { + } + + public ServerStatisticsPacket(Map statistics) { + this.statistics = statistics; + } + + public Map getStatistics() { + return this.statistics; + } + + @Override + public void read(NetInput in) throws IOException { + int length = in.readVarInt(); + for(int index = 0; index < length; index++) { + this.statistics.put(in.readString(), in.readVarInt()); + } + } + + @Override + public void write(NetOutput out) throws IOException { + for(String statistic : this.statistics.keySet()) { + out.writeString(statistic); + out.writeVarInt(this.statistics.get(statistic)); + } + } + + @Override + public boolean isPriority() { + return false; + } + + public static class Achievement { + public static final String OPEN_INVENTORY = "achievement.openInventory"; + public static final String GET_WOOD = "achievement.mineWood"; + public static final String MAKE_WORKBENCH = "achievement.buildWorkBench"; + public static final String MAKE_PICKAXE = "achievement.buildPickaxe"; + public static final String MAKE_FURNACE = "achievement.buildFurnace"; + public static final String GET_IRON = "achievement.acquireIron"; + public static final String MAKE_HOE = "achievement.buildHoe"; + public static final String MAKE_BREAD = "achievement.makeBread"; + public static final String MAKE_CAKE = "achievement.bakeCake"; + public static final String MAKE_IRON_PICKAXE = "achievement.buildBetterPickaxe"; + public static final String COOK_FISH = "achievement.cookFish"; + public static final String RIDE_MINECART_1000_BLOCKS = "achievement.onARail"; + public static final String MAKE_SWORD = "achievement.buildSword"; + public static final String KILL_ENEMY = "achievement.killEnemy"; + public static final String KILL_COW = "achievement.killCow"; + public static final String FLY_PIG = "achievement.flyPig"; + public static final String SNIPE_SKELETON = "achievement.snipeSkeleton"; + public static final String GET_DIAMONDS = "achievement.diamonds"; + public static final String GIVE_DIAMONDS = "achievement.diamondsToYou"; + public static final String ENTER_PORTAL = "achievement.portal"; + public static final String ATTACKED_BY_GHAST = "achievement.ghast"; + public static final String GET_BLAZE_ROD = "achievement.blazeRod"; + public static final String MAKE_POTION = "achievement.potion"; + public static final String GO_TO_THE_END = "achievement.theEnd"; + public static final String DEFEAT_ENDER_DRAGON = "achievement.theEnd2"; + public static final String DEAL_18_OR_MORE_DAMAGE = "achievement.overkill"; + public static final String MAKE_BOOKCASE = "achievement.bookcase"; + public static final String BREED_COW = "achievement.breedCow"; + public static final String SPAWN_WITHER = "achievement.spawnWither"; + public static final String KILL_WITHER = "achievement.killWither"; + public static final String MAKE_FULL_BEACON = "achievement.fullBeacon"; + public static final String EXPLORE_ALL_BIOMES = "achievement.exploreAllBiomes"; + } + + public static class Statistic { + public static final String TIMES_LEFT_GAME = "stat.leaveGame"; + public static final String MINUTES_PLAYED = "stat.playOneMinute"; + public static final String BLOCKS_WALKED = "stat.walkOneCm"; + public static final String BLOCKS_SWAM = "stat.swimOneCm"; + public static final String BLOCKS_FALLEN = "stat.fallOneCm"; + public static final String BLOCKS_CLIMBED = "stat.climbOneCm"; + public static final String BLOCKS_FLOWN = "stat.flyOneCm"; + public static final String BLOCKS_DOVE = "stat.diveOneCm"; + public static final String BLOCKS_TRAVELLED_IN_MINECART = "stat.minecartOneCm"; + public static final String BLOCKS_TRAVELLED_IN_BOAT = "stat.boatOneCm"; + public static final String BLOCKS_RODE_ON_PIG = "stat.pigOneCm"; + public static final String BLOCKS_RODE_ON_HORSE = "stat.horseOneCm"; + public static final String TIMES_JUMPED = "stat.jump"; + public static final String TIMES_DROPPED_ITEMS = "stat.drop"; + public static final String TIMES_DEALT_DAMAGE = "stat.damageDealt"; + public static final String DAMAGE_TAKEN = "stat.damageTaken"; + public static final String DEATHS = "stat.deaths"; + public static final String MOB_KILLS = "stat.mobKills"; + public static final String ANIMALS_BRED = "stat.animalsBred"; + public static final String PLAYERS_KILLED = "stat.playerKills"; + public static final String FISH_CAUGHT = "stat.fishCaught"; + public static final String JUNK_FISHED = "stat.junkFished"; + public static final String TREASURE_FISHED = "stat.treasureFished"; + + private static final String CRAFT_ITEM_BASE = "stat.craftItem."; + private static final String BREAK_BLOCK_BASE = "stat.mineBlock."; + private static final String USE_ITEM_BASE = "stat.useItem."; + private static final String BREAK_ITEM_BASE = "stat.breakItem."; + + public static final String CRAFT_ITEM(int id) { + return CRAFT_ITEM_BASE + id; + } + + public static final String BREAK_BLOCK(int id) { + return BREAK_BLOCK_BASE + id; + } + + public static final String USE_ITEM(int id) { + return USE_ITEM_BASE + id; + } + + public static final String BREAK_ITEM(int id) { + return BREAK_ITEM_BASE + id; + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerTabCompletePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerTabCompletePacket.java new file mode 100644 index 00000000..4a2168f9 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/ServerTabCompletePacket.java @@ -0,0 +1,45 @@ +package ch.spacebase.mc.protocol.packet.ingame.server; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerTabCompletePacket implements Packet { + + private String matches[]; + + public ServerTabCompletePacket() { + } + + public ServerTabCompletePacket(String matches[]) { + this.matches = matches; + } + + public String[] getMatches() { + return this.matches; + } + + @Override + public void read(NetInput in) throws IOException { + this.matches = new String[in.readVarInt()]; + for(int index = 0; index < this.matches.length; index++) { + this.matches[index] = in.readString(); + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeVarInt(this.matches.length); + for(String match : this.matches) { + out.writeString(match); + } + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerAnimationPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerAnimationPacket.java new file mode 100644 index 00000000..57b3ebb7 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerAnimationPacket.java @@ -0,0 +1,56 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerAnimationPacket implements Packet { + + private int entityId; + private Animation animation; + + public ServerAnimationPacket() { + } + + public ServerAnimationPacket(int entityId, Animation animation) { + this.entityId = entityId; + this.animation = animation; + } + + public int getEntityId() { + return this.entityId; + } + + public Animation getAnimation() { + return this.animation; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.animation = Animation.values()[in.readByte()]; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeByte(this.animation.ordinal()); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Animation { + SWING_ARM, + DAMAGE, + LEAVE_BED, + EAT_FOOD, + CRITICAL_HIT, + ENCHANTMENT_CRITICAL_HIT; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerCollectItemPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerCollectItemPacket.java new file mode 100644 index 00000000..582b5c48 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerCollectItemPacket.java @@ -0,0 +1,47 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerCollectItemPacket implements Packet { + + private int collectedEntityId; + private int collectorEntityId; + + public ServerCollectItemPacket() { + } + + public ServerCollectItemPacket(int collectedEntityId, int collectorEntityId) { + this.collectedEntityId = collectedEntityId; + this.collectorEntityId = collectorEntityId; + } + + public int getCollectedEntityId() { + return this.collectedEntityId; + } + + public int getCollectorEntityId() { + return this.collectorEntityId; + } + + @Override + public void read(NetInput in) throws IOException { + this.collectedEntityId = in.readInt(); + this.collectorEntityId = in.readInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.collectedEntityId); + out.writeInt(this.collectorEntityId); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerDestroyEntitiesPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerDestroyEntitiesPacket.java new file mode 100644 index 00000000..1ab4259c --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerDestroyEntitiesPacket.java @@ -0,0 +1,45 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerDestroyEntitiesPacket implements Packet { + + private int entityIds[]; + + public ServerDestroyEntitiesPacket() { + } + + public ServerDestroyEntitiesPacket(int... entityIds) { + this.entityIds = entityIds; + } + + public int[] getEntityIds() { + return this.entityIds; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityIds = new int[in.readByte()]; + for(int index = 0; index < this.entityIds.length; index++) { + this.entityIds[index] = in.readInt(); + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.entityIds.length); + for(int entityId : this.entityIds) { + out.writeInt(entityId); + } + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityAttachPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityAttachPacket.java new file mode 100644 index 00000000..47aad71a --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityAttachPacket.java @@ -0,0 +1,55 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerEntityAttachPacket implements Packet { + + private int entityId; + private int attachedToId; + private boolean leash; + + public ServerEntityAttachPacket() { + } + + public ServerEntityAttachPacket(int entityId, int attachedToId, boolean leash) { + this.entityId = entityId; + this.attachedToId = attachedToId; + this.leash = leash; + } + + public int getEntityId() { + return this.entityId; + } + + public int getAttachedToId() { + return this.attachedToId; + } + + public boolean getLeash() { + return this.leash; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.attachedToId = in.readInt(); + this.leash = in.readBoolean(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeInt(this.attachedToId); + out.writeBoolean(this.leash); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityEffectPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityEffectPacket.java new file mode 100644 index 00000000..488627a0 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityEffectPacket.java @@ -0,0 +1,89 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerEntityEffectPacket implements Packet { + + private int entityId; + private Effect effect; + private int amplifier; + private int duration; + + public ServerEntityEffectPacket() { + } + + public ServerEntityEffectPacket(int entityId, Effect effect, int amplifier, int duration) { + this.entityId = entityId; + this.effect = effect; + this.amplifier = amplifier; + this.duration = duration; + } + + public int getEntityId() { + return this.entityId; + } + + public Effect getEffect() { + return this.effect; + } + + public int getAmplifier() { + return this.amplifier; + } + + public int getDuration() { + return this.duration; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.effect = Effect.values()[in.readByte()]; + this.amplifier = in.readByte(); + this.duration = in.readShort(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeByte(this.effect.ordinal()); + out.writeByte(this.amplifier); + out.writeShort(this.duration); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Effect { + SPEED, + SLOWNESS, + DIG_SPEED, + DIG_SLOWNESS, + DAMAGE_BOOST, + HEAL, + DAMAGE, + ENHANCED_JUMP, + CONFUSION, + REGENERATION, + RESISTANCE, + FIRE_RESISTANCE, + WATER_BREATHING, + INVISIBILITY, + BLINDNESS, + NIGHT_VISION, + HUNGER, + WEAKNESS, + POISON, + WITHER_EFFECT, + HEALTH_BOOST, + ABSORPTION, + SATURATION; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityEquipmentPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityEquipmentPacket.java new file mode 100644 index 00000000..30edd14c --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityEquipmentPacket.java @@ -0,0 +1,57 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.mc.protocol.data.game.ItemStack; +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerEntityEquipmentPacket implements Packet { + + private int entityId; + private int slot; + private ItemStack item; + + public ServerEntityEquipmentPacket() { + } + + public ServerEntityEquipmentPacket(int entityId, int slot, ItemStack item) { + this.entityId = entityId; + this.slot = slot; + this.item = item; + } + + public int getEntityId() { + return this.entityId; + } + + public int getSlot() { + return this.slot; + } + + public ItemStack getItem() { + return this.item; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.slot = in.readShort(); + this.item = NetUtil.readItem(in); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeShort(this.slot); + NetUtil.writeItem(out, this.item); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityHeadLookPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityHeadLookPacket.java new file mode 100644 index 00000000..25434f93 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityHeadLookPacket.java @@ -0,0 +1,43 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerEntityHeadLookPacket implements Packet { + + protected int entityId; + protected float headYaw; + + public ServerEntityHeadLookPacket() { + } + + public ServerEntityHeadLookPacket(int entityId, float headYaw) { + this.entityId = entityId; + this.headYaw = headYaw; + } + + public float getHeadYaw() { + return this.headYaw; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.headYaw = in.readByte() * 360 / 256f; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeByte((byte) (this.headYaw * 256 / 360)); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityMetadataPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityMetadataPacket.java new file mode 100644 index 00000000..d482af31 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityMetadataPacket.java @@ -0,0 +1,49 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.mc.protocol.data.game.EntityMetadata; +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerEntityMetadataPacket implements Packet { + + private int entityId; + private EntityMetadata metadata[]; + + public ServerEntityMetadataPacket() { + } + + public ServerEntityMetadataPacket(int entityId, EntityMetadata metadata[]) { + this.entityId = entityId; + this.metadata = metadata; + } + + public int getEntityId() { + return this.entityId; + } + + public EntityMetadata[] getMetadata() { + return this.metadata; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.metadata = NetUtil.readEntityMetadata(in); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + NetUtil.writeEntityMetadata(out, this.metadata); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityMovementPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityMovementPacket.java new file mode 100644 index 00000000..296cfd4f --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityMovementPacket.java @@ -0,0 +1,87 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerEntityMovementPacket implements Packet { + + protected int entityId; + protected double moveX; + protected double moveY; + protected double moveZ; + protected float yaw; + protected float pitch; + + protected boolean pos = false; + protected boolean rot = false; + + public ServerEntityMovementPacket() { + } + + public ServerEntityMovementPacket(int entityId) { + this.entityId = entityId; + } + + public int getEntityId() { + return this.entityId; + } + + public double getMovementX() { + return this.moveX; + } + + public double getMovementY() { + return this.moveY; + } + + public double getMovementZ() { + return this.moveZ; + } + + public float getYaw() { + return this.yaw; + } + + public float getPitch() { + return this.pitch; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + if(this.pos) { + this.moveX = in.readByte() / 32D; + this.moveY = in.readByte() / 32D; + this.moveZ = in.readByte() / 32D; + } + + if(this.rot) { + this.yaw = in.readByte() * 360 / 256f; + this.pitch = in.readByte() * 360 / 256f; + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + if(this.pos) { + out.writeByte((int) (this.moveX * 32)); + out.writeByte((int) (this.moveY * 32)); + out.writeByte((int) (this.moveZ * 32)); + } + + if(this.rot) { + out.writeByte((byte) (this.yaw * 256 / 360)); + out.writeByte((byte) (this.pitch * 256 / 360)); + } + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityPositionPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityPositionPacket.java new file mode 100644 index 00000000..7a42ea5f --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityPositionPacket.java @@ -0,0 +1,17 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +public class ServerEntityPositionPacket extends ServerEntityMovementPacket { + + public ServerEntityPositionPacket() { + this.pos = true; + } + + public ServerEntityPositionPacket(int entityId, double moveX, double moveY, double moveZ) { + super(entityId); + this.pos = true; + this.moveX = moveX; + this.moveY = moveY; + this.moveZ = moveZ; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityPositionRotationPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityPositionRotationPacket.java new file mode 100644 index 00000000..704a562c --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityPositionRotationPacket.java @@ -0,0 +1,21 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +public class ServerEntityPositionRotationPacket extends ServerEntityMovementPacket { + + public ServerEntityPositionRotationPacket() { + this.pos = true; + this.rot = true; + } + + public ServerEntityPositionRotationPacket(int entityId, double moveX, double moveY, double moveZ, float yaw, float pitch) { + super(entityId); + this.pos = true; + this.rot = true; + this.moveX = moveX; + this.moveY = moveY; + this.moveZ = moveZ; + this.yaw = yaw; + this.pitch = pitch; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityPropertiesPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityPropertiesPacket.java new file mode 100644 index 00000000..be09337c --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityPropertiesPacket.java @@ -0,0 +1,75 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import ch.spacebase.mc.protocol.data.game.Attribute; +import ch.spacebase.mc.protocol.data.game.AttributeModifier; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerEntityPropertiesPacket implements Packet { + + private int entityId; + private List attributes; + + public ServerEntityPropertiesPacket() { + } + + public ServerEntityPropertiesPacket(int entityId, List attributes) { + this.entityId = entityId; + this.attributes = attributes; + } + + public int getEntityId() { + return this.entityId; + } + + public List getAttributes() { + return this.attributes; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.attributes = new ArrayList(); + int length = in.readInt(); + for(int index = 0; index < length; index++) { + String key = in.readString(); + double value = in.readDouble(); + List modifiers = new ArrayList(); + short len = in.readShort(); + for(int ind = 0; ind < len; ind++) { + modifiers.add(new AttributeModifier(new UUID(in.readLong(), in.readLong()), in.readDouble(), in.readByte())); + } + + this.attributes.add(new Attribute(key, value, modifiers)); + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeInt(this.attributes.size()); + for(Attribute attribute : this.attributes) { + out.writeString(attribute.getKey()); + out.writeDouble(attribute.getValue()); + out.writeShort(attribute.getModifiers().size()); + for(AttributeModifier modifier : attribute.getModifiers()) { + out.writeLong(modifier.getUUID().getMostSignificantBits()); + out.writeLong(modifier.getUUID().getLeastSignificantBits()); + out.writeDouble(modifier.getAmount()); + out.writeByte(modifier.getOperation()); + } + } + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityRemoveEffectPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityRemoveEffectPacket.java new file mode 100644 index 00000000..e2022485 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityRemoveEffectPacket.java @@ -0,0 +1,89 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerEntityRemoveEffectPacket implements Packet { + + private int entityId; + private Effect effect; + private int amplifier; + private int duration; + + public ServerEntityRemoveEffectPacket() { + } + + public ServerEntityRemoveEffectPacket(int entityId, Effect effect, int amplifier, int duration) { + this.entityId = entityId; + this.effect = effect; + this.amplifier = amplifier; + this.duration = duration; + } + + public int getEntityId() { + return this.entityId; + } + + public Effect getEffect() { + return this.effect; + } + + public int getAmplifier() { + return this.amplifier; + } + + public int getDuration() { + return this.duration; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.effect = Effect.values()[in.readByte()]; + this.amplifier = in.readByte(); + this.duration = in.readShort(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeByte(this.effect.ordinal()); + out.writeByte(this.amplifier); + out.writeShort(this.duration); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Effect { + SPEED, + SLOWNESS, + DIG_SPEED, + DIG_SLOWNESS, + DAMAGE_BOOST, + HEAL, + DAMAGE, + ENHANCED_JUMP, + CONFUSION, + REGENERATION, + RESISTANCE, + FIRE_RESISTANCE, + WATER_BREATHING, + INVISIBILITY, + BLINDNESS, + NIGHT_VISION, + HUNGER, + WEAKNESS, + POISON, + WITHER_EFFECT, + HEALTH_BOOST, + ABSORPTION, + SATURATION; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityRotationPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityRotationPacket.java new file mode 100644 index 00000000..a77faaca --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityRotationPacket.java @@ -0,0 +1,16 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +public class ServerEntityRotationPacket extends ServerEntityMovementPacket { + + public ServerEntityRotationPacket() { + this.rot = true; + } + + public ServerEntityRotationPacket(int entityId, float yaw, float pitch) { + super(entityId); + this.rot = true; + this.yaw = yaw; + this.pitch = pitch; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityStatusPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityStatusPacket.java new file mode 100644 index 00000000..f946224e --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityStatusPacket.java @@ -0,0 +1,145 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerEntityStatusPacket implements Packet { + + protected int entityId; + protected Status status; + + public ServerEntityStatusPacket() { + } + + public ServerEntityStatusPacket(int entityId, Status status) { + this.entityId = entityId; + this.status = status; + } + + public Status getStatus() { + return this.status; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.status = valueToStatus(in.readByte()); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeByte(statusToValue(this.status)); + } + + @Override + public boolean isPriority() { + return false; + } + + private static byte statusToValue(Status status) throws IOException { + switch(status) { + case HURT_OR_MINECART_SPAWNER_DELAY_RESET: + return 1; + case LIVING_HURT: + return 2; + case DEAD: + return 3; + case IRON_GOLEM_THROW: + return 4; + case TAMING: + return 6; + case TAMED: + return 7; + case WOLF_SHAKING: + return 8; + case FINISHED_EATING: + return 9; + case SHEEP_GRAZING_OR_TNT_CART_EXPLODING: + return 10; + case IRON_GOLEM_ROSE: + return 11; + case VILLAGER_HEARTS: + return 12; + case VILLAGER_ANGRY: + return 13; + case VILLAGER_HAPPY: + return 14; + case WITCH_MAGIC_PARTICLES: + return 15; + case ZOMBIE_VILLAGER_SHAKING: + return 16; + case FIREWORK_EXPLODING: + return 17; + case ANIMAL_HEARTS: + return 18; + default: + throw new IOException("Unmapped entity status: " + status); + } + } + + private static Status valueToStatus(byte value) throws IOException { + switch(value) { + case 1: + return Status.HURT_OR_MINECART_SPAWNER_DELAY_RESET; + case 2: + return Status.LIVING_HURT; + case 3: + return Status.DEAD; + case 4: + return Status.IRON_GOLEM_THROW; + case 6: + return Status.TAMING; + case 7: + return Status.TAMED; + case 8: + return Status.WOLF_SHAKING; + case 9: + return Status.FINISHED_EATING; + case 10: + return Status.SHEEP_GRAZING_OR_TNT_CART_EXPLODING; + case 11: + return Status.IRON_GOLEM_ROSE; + case 12: + return Status.VILLAGER_HEARTS; + case 13: + return Status.VILLAGER_ANGRY; + case 14: + return Status.VILLAGER_HAPPY; + case 15: + return Status.WITCH_MAGIC_PARTICLES; + case 16: + return Status.ZOMBIE_VILLAGER_SHAKING; + case 17: + return Status.FIREWORK_EXPLODING; + case 18: + return Status.ANIMAL_HEARTS; + default: + throw new IOException("Unknown entity status value: " + value); + } + } + + public static enum Status { + HURT_OR_MINECART_SPAWNER_DELAY_RESET, + LIVING_HURT, + DEAD, + IRON_GOLEM_THROW, + TAMING, + TAMED, + WOLF_SHAKING, + FINISHED_EATING, + SHEEP_GRAZING_OR_TNT_CART_EXPLODING, + IRON_GOLEM_ROSE, + VILLAGER_HEARTS, + VILLAGER_ANGRY, + VILLAGER_HAPPY, + WITCH_MAGIC_PARTICLES, + ZOMBIE_VILLAGER_SHAKING, + FIREWORK_EXPLODING, + ANIMAL_HEARTS; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityTeleportPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityTeleportPacket.java new file mode 100644 index 00000000..eeebfea2 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityTeleportPacket.java @@ -0,0 +1,79 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerEntityTeleportPacket implements Packet { + + protected int entityId; + protected double x; + protected double y; + protected double z; + protected float yaw; + protected float pitch; + + public ServerEntityTeleportPacket() { + } + + public ServerEntityTeleportPacket(int entityId, double x, double y, double z, float yaw, float pitch) { + this.entityId = entityId; + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + } + + public int getEntityId() { + return this.entityId; + } + + public double getX() { + return this.x; + } + + public double getY() { + return this.y; + } + + public double getZ() { + return this.z; + } + + public float getYaw() { + return this.yaw; + } + + public float getPitch() { + return this.pitch; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.x = in.readInt() / 32D; + this.y = in.readInt() / 32D; + this.z = in.readInt() / 32D; + this.yaw = in.readByte() * 360 / 256f; + this.pitch = in.readByte() * 360 / 256f; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeInt((int) (this.x * 32)); + out.writeInt((int) (this.y * 32)); + out.writeInt((int) (this.z * 32)); + out.writeByte((byte) (this.yaw * 256 / 360)); + out.writeByte((byte) (this.pitch * 256 / 360)); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityVelocityPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityVelocityPacket.java new file mode 100644 index 00000000..3fb4376b --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerEntityVelocityPacket.java @@ -0,0 +1,63 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerEntityVelocityPacket implements Packet { + + private int entityId; + private double motX; + private double motY; + private double motZ; + + public ServerEntityVelocityPacket() { + } + + public ServerEntityVelocityPacket(int entityId, double motX, double motY, double motZ) { + this.entityId = entityId; + this.motX = motX; + this.motY = motY; + this.motZ = motZ; + } + + public int getEntityId() { + return this.entityId; + } + + public double getMotionX() { + return this.motX; + } + + public double getMotionY() { + return this.motY; + } + + public double getMotionZ() { + return this.motZ; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.motX = in.readShort() / 8000D; + this.motY = in.readShort() / 8000D; + this.motZ = in.readShort() / 8000D; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeShort((int) (this.motX * 8000)); + out.writeShort((int) (this.motY * 8000)); + out.writeShort((int) (this.motZ * 8000)); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerRemoveEffectPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerRemoveEffectPacket.java new file mode 100644 index 00000000..5b29c502 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/ServerRemoveEffectPacket.java @@ -0,0 +1,73 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerRemoveEffectPacket implements Packet { + + private int entityId; + private Effect effect; + + public ServerRemoveEffectPacket() { + } + + public ServerRemoveEffectPacket(int entityId, Effect effect) { + this.entityId = entityId; + this.effect = effect; + } + + public int getEntityId() { + return this.entityId; + } + + public Effect getEffect() { + return this.effect; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.effect = Effect.values()[in.readByte()]; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeByte(this.effect.ordinal()); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Effect { + SPEED, + SLOWNESS, + DIG_SPEED, + DIG_SLOWNESS, + DAMAGE_BOOST, + HEAL, + DAMAGE, + ENHANCED_JUMP, + CONFUSION, + REGENERATION, + RESISTANCE, + FIRE_RESISTANCE, + WATER_BREATHING, + INVISIBILITY, + BLINDNESS, + NIGHT_VISION, + HUNGER, + WEAKNESS, + POISON, + WITHER_EFFECT, + HEALTH_BOOST, + ABSORPTION, + SATURATION; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerChangeHeldItemPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerChangeHeldItemPacket.java new file mode 100644 index 00000000..4fedcecc --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerChangeHeldItemPacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.player; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerChangeHeldItemPacket implements Packet { + + private int slot; + + public ServerChangeHeldItemPacket() { + } + + public ServerChangeHeldItemPacket(int slot) { + this.slot = slot; + } + + public int getSlot() { + return this.slot; + } + + @Override + public void read(NetInput in) throws IOException { + this.slot = in.readByte(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.slot); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerPlayerAbilitiesPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerPlayerAbilitiesPacket.java new file mode 100644 index 00000000..9c4cc9f6 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerPlayerAbilitiesPacket.java @@ -0,0 +1,94 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.player; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerPlayerAbilitiesPacket implements Packet { + + private boolean invincible; + private boolean canFly; + private boolean flying; + private boolean creative; + private float flySpeed; + private float walkSpeed; + + public ServerPlayerAbilitiesPacket() { + } + + public ServerPlayerAbilitiesPacket(boolean invincible, boolean canFly, boolean flying, boolean creative, float flySpeed, float walkSpeed) { + this.invincible = invincible; + this.canFly = canFly; + this.flying = flying; + this.creative = creative; + this.flySpeed = flySpeed; + this.walkSpeed = walkSpeed; + } + + public boolean getInvincible() { + return this.invincible; + } + + public boolean getCanFly() { + return this.canFly; + } + + public boolean getFlying() { + return this.flying; + } + + public boolean getCreative() { + return this.creative; + } + + public float getFlySpeed() { + return this.flySpeed; + } + + public float getWalkSpeed() { + return this.walkSpeed; + } + + @Override + public void read(NetInput in) throws IOException { + byte flags = in.readByte(); + this.invincible = (flags & 1) > 0; + this.canFly = (flags & 2) > 0; + this.flying = (flags & 4) > 0; + this.creative = (flags & 8) > 0; + this.flySpeed = in.readFloat(); + this.walkSpeed = in.readFloat(); + } + + @Override + public void write(NetOutput out) throws IOException { + byte flags = 0; + if(this.invincible) { + flags = (byte) (flags | 1); + } + + if(this.canFly) { + flags = (byte) (flags | 2); + } + + if(this.flying) { + flags = (byte) (flags | 4); + } + + if(this.creative) { + flags = (byte) (flags | 8); + } + + out.writeByte(flags); + out.writeFloat(this.flySpeed); + out.writeFloat(this.walkSpeed); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerPlayerPositionRotationPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerPlayerPositionRotationPacket.java new file mode 100644 index 00000000..0ade52b4 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerPlayerPositionRotationPacket.java @@ -0,0 +1,79 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.player; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerPlayerPositionRotationPacket implements Packet { + + protected double x; + protected double y; + protected double z; + protected float yaw; + protected float pitch; + protected boolean onGround; + + public ServerPlayerPositionRotationPacket() { + } + + public ServerPlayerPositionRotationPacket(double x, double y, double z, float yaw, float pitch, boolean onGround) { + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + this.onGround = onGround; + } + + public double getX() { + return this.x; + } + + public double getY() { + return this.y; + } + + public double getZ() { + return this.z; + } + + public float getYaw() { + return this.yaw; + } + + public float getPitch() { + return this.pitch; + } + + public boolean isOnGround() { + return this.onGround; + } + + @Override + public void read(NetInput in) throws IOException { + this.x = in.readDouble(); + this.y = in.readDouble(); + this.z = in.readDouble(); + this.yaw = in.readFloat(); + this.pitch = in.readFloat(); + this.onGround = in.readBoolean(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeDouble(this.x); + out.writeDouble(this.y); + out.writeDouble(this.z); + out.writeFloat(this.yaw); + out.writeFloat(this.pitch); + out.writeBoolean(this.onGround); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerPlayerUseBedPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerPlayerUseBedPacket.java new file mode 100644 index 00000000..aa69accb --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerPlayerUseBedPacket.java @@ -0,0 +1,63 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.player; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerPlayerUseBedPacket implements Packet { + + private int entityId; + private int x; + private int y; + private int z; + + public ServerPlayerUseBedPacket() { + } + + public ServerPlayerUseBedPacket(int entityId, int x, int y, int z) { + this.entityId = entityId; + this.x = x; + this.y = y; + this.z = z; + } + + public int getEntityId() { + return this.entityId; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readInt(); + this.x = in.readInt(); + this.y = in.readUnsignedByte(); + this.z = in.readInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.entityId); + out.writeInt(this.x); + out.writeByte(this.y); + out.writeInt(this.z); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerSetExperiencePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerSetExperiencePacket.java new file mode 100644 index 00000000..92fdc0ad --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerSetExperiencePacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.player; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerSetExperiencePacket implements Packet { + + private int slot; + + public ServerSetExperiencePacket() { + } + + public ServerSetExperiencePacket(int slot) { + this.slot = slot; + } + + public int getSlot() { + return this.slot; + } + + @Override + public void read(NetInput in) throws IOException { + this.slot = in.readByte(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.slot); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerUpdateHealthPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerUpdateHealthPacket.java new file mode 100644 index 00000000..e6a5a090 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/player/ServerUpdateHealthPacket.java @@ -0,0 +1,55 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.player; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerUpdateHealthPacket implements Packet { + + private float health; + private int food; + private float saturation; + + public ServerUpdateHealthPacket() { + } + + public ServerUpdateHealthPacket(float health, int food, float saturation) { + this.health = health; + this.food = food; + this.saturation = saturation; + } + + public float getHealth() { + return this.health; + } + + public int getFood() { + return this.food; + } + + public float getSaturation() { + return this.saturation; + } + + @Override + public void read(NetInput in) throws IOException { + this.health = in.readFloat(); + this.food = in.readShort(); + this.saturation = in.readFloat(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeFloat(this.health); + out.writeShort(this.food); + out.writeFloat(this.saturation); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnExpOrbPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnExpOrbPacket.java new file mode 100644 index 00000000..bc6db695 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnExpOrbPacket.java @@ -0,0 +1,71 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerSpawnExpOrbPacket implements Packet { + + private int entityId; + private double x; + private double y; + private double z; + private int exp; + + public ServerSpawnExpOrbPacket() { + } + + public ServerSpawnExpOrbPacket(int entityId, double x, double y, double z, int exp) { + this.entityId = entityId; + this.x = x; + this.y = y; + this.z = z; + this.exp = exp; + } + + public int getEntityId() { + return this.entityId; + } + + public double getX() { + return this.x; + } + + public double getY() { + return this.y; + } + + public double getZ() { + return this.z; + } + + public int getExp() { + return this.exp; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readVarInt(); + this.x = in.readInt() / 32D; + this.y = in.readInt() / 32D; + this.z = in.readInt() / 32D; + this.exp = in.readShort(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeVarInt(this.entityId); + out.writeInt((int) (this.x * 32)); + out.writeInt((int) (this.y * 32)); + out.writeInt((int) (this.z * 32)); + out.writeShort(this.exp); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnGlobalEntityPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnGlobalEntityPacket.java new file mode 100644 index 00000000..82f02570 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnGlobalEntityPacket.java @@ -0,0 +1,75 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerSpawnGlobalEntityPacket implements Packet { + + private int entityId; + private Type type; + private int x; + private int y; + private int z; + + public ServerSpawnGlobalEntityPacket() { + } + + public ServerSpawnGlobalEntityPacket(int entityId, Type type, int x, int y, int z) { + this.entityId = entityId; + this.type = type; + this.x = x; + this.y = y; + this.z = z; + } + + public int getEntityId() { + return this.entityId; + } + + public Type getType() { + return this.type; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readVarInt(); + this.type = Type.values()[in.readByte()]; + this.x = in.readInt(); + this.y = in.readInt(); + this.z = in.readInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeVarInt(this.entityId); + out.writeByte(this.type.ordinal()); + out.writeInt(this.x); + out.writeInt(this.y); + out.writeInt(this.z); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Type { + LIGHTNING_BOLT; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnMobPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnMobPacket.java new file mode 100644 index 00000000..ab9b8c35 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnMobPacket.java @@ -0,0 +1,291 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn; + +import java.io.IOException; + +import ch.spacebase.mc.protocol.data.game.EntityMetadata; +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerSpawnMobPacket implements Packet { + + private int entityId; + private Type type; + private double x; + private double y; + private double z; + private float pitch; + private float yaw; + private float headYaw; + private double motX; + private double motY; + private double motZ; + private EntityMetadata metadata[]; + + public ServerSpawnMobPacket() { + } + + public ServerSpawnMobPacket(int entityId, Type type, double x, double y, double z, float yaw, float pitch, float headYaw, double motX, double motY, double motZ, EntityMetadata metadata[]) { + this.entityId = entityId; + this.type = type; + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + this.headYaw = headYaw; + this.motX = motX; + this.motY = motY; + this.motZ = motZ; + this.metadata = metadata; + } + + public int getEntityId() { + return this.entityId; + } + + public Type getType() { + return this.type; + } + + public double getX() { + return this.x; + } + + public double getY() { + return this.y; + } + + public double getZ() { + return this.z; + } + + public float getYaw() { + return this.yaw; + } + + public float getPitch() { + return this.pitch; + } + + public float getHeadYaw() { + return this.headYaw; + } + + public double getMotionX() { + return this.motX; + } + + public double getMotionY() { + return this.motY; + } + + public double getMotionZ() { + return this.motZ; + } + + public EntityMetadata[] getMetadata() { + return this.metadata; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readVarInt(); + this.type = idToType(in.readByte()); + this.x = in.readInt() / 32D; + this.y = in.readInt() / 32D; + this.z = in.readInt() / 32D; + this.yaw = in.readByte() * 360 / 256f; + this.pitch = in.readByte() * 360 / 256f; + this.headYaw = in.readByte() * 360 / 256f; + this.motX = in.readShort() / 8000D; + this.motY = in.readShort() / 8000D; + this.motZ = in.readShort() / 8000D; + this.metadata = NetUtil.readEntityMetadata(in); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeVarInt(this.entityId); + out.writeByte(typeToId(this.type)); + out.writeInt((int) (this.x * 32)); + out.writeInt((int) (this.y * 32)); + out.writeInt((int) (this.z * 32)); + out.writeByte((byte) (this.yaw * 256 / 360)); + out.writeByte((byte) (this.pitch * 256 / 360)); + out.writeByte((byte) (this.headYaw * 256 / 360)); + out.writeShort((int) (this.motX * 8000)); + out.writeShort((int) (this.motY * 8000)); + out.writeShort((int) (this.motZ * 8000)); + NetUtil.writeEntityMetadata(out, this.metadata); + } + + @Override + public boolean isPriority() { + return false; + } + + private static Type idToType(byte id) throws IOException { + switch(id) { + case 50: + return Type.CREEPER; + case 51: + return Type.SKELETON; + case 52: + return Type.SPIDER; + case 53: + return Type.GIANT_ZOMBIE; + case 54: + return Type.ZOMBIE; + case 55: + return Type.SLIME; + case 56: + return Type.GHAST; + case 57: + return Type.ZOMBIE_PIGMAN; + case 58: + return Type.ENDERMAN; + case 59: + return Type.CAVE_SPIDER; + case 60: + return Type.SILVERFISH; + case 61: + return Type.BLAZE; + case 62: + return Type.MAGMA_CUBE; + case 63: + return Type.ENDER_DRAGON; + case 64: + return Type.WITHER; + case 65: + return Type.BAT; + case 66: + return Type.WITCH; + case 90: + return Type.PIG; + case 91: + return Type.SHEEP; + case 92: + return Type.COW; + case 93: + return Type.CHICKEN; + case 94: + return Type.SQUID; + case 95: + return Type.WOLF; + case 96: + return Type.MOOSHROOM; + case 97: + return Type.SNOWMAN; + case 98: + return Type.OCELOT; + case 99: + return Type.IRON_GOLEM; + case 100: + return Type.HORSE; + case 120: + return Type.VILLAGER; + default: + throw new IOException("Unknown mob type id: " + id); + } + } + + private static byte typeToId(Type type) throws IOException { + switch(type) { + case CREEPER: + return 50; + case SKELETON: + return 51; + case SPIDER: + return 52; + case GIANT_ZOMBIE: + return 53; + case ZOMBIE: + return 54; + case SLIME: + return 55; + case GHAST: + return 56; + case ZOMBIE_PIGMAN: + return 57; + case ENDERMAN: + return 58; + case CAVE_SPIDER: + return 59; + case SILVERFISH: + return 60; + case BLAZE: + return 61; + case MAGMA_CUBE: + return 62; + case ENDER_DRAGON: + return 63; + case WITHER: + return 64; + case BAT: + return 65; + case WITCH: + return 66; + case PIG: + return 90; + case SHEEP: + return 91; + case COW: + return 92; + case CHICKEN: + return 93; + case SQUID: + return 94; + case WOLF: + return 95; + case MOOSHROOM: + return 96; + case SNOWMAN: + return 97; + case OCELOT: + return 98; + case IRON_GOLEM: + return 99; + case HORSE: + return 100; + case VILLAGER: + return 120; + default: + throw new IOException("Unmapped mob type: " + type); + } + } + + public static enum Type { + CREEPER, + SKELETON, + SPIDER, + GIANT_ZOMBIE, + ZOMBIE, + SLIME, + GHAST, + ZOMBIE_PIGMAN, + ENDERMAN, + CAVE_SPIDER, + SILVERFISH, + BLAZE, + MAGMA_CUBE, + ENDER_DRAGON, + WITHER, + BAT, + WITCH, + PIG, + SHEEP, + COW, + CHICKEN, + SQUID, + WOLF, + MOOSHROOM, + SNOWMAN, + OCELOT, + IRON_GOLEM, + HORSE, + VILLAGER; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnObjectPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnObjectPacket.java new file mode 100644 index 00000000..599c813e --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnObjectPacket.java @@ -0,0 +1,293 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerSpawnObjectPacket implements Packet { + + private int entityId; + private Type type; + private double x; + private double y; + private double z; + private float pitch; + private float yaw; + private int data; + private double motX; + private double motY; + private double motZ; + + public ServerSpawnObjectPacket() { + } + + public ServerSpawnObjectPacket(int entityId, Type type, double x, double y, double z, float yaw, float pitch) { + this(entityId, type, 0, x, y, z, yaw, pitch, 0, 0, 0); + } + + public ServerSpawnObjectPacket(int entityId, Type type, int data, double x, double y, double z, float yaw, float pitch, double motX, double motY, double motZ) { + this.entityId = entityId; + this.type = type; + this.data = data; + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + this.motX = motX; + this.motY = motY; + this.motZ = motZ; + } + + public int getEntityId() { + return this.entityId; + } + + public Type getType() { + return this.type; + } + + public int getData() { + return this.data; + } + + public double getX() { + return this.x; + } + + public double getY() { + return this.y; + } + + public double getZ() { + return this.z; + } + + public float getYaw() { + return this.yaw; + } + + public float getPitch() { + return this.pitch; + } + + public double getMotionX() { + return this.motX; + } + + public double getMotionY() { + return this.motY; + } + + public double getMotionZ() { + return this.motZ; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readVarInt(); + this.type = idToType(in.readByte()); + this.x = in.readInt() / 32D; + this.y = in.readInt() / 32D; + this.z = in.readInt() / 32D; + this.pitch = in.readByte() * 360 / 256f; + this.yaw = in.readByte() * 360 / 256f; + this.data = in.readInt(); + if(this.data > 0) { + this.motX = in.readShort() / 8000D; + this.motY = in.readShort() / 8000D; + this.motZ = in.readShort() / 8000D; + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeVarInt(this.entityId); + out.writeByte(typeToId(this.type)); + out.writeInt((int) (this.x * 32)); + out.writeInt((int) (this.y * 32)); + out.writeInt((int) (this.z * 32)); + out.writeByte((byte) (this.pitch * 256 / 360)); + out.writeByte((byte) (this.yaw * 256 / 360)); + out.writeInt(this.data); + if(this.data > 0) { + out.writeShort((int) (this.motX * 8000)); + out.writeShort((int) (this.motY * 8000)); + out.writeShort((int) (this.motZ * 8000)); + } + } + + @Override + public boolean isPriority() { + return false; + } + + private static Type idToType(byte id) throws IOException { + switch(id) { + case 1: + return Type.BOAT; + case 2: + return Type.ITEM; + case 10: + return Type.MINECART; + case 50: + return Type.PRIMED_TNT; + case 51: + return Type.ENDER_CRYSTAL; + case 60: + return Type.ARROW; + case 61: + return Type.SNOWBALL; + case 62: + return Type.EGG; + case 63: + return Type.GHAST_FIREBALL; + case 64: + return Type.BLAZE_FIREBALL; + case 65: + return Type.ENDER_PEARL; + case 66: + return Type.WITHER_HEAD_PROJECTILE; + case 70: + return Type.FALLING_BLOCK; + case 71: + return Type.ITEM_FRAME; + case 72: + return Type.EYE_OF_ENDER; + case 73: + return Type.POTION; + case 75: + return Type.EXP_BOTTLE; + case 76: + return Type.FIREWORK_ROCKET; + case 77: + return Type.LEASH_KNOT; + case 90: + return Type.FISH_HOOK; + default: + throw new IOException("Unknown object type id: " + id); + } + } + + private static byte typeToId(Type type) throws IOException { + switch(type) { + case BOAT: + return 1; + case ITEM: + return 2; + case MINECART: + return 10; + case PRIMED_TNT: + return 50; + case ENDER_CRYSTAL: + return 51; + case ARROW: + return 60; + case SNOWBALL: + return 61; + case EGG: + return 62; + case GHAST_FIREBALL: + return 63; + case BLAZE_FIREBALL: + return 64; + case ENDER_PEARL: + return 65; + case WITHER_HEAD_PROJECTILE: + return 66; + case FALLING_BLOCK: + return 70; + case ITEM_FRAME: + return 71; + case EYE_OF_ENDER: + return 72; + case POTION: + return 73; + case EXP_BOTTLE: + return 75; + case FIREWORK_ROCKET: + return 76; + case LEASH_KNOT: + return 77; + case FISH_HOOK: + return 90; + default: + throw new IOException("Unmapped object type: " + type); + } + } + + public static enum Type { + BOAT, + ITEM, + MINECART, + PRIMED_TNT, + ENDER_CRYSTAL, + ARROW, + SNOWBALL, + EGG, + GHAST_FIREBALL, + BLAZE_FIREBALL, + ENDER_PEARL, + WITHER_HEAD_PROJECTILE, + FALLING_BLOCK, + ITEM_FRAME, + EYE_OF_ENDER, + POTION, + EXP_BOTTLE, + FIREWORK_ROCKET, + LEASH_KNOT, + FISH_HOOK; + } + + public static class MinecartType { + public static final int NORMAL = 0; + public static final int CHEST = 1; + public static final int POWERED = 2; + public static final int TNT = 3; + public static final int MOB_SPAWNER = 4; + public static final int HOPPER = 5; + public static final int COMMAND_BLOCK = 6; + } + + public static class ItemFrameDirection { + public static final int SOUTH = 0; + public static final int WEST = 1; + public static final int NORTH = 2; + public static final int EAST = 3; + } + + public static class FallingBlockData { + public static final int BLOCK_TYPE_TO_DATA(FallingBlockType type) { + return BLOCK_TYPE_TO_DATA(type.getId(), type.getMetadata()); + } + + public static final int BLOCK_TYPE_TO_DATA(int block, int metadata) { + return block | metadata << 16; + } + + public static final FallingBlockType DATA_TO_BLOCK_TYPE(int data) { + return new FallingBlockType(data & 65535, data >> 16); + } + } + + public static class FallingBlockType { + private int id; + private int metadata; + + public FallingBlockType(int id, int metadata) { + this.id = id; + this.metadata = metadata; + } + + public int getId() { + return this.id; + } + + public int getMetadata() { + return this.metadata; + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnPaintingPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnPaintingPacket.java new file mode 100644 index 00000000..fac828ed --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnPaintingPacket.java @@ -0,0 +1,117 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerSpawnPaintingPacket implements Packet { + + private int entityId; + private Art art; + private int x; + private int y; + private int z; + private Direction direction; + + public ServerSpawnPaintingPacket() { + } + + public ServerSpawnPaintingPacket(int entityId, Art art, int x, int y, int z, Direction direction) { + this.entityId = entityId; + this.art = art; + this.x = x; + this.y = y; + this.z = z; + this.direction = direction; + } + + public int getEntityId() { + return this.entityId; + } + + public Art getArt() { + return this.art; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public Direction getDirection() { + return this.direction; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readVarInt(); + this.art = Art.valueOf(in.readString()); + this.x = in.readInt(); + this.y = in.readInt(); + this.z = in.readInt(); + this.direction = Direction.values()[in.readInt()]; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeVarInt(this.entityId); + out.writeString(this.art.name()); + out.writeInt(this.x); + out.writeInt(this.y); + out.writeInt(this.z); + out.writeInt(this.direction.ordinal()); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Direction { + BOTTOM, + TOP, + EAST, + WEST, + NORTH, + SOUTH; + } + + public static enum Art { + Kebab, + Aztec, + Alban, + Aztec2, + Bomb, + Plant, + Wasteland, + Pool, + Courbet, + Sea, + Sunset, + Creebet, + Wanderer, + Graham, + Match, + Bust, + Stage, + Void, + SkullAndRoses, + Wither, + Fighters, + Pointer, + Pigscene, + BurningSkull, + Skeleton, + DonkeyKong; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnPlayerPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnPlayerPacket.java new file mode 100644 index 00000000..66d38729 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnPlayerPacket.java @@ -0,0 +1,113 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.entity.spawn; + +import java.io.IOException; + +import ch.spacebase.mc.protocol.data.game.EntityMetadata; +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerSpawnPlayerPacket implements Packet { + + private int entityId; + private String uuid; + private String name; + private double x; + private double y; + private double z; + private float yaw; + private float pitch; + private int currentItem; + private EntityMetadata metadata[]; + + public ServerSpawnPlayerPacket() { + } + + public ServerSpawnPlayerPacket(int entityId, String uuid, String name, double x, double y, double z, float yaw, float pitch, int currentItem, EntityMetadata metadata[]) { + this.entityId = entityId; + this.uuid = uuid; + this.name = name; + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + this.currentItem = currentItem; + this.metadata = metadata; + } + + public int getEntityId() { + return this.entityId; + } + + public String getUUID() { + return this.uuid; + } + + public String getName() { + return this.name; + } + + public double getX() { + return this.x; + } + + public double getY() { + return this.y; + } + + public double getZ() { + return this.z; + } + + public float getYaw() { + return this.yaw; + } + + public float getPitch() { + return this.pitch; + } + + public int getCurrentItem() { + return this.currentItem; + } + + public EntityMetadata[] getMetadata() { + return this.metadata; + } + + @Override + public void read(NetInput in) throws IOException { + this.entityId = in.readVarInt(); + this.uuid = in.readString(); + this.name = in.readString(); + this.x = in.readInt() / 32D; + this.y = in.readInt() / 32D; + this.z = in.readInt() / 32D; + this.yaw = in.readByte() * 360 / 256f; + this.pitch = in.readByte() * 360 / 256f; + this.currentItem = in.readShort(); + this.metadata = NetUtil.readEntityMetadata(in); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeVarInt(this.entityId); + out.writeString(this.uuid); + out.writeString(this.name); + out.writeInt((int) (this.x * 32)); + out.writeInt((int) (this.y * 32)); + out.writeInt((int) (this.z * 32)); + out.writeByte((byte) (this.yaw * 256 / 360)); + out.writeByte((byte) (this.pitch * 256 / 360)); + out.writeShort(this.currentItem); + NetUtil.writeEntityMetadata(out, this.metadata); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerDisplayScoreboardPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerDisplayScoreboardPacket.java new file mode 100644 index 00000000..72b76b3e --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerDisplayScoreboardPacket.java @@ -0,0 +1,53 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.scoreboard; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerDisplayScoreboardPacket implements Packet { + + private Position position; + private String name; + + public ServerDisplayScoreboardPacket() { + } + + public ServerDisplayScoreboardPacket(Position position, String name) { + this.position = position; + this.name = name; + } + + public Position getPosition() { + return this.position; + } + + public String getScoreboardName() { + return this.name; + } + + @Override + public void read(NetInput in) throws IOException { + this.position = Position.values()[in.readByte()]; + this.name = in.readString(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.position.ordinal()); + out.writeString(this.name); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Position { + PLAYER_LIST, + SIDEBAR, + BELOW_NAME; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerScoreboardObjectivePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerScoreboardObjectivePacket.java new file mode 100644 index 00000000..3dc651cb --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerScoreboardObjectivePacket.java @@ -0,0 +1,61 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.scoreboard; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerScoreboardObjectivePacket implements Packet { + + private String name; + private String value; + private Action action; + + public ServerScoreboardObjectivePacket() { + } + + public ServerScoreboardObjectivePacket(String name, String value, Action action) { + this.name = name; + this.value = value; + this.action = action; + } + + public String getName() { + return this.name; + } + + public String getValue() { + return this.value; + } + + public Action getAction() { + return this.action; + } + + @Override + public void read(NetInput in) throws IOException { + this.name = in.readString(); + this.value = in.readString(); + this.action = Action.values()[in.readByte()]; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.name); + out.writeString(this.value); + out.writeByte(this.action.ordinal()); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Action { + ADD, + REMOVE, + UPDATE; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerTeamPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerTeamPacket.java new file mode 100644 index 00000000..4867da9e --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerTeamPacket.java @@ -0,0 +1,142 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.scoreboard; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerTeamPacket implements Packet { + + private String name; + private Action action; + private String displayName; + private String prefix; + private String suffix; + private FriendlyFireMode friendlyFire; + private String players[]; + + public ServerTeamPacket() { + } + + public ServerTeamPacket(String name) { + this.name = name; + this.action = Action.REMOVE; + } + + public ServerTeamPacket(String name, Action action, String players[]) { + if(action != Action.ADD_PLAYER && action != Action.REMOVE_PLAYER) { + throw new IllegalArgumentException("(name, action, players) constructor only valid for adding and removing players."); + } + + this.name = name; + this.action = action; + this.players = players; + } + + public ServerTeamPacket(String name, String displayName, String prefix, String suffix, FriendlyFireMode friendlyFire) { + this.name = name; + this.displayName = displayName; + this.prefix = prefix; + this.suffix = suffix; + this.friendlyFire = friendlyFire; + this.action = Action.UPDATE; + } + + public ServerTeamPacket(String name, String displayName, String prefix, String suffix, FriendlyFireMode friendlyFire, String players[]) { + this.name = name; + this.displayName = displayName; + this.prefix = prefix; + this.suffix = suffix; + this.friendlyFire = friendlyFire; + this.players = players; + this.action = Action.CREATE; + } + + public String getTeamName() { + return this.name; + } + + public Action getAction() { + return this.action; + } + + public String getDisplayName() { + return this.displayName; + } + + public String getPrefix() { + return this.prefix; + } + + public String getSuffix() { + return this.suffix; + } + + public FriendlyFireMode getFriendlyFire() { + return this.friendlyFire; + } + + public String[] getPlayers() { + return this.players; + } + + @Override + public void read(NetInput in) throws IOException { + this.name = in.readString(); + this.action = Action.values()[in.readByte()]; + if(this.action == Action.CREATE || this.action == Action.UPDATE) { + this.displayName = in.readString(); + this.prefix = in.readString(); + this.suffix = in.readString(); + byte friendlyFire = in.readByte(); + this.friendlyFire = friendlyFire == 3 ? FriendlyFireMode.FRIENDLY_INVISIBLES_VISIBLE : FriendlyFireMode.values()[friendlyFire]; + } + + if(this.action == Action.CREATE || this.action == Action.ADD_PLAYER || this.action == Action.REMOVE_PLAYER) { + this.players = new String[in.readShort()]; + for(int index = 0; index < this.players.length; index++) { + this.players[index] = in.readString(); + } + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.name); + out.writeByte(this.action.ordinal()); + if(this.action == Action.CREATE || this.action == Action.UPDATE) { + out.writeString(this.displayName); + out.writeString(this.prefix); + out.writeString(this.suffix); + out.writeByte(this.friendlyFire == FriendlyFireMode.FRIENDLY_INVISIBLES_VISIBLE ? 3 : this.friendlyFire.ordinal()); + } + + if(this.action == Action.CREATE || this.action == Action.ADD_PLAYER || this.action == Action.REMOVE_PLAYER) { + out.writeShort(this.players.length); + for(String player : this.players) { + out.writeString(player); + } + } + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Action { + CREATE, + REMOVE, + UPDATE, + ADD_PLAYER, + REMOVE_PLAYER; + } + + public static enum FriendlyFireMode { + OFF, + ON, + FRIENDLY_INVISIBLES_VISIBLE; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerUpdateScorePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerUpdateScorePacket.java new file mode 100644 index 00000000..bab76b28 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/scoreboard/ServerUpdateScorePacket.java @@ -0,0 +1,77 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.scoreboard; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerUpdateScorePacket implements Packet { + + private String name; + private Action action; + private String scoreName; + private int scoreValue; + + public ServerUpdateScorePacket() { + } + + public ServerUpdateScorePacket(String name) { + this.name = name; + this.action = Action.REMOVE; + } + + public ServerUpdateScorePacket(String name, String scoreName, int scoreValue) { + this.name = name; + this.scoreName = scoreName; + this.scoreValue = scoreValue; + this.action = Action.ADD_OR_UPDATE; + } + + public String getScoreboardName() { + return this.name; + } + + public Action getAction() { + return this.action; + } + + public String getScoreName() { + return this.scoreName; + } + + public int getScoreValue() { + return this.scoreValue; + } + + @Override + public void read(NetInput in) throws IOException { + this.name = in.readString(); + this.action = Action.values()[in.readByte()]; + if(this.action == Action.ADD_OR_UPDATE) { + this.scoreName = in.readString(); + this.scoreValue = in.readInt(); + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.name); + out.writeByte(this.action.ordinal()); + if(this.action == Action.ADD_OR_UPDATE) { + out.writeString(this.scoreName); + out.writeInt(this.scoreValue); + } + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Action { + ADD_OR_UPDATE, + REMOVE; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerCloseWindowPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerCloseWindowPacket.java new file mode 100644 index 00000000..75dfffa1 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerCloseWindowPacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.window; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerCloseWindowPacket implements Packet { + + private int windowId; + + public ServerCloseWindowPacket() { + } + + public ServerCloseWindowPacket(int windowId) { + this.windowId = windowId; + } + + public int getWindowId() { + return this.windowId; + } + + @Override + public void read(NetInput in) throws IOException { + this.windowId = in.readUnsignedByte(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.windowId); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerConfirmTransactionPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerConfirmTransactionPacket.java new file mode 100644 index 00000000..2ca5aede --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerConfirmTransactionPacket.java @@ -0,0 +1,55 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.window; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerConfirmTransactionPacket implements Packet { + + private int windowId; + private int actionId; + private boolean accepted; + + public ServerConfirmTransactionPacket() { + } + + public ServerConfirmTransactionPacket(int windowId, int actionId, boolean accepted) { + this.windowId = windowId; + this.actionId = actionId; + this.accepted = accepted; + } + + public int getWindowId() { + return this.windowId; + } + + public int getActionId() { + return this.actionId; + } + + public boolean getAccepted() { + return this.accepted; + } + + @Override + public void read(NetInput in) throws IOException { + this.windowId = in.readUnsignedByte(); + this.actionId = in.readShort(); + this.accepted = in.readBoolean(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.windowId); + out.writeShort(this.actionId); + out.writeBoolean(this.accepted); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerOpenWindowPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerOpenWindowPacket.java new file mode 100644 index 00000000..1d3edfc7 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerOpenWindowPacket.java @@ -0,0 +1,97 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.window; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerOpenWindowPacket implements Packet { + + private int windowId; + private Type type; + private String name; + private int slots; + private boolean useName; + private int ownerEntityId; + + public ServerOpenWindowPacket() { + } + + public ServerOpenWindowPacket(int windowId, Type type, String name, int slots, boolean useName) { + this(windowId, type, name, slots, useName, 0); + } + + public ServerOpenWindowPacket(int windowId, Type type, String name, int slots, boolean useName, int ownerEntityId) { + this.windowId = windowId; + } + + public int getWindowId() { + return this.windowId; + } + + public Type getType() { + return this.type; + } + + public String getName() { + return this.name; + } + + public int getSlots() { + return this.slots; + } + + public boolean getUseName() { + return this.useName; + } + + public int getOwnerEntityId() { + return this.ownerEntityId; + } + + @Override + public void read(NetInput in) throws IOException { + this.windowId = in.readUnsignedByte(); + this.type = Type.values()[in.readUnsignedByte()]; + this.name = in.readString(); + this.slots = in.readUnsignedByte(); + this.useName = in.readBoolean(); + if(this.type == Type.HORSE_INVENTORY) { + this.ownerEntityId = in.readInt(); + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.windowId); + out.writeByte(this.type.ordinal()); + out.writeString(this.name); + out.writeByte(this.slots); + out.writeBoolean(this.useName); + if(this.type == Type.HORSE_INVENTORY) { + out.writeInt(this.ownerEntityId); + } + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Type { + CHEST, + CRAFTING_TABLE, + FURNACE, + DISPENSER, + ENCHANTMENT_TABLE, + BREWING_STAND, + VILLAGER_TRADE, + BEACON, + ANVIL, + HOPPER, + DROPPER, + HORSE_INVENTORY; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerSetSlotPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerSetSlotPacket.java new file mode 100644 index 00000000..99ba3dca --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerSetSlotPacket.java @@ -0,0 +1,57 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.window; + +import java.io.IOException; + +import ch.spacebase.mc.protocol.data.game.ItemStack; +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerSetSlotPacket implements Packet { + + private int windowId; + private int slot; + private ItemStack item; + + public ServerSetSlotPacket() { + } + + public ServerSetSlotPacket(int windowId, int slot, ItemStack item) { + this.windowId = windowId; + this.slot = slot; + this.item = item; + } + + public int getWindowId() { + return this.windowId; + } + + public int getSlot() { + return this.slot; + } + + public ItemStack getItem() { + return this.item; + } + + @Override + public void read(NetInput in) throws IOException { + this.windowId = in.readUnsignedByte(); + this.slot = in.readShort(); + this.item = NetUtil.readItem(in); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.windowId); + out.writeShort(this.slot); + NetUtil.writeItem(out, this.item); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerWindowItemsPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerWindowItemsPacket.java new file mode 100644 index 00000000..7b26e966 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerWindowItemsPacket.java @@ -0,0 +1,55 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.window; + +import java.io.IOException; + +import ch.spacebase.mc.protocol.data.game.ItemStack; +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerWindowItemsPacket implements Packet { + + private int windowId; + private ItemStack items[]; + + public ServerWindowItemsPacket() { + } + + public ServerWindowItemsPacket(int windowId, ItemStack items[]) { + this.windowId = windowId; + this.items = items; + } + + public int getWindowId() { + return this.windowId; + } + + public ItemStack[] getItems() { + return this.items; + } + + @Override + public void read(NetInput in) throws IOException { + this.windowId = in.readUnsignedByte(); + this.items = new ItemStack[in.readShort()]; + for(int index = 0; index < this.items.length; index++) { + this.items[index] = NetUtil.readItem(in); + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.windowId); + out.writeShort(this.items.length); + for(ItemStack item : this.items) { + NetUtil.writeItem(out, item); + } + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerWindowPropertyPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerWindowPropertyPacket.java new file mode 100644 index 00000000..52d054e4 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/window/ServerWindowPropertyPacket.java @@ -0,0 +1,64 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.window; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerWindowPropertyPacket implements Packet { + + private int windowId; + private int property; + private int value; + + public ServerWindowPropertyPacket() { + } + + public ServerWindowPropertyPacket(int windowId, int property, int value) { + this.windowId = windowId; + this.property = property; + this.value = value; + } + + public int getWindowId() { + return this.windowId; + } + + public int getProperty() { + return this.property; + } + + public int getValue() { + return this.value; + } + + @Override + public void read(NetInput in) throws IOException { + this.windowId = in.readUnsignedByte(); + this.property = in.readShort(); + this.value = in.readShort(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.windowId); + out.writeShort(this.property); + out.writeShort(this.value); + } + + @Override + public boolean isPriority() { + return false; + } + + public static class Property { + public static final int FURNACE_PROGRESS = 0; + public static final int FURNACE_FUEL = 1; + + public static final int ENCHANTMENT_SLOT_1 = 0; + public static final int ENCHANTMENT_SLOT_2 = 1; + public static final int ENCHANTMENT_SLOT_3 = 2; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerBlockBreakAnimPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerBlockBreakAnimPacket.java new file mode 100644 index 00000000..72398992 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerBlockBreakAnimPacket.java @@ -0,0 +1,84 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerBlockBreakAnimPacket implements Packet { + + private int breakerEntityId; + private int x; + private int y; + private int z; + private Stage stage; + + public ServerBlockBreakAnimPacket() { + } + + public ServerBlockBreakAnimPacket(int breakerEntityId, int x, int y, int z, Stage stage) { + this.breakerEntityId = breakerEntityId; + this.x = x; + this.y = y; + this.z = z; + this.stage = stage; + } + + public int getBreakerEntityId() { + return this.breakerEntityId; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public Stage getStage() { + return this.stage; + } + + @Override + public void read(NetInput in) throws IOException { + this.breakerEntityId = in.readVarInt(); + this.x = in.readInt(); + this.y = in.readInt(); + this.z = in.readInt(); + this.stage = Stage.values()[in.readByte()]; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeVarInt(this.breakerEntityId); + out.writeInt(this.x); + out.writeInt(this.y); + out.writeInt(this.z); + out.writeByte(this.stage.ordinal()); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Stage { + STAGE_1, + STAGE_2, + STAGE_3, + STAGE_4, + STAGE_5, + STAGE_6, + STAGE_7, + STAGE_8, + STAGE_9, + STAGE_10; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerBlockChangePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerBlockChangePacket.java new file mode 100644 index 00000000..3e2a5def --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerBlockChangePacket.java @@ -0,0 +1,44 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.mc.protocol.data.game.BlockChangeRecord; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerBlockChangePacket implements Packet { + + private BlockChangeRecord record; + + public ServerBlockChangePacket() { + } + + public ServerBlockChangePacket(BlockChangeRecord record) { + this.record = record; + } + + public BlockChangeRecord getRecord() { + return this.record; + } + + @Override + public void read(NetInput in) throws IOException { + this.record = new BlockChangeRecord(in.readInt(), in.readUnsignedByte(), in.readInt(), in.readVarInt(), in.readUnsignedByte()); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.record.getX()); + out.writeByte(this.record.getY()); + out.writeInt(this.record.getZ()); + out.writeVarInt(this.record.getId()); + out.writeByte(this.record.getMetadata()); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerBlockValuePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerBlockValuePacket.java new file mode 100644 index 00000000..6d20fde2 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerBlockValuePacket.java @@ -0,0 +1,279 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerBlockValuePacket implements Packet { + + private static final int NOTE_BLOCK = 25; + private static final int STICKY_PISTON = 29; + private static final int PISTON = 33; + private static final int MOB_SPAWNER = 52; + private static final int CHEST = 54; + private static final int ENDER_CHEST = 130; + private static final int TRAPPED_CHEST = 146; + + private int x; + private int y; + private int z; + private ValueType type; + private Value value; + private int blockId; + + public ServerBlockValuePacket() { + } + + public ServerBlockValuePacket(int x, int y, int z, ValueType type, Value value, int blockId) { + this.x = x; + this.y = y; + this.z = z; + this.type = type; + this.value = value; + this.blockId = blockId; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public ValueType getType() { + return this.type; + } + + public Value getValue() { + return this.value; + } + + public int getBlockId() { + return this.blockId; + } + + @Override + public void read(NetInput in) throws IOException { + this.x = in.readInt(); + this.y = in.readShort(); + this.z = in.readInt(); + this.type = intToType(in.readUnsignedByte()); + this.value = intToValue(in.readUnsignedByte()); + this.blockId = in.readVarInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.x); + out.writeShort(this.y); + out.writeInt(this.z); + out.writeByte(typeToInt(this.type)); + out.writeByte(valueToInt(this.value)); + out.writeVarInt(this.blockId); + } + + @Override + public boolean isPriority() { + return false; + } + + private ValueType intToType(int value) throws IOException { + if(this.blockId == NOTE_BLOCK) { + if(value == 0) { + return NoteBlockValueType.HARP; + } else if(value == 1) { + return NoteBlockValueType.DOUBLE_BASS; + } else if(value == 2) { + return NoteBlockValueType.SNARE_DRUM; + } else if(value == 3) { + return NoteBlockValueType.HI_HAT; + } else if(value == 4) { + return NoteBlockValueType.BASS_DRUM; + } + } else if(this.blockId == STICKY_PISTON || this.blockId == PISTON) { + if(value == 0) { + return PistonValueType.PUSHING; + } else if(value == 1) { + return PistonValueType.PULLING; + } + } else if(this.blockId == MOB_SPAWNER) { + if(value == 1) { + return MobSpawnerValueType.RESET_DELAY; + } + } else if(this.blockId == CHEST || this.blockId == ENDER_CHEST || this.blockId == TRAPPED_CHEST) { + if(value == 1) { + return ChestValueType.VIEWING_PLAYER_COUNT; + } + } else { + throw new IOException("Unknown value type for block id: " + this.blockId); + } + + throw new IOException("Unknown value type id: " + value + ", " + this.blockId); + } + + private int typeToInt(ValueType type) throws IOException { + if(type == NoteBlockValueType.HARP) { + return 0; + } else if(type == NoteBlockValueType.DOUBLE_BASS) { + return 1; + } else if(type == NoteBlockValueType.SNARE_DRUM) { + return 2; + } else if(type == NoteBlockValueType.HI_HAT) { + return 3; + } else if(type == NoteBlockValueType.BASS_DRUM) { + return 4; + } + + if(type == PistonValueType.PUSHING) { + return 0; + } else if(type == PistonValueType.PULLING) { + return 1; + } + + if(type == MobSpawnerValueType.RESET_DELAY) { + return 1; + } + + if(type == ChestValueType.VIEWING_PLAYER_COUNT) { + return 1; + } + + throw new IOException("Unmapped value type: " + type); + } + + private Value intToValue(int value) throws IOException { + if(this.blockId == NOTE_BLOCK) { + return new NoteBlockValue(value); + } else if(this.blockId == STICKY_PISTON || this.blockId == PISTON) { + if(value == 0) { + return PistonValue.DOWN; + } else if(value == 1) { + return PistonValue.UP; + } else if(value == 2) { + return PistonValue.SOUTH; + } else if(value == 3) { + return PistonValue.WEST; + } else if(value == 4) { + return PistonValue.NORTH; + } else if(value == 5) { + return PistonValue.EAST; + } + } else if(this.blockId == MOB_SPAWNER) { + if(value == 0) { + return MobSpawnerValue.VALUE; + } + } else if(this.blockId == CHEST || this.blockId == ENDER_CHEST || this.blockId == TRAPPED_CHEST) { + return new ChestValue(value); + } else { + throw new IOException("Unknown value for block id: " + this.blockId); + } + + throw new IOException("Unknown value id: " + value + ", " + this.blockId); + } + + private int valueToInt(Value value) throws IOException { + if(value instanceof NoteBlockValue) { + return ((NoteBlockValue) value).getPitch(); + } + + if(value == PistonValue.DOWN) { + return 0; + } else if(value == PistonValue.UP) { + return 1; + } else if(value == PistonValue.SOUTH) { + return 2; + } else if(value == PistonValue.WEST) { + return 3; + } else if(value == PistonValue.NORTH) { + return 4; + } else if(value == PistonValue.EAST) { + return 5; + } + + if(value == MobSpawnerValue.VALUE) { + return 0; + } + + if(value instanceof ChestValue) { + return ((ChestValue) value).getViewers(); + } + + throw new IOException("Unmapped value: " + value); + } + + public static interface ValueType { + } + + public static enum NoteBlockValueType implements ValueType { + HARP, + DOUBLE_BASS, + SNARE_DRUM, + HI_HAT, + BASS_DRUM; + } + + public static enum PistonValueType implements ValueType { + PUSHING, + PULLING; + } + + public static enum ChestValueType implements ValueType { + VIEWING_PLAYER_COUNT; + } + + public static enum MobSpawnerValueType implements ValueType { + RESET_DELAY; + } + + public static interface Value { + } + + public static class NoteBlockValue implements Value { + private int pitch; + + public NoteBlockValue(int pitch) { + if(pitch < 0 || pitch > 24) { + throw new IllegalArgumentException("Pitch must be between 0 and 24."); + } + + this.pitch = pitch; + } + + public int getPitch() { + return this.pitch; + } + } + + public static enum PistonValue implements Value { + DOWN, + UP, + SOUTH, + WEST, + NORTH, + EAST; + } + + public static class ChestValue implements Value { + private int viewers; + + public ChestValue(int viewers) { + this.viewers = viewers; + } + + public int getViewers() { + return this.viewers; + } + } + + public static enum MobSpawnerValue implements Value { + VALUE; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerChunkDataPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerChunkDataPacket.java new file mode 100644 index 00000000..504fd0a5 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerChunkDataPacket.java @@ -0,0 +1,147 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; +import java.util.zip.DataFormatException; +import java.util.zip.Deflater; +import java.util.zip.Inflater; + +import ch.spacebase.mc.protocol.data.game.Chunk; +import ch.spacebase.mc.util.ParsedChunkData; +import ch.spacebase.mc.util.NetworkChunkData; +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerChunkDataPacket implements Packet { + + private Chunk chunks[]; + private byte biomeData[]; + + public ServerChunkDataPacket() { + } + + public ServerChunkDataPacket(Chunk chunks[]) { + this(chunks, null); + } + + public ServerChunkDataPacket(Chunk chunks[], byte biomeData[]) { + if(chunks.length != 16) { + throw new IllegalArgumentException("Chunks length must be 16."); + } + + int x = 0; + int z = 0; + boolean hasCoords = false; + boolean noSkylight = false; + boolean skylight = false; + for(int index = 0; index < chunks.length; index++) { + if(chunks[index] != null) { + if(!hasCoords) { + x = chunks[index].getX(); + z = chunks[index].getZ(); + hasCoords = true; + } else if(chunks[index].getX() != x || chunks[index].getZ() != z) { + throw new IllegalArgumentException("Chunks must all have the same coords."); + } + + if(chunks[index].getSkyLight() == null) { + noSkylight = true; + } else { + skylight = true; + } + } else if(biomeData != null) { + throw new IllegalArgumentException("Chunks must contain all 16 chunks in a column if biomeData is not null."); + } + } + + if(noSkylight && skylight) { + throw new IllegalArgumentException("Either all chunks must have skylight values or none must have them."); + } + + this.chunks = chunks; + this.biomeData = biomeData; + } + + public Chunk[] getChunks() { + return this.chunks; + } + + public boolean hasBiomeData() { + return this.biomeData != null; + } + + public byte[] getBiomeData() { + return this.biomeData; + } + + @Override + public void read(NetInput in) throws IOException { + // Read column data. + int x = in.readInt(); + int z = in.readInt(); + boolean biomes = in.readBoolean(); + int chunkMask = in.readShort(); + int extendedChunkMask = in.readShort(); + byte deflated[] = in.readBytes(in.readInt()); + // Determine inflated data length. + int chunkCount = 0; + for(int count = 0; count < 16; count++) { + chunkCount += chunkMask >> count & 1; + } + + int len = 12288 * chunkCount; + if(biomes) { + len += 256; + } + + byte data[] = new byte[len]; + // Inflate chunk data. + Inflater inflater = new Inflater(); + inflater.setInput(deflated, 0, deflated.length); + try { + inflater.inflate(data); + } catch(DataFormatException e) { + throw new IOException("Bad compressed data format"); + } finally { + inflater.end(); + } + + // Parse data into chunks and biome data. + ParsedChunkData chunkData = NetUtil.dataToChunks(new NetworkChunkData(x, z, chunkMask, extendedChunkMask, biomes, NetUtil.hasSky, data)); + this.chunks = chunkData.getChunks(); + this.biomeData = chunkData.getBiomes(); + } + + @Override + public void write(NetOutput out) throws IOException { + // Parse chunks into data. + NetworkChunkData data = NetUtil.chunksToData(new ParsedChunkData(this.chunks, this.biomeData)); + // Deflate chunk data. + Deflater deflater = new Deflater(-1); + byte deflated[] = new byte[data.getData().length]; + int len = data.getData().length; + try { + deflater.setInput(data.getData(), 0, data.getData().length); + deflater.finish(); + len = deflater.deflate(deflated); + } finally { + deflater.end(); + } + + // Write data to the network. + out.writeInt(data.getX()); + out.writeInt(data.getZ()); + out.writeBoolean(data.hasBiomes()); + out.writeShort(data.getMask()); + out.writeShort(data.getExtendedMask()); + out.writeInt(len); + out.writeBytes(deflated, len); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerExplosionPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerExplosionPacket.java new file mode 100644 index 00000000..c1071a6d --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerExplosionPacket.java @@ -0,0 +1,132 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerExplosionPacket implements Packet { + + private float x; + private float y; + private float z; + private float radius; + private List exploded; + private float pushX; + private float pushY; + private float pushZ; + + public ServerExplosionPacket() { + } + + public ServerExplosionPacket(float x, float y, float z, float radius, List exploded, float pushX, float pushY, float pushZ) { + this.x = x; + this.y = y; + this.z = z; + this.radius = radius; + this.exploded = exploded; + this.pushX = pushX; + this.pushY = pushY; + this.pushZ = pushZ; + } + + public float getX() { + return this.x; + } + + public float getY() { + return this.y; + } + + public float getZ() { + return this.z; + } + + public float getRadius() { + return this.radius; + } + + public List getExploded() { + return this.exploded; + } + + public float getPushX() { + return this.pushX; + } + + public float getPushY() { + return this.pushY; + } + + public float getPushZ() { + return this.pushZ; + } + + @Override + public void read(NetInput in) throws IOException { + this.x = in.readFloat(); + this.y = in.readFloat(); + this.z = in.readFloat(); + this.radius = in.readFloat(); + this.exploded = new ArrayList(); + int length = in.readInt(); + for(int count = 0; count < length; count++) { + this.exploded.add(new ExplodedBlockRecord(in.readByte(), in.readByte(), in.readByte())); + } + + this.pushX = in.readFloat(); + this.pushY = in.readFloat(); + this.pushZ = in.readFloat(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeFloat(this.x); + out.writeFloat(this.y); + out.writeFloat(this.z); + out.writeFloat(this.radius); + out.writeInt(this.exploded.size()); + for(ExplodedBlockRecord record : this.exploded) { + out.writeByte(record.getX()); + out.writeByte(record.getY()); + out.writeByte(record.getZ()); + } + + out.writeFloat(this.pushX); + out.writeFloat(this.pushY); + out.writeFloat(this.pushZ); + } + + @Override + public boolean isPriority() { + return false; + } + + public static class ExplodedBlockRecord { + private int x; + private int y; + private int z; + + public ExplodedBlockRecord(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerMapDataPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerMapDataPacket.java new file mode 100644 index 00000000..c98dd052 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerMapDataPacket.java @@ -0,0 +1,219 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerMapDataPacket implements Packet { + + private int mapId; + private Type type; + private MapData data; + + public ServerMapDataPacket() { + } + + public ServerMapDataPacket(int mapId, Type type, MapData data) { + this.mapId = mapId; + this.type = type; + this.data = data; + } + + public int getMapId() { + return this.mapId; + } + + public Type getType() { + return this.type; + } + + public MapData getData() { + return this.data; + } + + @Override + public void read(NetInput in) throws IOException { + this.mapId = in.readVarInt(); + byte data[] = in.readBytes(in.readShort()); + this.type = Type.values()[data[0]]; + switch(this.type) { + case IMAGE: + byte x = data[1]; + byte y = data[2]; + byte height = (byte) (data.length - 3); + byte colors[] = new byte[height]; + for(int index = 0; index < height; index++) { + colors[index] = data[index + 3]; + } + + this.data = new MapColumnUpdate(x, y, height, colors); + break; + case PLAYERS: + List players = new ArrayList(); + for(int index = 0; index < (data.length - 1) / 3; index++) { + byte iconSize = (byte) (data[index * 3 + 1] >> 4); + byte iconRotation = (byte) (data[index * 3 + 1] & 15); + byte centerX = data[index * 3 + 2]; + byte centerY = data[index * 3 + 3]; + players.add(new MapPlayer(iconSize, iconRotation, centerX, centerY)); + } + + this.data = new MapPlayers(players); + break; + case SCALE: + this.data = new MapScale(data[1]); + break; + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeVarInt(this.mapId); + byte data[] = null; + switch(this.type) { + case IMAGE: + MapColumnUpdate column = (MapColumnUpdate) this.data; + data = new byte[column.getHeight() + 4]; + data[0] = 0; + data[1] = column.getX(); + data[2] = column.getY(); + + for(int index = 0; index < data.length - 3; index++) { + data[index + 3] = column.getColors()[index]; + } + + break; + case PLAYERS: + MapPlayers players = (MapPlayers) this.data; + data = new byte[players.getPlayers().size() * 3 + 1]; + data[0] = 1; + for(int index = 0; index < players.getPlayers().size(); index++) { + MapPlayer player = players.getPlayers().get(index); + data[index * 3 + 1] = (byte) (player.getIconSize() << 4 | player.getIconRotation() & 15); + data[index * 3 + 2] = player.getCenterX(); + data[index * 3 + 3] = player.getCenterZ(); + } + + break; + case SCALE: + MapScale scale = (MapScale) this.data; + data = new byte[2]; + data[0] = 2; + data[1] = scale.getScale(); + break; + } + + out.writeShort(data.length); + out.writeBytes(data); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Type { + IMAGE, + PLAYERS, + SCALE; + } + + public static interface MapData { + } + + public static class MapColumnUpdate implements MapData { + private byte x; + private byte y; + private byte height; + private byte colors[]; + + /** + * Creates a new map column update instance. + * @param x X of the map column. + * @param y Y of the data's update range. + * @param height Height of the data's update range. + * @param fullMapColors The full array of map color data, arranged in order of ascending Y value relative to the given Y value. + */ + public MapColumnUpdate(int x, int y, int height, byte colors[]) { + this.x = (byte) x; + this.y = (byte) y; + this.height = (byte) height; + this.colors = colors; + } + + public byte getX() { + return this.x; + } + + public byte getY() { + return this.y; + } + + public byte getHeight() { + return this.height; + } + + public byte[] getColors() { + return this.colors; + } + } + + public static class MapPlayers implements MapData { + private List players = new ArrayList(); + + public MapPlayers(List players) { + this.players = players; + } + + public List getPlayers() { + return new ArrayList(this.players); + } + } + + public static class MapPlayer { + private byte iconSize; + private byte iconRotation; + private byte centerX; + private byte centerZ; + + public MapPlayer(int iconSize, int iconRotation, int centerX, int centerZ) { + this.iconSize = (byte) iconSize; + this.iconRotation = (byte) iconRotation; + this.centerX = (byte) centerX; + this.centerZ = (byte) centerZ; + } + + public byte getIconSize() { + return this.iconSize; + } + + public byte getIconRotation() { + return this.iconRotation; + } + + public byte getCenterX() { + return this.centerX; + } + + public byte getCenterZ() { + return this.centerZ; + } + } + + public static class MapScale implements MapData { + private byte scale; + + public MapScale(int scale) { + this.scale = (byte) scale; + } + + public byte getScale() { + return this.scale; + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerMultiBlockChangePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerMultiBlockChangePacket.java new file mode 100644 index 00000000..d0eb7b9b --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerMultiBlockChangePacket.java @@ -0,0 +1,66 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.mc.protocol.data.game.BlockChangeRecord; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerMultiBlockChangePacket implements Packet { + + private BlockChangeRecord records[]; + + public ServerMultiBlockChangePacket() { + } + + public ServerMultiBlockChangePacket(BlockChangeRecord... records) { + if(records == null || records.length == 0) { + throw new IllegalArgumentException("Records must contain at least 1 value."); + } + + this.records = records; + } + + public BlockChangeRecord[] getRecords() { + return this.records; + } + + @Override + public void read(NetInput in) throws IOException { + int chunkX = in.readInt(); + int chunkZ = in.readInt(); + this.records = new BlockChangeRecord[in.readShort()]; + in.readInt(); // Unneeded size variable + for(int index = 0; index < this.records.length; index++) { + short coords = in.readShort(); + short block = in.readShort(); + int x = (chunkX << 4) + (coords >> 12 & 15); + int y = coords & 255; + int z = (chunkZ << 4) + (coords >> 8 & 15); + int id = block >> 4 & 4095; + int metadata = block & 15; + this.records[index] = new BlockChangeRecord(x, y, z, id, metadata); + } + } + + @Override + public void write(NetOutput out) throws IOException { + int chunkX = this.records[0].getX() >> 4; + int chunkZ = this.records[0].getZ() >> 4; + out.writeInt(chunkX); + out.writeInt(chunkZ); + out.writeShort(this.records.length); + out.writeInt(this.records.length * 4); + for(BlockChangeRecord record : this.records) { + out.writeShort((record.getX() - (chunkX << 4)) << 12 | (record.getZ() - (chunkZ << 4)) << 8 | record.getY()); + out.writeShort((record.getId() & 4095) << 4 | record.getMetadata() & 15); + } + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerMultiChunkDataPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerMultiChunkDataPacket.java new file mode 100644 index 00000000..c249ab3f --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerMultiChunkDataPacket.java @@ -0,0 +1,199 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; +import java.util.zip.DataFormatException; +import java.util.zip.Deflater; +import java.util.zip.Inflater; + +import ch.spacebase.mc.protocol.data.game.Chunk; +import ch.spacebase.mc.util.ParsedChunkData; +import ch.spacebase.mc.util.NetworkChunkData; +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerMultiChunkDataPacket implements Packet { + + private Chunk chunks[][]; + private byte biomeData[][]; + + public ServerMultiChunkDataPacket() { + } + + public ServerMultiChunkDataPacket(Chunk chunks[][], byte biomeData[][]) { + if(biomeData == null) { + throw new IllegalArgumentException("BiomeData cannot be null."); + } + + boolean noSkylight = false; + boolean skylight = false; + for(int index = 0; index < chunks.length; index++) { + Chunk column[] = chunks[index]; + if(column.length != 16) { + throw new IllegalArgumentException("Chunk columns must contain 16 chunks each."); + } + + int x = 0; + int z = 0; + boolean hasCoords = false; + for(int y = 0; y < column.length; y++) { + if(column[y] == null) { + throw new IllegalArgumentException("Chunk column must contain all 16 chunks."); + } + + if(!hasCoords) { + x = column[y].getX(); + z = column[y].getZ(); + hasCoords = true; + } else if(column[y].getX() != x || column[y].getZ() != z) { + throw new IllegalArgumentException("Chunks in a column must all have the same coords."); + } + + if(column[y].getSkyLight() == null) { + noSkylight = true; + } else { + skylight = true; + } + } + } + + if(noSkylight && skylight) { + throw new IllegalArgumentException("Either all chunks must have skylight values or none must have them."); + } + + this.chunks = chunks; + this.biomeData = biomeData; + } + + public int getColumns() { + return this.chunks.length; + } + + public Chunk[] getChunks(int column) { + return this.chunks[column]; + } + + public byte[] getBiomeData(int column) { + return this.biomeData[column]; + } + + @Override + public void read(NetInput in) throws IOException { + // Read packet base data. + short columns = in.readShort(); + int deflatedLength = in.readInt(); + boolean skylight = in.readBoolean(); + byte deflatedBytes[] = in.readBytes(deflatedLength); + // Inflate chunk data. + byte[] inflated = new byte[196864 * columns]; + Inflater inflater = new Inflater(); + inflater.setInput(deflatedBytes, 0, deflatedLength); + try { + inflater.inflate(inflated); + } catch(DataFormatException e) { + throw new IOException("Bad compressed data format"); + } finally { + inflater.end(); + } + + this.chunks = new Chunk[columns][]; + this.biomeData = new byte[columns][]; + // Cycle through and read all columns. + int pos = 0; + for(int count = 0; count < columns; count++) { + // Read column-specific data. + int x = in.readInt(); + int z = in.readInt(); + int chunkMask = in.readShort(); + int extendedChunkMask = in.readShort(); + // Determine column data length. + int chunks = 0; + int extended = 0; + for(int ch = 0; ch < 16; ch++) { + chunks += chunkMask >> ch & 1; + extended += extendedChunkMask >> ch & 1; + } + + int length = (8192 * chunks + 256) + (2048 * extended); + if(skylight) { + length += 2048 * chunks; + } + + // Copy column data into a new array. + byte dat[] = new byte[length]; + System.arraycopy(inflated, pos, dat, 0, length); + // Read data into chunks and biome data. + ParsedChunkData chunkData = NetUtil.dataToChunks(new NetworkChunkData(x, z, chunkMask, extendedChunkMask, true, skylight, dat)); + this.chunks[count] = chunkData.getChunks(); + this.biomeData[count] = chunkData.getBiomes(); + pos += length; + } + } + + @Override + public void write(NetOutput out) throws IOException { + // Prepare chunk data arrays. + int x[] = new int[this.chunks.length]; + int z[] = new int[this.chunks.length]; + int chunkMask[] = new int[this.chunks.length]; + int extendedChunkMask[] = new int[this.chunks.length]; + // Determine values to be written by cycling through columns. + int pos = 0; + byte bytes[] = new byte[0]; + boolean skylight = false; + for(int count = 0; count < this.chunks.length; ++count) { + Chunk column[] = this.chunks[count]; + // Convert chunks into network data. + NetworkChunkData netData = NetUtil.chunksToData(new ParsedChunkData(column, this.biomeData[count])); + if(bytes.length < pos + netData.getData().length) { + byte[] newArray = new byte[pos + netData.getData().length]; + System.arraycopy(bytes, 0, newArray, 0, bytes.length); + bytes = newArray; + } + + if(netData.hasSkyLight()) { + skylight = true; + } + + // Copy column data into data array. + System.arraycopy(netData.getData(), 0, bytes, pos, netData.getData().length); + pos += netData.getData().length; + // Set column-specific values. + x[count] = netData.getX(); + z[count] = netData.getZ(); + chunkMask[count] = netData.getMask(); + extendedChunkMask[count] = netData.getExtendedMask(); + } + + // Deflate chunk data. + Deflater deflater = new Deflater(-1); + byte deflatedData[] = new byte[pos]; + int deflatedLength = pos; + try { + deflater.setInput(bytes, 0, pos); + deflater.finish(); + deflatedLength = deflater.deflate(deflatedData); + } finally { + deflater.end(); + } + + // Write data to the network. + out.writeShort(this.chunks.length); + out.writeInt(deflatedLength); + out.writeBoolean(skylight); + out.writeBytes(deflatedData, deflatedLength); + for(int count = 0; count < this.chunks.length; ++count) { + out.writeInt(x[count]); + out.writeInt(z[count]); + out.writeShort((short) (chunkMask[count] & 65535)); + out.writeShort((short) (extendedChunkMask[count] & 65535)); + } + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerNotifyClientPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerNotifyClientPacket.java new file mode 100644 index 00000000..58c3a069 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerNotifyClientPacket.java @@ -0,0 +1,168 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerNotifyClientPacket implements Packet { + + private Notification notification; + private NotificationValue value; + + public ServerNotifyClientPacket() { + } + + public ServerNotifyClientPacket(NotificationValue value) { + this.value = value; + } + + public NotificationValue getValue() { + return this.value; + } + + @Override + public void read(NetInput in) throws IOException { + this.notification = Notification.values()[in.readUnsignedByte()]; + this.value = this.floatToValue(in.readFloat()); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeByte(this.notification.ordinal()); + out.writeFloat(this.valueToFloat(this.value)); + } + + @Override + public boolean isPriority() { + return false; + } + + private NotificationValue floatToValue(float f) { + if(this.notification == Notification.CHANGE_GAMEMODE) { + if(f == 0) { + return GameModeValue.SURVIVAL; + } else if(f == 1) { + return GameModeValue.CREATIVE; + } else if(f == 2) { + return GameModeValue.ADVENTURE; + } + } else if(this.notification == Notification.DEMO_MESSAGE) { + if(f == 0) { + return DemoMessageValue.WELCOME; + } else if(f == 101) { + return DemoMessageValue.MOVEMENT_CONTROLS; + } else if(f == 102) { + return DemoMessageValue.JUMP_CONTROL; + } else if(f == 103) { + return DemoMessageValue.INVENTORY_CONTROL; + } + } else if(this.notification == Notification.RAIN_STRENGTH) { + return new RainStrengthValue((int) f); + } else if(this.notification == Notification.THUNDER_STRENGTH) { + return new ThunderStrengthValue((int) f); + } + + return null; + } + + private float valueToFloat(NotificationValue value) { + if(value == GameModeValue.SURVIVAL) { + return 0; + } else if(value == GameModeValue.CREATIVE) { + return 1; + } else if(value == GameModeValue.ADVENTURE) { + return 2; + } + + if(value == DemoMessageValue.WELCOME) { + return 0; + } else if(value == DemoMessageValue.MOVEMENT_CONTROLS) { + return 101; + } else if(value == DemoMessageValue.JUMP_CONTROL) { + return 102; + } else if(value == DemoMessageValue.INVENTORY_CONTROL) { + return 103; + } + + if(value instanceof RainStrengthValue) { + return ((RainStrengthValue) value).getStrength(); + } + + if(value instanceof ThunderStrengthValue) { + return ((ThunderStrengthValue) value).getStrength(); + } + + return 0; + } + + public static enum Notification { + INVALID_BED, + START_RAIN, + STOP_RAIN, + CHANGE_GAMEMODE, + ENTER_CREDITS, + DEMO_MESSAGE, + ARROW_HIT_PLAYER, + RAIN_STRENGTH, + THUNDER_STRENGTH; + } + + public static interface NotificationValue { + } + + public static enum GameModeValue implements NotificationValue { + SURVIVAL, + CREATIVE, + ADVENTURE; + } + + public static enum DemoMessageValue implements NotificationValue { + WELCOME, + MOVEMENT_CONTROLS, + JUMP_CONTROL, + INVENTORY_CONTROL; + } + + public static class RainStrengthValue implements NotificationValue { + private float strength; + + public RainStrengthValue(float strength) { + if(strength > 1) { + strength = 1; + } + + if(strength < 0) { + strength = 0; + } + + this.strength = strength; + } + + public float getStrength() { + return this.strength; + } + } + + public static class ThunderStrengthValue implements NotificationValue { + private float strength; + + public ThunderStrengthValue(float strength) { + if(strength > 1) { + strength = 1; + } + + if(strength < 0) { + strength = 0; + } + + this.strength = strength; + } + + public float getStrength() { + return this.strength; + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerOpenTileEntityEditorPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerOpenTileEntityEditorPacket.java new file mode 100644 index 00000000..8e49c8c6 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerOpenTileEntityEditorPacket.java @@ -0,0 +1,55 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerOpenTileEntityEditorPacket implements Packet { + + private int x; + private int y; + private int z; + + public ServerOpenTileEntityEditorPacket() { + } + + public ServerOpenTileEntityEditorPacket(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + @Override + public void read(NetInput in) throws IOException { + this.x = in.readInt(); + this.y = in.readInt(); + this.z = in.readInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.x); + out.writeInt(this.y); + out.writeInt(this.z); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerPlayEffectPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerPlayEffectPacket.java new file mode 100644 index 00000000..3b9a3dcb --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerPlayEffectPacket.java @@ -0,0 +1,384 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerPlayEffectPacket implements Packet { + + private Effect effect; + private int x; + private int y; + private int z; + private EffectData data; + private boolean broadcast; + + public ServerPlayEffectPacket() { + } + + public ServerPlayEffectPacket(Effect effect, int x, int y, int z, EffectData data) { + this(effect, x, y, z, data, false); + } + + public ServerPlayEffectPacket(Effect effect, int x, int y, int z, EffectData data, boolean broadcast) { + this.effect = effect; + this.x = x; + this.y = y; + this.z = z; + this.data = data; + this.broadcast = broadcast; + } + + public Effect getEffect() { + return this.effect; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public EffectData getData() { + return this.data; + } + + public boolean getBroadcast() { + return this.broadcast; + } + + @Override + public void read(NetInput in) throws IOException { + this.effect = this.idToEffect(in.readInt()); + this.x = in.readInt(); + this.y = in.readUnsignedByte(); + this.z = in.readInt(); + this.data = this.valueToData(in.readInt()); + this.broadcast = in.readBoolean(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.effectToId(this.effect)); + out.writeInt(this.x); + out.writeByte(this.y); + out.writeInt(this.z); + out.writeInt(this.dataToValue(this.data)); + out.writeBoolean(this.broadcast); + } + + @Override + public boolean isPriority() { + return false; + } + + private Effect idToEffect(int id) throws IOException { + switch(id) { + case 1000: + return SoundEffect.CLICK; + case 1001: + return SoundEffect.EMPTY_DISPENSER_CLICK; + case 1002: + return SoundEffect.FIRE_PROJECTILE; + case 1003: + return SoundEffect.DOOR; + case 1004: + return SoundEffect.FIZZLE; + case 1005: + return SoundEffect.PLAY_RECORD; + case 1007: + return SoundEffect.GHAST_CHARGE; + case 1008: + return SoundEffect.GHAST_FIRE; + case 1009: + return SoundEffect.BLAZE_FIRE; + case 1010: + return SoundEffect.POUND_WOODEN_DOOR; + case 1011: + return SoundEffect.POUND_METAL_DOOR; + case 1012: + return SoundEffect.BREAK_WOODEN_DOOR; + case 1014: + return SoundEffect.WITHER_SHOOT; + case 1015: + return SoundEffect.BAT_TAKE_OFF; + case 1016: + return SoundEffect.INFECT_VILLAGER; + case 1017: + return SoundEffect.DISINFECT_VILLAGER; + case 1018: + return SoundEffect.ENDER_DRAGON_DEATH; + case 1020: + return SoundEffect.ANVIL_BREAK; + case 1021: + return SoundEffect.ANVIL_USE; + case 1022: + return SoundEffect.ANVIL_LAND; + } + + switch(id) { + case 2000: + return ParticleEffect.SMOKE; + case 2001: + return ParticleEffect.BREAK_BLOCK; + case 2002: + return ParticleEffect.BREAK_SPLASH_POTION; + case 2003: + return ParticleEffect.BREAK_EYE_OF_ENDER; + case 2004: + return ParticleEffect.MOB_SPAWN; + case 2005: + return ParticleEffect.BONEMEAL_GROW; + case 2006: + return ParticleEffect.HARD_LANDING_DUST; + } + + throw new IOException("Unknown effect id: " + id); + } + + private int effectToId(Effect effect) throws IOException { + if(effect == SoundEffect.CLICK) { + return 1000; + } else if(effect == SoundEffect.EMPTY_DISPENSER_CLICK) { + return 1001; + } else if(effect == SoundEffect.FIRE_PROJECTILE) { + return 1002; + } else if(effect == SoundEffect.DOOR) { + return 1003; + } else if(effect == SoundEffect.FIZZLE) { + return 1004; + } else if(effect == SoundEffect.PLAY_RECORD) { + return 1005; + } else if(effect == SoundEffect.GHAST_CHARGE) { + return 1007; + } else if(effect == SoundEffect.GHAST_FIRE) { + return 1008; + } else if(effect == SoundEffect.BLAZE_FIRE) { + return 1009; + } else if(effect == SoundEffect.POUND_WOODEN_DOOR) { + return 1010; + } else if(effect == SoundEffect.POUND_METAL_DOOR) { + return 1011; + } else if(effect == SoundEffect.BREAK_WOODEN_DOOR) { + return 1012; + } else if(effect == SoundEffect.WITHER_SHOOT) { + return 1014; + } else if(effect == SoundEffect.BAT_TAKE_OFF) { + return 1015; + } else if(effect == SoundEffect.INFECT_VILLAGER) { + return 1016; + } else if(effect == SoundEffect.DISINFECT_VILLAGER) { + return 1017; + } else if(effect == SoundEffect.ENDER_DRAGON_DEATH) { + return 1018; + } else if(effect == SoundEffect.ANVIL_BREAK) { + return 1020; + } else if(effect == SoundEffect.ANVIL_USE) { + return 1021; + } else if(effect == SoundEffect.ANVIL_LAND) { + return 1022; + } + + if(effect == ParticleEffect.SMOKE) { + return 2000; + } else if(effect == ParticleEffect.BREAK_BLOCK) { + return 2001; + } else if(effect == ParticleEffect.BREAK_SPLASH_POTION) { + return 2002; + } else if(effect == ParticleEffect.BREAK_EYE_OF_ENDER) { + return 2003; + } else if(effect == ParticleEffect.MOB_SPAWN) { + return 2004; + } else if(effect == ParticleEffect.BONEMEAL_GROW) { + return 2005; + } else if(effect == ParticleEffect.HARD_LANDING_DUST) { + return 2006; + } + + throw new IOException("Unmapped effect: " + effect); + } + + private EffectData valueToData(int value) { + if(this.effect == SoundEffect.PLAY_RECORD) { + return new RecordData(value); + } else if(this.effect == ParticleEffect.SMOKE) { + if(value == 0) { + return SmokeData.SOUTH_EAST; + } else if(value == 1) { + return SmokeData.SOUTH; + } else if(value == 2) { + return SmokeData.SOUTH_WEST; + } else if(value == 3) { + return SmokeData.EAST; + } else if(value == 4) { + return SmokeData.UP; + } else if(value == 5) { + return SmokeData.WEST; + } else if(value == 6) { + return SmokeData.NORTH_EAST; + } else if(value == 7) { + return SmokeData.NORTH; + } else if(value == 8) { + return SmokeData.NORTH_WEST; + } + } else if(this.effect == ParticleEffect.BREAK_BLOCK) { + return new BreakBlockData(value); + } else if(this.effect == ParticleEffect.BREAK_SPLASH_POTION) { + return new BreakPotionData(value); + } else if(this.effect == ParticleEffect.HARD_LANDING_DUST) { + return new HardLandingData(value); + } + + return null; + } + + private int dataToValue(EffectData data) { + if(data instanceof RecordData) { + return ((RecordData) data).getRecordId(); + } + + if(data instanceof SmokeData) { + if(data == SmokeData.SOUTH_EAST) { + return 0; + } else if(data == SmokeData.SOUTH) { + return 1; + } else if(data == SmokeData.SOUTH_WEST) { + return 2; + } else if(data == SmokeData.EAST) { + return 3; + } else if(data == SmokeData.UP) { + return 4; + } else if(data == SmokeData.WEST) { + return 5; + } else if(data == SmokeData.NORTH_EAST) { + return 6; + } else if(data == SmokeData.NORTH) { + return 7; + } else if(data == SmokeData.NORTH_WEST) { + return 8; + } + } + + if(data instanceof BreakBlockData) { + return ((BreakBlockData) data).getBlockId(); + } + + if(data instanceof BreakPotionData) { + return ((BreakPotionData) data).getPotionId(); + } + + if(data instanceof HardLandingData) { + return ((HardLandingData) data).getDamagingDistance(); + } + + return 0; + } + + public static interface Effect { + } + + public static enum SoundEffect implements Effect { + CLICK, + EMPTY_DISPENSER_CLICK, + FIRE_PROJECTILE, + DOOR, + FIZZLE, + PLAY_RECORD, + GHAST_CHARGE, + GHAST_FIRE, + BLAZE_FIRE, + POUND_WOODEN_DOOR, + POUND_METAL_DOOR, + BREAK_WOODEN_DOOR, + WITHER_SHOOT, + BAT_TAKE_OFF, + INFECT_VILLAGER, + DISINFECT_VILLAGER, + ENDER_DRAGON_DEATH, + ANVIL_BREAK, + ANVIL_USE, + ANVIL_LAND; + } + + public static enum ParticleEffect implements Effect { + SMOKE, + BREAK_BLOCK, + BREAK_SPLASH_POTION, + BREAK_EYE_OF_ENDER, + MOB_SPAWN, + BONEMEAL_GROW, + HARD_LANDING_DUST; + } + + public static interface EffectData { + } + + public static class RecordData implements EffectData { + private int recordId; + + public RecordData(int recordId) { + this.recordId = recordId; + } + + public int getRecordId() { + return this.recordId; + } + } + + public static enum SmokeData implements EffectData { + SOUTH_EAST, + SOUTH, + SOUTH_WEST, + EAST, + UP, + WEST, + NORTH_EAST, + NORTH, + NORTH_WEST; + } + + public static class BreakBlockData implements EffectData { + private int blockId; + + public BreakBlockData(int blockId) { + this.blockId = blockId; + } + + public int getBlockId() { + return this.blockId; + } + } + + public static class BreakPotionData implements EffectData { + private int potionId; + + public BreakPotionData(int potionId) { + this.potionId = potionId; + } + + public int getPotionId() { + return this.potionId; + } + } + + public static class HardLandingData implements EffectData { + private int damagingDistance; + + public HardLandingData(int damagingDistance) { + this.damagingDistance = damagingDistance; + } + + public int getDamagingDistance() { + return this.damagingDistance; + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerPlaySoundPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerPlaySoundPacket.java new file mode 100644 index 00000000..2205cff7 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerPlaySoundPacket.java @@ -0,0 +1,290 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerPlaySoundPacket implements Packet { + + private String sound; + private double x; + private double y; + private double z; + private float volume; + private float pitch; + + public ServerPlaySoundPacket() { + } + + public ServerPlaySoundPacket(String sound, double x, double y, double z, float volume, float pitch) { + this.sound = sound; + this.x = x; + this.y = y; + this.z = z; + this.volume = volume; + this.pitch = pitch; + } + + public String getSound() { + return this.sound; + } + + public double getX() { + return this.x; + } + + public double getY() { + return this.y; + } + + public double getZ() { + return this.z; + } + + public float getVolume() { + return this.volume; + } + + public float getPitch() { + return this.pitch; + } + + @Override + public void read(NetInput in) throws IOException { + this.sound = in.readString(); + this.x = in.readInt() / 8D; + this.y = in.readInt() / 8D; + this.z = in.readInt() / 8D; + this.volume = in.readFloat(); + this.pitch = in.readUnsignedByte() / 63f; + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.sound); + out.writeInt((int) (this.x * 8)); + out.writeInt((int) (this.y * 8)); + out.writeInt((int) (this.z * 8)); + out.writeFloat(this.volume); + int pitch = (int) (this.pitch * 63); + if(pitch > 255) { + pitch = 255; + } + + if(pitch < 0) { + pitch = 0; + } + + out.writeByte(pitch); + } + + @Override + public boolean isPriority() { + return false; + } + + public static class Sound { + public static final String CLICK = "random.click"; + public static final String FIZZ = "random.fizz"; + public static final String FIRE_AMBIENT = "fire.fire"; + public static final String IGNITE_FIRE = "fire.ignite"; + public static final String WATER_AMBIENT = "liquid.water"; + public static final String LAVA_AMBIENT = "liquid.lava"; + public static final String LAVA_POP = "liquid.lavapop"; + public static final String HARP = "note.harp"; + public static final String BASS_DRUM = "note.bd"; + public static final String SNARE_DRUM = "note.snare"; + public static final String HI_HAT = "note.hat"; + public static final String DOUBLE_BASS = "note.bassattack"; + public static final String PISTON_EXTEND = "tile.piston.out"; + public static final String PISTON_RETRACT = "tile.piston.in"; + public static final String PORTAL_AMBIENT = "portal.portal"; + public static final String TNT_PRIMED = "game.tnt.primed"; + public static final String BOW_HIT = "random.bowhit"; + public static final String COLLECT_ITEM = "random.pop"; + public static final String COLLECT_EXP = "random.orb"; + public static final String SUCCESSFUL_HIT = "random.successful_hit"; + public static final String FIREWORK_BLAST = "fireworks.blast"; + public static final String FIREWORK_LARGE_BLAST = "fireworks.largeBlast"; + public static final String FIREWORK_FAR_BLAST = "fireworks.blast_far"; + public static final String FIREWORK_FAR_LARGE_BLAST = "fireworks.largeBlast_far"; + public static final String FIREWORK_TWINKLE = "fireworks.twinkle"; + public static final String FIREWORK_FAR_TWINKLE = "fireworks.twinkle_far"; + public static final String RAIN_AMBIENT = "ambient.weather.rain"; + public static final String WITHER_SPAWN = "mob.wither.spawn"; + public static final String ENDER_DRAGON_DEATH = "mob.enderdragon.end"; + public static final String FIRE_PROJECTILE = "random.bow"; + public static final String DOOR_OPEN = "random.door_open"; + public static final String DOOR_CLOSE = "random.door_close"; + public static final String GHAST_CHARGE = "mob.ghast.charge"; + public static final String GHAST_FIRE = "mob.ghast.fireball"; + public static final String POUND_WOODEN_DOOR = "mob.zombie.wood"; + public static final String POUND_METAL_DOOR = "mob.zombie.metal"; + public static final String BREAK_WOODEN_DOOR = "mob.zombie.woodbreak"; + public static final String WITHER_SHOOT = "mob.wither.shoot"; + public static final String BAT_TAKE_OFF = "mob.bat.takeoff"; + public static final String INFECT_VILLAGER = "mob.zombie.infect"; + public static final String DISINFECT_VILLAGER = "mob.zombie.unfect"; + public static final String ANVIL_BREAK = "random.anvil_break"; + public static final String ANVIL_USE = "random.anvil_use"; + public static final String ANVIL_LAND = "random.anvil_land"; + public static final String BREAK_SPLASH_POTION = "game.potion.smash"; + public static final String THORNS_DAMAGE = "damage.thorns"; + public static final String EXPLOSION = "random.explode"; + public static final String CAVE_AMBIENT = "ambient.cave.cave"; + public static final String OPEN_CHEST = "random.chestopen"; + public static final String CLOSE_CHEST = "random.chestclosed"; + public static final String DIG_STONE = "dig.stone"; + public static final String DIG_WOOD = "dig.wood"; + public static final String DIG_GRAVEL = "dig.gravel"; + public static final String DIG_GRASS = "dig.grass"; + public static final String DIG_CLOTH = "dig.cloth"; + public static final String DIG_SAND = "dig.sand"; + public static final String DIG_SNOW = "dig.snow"; + public static final String DIG_GLASS = "dig.glass"; + public static final String ANVIL_STEP = "step.anvil"; + public static final String LADDER_STEP = "step.ladder"; + public static final String STONE_STEP = "step.stone"; + public static final String WOOD_STEP = "step.wood"; + public static final String GRAVEL_STEP = "step.gravel"; + public static final String GRASS_STEP = "step.grass"; + public static final String CLOTH_STEP = "step.cloth"; + public static final String SAND_STEP = "step.sand"; + public static final String SNOW_STEP = "step.snow"; + public static final String BURP = "random.burp"; + public static final String SADDLE_HORSE = "mob.horse.leather"; + public static final String ENDER_DRAGON_FLAP_WINGS = "mob.enderdragon.wings"; + public static final String THUNDER_AMBIENT = "ambient.weather.thunder"; + public static final String LAUNCH_FIREWORKS = "fireworks.launch"; + public static final String CREEPER_PRIMED = "creeper.primed"; + public static final String ENDERMAN_STARE = "mob.endermen.stare"; + public static final String ENDERMAN_TELEPORT = "mob.endermen.portal"; + public static final String IRON_GOLEM_THROW = "mob.irongolem.throw"; + public static final String IRON_GOLEM_WALK = "mob.irongolem.walk"; + public static final String ZOMBIE_PIGMAN_ANGRY = "mob.zombiepig.zpigangry"; + public static final String SILVERFISH_STEP = "mob.silverfish.step"; + public static final String SKELETON_STEP = "mob.skeleton.step"; + public static final String SPIDER_STEP = "mob.spider.step"; + public static final String ZOMBIE_STEP = "mob.zombie.step"; + public static final String ZOMBIE_CURE = "mob.zombie.remedy"; + public static final String CHICKEN_LAY_EGG = "mob.chicken.plop"; + public static final String CHICKEN_STEP = "mob.chicken.step"; + public static final String COW_STEP = "mob.cow.step"; + public static final String HORSE_EATING = "eating"; + public static final String HORSE_LAND = "mob.horse.land"; + public static final String HORSE_WEAR_ARMOR = "mob.horse.armor"; + public static final String HORSE_GALLOP = "mob.horse.gallop"; + public static final String HORSE_BREATHE = "mob.horse.breathe"; + public static final String HORSE_WOOD_STEP = "mob.horse.wood"; + public static final String HORSE_SOFT_STEP = "mob.horse.soft"; + public static final String HORSE_JUMP = "mob.horse.jump"; + public static final String SHEAR_SHEEP = "mob.sheep.shear"; + public static final String PIG_STEP = "mob.pig.step"; + public static final String SHEEP_STEP = "mob.sheep.step"; + public static final String VILLAGER_YES = "mob.villager.yes"; + public static final String VILLAGER_NO = "mob.villager.no"; + public static final String WOLF_STEP = "mob.wolf.step"; + public static final String WOLF_SHAKE = "mob.wolf.shake"; + public static final String DRINK = "random.drink"; + public static final String EAT = "random.eat"; + public static final String LEVEL_UP = "random.levelup"; + public static final String FISH_HOOK_SPLASH = "random.splash"; + public static final String ITEM_BREAK = "random.break"; + public static final String SWIM = "game.neutral.swim"; + public static final String SPLASH = "game.neutral.swim.splash"; + public static final String HURT = "game.neutral.hurt"; + public static final String DEATH = "game.neutral.die"; + public static final String BIG_FALL = "game.neutral.hurt.fall.big"; + public static final String SMALL_FALL = "game.neutral.hurt.fall.small"; + public static final String MOB_SWIM = "game.hostile.swim"; + public static final String MOB_SPLASH = "game.hostile.swim.splash"; + public static final String PLAYER_SWIM = "game.player.swim"; + public static final String PLAYER_SPLASH = "game.player.swim.splash"; + public static final String ENDER_DRAGON_GROWL = "mob.enderdragon.growl"; + public static final String WITHER_IDLE = "mob.wither.idle"; + public static final String BLAZE_BREATHE = "mob.blaze.breathe"; + public static final String ENDERMAN_SCREAM = "mob.endermen.scream"; + public static final String ENDERMAN_IDLE = "mob.endermen.idle"; + public static final String GHAST_MOAN = "mob.ghast.moan"; + public static final String ZOMBIE_PIGMAN_IDLE = "mob.zombiepig.zpig"; + public static final String SILVERFISH_IDLE = "mob.silverfish.say"; + public static final String SKELETON_IDLE = "mob.skeleton.say"; + public static final String SPIDER_IDLE = "mob.spider.say"; + public static final String WITCH_IDLE = "mob.witch.idle"; + public static final String ZOMBIE_IDLE = "mob.zombie.say"; + public static final String BAT_IDLE = "mob.bat.idle"; + public static final String CHICKEN_IDLE = "mob.chicken.say"; + public static final String COW_IDLE = "mob.cow.say"; + public static final String HORSE_IDLE = "mob.horse.idle"; + public static final String DONKEY_IDLE = "mob.horse.donkey.idle"; + public static final String ZOMBIE_HORSE_IDLE = "mob.horse.zombie.idle"; + public static final String SKELETON_HORSE_IDLE = "mob.horse.skeleton.idle"; + public static final String OCELOT_PURR = "mob.cat.purr"; + public static final String OCELOT_PURR_MEOW = "mob.cat.purreow"; + public static final String OCELOT_MEOW = "mob.cat.meow"; + public static final String PIG_IDLE = "mob.pig.say"; + public static final String SHEEP_IDLE = "mob.sheep.say"; + public static final String VILLAGER_HAGGLE = "mob.villager.haggle"; + public static final String VILLAGER_IDLE = "mob.villager.idle"; + public static final String WOLF_GROWL = "mob.wolf.growl"; + public static final String WOLF_PANT = "mob.wolf.panting"; + public static final String WOLF_WHINE = "mob.wolf.whine"; + public static final String WOLF_BARK = "mob.wolf.bark"; + public static final String MOB_BIG_FALL = "game.hostile.hurt.fall.big"; + public static final String MOB_SMALL_FALL = "game.hostile.hurt.fall.small"; + public static final String PLAYER_BIG_FALL = "game.player.hurt.fall.big"; + public static final String PLAYER_SMALL_FALL = "game.player.hurt.fall.small"; + public static final String ENDER_DRAGON_HURT = "mob.enderdragon.hit"; + public static final String WITHER_HURT = "mob.wither.hurt"; + public static final String WITHER_DEATH = "mob.wither.death"; + public static final String BLAZE_HURT = "mob.blaze.hit"; + public static final String BLAZE_DEATH = "mob.blaze.death"; + public static final String CREEPER_HURT = "mob.creeper.say"; + public static final String CREEPER_DEATH = "mob.creeper.death"; + public static final String ENDERMAN_HURT = "mob.endermen.hit"; + public static final String ENDERMAN_DEATH = "mob.endermen.death"; + public static final String GHAST_HURT = "mob.ghast.scream"; + public static final String GHAST_DEATH = "mob.ghast.death"; + public static final String IRON_GOLEM_HURT = "mob.irongolem.hit"; + public static final String IRON_GOLEM_DEATH = "mob.irongolem.death"; + public static final String MOB_HURT = "game.hostile.hurt"; + public static final String MOB_DEATH = "game.hostile.die"; + public static final String ZOMBIE_PIGMAN_HURT = "mob.zombiepig.zpighurt"; + public static final String ZOMBIE_PIGMAN_DEATH = "mob.zombiepig.zpigdeath"; + public static final String SILVERFISH_HURT = "mob.silverfish.hit"; + public static final String SILVERFISH_DEATH = "mob.silverfish.kill"; + public static final String SKELETON_HURT = "mob.skeleton.hurt"; + public static final String SKELETON_DEATH = "mob.skeleton.death"; + public static final String SLIME = "mob.slime.small"; + public static final String BIG_SLIME = "mob.slime.big"; + public static final String SPIDER_DEATH = "mob.spider.death"; + public static final String WITCH_HURT = "mob.witch.hurt"; + public static final String WITCH_DEATH = "mob.witch.death"; + public static final String ZOMBIE_HURT = "mob.zombie.hurt"; + public static final String ZOMBIE_DEATH = "mob.zombie.death"; + public static final String PLAYER_HURT = "game.player.hurt"; + public static final String PLAYER_DEATH = "game.player.die"; + public static final String WOLF_HURT = "mob.wolf.hurt"; + public static final String WOLF_DEATH = "mob.wolf.death"; + public static final String VILLAGER_HURT = "mob.villager.hit"; + public static final String VILLAGER_DEATH = "mob.villager.death"; + public static final String PIG_DEATH = "mob.pig.death"; + public static final String OCELOT_HURT = "mob.cat.hitt"; + public static final String HORSE_HURT = "mob.horse.hit"; + public static final String DONKEY_HURT = "mob.horse.donkey.hit"; + public static final String ZOMBIE_HORSE_HURT = "mob.horse.zombie.hit"; + public static final String SKELETON_HORSE_HURT = "mob.horse.skeleton.hit"; + public static final String HORSE_DEATH = "mob.horse.death"; + public static final String DONKEY_DEATH = "mob.horse.donkey.death"; + public static final String ZOMBIE_HORSE_DEATH = "mob.horse.zombie.death"; + public static final String SKELETON_HORSE_DEATH = "mob.horse.skeleton.death"; + public static final String COW_HURT = "mob.cow.hurt"; + public static final String CHICKEN_HURT = "mob.chicken.hurt"; + public static final String BAT_HURT = "mob.bat.hurt"; + public static final String BAT_DEATH = "mob.bat.death"; + public static final String MOB_ATTACK = "mob.attack"; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerSpawnParticlePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerSpawnParticlePacket.java new file mode 100644 index 00000000..4ba3831d --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerSpawnParticlePacket.java @@ -0,0 +1,169 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerSpawnParticlePacket implements Packet { + + private String particle; + private float x; + private float y; + private float z; + private float offsetX; + private float offsetY; + private float offsetZ; + private float velocityOffset; + private int amount; + + public ServerSpawnParticlePacket() { + } + + public ServerSpawnParticlePacket(String particle, float x, float y, float z, float offsetX, float offsetY, float offsetZ, float velocityOffset, int amount) { + this.particle = particle; + this.x = x; + this.y = y; + this.z = z; + this.offsetX = offsetX; + this.offsetY = offsetY; + this.offsetZ = offsetZ; + this.velocityOffset = velocityOffset; + this.amount = amount; + } + + public String getParticle() { + return this.particle; + } + + public float getX() { + return this.x; + } + + public float getY() { + return this.y; + } + + public float getZ() { + return this.z; + } + + public float getOffsetX() { + return this.offsetX; + } + + public float getOffsetY() { + return this.offsetY; + } + + public float getOffsetZ() { + return this.offsetZ; + } + + public float getVelocityOffset() { + return this.velocityOffset; + } + + public int getAmount() { + return this.amount; + } + + @Override + public void read(NetInput in) throws IOException { + this.particle = in.readString(); + this.x = in.readFloat(); + this.y = in.readFloat(); + this.z = in.readFloat(); + this.offsetX = in.readFloat(); + this.offsetY = in.readFloat(); + this.offsetZ = in.readFloat(); + this.offsetZ = in.readFloat(); + this.velocityOffset = in.readFloat(); + this.amount = in.readInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.particle); + out.writeFloat(this.x); + out.writeFloat(this.y); + out.writeFloat(this.z); + out.writeFloat(this.offsetX); + out.writeFloat(this.offsetY); + out.writeFloat(this.offsetZ); + out.writeFloat(this.velocityOffset); + out.writeInt(this.amount); + } + + @Override + public boolean isPriority() { + return false; + } + + public static class Particle { + public static final String HUGE_EXPLOSION = "hugeexplosion"; + public static final String LARGE_EXPLOSION = "largeexplode"; + public static final String FIREWORKS_SPARK = "fireworksSpark"; + public static final String LIQUID_PARTICLES = "suspended"; + public static final String DEPTH_PARTICLES = "depthsuspend"; + public static final String MYCELIUM_PARTICLES = "townaura"; + public static final String CRITICAL_HIT = "crit"; + public static final String ENCHANTED_CRITICAL_HIT = "magicCrit"; + public static final String SMOKE = "smoke"; + public static final String MOB_POTION_EFFECT = "mobSpell"; + public static final String MOB_POTION_EFFECT_AMBIENT = "mobSpellAmbient"; + public static final String POTION_EFFECT = "spell"; + public static final String INSTANT_POTION_EFFECT = "instantSpell"; + public static final String WITCH_PARTICLES = "witchMagic"; + public static final String NOTE = "note"; + public static final String PORTAL = "portal"; + public static final String ENCHANTMENT_TABLE_LETTERS = "enchantmenttable"; + public static final String EXPLOSION = "explode"; + public static final String FLAME = "flame"; + public static final String LAVA_PARTICLES = "lava"; + public static final String FOOTSTEP_PARTICLES = "footstep"; + public static final String SPLASH = "splash"; + public static final String FISH_HOOK_WAKE = "wake"; + public static final String LARGE_SMOKE = "largesmoke"; + public static final String CLOUD = "cloud"; + public static final String REDSTONE_PARTICLES = "reddust"; + public static final String BREAKING_SNOWBALL = "snowballpoof"; + public static final String DRIP_WATER = "dripWater"; + public static final String DRIP_LAVA = "dripLava"; + public static final String SHOVEL_SNOW = "snowshovel"; + public static final String SLIME = "slime"; + public static final String HEART = "heart"; + public static final String ANGRY_VILLAGER = "angryVillager"; + public static final String HAPPY_VILLAGER = "happyVillager"; + + private static final String ITEM_BREAK_PREFIX = "iconcrack_"; + private static final String BLOCK_BREAK_PREFIX = "blockcrack_"; + private static final String BLOCK_IMPACT_PREFIX = "blockdust_"; + + public static final String ITEM_BREAK_PARTICLES(int id) { + return ITEM_BREAK_PARTICLES(id, -1); + } + + public static final String ITEM_BREAK_PARTICLES(int id, int data) { + return ITEM_BREAK_PREFIX + id + (id != -1 ? "_" + data : ""); + } + + public static final String BLOCK_BREAK_PARTICLES(int id) { + return BLOCK_BREAK_PARTICLES(id, -1); + } + + public static final String BLOCK_BREAK_PARTICLES(int id, int data) { + return BLOCK_BREAK_PREFIX + id + (id != -1 ? "_" + data : ""); + } + + public static final String BLOCK_IMPACT_PARTICLES(int id) { + return BLOCK_IMPACT_PARTICLES(id, -1); + } + + public static final String BLOCK_IMPACT_PARTICLES(int id, int data) { + return BLOCK_IMPACT_PREFIX + id + (id != -1 ? "_" + data : ""); + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerSpawnPositionPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerSpawnPositionPacket.java new file mode 100644 index 00000000..cf468a29 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerSpawnPositionPacket.java @@ -0,0 +1,55 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerSpawnPositionPacket implements Packet { + + private int x; + private int y; + private int z; + + public ServerSpawnPositionPacket() { + } + + public ServerSpawnPositionPacket(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + @Override + public void read(NetInput in) throws IOException { + this.x = in.readInt(); + this.y = in.readInt(); + this.z = in.readInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.x); + out.writeInt(this.y); + out.writeInt(this.z); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerUpdateSignPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerUpdateSignPacket.java new file mode 100644 index 00000000..fb5253d8 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerUpdateSignPacket.java @@ -0,0 +1,72 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerUpdateSignPacket implements Packet { + + private int x; + private int y; + private int z; + private String lines[]; + + public ServerUpdateSignPacket() { + } + + public ServerUpdateSignPacket(int x, int y, int z, String lines[]) { + if(lines.length != 4) { + throw new IllegalArgumentException("Lines must contain exactly 4 strings!"); + } + + this.x = x; + this.y = y; + this.z = z; + this.lines = lines; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public String[] getLines() { + return this.lines; + } + + @Override + public void read(NetInput in) throws IOException { + this.x = in.readInt(); + this.y = in.readShort(); + this.z = in.readInt(); + this.lines = new String[4]; + for(int count = 0; count < this.lines.length; count++) { + this.lines[count] = in.readString(); + } + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.x); + out.writeShort(this.y); + out.writeInt(this.z); + for(String line : this.lines) { + out.writeString(line); + } + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerUpdateTileEntityPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerUpdateTileEntityPacket.java new file mode 100644 index 00000000..3e90deca --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerUpdateTileEntityPacket.java @@ -0,0 +1,81 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.mc.util.NetUtil; +import ch.spacebase.opennbt.tag.CompoundTag; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerUpdateTileEntityPacket implements Packet { + + private int x; + private int y; + private int z; + private Type type; + private CompoundTag nbt; + + public ServerUpdateTileEntityPacket() { + } + + public ServerUpdateTileEntityPacket(int breakerEntityId, int x, int y, int z, Type type, CompoundTag nbt) { + this.x = x; + this.y = y; + this.z = z; + this.type = type; + this.nbt = nbt; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public Type getType() { + return this.type; + } + + public CompoundTag getNBT() { + return this.nbt; + } + + @Override + public void read(NetInput in) throws IOException { + this.x = in.readInt(); + this.y = in.readShort(); + this.z = in.readInt(); + this.type = Type.values()[in.readUnsignedByte() - 1]; + this.nbt = NetUtil.readNBT(in); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.x); + out.writeShort(this.y); + out.writeInt(this.z); + out.writeByte(this.type.ordinal() + 1); + NetUtil.writeNBT(out, this.nbt); + } + + @Override + public boolean isPriority() { + return false; + } + + public static enum Type { + MOB_SPAWNER, + COMMAND_BLOCK, + BEACON, + SKULL, + FLOWER_POT; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerUpdateTimePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerUpdateTimePacket.java new file mode 100644 index 00000000..9b9dee71 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/ingame/server/world/ServerUpdateTimePacket.java @@ -0,0 +1,47 @@ +package ch.spacebase.mc.protocol.packet.ingame.server.world; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class ServerUpdateTimePacket implements Packet { + + private long age; + private long time; + + public ServerUpdateTimePacket() { + } + + public ServerUpdateTimePacket(long age, long time) { + this.age = age; + this.time = time; + } + + public long getWorldAge() { + return this.age; + } + + public long getTime() { + return this.time; + } + + @Override + public void read(NetInput in) throws IOException { + this.age = in.readLong(); + this.time = in.readLong(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeLong(this.age); + out.writeLong(this.time); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/login/client/EncryptionResponsePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/login/client/EncryptionResponsePacket.java new file mode 100644 index 00000000..3a2c6c07 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/login/client/EncryptionResponsePacket.java @@ -0,0 +1,52 @@ +package ch.spacebase.mc.protocol.packet.login.client; + +import java.io.IOException; +import java.security.PrivateKey; +import java.security.PublicKey; + +import javax.crypto.SecretKey; + +import ch.spacebase.mc.util.CryptUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class EncryptionResponsePacket implements Packet { + + private byte sharedKey[]; + private byte verifyToken[]; + + public EncryptionResponsePacket() { + } + + public EncryptionResponsePacket(SecretKey secretKey, PublicKey publicKey, byte verifyToken[]) { + this.sharedKey = CryptUtil.encryptData(publicKey, secretKey.getEncoded()); + this.verifyToken = CryptUtil.encryptData(publicKey, verifyToken); + } + + public SecretKey getSecretKey(PrivateKey privateKey) { + return CryptUtil.decryptSharedKey(privateKey, this.sharedKey); + } + + public byte[] getVerifyToken(PrivateKey privateKey) { + return CryptUtil.decryptData(privateKey, this.verifyToken); + } + + @Override + public void read(NetInput in) throws IOException { + this.sharedKey = in.readPrefixedBytes(); + this.verifyToken = in.readPrefixedBytes(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writePrefixedBytes(this.sharedKey); + out.writePrefixedBytes(this.verifyToken); + } + + @Override + public boolean isPriority() { + return true; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/login/client/LoginStartPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/login/client/LoginStartPacket.java new file mode 100644 index 00000000..ee28db95 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/login/client/LoginStartPacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.login.client; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class LoginStartPacket implements Packet { + + private String username; + + public LoginStartPacket() { + } + + public LoginStartPacket(String username) { + this.username = username; + } + + public String getUsername() { + return this.username; + } + + @Override + public void read(NetInput in) throws IOException { + this.username = in.readString(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.username); + } + + @Override + public boolean isPriority() { + return true; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/login/server/EncryptionRequestPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/login/server/EncryptionRequestPacket.java new file mode 100644 index 00000000..ed6d3f7b --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/login/server/EncryptionRequestPacket.java @@ -0,0 +1,57 @@ +package ch.spacebase.mc.protocol.packet.login.server; + +import java.io.IOException; +import java.security.PublicKey; + +import ch.spacebase.mc.util.CryptUtil; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class EncryptionRequestPacket implements Packet { + + private String serverId; + private PublicKey publicKey; + private byte verifyToken[]; + + public EncryptionRequestPacket() { + } + + public EncryptionRequestPacket(String serverId, PublicKey publicKey, byte verifyToken[]) { + this.serverId = serverId; + this.publicKey = publicKey; + this.verifyToken = verifyToken; + } + + public String getServerId() { + return this.serverId; + } + + public PublicKey getPublicKey() { + return this.publicKey; + } + + public byte[] getVerifyToken() { + return this.verifyToken; + } + + @Override + public void read(NetInput in) throws IOException { + this.serverId = in.readString(); + this.publicKey = CryptUtil.decodePublicKey(in.readPrefixedBytes()); + this.verifyToken = in.readPrefixedBytes(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.serverId); + out.writePrefixedBytes(this.publicKey.getEncoded()); + out.writePrefixedBytes(this.verifyToken); + } + + @Override + public boolean isPriority() { + return true; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/login/server/LoginDisconnectPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/login/server/LoginDisconnectPacket.java new file mode 100644 index 00000000..92bc6ea1 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/login/server/LoginDisconnectPacket.java @@ -0,0 +1,48 @@ +package ch.spacebase.mc.protocol.packet.login.server; + +import java.io.IOException; + +import ch.spacebase.mc.util.message.Message; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class LoginDisconnectPacket implements Packet { + + private Message message; + + public LoginDisconnectPacket() { + } + + public LoginDisconnectPacket(String message) { + this(new Message(message)); + } + + public LoginDisconnectPacket(Message message) { + this.message = message; + } + + public String getRawReason() { + return this.getReason().getRawText(); + } + + public Message getReason() { + return this.message; + } + + @Override + public void read(NetInput in) throws IOException { + this.message = new Message(in.readString(), true); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.message.toString()); + } + + @Override + public boolean isPriority() { + return true; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/login/server/LoginSuccessPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/login/server/LoginSuccessPacket.java new file mode 100644 index 00000000..acd5c661 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/login/server/LoginSuccessPacket.java @@ -0,0 +1,47 @@ +package ch.spacebase.mc.protocol.packet.login.server; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class LoginSuccessPacket implements Packet { + + private String id; + private String username; + + public LoginSuccessPacket() { + } + + public LoginSuccessPacket(String id, String username) { + this.id = id; + this.username = username; + } + + public String getPlayerId() { + return this.id; + } + + public String getUsername() { + return this.username; + } + + @Override + public void read(NetInput in) throws IOException { + this.id = in.readString(); + this.username = in.readString(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeString(this.id); + out.writeString(this.username); + } + + @Override + public boolean isPriority() { + return true; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/status/client/StatusPingPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/status/client/StatusPingPacket.java new file mode 100644 index 00000000..4599b2ea --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/status/client/StatusPingPacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.status.client; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class StatusPingPacket implements Packet { + + private long time; + + public StatusPingPacket() { + } + + public StatusPingPacket(long time) { + this.time = time; + } + + public long getPingTime() { + return this.time; + } + + @Override + public void read(NetInput in) throws IOException { + this.time = in.readLong(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeLong(this.time); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/status/client/StatusQueryPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/status/client/StatusQueryPacket.java new file mode 100644 index 00000000..f1b8466b --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/status/client/StatusQueryPacket.java @@ -0,0 +1,27 @@ +package ch.spacebase.mc.protocol.packet.status.client; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class StatusQueryPacket implements Packet { + + public StatusQueryPacket() { + } + + @Override + public void read(NetInput in) throws IOException { + } + + @Override + public void write(NetOutput out) throws IOException { + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/status/server/StatusPongPacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/status/server/StatusPongPacket.java new file mode 100644 index 00000000..2087368f --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/status/server/StatusPongPacket.java @@ -0,0 +1,39 @@ +package ch.spacebase.mc.protocol.packet.status.server; + +import java.io.IOException; + +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class StatusPongPacket implements Packet { + + private long time; + + public StatusPongPacket() { + } + + public StatusPongPacket(long time) { + this.time = time; + } + + public long getPingTime() { + return this.time; + } + + @Override + public void read(NetInput in) throws IOException { + this.time = in.readLong(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeLong(this.time); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/packet/status/server/StatusResponsePacket.java b/src/main/java/ch/spacebase/mc/protocol/packet/status/server/StatusResponsePacket.java new file mode 100644 index 00000000..90add915 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/packet/status/server/StatusResponsePacket.java @@ -0,0 +1,133 @@ +package ch.spacebase.mc.protocol.packet.status.server; + +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import ch.spacebase.mc.auth.GameProfile; +import ch.spacebase.mc.protocol.data.status.PlayerInfo; +import ch.spacebase.mc.protocol.data.status.ServerStatusInfo; +import ch.spacebase.mc.protocol.data.status.VersionInfo; +import ch.spacebase.mc.util.Base64; +import ch.spacebase.mc.util.message.Message; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; +import ch.spacebase.packetlib.packet.Packet; + +public class StatusResponsePacket implements Packet { + + private ServerStatusInfo info; + + public StatusResponsePacket() { + } + + public StatusResponsePacket(ServerStatusInfo info) { + this.info = info; + } + + public ServerStatusInfo getInfo() { + return this.info; + } + + @Override + public void read(NetInput in) throws IOException { + JsonObject obj = new Gson().fromJson(in.readString(), JsonObject.class); + JsonObject ver = obj.get("version").getAsJsonObject(); + VersionInfo version = new VersionInfo(ver.get("name").getAsString(), ver.get("protocol").getAsInt()); + JsonObject plrs = obj.get("players").getAsJsonObject(); + GameProfile profiles[] = new GameProfile[0]; + if(plrs.has("sample")) { + JsonArray prof = plrs.get("sample").getAsJsonArray(); + if(prof.size() > 0) { + profiles = new GameProfile[prof.size()]; + for(int index = 0; index < prof.size(); index++) { + JsonObject o = prof.get(index).getAsJsonObject(); + profiles[index] = new GameProfile(o.get("id").getAsString(), o.get("name").getAsString()); + } + } + } + + PlayerInfo players = new PlayerInfo(plrs.get("max").getAsInt(), plrs.get("online").getAsInt(), profiles); + JsonElement desc = obj.get("description"); + Message description = new Message(desc.isJsonObject() ? desc.getAsJsonObject().toString() : desc.getAsString(), desc.isJsonObject() ? true : false); + BufferedImage icon = null; + if(obj.has("favicon")) { + icon = this.stringToIcon(obj.get("favicon").getAsString()); + } + + this.info = new ServerStatusInfo(version, players, description, icon); + } + + @Override + public void write(NetOutput out) throws IOException { + JsonObject obj = new JsonObject(); + JsonObject ver = new JsonObject(); + ver.addProperty("name", this.info.getVersionInfo().getVersionName()); + ver.addProperty("protocol", this.info.getVersionInfo().getProtocolVersion()); + JsonObject plrs = new JsonObject(); + plrs.addProperty("max", this.info.getPlayerInfo().getMaxPlayers()); + plrs.addProperty("online", this.info.getPlayerInfo().getOnlinePlayers()); + if(this.info.getPlayerInfo().getPlayers().length > 0) { + JsonArray array = new JsonArray(); + for(GameProfile profile : this.info.getPlayerInfo().getPlayers()) { + JsonObject o = new JsonObject(); + o.addProperty("name", profile.getName()); + o.addProperty("id", profile.getId()); + array.add(o); + } + + plrs.add("sample", array); + } + + obj.add("version", ver); + obj.add("players", plrs); + obj.add("description", this.info.getDescription().getJson()); + if(this.info.getIcon() != null) { + obj.addProperty("favicon", this.iconToString(this.info.getIcon())); + } + + out.writeString(obj.toString()); + } + + private BufferedImage stringToIcon(String str) throws IOException { + if(str.startsWith("data:image/png;base64,")) { + str = str.substring("data:image/png;base64,".length()); + } + + byte bytes[] = Base64.decode(str.getBytes("UTF-8")); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + BufferedImage icon = ImageIO.read(in); + in.close(); + if(icon != null && (icon.getWidth() != 64 || icon.getHeight() != 64)) { + throw new IOException("Icon must be 64x64."); + } + + return icon; + } + + private String iconToString(BufferedImage icon) throws IOException { + if(icon.getWidth() != 64 || icon.getHeight() != 64) { + throw new IOException("Icon must be 64x64."); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ImageIO.write(icon, "PNG", out); + out.close(); + byte encoded[] = Base64.encode(out.toByteArray()); + return "data:image/png;base64," + new String(encoded, "UTF-8"); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/ch/spacebase/mc/protocol/test/Test.java b/src/main/java/ch/spacebase/mc/protocol/test/Test.java new file mode 100644 index 00000000..94d2891b --- /dev/null +++ b/src/main/java/ch/spacebase/mc/protocol/test/Test.java @@ -0,0 +1,141 @@ +package ch.spacebase.mc.protocol.test; + +import java.util.Arrays; + +import ch.spacebase.mc.auth.GameProfile; +import ch.spacebase.mc.auth.exceptions.AuthenticationException; +import ch.spacebase.mc.protocol.MinecraftProtocol; +import ch.spacebase.mc.protocol.ProtocolConstants; +import ch.spacebase.mc.protocol.ProtocolMode; +import ch.spacebase.mc.protocol.ServerLoginHandler; +import ch.spacebase.mc.protocol.data.status.PlayerInfo; +import ch.spacebase.mc.protocol.data.status.ServerStatusInfo; +import ch.spacebase.mc.protocol.data.status.VersionInfo; +import ch.spacebase.mc.protocol.data.status.handler.ServerInfoBuilder; +import ch.spacebase.mc.protocol.data.status.handler.ServerInfoHandler; +import ch.spacebase.mc.protocol.data.status.handler.ServerPingTimeHandler; +import ch.spacebase.mc.protocol.packet.ingame.client.ClientChatPacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerJoinGamePacket; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerJoinGamePacket.Difficulty; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerJoinGamePacket.GameMode; +import ch.spacebase.mc.protocol.packet.ingame.server.ServerJoinGamePacket.WorldType; +import ch.spacebase.mc.util.message.Message; +import ch.spacebase.packetlib.Client; +import ch.spacebase.packetlib.Server; +import ch.spacebase.packetlib.Session; +import ch.spacebase.packetlib.event.server.ServerAdapter; +import ch.spacebase.packetlib.event.server.SessionAddedEvent; +import ch.spacebase.packetlib.event.session.DisconnectedEvent; +import ch.spacebase.packetlib.event.session.PacketReceivedEvent; +import ch.spacebase.packetlib.event.session.SessionAdapter; +import ch.spacebase.packetlib.tcp.TcpSessionFactory; + +public class Test { + + private static final boolean SPAWN_SERVER = true; + private static final String HOST = "127.0.0.1"; + private static final int PORT = 25565; + private static final String USERNAME = "Player"; + private static final String PASSWORD = "passwordgoeshere"; + + public static void main(String[] args) { + if(SPAWN_SERVER) { + Server server = new Server(HOST, PORT, MinecraftProtocol.class, new TcpSessionFactory()); + server.setGlobalFlag(ProtocolConstants.VERIFY_USERS_KEY, true); + server.setGlobalFlag(ProtocolConstants.SERVER_INFO_BUILDER_KEY, new ServerInfoBuilder() { + @Override + public ServerStatusInfo buildInfo() { + return new ServerStatusInfo(new VersionInfo("1.7.2", 4), new PlayerInfo(100, 0, new GameProfile[0]), new Message("Hello world!"), null); + } + }); + + server.setGlobalFlag(ProtocolConstants.SERVER_LOGIN_HANDLER_KEY, new ServerLoginHandler() { + @Override + public void loggedIn(Session session) { + session.send(new ServerJoinGamePacket(0, false, GameMode.SURVIVAL, 0, Difficulty.PEACEFUL, 10, WorldType.DEFAULT)); + } + }); + + server.addListener(new ServerAdapter() { + @Override + public void sessionAdded(SessionAddedEvent event) { + event.getSession().addListener(new SessionAdapter() { + @Override + public void packetReceived(PacketReceivedEvent event) { + if(event.getPacket() instanceof ClientChatPacket) { + ClientChatPacket packet = event.getPacket(); + GameProfile profile = event.getSession().getFlag(ProtocolConstants.PROFILE_KEY); + System.out.println(profile.getName() + ": " + packet.getMessage()); + } + } + }); + } + }); + + server.bind(); + } + + status(); + login(); + } + + private static void status() { + MinecraftProtocol protocol = new MinecraftProtocol(ProtocolMode.STATUS); + Client client = new Client(HOST, PORT, protocol, new TcpSessionFactory()); + client.getSession().setFlag(ProtocolConstants.SERVER_INFO_HANDLER_KEY, new ServerInfoHandler() { + @Override + public void handle(ServerStatusInfo info) { + System.out.println("Version: " + info.getVersionInfo().getVersionName() + ", " + info.getVersionInfo().getProtocolVersion()); + System.out.println("Player Count: " + info.getPlayerInfo().getOnlinePlayers() + " / " + info.getPlayerInfo().getMaxPlayers()); + System.out.println("Players: " + Arrays.toString(info.getPlayerInfo().getPlayers())); + System.out.println("Description: " + info.getDescription().getRawText()); + System.out.println("Icon: " + info.getIcon()); + } + }); + + client.getSession().setFlag(ProtocolConstants.SERVER_PING_TIME_HANDLER_KEY, new ServerPingTimeHandler() { + @Override + public void handle(long pingTime) { + System.out.println("Server ping took " + pingTime + "ms"); + } + }); + + client.getSession().connect(); + while(client.getSession().isConnected()) { + try { + Thread.sleep(5); + } catch(InterruptedException e) { + e.printStackTrace(); + } + } + } + + private static void login() { + MinecraftProtocol protocol = null; + try { + protocol = new MinecraftProtocol(USERNAME, PASSWORD); + } catch(AuthenticationException e) { + e.printStackTrace(); + return; + } + + Client client = new Client(HOST, PORT, protocol, new TcpSessionFactory()); + client.getSession().addListener(new SessionAdapter() { + @Override + public void packetReceived(PacketReceivedEvent event) { + if(event.getPacket() instanceof ServerJoinGamePacket) { + event.getSession().send(new ClientChatPacket("Hello, this is a test of MCProtocolLib.")); + event.getSession().disconnect("Finished"); + } + } + + @Override + public void disconnected(DisconnectedEvent event) { + System.out.println("Disconnected: " + new Message(event.getReason(), true).getRawText()); + } + }); + + client.getSession().connect(); + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/Base64.java b/src/main/java/ch/spacebase/mc/util/Base64.java new file mode 100644 index 00000000..834482ae --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/Base64.java @@ -0,0 +1,176 @@ +package ch.spacebase.mc.util; + +public class Base64 { + + private final static byte EQUALS_SIGN = (byte) '='; + private final static byte WHITE_SPACE_ENC = -5; + private final static byte EQUALS_SIGN_ENC = -1; + private final static byte[] _STANDARD_ALPHABET = { (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', (byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', (byte) 'z', (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) '+', (byte) '/' }; + private final static byte[] _STANDARD_DECODABET = { -9, -9, -9, -9, -9, -9, -9, -9, -9, -5, -5, -9, -9, -5, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -5, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, 62, -9, -9, -9, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -9, -9, -9, -1, -9, -9, -9, 0, 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, -9, -9, -9, -9, -9, -9, 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, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9 }; + + private static byte[] getAlphabet() { + return _STANDARD_ALPHABET; + } + + private static byte[] getDecodabet() { + return _STANDARD_DECODABET; + } + + private static byte[] encode3to4(byte[] source, int srcOffset, int numSigBytes, byte[] destination, int destOffset) { + byte[] ALPHABET = getAlphabet(); + int inBuff = (numSigBytes > 0 ? ((source[srcOffset] << 24) >>> 8) : 0) | (numSigBytes > 1 ? ((source[srcOffset + 1] << 24) >>> 16) : 0) | (numSigBytes > 2 ? ((source[srcOffset + 2] << 24) >>> 24) : 0); + switch(numSigBytes) { + case 3: + destination[destOffset] = ALPHABET[(inBuff >>> 18)]; + destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f]; + destination[destOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3f]; + destination[destOffset + 3] = ALPHABET[(inBuff) & 0x3f]; + return destination; + case 2: + destination[destOffset] = ALPHABET[(inBuff >>> 18)]; + destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f]; + destination[destOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3f]; + destination[destOffset + 3] = EQUALS_SIGN; + return destination; + case 1: + destination[destOffset] = ALPHABET[(inBuff >>> 18)]; + destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f]; + destination[destOffset + 2] = EQUALS_SIGN; + destination[destOffset + 3] = EQUALS_SIGN; + return destination; + default: + return destination; + } + } + + public static byte[] encode(byte[] source) { + return encode(source, 0, source.length); + } + + public static byte[] encode(byte[] source, int off, int len) { + if(source == null) { + throw new NullPointerException("Cannot serialize a null array."); + } + + if(off < 0) { + throw new IllegalArgumentException("Cannot have negative offset: " + off); + } + + if(len < 0) { + throw new IllegalArgumentException("Cannot have length offset: " + len); + } + + if(off + len > source.length) { + throw new IllegalArgumentException(String.format("Cannot have offset of %d and length of %d with array of length %d", off, len, source.length)); + } + + int encLen = (len / 3) * 4 + (len % 3 > 0 ? 4 : 0); + byte[] outBuff = new byte[encLen]; + int d = 0; + int e = 0; + int len2 = len - 2; + for(; d < len2; d += 3, e += 4) { + encode3to4(source, d + off, 3, outBuff, e); + } + + if(d < len) { + encode3to4(source, d + off, len - d, outBuff, e); + e += 4; + } + + if(e <= outBuff.length - 1) { + byte[] finalOut = new byte[e]; + System.arraycopy(outBuff, 0, finalOut, 0, e); + return finalOut; + } else { + return outBuff; + } + } + + private static int decode4to3(byte[] source, int srcOffset, byte[] destination, int destOffset) { + if(source == null) { + throw new NullPointerException("Source array was null."); + } + + if(destination == null) { + throw new NullPointerException("Destination array was null."); + } + + if(srcOffset < 0 || srcOffset + 3 >= source.length) { + throw new IllegalArgumentException(String.format("Source array with length %d cannot have offset of %d and still process four bytes.", source.length, srcOffset)); + } + + if(destOffset < 0 || destOffset + 2 >= destination.length) { + throw new IllegalArgumentException(String.format("Destination array with length %d cannot have offset of %d and still store three bytes.", destination.length, destOffset)); + } + + byte[] DECODABET = getDecodabet(); + if(source[srcOffset + 2] == EQUALS_SIGN) { + int outBuff = ((DECODABET[source[srcOffset]] & 0xFF) << 18) | ((DECODABET[source[srcOffset + 1]] & 0xFF) << 12); + destination[destOffset] = (byte) (outBuff >>> 16); + return 1; + } else if(source[srcOffset + 3] == EQUALS_SIGN) { + int outBuff = ((DECODABET[source[srcOffset]] & 0xFF) << 18) | ((DECODABET[source[srcOffset + 1]] & 0xFF) << 12) | ((DECODABET[source[srcOffset + 2]] & 0xFF) << 6); + destination[destOffset] = (byte) (outBuff >>> 16); + destination[destOffset + 1] = (byte) (outBuff >>> 8); + return 2; + } else { + int outBuff = ((DECODABET[source[srcOffset]] & 0xFF) << 18) | ((DECODABET[source[srcOffset + 1]] & 0xFF) << 12) | ((DECODABET[source[srcOffset + 2]] & 0xFF) << 6) | ((DECODABET[source[srcOffset + 3]] & 0xFF)); + destination[destOffset] = (byte) (outBuff >> 16); + destination[destOffset + 1] = (byte) (outBuff >> 8); + destination[destOffset + 2] = (byte) (outBuff); + return 3; + } + } + + public static byte[] decode(byte[] source) throws java.io.IOException { + return decode(source, 0, source.length); + } + + public static byte[] decode(byte[] source, int off, int len) throws java.io.IOException { + if(source == null) { + throw new NullPointerException("Cannot decode null source array."); + } + + if(off < 0 || off + len > source.length) { + throw new IllegalArgumentException(String.format("Source array with length %d cannot have offset of %d and process %d bytes.", source.length, off, len)); + } + + if(len == 0) { + return new byte[0]; + } else if(len < 4) { + throw new IllegalArgumentException("Base64-encoded string must have at least four characters, but length specified was " + len); + } + + byte[] DECODABET = getDecodabet(); + int len34 = len * 3 / 4; + byte[] outBuff = new byte[len34]; + int outBuffPosn = 0; + byte[] b4 = new byte[4]; + int b4Posn = 0; + int i = 0; + byte sbiDecode = 0; + for(i = off; i < off + len; i++) { + sbiDecode = DECODABET[source[i] & 0xFF]; + if(sbiDecode >= WHITE_SPACE_ENC) { + if(sbiDecode >= EQUALS_SIGN_ENC) { + b4[b4Posn++] = source[i]; + if(b4Posn > 3) { + outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn); + b4Posn = 0; + if(source[i] == EQUALS_SIGN) { + break; + } + } + } + } else { + throw new java.io.IOException(String.format("Bad Base64 input character decimal %d in array position %d", source[i] & 0xFF, i)); + } + } + + byte[] out = new byte[outBuffPosn]; + System.arraycopy(outBuff, 0, out, 0, outBuffPosn); + return out; + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/CryptUtil.java b/src/main/java/ch/spacebase/mc/util/CryptUtil.java new file mode 100644 index 00000000..076438e1 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/CryptUtil.java @@ -0,0 +1,104 @@ +package ch.spacebase.mc.util; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; +import java.security.Key; +import java.security.KeyFactory; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.X509EncodedKeySpec; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; + +public class CryptUtil { + + public static SecretKey generateSharedKey() { + try { + KeyGenerator gen = KeyGenerator.getInstance("AES"); + gen.init(128); + return gen.generateKey(); + } catch(NoSuchAlgorithmException e) { + System.err.println("Failed to generate shared key."); + e.printStackTrace(); + return null; + } + } + + public static KeyPair generateKeyPair() { + try { + KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA"); + gen.initialize(1024); + return gen.generateKeyPair(); + } catch(NoSuchAlgorithmException e) { + System.err.println("Failed to generate key pair."); + e.printStackTrace(); + return null; + } + } + + public static PublicKey decodePublicKey(byte bytes[]) throws IOException { + try { + return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(bytes)); + } catch(GeneralSecurityException e) { + throw new IOException("Could not decrypt public key.", e); + } + } + + public static SecretKey decryptSharedKey(PrivateKey privateKey, byte[] sharedKey) { + return new SecretKeySpec(decryptData(privateKey, sharedKey), "AES"); + } + + public static byte[] encryptData(Key key, byte[] data) { + return runEncryption(1, key, data); + } + + public static byte[] decryptData(Key key, byte[] data) { + return runEncryption(2, key, data); + } + + private static byte[] runEncryption(int mode, Key key, byte[] data) { + try { + Cipher cipher = Cipher.getInstance(key.getAlgorithm()); + cipher.init(mode, key); + return cipher.doFinal(data); + } catch(GeneralSecurityException e) { + System.err.println("Failed to run encryption."); + e.printStackTrace(); + return new byte[0]; + } + } + + public static byte[] getServerIdHash(String serverId, PublicKey publicKey, SecretKey secretKey) { + try { + return encrypt("SHA-1", new byte[][] { serverId.getBytes("ISO_8859_1"), secretKey.getEncoded(), publicKey.getEncoded() }); + } catch(UnsupportedEncodingException e) { + System.err.println("Failed to generate server id hash."); + e.printStackTrace(); + return new byte[0]; + } + } + + private static byte[] encrypt(String encryption, byte[]... data) { + try { + MessageDigest digest = MessageDigest.getInstance(encryption); + for(byte array[] : data) { + digest.update(array); + } + + return digest.digest(); + } catch(NoSuchAlgorithmException e) { + System.err.println("Failed to encrypt data."); + e.printStackTrace(); + return null; + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/IOUtils.java b/src/main/java/ch/spacebase/mc/util/IOUtils.java new file mode 100644 index 00000000..09e246ce --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/IOUtils.java @@ -0,0 +1,35 @@ +package ch.spacebase.mc.util; + +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.StringWriter; + +public class IOUtils { + + private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; + + public static void closeQuietly(Closeable close) { + try { + if(close != null) { + close.close(); + } + } catch(IOException e) { + } + } + + public static String toString(InputStream input, String encoding) throws IOException { + StringWriter writer = new StringWriter(); + InputStreamReader in = encoding != null ? new InputStreamReader(input, encoding) : new InputStreamReader(input); + char[] buffer = new char[DEFAULT_BUFFER_SIZE]; + int n = 0; + while(-1 != (n = in.read(buffer))) { + writer.write(buffer, 0, n); + } + + in.close(); + return writer.toString(); + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/NetUtil.java b/src/main/java/ch/spacebase/mc/util/NetUtil.java new file mode 100644 index 00000000..dc1a2db9 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/NetUtil.java @@ -0,0 +1,307 @@ +package ch.spacebase.mc.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +import ch.spacebase.mc.protocol.data.game.Chunk; +import ch.spacebase.mc.protocol.data.game.Coordinates; +import ch.spacebase.mc.protocol.data.game.EntityMetadata; +import ch.spacebase.mc.protocol.data.game.ItemStack; +import ch.spacebase.mc.protocol.data.game.NibbleArray; +import ch.spacebase.opennbt.NBTIO; +import ch.spacebase.opennbt.tag.CompoundTag; +import ch.spacebase.packetlib.io.NetInput; +import ch.spacebase.packetlib.io.NetOutput; + +public class NetUtil { + + /** + * An unfortunately necessary hack value for chunk data packet checks as to whether a packet contains skylight values or not. + */ + public static boolean hasSky = true; + + public static CompoundTag readNBT(NetInput in) throws IOException { + short length = in.readShort(); + if(length < 0) { + return null; + } else { + return (CompoundTag) NBTIO.readTag(new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(in.readBytes(length))))); + } + } + + public static void writeNBT(NetOutput out, CompoundTag tag) throws IOException { + if(tag == null) { + out.writeShort(-1); + } else { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + NBTIO.writeTag(new DataOutputStream(new GZIPOutputStream(output)), tag); + output.close(); + byte bytes[] = output.toByteArray(); + out.writeShort((short) bytes.length); + out.writeBytes(bytes); + } + } + + public static ItemStack readItem(NetInput in) throws IOException { + short item = in.readShort(); + if(item < 0) { + return null; + } else { + return new ItemStack(item, in.readByte(), in.readShort(), readNBT(in)); + } + } + + public static void writeItem(NetOutput out, ItemStack item) throws IOException { + if(item == null) { + out.writeShort(-1); + } else { + out.writeShort(item.getId()); + out.writeByte(item.getAmount()); + out.writeShort(item.getData()); + writeNBT(out, item.getNBT()); + } + } + + public static EntityMetadata[] readEntityMetadata(NetInput in) throws IOException { + List ret = new ArrayList(); + byte b; + while((b = in.readByte()) != 127) { + int typeId = (b & 224) >> 5; + EntityMetadata.Type type = EntityMetadata.Type.values()[typeId]; + int id = b & 31; + Object value = null; + switch(type) { + case BYTE: + value = in.readByte(); + break; + case SHORT: + value = in.readShort(); + break; + case INT: + value = in.readInt(); + break; + case FLOAT: + value = in.readFloat(); + break; + case STRING: + value = in.readString(); + break; + case ITEM: + value = readItem(in); + break; + case COORDINATES: + value = new Coordinates(in.readInt(), in.readInt(), in.readInt()); + break; + default: + throw new IOException("Unknown metadata type id: " + typeId); + } + + ret.add(new EntityMetadata(id, type, value)); + } + + return ret.toArray(new EntityMetadata[ret.size()]); + } + + public static void writeEntityMetadata(NetOutput out, EntityMetadata[] metadata) throws IOException { + for(EntityMetadata meta : metadata) { + int id = (meta.getType().ordinal() << 5 | meta.getId() & 31) & 255; + out.writeByte(id); + switch(meta.getType()) { + case BYTE: + out.writeByte((Byte) meta.getValue()); + break; + case SHORT: + out.writeShort((Short) meta.getValue()); + break; + case INT: + out.writeInt((Integer) meta.getValue()); + break; + case FLOAT: + out.writeFloat((Float) meta.getValue()); + break; + case STRING: + out.writeString((String) meta.getValue()); + break; + case ITEM: + writeItem(out, (ItemStack) meta.getValue()); + break; + case COORDINATES: + Coordinates coords = (Coordinates) meta.getValue(); + out.writeInt(coords.getX()); + out.writeInt(coords.getY()); + out.writeInt(coords.getZ()); + break; + default: + throw new IOException("Unmapped metadata type: " + meta.getType()); + } + } + + out.writeByte(127); + } + + public static ParsedChunkData dataToChunks(NetworkChunkData data) { + Chunk chunks[] = new Chunk[16]; + int pos = 0; + // 0 = Create chunks from mask and get blocks. + // 1 = Get metadata. + // 2 = Get block light. + // 3 = Get sky light. + // 4 = Get extended block data. + for(int pass = 0; pass < 5; pass++) { + for(int ind = 0; ind < 16; ind++) { + if((data.getMask() & 1 << ind) != 0) { + if(pass == 0) { + chunks[ind] = new Chunk(data.getX(), data.getZ(), new byte[4096], new NibbleArray(4096), new NibbleArray(4096), data.hasSkyLight() ? new NibbleArray(4096) : null, (data.getExtendedMask() & 1 << ind) != 0 ? new NibbleArray(4096) : null); + byte[] blocks = chunks[ind].getBlocks(); + System.arraycopy(data.getData(), pos, blocks, 0, blocks.length); + pos += blocks.length; + } + + if(pass == 1) { + NibbleArray metadata = chunks[ind].getMetadata(); + System.arraycopy(data.getData(), pos, metadata.getData(), 0, metadata.getData().length); + pos += metadata.getData().length; + } + + if(pass == 2) { + NibbleArray blocklight = chunks[ind].getBlockLight(); + System.arraycopy(data.getData(), pos, blocklight.getData(), 0, blocklight.getData().length); + pos += blocklight.getData().length; + } + + if(pass == 3 && data.hasSkyLight()) { + NibbleArray skylight = chunks[ind].getSkyLight(); + System.arraycopy(data.getData(), pos, skylight.getData(), 0, skylight.getData().length); + pos += skylight.getData().length; + } + } else if(data.hasBiomes() && chunks[ind] != null) { + chunks[ind] = null; + } + + if(pass == 4) { + if((data.getExtendedMask() & 1 << ind) != 0) { + if(chunks[ind] == null) { + pos += 2048; + } else { + NibbleArray extended = chunks[ind].getExtendedBlocks(); + System.arraycopy(data.getData(), pos, extended.getData(), 0, extended.getData().length); + pos += extended.getData().length; + } + } else if(data.hasBiomes() && chunks[ind] != null && chunks[ind].getExtendedBlocks() != null) { + chunks[ind].deleteExtendedBlocks(); + } + } + } + } + + byte biomeData[] = null; + if(data.hasBiomes()) { + biomeData = new byte[256]; + System.arraycopy(data.getData(), pos, biomeData, 0, biomeData.length); + pos += biomeData.length; + } + + return new ParsedChunkData(chunks, biomeData); + } + + public static NetworkChunkData chunksToData(ParsedChunkData chunks) { + int x = 0; + int z = 0; + int chunkMask = 0; + int extendedChunkMask = 0; + boolean biomes = chunks.getBiomes() != null; + boolean sky = false; + // Determine chunk coordinates. + for(Chunk chunk : chunks.getChunks()) { + if(chunk != null) { + x = chunk.getX(); + z = chunk.getZ(); + } + } + + int length = biomes ? chunks.getBiomes().length : 0; + byte[] data = null; + int pos = 0; + // 0 = Determine length and masks. + // 1 = Add blocks. + // 2 = Add metadata. + // 3 = Add block light. + // 4 = Add sky light. + // 5 = Add extended block data. + for(int pass = 0; pass < 6; pass++) { + for(int ind = 0; ind < chunks.getChunks().length; ++ind) { + Chunk chunk = chunks.getChunks()[ind]; + if(chunk != null && (!biomes || !chunk.isEmpty())) { + if(pass == 0) { + chunkMask |= 1 << ind; + if(chunk.getExtendedBlocks() != null) { + extendedChunkMask |= 1 << ind; + } + + length += chunk.getBlocks().length; + length += chunk.getMetadata().getData().length; + length += chunk.getBlockLight().getData().length; + if(chunk.getSkyLight() != null) { + length += chunk.getSkyLight().getData().length; + } + + if(chunk.getExtendedBlocks() != null) { + length += chunk.getExtendedBlocks().getData().length; + } + } + + if(pass == 1) { + if(data == null) { + data = new byte[length]; + } + + byte[] blocks = chunk.getBlocks(); + System.arraycopy(blocks, 0, data, pos, blocks.length); + pos += blocks.length; + } + + if(pass == 2) { + byte meta[] = chunk.getMetadata().getData(); + System.arraycopy(meta, 0, data, pos, meta.length); + pos += meta.length; + } + + if(pass == 3) { + byte blocklight[] = chunk.getBlockLight().getData(); + System.arraycopy(blocklight, 0, data, pos, blocklight.length); + pos += blocklight.length; + } + + if(pass == 4 && chunk.getSkyLight() != null) { + byte skylight[] = chunk.getSkyLight().getData(); + System.arraycopy(skylight, 0, data, pos, skylight.length); + pos += skylight.length; + sky = true; + } + + if(pass == 5 && chunk.getExtendedBlocks() != null) { + byte extended[] = chunk.getExtendedBlocks().getData(); + System.arraycopy(extended, 0, data, pos, extended.length); + pos += extended.length; + } + } + } + } + + // Add biomes. + if(biomes) { + System.arraycopy(chunks.getBiomes(), 0, data, pos, chunks.getBiomes().length); + pos += chunks.getBiomes().length; + } + + return new NetworkChunkData(x, z, chunkMask, extendedChunkMask, biomes, sky, data); + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/NetworkChunkData.java b/src/main/java/ch/spacebase/mc/util/NetworkChunkData.java new file mode 100644 index 00000000..198e15a7 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/NetworkChunkData.java @@ -0,0 +1,51 @@ +package ch.spacebase.mc.util; + +public class NetworkChunkData { + + private int x; + private int z; + private int mask; + private int extendedMask; + private boolean biomes; + private boolean sky; + private byte data[]; + + public NetworkChunkData(int x, int z, int mask, int extendedMask, boolean biomes, boolean sky, byte data[]) { + this.x = x; + this.z = z; + this.mask = mask; + this.extendedMask = extendedMask; + this.biomes = biomes; + this.sky = sky; + this.data = data; + } + + public int getX() { + return this.x; + } + + public int getZ() { + return this.z; + } + + public int getMask() { + return this.mask; + } + + public int getExtendedMask() { + return this.extendedMask; + } + + public boolean hasBiomes() { + return this.biomes; + } + + public boolean hasSkyLight() { + return this.sky; + } + + public byte[] getData() { + return this.data; + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/ParsedChunkData.java b/src/main/java/ch/spacebase/mc/util/ParsedChunkData.java new file mode 100644 index 00000000..eeaf8b37 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/ParsedChunkData.java @@ -0,0 +1,23 @@ +package ch.spacebase.mc.util; + +import ch.spacebase.mc.protocol.data.game.Chunk; + +public class ParsedChunkData { + + private Chunk chunks[]; + private byte biomes[]; + + public ParsedChunkData(Chunk chunks[], byte biomes[]) { + this.chunks = chunks; + this.biomes = biomes; + } + + public Chunk[] getChunks() { + return this.chunks; + } + + public byte[] getBiomes() { + return this.biomes; + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/URLUtils.java b/src/main/java/ch/spacebase/mc/util/URLUtils.java new file mode 100644 index 00000000..0fcf647e --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/URLUtils.java @@ -0,0 +1,59 @@ +package ch.spacebase.mc.util; + +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLEncoder; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +public class URLUtils { + + public static URL constantURL(String url) { + try { + return new URL(url); + } catch(MalformedURLException e) { + throw new Error("Malformed constant url: " + url); + } + } + + public static URL concatenateURL(URL url, String query) { + try { + return url.getQuery() != null && url.getQuery().length() > 0 ? new URL(url.getProtocol(), url.getHost(), url.getFile() + "&" + query) : new URL(url.getProtocol(), url.getHost(), url.getFile() + "?" + query); + } catch(MalformedURLException e) { + throw new IllegalArgumentException("Concatenated URL was malformed: " + url.toString() + ", " + query); + } + } + + public static String buildQuery(Map query) { + if(query == null) { + return ""; + } else { + StringBuilder builder = new StringBuilder(); + Iterator> it = query.entrySet().iterator(); + while(it.hasNext()) { + Entry entry = it.next(); + if(builder.length() > 0) { + builder.append("&"); + } + + try { + builder.append(URLEncoder.encode(entry.getKey(), "UTF-8")); + } catch(UnsupportedEncodingException e) { + } + + if(entry.getValue() != null) { + builder.append("="); + try { + builder.append(URLEncoder.encode(entry.getValue().toString(), "UTF-8")); + } catch(UnsupportedEncodingException e) { + } + } + } + + return builder.toString(); + } + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/message/ChatColor.java b/src/main/java/ch/spacebase/mc/util/message/ChatColor.java new file mode 100644 index 00000000..68ec7e81 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/message/ChatColor.java @@ -0,0 +1,43 @@ +package ch.spacebase.mc.util.message; + +public enum ChatColor { + + WHITE("white"), + YELLOW("yellow"), + LIGHT_PURPLE("light_purple"), + RED("red"), + AQUA("aqua"), + GREEN("green"), + BLUE("blue"), + DARK_GRAY("dark_gray"), + GRAY("gray"), + GOLD("gold"), + DARK_PURPLE("dark_purple"), + DARK_RED("dark_red"), + DARK_AQUA("dark_aqua"), + DARK_GREEN("dark_green"), + DARK_BLUE("dark_blue"), + BLACK("black"); + + private String color; + + private ChatColor(String color) { + this.color = color; + } + + @Override + public String toString() { + return this.color; + } + + public static ChatColor byValue(String val) { + for(ChatColor color : values()) { + if(color.toString().equals(val)) { + return color; + } + } + + return null; + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/message/ChatFormat.java b/src/main/java/ch/spacebase/mc/util/message/ChatFormat.java new file mode 100644 index 00000000..f961412e --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/message/ChatFormat.java @@ -0,0 +1,22 @@ +package ch.spacebase.mc.util.message; + +public enum ChatFormat { + + BOLD("bold"), + UNDERLINED("underlined"), + STRIKETHROUGH("strikethrough"), + ITALIC("italic"), + OBFUSCATED("obfuscated"); + + private String format; + + private ChatFormat(String format) { + this.format = format; + } + + @Override + public String toString() { + return this.format; + } + +} \ No newline at end of file diff --git a/src/main/java/ch/spacebase/mc/util/message/ClickAction.java b/src/main/java/ch/spacebase/mc/util/message/ClickAction.java new file mode 100644 index 00000000..e1665878 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/message/ClickAction.java @@ -0,0 +1,31 @@ +package ch.spacebase.mc.util.message; + +public enum ClickAction { + + RUN_COMMAND("run_command"), + SUGGEST_COMMAND("suggest_command"), + OPEN_URL("open_url"), + OPEN_FILE("open_file"); + + private String type; + + private ClickAction(String type) { + this.type = type; + } + + @Override + public String toString() { + return this.type; + } + + public static ClickAction byValue(String val) { + for(ClickAction action : values()) { + if(action.toString().equals(val)) { + return action; + } + } + + return null; + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/message/ClickEvent.java b/src/main/java/ch/spacebase/mc/util/message/ClickEvent.java new file mode 100644 index 00000000..0bdac4bb --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/message/ClickEvent.java @@ -0,0 +1,21 @@ +package ch.spacebase.mc.util.message; + +public class ClickEvent { + + private ClickAction action; + private String value; + + public ClickEvent(ClickAction action, String value) { + this.action = action; + this.value = value; + } + + public ClickAction getAction() { + return this.action; + } + + public String getValue() { + return this.value; + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/message/HoverAction.java b/src/main/java/ch/spacebase/mc/util/message/HoverAction.java new file mode 100644 index 00000000..34ee93c8 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/message/HoverAction.java @@ -0,0 +1,30 @@ +package ch.spacebase.mc.util.message; + +public enum HoverAction { + + SHOW_TEXT("show_text"), + SHOW_ITEM("show_item"), + SHOW_ACHIEVEMENT("show_achievement"); + + private String type; + + private HoverAction(String type) { + this.type = type; + } + + @Override + public String toString() { + return this.type; + } + + public static HoverAction byValue(String val) { + for(HoverAction action : values()) { + if(action.toString().equals(val)) { + return action; + } + } + + return null; + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/message/HoverEvent.java b/src/main/java/ch/spacebase/mc/util/message/HoverEvent.java new file mode 100644 index 00000000..e1375020 --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/message/HoverEvent.java @@ -0,0 +1,21 @@ +package ch.spacebase.mc.util.message; + +public class HoverEvent { + + private HoverAction action; + private String value; + + public HoverEvent(HoverAction action, String value) { + this.action = action; + this.value = value; + } + + public HoverAction getAction() { + return this.action; + } + + public String getValue() { + return this.value; + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/message/Message.java b/src/main/java/ch/spacebase/mc/util/message/Message.java new file mode 100644 index 00000000..b700acde --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/message/Message.java @@ -0,0 +1,102 @@ +package ch.spacebase.mc.util.message; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +import java.util.ArrayList; +import java.util.List; + +public class Message { + + private JsonObject json; + + public Message(String text) { + this(text, false); + } + + public Message(String str, boolean tryJson) { + if(tryJson) { + try { + this.json = new Gson().fromJson(str, JsonObject.class); + return; + } catch(Exception e) { + } + } + + this.json = new JsonObject(); + this.json.addProperty("text", str); + } + + public Message(String text, ChatColor color) { + this(text, color, null); + } + + public Message(String text, ChatColor color, List formats) { + this.json = new JsonObject(); + this.json.addProperty("text", text); + this.json.addProperty("color", color != null ? color.toString() : ChatColor.WHITE.toString()); + if(formats != null) { + for(ChatFormat format : formats) { + this.json.addProperty(format.toString(), true); + } + } + } + + public String getText() { + return this.json.get("text").getAsString(); + } + + public ChatColor getColor() { + ChatColor color = ChatColor.byValue(this.json.get("color").getAsString()); + if(color == null) { + return ChatColor.WHITE; + } + + return color; + } + + public List getFormats() { + List ret = new ArrayList(); + for(ChatFormat format : ChatFormat.values()) { + if(this.json.get(format.toString()).getAsBoolean()) { + ret.add(format); + } + } + + return ret; + } + + public void addExtra(MessageExtra extra) { + if(!this.json.has("extra")) { + this.json.add("extra", new JsonArray()); + } + + JsonArray json = (JsonArray) this.json.get("extra"); + json.add(extra.getJson()); + this.json.add("extra", json); + } + + public String getRawText() { + StringBuilder build = new StringBuilder(); + build.append(this.json.get("text").getAsString()); + if(this.json.has("extra")) { + JsonArray extra = (JsonArray) this.json.get("extra"); + for(int index = 0; index < extra.size(); index++) { + build.append(extra.get(index).toString()); + } + } + + return build.toString(); + } + + public JsonObject getJson() { + return this.json; + } + + @Override + public String toString() { + return this.json.toString(); + } + +} diff --git a/src/main/java/ch/spacebase/mc/util/message/MessageExtra.java b/src/main/java/ch/spacebase/mc/util/message/MessageExtra.java new file mode 100644 index 00000000..495fc36b --- /dev/null +++ b/src/main/java/ch/spacebase/mc/util/message/MessageExtra.java @@ -0,0 +1,98 @@ +package ch.spacebase.mc.util.message; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; + +import java.util.ArrayList; +import java.util.List; + +public class MessageExtra { + + private JsonObject json; + + public MessageExtra(String str, boolean json) { + if(json) { + this.json = new Gson().fromJson(str, JsonObject.class); + } else { + this.json = new JsonObject(); + this.json.addProperty("text", str); + this.json.addProperty("color", ChatColor.WHITE.toString()); + } + } + + public MessageExtra(String text, ChatColor color) { + this(text, color, null); + } + + public MessageExtra(String text, ChatColor color, List formats) { + this.json = new JsonObject(); + this.json.addProperty("text", text); + this.json.addProperty("color", color != null ? color.toString() : ChatColor.WHITE.toString()); + if(formats != null) { + for(ChatFormat format : formats) { + this.json.addProperty(format.toString(), true); + } + } + } + + public String getText() { + return this.json.get("text").getAsString(); + } + + public ChatColor getColor() { + ChatColor color = ChatColor.byValue(this.json.get("color").getAsString()); + if(color == null) { + return ChatColor.WHITE; + } + + return color; + } + + public List getFormats() { + List ret = new ArrayList(); + for(ChatFormat format : ChatFormat.values()) { + if(this.json.get(format.toString()).getAsBoolean()) { + ret.add(format); + } + } + + return ret; + } + + public ClickEvent getClickEvent() { + if(!this.json.has("clickEvent")) { + return null; + } + + JsonObject json = this.json.get("clickEvent").getAsJsonObject(); + return new ClickEvent(ClickAction.byValue(json.get("action").getAsString()), json.get("value").getAsString()); + } + + public HoverEvent getHoverEvent() { + if(!this.json.has("hoverEvent")) { + return null; + } + + JsonObject json = this.json.get("hoverEvent").getAsJsonObject(); + return new HoverEvent(HoverAction.byValue(json.get("action").getAsString()), json.get("value").getAsString()); + } + + public void setClickEvent(ClickEvent event) { + JsonObject json = new JsonObject(); + json.addProperty("action", event.getAction().toString()); + json.addProperty("value", event.getValue()); + this.json.add("clickEvent", json); + } + + public void setHoverEvent(HoverEvent event) { + JsonObject json = new JsonObject(); + json.addProperty("action", event.getAction().toString()); + json.addProperty("value", event.getValue()); + this.json.add("hoverEvent", json); + } + + protected JsonObject getJson() { + return this.json; + } + +} diff --git a/src/main/java/ch/spacebase/mcprotocol/event/ConnectEvent.java b/src/main/java/ch/spacebase/mcprotocol/event/ConnectEvent.java deleted file mode 100644 index 00ad97ae..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/event/ConnectEvent.java +++ /dev/null @@ -1,36 +0,0 @@ -package ch.spacebase.mcprotocol.event; - -import ch.spacebase.mcprotocol.net.ServerConnection; - -/** - * Called when a client connects to the server. - */ -public class ConnectEvent extends ProtocolEvent { - - /** - * The client's connection. - */ - private ServerConnection conn; - - /** - * Creates a connect event instance. - * @param conn Connection of the connecting client. - */ - public ConnectEvent(ServerConnection conn) { - this.conn = conn; - } - - /** - * Gets the client's connection. - * @return The client's connection. - */ - public ServerConnection getConnection() { - return this.conn; - } - - @Override - public void call(ServerListener listener) { - listener.onConnect(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/event/DisconnectEvent.java b/src/main/java/ch/spacebase/mcprotocol/event/DisconnectEvent.java deleted file mode 100644 index 210244f1..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/event/DisconnectEvent.java +++ /dev/null @@ -1,51 +0,0 @@ -package ch.spacebase.mcprotocol.event; - -import ch.spacebase.mcprotocol.net.Connection; - -/** - * Called when the connection is disconnected. - */ -public class DisconnectEvent extends ProtocolEvent { - - /** - * The connection that was disconnected. - */ - private Connection conn; - - /** - * The given reason for disconnecting. - */ - private String reason; - - /** - * Creates a new disconnect event instance. - * @param conn Connection that is disconnecting. - * @param reason Reason given for disconnecting. - */ - public DisconnectEvent(Connection conn, String reason) { - this.conn = conn; - this.reason = reason; - } - - /** - * Gets the connection that is disconnecting. - * @return The disconnecting connection. - */ - public Connection getConnection() { - return this.conn; - } - - /** - * Gets the given reason for disconnecting. - * @return The reason for disconnecting. - */ - public String getReason() { - return this.reason; - } - - @Override - public void call(ProtocolListener listener) { - listener.onDisconnect(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/event/PacketReceiveEvent.java b/src/main/java/ch/spacebase/mcprotocol/event/PacketReceiveEvent.java deleted file mode 100644 index 5b1c3c79..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/event/PacketReceiveEvent.java +++ /dev/null @@ -1,50 +0,0 @@ -package ch.spacebase.mcprotocol.event; - -import ch.spacebase.mcprotocol.packet.Packet; - -/** - * Called when a packet is received. - */ -public class PacketReceiveEvent extends ProtocolEvent { - - /** - * The received packet. - */ - private Packet packet; - - /** - * Creates a new packet receive event instance. - * @param packet Packet being received. - */ - public PacketReceiveEvent(Packet packet) { - this.packet = packet; - } - - /** - * Gets the received packet. - * @return The received packet. - */ - public Packet getPacket() { - return this.packet; - } - - /** - * Gets and casts the received packet to the given type. - * @param clazz Class to cast to. - * @return The received packet, or null if it is not of that type. - */ - @SuppressWarnings("unchecked") - public T getPacket(Class clazz) { - try { - return (T) this.packet; - } catch(ClassCastException e) { - return null; - } - } - - @Override - public void call(ProtocolListener listener) { - listener.onPacketReceive(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/event/PacketSendEvent.java b/src/main/java/ch/spacebase/mcprotocol/event/PacketSendEvent.java deleted file mode 100644 index 68401472..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/event/PacketSendEvent.java +++ /dev/null @@ -1,50 +0,0 @@ -package ch.spacebase.mcprotocol.event; - -import ch.spacebase.mcprotocol.packet.Packet; - -/** - * Called when a packet is sent. - */ -public class PacketSendEvent extends ProtocolEvent { - - /** - * The sent packet. - */ - private Packet packet; - - /** - * Creates a new packet send event instance. - * @param packet Packet being sent. - */ - public PacketSendEvent(Packet packet) { - this.packet = packet; - } - - /** - * Gets the sent packet. - * @return The sent packet. - */ - public Packet getPacket() { - return this.packet; - } - - /** - * Gets and casts the sent packet to the given type. - * @param clazz Class to cast to. - * @return The sent packet, or null if it is not of that type. - */ - @SuppressWarnings("unchecked") - public T getPacket(Class clazz) { - try { - return (T) this.packet; - } catch(ClassCastException e) { - return null; - } - } - - @Override - public void call(ProtocolListener listener) { - listener.onPacketSend(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/event/PacketVisitable.java b/src/main/java/ch/spacebase/mcprotocol/event/PacketVisitable.java deleted file mode 100644 index 6d8303c7..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/event/PacketVisitable.java +++ /dev/null @@ -1,11 +0,0 @@ -package ch.spacebase.mcprotocol.event; - -/** - * Visitable interface to allow packets to accept visitors - * - * @author dconnor - */ -public interface PacketVisitable { - - public void accept(PacketVisitor visitor); -} diff --git a/src/main/java/ch/spacebase/mcprotocol/event/PacketVisitor.java b/src/main/java/ch/spacebase/mcprotocol/event/PacketVisitor.java deleted file mode 100644 index 67f2b1ab..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/event/PacketVisitor.java +++ /dev/null @@ -1,175 +0,0 @@ -package ch.spacebase.mcprotocol.event; - -import ch.spacebase.mcprotocol.standard.packet.*; - -/** - * Visitor interface for each packet - * - * @author dconnor - */ -public interface PacketVisitor { - - public void visit(PacketKeepAlive packet); - - public void visit(PacketLogin packet); - - public void visit(PacketHandshake packet); - - public void visit(PacketChat packet); - - public void visit(PacketTimeUpdate packet); - - public void visit(PacketEntityEquipment packet); - - public void visit(PacketSpawnPosition packet); - - public void visit(PacketUseEntity packet); - - public void visit(PacketHealthUpdate packet); - - public void visit(PacketRespawn packet); - - public void visit(PacketPlayer packet); - - public void visit(PacketPlayerPosition packet); - - public void visit(PacketPlayerLook packet); - - public void visit(PacketPlayerPositionLook packet); - - public void visit(PacketPlayerDigging packet); - - public void visit(PacketPlayerBlockPlace packet); - - public void visit(PacketHeldItemChange packet); - - public void visit(PacketUseBed packet); - - public void visit(PacketAnimation packet); - - public void visit(PacketEntityAction packet); - - public void visit(PacketSpawnNamedEntity packet); - - public void visit(PacketCollectItem packet); - - public void visit(PacketSpawnObject packet); - - public void visit(PacketSpawnMob packet); - - public void visit(PacketSpawnPainting packet); - - public void visit(PacketSpawnExpOrb packet); - - public void visit(PacketSteerVehicle packet); - - public void visit(PacketEntityVelocity packet); - - public void visit(PacketDestroyEntity packet); - - public void visit(PacketEntity packet); - - public void visit(PacketEntityRelativeMove packet); - - public void visit(PacketEntityLook packet); - - public void visit(PacketEntityLookRelativeMove packet); - - public void visit(PacketEntityTeleport packet); - - public void visit(PacketEntityHeadYaw packet); - - public void visit(PacketEntityStatus packet); - - public void visit(PacketAttachEntity packet); - - public void visit(PacketEntityMetadata packet); - - public void visit(PacketEntityEffect packet); - - public void visit(PacketRemoveEntityEffect packet); - - public void visit(PacketSetExperience packet); - - public void visit(PacketEntityAttributes packet); - - public void visit(PacketMapChunk packet); - - public void visit(PacketMultiBlockChange packet); - - public void visit(PacketBlockChange packet); - - public void visit(PacketBlockAction packet); - - public void visit(PacketBlockBreakAnimation packet); - - public void visit(PacketMapChunkBulk packet); - - public void visit(PacketExplosion packet); - - public void visit(PacketEffect packet); - - public void visit(PacketNamedSound packet); - - public void visit(PacketSpawnParticle packet); - - public void visit(PacketGameState packet); - - public void visit(PacketLightning packet); - - public void visit(PacketOpenWindow packet); - - public void visit(PacketCloseWindow packet); - - public void visit(PacketWindowClick packet); - - public void visit(PacketSetSlot packet); - - public void visit(PacketWindowItems packet); - - public void visit(PacketWindowProperty packet); - - public void visit(PacketConfirmTransaction packet); - - public void visit(PacketCreativeSlot packet); - - public void visit(PacketEnchantItem packet); - - public void visit(PacketUpdateSign packet); - - public void visit(PacketItemData packet); - - public void visit(PacketUpdateTileEntity packet); - - public void visit(PacketOpenTileEditor packet); - - public void visit(PacketIncrementStatistic packet); - - public void visit(PacketPlayerListItem packet); - - public void visit(PacketPlayerAbilities packet); - - public void visit(PacketTabComplete packet); - - public void visit(PacketClientInfo packet); - - public void visit(PacketClientStatus packet); - - public void visit(PacketScoreboardObjective packet); - - public void visit(PacketUpdateScoreboard packet); - - public void visit(PacketDisplayScoreboard packet); - - public void visit(PacketTeam packet); - - public void visit(PacketPluginMessage packet); - - public void visit(PacketKeyResponse packet); - - public void visit(PacketKeyRequest packet); - - public void visit(PacketServerPing packet); - - public void visit(PacketDisconnect packet); -} diff --git a/src/main/java/ch/spacebase/mcprotocol/event/PacketVisitorAdapter.java b/src/main/java/ch/spacebase/mcprotocol/event/PacketVisitorAdapter.java deleted file mode 100644 index e7d47b8e..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/event/PacketVisitorAdapter.java +++ /dev/null @@ -1,339 +0,0 @@ -package ch.spacebase.mcprotocol.event; - -import ch.spacebase.mcprotocol.standard.packet.PacketAnimation; -import ch.spacebase.mcprotocol.standard.packet.PacketAttachEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketBlockAction; -import ch.spacebase.mcprotocol.standard.packet.PacketBlockBreakAnimation; -import ch.spacebase.mcprotocol.standard.packet.PacketBlockChange; -import ch.spacebase.mcprotocol.standard.packet.PacketChat; -import ch.spacebase.mcprotocol.standard.packet.PacketClientInfo; -import ch.spacebase.mcprotocol.standard.packet.PacketClientStatus; -import ch.spacebase.mcprotocol.standard.packet.PacketCloseWindow; -import ch.spacebase.mcprotocol.standard.packet.PacketCollectItem; -import ch.spacebase.mcprotocol.standard.packet.PacketConfirmTransaction; -import ch.spacebase.mcprotocol.standard.packet.PacketCreativeSlot; -import ch.spacebase.mcprotocol.standard.packet.PacketDestroyEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketDisconnect; -import ch.spacebase.mcprotocol.standard.packet.PacketDisplayScoreboard; -import ch.spacebase.mcprotocol.standard.packet.PacketEffect; -import ch.spacebase.mcprotocol.standard.packet.PacketEnchantItem; -import ch.spacebase.mcprotocol.standard.packet.PacketEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityAction; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityAttributes; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityEffect; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityEquipment; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityHeadYaw; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityLook; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityLookRelativeMove; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityMetadata; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityRelativeMove; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityStatus; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityTeleport; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityVelocity; -import ch.spacebase.mcprotocol.standard.packet.PacketExplosion; -import ch.spacebase.mcprotocol.standard.packet.PacketGameState; -import ch.spacebase.mcprotocol.standard.packet.PacketHandshake; -import ch.spacebase.mcprotocol.standard.packet.PacketHealthUpdate; -import ch.spacebase.mcprotocol.standard.packet.PacketHeldItemChange; -import ch.spacebase.mcprotocol.standard.packet.PacketIncrementStatistic; -import ch.spacebase.mcprotocol.standard.packet.PacketItemData; -import ch.spacebase.mcprotocol.standard.packet.PacketKeepAlive; -import ch.spacebase.mcprotocol.standard.packet.PacketKeyRequest; -import ch.spacebase.mcprotocol.standard.packet.PacketKeyResponse; -import ch.spacebase.mcprotocol.standard.packet.PacketLightning; -import ch.spacebase.mcprotocol.standard.packet.PacketLogin; -import ch.spacebase.mcprotocol.standard.packet.PacketMapChunk; -import ch.spacebase.mcprotocol.standard.packet.PacketMapChunkBulk; -import ch.spacebase.mcprotocol.standard.packet.PacketMultiBlockChange; -import ch.spacebase.mcprotocol.standard.packet.PacketNamedSound; -import ch.spacebase.mcprotocol.standard.packet.PacketOpenTileEditor; -import ch.spacebase.mcprotocol.standard.packet.PacketOpenWindow; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayer; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerAbilities; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerBlockPlace; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerDigging; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerListItem; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerLook; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerPosition; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerPositionLook; -import ch.spacebase.mcprotocol.standard.packet.PacketPluginMessage; -import ch.spacebase.mcprotocol.standard.packet.PacketRemoveEntityEffect; -import ch.spacebase.mcprotocol.standard.packet.PacketRespawn; -import ch.spacebase.mcprotocol.standard.packet.PacketScoreboardObjective; -import ch.spacebase.mcprotocol.standard.packet.PacketServerPing; -import ch.spacebase.mcprotocol.standard.packet.PacketSetExperience; -import ch.spacebase.mcprotocol.standard.packet.PacketSetSlot; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnExpOrb; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnMob; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnNamedEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnObject; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnPainting; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnParticle; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnPosition; -import ch.spacebase.mcprotocol.standard.packet.PacketSteerVehicle; -import ch.spacebase.mcprotocol.standard.packet.PacketTabComplete; -import ch.spacebase.mcprotocol.standard.packet.PacketTeam; -import ch.spacebase.mcprotocol.standard.packet.PacketTimeUpdate; -import ch.spacebase.mcprotocol.standard.packet.PacketUpdateScoreboard; -import ch.spacebase.mcprotocol.standard.packet.PacketUpdateSign; -import ch.spacebase.mcprotocol.standard.packet.PacketUpdateTileEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketUseBed; -import ch.spacebase.mcprotocol.standard.packet.PacketUseEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketWindowClick; -import ch.spacebase.mcprotocol.standard.packet.PacketWindowItems; -import ch.spacebase.mcprotocol.standard.packet.PacketWindowProperty; - -/** - * Empty implementation of the PacketVisitor interface for convenience. Usually - * used when most methods are not implemented. - * - * @author dconnor - */ -public class PacketVisitorAdapter implements PacketVisitor { - - public void visit(PacketKeepAlive packet) { - } - - public void visit(PacketLogin packet) { - } - - public void visit(PacketHandshake packet) { - } - - public void visit(PacketChat packet) { - } - - public void visit(PacketTimeUpdate packet) { - } - - public void visit(PacketEntityEquipment packet) { - } - - public void visit(PacketSpawnPosition packet) { - } - - public void visit(PacketUseEntity packet) { - } - - public void visit(PacketHealthUpdate packet) { - } - - public void visit(PacketRespawn packet) { - } - - public void visit(PacketPlayer packet) { - } - - public void visit(PacketPlayerPosition packet) { - } - - public void visit(PacketPlayerLook packet) { - } - - public void visit(PacketPlayerPositionLook packet) { - } - - public void visit(PacketPlayerDigging packet) { - } - - public void visit(PacketPlayerBlockPlace packet) { - } - - public void visit(PacketHeldItemChange packet) { - } - - public void visit(PacketUseBed packet) { - } - - public void visit(PacketAnimation packet) { - } - - public void visit(PacketEntityAction packet) { - } - - public void visit(PacketSpawnNamedEntity packet) { - } - - public void visit(PacketCollectItem packet) { - } - - public void visit(PacketSpawnObject packet) { - } - - public void visit(PacketSpawnMob packet) { - } - - public void visit(PacketSpawnPainting packet) { - } - - public void visit(PacketSpawnExpOrb packet) { - } - - public void visit(PacketSteerVehicle packet) { - } - - public void visit(PacketEntityVelocity packet) { - } - - public void visit(PacketDestroyEntity packet) { - } - - public void visit(PacketEntity packet) { - } - - public void visit(PacketEntityRelativeMove packet) { - } - - public void visit(PacketEntityLook packet) { - } - - public void visit(PacketEntityLookRelativeMove packet) { - } - - public void visit(PacketEntityTeleport packet) { - } - - public void visit(PacketEntityHeadYaw packet) { - } - - public void visit(PacketEntityStatus packet) { - } - - public void visit(PacketAttachEntity packet) { - } - - public void visit(PacketEntityMetadata packet) { - } - - public void visit(PacketEntityEffect packet) { - } - - public void visit(PacketRemoveEntityEffect packet) { - } - - public void visit(PacketSetExperience packet) { - } - - public void visit(PacketEntityAttributes packet) { - } - - public void visit(PacketMapChunk packet) { - } - - public void visit(PacketMultiBlockChange packet) { - } - - public void visit(PacketBlockChange packet) { - } - - public void visit(PacketBlockAction packet) { - } - - public void visit(PacketBlockBreakAnimation packet) { - } - - public void visit(PacketMapChunkBulk packet) { - } - - public void visit(PacketExplosion packet) { - } - - public void visit(PacketEffect packet) { - } - - public void visit(PacketNamedSound packet) { - } - - public void visit(PacketSpawnParticle packet) { - } - - public void visit(PacketGameState packet) { - } - - public void visit(PacketLightning packet) { - } - - public void visit(PacketOpenWindow packet) { - } - - public void visit(PacketCloseWindow packet) { - } - - public void visit(PacketWindowClick packet) { - } - - public void visit(PacketSetSlot packet) { - } - - public void visit(PacketWindowItems packet) { - } - - public void visit(PacketWindowProperty packet) { - } - - public void visit(PacketConfirmTransaction packet) { - } - - public void visit(PacketCreativeSlot packet) { - } - - public void visit(PacketEnchantItem packet) { - } - - public void visit(PacketUpdateSign packet) { - } - - public void visit(PacketItemData packet) { - } - - public void visit(PacketUpdateTileEntity packet) { - } - - public void visit(PacketOpenTileEditor packet) { - } - - public void visit(PacketIncrementStatistic packet) { - } - - public void visit(PacketPlayerListItem packet) { - } - - public void visit(PacketPlayerAbilities packet) { - } - - public void visit(PacketTabComplete packet) { - } - - public void visit(PacketClientInfo packet) { - } - - public void visit(PacketClientStatus packet) { - } - - public void visit(PacketScoreboardObjective packet) { - } - - public void visit(PacketUpdateScoreboard packet) { - } - - public void visit(PacketDisplayScoreboard packet) { - } - - public void visit(PacketTeam packet) { - } - - public void visit(PacketPluginMessage packet) { - } - - public void visit(PacketKeyResponse packet) { - } - - public void visit(PacketKeyRequest packet) { - } - - public void visit(PacketServerPing packet) { - } - - public void visit(PacketDisconnect packet) { - } -} diff --git a/src/main/java/ch/spacebase/mcprotocol/event/ProtocolEvent.java b/src/main/java/ch/spacebase/mcprotocol/event/ProtocolEvent.java deleted file mode 100644 index b9770512..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/event/ProtocolEvent.java +++ /dev/null @@ -1,11 +0,0 @@ -package ch.spacebase.mcprotocol.event; - -/** - * An event relating to protocol. - * @param The type of listener used to listen to this event. - */ -public abstract class ProtocolEvent { - - public abstract void call(T listener); - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/event/ProtocolListener.java b/src/main/java/ch/spacebase/mcprotocol/event/ProtocolListener.java deleted file mode 100644 index 00a714a7..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/event/ProtocolListener.java +++ /dev/null @@ -1,26 +0,0 @@ -package ch.spacebase.mcprotocol.event; - -/** - * A listener for general connection protocol events. - */ -public abstract class ProtocolListener { - - /** - * Called when a packet is received. - * @param event The called event. - */ - public abstract void onPacketReceive(PacketReceiveEvent event); - - /** - * Called when a packet is sent. - * @param event The called event. - */ - public abstract void onPacketSend(PacketSendEvent event); - - /** - * Called when a connection is disconnected. - * @param event The called event. - */ - public abstract void onDisconnect(DisconnectEvent event); - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/event/ServerListener.java b/src/main/java/ch/spacebase/mcprotocol/event/ServerListener.java deleted file mode 100644 index b1e379e3..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/event/ServerListener.java +++ /dev/null @@ -1,14 +0,0 @@ -package ch.spacebase.mcprotocol.event; - -/** - * A listener for server-related events. - */ -public abstract class ServerListener { - - /** - * Called when a client connects to the server. - * @param event The called event. - */ - public abstract void onConnect(ConnectEvent event); - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/exception/ConnectException.java b/src/main/java/ch/spacebase/mcprotocol/exception/ConnectException.java deleted file mode 100644 index 25deeadf..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/exception/ConnectException.java +++ /dev/null @@ -1,27 +0,0 @@ -package ch.spacebase.mcprotocol.exception; - -/** - * An exception thrown when an error occurs while connecting. - */ -public class ConnectException extends Exception { - - private static final long serialVersionUID = 1L; - - /** - * Creates a new connect exception. - * @param message Message describing the exception. - */ - public ConnectException(String message) { - super(message); - } - - /** - * Creates a new connect exception. - * @param message Message describing the exception. - * @param e Cause of this exception - */ - public ConnectException(String message, Exception e) { - super(message, e); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/exception/LoginException.java b/src/main/java/ch/spacebase/mcprotocol/exception/LoginException.java deleted file mode 100644 index e4a89bc8..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/exception/LoginException.java +++ /dev/null @@ -1,27 +0,0 @@ -package ch.spacebase.mcprotocol.exception; - -/** - * An exception thrown when there is an error logging in. - */ -public class LoginException extends Exception { - - private static final long serialVersionUID = 1L; - - /** - * Creates a new login exception. - * @param message Message describing the exception. - */ - public LoginException(String message) { - super(message); - } - - /** - * Creates a new login exception. - * @param message Message describing the exception. - * @param e Cause of this exception - */ - public LoginException(String message, Exception e) { - super(message, e); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/exception/OutdatedLibraryException.java b/src/main/java/ch/spacebase/mcprotocol/exception/OutdatedLibraryException.java deleted file mode 100644 index 30ca2e7c..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/exception/OutdatedLibraryException.java +++ /dev/null @@ -1,10 +0,0 @@ -package ch.spacebase.mcprotocol.exception; - -/** - * An exception thrown when the library is out of date. - */ -public class OutdatedLibraryException extends Exception { - - private static final long serialVersionUID = 1L; - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/net/BaseConnection.java b/src/main/java/ch/spacebase/mcprotocol/net/BaseConnection.java deleted file mode 100644 index f708fb59..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/net/BaseConnection.java +++ /dev/null @@ -1,93 +0,0 @@ -package ch.spacebase.mcprotocol.net; - -import java.util.ArrayList; -import java.util.List; - -import ch.spacebase.mcprotocol.event.ProtocolEvent; -import ch.spacebase.mcprotocol.event.ProtocolListener; - -/** - * A basic connection class. - */ -public abstract class BaseConnection implements Connection { - - /** - * The connection's remote host. - */ - private String host; - - /** - * The connection's remote port. - */ - private int port; - - /** - * The connection's username. - */ - private String username; - - /** - * The connection's packets. - */ - private PacketRegistry packets; - - /** - * Listeners listening to this connection. - */ - private List listeners = new ArrayList(); - - /** - * Creates a new connection. - * @param host Host to connect to. - * @param port Port to connect to. - */ - public BaseConnection(PacketRegistry packets, String host, int port) { - this.packets = packets; - this.host = host; - this.port = port; - } - - @Override - public String getRemoteHost() { - return this.host; - } - - @Override - public int getRemotePort() { - return this.port; - } - - @Override - public PacketRegistry getPacketRegistry() { - return this.packets; - } - - @Override - public String getUsername() { - return this.username; - } - - @Override - public void setUsername(String name) { - if(this.username != null) { - return; - } - - this.username = name; - } - - @Override - public void listen(ProtocolListener listener) { - this.listeners.add(listener); - } - - @Override - public > T call(T event) { - for(ProtocolListener listener : this.listeners) { - event.call(listener); - } - - return event; - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/net/Client.java b/src/main/java/ch/spacebase/mcprotocol/net/Client.java deleted file mode 100644 index 378a1593..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/net/Client.java +++ /dev/null @@ -1,19 +0,0 @@ -package ch.spacebase.mcprotocol.net; - -import ch.spacebase.mcprotocol.exception.LoginException; -import ch.spacebase.mcprotocol.exception.OutdatedLibraryException; - -/** - * A client connected to a server. - */ -public interface Client extends Connection { - - /** - * Logs the client in using the given username and password. - * @param username Username to login with. - * @param password Password to login with. - * @return Whether the login was successful. - */ - public boolean login(String username, String password) throws LoginException, OutdatedLibraryException; - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/net/Connection.java b/src/main/java/ch/spacebase/mcprotocol/net/Connection.java deleted file mode 100644 index acfbe35b..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/net/Connection.java +++ /dev/null @@ -1,88 +0,0 @@ -package ch.spacebase.mcprotocol.net; - -import ch.spacebase.mcprotocol.event.ProtocolEvent; -import ch.spacebase.mcprotocol.event.ProtocolListener; -import ch.spacebase.mcprotocol.exception.ConnectException; -import ch.spacebase.mcprotocol.packet.Packet; - -/** - * A network connection. - */ -public interface Connection { - - /** - * Gets the protocol type of this connection. - * @return The connection's protocol type. - */ - public abstract PacketRegistry getPacketRegistry(); - - /** - * Gets the remote host of this connection. - * @return The connection's remote host. - */ - public String getRemoteHost(); - - /** - * Gets the remote port of this connection. - * @return The connection's remote port. - */ - public int getRemotePort(); - - /** - * Adds a listener to listen to this connection. - * @param listener Listener to add. - */ - public void listen(ProtocolListener listener); - - /** - * Calls an event for this connection. - * @param event Event to call. - * @return The event called. - */ - public > T call(T event); - - /** - * Gets the connection's username. - * @return The connection's username. - */ - public String getUsername(); - - /** - * Sets the connection's username if it isn't already set, ignoring any - * authentication. - * @param name The new username. - */ - public void setUsername(String name); - - /** - * Gets whether the connection is connected. - * @return True if the connection is connected. - */ - public boolean isConnected(); - - /** - * Connects this connection. - * @throws ConnectException If a connection error occurs. - */ - public void connect() throws ConnectException; - - /** - * Disconnects this connection, sending a packet with a reason. - * @param reason Reason to disconnect. - */ - public void disconnect(String reason); - - /** - * Disconnects this connection, sending a packet with a reason. - * @param reason Reason to disconnect. - * @param packet Whether a disconnect packet is necessary. - */ - public void disconnect(String reason, boolean packet); - - /** - * Sends a packet. - * @param packet Packet to send. - */ - public void send(Packet packet); - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/net/PacketRegistry.java b/src/main/java/ch/spacebase/mcprotocol/net/PacketRegistry.java deleted file mode 100644 index f8c47b8a..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/net/PacketRegistry.java +++ /dev/null @@ -1,35 +0,0 @@ -package ch.spacebase.mcprotocol.net; - -import ch.spacebase.mcprotocol.packet.Packet; - -public abstract class PacketRegistry { - - /** - * The packet registry array. - */ - @SuppressWarnings("unchecked") - private final Class packets[] = new Class[256]; - - /** - * Registers a packet. - * @param id Id of the packet. - * @param packet Class of the packet. - */ - public void registerPacket(int id, Class packet) { - this.packets[id] = packet; - } - - /** - * Gets a packet class from the given id. - * @param id Id of the packet. - * @return The packet class. - */ - public Class getPacket(int id) { - try { - return this.packets[id]; - } catch(ArrayIndexOutOfBoundsException e) { - return null; - } - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/net/Server.java b/src/main/java/ch/spacebase/mcprotocol/net/Server.java deleted file mode 100644 index d690d86f..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/net/Server.java +++ /dev/null @@ -1,112 +0,0 @@ -package ch.spacebase.mcprotocol.net; - -import java.util.ArrayList; -import java.util.List; - -import ch.spacebase.mcprotocol.event.ProtocolEvent; -import ch.spacebase.mcprotocol.event.ServerListener; - -/** - * A server accepting client connections. - */ -public abstract class Server { - - /** - * The server's host to listen on. - */ - private String host; - - /** - * The server's port to listen on. - */ - private int port; - - /** - * Whether auth is enabled. - */ - private boolean auth; - - /** - * Listeners listening to this server. - */ - private List listeners = new ArrayList(); - - /** - * Creates a new server instance. - * @param host Host to listen on. - * @param port Port to listen on. - */ - public Server(String host, int port, boolean auth) { - this.host = host; - this.port = port; - this.auth = auth; - } - - /** - * Gets the host of this server. - * @return The server's host. - */ - public String getHost() { - return this.host; - } - - /** - * Gets the port of this server. - * @return The server's port. - */ - public int getPort() { - return this.port; - } - - /** - * Gets whether authentication is enabled. - * @return Whether auth is enabled. - */ - public boolean isAuthEnabled() { - return this.auth; - } - - /** - * Adds a listener to listen to this server. - * @param listener Listener to add. - */ - public void listen(ServerListener listener) { - this.listeners.add(listener); - } - - /** - * Calls an event for this server. - * @param event Event to call. - * @return The event called. - */ - public > T call(T event) { - for(ServerListener listener : this.listeners) { - event.call(listener); - } - - return event; - } - - /** - * Gets whether the server is active. - * @return Whether the server is active. - */ - public abstract boolean isActive(); - - /** - * Binds the server to its host and port. - */ - public abstract void bind(); - - /** - * Shuts the server down. - */ - public abstract void shutdown(); - - /** - * Gets a list of connections connected to this server. - * @return The server's connections. - */ - public abstract List getConnections(); - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/net/ServerConnection.java b/src/main/java/ch/spacebase/mcprotocol/net/ServerConnection.java deleted file mode 100644 index fd879fc3..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/net/ServerConnection.java +++ /dev/null @@ -1,16 +0,0 @@ -package ch.spacebase.mcprotocol.net; - -import ch.spacebase.mcprotocol.net.Server; - -/** - * A server's connection to a client. - */ -public interface ServerConnection extends Connection { - - /** - * Gets the server this connection belongs to. - * @return The connection's server. - */ - public Server getServer(); - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/net/io/NetInput.java b/src/main/java/ch/spacebase/mcprotocol/net/io/NetInput.java deleted file mode 100644 index 409d69b4..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/net/io/NetInput.java +++ /dev/null @@ -1,101 +0,0 @@ -package ch.spacebase.mcprotocol.net.io; - -import java.io.IOException; - -/** - * An interface for reading network data. - */ -public interface NetInput { - - /** - * Reads the next boolean. - * @return The next boolean. - * @throws IOException If an I/O error occurs. - */ - public boolean readBoolean() throws IOException; - - /** - * Reads the next byte. - * @return The next byte. - * @throws IOException If an I/O error occurs. - */ - public byte readByte() throws IOException; - - /** - * Reads the next unsigned byte. - * @return The next unsigned byte. - * @throws IOException If an I/O error occurs. - */ - public int readUnsignedByte() throws IOException; - - /** - * Reads the next short. - * @return The next short. - * @throws IOException If an I/O error occurs. - */ - public short readShort() throws IOException; - - /** - * Reads the next unsigned short. - * @return The next unsigned short. - * @throws IOException If an I/O error occurs. - */ - public int readUnsignedShort() throws IOException; - - /** - * Reads the next char. - * @return The next char. - * @throws IOException If an I/O error occurs. - */ - public char readChar() throws IOException; - - /** - * Reads the next integer. - * @return The next integer. - * @throws IOException If an I/O error occurs. - */ - public int readInt() throws IOException; - - /** - * Reads the next long. - * @return The next long. - * @throws IOException If an I/O error occurs. - */ - public long readLong() throws IOException; - - /** - * Reads the next float. - * @return The next float. - * @throws IOException If an I/O error occurs. - */ - public float readFloat() throws IOException; - - /** - * Reads the next double. - * @return The next double. - * @throws IOException If an I/O error occurs. - */ - public double readDouble() throws IOException; - - /** - * Reads the next byte array. - * @param The length of the byte array. - * @return The next byte array. - * @throws IOException If an I/O error occurs. - */ - public byte[] readBytes(int length) throws IOException; - - /** - * Reads the next string. - * @return The next string. - * @throws IOException If an I/O error occurs. - */ - public String readString() throws IOException; - - /** - * Gets the number of available bytes. - * @return The number of available bytes. - */ - public int available() throws IOException; - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/net/io/NetOutput.java b/src/main/java/ch/spacebase/mcprotocol/net/io/NetOutput.java deleted file mode 100644 index 347e8569..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/net/io/NetOutput.java +++ /dev/null @@ -1,91 +0,0 @@ -package ch.spacebase.mcprotocol.net.io; - -import java.io.IOException; - -public interface NetOutput { - - /** - * Writes a boolean. - * @param b Boolean to write. - * @throws IOException If an I/O error occurs. - */ - public void writeBoolean(boolean b) throws IOException; - - /** - * Writes a byte. - * @param b Byte to write. - * @throws IOException If an I/O error occurs. - */ - public void writeByte(int b) throws IOException; - - /** - * Writes a short. - * @param s Short to write. - * @throws IOException If an I/O error occurs. - */ - public void writeShort(int s) throws IOException; - - /** - * Writes a char. - * @param c Char to write. - * @throws IOException If an I/O error occurs. - */ - public void writeChar(int c) throws IOException; - - /** - * Writes a integer. - * @param i Integer to write. - * @throws IOException If an I/O error occurs. - */ - public void writeInt(int i) throws IOException; - - /** - * Writes a long. - * @param l Long to write. - * @throws IOException If an I/O error occurs. - */ - public void writeLong(long l) throws IOException; - - /** - * Writes a float. - * @param f Float to write. - * @throws IOException If an I/O error occurs. - */ - public void writeFloat(float f) throws IOException; - - /** - * Writes a double. - * @param d Double to write. - * @throws IOException If an I/O error occurs. - */ - public void writeDouble(double d) throws IOException; - - /** - * Writes a byte array. - * @param b Byte array to write. - * @throws IOException If an I/O error occurs. - */ - public void writeBytes(byte b[]) throws IOException; - - /** - * Writes a byte array, using the given amount of bytes. - * @param b Byte array to write. - * @param length Bytes to write. - * @throws IOException If an I/O error occurs. - */ - public void writeBytes(byte b[], int length) throws IOException; - - /** - * Writes a string. - * @param s String to write. - * @throws IOException If an I/O error occurs. - */ - public void writeString(String s) throws IOException; - - /** - * Flushes the output. - * @throws IOException If an I/O error occurs. - */ - public void flush() throws IOException; - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/packet/Packet.java b/src/main/java/ch/spacebase/mcprotocol/packet/Packet.java deleted file mode 100644 index 09dd1ce5..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/packet/Packet.java +++ /dev/null @@ -1,53 +0,0 @@ -package ch.spacebase.mcprotocol.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitable; -import java.io.IOException; -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; - -/** - * A network data packet. - */ -public abstract class Packet implements PacketVisitable { - - /** - * Creates an empty packet for reading to. - */ - public Packet() { - } - - /** - * Reads the packet's data from the given input. - * @param in Input to read from. - * @throws IOException If an I/O error occurs. - */ - public abstract void read(NetInput in) throws IOException; - - /** - * Writes the packet's data to the given output. - * @param out Output to write to. - * @throws IOException If an I/O error occurs. - */ - public abstract void write(NetOutput out) throws IOException; - - /** - * Handles this packet when received by a client. - * @param conn Client receiving the packet. - */ - public abstract void handleClient(Client conn); - - /** - * Handles this packet when received by a server. - * @param conn Client connection sending the packet. - */ - public abstract void handleServer(ServerConnection conn); - - /** - * Gets the id of this packet. - * @return The packet's id. - */ - public abstract int getId(); - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/StandardClient.java b/src/main/java/ch/spacebase/mcprotocol/standard/StandardClient.java deleted file mode 100644 index f4c84bc1..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/StandardClient.java +++ /dev/null @@ -1,222 +0,0 @@ -package ch.spacebase.mcprotocol.standard; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.Socket; -import java.net.URL; -import java.net.URLEncoder; -import java.net.UnknownHostException; - -import ch.spacebase.mcprotocol.exception.ConnectException; -import ch.spacebase.mcprotocol.exception.LoginException; -import ch.spacebase.mcprotocol.exception.OutdatedLibraryException; -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.standard.packet.PacketHandshake; -import ch.spacebase.mcprotocol.util.Constants; -import ch.spacebase.mcprotocol.util.Util; - -/** - * A client implementing standard Minecraft protocol. - */ -public class StandardClient extends StandardConnection implements Client { - - /** - * The client's session id. - */ - private String sessionId; - - /** - * Whether the client is logged in. - */ - private boolean loggedIn; - - /** - * Creates a new standard client. - * @param host Host to connect to. - * @param port Port to connect to. - */ - public StandardClient(String host, int port) { - super(host, port); - } - - /** - * Gets the client's session id. - * @return The client's session id. - */ - public String getSessionId() { - return this.sessionId; - } - - @Override - public boolean login(String username, String password) throws LoginException, OutdatedLibraryException { - if(this.loggedIn || this.getUsername() != null) { - throw new IllegalStateException("Already logged in with username: " + this.getUsername()); - } - - URL url = null; - - try { - url = new URL("https://login.minecraft.net/"); - } catch(MalformedURLException e) { - throw new LoginException("Login URL is malformed?", e); - } - - String params = ""; - - try { - params = "user=" + URLEncoder.encode(username, "UTF-8") + "&password=" + URLEncoder.encode(password, "UTF-8") + "&version=" + Constants.LAUNCHER_VERSION; - } catch(UnsupportedEncodingException e) { - throw new LoginException("UTF-8 unsupported", e); - } - - HttpURLConnection conn = null; - - try { - Util.logger().info("Sending info to login.minecraft.net..."); - conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - conn.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length)); - conn.setRequestProperty("Content-Language", "en-US"); - conn.setUseCaches(false); - conn.setDoInput(true); - conn.setDoOutput(true); - conn.setReadTimeout(1000 * 60 * 10); - - conn.connect(); - - DataOutputStream out = new DataOutputStream(conn.getOutputStream()); - out.writeBytes(params); - out.flush(); - out.close(); - - if(conn.getResponseCode() != 200) { - throw new LoginException("Login returned response " + conn.getResponseCode() + ": " + conn.getResponseMessage()); - } - - BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); - StringBuilder build = new StringBuilder(); - - char[] buffer = new char[1024]; - int length = 0; - while((length = reader.read(buffer)) != -1) { - build.append(buffer, 0, length); - } - - String result = build.toString(); - if(result.contains(":")) { - String[] values = result.split(":"); - - try { - this.setUsername(values[2].trim()); - this.sessionId = values[3].trim(); - this.loggedIn = true; - - new Thread(new KeepAliveTask()).start(); - } catch(ArrayIndexOutOfBoundsException e) { - throw new LoginException("Response contained incorrect amount of parameters: " + result); - } - - Util.logger().info("Finished logging in to minecraft.net"); - return true; - } else { - if(result.trim().equals("Old version")) { - throw new OutdatedLibraryException(); - } else { - throw new LoginException(result.trim()); - } - } - } catch(IOException e) { - throw new LoginException("Failed to login", e); - } finally { - if(conn != null) conn.disconnect(); - conn = null; - } - } - - @Override - public void disconnect(String reason, boolean packet) { - this.loggedIn = false; - super.disconnect(reason, packet); - } - - /** - * A task that keeps the client's minecraft.net session alive. - */ - private class KeepAliveTask implements Runnable { - /** - * The minecraft.net session URL. - */ - private URL url; - - /** - * The time when a keep alive was last sent. - */ - private long last; - - /** - * Creates a new keep alive task runnable. - * @throws LoginException If a login error occurs. - */ - public KeepAliveTask() throws LoginException { - try { - this.url = new URL("https://login.minecraft.net/"); - } catch(MalformedURLException e) { - throw new LoginException("Failed to create keep alive URL!", e); - } - } - - @Override - public void run() { - this.last = System.currentTimeMillis(); - while(loggedIn) { - if(System.currentTimeMillis() - this.last >= 300000) { - HttpURLConnection conn = null; - - try { - conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod("POST"); - conn.setUseCaches(false); - conn.setDoInput(true); - conn.setDoOutput(true); - conn.setReadTimeout(1000 * 60 * 10); - conn.connect(); - } catch(IOException e) { - Util.logger().severe("Failed to send keep alive to login.minecraft.net!"); - e.printStackTrace(); - } finally { - if(conn != null) conn.disconnect(); - conn = null; - } - } - - try { - Thread.sleep(2); - } catch(InterruptedException e) { - } - } - } - } - - @Override - public void connect() throws ConnectException { - try { - Socket sock = new Socket(InetAddress.getByName(this.getRemoteHost()), this.getRemotePort()); - sock.setSoTimeout(30000); - sock.setTrafficClass(24); - super.connect(sock); - this.send(new PacketHandshake(this.getUsername(), this.getRemoteHost(), this.getRemotePort())); - } catch(UnknownHostException e) { - throw new ConnectException("Unknown host: " + this.getRemoteHost()); - } catch(IOException e) { - throw new ConnectException("Failed to open stream: " + this.getRemoteHost(), e); - } - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/StandardConnection.java b/src/main/java/ch/spacebase/mcprotocol/standard/StandardConnection.java deleted file mode 100644 index 8c5cc453..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/StandardConnection.java +++ /dev/null @@ -1,263 +0,0 @@ -package ch.spacebase.mcprotocol.standard; - -import java.io.EOFException; -import java.io.IOException; -import java.net.Socket; -import java.net.UnknownHostException; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; - -import javax.crypto.SecretKey; - -import org.bouncycastle.crypto.BufferedBlockCipher; -import org.bouncycastle.crypto.engines.AESFastEngine; -import org.bouncycastle.crypto.io.CipherInputStream; -import org.bouncycastle.crypto.io.CipherOutputStream; -import org.bouncycastle.crypto.modes.CFBBlockCipher; -import org.bouncycastle.crypto.params.KeyParameter; -import org.bouncycastle.crypto.params.ParametersWithIV; - -import ch.spacebase.mcprotocol.event.DisconnectEvent; -import ch.spacebase.mcprotocol.event.PacketReceiveEvent; -import ch.spacebase.mcprotocol.event.PacketSendEvent; -import ch.spacebase.mcprotocol.exception.ConnectException; -import ch.spacebase.mcprotocol.net.BaseConnection; -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.Connection; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.io.StandardInput; -import ch.spacebase.mcprotocol.standard.io.StandardOutput; -import ch.spacebase.mcprotocol.standard.packet.PacketDisconnect; -import ch.spacebase.mcprotocol.util.Util; - -/** - * A connection implementing standard Minecraft protocol. - */ -public abstract class StandardConnection extends BaseConnection { - - /** - * The connection's socket. - */ - private Socket sock; - - /** - * The connection's input stream. - */ - private StandardInput input; - - /** - * The connection's output stream. - */ - private StandardOutput output; - - /** - * The connection's packet write queue. - */ - private Queue packets = new ConcurrentLinkedQueue(); - - /** - * Whether the connection is writing. - */ - private boolean writing = false; - - /** - * Whether the connection is connected. - */ - private boolean connected = false; - - /** - * The connection's secret key. - */ - private SecretKey key; - - /** - * Creates a new standard connection. - * @param host Host to connect to. - * @param port Port to connect to. - */ - public StandardConnection(String host, int port) { - super(new StandardPackets(), host, port); - } - - @Override - public boolean isConnected() { - return this.connected; - } - - /** - * Connects using the given socket. - * @param sock Socket to use. - * @throws ConnectException If a connection error occurs. - */ - protected void connect(Socket sock) throws ConnectException { - this.sock = sock; - try { - this.input = new StandardInput(this.sock.getInputStream()); - this.output = new StandardOutput(this.sock.getOutputStream()); - this.connected = true; - new ListenThread().start(); - new WriteThread().start(); - } catch(UnknownHostException e) { - throw new ConnectException("Unknown host: " + this.getRemoteHost()); - } catch(IOException e) { - throw new ConnectException("Failed to open stream: " + this.getRemoteHost(), e); - } - } - - @Override - public void disconnect(String reason) { - this.disconnect(reason, true); - } - - @Override - public void disconnect(String reason, boolean packet) { - this.packets.clear(); - if(packet && this.isConnected()) { - this.send(new PacketDisconnect(reason)); - } - - new CloseThread().start(); - this.connected = false; - this.call(new DisconnectEvent(this, reason)); - } - - @Override - public void send(Packet packet) { - this.packets.add(packet); - } - - /** - * Gets the protocol's secret key. - * @return The protocol's secret key. - */ - public SecretKey getSecretKey() { - return this.key; - } - - /** - * Sets the protocol's secret key. - * @param key The new secret key. - */ - public void setSecretKey(SecretKey key) { - this.key = key; - } - - /** - * Enabled AES encryption on the connection. - * @param conn Connection to enable AES on. - */ - public void setAES(Connection conn) { - BufferedBlockCipher in = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8)); - in.init(false, new ParametersWithIV(new KeyParameter(this.key.getEncoded()), this.key.getEncoded(), 0, 16)); - BufferedBlockCipher out = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8)); - out.init(true, new ParametersWithIV(new KeyParameter(this.key.getEncoded()), this.key.getEncoded(), 0, 16)); - - this.input = new StandardInput(new CipherInputStream(this.input.getStream(), in)); - this.output = new StandardOutput(new CipherOutputStream(this.output.getStream(), out)); - } - - /** - * A thread listening for incoming packets. - */ - private class ListenThread extends Thread { - @Override - public void run() { - while(isConnected()) { - try { - int opcode = input.readUnsignedByte(); - if(opcode < 0) { - continue; - } - - if(getPacketRegistry().getPacket(opcode) == null) { - Util.logger().severe("Bad packet ID: " + opcode); - disconnect("Bad packet ID: " + opcode); - return; - } - - Packet packet = getPacketRegistry().getPacket(opcode).newInstance(); - packet.read(input); - call(new PacketReceiveEvent(packet)); - if(StandardConnection.this instanceof Client) { - packet.handleClient((Client) StandardConnection.this); - } else if(StandardConnection.this instanceof ServerConnection) { - packet.handleServer((ServerConnection) StandardConnection.this); - } - } catch(EOFException e) { - disconnect("End of Stream"); - } catch(Exception e) { - Util.logger().severe("Error while listening to connection!"); - e.printStackTrace(); - disconnect("Error while listening to connection!"); - } - - try { - Thread.sleep(2); - } catch(InterruptedException e) { - } - } - } - } - - /** - * A thread writing outgoing packets. - */ - private class WriteThread extends Thread { - @Override - public void run() { - while(isConnected()) { - if(packets.size() > 0) { - writing = true; - Packet packet = packets.poll(); - call(new PacketSendEvent(packet)); - - try { - output.writeByte(packet.getId()); - packet.write(output); - output.flush(); - } catch(Exception e) { - Util.logger().severe("Error while writing packet \"" + packet.getId() + "\"!"); - e.printStackTrace(); - disconnect("Error while writing packet."); - } - - writing = false; - } - - try { - Thread.sleep(2); - } catch(InterruptedException e) { - } - - writing = false; - } - } - } - - /** - * A thread that waits for the connection to finish writing before closing - * it. - */ - private class CloseThread extends Thread { - @Override - public void run() { - while(writing) { - try { - Thread.sleep(2); - } catch(InterruptedException e) { - } - } - - try { - sock.close(); - } catch(IOException e) { - System.err.println("Failed to close socket."); - e.printStackTrace(); - } - - connected = false; - } - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/StandardPackets.java b/src/main/java/ch/spacebase/mcprotocol/standard/StandardPackets.java deleted file mode 100644 index 12b244a1..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/StandardPackets.java +++ /dev/null @@ -1,177 +0,0 @@ -package ch.spacebase.mcprotocol.standard; - -import ch.spacebase.mcprotocol.net.PacketRegistry; -import ch.spacebase.mcprotocol.standard.packet.PacketAnimation; -import ch.spacebase.mcprotocol.standard.packet.PacketAttachEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketBlockAction; -import ch.spacebase.mcprotocol.standard.packet.PacketBlockBreakAnimation; -import ch.spacebase.mcprotocol.standard.packet.PacketBlockChange; -import ch.spacebase.mcprotocol.standard.packet.PacketChat; -import ch.spacebase.mcprotocol.standard.packet.PacketClientInfo; -import ch.spacebase.mcprotocol.standard.packet.PacketClientStatus; -import ch.spacebase.mcprotocol.standard.packet.PacketCloseWindow; -import ch.spacebase.mcprotocol.standard.packet.PacketCollectItem; -import ch.spacebase.mcprotocol.standard.packet.PacketConfirmTransaction; -import ch.spacebase.mcprotocol.standard.packet.PacketCreativeSlot; -import ch.spacebase.mcprotocol.standard.packet.PacketDestroyEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketDisconnect; -import ch.spacebase.mcprotocol.standard.packet.PacketDisplayScoreboard; -import ch.spacebase.mcprotocol.standard.packet.PacketEffect; -import ch.spacebase.mcprotocol.standard.packet.PacketEnchantItem; -import ch.spacebase.mcprotocol.standard.packet.PacketEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityAction; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityEffect; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityEquipment; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityHeadYaw; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityLook; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityLookRelativeMove; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityMetadata; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityAttributes; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityRelativeMove; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityStatus; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityTeleport; -import ch.spacebase.mcprotocol.standard.packet.PacketEntityVelocity; -import ch.spacebase.mcprotocol.standard.packet.PacketExplosion; -import ch.spacebase.mcprotocol.standard.packet.PacketGameState; -import ch.spacebase.mcprotocol.standard.packet.PacketHandshake; -import ch.spacebase.mcprotocol.standard.packet.PacketHealthUpdate; -import ch.spacebase.mcprotocol.standard.packet.PacketHeldItemChange; -import ch.spacebase.mcprotocol.standard.packet.PacketIncrementStatistic; -import ch.spacebase.mcprotocol.standard.packet.PacketItemData; -import ch.spacebase.mcprotocol.standard.packet.PacketKeepAlive; -import ch.spacebase.mcprotocol.standard.packet.PacketKeyRequest; -import ch.spacebase.mcprotocol.standard.packet.PacketKeyResponse; -import ch.spacebase.mcprotocol.standard.packet.PacketLightning; -import ch.spacebase.mcprotocol.standard.packet.PacketLogin; -import ch.spacebase.mcprotocol.standard.packet.PacketMapChunk; -import ch.spacebase.mcprotocol.standard.packet.PacketMapChunkBulk; -import ch.spacebase.mcprotocol.standard.packet.PacketMultiBlockChange; -import ch.spacebase.mcprotocol.standard.packet.PacketNamedSound; -import ch.spacebase.mcprotocol.standard.packet.PacketOpenTileEditor; -import ch.spacebase.mcprotocol.standard.packet.PacketOpenWindow; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayer; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerAbilities; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerBlockPlace; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerDigging; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerListItem; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerLook; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerPosition; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerPositionLook; -import ch.spacebase.mcprotocol.standard.packet.PacketPluginMessage; -import ch.spacebase.mcprotocol.standard.packet.PacketRemoveEntityEffect; -import ch.spacebase.mcprotocol.standard.packet.PacketRespawn; -import ch.spacebase.mcprotocol.standard.packet.PacketScoreboardObjective; -import ch.spacebase.mcprotocol.standard.packet.PacketServerPing; -import ch.spacebase.mcprotocol.standard.packet.PacketSetExperience; -import ch.spacebase.mcprotocol.standard.packet.PacketSetSlot; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnExpOrb; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnMob; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnNamedEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnObject; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnPainting; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnParticle; -import ch.spacebase.mcprotocol.standard.packet.PacketSpawnPosition; -import ch.spacebase.mcprotocol.standard.packet.PacketSteerVehicle; -import ch.spacebase.mcprotocol.standard.packet.PacketTabComplete; -import ch.spacebase.mcprotocol.standard.packet.PacketTeam; -import ch.spacebase.mcprotocol.standard.packet.PacketTimeUpdate; -import ch.spacebase.mcprotocol.standard.packet.PacketUpdateScoreboard; -import ch.spacebase.mcprotocol.standard.packet.PacketUpdateSign; -import ch.spacebase.mcprotocol.standard.packet.PacketUpdateTileEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketUseBed; -import ch.spacebase.mcprotocol.standard.packet.PacketUseEntity; -import ch.spacebase.mcprotocol.standard.packet.PacketWindowClick; -import ch.spacebase.mcprotocol.standard.packet.PacketWindowItems; -import ch.spacebase.mcprotocol.standard.packet.PacketWindowProperty; - -/** - * A packet registry containing standard Minecraft packets. - */ -public class StandardPackets extends PacketRegistry { - - public StandardPackets() { - this.registerPacket(0, PacketKeepAlive.class); - this.registerPacket(1, PacketLogin.class); - this.registerPacket(2, PacketHandshake.class); - this.registerPacket(3, PacketChat.class); - this.registerPacket(4, PacketTimeUpdate.class); - this.registerPacket(5, PacketEntityEquipment.class); - this.registerPacket(6, PacketSpawnPosition.class); - this.registerPacket(7, PacketUseEntity.class); - this.registerPacket(8, PacketHealthUpdate.class); - this.registerPacket(9, PacketRespawn.class); - this.registerPacket(10, PacketPlayer.class); - this.registerPacket(11, PacketPlayerPosition.class); - this.registerPacket(12, PacketPlayerLook.class); - this.registerPacket(13, PacketPlayerPositionLook.class); - this.registerPacket(14, PacketPlayerDigging.class); - this.registerPacket(15, PacketPlayerBlockPlace.class); - this.registerPacket(16, PacketHeldItemChange.class); - this.registerPacket(17, PacketUseBed.class); - this.registerPacket(18, PacketAnimation.class); - this.registerPacket(19, PacketEntityAction.class); - this.registerPacket(20, PacketSpawnNamedEntity.class); - this.registerPacket(22, PacketCollectItem.class); - this.registerPacket(23, PacketSpawnObject.class); - this.registerPacket(24, PacketSpawnMob.class); - this.registerPacket(25, PacketSpawnPainting.class); - this.registerPacket(26, PacketSpawnExpOrb.class); - this.registerPacket(27, PacketSteerVehicle.class); - this.registerPacket(28, PacketEntityVelocity.class); - this.registerPacket(29, PacketDestroyEntity.class); - this.registerPacket(30, PacketEntity.class); - this.registerPacket(31, PacketEntityRelativeMove.class); - this.registerPacket(32, PacketEntityLook.class); - this.registerPacket(33, PacketEntityLookRelativeMove.class); - this.registerPacket(34, PacketEntityTeleport.class); - this.registerPacket(35, PacketEntityHeadYaw.class); - this.registerPacket(38, PacketEntityStatus.class); - this.registerPacket(39, PacketAttachEntity.class); - this.registerPacket(40, PacketEntityMetadata.class); - this.registerPacket(41, PacketEntityEffect.class); - this.registerPacket(42, PacketRemoveEntityEffect.class); - this.registerPacket(43, PacketSetExperience.class); - this.registerPacket(44, PacketEntityAttributes.class); - this.registerPacket(51, PacketMapChunk.class); - this.registerPacket(52, PacketMultiBlockChange.class); - this.registerPacket(53, PacketBlockChange.class); - this.registerPacket(54, PacketBlockAction.class); - this.registerPacket(55, PacketBlockBreakAnimation.class); - this.registerPacket(56, PacketMapChunkBulk.class); - this.registerPacket(60, PacketExplosion.class); - this.registerPacket(61, PacketEffect.class); - this.registerPacket(62, PacketNamedSound.class); - this.registerPacket(63, PacketSpawnParticle.class); - this.registerPacket(70, PacketGameState.class); - this.registerPacket(71, PacketLightning.class); - this.registerPacket(100, PacketOpenWindow.class); - this.registerPacket(101, PacketCloseWindow.class); - this.registerPacket(102, PacketWindowClick.class); - this.registerPacket(103, PacketSetSlot.class); - this.registerPacket(104, PacketWindowItems.class); - this.registerPacket(105, PacketWindowProperty.class); - this.registerPacket(106, PacketConfirmTransaction.class); - this.registerPacket(107, PacketCreativeSlot.class); - this.registerPacket(108, PacketEnchantItem.class); - this.registerPacket(130, PacketUpdateSign.class); - this.registerPacket(131, PacketItemData.class); - this.registerPacket(132, PacketUpdateTileEntity.class); - this.registerPacket(133, PacketOpenTileEditor.class); - this.registerPacket(200, PacketIncrementStatistic.class); - this.registerPacket(201, PacketPlayerListItem.class); - this.registerPacket(202, PacketPlayerAbilities.class); - this.registerPacket(203, PacketTabComplete.class); - this.registerPacket(204, PacketClientInfo.class); - this.registerPacket(205, PacketClientStatus.class); - this.registerPacket(206, PacketScoreboardObjective.class); - this.registerPacket(207, PacketUpdateScoreboard.class); - this.registerPacket(208, PacketDisplayScoreboard.class); - this.registerPacket(209, PacketTeam.class); - this.registerPacket(250, PacketPluginMessage.class); - this.registerPacket(252, PacketKeyResponse.class); - this.registerPacket(253, PacketKeyRequest.class); - this.registerPacket(254, PacketServerPing.class); - this.registerPacket(255, PacketDisconnect.class); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/StandardServer.java b/src/main/java/ch/spacebase/mcprotocol/standard/StandardServer.java deleted file mode 100644 index f14c984b..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/StandardServer.java +++ /dev/null @@ -1,139 +0,0 @@ -package ch.spacebase.mcprotocol.standard; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.NoSuchAlgorithmException; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import ch.spacebase.mcprotocol.event.ConnectEvent; -import ch.spacebase.mcprotocol.net.Server; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.util.Util; - -/** - * A server implementing standard Minecraft protocol. - */ -public class StandardServer extends Server { - - /** - * Whether the server is online. - */ - private boolean online = true; - - /** - * The connections connected to the server. - */ - private List connections = new CopyOnWriteArrayList(); - - /** - * The server's key pair. - */ - private KeyPair keys; - - /** - * Creates a new standard server. - * @param host Host to listen on. - * @param port Port to listen on. - * @param auth Whether to use authentication. - */ - public StandardServer(String host, int port, boolean auth) { - super(host, port, auth); - try { - KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA"); - gen.initialize(1024); - this.keys = gen.generateKeyPair(); - } catch(NoSuchAlgorithmException e) { - e.printStackTrace(); - } - } - - /** - * Gets the server's key pair. - * @return The server's key pair. - */ - public KeyPair getKeys() { - return this.keys; - } - - @Override - public boolean isActive() { - return this.online; - } - - @Override - public void bind() { - try { - ServerSocket sock = new ServerSocket(); - sock.bind(new InetSocketAddress(this.getHost(), this.getPort())); - new ServerConnectionThread(sock).start(); - } catch(IOException e) { - Util.logger().severe("Failed to bind to " + this.getHost() + ":" + this.getPort() + "!"); - e.printStackTrace(); - } - } - - @Override - public void shutdown() { - for(ServerConnection conn : this.connections) { - conn.disconnect("The server is shutting down!"); - } - - this.online = false; - } - - @Override - public List getConnections() { - return this.connections; - } - - /** - * Listens for new server connections. - */ - private class ServerConnectionThread extends Thread { - /** - * The server's socket. - */ - private ServerSocket sock; - - /** - * Creates a new server connection thread instance. - * @param sock Socket to listen on. - */ - public ServerConnectionThread(ServerSocket sock) { - this.sock = sock; - } - - @Override - public void run() { - while(online) { - try { - Socket client = this.sock.accept(); - try { - ServerConnection conn = new StandardServerConnection(StandardServer.this, client); - conn.connect(); - connections.add(conn); - call(new ConnectEvent(conn)); - } catch(Exception e) { - Util.logger().severe("Failed to create server connection!"); - e.printStackTrace(); - } - } catch(IOException e) { - Util.logger().severe("Failed to accept connection from client!"); - e.printStackTrace(); - continue; - } - - try { - Thread.sleep(2); - } catch(InterruptedException e) { - } - } - } - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/StandardServerConnection.java b/src/main/java/ch/spacebase/mcprotocol/standard/StandardServerConnection.java deleted file mode 100644 index 88a5028d..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/StandardServerConnection.java +++ /dev/null @@ -1,138 +0,0 @@ -package ch.spacebase.mcprotocol.standard; - -import java.net.InetSocketAddress; -import java.net.Socket; -import ch.spacebase.mcprotocol.exception.ConnectException; -import ch.spacebase.mcprotocol.net.Server; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.standard.packet.PacketKeepAlive; -import ch.spacebase.mcprotocol.util.Util; - -/** - * A server connection for the standard minecraft protocol. - */ -public class StandardServerConnection extends StandardConnection implements ServerConnection { - - /** - * The server this connection belongs to. - */ - private Server server; - - /** - * The connection's temporary socket variable. - */ - private Socket sock; - - /** - * The last time a keep alive was sent. - */ - private long aliveTime = System.currentTimeMillis(); - - /** - * The last sent server keep alive id. - */ - private int aliveId; - - /** - * The protocol's login key. - */ - private String loginKey; - - /** - * The protocol's security token. - */ - private byte token[]; - - /** - * Creates a new server connection. - * @param server Server the connection belongs to. - * @param sock Socket to use. - */ - public StandardServerConnection(Server server, Socket sock) { - super(sock.getInetAddress().getHostName(), ((InetSocketAddress) sock.getRemoteSocketAddress()).getPort()); - this.server = server; - this.sock = sock; - } - - /** - * Gets the last id used in a keep alive to this connection. - * @return The last keep alive id. - */ - public int getLastAliveId() { - return this.aliveId; - } - - /** - * Gets the last time a keep alive was performed. - * @return The last keep alive time. - */ - public long getLastAliveTime() { - return this.aliveTime; - } - - @Override - public Server getServer() { - return this.server; - } - - @Override - public void connect() throws ConnectException { - super.connect(this.sock); - this.sock = null; - new KeepAliveThread().start(); - } - - /** - * Gets the connection's login key. - * @return The connection's login key. - */ - public String getLoginKey() { - return this.loginKey; - } - - /** - * Sets the connection's login key. - * @param key The new login key. - */ - public void setLoginKey(String key) { - this.loginKey = key; - } - - /** - * Gets the connection's security token. - * @return The connection's security token. - */ - public byte[] getToken() { - return this.token; - } - - /** - * Sets the connection's security token. - * @param token The new security token. - */ - public void setToken(byte token[]) { - this.token = token; - } - - /** - * A thread that keeps the connection alive. - */ - private class KeepAliveThread extends Thread { - @Override - public void run() { - while(isConnected()) { - if(System.currentTimeMillis() - aliveTime > 1000) { - aliveTime = System.currentTimeMillis(); - aliveId = Util.random().nextInt(); - send(new PacketKeepAlive(aliveId)); - } - - try { - Thread.sleep(2); - } catch(InterruptedException e) { - } - } - } - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/data/AttributeModifier.java b/src/main/java/ch/spacebase/mcprotocol/standard/data/AttributeModifier.java deleted file mode 100644 index 2722f6f5..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/data/AttributeModifier.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.data; - -import java.util.UUID; - -/** - * A modifier of an entity's attribute. - */ -public class AttributeModifier { - - /** - * The modifier's unique id. - */ - private UUID uid; - /** - * The modifier's amount. - */ - private double amount; - /** - * The modifier's operation. - */ - private int operation; - - /** - * Creates a new modifier. - * @param uid Unique id of the modifier. - * @param amount Amount of the modifier. - * @param operation Operation of the modifier. - */ - public AttributeModifier(UUID uid, double amount, int operation) { - this.uid = uid; - this.amount = amount; - this.operation = operation; - } - - /** - * Gets the modifier's unique id. - * @return The modifier's unique id. - */ - public UUID getUID() { - return this.uid; - } - - /** - * Gets the modifier's amount. - * @return The modifier's amount. - */ - public double getAmount() { - return this.amount; - } - - /** - * Gets the modifier's operation. - * @return The modifier's operation. - */ - public int getOperation() { - return this.operation; - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/data/Coordinates.java b/src/main/java/ch/spacebase/mcprotocol/standard/data/Coordinates.java deleted file mode 100644 index 9d920e27..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/data/Coordinates.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.data; - -/** - * Contains a coordinate set. - */ -public class Coordinates { - - /** - * The X coordinate. - */ - private int x; - - /** - * The Y coordinate. - */ - private int y; - - /** - * The Z coordinate. - */ - private int z; - - /** - * Creates a new coordinate set. - * @param x X coordinate. - * @param y Y coordinate. - * @param z Z coordinate. - */ - public Coordinates(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - /** - * Gets the X coordinate. - * @return The X coordinate. - */ - public int getX() { - return this.x; - } - - /** - * Gets the Y coordinate. - * @return The Y coordinate. - */ - public int getY() { - return this.y; - } - - /** - * Gets the Z coordinate. - * @return The Z coordinate. - */ - public int getZ() { - return this.z; - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/data/EntityAttribute.java b/src/main/java/ch/spacebase/mcprotocol/standard/data/EntityAttribute.java deleted file mode 100644 index e796ad0d..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/data/EntityAttribute.java +++ /dev/null @@ -1,77 +0,0 @@ -package ch.spacebase.mcprotocol.standard.data; - -import java.util.ArrayList; -import java.util.List; - -/** - * Contains a attribute of an entity. - */ -public class EntityAttribute { - - /** - * The attribute's name. - */ - private String name; - /** - * The attribute's value. - */ - private double value; - /** - * The attribute's modifiers. - */ - private List modifiers; - - /** - * Creates a new entity attribute instance. - * @param name Name of the attribute. - * @param value Attribute value. - */ - public EntityAttribute(String name, double value) { - this(name, value, new ArrayList()); - } - - /** - * Creates a new entity attribute instance. - * @param name Name of the attribute. - * @param value Attribute value. - * @param modifiers A list of modifiers. - */ - public EntityAttribute(String name, double value, List modifiers) { - this.name = name; - this.value = value; - this.modifiers = modifiers; - } - - /** - * Gets the attribute's name. - * @return The attribute's name. - */ - public String getName() { - return this.name; - } - - /** - * Gets the attribute's value. - * @return The attribute's value. - */ - public double getValue() { - return this.value; - } - - /** - * Gets the attribute's modifiers. - * @return The attribute's modifiers. - */ - public List getModifiers() { - return this.modifiers; - } - - /** - * Adds a modifier to the attribute. - * @param mod Modifier to add. - */ - public void addModifier(AttributeModifier mod) { - this.modifiers.add(mod); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/data/StandardItemStack.java b/src/main/java/ch/spacebase/mcprotocol/standard/data/StandardItemStack.java deleted file mode 100644 index da12a14b..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/data/StandardItemStack.java +++ /dev/null @@ -1,134 +0,0 @@ -package ch.spacebase.mcprotocol.standard.data; - -/** - * A stack of items. - */ -public class StandardItemStack { - - /** - * Id of the items in the stack. - */ - private short item; - - /** - * The size of the item stack. - */ - private byte stackSize; - - /** - * The damage value of the items in the stack. - */ - private short damage; - - /** - * The compressed NBT data of the item stack. - */ - private byte nbt[]; - - /** - * Creates an item stack with the given id. - * @param item Item id of the stack. - */ - public StandardItemStack(short item) { - this(item, (byte) 1); - } - - /** - * Creates an item stack with the given id and size. - * @param item Item id of the stack. - * @param stackSize Size of the stack. - */ - public StandardItemStack(short item, byte stackSize) { - this(item, stackSize, (short) 0); - } - - /** - * Creates an item stack with the given id, size, and damage value. - * @param item Item id of the stack. - * @param stackSize Size of the stack. - * @param damage Damage value of the stack. - */ - public StandardItemStack(short item, byte stackSize, short damage) { - this(item, stackSize, damage, null); - } - - /** - * Creates an item stack with the given id, size, damage value, and - * compressed NBT data. - * @param item Item id of the stack. - * @param stackSize Size of the stack. - * @param damage Damage value of the stack. - * @param nbt Compressed NBT data of the stack. - */ - public StandardItemStack(short item, byte stackSize, short damage, byte nbt[]) { - this.item = item; - this.stackSize = stackSize; - this.damage = damage; - this.nbt = nbt; - } - - /** - * Gets the item id of the stack. - * @return The stack's item id. - */ - public short getItem() { - return this.item; - } - - /** - * Sets the item id of the stack. - * @param item New item id of the stack. - */ - public void setItem(short item) { - this.item = item; - } - - /** - * Gets the size of the stack. - * @return The stack's size. - */ - public byte getStackSize() { - return this.stackSize; - } - - /** - * Sets the size of the stack. - * @param item New size of the stack. - */ - public void setStackSize(byte stackSize) { - this.stackSize = stackSize; - } - - /** - * Gets the damage value of the stack. - * @return The stack's damage value. - */ - public short getDamage() { - return this.damage; - } - - /** - * Sets the damage value of the stack. - * @param item New damage value of the stack. - */ - public void setDamage(short damage) { - this.damage = damage; - } - - /** - * Gets the compressed NBT data of the stack. - * @return The stack's compressed NBT data. - */ - public byte[] getNBT() { - return this.nbt; - } - - /** - * Sets the compressed NBT data of the stack. - * @param item New compressed NBT data of the stack. - */ - public void setNBT(byte nbt[]) { - this.nbt = nbt; - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/data/WatchableObject.java b/src/main/java/ch/spacebase/mcprotocol/standard/data/WatchableObject.java deleted file mode 100644 index 8e3f9d8b..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/data/WatchableObject.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.data; - -/** - * A watchable object, typically used for entity metadata. - */ -public class WatchableObject { - - /** - * The type id of the object. - */ - private int type; - - /** - * The id of the object. - */ - private int id; - - /** - * The value of the object. - */ - private Object value; - - /** - * Creates a new watchable object. - * @param type Type of the object. - * @param id Id of the object. - * @param value Value of the object. - */ - public WatchableObject(int type, int id, Object value) { - this.type = type; - this.id = id; - this.value = value; - } - - /** - * Gets the object's type id. - * @return The object's type. - */ - public int getType() { - return this.type; - } - - /** - * Gets the object's id. - * @return The object's id. - */ - public int getId() { - return this.id; - } - - /** - * Gets the object's value. - * @return The object's value. - */ - public Object getValue() { - return this.value; - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/example/ChatBot.java b/src/main/java/ch/spacebase/mcprotocol/standard/example/ChatBot.java deleted file mode 100644 index e3e30146..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/example/ChatBot.java +++ /dev/null @@ -1,86 +0,0 @@ -package ch.spacebase.mcprotocol.standard.example; - -import java.text.DecimalFormat; - -import ch.spacebase.mcprotocol.event.DisconnectEvent; -import ch.spacebase.mcprotocol.event.PacketReceiveEvent; -import ch.spacebase.mcprotocol.event.PacketSendEvent; -import ch.spacebase.mcprotocol.event.ProtocolListener; -import ch.spacebase.mcprotocol.exception.ConnectException; -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.StandardClient; -import ch.spacebase.mcprotocol.standard.packet.PacketChat; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerPositionLook; -import ch.spacebase.mcprotocol.util.Util; - -/** - * A simple bot that prints - * "Hello, this is Heisenberg at coordinate ". Be sure to use the - * Bukkit server setting online-mode=false in server.properties. Otherwise - * supply a valid minecraft.net username and password. - */ -public class ChatBot { - - private Client client; - private Listener listener; - - public ChatBot(String host, int port) { - this.client = new StandardClient(host, port); - this.listener = new Listener(); - - this.client.listen(this.listener); - } - - public void login(String username) { - this.client.setUsername(username); - - try { - this.client.connect(); - } catch(ConnectException e) { - e.printStackTrace(); - } - } - - public void say(String text) { - PacketChat chat = new PacketChat(); - chat.message = text; - this.client.send(chat); - } - - public static void main(String[] args) { - ChatBot bot = new ChatBot("127.0.0.1", 25565); - Util.logger().info("Logging in..."); - bot.login("Heisenberg"); - } - - private class Listener extends ProtocolListener { - @Override - public void onPacketReceive(PacketReceiveEvent event) { - Packet packet = event.getPacket(); - - switch(event.getPacket().getId()) { - case 0x0D: - onPositionLook((PacketPlayerPositionLook) packet); - break; - } - } - - @Override - public void onPacketSend(PacketSendEvent event) { - } - - @Override - public void onDisconnect(DisconnectEvent event) { - Util.logger().info("Disconnected: " + event.getReason()); - } - - public void onPositionLook(PacketPlayerPositionLook packet) { - client.send(packet); - DecimalFormat format = new DecimalFormat("#.00"); - - ChatBot.this.say("Hello, this is Heisenberg at coordinate (" + format.format(packet.x) + ", " + format.format(packet.y) + ", " + format.format(packet.z) + ")"); - } - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/example/ChatBotVisitor.java b/src/main/java/ch/spacebase/mcprotocol/standard/example/ChatBotVisitor.java deleted file mode 100644 index fcbaa855..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/example/ChatBotVisitor.java +++ /dev/null @@ -1,104 +0,0 @@ -package ch.spacebase.mcprotocol.standard.example; - -import ch.spacebase.mcprotocol.exception.LoginException; -import ch.spacebase.mcprotocol.exception.OutdatedLibraryException; -import java.text.DecimalFormat; - -import ch.spacebase.mcprotocol.event.DisconnectEvent; -import ch.spacebase.mcprotocol.event.PacketReceiveEvent; -import ch.spacebase.mcprotocol.event.PacketSendEvent; -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.event.PacketVisitorAdapter; -import ch.spacebase.mcprotocol.event.ProtocolListener; -import ch.spacebase.mcprotocol.exception.ConnectException; -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.StandardClient; -import ch.spacebase.mcprotocol.standard.packet.PacketChat; -import ch.spacebase.mcprotocol.standard.packet.PacketPlayerPositionLook; -import ch.spacebase.mcprotocol.util.Util; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A simple bot that prints - * "Hello, this is Heisenberg at coordinate ". Be sure to use the - * Bukkit server setting online-mode=false in server.properties. Otherwise - * supply a valid minecraft.net username and password. - */ -public class ChatBotVisitor { - - private static final String USERNAME = ""; - private static final String PASSWORD = ""; - private static final String HOST = "127.0.0.1"; - private static final int PORT = 25565; - - private Client client; - private Listener listener; - private PacketVisitor visitor; - - public ChatBotVisitor(String host, int port) { - this.client = new StandardClient(host, port); - this.listener = new Listener(); - - this.client.listen(this.listener); - - this.visitor = new Visitor(); - } - - public void login(String username, String password) { - try { - this.client.login(username, password); - } catch(LoginException ex) { - Logger.getLogger("Login Error: " + ex.getLocalizedMessage()); - } catch(OutdatedLibraryException ex) { - Logger.getLogger(ChatBotVisitor.class.getName()).log(Level.SEVERE, null, ex); - } - try { - this.client.connect(); - } catch(ConnectException e) { - e.printStackTrace(); - } - } - - public void say(String text) { - PacketChat chat = new PacketChat(); - chat.message = text; - this.client.send(chat); - } - - public static void main(String[] args) { - ChatBotVisitor bot = new ChatBotVisitor(HOST, PORT); - Util.logger().info("Logging in..."); - bot.login(USERNAME, PASSWORD); - } - - private class Visitor extends PacketVisitorAdapter { - - @Override - public void visit(PacketPlayerPositionLook packet) { - client.send(packet); - DecimalFormat format = new DecimalFormat("#.00"); - - ChatBotVisitor.this.say("Hello, this is " + USERNAME + " at coordinate (" + format.format(packet.x) + ", " + format.format(packet.y) + ", " + format.format(packet.z) + ")"); - } - } - - private class Listener extends ProtocolListener { - - @Override - public void onPacketReceive(PacketReceiveEvent event) { - Packet packet = event.getPacket(); - packet.accept(visitor); - } - - @Override - public void onPacketSend(PacketSendEvent event) { - } - - @Override - public void onDisconnect(DisconnectEvent event) { - Util.logger().info("Disconnected: " + event.getReason()); - } - } -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/io/StandardInput.java b/src/main/java/ch/spacebase/mcprotocol/standard/io/StandardInput.java deleted file mode 100644 index a67ed84d..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/io/StandardInput.java +++ /dev/null @@ -1,204 +0,0 @@ -package ch.spacebase.mcprotocol.standard.io; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.standard.data.Coordinates; -import ch.spacebase.mcprotocol.standard.data.StandardItemStack; -import ch.spacebase.mcprotocol.standard.data.WatchableObject; -import ch.spacebase.mcprotocol.util.Constants; - -public class StandardInput implements NetInput { - - private InputStream in; - - public StandardInput(InputStream in) { - this.in = in; - } - - public InputStream getStream() { - return this.in; - } - - @Override - public boolean readBoolean() throws IOException { - return this.readByte() == 1; - } - - @Override - public byte readByte() throws IOException { - return (byte) this.readUnsignedByte(); - } - - @Override - public int readUnsignedByte() throws IOException { - int b = this.in.read(); - if(b < 0) { - throw new EOFException(); - } - - return b; - } - - @Override - public short readShort() throws IOException { - return (short) this.readUnsignedShort(); - } - - @Override - public int readUnsignedShort() throws IOException { - int ch1 = this.readUnsignedByte(); - int ch2 = this.readUnsignedByte(); - return (ch1 << 8) + (ch2 << 0); - } - - @Override - public char readChar() throws IOException { - int ch1 = this.readUnsignedByte(); - int ch2 = this.readUnsignedByte(); - return (char) ((ch1 << 8) + (ch2 << 0)); - } - - @Override - public int readInt() throws IOException { - int ch1 = this.readUnsignedByte(); - int ch2 = this.readUnsignedByte(); - int ch3 = this.readUnsignedByte(); - int ch4 = this.readUnsignedByte(); - return (ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0); - } - - @Override - public long readLong() throws IOException { - byte read[] = this.readBytes(8); - return ((long) read[0] << 56) + ((long) (read[1] & 255) << 48) + ((long) (read[2] & 255) << 40) + ((long) (read[3] & 255) << 32) + ((long) (read[4] & 255) << 24) + ((read[5] & 255) << 16) + ((read[6] & 255) << 8) + ((read[7] & 255) << 0); - } - - @Override - public float readFloat() throws IOException { - return Float.intBitsToFloat(this.readInt()); - } - - @Override - public double readDouble() throws IOException { - return Double.longBitsToDouble(this.readLong()); - } - - @Override - public byte[] readBytes(int length) throws IOException { - byte b[] = new byte[length]; - if(length < 0) { - throw new IndexOutOfBoundsException(); - } - - int n = 0; - while(n < length) { - int count = this.in.read(b, n, length - n); - if(count < 0) { - throw new EOFException(); - } - - n += count; - } - - return b; - } - - @Override - public String readString() throws IOException { - int len = this.readUnsignedShort(); - char[] characters = new char[len]; - for(int i = 0; i < len; i++) { - characters[i] = this.readChar(); - } - - return new String(characters); - } - - @Override - public int available() throws IOException { - return this.in.available(); - } - - /** - * Reads an entity's metadata. - * @return The read metadata objects. - * @throws IOException If an I/O error occurs. - */ - public WatchableObject[] readMetadata() throws IOException { - List objects = new ArrayList(); - byte b; - while((b = this.readByte()) != 127) { - int type = (b & 0xe0) >> 5; - int id = b & 0x1f; - WatchableObject obj = null; - - switch(type) { - case Constants.StandardProtocol.WatchableObjectIds.BYTE: - obj = new WatchableObject(type, id, Byte.valueOf(this.readByte())); - break; - case Constants.StandardProtocol.WatchableObjectIds.SHORT: - obj = new WatchableObject(type, id, Short.valueOf(this.readShort())); - break; - case Constants.StandardProtocol.WatchableObjectIds.INT: - obj = new WatchableObject(type, id, Integer.valueOf(this.readInt())); - break; - case Constants.StandardProtocol.WatchableObjectIds.FLOAT: - obj = new WatchableObject(type, id, Float.valueOf(this.readFloat())); - break; - case Constants.StandardProtocol.WatchableObjectIds.STRING: - obj = new WatchableObject(type, id, this.readString()); - break; - case Constants.StandardProtocol.WatchableObjectIds.ITEM_STACK: - obj = new WatchableObject(type, id, this.readItem()); - break; - case Constants.StandardProtocol.WatchableObjectIds.COORDINATES: - obj = new WatchableObject(type, id, this.readCoordinates()); - break; - } - - objects.add(obj); - } - - return objects.toArray(new WatchableObject[objects.size()]); - } - - /** - * Reads an item stack. - * @return The read item stack. - * @throws IOException If an I/O error occurs. - */ - public StandardItemStack readItem() throws IOException { - short item = this.readShort(); - byte stackSize = 1; - short damage = 0; - byte nbt[] = null; - if(item > -1) { - stackSize = this.readByte(); - damage = this.readShort(); - short length = this.readShort(); - if(length > -1) { - nbt = this.readBytes(length); - } - } - - return new StandardItemStack(item, stackSize, damage, nbt); - } - - /** - * Reads a coordinate group. - * @return The read coordinates. - * @throws IOException If an I/O error occurs. - */ - public Coordinates readCoordinates() throws IOException { - int x = this.readInt(); - int y = this.readInt(); - int z = this.readInt(); - return new Coordinates(x, y, z); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/io/StandardOutput.java b/src/main/java/ch/spacebase/mcprotocol/standard/io/StandardOutput.java deleted file mode 100644 index c3b78f1e..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/io/StandardOutput.java +++ /dev/null @@ -1,174 +0,0 @@ -package ch.spacebase.mcprotocol.standard.io; - -import java.io.IOException; -import java.io.OutputStream; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import ch.spacebase.mcprotocol.standard.data.Coordinates; -import ch.spacebase.mcprotocol.standard.data.StandardItemStack; -import ch.spacebase.mcprotocol.standard.data.WatchableObject; -import ch.spacebase.mcprotocol.util.Constants; - -public class StandardOutput implements NetOutput { - - private OutputStream out; - - public StandardOutput(OutputStream out) { - this.out = out; - } - - public OutputStream getStream() { - return this.out; - } - - @Override - public void writeBoolean(boolean b) throws IOException { - this.writeByte(b ? 1 : 0); - } - - @Override - public void writeByte(int b) throws IOException { - this.out.write(b); - } - - @Override - public void writeShort(int s) throws IOException { - this.writeByte((byte) ((s >>> 8) & 0xFF)); - this.writeByte((byte) ((s >>> 0) & 0xFF)); - } - - @Override - public void writeChar(int c) throws IOException { - this.writeByte((byte) ((c >>> 8) & 0xFF)); - this.writeByte((byte) ((c >>> 0) & 0xFF)); - } - - @Override - public void writeInt(int i) throws IOException { - this.writeByte((byte) ((i >>> 24) & 0xFF)); - this.writeByte((byte) ((i >>> 16) & 0xFF)); - this.writeByte((byte) ((i >>> 8) & 0xFF)); - this.writeByte((byte) ((i >>> 0) & 0xFF)); - } - - @Override - public void writeLong(long l) throws IOException { - this.writeByte((byte) (l >>> 56)); - this.writeByte((byte) (l >>> 48)); - this.writeByte((byte) (l >>> 40)); - this.writeByte((byte) (l >>> 32)); - this.writeByte((byte) (l >>> 24)); - this.writeByte((byte) (l >>> 16)); - this.writeByte((byte) (l >>> 8)); - this.writeByte((byte) (l >>> 0)); - } - - @Override - public void writeFloat(float f) throws IOException { - this.writeInt(Float.floatToIntBits(f)); - } - - @Override - public void writeDouble(double d) throws IOException { - this.writeLong(Double.doubleToLongBits(d)); - } - - @Override - public void writeBytes(byte b[]) throws IOException { - this.writeBytes(b, b.length); - } - - @Override - public void writeBytes(byte b[], int length) throws IOException { - this.out.write(b, 0, length); - } - - @Override - public void writeString(String s) throws IOException { - if(s == null) { - throw new IllegalArgumentException("String cannot be null!"); - } - - int len = s.length(); - if(len >= 65536) { - throw new IllegalArgumentException("String too long."); - } - - this.writeShort(len); - for(int i = 0; i < len; ++i) { - this.writeChar(s.charAt(i)); - } - } - - @Override - public void flush() throws IOException { - this.out.flush(); - } - - /** - * Writes an entity's metadata. - * @param data Metadata objects to write. - * @throws IOException If an I/O error occurs. - */ - public void writeMetadata(WatchableObject data[]) throws IOException { - for(WatchableObject obj : data) { - int header = (obj.getType() << 5 | obj.getType() & 0x1f) & 0xff; - this.writeByte(header); - switch(obj.getType()) { - case Constants.StandardProtocol.WatchableObjectIds.BYTE: - this.writeByte((Byte) obj.getValue()); - break; - case Constants.StandardProtocol.WatchableObjectIds.SHORT: - this.writeShort((Short) obj.getValue()); - break; - case Constants.StandardProtocol.WatchableObjectIds.INT: - this.writeInt((Integer) obj.getValue()); - break; - case Constants.StandardProtocol.WatchableObjectIds.FLOAT: - this.writeFloat((Float) obj.getValue()); - break; - case Constants.StandardProtocol.WatchableObjectIds.STRING: - this.writeString((String) obj.getValue()); - break; - case Constants.StandardProtocol.WatchableObjectIds.ITEM_STACK: - this.writeItem((StandardItemStack) obj.getValue()); - break; - case Constants.StandardProtocol.WatchableObjectIds.COORDINATES: - this.writeCoordinates((Coordinates) obj.getValue()); - break; - } - } - - this.writeByte(127); - } - - /** - * Writes an item stack. - * @param item Item stack to write. - * @throws IOException If an I/O error occurs. - */ - public void writeItem(StandardItemStack item) throws IOException { - this.writeShort(item.getItem()); - if(item.getItem() != -1) { - this.writeByte(item.getStackSize()); - this.writeShort(item.getDamage()); - if(item.getNBT() != null) { - this.writeShort(item.getNBT().length); - this.writeBytes(item.getNBT()); - } else { - this.writeShort(-1); - } - } - } - - /** - * Writes a coordinate group. - * @param coords Coordinates to write. - * @throws IOException If an I/O error occurs. - */ - public void writeCoordinates(Coordinates coords) throws IOException { - this.writeInt(coords.getX()); - this.writeInt(coords.getY()); - this.writeInt(coords.getZ()); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketAnimation.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketAnimation.java deleted file mode 100644 index 5963beab..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketAnimation.java +++ /dev/null @@ -1,55 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketAnimation extends Packet { - - public int entityId; - public byte animation; - - public PacketAnimation() { - } - - public PacketAnimation(int entityId, byte animation) { - this.entityId = entityId; - this.animation = animation; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.animation = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.animation); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 18; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketAttachEntity.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketAttachEntity.java deleted file mode 100644 index 155083c5..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketAttachEntity.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketAttachEntity extends Packet { - - public int entityId; - public int vehicleId; - public boolean leash; - - public PacketAttachEntity() { - } - - public PacketAttachEntity(int entityId, int vehicleId, boolean leash) { - this.entityId = entityId; - this.vehicleId = vehicleId; - this.leash = leash; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.vehicleId = in.readInt(); - this.leash = in.readBoolean(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeInt(this.vehicleId); - out.writeBoolean(this.leash); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 39; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketBlockAction.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketBlockAction.java deleted file mode 100644 index d77ce2c1..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketBlockAction.java +++ /dev/null @@ -1,71 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketBlockAction extends Packet { - - public int x; - public int y; - public int z; - public byte b1; - public byte b2; - public int block; - - public PacketBlockAction() { - } - - public PacketBlockAction(int x, int y, int z, byte b1, byte b2, short block) { - this.x = x; - this.y = y; - this.z = z; - this.b1 = b1; - this.b2 = b2; - this.block = block; - } - - @Override - public void read(NetInput in) throws IOException { - this.x = in.readInt(); - this.y = in.readShort(); - this.z = in.readInt(); - this.b1 = in.readByte(); - this.b2 = in.readByte(); - this.block = in.readUnsignedShort(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.x); - out.writeShort(this.y); - out.writeInt(this.z); - out.writeByte(this.b1); - out.writeByte(this.b2); - out.writeShort(this.block); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 54; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketBlockBreakAnimation.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketBlockBreakAnimation.java deleted file mode 100644 index b86de4ed..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketBlockBreakAnimation.java +++ /dev/null @@ -1,67 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketBlockBreakAnimation extends Packet { - - public int entityId; - public int x; - public int y; - public int z; - public byte stage; - - public PacketBlockBreakAnimation() { - } - - public PacketBlockBreakAnimation(int entityId, int x, int y, int z, byte stage) { - this.entityId = entityId; - this.x = x; - this.y = y; - this.z = z; - this.stage = stage; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.x = in.readInt(); - this.y = in.readInt(); - this.z = in.readInt(); - this.stage = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeInt(this.x); - out.writeInt(this.y); - out.writeInt(this.z); - out.writeByte(this.stage); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 55; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketBlockChange.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketBlockChange.java deleted file mode 100644 index 8072adff..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketBlockChange.java +++ /dev/null @@ -1,67 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketBlockChange extends Packet { - - public int x; - public int y; - public int z; - public short block; - public byte data; - - public PacketBlockChange() { - } - - public PacketBlockChange(int x, int y, int z, short block, byte data) { - this.x = x; - this.y = y; - this.z = z; - this.block = block; - this.data = data; - } - - @Override - public void read(NetInput in) throws IOException { - this.x = in.readInt(); - this.y = in.readByte(); - this.z = in.readInt(); - this.block = in.readShort(); - this.data = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.x); - out.writeByte(this.y); - out.writeInt(this.z); - out.writeShort(this.block); - out.writeByte(this.data); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 53; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketChat.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketChat.java deleted file mode 100644 index e0024ae2..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketChat.java +++ /dev/null @@ -1,55 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketChat extends Packet { - - public String message; - - public PacketChat() { - } - - public PacketChat(String message) { - this.message = message; - } - - public String getMessage() { - return this.message; - } - - @Override - public void read(NetInput in) throws IOException { - this.message = in.readString(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.message); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 3; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketClientInfo.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketClientInfo.java deleted file mode 100644 index c0d7607d..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketClientInfo.java +++ /dev/null @@ -1,67 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketClientInfo extends Packet { - - public String locale; - public byte viewDistance; - public byte chatFlags; - public byte difficulty; - public boolean cape; - - public PacketClientInfo() { - } - - public PacketClientInfo(String locale, byte viewDistance, byte chatFlags, byte difficulty, boolean cape) { - this.locale = locale; - this.viewDistance = viewDistance; - this.chatFlags = chatFlags; - this.difficulty = difficulty; - this.cape = cape; - } - - @Override - public void read(NetInput in) throws IOException { - this.locale = in.readString(); - this.viewDistance = in.readByte(); - this.chatFlags = in.readByte(); - this.difficulty = in.readByte(); - this.cape = in.readBoolean(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.locale); - out.writeByte(this.viewDistance); - out.writeByte(this.chatFlags); - out.writeByte(this.difficulty); - out.writeBoolean(this.cape); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 204; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketClientStatus.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketClientStatus.java deleted file mode 100644 index 358a603a..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketClientStatus.java +++ /dev/null @@ -1,88 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import java.io.BufferedReader; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; -import java.io.InputStreamReader; -import java.math.BigInteger; -import java.net.URL; -import java.net.URLEncoder; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.StandardServer; -import ch.spacebase.mcprotocol.standard.StandardServerConnection; -import ch.spacebase.mcprotocol.util.Util; - -public class PacketClientStatus extends Packet { - - public byte status; - - public PacketClientStatus() { - } - - public PacketClientStatus(byte status) { - this.status = status; - } - - public byte getStatus() { - return this.status; - } - - @Override - public void read(NetInput in) throws IOException { - this.status = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.status); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - if(this.status == 0 && conn.getServer().isAuthEnabled()) { - String encrypted = new BigInteger(Util.encrypt(((StandardServerConnection) conn).getLoginKey(), ((StandardServer) conn.getServer()).getKeys().getPublic(), ((StandardServerConnection) conn).getSecretKey())).toString(16); - String response = null; - - try { - URL url = new URL("http://session.minecraft.net/game/checkserver.jsp?user=" + URLEncoder.encode(conn.getUsername(), "UTF-8") + "&serverId=" + URLEncoder.encode(encrypted, "UTF-8")); - BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); - response = reader.readLine(); - reader.close(); - } catch(IOException e) { - response = e.toString(); - } - - if(!response.equals("YES")) { - conn.disconnect("Failed to verify username!"); - return; - } - } - - for(ServerConnection c : conn.getServer().getConnections()) { - if(c.getUsername().equals(conn.getUsername())) { - c.disconnect("You logged in from another location!"); - break; - } - } - } - - @Override - public int getId() { - return 205; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketCloseWindow.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketCloseWindow.java deleted file mode 100644 index b6ac14e1..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketCloseWindow.java +++ /dev/null @@ -1,51 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketCloseWindow extends Packet { - - public byte id; - - public PacketCloseWindow() { - } - - public PacketCloseWindow(byte id) { - this.id = id; - } - - @Override - public void read(NetInput in) throws IOException { - this.id = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.id); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 101; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketCollectItem.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketCollectItem.java deleted file mode 100644 index fcccc228..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketCollectItem.java +++ /dev/null @@ -1,55 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketCollectItem extends Packet { - - public int collected; - public int collector; - - public PacketCollectItem() { - } - - public PacketCollectItem(int collected, int collector) { - this.collected = collected; - this.collector = collector; - } - - @Override - public void read(NetInput in) throws IOException { - this.collected = in.readInt(); - this.collector = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.collected); - out.writeInt(this.collector); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 22; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketConfirmTransaction.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketConfirmTransaction.java deleted file mode 100644 index 8d2ef3ed..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketConfirmTransaction.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketConfirmTransaction extends Packet { - - public byte id; - public short action; - public boolean confirm; - - public PacketConfirmTransaction() { - } - - public PacketConfirmTransaction(byte id, short action, boolean confirm) { - this.id = id; - this.action = action; - this.confirm = confirm; - } - - @Override - public void read(NetInput in) throws IOException { - this.id = in.readByte(); - this.action = in.readShort(); - this.confirm = in.readBoolean(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.id); - out.writeShort(this.action); - out.writeBoolean(this.confirm); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 106; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketCreativeSlot.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketCreativeSlot.java deleted file mode 100644 index 11464c93..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketCreativeSlot.java +++ /dev/null @@ -1,60 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.data.StandardItemStack; -import ch.spacebase.mcprotocol.standard.io.StandardInput; -import ch.spacebase.mcprotocol.standard.io.StandardOutput; - -public class PacketCreativeSlot extends Packet { - - public short slot; - public StandardItemStack clicked; - - public PacketCreativeSlot() { - } - - public PacketCreativeSlot(short slot, StandardItemStack clicked) { - this.slot = slot; - this.clicked = clicked; - } - - @Override - public void read(NetInput in) throws IOException { - this.slot = in.readShort(); - this.clicked = ((StandardInput) in).readItem(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeShort(this.slot); - if(this.clicked != null) { - ((StandardOutput) out).writeItem(this.clicked); - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 107; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketDestroyEntity.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketDestroyEntity.java deleted file mode 100644 index f8876221..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketDestroyEntity.java +++ /dev/null @@ -1,57 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketDestroyEntity extends Packet { - - public int entityIds[]; - - public PacketDestroyEntity() { - } - - public PacketDestroyEntity(int... entityIds) { - this.entityIds = entityIds.clone(); - } - - @Override - public void read(NetInput in) throws IOException { - this.entityIds = new int[in.readUnsignedByte()]; - for(int count = 0; count < this.entityIds.length; count++) { - this.entityIds[count] = in.readInt(); - } - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.entityIds.length); - for(int id : this.entityIds) { - out.writeInt(id); - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 29; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketDisconnect.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketDisconnect.java deleted file mode 100644 index fde46f41..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketDisconnect.java +++ /dev/null @@ -1,57 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketDisconnect extends Packet { - - public String reason; - - public PacketDisconnect() { - } - - public PacketDisconnect(String reason) { - this.reason = reason; - } - - public String getReason() { - return this.reason; - } - - @Override - public void read(NetInput in) throws IOException { - this.reason = in.readString(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.reason); - } - - @Override - public void handleClient(Client conn) { - conn.disconnect(this.reason, false); - } - - @Override - public void handleServer(ServerConnection conn) { - conn.disconnect(this.reason, false); - } - - @Override - public int getId() { - return 255; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketDisplayScoreboard.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketDisplayScoreboard.java deleted file mode 100644 index 7a71638f..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketDisplayScoreboard.java +++ /dev/null @@ -1,54 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketDisplayScoreboard extends Packet { - - public byte position; - public String scoreboard; - - public PacketDisplayScoreboard() { - } - - public PacketDisplayScoreboard(byte position, String scoreboard) { - this.position = position; - this.scoreboard = scoreboard; - } - - @Override - public void read(NetInput in) throws IOException { - this.position = in.readByte(); - this.scoreboard = in.readString(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.position); - out.writeString(this.scoreboard); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 208; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEffect.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEffect.java deleted file mode 100644 index ae2229fd..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEffect.java +++ /dev/null @@ -1,71 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEffect extends Packet { - - public int effectId; - public int x; - public int y; - public int z; - public int data; - public boolean ignoreVolume; - - public PacketEffect() { - } - - public PacketEffect(int effectId, int x, int y, int z, int data, boolean ignoreVolume) { - this.effectId = effectId; - this.x = x; - this.y = y; - this.z = z; - this.data = data; - this.ignoreVolume = ignoreVolume; - } - - @Override - public void read(NetInput in) throws IOException { - this.effectId = in.readInt(); - this.x = in.readInt(); - this.y = in.readUnsignedByte(); - this.z = in.readInt(); - this.data = in.readInt(); - this.ignoreVolume = in.readBoolean(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.effectId); - out.writeInt(this.x); - out.writeByte(this.y); - out.writeInt(this.z); - out.writeInt(this.data); - out.writeBoolean(this.ignoreVolume); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 61; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEnchantItem.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEnchantItem.java deleted file mode 100644 index ca68fc86..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEnchantItem.java +++ /dev/null @@ -1,55 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEnchantItem extends Packet { - - public byte id; - public byte enchantment; - - public PacketEnchantItem() { - } - - public PacketEnchantItem(byte id, byte enchantment) { - this.id = id; - this.enchantment = enchantment; - } - - @Override - public void read(NetInput in) throws IOException { - this.id = in.readByte(); - this.enchantment = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.id); - out.writeByte(this.enchantment); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 108; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntity.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntity.java deleted file mode 100644 index dcfc1ee1..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntity.java +++ /dev/null @@ -1,51 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEntity extends Packet { - - public int entityId; - - public PacketEntity() { - } - - public PacketEntity(int entityId) { - this.entityId = entityId; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 30; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityAction.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityAction.java deleted file mode 100644 index ff50812a..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityAction.java +++ /dev/null @@ -1,63 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEntityAction extends Packet { - - public int entityId; - public byte action; - public int jumpBar; - - public PacketEntityAction() { - } - - public PacketEntityAction(int entityId, byte action) { - this(entityId, action, 0); - } - - public PacketEntityAction(int entityId, byte action, int jumpBar) { - this.entityId = entityId; - this.action = action; - this.jumpBar = jumpBar; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.action = in.readByte(); - this.jumpBar = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.action); - out.writeInt(this.jumpBar); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 19; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityAttributes.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityAttributes.java deleted file mode 100644 index 331002b9..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityAttributes.java +++ /dev/null @@ -1,82 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.data.EntityAttribute; -import ch.spacebase.mcprotocol.standard.data.AttributeModifier; - -public class PacketEntityAttributes extends Packet { - - public int entityId; - public List attributes; - - public PacketEntityAttributes() { - } - - public PacketEntityAttributes(int entityId, List attributes) { - if(attributes.size() == 0) { - throw new IllegalArgumentException("Attribute map is empty."); - } - this.entityId = entityId; - this.attributes = attributes; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - int count = in.readInt(); - this.attributes = new ArrayList(); - for(int ct = 0; ct < count; ct++) { - EntityAttribute attrib = new EntityAttribute(in.readString(), in.readDouble()); - short len = in.readShort(); - for(int i = 0; i < len; i++) { - attrib.addModifier(new AttributeModifier(new UUID(in.readLong(), in.readLong()), in.readDouble(), in.readByte())); - } - } - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeInt(this.attributes.size()); - for(EntityAttribute attrib : this.attributes) { - out.writeString(attrib.getName()); - out.writeDouble(attrib.getValue()); - out.writeShort(attrib.getModifiers().size()); - for(AttributeModifier mod : attrib.getModifiers()) { - out.writeLong(mod.getUID().getMostSignificantBits()); - out.writeLong(mod.getUID().getLeastSignificantBits()); - out.writeDouble(mod.getAmount()); - out.writeByte(mod.getOperation()); - } - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 44; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityEffect.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityEffect.java deleted file mode 100644 index d2c8a94b..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityEffect.java +++ /dev/null @@ -1,63 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEntityEffect extends Packet { - - public int entityId; - public byte effect; - public byte amplifier; - public short duration; - - public PacketEntityEffect() { - } - - public PacketEntityEffect(int entityId, byte effect, byte amplifier, short duration) { - this.entityId = entityId; - this.effect = effect; - this.amplifier = amplifier; - this.duration = duration; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.effect = in.readByte(); - this.amplifier = in.readByte(); - this.duration = in.readShort(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.effect); - out.writeByte(this.amplifier); - out.writeShort(this.duration); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 41; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityEquipment.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityEquipment.java deleted file mode 100644 index 64fe59db..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityEquipment.java +++ /dev/null @@ -1,74 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.data.StandardItemStack; -import ch.spacebase.mcprotocol.standard.io.StandardInput; -import ch.spacebase.mcprotocol.standard.io.StandardOutput; - -public class PacketEntityEquipment extends Packet { - - public int entityId; - public short slot; - public StandardItemStack item; - - public PacketEntityEquipment() { - } - - public PacketEntityEquipment(int entityId, short slot, StandardItemStack item) { - this.entityId = entityId; - this.slot = slot; - this.item = item; - } - - public int getEntityId() { - return this.entityId; - } - - public short getSlot() { - return this.slot; - } - - public StandardItemStack getItem() { - return this.item; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.slot = in.readShort(); - this.item = ((StandardInput) in).readItem(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeShort(this.slot); - ((StandardOutput) out).writeItem(this.item); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 5; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityHeadYaw.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityHeadYaw.java deleted file mode 100644 index 70b32c68..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityHeadYaw.java +++ /dev/null @@ -1,55 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEntityHeadYaw extends Packet { - - public int entityId; - public byte headYaw; - - public PacketEntityHeadYaw() { - } - - public PacketEntityHeadYaw(int entityId, byte headYaw) { - this.entityId = entityId; - this.headYaw = headYaw; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.headYaw = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.headYaw); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 35; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityLook.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityLook.java deleted file mode 100644 index 7d168a6b..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityLook.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEntityLook extends Packet { - - public int entityId; - public byte yaw; - public byte pitch; - - public PacketEntityLook() { - } - - public PacketEntityLook(int entityId, byte yaw, byte pitch) { - this.entityId = entityId; - this.yaw = yaw; - this.pitch = pitch; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.yaw = in.readByte(); - this.pitch = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.yaw); - out.writeByte(this.pitch); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 32; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityLookRelativeMove.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityLookRelativeMove.java deleted file mode 100644 index b8ab24e9..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityLookRelativeMove.java +++ /dev/null @@ -1,71 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEntityLookRelativeMove extends Packet { - - public int entityId; - public byte dX; - public byte dY; - public byte dZ; - public byte yaw; - public byte pitch; - - public PacketEntityLookRelativeMove() { - } - - public PacketEntityLookRelativeMove(int entityId, byte dX, byte dY, byte dZ, byte yaw, byte pitch) { - this.entityId = entityId; - this.dX = dX; - this.dY = dY; - this.dZ = dZ; - this.yaw = yaw; - this.pitch = pitch; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.dX = in.readByte(); - this.dY = in.readByte(); - this.dZ = in.readByte(); - this.yaw = in.readByte(); - this.pitch = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.dX); - out.writeByte(this.dY); - out.writeByte(this.dZ); - out.writeByte(this.yaw); - out.writeByte(this.pitch); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 33; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityMetadata.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityMetadata.java deleted file mode 100644 index deebd50c..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityMetadata.java +++ /dev/null @@ -1,58 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.data.WatchableObject; -import ch.spacebase.mcprotocol.standard.io.StandardInput; -import ch.spacebase.mcprotocol.standard.io.StandardOutput; - -public class PacketEntityMetadata extends Packet { - - public int entityId; - public WatchableObject metadata[]; - - public PacketEntityMetadata() { - } - - public PacketEntityMetadata(int entityId, WatchableObject metadata[]) { - this.entityId = entityId; - this.metadata = metadata; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.metadata = ((StandardInput) in).readMetadata(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - ((StandardOutput) out).writeMetadata(this.metadata); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 40; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityRelativeMove.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityRelativeMove.java deleted file mode 100644 index 5a271435..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityRelativeMove.java +++ /dev/null @@ -1,63 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEntityRelativeMove extends Packet { - - public int entityId; - public byte dX; - public byte dY; - public byte dZ; - - public PacketEntityRelativeMove() { - } - - public PacketEntityRelativeMove(int entityId, byte dX, byte dY, byte dZ) { - this.entityId = entityId; - this.dX = dX; - this.dY = dY; - this.dZ = dZ; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.dX = in.readByte(); - this.dY = in.readByte(); - this.dZ = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.dX); - out.writeByte(this.dY); - out.writeByte(this.dZ); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 31; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityStatus.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityStatus.java deleted file mode 100644 index 443e4c6e..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityStatus.java +++ /dev/null @@ -1,55 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEntityStatus extends Packet { - - public int entityId; - public byte status; - - public PacketEntityStatus() { - } - - public PacketEntityStatus(int entityId, byte status) { - this.entityId = entityId; - this.status = status; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.status = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.status); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 38; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityTeleport.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityTeleport.java deleted file mode 100644 index 20896fef..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityTeleport.java +++ /dev/null @@ -1,71 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEntityTeleport extends Packet { - - public int entityId; - public int x; - public int y; - public int z; - public byte yaw; - public byte pitch; - - public PacketEntityTeleport() { - } - - public PacketEntityTeleport(int entityId, int x, int y, int z, byte yaw, byte pitch) { - this.entityId = entityId; - this.x = x; - this.y = y; - this.z = z; - this.yaw = yaw; - this.pitch = pitch; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.x = in.readInt(); - this.y = in.readInt(); - this.z = in.readInt(); - this.yaw = in.readByte(); - this.pitch = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeInt(this.x); - out.writeInt(this.y); - out.writeInt(this.z); - out.writeByte(this.yaw); - out.writeByte(this.pitch); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 34; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityVelocity.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityVelocity.java deleted file mode 100644 index c65537ed..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketEntityVelocity.java +++ /dev/null @@ -1,63 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketEntityVelocity extends Packet { - - public int entityId; - public short velX; - public short velY; - public short velZ; - - public PacketEntityVelocity() { - } - - public PacketEntityVelocity(int entityId, short velX, short velY, short velZ) { - this.entityId = entityId; - this.velX = velX; - this.velY = velY; - this.velZ = velZ; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.velX = in.readShort(); - this.velY = in.readShort(); - this.velZ = in.readShort(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeShort(this.velX); - out.writeShort(this.velY); - out.writeShort(this.velZ); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 28; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketExplosion.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketExplosion.java deleted file mode 100644 index c9c42392..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketExplosion.java +++ /dev/null @@ -1,80 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketExplosion extends Packet { - - public double x; - public double y; - public double z; - public float radius; - public byte blocks[]; - public float unk1; - public float unk2; - public float unk3; - - public PacketExplosion() { - } - - public PacketExplosion(double x, double y, double z, float radius, byte blocks[], float unk1, float unk2, float unk3) { - this.x = x; - this.y = y; - this.z = z; - this.radius = radius; - this.blocks = blocks; - this.unk1 = unk1; - this.unk2 = unk2; - this.unk3 = unk3; - } - - @Override - public void read(NetInput in) throws IOException { - this.x = in.readDouble(); - this.y = in.readDouble(); - this.z = in.readDouble(); - this.radius = in.readFloat(); - this.blocks = in.readBytes(in.readInt() * 3); - this.unk1 = in.readFloat(); - this.unk2 = in.readFloat(); - this.unk3 = in.readFloat(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeDouble(this.x); - out.writeDouble(this.y); - out.writeDouble(this.z); - out.writeFloat(this.radius); - out.writeInt(this.blocks.length / 3); - out.writeBytes(this.blocks); - out.writeFloat(this.unk1); - out.writeFloat(this.unk2); - out.writeFloat(this.unk3); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 60; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketGameState.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketGameState.java deleted file mode 100644 index b4215e85..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketGameState.java +++ /dev/null @@ -1,55 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketGameState extends Packet { - - public byte reason; - public byte gamemode; - - public PacketGameState() { - } - - public PacketGameState(byte reason, byte gamemode) { - this.reason = reason; - this.gamemode = gamemode; - } - - @Override - public void read(NetInput in) throws IOException { - this.reason = in.readByte(); - this.gamemode = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.reason); - out.writeByte(this.gamemode); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 70; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketHandshake.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketHandshake.java deleted file mode 100644 index 48d860c9..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketHandshake.java +++ /dev/null @@ -1,86 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; -import java.security.PublicKey; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.StandardServer; -import ch.spacebase.mcprotocol.standard.StandardServerConnection; -import ch.spacebase.mcprotocol.util.Constants; -import ch.spacebase.mcprotocol.util.Util; - -public class PacketHandshake extends Packet { - - public int protocol; - public String user; - public String host; - public int port; - - public PacketHandshake() { - } - - public PacketHandshake(String user, String host, int port) { - this.protocol = Constants.StandardProtocol.PROTOCOL_VERSION; - this.user = user; - this.host = host; - this.port = port; - } - - @Override - public void read(NetInput in) throws IOException { - this.protocol = in.readByte(); - this.user = in.readString(); - this.host = in.readString(); - this.port = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.protocol); - out.writeString(this.user); - out.writeString(this.host); - out.writeInt(this.port); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - if(!Util.stripColor(this.user).equals(this.user)) { - conn.disconnect("Invalid username."); - } else if(this.protocol != Constants.StandardProtocol.PROTOCOL_VERSION) { - if(this.protocol > Constants.StandardProtocol.PROTOCOL_VERSION) { - conn.disconnect("Outdated Server!"); - } else { - conn.disconnect("Outdated Client!"); - } - } else { - conn.setUsername(this.user); - PublicKey key = ((StandardServer) conn.getServer()).getKeys().getPublic(); - ((StandardServerConnection) conn).setLoginKey(conn.getServer().isAuthEnabled() ? Long.toString(Util.random().nextLong(), 16) : "-"); - byte token[] = new byte[4]; - Util.random().nextBytes(token); - ((StandardServerConnection) conn).setToken(token); - - conn.send(new PacketKeyRequest(((StandardServerConnection) conn).getLoginKey(), key.getEncoded(), token)); - } - } - - @Override - public int getId() { - return 2; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketHealthUpdate.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketHealthUpdate.java deleted file mode 100644 index 2c7dfa71..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketHealthUpdate.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketHealthUpdate extends Packet { - - public float health; - public short food; - public float saturation; - - public PacketHealthUpdate() { - } - - public PacketHealthUpdate(float health, short food, float saturation) { - this.health = health; - this.food = food; - this.saturation = saturation; - } - - @Override - public void read(NetInput in) throws IOException { - this.health = in.readFloat(); - this.food = in.readShort(); - this.saturation = in.readFloat(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeFloat(this.health); - out.writeShort(this.food); - out.writeFloat(saturation); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 8; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketHeldItemChange.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketHeldItemChange.java deleted file mode 100644 index a236acb3..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketHeldItemChange.java +++ /dev/null @@ -1,51 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketHeldItemChange extends Packet { - - public short slot; - - public PacketHeldItemChange() { - } - - public PacketHeldItemChange(short slot) { - this.slot = slot; - } - - @Override - public void read(NetInput in) throws IOException { - this.slot = in.readShort(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeShort(this.slot); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 16; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketIncrementStatistic.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketIncrementStatistic.java deleted file mode 100644 index 9eea1c30..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketIncrementStatistic.java +++ /dev/null @@ -1,55 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketIncrementStatistic extends Packet { - - public int statistic; - public int amount; - - public PacketIncrementStatistic() { - } - - public PacketIncrementStatistic(int statistic, int amount) { - this.statistic = statistic; - this.amount = amount; - } - - @Override - public void read(NetInput in) throws IOException { - this.statistic = in.readInt(); - this.amount = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.statistic); - out.writeInt(this.amount); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 200; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketItemData.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketItemData.java deleted file mode 100644 index 7d7207b7..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketItemData.java +++ /dev/null @@ -1,60 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketItemData extends Packet { - - public short item; - public short damage; - public byte data[]; - - public PacketItemData() { - } - - public PacketItemData(short item, short damage, byte data[]) { - this.item = item; - this.damage = damage; - this.data = data; - } - - @Override - public void read(NetInput in) throws IOException { - this.item = in.readShort(); - this.damage = in.readShort(); - this.data = in.readBytes(in.readShort()); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeShort(this.item); - out.writeShort(this.damage); - out.writeShort(this.data.length); - out.writeBytes(this.data); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 131; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketKeepAlive.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketKeepAlive.java deleted file mode 100644 index 31624fe6..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketKeepAlive.java +++ /dev/null @@ -1,52 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketKeepAlive extends Packet { - - public int id; - - public PacketKeepAlive() { - } - - public PacketKeepAlive(int id) { - this.id = id; - } - - @Override - public void read(NetInput in) throws IOException { - this.id = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.id); - } - - @Override - public void handleClient(Client conn) { - conn.send(new PacketKeepAlive(this.id)); - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 0; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketKeyRequest.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketKeyRequest.java deleted file mode 100644 index cea61e23..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketKeyRequest.java +++ /dev/null @@ -1,168 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import java.io.BufferedReader; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; -import java.io.InputStreamReader; -import java.math.BigInteger; -import java.net.URL; -import java.net.URLEncoder; -import java.security.InvalidKeyException; -import java.security.KeyFactory; -import java.security.NoSuchAlgorithmException; -import java.security.PublicKey; -import java.security.SecureRandom; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.X509EncodedKeySpec; - -import javax.crypto.BadPaddingException; -import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; - -import org.bouncycastle.crypto.CipherKeyGenerator; -import org.bouncycastle.crypto.KeyGenerationParameters; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.StandardClient; -import ch.spacebase.mcprotocol.util.Util; - -public class PacketKeyRequest extends Packet { - - public String serverId; - public byte[] pubKey; - public byte[] verifyToken; - - public PacketKeyRequest() { - } - - public PacketKeyRequest(String serverId, byte[] pubKey, byte[] verifyToken) { - this.serverId = serverId; - this.pubKey = pubKey; - this.verifyToken = verifyToken; - } - - public String getServerId() { - return this.serverId; - } - - public byte[] getPublicKey() { - return this.pubKey; - } - - public byte[] getVerifyToken() { - return this.verifyToken; - } - - @Override - public void read(NetInput in) throws IOException { - this.serverId = in.readString(); - byte pubKey[] = in.readBytes(in.readShort()); - this.pubKey = pubKey; - - byte verifyToken[] = in.readBytes(in.readShort()); - this.verifyToken = verifyToken; - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.serverId); - out.writeShort(this.pubKey.length); - out.writeBytes(this.pubKey); - out.writeShort(this.verifyToken.length); - out.writeBytes(this.verifyToken); - } - - @Override - public void handleClient(Client conn) { - PublicKey key = toKey(this.pubKey); - SecretKey secret = generateKey(); - if(!this.serverId.equals("-")) { - String encrypted = new BigInteger(Util.encrypt(this.serverId, key, secret)).toString(16); - String response = joinServer(conn.getUsername(), ((StandardClient) conn).getSessionId(), encrypted); - if(!response.equalsIgnoreCase("ok")) { - Util.logger().severe("Failed to login to session.minecraft.net! (RESPONSE: \"" + response + "\")"); - conn.disconnect("Failed to login to session.minecraft.net!"); - return; - } - } - - conn.send(new PacketKeyResponse(encryptBytes(key, secret.getEncoded()), encryptBytes(key, this.verifyToken))); - ((StandardClient) conn).setSecretKey(secret); - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 253; - } - - private static byte[] encryptBytes(PublicKey key, byte[] bytes) { - try { - Cipher cipher = Cipher.getInstance(key.getAlgorithm()); - cipher.init(1, key); - return cipher.doFinal(bytes); - } catch(InvalidKeyException e) { - e.printStackTrace(); - } catch(NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch(NoSuchPaddingException e) { - e.printStackTrace(); - } catch(IllegalBlockSizeException e) { - e.printStackTrace(); - } catch(BadPaddingException e) { - e.printStackTrace(); - } - - return null; - } - - private static SecretKey generateKey() { - CipherKeyGenerator gen = new CipherKeyGenerator(); - gen.init(new KeyGenerationParameters(new SecureRandom(), 128)); - return new SecretKeySpec(gen.generateKey(), "AES"); - } - - private static PublicKey toKey(byte[] key) { - try { - X509EncodedKeySpec spec = new X509EncodedKeySpec(key); - KeyFactory factory = KeyFactory.getInstance("RSA"); - return factory.generatePublic(spec); - } catch(NoSuchAlgorithmException e) { - Util.logger().warning("Failed to get public key from array!"); - e.printStackTrace(); - return null; - } catch(InvalidKeySpecException e) { - Util.logger().warning("Failed to get public key from array!"); - e.printStackTrace(); - return null; - } - } - - private static String joinServer(String user, String session, String key) { - try { - URL url = new URL("http://session.minecraft.net/game/joinserver.jsp?user=" + URLEncoder.encode(user, "UTF-8") + "&sessionId=" + URLEncoder.encode(session, "UTF-8") + "&serverId=" + URLEncoder.encode(key, "UTF-8")); - BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); - String response = reader.readLine(); - reader.close(); - return response; - } catch(IOException e) { - return e.toString(); - } - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketKeyResponse.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketKeyResponse.java deleted file mode 100644 index cae6d18b..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketKeyResponse.java +++ /dev/null @@ -1,113 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.util.Arrays; - -import javax.crypto.BadPaddingException; -import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.spec.SecretKeySpec; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.StandardClient; -import ch.spacebase.mcprotocol.standard.StandardServer; -import ch.spacebase.mcprotocol.standard.StandardServerConnection; - -public class PacketKeyResponse extends Packet { - - public byte[] sharedKey; - public byte[] verifyToken; - - public PacketKeyResponse() { - } - - public PacketKeyResponse(byte[] sharedKey, byte[] verifyToken) { - this.sharedKey = sharedKey; - this.verifyToken = verifyToken; - } - - public byte[] getSharedKey() { - return this.sharedKey; - } - - public byte[] getVerifyToken() { - return this.verifyToken; - } - - @Override - public void read(NetInput in) throws IOException { - byte sharedKey[] = in.readBytes(in.readShort()); - this.sharedKey = sharedKey; - - byte verifyToken[] = in.readBytes(in.readShort()); - this.verifyToken = verifyToken; - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeShort(this.sharedKey.length); - out.writeBytes(this.sharedKey); - out.writeShort(this.verifyToken.length); - out.writeBytes(this.verifyToken); - } - - @Override - public void handleClient(Client conn) { - ((StandardClient) conn).setAES(conn); - conn.send(new PacketClientStatus((byte) 0)); - } - - @Override - public void handleServer(ServerConnection conn) { - PrivateKey priv = ((StandardServer) conn.getServer()).getKeys().getPrivate(); - - ((StandardServerConnection) conn).setSecretKey(new SecretKeySpec(encryptBytes(priv, this.sharedKey), "AES")); - if(!Arrays.equals(((StandardServerConnection) conn).getToken(), encryptBytes(priv, this.verifyToken))) { - conn.disconnect("Invalid client reply"); - return; - } - - conn.send(new PacketKeyResponse(new byte[0], new byte[0])); - ((StandardServerConnection) conn).setAES(conn); - } - - @Override - public int getId() { - return 252; - } - - private static byte[] encryptBytes(PrivateKey key, byte[] bytes) { - try { - Cipher cipher = Cipher.getInstance(key.getAlgorithm()); - cipher.init(2, key); - return cipher.doFinal(bytes); - } catch(InvalidKeyException e) { - e.printStackTrace(); - } catch(NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch(NoSuchPaddingException e) { - e.printStackTrace(); - } catch(IllegalBlockSizeException e) { - e.printStackTrace(); - } catch(BadPaddingException e) { - e.printStackTrace(); - } - - return null; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketLightning.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketLightning.java deleted file mode 100644 index e3dd5ae0..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketLightning.java +++ /dev/null @@ -1,67 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketLightning extends Packet { - - public int entityId; - public boolean unk; - public int x; - public int y; - public int z; - - public PacketLightning() { - } - - public PacketLightning(int entityId, boolean unk, int x, int y, int z) { - this.entityId = entityId; - this.unk = unk; - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.unk = in.readBoolean(); - this.x = in.readInt(); - this.y = in.readInt(); - this.z = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeBoolean(this.unk); - out.writeInt(this.x); - out.writeInt(this.y); - out.writeInt(this.z); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 71; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketLogin.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketLogin.java deleted file mode 100644 index b6c2486d..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketLogin.java +++ /dev/null @@ -1,86 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketLogin extends Packet { - - public static boolean FORGE = false; - - public int entityId; - public String levelType; - public byte gameMode; - public int dimension; - public byte difficulty; - public byte unused; - public byte maxPlayers; - - public PacketLogin() { - } - - public PacketLogin(int entityId, String levelType, byte gameMode, int dimension, byte difficulty, byte unused, byte maxPlayers) { - this.entityId = entityId; - this.levelType = levelType; - this.gameMode = gameMode; - this.dimension = dimension; - this.difficulty = difficulty; - this.unused = unused; - this.maxPlayers = maxPlayers; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.levelType = in.readString(); - this.gameMode = in.readByte(); - if(FORGE) { - this.dimension = in.readInt(); - } else { - this.dimension = in.readByte(); - } - - this.difficulty = in.readByte(); - this.unused = in.readByte(); - this.maxPlayers = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeString(this.levelType); - out.writeByte(this.gameMode); - if(FORGE) { - out.writeInt(this.dimension); - } else { - out.writeByte(this.dimension); - } - out.writeByte(this.difficulty); - out.writeByte(this.unused); - out.writeByte(this.maxPlayers); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 1; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMapChunk.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMapChunk.java deleted file mode 100644 index 9f72baff..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMapChunk.java +++ /dev/null @@ -1,113 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; -import java.util.zip.DataFormatException; -import java.util.zip.Deflater; -import java.util.zip.Inflater; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketMapChunk extends Packet { - - public int x; - public int z; - public boolean groundUp; - public int startY; - public int endY; - public byte data[]; - - public PacketMapChunk() { - } - - public PacketMapChunk(int x, int z, boolean groundUp, int startY, int endY, byte data[]) { - this.x = x; - this.z = z; - this.groundUp = groundUp; - this.startY = startY; - this.endY = endY; - this.data = data; - } - - @Override - public void read(NetInput in) throws IOException { - this.x = in.readInt(); - this.z = in.readInt(); - this.groundUp = in.readBoolean(); - this.startY = in.readShort(); - this.endY = in.readShort(); - int length = in.readInt(); - - byte[] compressed = in.readBytes(length); - - int off = 0; - int msb = 0; - for(int count = 0; count < 16; count++) { - off += this.startY >> count & 1; - msb += this.endY >> count & 1; - } - - int size = (12288 * off) + (2048 * msb); - if(this.groundUp) { - size += 256; - } - - this.data = new byte[size]; - Inflater inflater = new Inflater(); - inflater.setInput(compressed, 0, length); - - try { - inflater.inflate(this.data); - } catch(DataFormatException e) { - throw new IOException("Bad compressed data format"); - } finally { - inflater.end(); - } - } - - @Override - public void write(NetOutput out) throws IOException { - Deflater deflater = new Deflater(-1); - byte data[] = new byte[0]; - int length = 0; - try { - deflater.setInput(this.data, 0, this.data.length); - deflater.finish(); - data = new byte[this.data.length]; - length = deflater.deflate(this.data); - } finally { - deflater.end(); - } - - out.writeInt(this.x); - out.writeInt(this.z); - out.writeBoolean(this.groundUp); - out.writeShort((short) (this.startY & 0xffff)); - out.writeShort((short) (this.endY & 0xffff)); - out.writeInt(length); - out.writeBytes(data, length); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 51; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMapChunkBulk.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMapChunkBulk.java deleted file mode 100644 index 3c84b60d..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMapChunkBulk.java +++ /dev/null @@ -1,125 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; -import java.util.zip.DataFormatException; -import java.util.zip.Deflater; -import java.util.zip.Inflater; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketMapChunkBulk extends Packet { - - public boolean skylight; - public int columnX[]; - public int columnZ[]; - public int primary[]; - public int add[]; - public byte compressed[]; - public byte chunks[][]; - public int length; - - public PacketMapChunkBulk() { - } - - public PacketMapChunkBulk(int columnX[], int columnZ[], int primary[], int add[], byte data[], byte chunks[][], boolean skylight) { - this.columnX = columnX; - this.columnZ = columnZ; - this.primary = primary; - this.add = add; - this.skylight = skylight; - - Deflater deflater = new Deflater(-1); - - try { - deflater.setInput(data, 0, data.length); - deflater.finish(); - this.compressed = new byte[data.length]; - this.length = deflater.deflate(this.compressed); - } finally { - deflater.end(); - } - - this.chunks = chunks; - } - - @Override - public void read(NetInput in) throws IOException { - short columns = in.readShort(); - this.length = in.readInt(); - this.skylight = in.readBoolean(); - this.columnX = new int[columns]; - this.columnZ = new int[columns]; - this.primary = new int[columns]; - this.add = new int[columns]; - this.chunks = new byte[columns][]; - - this.compressed = in.readBytes(this.length); - byte decompressed[] = new byte[0x30100 * columns]; - Inflater inflater = new Inflater(); - inflater.setInput(this.compressed, 0, this.length); - - try { - inflater.inflate(decompressed); - } catch(DataFormatException e) { - throw new IOException("Bad compressed data format"); - } finally { - inflater.end(); - } - - int currlen = 0; - for(int column = 0; column < columns; column++) { - this.columnX[column] = in.readInt(); - this.columnZ[column] = in.readInt(); - this.primary[column] = in.readShort(); - this.add[column] = in.readShort(); - int off = 0; - - for(int count = 0; count < 16; count++) { - off += this.primary[column] >> count & 1; - } - - int datalen = 2048 * (5 * off) + 256; - this.chunks[column] = new byte[datalen]; - System.arraycopy(decompressed, currlen, this.chunks[column], 0, datalen); - currlen += datalen; - } - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeShort(this.columnX.length); - out.writeInt(this.length); - out.writeBoolean(this.skylight); - out.writeBytes(this.compressed, this.length); - for(int count = 0; count < this.columnX.length; count++) { - out.writeInt(this.columnX[count]); - out.writeInt(this.columnZ[count]); - out.writeShort(this.primary[count]); - out.writeShort(this.add[count]); - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 56; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMultiBlockChange.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMultiBlockChange.java deleted file mode 100644 index 1a71ae60..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMultiBlockChange.java +++ /dev/null @@ -1,71 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketMultiBlockChange extends Packet { - - public int x; - public int z; - public int records; - public byte data[]; - - public PacketMultiBlockChange() { - } - - public PacketMultiBlockChange(int x, int z, int records, byte data[]) { - this.x = x; - this.z = z; - this.records = records; - this.data = data; - } - - @Override - public void read(NetInput in) throws IOException { - this.x = in.readInt(); - this.z = in.readInt(); - this.records = in.readShort() & 0xffff; - int size = in.readInt(); - if(size > 0) { - this.data = in.readBytes(size); - } - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.x); - out.writeInt(this.z); - out.writeShort((short) this.records); - if(this.data != null) { - out.writeInt(this.data.length); - out.writeBytes(this.data); - } else { - out.writeInt(0); - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 52; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketNamedSound.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketNamedSound.java deleted file mode 100644 index daecab2f..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketNamedSound.java +++ /dev/null @@ -1,71 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketNamedSound extends Packet { - - public String sound; - public int x; - public int y; - public int z; - public float volume; - public int pitch; - - public PacketNamedSound() { - } - - public PacketNamedSound(String sound, int x, int y, int z, float volume, int pitch) { - this.sound = sound; - this.x = x; - this.y = y; - this.z = z; - this.volume = volume; - this.pitch = pitch; - } - - @Override - public void read(NetInput in) throws IOException { - this.sound = in.readString(); - this.x = in.readInt(); - this.y = in.readInt(); - this.z = in.readInt(); - this.volume = in.readFloat(); - this.pitch = in.readUnsignedByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.sound); - out.writeInt(this.x); - out.writeInt(this.y); - out.writeInt(this.z); - out.writeFloat(this.volume); - out.writeByte(this.pitch); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 62; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketOpenTileEditor.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketOpenTileEditor.java deleted file mode 100644 index b6e1d5e7..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketOpenTileEditor.java +++ /dev/null @@ -1,63 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketOpenTileEditor extends Packet { - - public byte type; - public int x; - public int y; - public int z; - - public PacketOpenTileEditor() { - } - - public PacketOpenTileEditor(byte type, int x, int y, int z) { - this.type = type; - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public void read(NetInput in) throws IOException { - this.type = in.readByte(); - this.x = in.readInt(); - this.y = in.readInt(); - this.z = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.type); - out.writeInt(this.x); - out.writeInt(this.y); - out.writeInt(this.z); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 133; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketOpenWindow.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketOpenWindow.java deleted file mode 100644 index 6cba00b3..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketOpenWindow.java +++ /dev/null @@ -1,80 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.util.Constants; - -public class PacketOpenWindow extends Packet { - - public byte id; - public byte type; - public String name; - public byte slots; - public boolean useTitle; - public int horseId; - - public PacketOpenWindow() { - } - - public PacketOpenWindow(byte id, byte type, String name, byte slots, boolean useTitle) { - this(id, type, name, slots, useTitle, 0); - } - - public PacketOpenWindow(byte id, byte type, String name, byte slots, boolean useTitle, int horseId) { - this.id = id; - this.type = type; - this.name = name; - this.slots = slots; - this.useTitle = useTitle; - this.horseId = horseId; - } - - @Override - public void read(NetInput in) throws IOException { - this.id = in.readByte(); - this.type = in.readByte(); - this.name = in.readString(); - this.slots = in.readByte(); - this.useTitle = in.readBoolean(); - if(this.type == Constants.StandardProtocol.WindowTypeIds.HORSE) { - this.horseId = in.readInt(); - } - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.id); - out.writeByte(this.type); - out.writeString(this.name); - out.writeByte(this.slots); - out.writeBoolean(this.useTitle); - if(this.type == Constants.StandardProtocol.WindowTypeIds.HORSE) { - out.writeInt(this.horseId); - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 100; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayer.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayer.java deleted file mode 100644 index 55bacc7f..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayer.java +++ /dev/null @@ -1,51 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketPlayer extends Packet { - - public boolean grounded; - - public PacketPlayer() { - } - - public PacketPlayer(boolean grounded) { - this.grounded = grounded; - } - - @Override - public void read(NetInput in) throws IOException { - this.grounded = in.readBoolean(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeBoolean(this.grounded); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 10; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerAbilities.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerAbilities.java deleted file mode 100644 index 27e93649..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerAbilities.java +++ /dev/null @@ -1,75 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.util.Util; - -public class PacketPlayerAbilities extends Packet { - - public boolean god; - public boolean flying; - public boolean canFly; - public boolean creative; - public float flySpeed; - public float walkSpeed; - - public PacketPlayerAbilities() { - } - - public PacketPlayerAbilities(boolean god, boolean flying, boolean canFly, boolean creative, float flySpeed, float walkSpeed) { - this.god = god; - this.flying = flying; - this.canFly = canFly; - this.creative = creative; - this.flySpeed = flySpeed; - this.walkSpeed = walkSpeed; - } - - @Override - public void read(NetInput in) throws IOException { - byte flags = in.readByte(); - this.god = Util.getBit(flags, 0x1); - this.flying = Util.getBit(flags, 0x2); - this.canFly = Util.getBit(flags, 0x4); - this.creative = Util.getBit(flags, 0x8); - this.flySpeed = in.readFloat(); - this.walkSpeed = in.readFloat(); - } - - @Override - public void write(NetOutput out) throws IOException { - byte flags = 0; - flags = Util.setBit(flags, 0x1, this.god); - flags = Util.setBit(flags, 0x2, this.flying); - flags = Util.setBit(flags, 0x4, this.canFly); - flags = Util.setBit(flags, 0x8, this.creative); - out.writeByte(flags); - out.writeFloat(this.flySpeed); - out.writeFloat(this.walkSpeed); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 202; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerBlockPlace.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerBlockPlace.java deleted file mode 100644 index 82b8757d..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerBlockPlace.java +++ /dev/null @@ -1,86 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.data.StandardItemStack; -import ch.spacebase.mcprotocol.standard.io.StandardInput; -import ch.spacebase.mcprotocol.standard.io.StandardOutput; - -public class PacketPlayerBlockPlace extends Packet { - - public int x; - public int y; - public int z; - public byte direction; - public StandardItemStack item; - public byte[] nbt; - public byte cursorX; - public byte cursorY; - public byte cursorZ; - - public PacketPlayerBlockPlace() { - } - - public PacketPlayerBlockPlace(int x, int y, int z, byte direction, StandardItemStack item, byte cursorX, byte cursorY, byte cursorZ) { - this.x = x; - this.y = y; - this.z = z; - this.direction = direction; - this.item = item; - this.cursorX = cursorX; - this.cursorY = cursorY; - this.cursorZ = cursorZ; - } - - @Override - public void read(NetInput in) throws IOException { - this.x = in.readInt(); - this.y = in.readUnsignedByte(); - this.z = in.readInt(); - this.direction = in.readByte(); - this.item = ((StandardInput) in).readItem(); - this.cursorX = in.readByte(); - this.cursorY = in.readByte(); - this.cursorZ = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.x); - out.writeByte(this.y); - out.writeInt(this.z); - out.writeByte(this.direction); - if(this.item != null) { - ((StandardOutput) out).writeItem(this.item); - } - - out.writeByte(this.cursorX); - out.writeByte(this.cursorY); - out.writeByte(this.cursorZ); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 15; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerDigging.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerDigging.java deleted file mode 100644 index 20ceea44..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerDigging.java +++ /dev/null @@ -1,67 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketPlayerDigging extends Packet { - - public byte status; - public int x; - public int y; - public int z; - public byte face; - - public PacketPlayerDigging() { - } - - public PacketPlayerDigging(byte status, int x, int y, int z, byte face) { - this.status = status; - this.x = x; - this.y = y; - this.z = z; - this.face = face; - } - - @Override - public void read(NetInput in) throws IOException { - this.status = in.readByte(); - this.x = in.readInt(); - this.y = in.readUnsignedByte(); - this.z = in.readInt(); - this.face = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.status); - out.writeInt(this.x); - out.writeByte(this.y); - out.writeInt(this.z); - out.writeByte(this.face); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 14; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerListItem.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerListItem.java deleted file mode 100644 index 35995032..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerListItem.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketPlayerListItem extends Packet { - - public String name; - public boolean online; - public short ping; - - public PacketPlayerListItem() { - } - - public PacketPlayerListItem(String name, boolean online, short ping) { - this.name = name; - this.online = online; - this.ping = ping; - } - - @Override - public void read(NetInput in) throws IOException { - this.name = in.readString(); - this.online = in.readBoolean(); - this.ping = in.readShort(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.name); - out.writeBoolean(this.online); - out.writeShort(this.ping); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 201; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerLook.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerLook.java deleted file mode 100644 index 47e3124d..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerLook.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketPlayerLook extends Packet { - - public float yaw; - public float pitch; - public boolean grounded; - - public PacketPlayerLook() { - } - - public PacketPlayerLook(float yaw, float pitch, boolean grounded) { - this.yaw = yaw; - this.pitch = pitch; - this.grounded = grounded; - } - - @Override - public void read(NetInput in) throws IOException { - this.yaw = in.readFloat(); - this.pitch = in.readFloat(); - this.grounded = in.readBoolean(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeFloat(this.yaw); - out.writeFloat(this.pitch); - out.writeBoolean(this.grounded); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 12; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerPosition.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerPosition.java deleted file mode 100644 index 016108ff..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerPosition.java +++ /dev/null @@ -1,67 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketPlayerPosition extends Packet { - - public double x; - public double y; - public double stance; - public double z; - public boolean grounded; - - public PacketPlayerPosition() { - } - - public PacketPlayerPosition(double x, double y, double stance, double z, boolean grounded) { - this.x = x; - this.y = y; - this.stance = stance; - this.z = z; - this.grounded = grounded; - } - - @Override - public void read(NetInput in) throws IOException { - this.x = in.readDouble(); - this.y = in.readDouble(); - this.stance = in.readDouble(); - this.z = in.readDouble(); - this.grounded = in.readBoolean(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeDouble(this.x); - out.writeDouble(this.y); - out.writeDouble(this.stance); - out.writeDouble(this.z); - out.writeBoolean(this.grounded); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 11; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerPositionLook.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerPositionLook.java deleted file mode 100644 index d7784bff..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerPositionLook.java +++ /dev/null @@ -1,75 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketPlayerPositionLook extends Packet { - - public double x; - public double y; - public double stance; - public double z; - public float yaw; - public float pitch; - public boolean grounded; - - public PacketPlayerPositionLook() { - } - - public PacketPlayerPositionLook(double x, double y, double stance, double z, float yaw, float pitch, boolean grounded) { - this.x = x; - this.y = y; - this.stance = stance; - this.z = z; - this.yaw = yaw; - this.pitch = pitch; - this.grounded = grounded; - } - - @Override - public void read(NetInput in) throws IOException { - this.x = in.readDouble(); - this.y = in.readDouble(); - this.stance = in.readDouble(); - this.z = in.readDouble(); - this.yaw = in.readFloat(); - this.pitch = in.readFloat(); - this.grounded = in.readBoolean(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeDouble(this.x); - out.writeDouble(this.y); - out.writeDouble(this.stance); - out.writeDouble(this.z); - out.writeFloat(this.yaw); - out.writeFloat(this.pitch); - out.writeBoolean(this.grounded); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 13; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPluginMessage.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPluginMessage.java deleted file mode 100644 index 5df25202..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPluginMessage.java +++ /dev/null @@ -1,56 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketPluginMessage extends Packet { - - public String channel; - public byte data[]; - - public PacketPluginMessage() { - } - - public PacketPluginMessage(String channel, byte data[]) { - this.channel = channel; - this.data = data; - } - - @Override - public void read(NetInput in) throws IOException { - this.channel = in.readString(); - this.data = in.readBytes(in.readShort()); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.channel); - out.writeShort(this.data.length); - out.writeBytes(this.data); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 250; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketRemoveEntityEffect.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketRemoveEntityEffect.java deleted file mode 100644 index 97c46e92..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketRemoveEntityEffect.java +++ /dev/null @@ -1,55 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketRemoveEntityEffect extends Packet { - - public int entityId; - public byte effect; - - public PacketRemoveEntityEffect() { - } - - public PacketRemoveEntityEffect(int entityId, byte effect) { - this.entityId = entityId; - this.effect = effect; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.effect = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.effect); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 42; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketRespawn.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketRespawn.java deleted file mode 100644 index 1577f491..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketRespawn.java +++ /dev/null @@ -1,67 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketRespawn extends Packet { - - public int dimension; - public byte difficulty; - public byte gameMode; - public short worldHeight; - public String levelType; - - public PacketRespawn() { - } - - public PacketRespawn(int dimension, byte difficulty, byte gameMode, short worldHeight, String levelType) { - this.dimension = dimension; - this.difficulty = difficulty; - this.gameMode = gameMode; - this.worldHeight = worldHeight; - this.levelType = levelType; - } - - @Override - public void read(NetInput in) throws IOException { - this.dimension = in.readInt(); - this.difficulty = in.readByte(); - this.gameMode = in.readByte(); - this.worldHeight = in.readShort(); - this.levelType = in.readString(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.dimension); - out.writeByte(this.difficulty); - out.writeByte(this.gameMode); - out.writeShort(this.worldHeight); - out.writeString(this.levelType); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 9; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketScoreboardObjective.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketScoreboardObjective.java deleted file mode 100644 index 8001c42d..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketScoreboardObjective.java +++ /dev/null @@ -1,58 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketScoreboardObjective extends Packet { - - public String name; - public String value; - public byte action; - - public PacketScoreboardObjective() { - } - - public PacketScoreboardObjective(String name, String value, byte action) { - this.name = name; - this.value = value; - this.action = action; - } - - @Override - public void read(NetInput in) throws IOException { - this.name = in.readString(); - this.value = in.readString(); - this.action = in.readByte(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.name); - out.writeString(this.value); - out.writeByte(this.action); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 206; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketServerPing.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketServerPing.java deleted file mode 100644 index 916b4a74..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketServerPing.java +++ /dev/null @@ -1,48 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.util.Constants; - -public class PacketServerPing extends Packet { - - public boolean readSuccessfully = false; - - public PacketServerPing() { - } - - @Override - public void read(NetInput in) throws IOException { - this.readSuccessfully = in.readBoolean(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(Constants.StandardProtocol.PING_MAGIC); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 254; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSetExperience.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSetExperience.java deleted file mode 100644 index 117b9f4e..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSetExperience.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketSetExperience extends Packet { - - public float experienceBar; - public short level; - public short experience; - - public PacketSetExperience() { - } - - public PacketSetExperience(float experienceBar, short level, short experience) { - this.experienceBar = experienceBar; - this.level = level; - this.experience = experience; - } - - @Override - public void read(NetInput in) throws IOException { - this.experienceBar = in.readFloat(); - this.level = in.readShort(); - this.experience = in.readShort(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeFloat(this.experienceBar); - out.writeShort(this.level); - out.writeShort(this.experience); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 43; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSetSlot.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSetSlot.java deleted file mode 100644 index 5896025a..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSetSlot.java +++ /dev/null @@ -1,64 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.data.StandardItemStack; -import ch.spacebase.mcprotocol.standard.io.StandardInput; -import ch.spacebase.mcprotocol.standard.io.StandardOutput; - -public class PacketSetSlot extends Packet { - - public byte id; - public short slot; - public StandardItemStack item; - - public PacketSetSlot() { - } - - public PacketSetSlot(byte id, short slot, StandardItemStack item) { - this.id = id; - this.slot = slot; - this.item = item; - } - - @Override - public void read(NetInput in) throws IOException { - this.id = in.readByte(); - this.slot = in.readShort(); - this.item = ((StandardInput) in).readItem(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.id); - out.writeShort(this.slot); - if(this.item != null) { - ((StandardOutput) out).writeItem(this.item); - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 103; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnExpOrb.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnExpOrb.java deleted file mode 100644 index 1dd28529..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnExpOrb.java +++ /dev/null @@ -1,67 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketSpawnExpOrb extends Packet { - - public int entityId; - public int x; - public int y; - public int z; - public short count; - - public PacketSpawnExpOrb() { - } - - public PacketSpawnExpOrb(int entityId, int x, int y, int z, short count) { - this.entityId = entityId; - this.x = x; - this.y = y; - this.z = z; - this.count = count; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.x = in.readInt(); - this.y = in.readInt(); - this.z = in.readInt(); - this.count = in.readShort(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeInt(this.x); - out.writeInt(this.y); - out.writeInt(this.z); - out.writeShort(this.count); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 26; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnMob.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnMob.java deleted file mode 100644 index d17191f0..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnMob.java +++ /dev/null @@ -1,98 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.data.WatchableObject; -import ch.spacebase.mcprotocol.standard.io.StandardInput; -import ch.spacebase.mcprotocol.standard.io.StandardOutput; - -public class PacketSpawnMob extends Packet { - - public int entityId; - public byte type; - public int x; - public int y; - public int z; - public byte yaw; - public byte pitch; - public byte headYaw; - public short velX; - public short velY; - public short velZ; - public WatchableObject metadata[]; - - public PacketSpawnMob() { - } - - public PacketSpawnMob(int entityId, byte type, int x, int y, int z, byte yaw, byte pitch, byte headYaw, short velX, short velY, short velZ, WatchableObject metadata[]) { - this.entityId = entityId; - this.type = type; - this.x = x; - this.y = y; - this.z = z; - this.yaw = yaw; - this.pitch = pitch; - this.headYaw = headYaw; - this.velX = velX; - this.velY = velY; - this.velZ = velZ; - this.metadata = metadata; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.type = in.readByte(); - this.x = in.readInt(); - this.y = in.readInt(); - this.z = in.readInt(); - this.yaw = in.readByte(); - this.pitch = in.readByte(); - this.headYaw = in.readByte(); - this.velX = in.readShort(); - this.velY = in.readShort(); - this.velZ = in.readShort(); - this.metadata = ((StandardInput) in).readMetadata(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.type); - out.writeInt(this.x); - out.writeInt(this.y); - out.writeInt(this.z); - out.writeByte(this.yaw); - out.writeByte(this.pitch); - out.writeByte(this.headYaw); - out.writeShort(this.velX); - out.writeShort(this.velY); - out.writeShort(this.velZ); - ((StandardOutput) out).writeMetadata(this.metadata); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 24; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnNamedEntity.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnNamedEntity.java deleted file mode 100644 index 9b9a5595..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnNamedEntity.java +++ /dev/null @@ -1,86 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.data.WatchableObject; -import ch.spacebase.mcprotocol.standard.io.StandardInput; -import ch.spacebase.mcprotocol.standard.io.StandardOutput; - -public class PacketSpawnNamedEntity extends Packet { - - public int entityId; - public String name; - public int x; - public int y; - public int z; - public byte yaw; - public byte pitch; - public short item; - public WatchableObject metadata[]; - - public PacketSpawnNamedEntity() { - } - - public PacketSpawnNamedEntity(int entityId, String name, int x, int y, int z, byte yaw, byte pitch, short item, WatchableObject metadata[]) { - this.entityId = entityId; - this.name = name; - this.x = x; - this.y = y; - this.z = z; - this.yaw = yaw; - this.pitch = pitch; - this.item = item; - this.metadata = metadata; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.name = in.readString(); - this.x = in.readInt(); - this.y = in.readInt(); - this.z = in.readInt(); - this.yaw = in.readByte(); - this.pitch = in.readByte(); - this.item = in.readShort(); - this.metadata = ((StandardInput) in).readMetadata(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeString(this.name); - out.writeInt(this.x); - out.writeInt(this.y); - out.writeInt(this.z); - out.writeByte(this.yaw); - out.writeByte(this.pitch); - out.writeShort(this.item); - ((StandardOutput) out).writeMetadata(this.metadata); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 20; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnObject.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnObject.java deleted file mode 100644 index 16475c2c..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnObject.java +++ /dev/null @@ -1,95 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketSpawnObject extends Packet { - - public int entityId; - public byte type; - public int x; - public int y; - public int z; - public byte pitch; - public byte yaw; - public int data; - public short speedX; - public short speedY; - public short speedZ; - - public PacketSpawnObject() { - } - - public PacketSpawnObject(int entityId, byte type, int x, int y, int z, byte yaw, byte pitch, int data, short speedX, short speedY, short speedZ) { - this.entityId = entityId; - this.type = type; - this.x = x; - this.y = y; - this.z = z; - this.yaw = yaw; - this.pitch = pitch; - this.data = data; - this.speedX = speedX; - this.speedY = speedY; - this.speedZ = speedZ; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.type = in.readByte(); - this.x = in.readInt(); - this.y = in.readInt(); - this.z = in.readInt(); - this.pitch = in.readByte(); - this.yaw = in.readByte(); - this.data = in.readInt(); - if(this.data > 0) { - this.speedX = in.readShort(); - this.speedY = in.readShort(); - this.speedZ = in.readShort(); - } - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.type); - out.writeInt(this.x); - out.writeInt(this.y); - out.writeInt(this.z); - out.writeByte(this.pitch); - out.writeByte(this.yaw); - out.writeInt(this.data); - if(this.data > 0) { - out.writeShort(this.speedX); - out.writeShort(this.speedY); - out.writeShort(this.speedZ); - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 23; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnPainting.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnPainting.java deleted file mode 100644 index cd6901d1..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnPainting.java +++ /dev/null @@ -1,71 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketSpawnPainting extends Packet { - - public int entityId; - public String title; - public int x; - public int y; - public int z; - public int direction; - - public PacketSpawnPainting() { - } - - public PacketSpawnPainting(int entityId, String title, int x, int y, int z, int direction) { - this.entityId = entityId; - this.title = title; - this.x = x; - this.y = y; - this.z = z; - this.direction = direction; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.title = in.readString(); - this.x = in.readInt(); - this.y = in.readInt(); - this.z = in.readInt(); - this.direction = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeString(this.title); - out.writeInt(this.x); - out.writeInt(this.y); - out.writeInt(this.z); - out.writeInt(this.direction); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 25; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnParticle.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnParticle.java deleted file mode 100644 index 8ab072ae..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnParticle.java +++ /dev/null @@ -1,80 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketSpawnParticle extends Packet { - - public String particle; - public float x; - public float y; - public float z; - public float offsetX; - public float offsetY; - public float offsetZ; - public float speed; - public int count; - - public PacketSpawnParticle() { - } - - public PacketSpawnParticle(String particle, float x, float y, float z, float offsetX, float offsetY, float offsetZ, float speed, int count) { - this.particle = particle; - this.x = x; - this.y = y; - this.z = z; - this.speed = speed; - this.count = count; - } - - @Override - public void read(NetInput in) throws IOException { - this.particle = in.readString(); - this.x = in.readFloat(); - this.y = in.readFloat(); - this.z = in.readFloat(); - this.offsetX = in.readFloat(); - this.offsetY = in.readFloat(); - this.offsetZ = in.readFloat(); - this.speed = in.readFloat(); - this.count = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.particle); - out.writeFloat(this.x); - out.writeFloat(this.y); - out.writeFloat(this.z); - out.writeFloat(this.offsetX); - out.writeFloat(this.offsetY); - out.writeFloat(this.offsetZ); - out.writeFloat(this.speed); - out.writeInt(this.count); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 63; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnPosition.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnPosition.java deleted file mode 100644 index 5740c40b..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSpawnPosition.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketSpawnPosition extends Packet { - - public int x; - public int y; - public int z; - - public PacketSpawnPosition() { - } - - public PacketSpawnPosition(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public void read(NetInput in) throws IOException { - this.x = in.readInt(); - this.y = in.readInt(); - this.z = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.x); - out.writeInt(this.y); - out.writeInt(this.z); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 6; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSteerVehicle.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSteerVehicle.java deleted file mode 100644 index 229a9f1c..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketSteerVehicle.java +++ /dev/null @@ -1,63 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketSteerVehicle extends Packet { - - public float sideways; - public float forward; - public boolean jump; - public boolean unmount; - - public PacketSteerVehicle() { - } - - public PacketSteerVehicle(float sideways, float forward, boolean jump, boolean unmount) { - this.sideways = sideways; - this.forward = forward; - this.jump = jump; - this.unmount = unmount; - } - - @Override - public void read(NetInput in) throws IOException { - this.sideways = in.readFloat(); - this.forward = in.readFloat(); - this.jump = in.readBoolean(); - this.unmount = in.readBoolean(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeFloat(this.sideways); - out.writeFloat(this.forward); - out.writeBoolean(this.jump); - out.writeBoolean(this.unmount); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 27; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketTabComplete.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketTabComplete.java deleted file mode 100644 index c0087b29..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketTabComplete.java +++ /dev/null @@ -1,51 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketTabComplete extends Packet { - - public String text; - - public PacketTabComplete() { - } - - public PacketTabComplete(String text) { - this.text = text; - } - - @Override - public void read(NetInput in) throws IOException { - this.text = in.readString(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.text); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 203; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketTeam.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketTeam.java deleted file mode 100644 index c0aff786..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketTeam.java +++ /dev/null @@ -1,169 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketTeam extends Packet { - - public String name; - public byte action; - public String displayName; - public String prefix; - public String suffix; - public byte friendlyFire; - public String players[]; - - public PacketTeam() { - } - - /** - * Creates a packet for removing a team. - * @param name Name of the team. - */ - public PacketTeam(String name) { - this.name = name; - this.action = 1; - } - - /** - * Creates a packet for adding or removing a team member. - * @param name Name of the team. - * @param players Players to add or remove - * @param add Whether to add or remove players. - */ - public PacketTeam(String name, String players[], boolean add) { - this.name = name; - this.players = players; - this.action = add ? (byte) 3 : 4; - } - - /** - * Creates a packet for updating a team. - * @param name Name of the team. - * @param displayName Display name of the team. - * @param prefix Prefix for team members. - * @param suffix Suffix for team members. - * @param friendlyFire Friendly fire mode for the team. - */ - public PacketTeam(String name, String displayName, String prefix, String suffix, byte friendlyFire) { - this.name = name; - this.displayName = displayName; - this.prefix = prefix; - this.suffix = suffix; - this.friendlyFire = friendlyFire; - this.action = 2; - } - - /** - * Creates a packet for adding a team. - * @param name Name of the team. - * @param displayName Display name of the team. - * @param prefix Prefix for team members. - * @param suffix Suffix for team members. - * @param friendlyFire Friendly fire mode for the team. - * @param players Players in the team. - */ - public PacketTeam(String name, String displayName, String prefix, String suffix, byte friendlyFire, String players[]) { - this.name = name; - this.displayName = displayName; - this.prefix = prefix; - this.suffix = suffix; - this.friendlyFire = friendlyFire; - this.players = players; - this.action = 0; - } - - @Override - public void read(NetInput in) throws IOException { - this.name = in.readString(); - this.action = in.readByte(); - switch(this.action) { - case 0: - this.displayName = in.readString(); - this.prefix = in.readString(); - this.suffix = in.readString(); - this.friendlyFire = in.readByte(); - this.players = new String[in.readShort()]; - for(int ind = 0; ind < this.players.length; ind++) { - this.players[ind] = in.readString(); - } - - break; - case 1: - break; - case 2: - this.displayName = in.readString(); - this.prefix = in.readString(); - this.suffix = in.readString(); - this.friendlyFire = in.readByte(); - break; - case 3: - case 4: - this.players = new String[in.readShort()]; - for(int ind = 0; ind < this.players.length; ind++) { - this.players[ind] = in.readString(); - } - - break; - } - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.name); - out.writeByte(this.action); - switch(this.action) { - case 0: - out.writeString(this.displayName); - out.writeString(this.prefix); - out.writeString(this.suffix); - out.writeByte(this.friendlyFire); - out.writeShort(this.players.length); - for(int ind = 0; ind < this.players.length; ind++) { - out.writeString(this.players[ind]); - } - - break; - case 1: - break; - case 2: - out.writeString(this.displayName); - out.writeString(this.prefix); - out.writeString(this.suffix); - out.writeByte(this.friendlyFire); - break; - case 3: - case 4: - out.writeShort(this.players.length); - for(int ind = 0; ind < this.players.length; ind++) { - out.writeString(this.players[ind]); - } - - break; - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 209; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketTimeUpdate.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketTimeUpdate.java deleted file mode 100644 index 73102a28..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketTimeUpdate.java +++ /dev/null @@ -1,55 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketTimeUpdate extends Packet { - - public long age; - public long time; - - public PacketTimeUpdate() { - } - - public PacketTimeUpdate(long age, long time) { - this.age = age; - this.time = time; - } - - @Override - public void read(NetInput in) throws IOException { - this.age = in.readLong(); - this.time = in.readLong(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeLong(this.age); - out.writeLong(this.time); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 4; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUpdateScoreboard.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUpdateScoreboard.java deleted file mode 100644 index 9ff79de1..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUpdateScoreboard.java +++ /dev/null @@ -1,66 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketUpdateScoreboard extends Packet { - - public String item; - public byte action; - public String scoreboard; - public int value; - - public PacketUpdateScoreboard() { - } - - public PacketUpdateScoreboard(String item, byte action, String scoreboard, int value) { - this.item = item; - this.action = action; - this.scoreboard = scoreboard; - this.value = value; - } - - @Override - public void read(NetInput in) throws IOException { - this.item = in.readString(); - this.action = in.readByte(); - if(this.action != 1) { - this.scoreboard = in.readString(); - this.value = in.readInt(); - } - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeString(this.item); - out.writeByte(this.action); - if(this.action != 1) { - out.writeString(this.scoreboard); - out.writeInt(this.value); - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 207; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUpdateSign.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUpdateSign.java deleted file mode 100644 index 15c1447e..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUpdateSign.java +++ /dev/null @@ -1,71 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketUpdateSign extends Packet { - - public int x; - public short y; - public int z; - public String lines[]; - - public PacketUpdateSign() { - } - - public PacketUpdateSign(int x, short y, int z, String lines[]) { - this.x = x; - this.y = y; - this.z = z; - this.lines = lines; - if(this.lines == null || this.lines.length != 4) throw new IllegalArgumentException("Line array size must be 4!"); - } - - @Override - public void read(NetInput in) throws IOException { - this.x = in.readInt(); - this.y = in.readShort(); - this.z = in.readInt(); - this.lines = new String[4]; - this.lines[0] = in.readString(); - this.lines[1] = in.readString(); - this.lines[2] = in.readString(); - this.lines[3] = in.readString(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.x); - out.writeShort(this.y); - out.writeInt(this.z); - out.writeString(this.lines[0]); - out.writeString(this.lines[1]); - out.writeString(this.lines[2]); - out.writeString(this.lines[3]); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 130; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUpdateTileEntity.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUpdateTileEntity.java deleted file mode 100644 index 77342fb2..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUpdateTileEntity.java +++ /dev/null @@ -1,70 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketUpdateTileEntity extends Packet { - - public int x; - public short y; - public int z; - public byte action; - public byte nbt[]; - - public PacketUpdateTileEntity() { - } - - public PacketUpdateTileEntity(int x, short y, int z, byte action, byte nbt[]) { - this.x = x; - this.y = y; - this.z = z; - this.action = action; - this.nbt = nbt; - } - - @Override - public void read(NetInput in) throws IOException { - this.x = in.readInt(); - this.y = in.readShort(); - this.z = in.readInt(); - this.action = in.readByte(); - this.nbt = in.readBytes(in.readShort()); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.x); - out.writeShort(this.y); - out.writeInt(this.z); - out.writeByte(this.action); - if(this.nbt != null) { - out.writeShort(this.nbt.length); - out.writeBytes(this.nbt); - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 132; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUseBed.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUseBed.java deleted file mode 100644 index 311d9491..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUseBed.java +++ /dev/null @@ -1,67 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketUseBed extends Packet { - - public int entityId; - public byte unknown; - public int x; - public int y; - public int z; - - public PacketUseBed() { - } - - public PacketUseBed(int entityId, byte unknown, int x, int y, int z) { - this.entityId = entityId; - this.unknown = unknown; - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public void read(NetInput in) throws IOException { - this.entityId = in.readInt(); - this.unknown = in.readByte(); - this.x = in.readInt(); - this.y = in.readUnsignedByte(); - this.z = in.readInt(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.entityId); - out.writeByte(this.unknown); - out.writeInt(this.x); - out.writeByte(this.y); - out.writeInt(this.z); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 17; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUseEntity.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUseEntity.java deleted file mode 100644 index 55147943..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketUseEntity.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketUseEntity extends Packet { - - public int user; - public int target; - public boolean leftclick; - - public PacketUseEntity() { - } - - public PacketUseEntity(int user, int target, boolean leftclick) { - this.user = user; - this.target = target; - this.leftclick = leftclick; - } - - @Override - public void read(NetInput in) throws IOException { - this.user = in.readInt(); - this.target = in.readInt(); - this.leftclick = in.readBoolean(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeInt(this.user); - out.writeInt(this.target); - out.writeBoolean(this.leftclick); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 7; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketWindowClick.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketWindowClick.java deleted file mode 100644 index 16eba853..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketWindowClick.java +++ /dev/null @@ -1,76 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.data.StandardItemStack; -import ch.spacebase.mcprotocol.standard.io.StandardInput; -import ch.spacebase.mcprotocol.standard.io.StandardOutput; - -public class PacketWindowClick extends Packet { - - public byte id; - public short slot; - public byte mousebutton; - public short action; - public byte type; - public StandardItemStack clicked; - - public PacketWindowClick() { - } - - public PacketWindowClick(byte id, short slot, byte mousebutton, short action, byte type, StandardItemStack clicked) { - this.id = id; - this.slot = slot; - this.mousebutton = mousebutton; - this.action = action; - this.type = type; - this.clicked = clicked; - } - - @Override - public void read(NetInput in) throws IOException { - this.id = in.readByte(); - this.slot = in.readShort(); - this.mousebutton = in.readByte(); - this.action = in.readShort(); - this.type = in.readByte(); - this.clicked = ((StandardInput) in).readItem(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.id); - out.writeShort(this.slot); - out.writeByte(this.mousebutton); - out.writeShort(this.action); - out.writeByte(this.type); - if(this.clicked != null) { - ((StandardOutput) out).writeItem(this.clicked); - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 102; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketWindowItems.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketWindowItems.java deleted file mode 100644 index 22020a23..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketWindowItems.java +++ /dev/null @@ -1,64 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; -import ch.spacebase.mcprotocol.standard.data.StandardItemStack; -import ch.spacebase.mcprotocol.standard.io.StandardInput; -import ch.spacebase.mcprotocol.standard.io.StandardOutput; - -public class PacketWindowItems extends Packet { - - public byte id; - public StandardItemStack items[]; - - public PacketWindowItems() { - } - - public PacketWindowItems(byte id, StandardItemStack items[]) { - this.id = id; - this.items = items; - } - - @Override - public void read(NetInput in) throws IOException { - this.id = in.readByte(); - this.items = new StandardItemStack[in.readShort()]; - for(int count = 0; count < this.items.length; count++) { - this.items[count] = ((StandardInput) in).readItem(); - } - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.id); - out.writeShort(this.items.length); - for(StandardItemStack item : this.items) { - ((StandardOutput) out).writeItem(item); - } - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 104; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketWindowProperty.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketWindowProperty.java deleted file mode 100644 index dcc94ce0..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketWindowProperty.java +++ /dev/null @@ -1,59 +0,0 @@ -package ch.spacebase.mcprotocol.standard.packet; - -import ch.spacebase.mcprotocol.event.PacketVisitor; -import ch.spacebase.mcprotocol.net.io.NetInput; -import ch.spacebase.mcprotocol.net.io.NetOutput; -import java.io.IOException; - -import ch.spacebase.mcprotocol.net.Client; -import ch.spacebase.mcprotocol.net.ServerConnection; -import ch.spacebase.mcprotocol.packet.Packet; - -public class PacketWindowProperty extends Packet { - - public byte id; - public short prop; - public short value; - - public PacketWindowProperty() { - } - - public PacketWindowProperty(byte id, short prop, short value) { - this.id = id; - this.prop = prop; - this.value = value; - } - - @Override - public void read(NetInput in) throws IOException { - this.id = in.readByte(); - this.prop = in.readShort(); - this.value = in.readShort(); - } - - @Override - public void write(NetOutput out) throws IOException { - out.writeByte(this.id); - out.writeShort(this.prop); - out.writeShort(this.value); - } - - @Override - public void handleClient(Client conn) { - } - - @Override - public void handleServer(ServerConnection conn) { - } - - @Override - public int getId() { - return 105; - } - - @Override - public void accept(PacketVisitor visitor) { - visitor.visit(this); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/util/PluginMessageBuilder.java b/src/main/java/ch/spacebase/mcprotocol/standard/util/PluginMessageBuilder.java deleted file mode 100644 index 15a8e439..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/util/PluginMessageBuilder.java +++ /dev/null @@ -1,211 +0,0 @@ -package ch.spacebase.mcprotocol.standard.util; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import ch.spacebase.mcprotocol.standard.io.StandardOutput; -import ch.spacebase.mcprotocol.standard.packet.PacketPluginMessage; -import ch.spacebase.mcprotocol.util.Util; - -/** - * A utility used to build plugin message packets. - */ -public class PluginMessageBuilder { - - /** - * The channel of the plugin message. - */ - private String channel; - - /** - * The internal output used in building the data. - */ - private StandardOutput out; - - /** - * Creates a new plugin message builder. - * @param channel Channel of the plugin message. - */ - public PluginMessageBuilder(String channel) { - this.channel = channel; - this.out = new StandardOutput(new ByteArrayOutputStream()); - } - - /** - * Writes a byte to the plugin message data. - * @param b Byte to write. - * @return This plugin message builder. - */ - public PluginMessageBuilder writeByte(int b) { - try { - this.out.writeByte(b); - } catch(IOException e) { - Util.logger().severe("Failed to write to plugin message"); - e.printStackTrace(); - } - - return this; - } - - /** - * Writes a boolean to the plugin message data. - * @param b Boolean to write. - * @return This plugin message builder. - */ - public PluginMessageBuilder writeBoolean(boolean b) { - try { - this.out.writeBoolean(b); - } catch(IOException e) { - Util.logger().severe("Failed to write to plugin message"); - e.printStackTrace(); - } - - return this; - } - - /** - * Writes a short to the plugin message data. - * @param s Short to write. - * @return This plugin message builder. - */ - public PluginMessageBuilder writeShort(int s) { - try { - this.out.writeShort(s); - } catch(IOException e) { - Util.logger().severe("Failed to write to plugin message"); - e.printStackTrace(); - } - - return this; - } - - /** - * Writes a char to the plugin message data. - * @param c Char to write. - * @return This plugin message builder. - */ - public PluginMessageBuilder writeChar(int c) { - try { - this.out.writeChar(c); - } catch(IOException e) { - Util.logger().severe("Failed to write to plugin message"); - e.printStackTrace(); - } - return this; - } - - /** - * Writes an int to the plugin message data. - * @param i int to write. - * @return This plugin message builder. - */ - public PluginMessageBuilder writeInt(int i) { - try { - this.out.writeInt(i); - } catch(IOException e) { - Util.logger().severe("Failed to write to plugin message"); - e.printStackTrace(); - } - - return this; - } - - /** - * Writes a long to the plugin message data. - * @param l Long to write. - * @return This plugin message builder. - */ - public PluginMessageBuilder writeLong(long l) { - try { - this.out.writeLong(l); - } catch(IOException e) { - Util.logger().severe("Failed to write to plugin message"); - e.printStackTrace(); - } - - return this; - } - - /** - * Writes a float to the plugin message data. - * @param f Float to write. - * @return This plugin message builder. - */ - public PluginMessageBuilder writeFloat(float f) { - try { - this.out.writeFloat(f); - } catch(IOException e) { - Util.logger().severe("Failed to write to plugin message"); - e.printStackTrace(); - } - - return this; - } - - /** - * Writes a double to the plugin message data. - * @param d Double to write. - * @return This plugin message builder. - */ - public PluginMessageBuilder writeDouble(double d) { - try { - this.out.writeDouble(d); - } catch(IOException e) { - Util.logger().severe("Failed to write to plugin message"); - e.printStackTrace(); - } - - return this; - } - - /** - * Writes a byte array to the plugin message data, prepending the array - * length. - * @param b Bytes to write. - * @return This plugin message builder. - */ - public PluginMessageBuilder writeBytes(byte b[]) { - try { - this.out.writeShort(b.length); - this.out.writeBytes(b); - } catch(IOException e) { - Util.logger().severe("Failed to write to plugin message"); - e.printStackTrace(); - } - - return this; - } - - /** - * Writes a string to the plugin message data. - * @param s String to write. - * @return This plugin message builder. - */ - public PluginMessageBuilder writeString(String s) { - try { - this.out.writeString(s); - } catch(IOException e) { - Util.logger().severe("Failed to write to plugin message"); - e.printStackTrace(); - } - - return this; - } - - /** - * Gets the current length of the written data. - * @return The data's current length. - */ - public int length() { - return ((ByteArrayOutputStream) this.out.getStream()).size(); - } - - /** - * Builds a plugin message from the currently stored data. - * @return The built plugin message. - */ - public PacketPluginMessage build() { - return new PacketPluginMessage(this.channel, ((ByteArrayOutputStream) this.out.getStream()).toByteArray()); - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/util/PluginMessageReader.java b/src/main/java/ch/spacebase/mcprotocol/standard/util/PluginMessageReader.java deleted file mode 100644 index f79ced4e..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/standard/util/PluginMessageReader.java +++ /dev/null @@ -1,140 +0,0 @@ -package ch.spacebase.mcprotocol.standard.util; - -import java.io.ByteArrayInputStream; -import java.io.IOException; - -import ch.spacebase.mcprotocol.standard.io.StandardInput; -import ch.spacebase.mcprotocol.standard.packet.PacketPluginMessage; - -/** - * A utility for reading plugin message packets. - */ -public class PluginMessageReader { - - /** - * The internal stream used to read data. - */ - private StandardInput in; - - /** - * The array being read from. - */ - private byte data[]; - - /** - * Creates a new plugin message reader. - * @param packet Packet to read from. - */ - public PluginMessageReader(PacketPluginMessage packet) { - this.in = new StandardInput(new ByteArrayInputStream(packet.data)); - this.data = packet.data; - } - - /** - * Reads the next byte from the message data. - * @return The next byte in the array. - * @throws IOException If an I/O error occurs. - */ - public byte readByte() throws IOException { - return this.in.readByte(); - } - - /** - * Reads the next unsigned byte from the message data. - * @return The next unsigned byte in the array. - * @throws IOException If an I/O error occurs. - */ - public int readUnsignedByte() throws IOException { - return this.in.readUnsignedByte(); - } - - /** - * Reads the next short from the message data. - * @return The next short in the array. - * @throws IOException If an I/O error occurs. - */ - public short readShort() throws IOException { - return this.in.readShort(); - } - - /** - * Reads the unsigned short from the message data. - * @return The next unsigned short in the array. - * @throws IOException If an I/O error occurs. - */ - public int readUnsignedShort() throws IOException { - return this.in.readUnsignedShort(); - } - - /** - * Reads the next char from the message data. - * @return The next char in the array. - * @throws IOException If an I/O error occurs. - */ - public char readChar() throws IOException { - return this.in.readChar(); - } - - /** - * Reads the next int from the message data. - * @return The next int in the array. - * @throws IOException If an I/O error occurs. - */ - public int readInt() throws IOException { - return this.in.readInt(); - } - - /** - * Reads the next long from the message data. - * @return The next long in the array. - * @throws IOException If an I/O error occurs. - */ - public long readLong() throws IOException { - return this.in.readLong(); - } - - /** - * Reads the next float from the message data. - * @return The next float in the array. - * @throws IOException If an I/O error occurs. - */ - public float readFloat() throws IOException { - return this.in.readFloat(); - } - - /** - * Reads the next double from the message data. - * @return The next double in the array. - * @throws IOException If an I/O error occurs. - */ - public double readDouble() throws IOException { - return this.in.readDouble(); - } - - /** - * Reads the given amount of bytes from the message data. - * @return An array containing the read bytes. - * @throws IOException If an I/O error occurs. - */ - public byte[] readBytes(int length) throws IOException { - return this.in.readBytes(length); - } - - /** - * Reads the next string from the message data. - * @return The next string in the array. - * @throws IOException If an I/O error occurs. - */ - public String readString() throws IOException { - return this.in.readString(); - } - - /** - * Gets the length of the data. - * @return The data's length. - */ - public int length() { - return this.data.length; - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/util/Constants.java b/src/main/java/ch/spacebase/mcprotocol/util/Constants.java deleted file mode 100644 index b022a2df..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/util/Constants.java +++ /dev/null @@ -1,466 +0,0 @@ -package ch.spacebase.mcprotocol.util; - -import java.util.UUID; - -/** - * Contains constant values relating to protocol. - */ -public class Constants { - - /** - * The current Minecraft launcher version. - */ - public static final int LAUNCHER_VERSION = 13; - - /** - * Contains constant values relating to standard Minecraft protocol. - */ - public static class StandardProtocol { - /** - * The current protocol version. - */ - public static final byte PROTOCOL_VERSION = 74; - - /** - * The current game version. - */ - public static final String MINECRAFT_VERSION = "1.6.2"; - - /** - * The server list ping magic value. - */ - public static final byte PING_MAGIC = 1; - - /** - * Contains animation ids. - */ - public static class AnimationIds { - public static final byte NONE = 0; - public static final byte ARM_SWING = 1; - public static final byte DAMAGE = 2; - public static final byte LEAVE_BED = 3; - public static final byte EAT_FOOD = 5; - public static final byte UNKNOWN = 102; - public static final byte CROUCH = 104; - public static final byte UNCROUCH = 105; - } - - /** - * Contains view distance ids. - */ - public static class ViewDistanceIds { - public static final byte FAR = 0; - public static final byte NORMAL = 1; - public static final byte SHORT = 2; - public static final byte TINY = 3; - } - - /** - * Contains difficulty ids. - */ - public static class DifficultyIds { - public static final byte PEACEFUL = 0; - public static final byte EASY = 1; - public static final byte NORMAL = 2; - public static final byte HARD = 3; - } - - /** - * Contains client status ids. - */ - public static class ClientStatusIds { - public static final byte INITIAL_SPAWN = 0; - public static final byte RESPAWN = 1; - } - - /** - * Contains entity action ids. - */ - public static class EntityActionIds { - public static final byte CROUCH = 1; - public static final byte UNCROUCH = 2; - public static final byte LEAVE_BED = 3; - public static final byte START_SPRINTING = 4; - public static final byte STOP_SPRINTING = 5; - } - - /** - * Contains entity status ids. - */ - public static class EntityStatusIds { - public static final byte HURT = 2; - public static final byte DEAD = 3; - public static final byte TAMING = 6; - public static final byte TAMED = 7; - public static final byte SHAKING_WATER = 8; - public static final byte EATING_ACCEPT = 9; - public static final byte SHEEP_EATING = 10; - public static final byte IRON_GOLEM_ROSE = 11; - public static final byte SPAWN_HEART_PARTICLES = 12; - public static final byte SPAWN_ANGRY_PARTICLES = 13; - public static final byte SPAWN_LOVE_PARTICLES = 14; - public static final byte SPAWN_MAGIC_PARTICLES = 15; - public static final byte ZOMBIE_INTO_VILLAGER = 16; - public static final byte EXPLODING_FIREWORK = 17; - public static final byte MOVE_TO_REPLICAPARTITION = 125; - public static final byte CONVERT_TO_AUTHORITATIVE = 126; - public static final byte CONVERT_TO_REPLICA = 127; - } - - /** - * Contains game state ids. - */ - public static class GameStateIds { - public static final byte INVALID_BED = 0; - public static final byte BEGIN_RAIN = 1; - public static final byte END_RAIN = 2; - public static final byte CHANGE_GAMEMODE = 3; - public static final byte ENTER_CREDITS = 4; - } - - /** - * Contains game mode ids. - */ - public static class GameModeIds { - public static final byte SURVIVAL = 0; - public static final byte CREATIVE = 1; - public static final byte ADVENTURE = 2; - } - - /** - * Contains dimension ids. - */ - public static class DimensionIds { - public static final byte NETHER = -1; - public static final byte NORMAL = 0; - public static final byte END = 1; - } - - /** - * Contains window type ids. - */ - public static class WindowTypeIds { - public static final byte CHEST = 0; - public static final byte WORKBENCH = 1; - public static final byte FURNACE = 2; - public static final byte DISPENSER = 3; - public static final byte ENCHANTMENT_TABLE = 4; - public static final byte BREWING_STAND = 5; - public static final byte NPC_TRADE = 6; - public static final byte BEACON = 7; - public static final byte ANVIL = 8; - public static final byte HOPPER = 9; - public static final byte DROPPER = 10; - public static final byte HORSE = 11; - } - - /** - * Contains scoreboard objective ids. - */ - public static class SBObjectiveIds { - public static final byte CREATE = 0; - public static final byte REMOVE = 1; - public static final byte UPDATE_TEXT = 2; - } - - /** - * Contains team action ids. - */ - public static class TeamActionIds { - public static final byte CREATE = 0; - public static final byte REMOVE = 1; - public static final byte UPDATE = 2; - public static final byte ADD_PLAYER = 3; - public static final byte REMOVE_PLAYER = 4; - } - - /** - * Contains friendly fire ids. - */ - public static class FriendlyFireIds { - public static final byte OFF = 0; - public static final byte ON = 1; - public static final byte SEE_INVISIBLE_TEAMMATES = 3; - } - - /** - * Contains ids for updating scoreboards. - */ - public static class UpdateSBIds { - public static final byte CREATE_OR_UPDATE = 0; - public static final byte REMOVE = 1; - } - - /** - * Contains ids for updating tile entities. - */ - public static class UpdateTileEntityIds { - public static final byte SET_MOB = 1; - } - - /** - * Contains window property ids. - */ - public static class WindowPropertyIds { - public static final byte FURNACE_SET_PROGRESS = 0; - public static final byte FURNACE_SET_FUEL = 0; - public static final byte ENCHANT_SLOT_0 = 0; - public static final byte ENCHANT_SLOT_1 = 1; - public static final byte ENCHANT_SLOT_2 = 2; - } - - /** - * Contains mob ids. - */ - public static class MobIds { - public static final byte CREEPER = 50; - public static final byte SKELETON = 51; - public static final byte SPIDER = 52; - public static final byte GIANT_ZOMBIE = 53; - public static final byte ZOMBIE = 54; - public static final byte SLIME = 55; - public static final byte GHAST = 56; - public static final byte ZOMBIE_PIGMAN = 57; - public static final byte ENDERMAN = 58; - public static final byte CAVE_SPIDER = 59; - public static final byte SILVERFISH = 60; - public static final byte BLAZE = 61; - public static final byte MAGMA_CUBE = 62; - public static final byte ENDER_DRAGON = 63; - public static final byte WITHER = 64; - public static final byte BAT = 65; - public static final byte WITCH = 66; - public static final byte PIG = 90; - public static final byte SHEEP = 91; - public static final byte COW = 92; - public static final byte CHICKEN = 93; - public static final byte SQUID = 94; - public static final byte WOLF = 95; - public static final byte MOOSHROOM = 96; - public static final byte SNOWMAN = 97; - public static final byte OCELOT = 98; - public static final byte IRON_GOLEM = 99; - public static final byte VILLAGER = 120; - } - - /** - * Contains object ids. - */ - public static class ObjectIds { - public static final byte BOAT = 1; - public static final byte ITEM_STACK = 2; - public static final byte MINECART = 10; - public static final byte ACTIVE_TNT = 50; - public static final byte ENDERCRYSTAL = 51; - public static final byte ARROW = 60; - public static final byte SNOWBALL = 61; - public static final byte EGG = 62; - public static final byte ENDERPEARL = 65; - public static final byte WITHER_SKULL = 66; - public static final byte FALLING_OBJECT = 70; - public static final byte ITEM_FRAME = 71; - public static final byte EYE_OF_ENDER = 72; - public static final byte THROWN_POTION = 73; - public static final byte FALLING_DRAGON_EGG = 74; - public static final byte XP_BOTTLE = 75; - public static final byte FISHING_HOOK = 90; - } - - /** - * Contains standard plugin channels. - */ - public static class PluginChannels { - public static final String REGISTER = "REGISTER"; - public static final String UNREGISTER = "UNREGISTER"; - public static final String COMMAND_BLOCK = "MC|AdvCdm"; - public static final String BEACON = "MC|Beacon"; - public static final String EDIT_BOOK = "MC|BEdit"; - public static final String SIGN_BOOK = "MC|BSign"; - public static final String ANVIL_NAME = "MC|ItemName"; - public static final String SERVER_TEXTURE_PACK = "MC|TPack"; - public static final String NPC_TRADES = "MC|TrList"; - public static final String SELECT_TRADE = "MC|TrSel"; - public static final String CLIENT_PING_DATA = "MC|PingHost"; - public static final String BRAND = "MC|Brand"; - } - - /** - * Contains entity attribute ids. - */ - public static class EntityAttributes { - public static final String MAX_HEALTH = "generic.maxHealth"; - public static final String FOLLOW_RANGE = "generic.followRange"; - public static final String KNOCKBACK_RESISTANCE = "generic.knockbackResistance"; - public static final String MOVEMENT_SPEED = "generic.movementSpeed"; - public static final String ATTACK_DAMAGE = "generic.attackDamage"; - public static final String HORSE_JUMP_STRENGTH = "horse.jumpStrength"; - public static final String ZOMBIE_SPAWN_REINFORCEMENTS = "zombie.spawnReinforcements"; - } - - /** - * Contains entity attribute modifier operations. - */ - public static class ModifierOperations { - public static final int ADD = 0; - public static final int ADD_MULTIPLIED = 1; - public static final int MULTIPLY = 2; - } - - /** - * Contains entity attribute modifier unique ids. - */ - public static class ModifierUIDs { - public static final UUID CREATURE_FLEE_SPEED_BONUS = UUID.fromString("E199AD21-BA8A-4C53-8D13-6182D5C69D3A"); - public static final UUID ENDERMAN_ATTACK_SPEED_BOOST = UUID.fromString("020E0DFB-87AE-4653-9556-831010E291A0"); - public static final UUID SPRINT_SPEED_BOOST = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D"); - public static final UUID PIGZOMBIE_ATTACK_SPEED_BOOST = UUID.fromString("49455A49-7EC5-45BA-B886-3B90B23A1718"); - public static final UUID WITCH_DRINKING_SPEED_PENALTY = UUID.fromString("5CD17E52-A79A-43D3-A529-90FDE04B181E"); - public static final UUID ZOMBIE_BABY_SPEED_BOOST = UUID.fromString("B9766B59-9566-4402-BC1F-2EE2A276D836"); - public static final UUID ITEM_MODIFIER = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"); - public static final UUID SPEED_POTION_MODIFIER = UUID.fromString("91AEAA56-376B-4498-935B-2F7F68070635"); - public static final UUID HEALTH_BOOST_POTION_MODIFIER = UUID.fromString("5D6F0BA2-1186-46AC-B896-C61C5CEE99CC"); - public static final UUID SLOW_POTION_MODIFIER = UUID.fromString("7107DE5E-7CE8-4030-940E-514C1F160890"); - public static final UUID STRENGTH_POTION_MODIFIER = UUID.fromString("648D7064-6A60-4F59-8ABE-C2C23A6DD7A9"); - public static final UUID WEAKNESS_POTION_MODIFIER = UUID.fromString("22653B89-116E-49DC-9B6B-9971489B5BE5"); - } - - /** - * Contains statistic ids. - */ - public static class Statistics { - public static final int START_GAME = 1000; - public static final int CREATE_WORLD = 1001; - public static final int LOAD_WORLD = 1002; - public static final int JOIN_MULTIPLAYER = 1003; - public static final int LEAVE_GAME = 1004; - public static final int PLAY_ONE_MINUTE = 1100; - public static final int WALK_ONE_CM = 2000; - public static final int SWIM_ONE_CM = 2001; - public static final int FALL_ONE_CM = 2002; - public static final int CLIMB_ONE_CM = 2003; - public static final int FLY_ONE_CM = 2004; - public static final int DIVE_ONE_CM = 2005; - public static final int MINECART_ONE_CM = 2006; - public static final int BOAT_ONE_CM = 2007; - public static final int PIG_ONE_CM = 2008; - public static final int JUMP = 2010; - public static final int DROP = 2011; - public static final int DAMAGE_DEALT = 2020; - public static final int DAMAGE_TAKEN = 2021; - public static final int DEATHS = 2022; - public static final int MOB_KILLS = 2023; - public static final int PLAYER_KILLS = 2024; - public static final int FISH_CAUGHT = 2025; - - private static final int MINE_BLOCK_BASE = 16777216; - private static final int CRAFT_ITEM_BASE = 16842752; - private static final int USE_ITEM_BASE = 16908288; - private static final int BREAK_ITEM_BASE = 16973824; - - /** - * Gets the statistic value for mining a block. - * @param block Block mined. - * @return Statistic value for the block. - */ - public static int mineBlock(int block) { - return MINE_BLOCK_BASE + block; - } - - /** - * Gets the statistic value for crafting an item. - * @param item Item crafted. - * @return Statistic value for the item. - */ - public static int craftItem(int item) { - return CRAFT_ITEM_BASE + item; - } - - /** - * Gets the statistic value for using an item. - * @param item Item used. - * @return Statistic value for the item. - */ - public static int useItem(int item) { - return USE_ITEM_BASE + item; - } - - /** - * Gets the statistic value for breaking an item. - * @param item Item broken. - * @return Statistic value for the item. - */ - public static int breakItem(int item) { - return BREAK_ITEM_BASE + item; - } - } - - /** - * Contains watchable object ids. - */ - public static class WatchableObjectIds { - public static final byte BYTE = 0; - public static final byte SHORT = 1; - public static final byte INT = 2; - public static final byte FLOAT = 3; - public static final byte STRING = 4; - public static final byte ITEM_STACK = 5; - public static final byte COORDINATES = 6; - } - - /** - * Contains tile editor ids. - */ - public static class TileEditorIds { - public static final byte SIGN = 0; - } - - /** - * Contains particle names. - */ - public static class ParticleNames { - public static final String SMOKE = "smoke"; - public static final String LARGE_SMOKE = "largesmoke"; - public static final String BLOCK_BREAK_ANIM = "iconcrack_"; - public static final String SNOWBALL_BREAK = "snowballpoof"; - public static final String TOOL_BREAK = "tilecrack_"; - public static final String PORTAL = "portal"; - public static final String SPLASH = "splash"; - public static final String BUBBLES = "bubble"; - public static final String MYCELIUM_SPORES = "townaura"; - public static final String EXPLOSION = "hugeexplosion"; - public static final String FLAME = "flame"; - public static final String HEART = "heart"; - public static final String CRITICAL_HIT_SPARK = "crit"; - public static final String ENCHANTED_WEAPON_SPARK = "magicCrit"; - public static final String NOTE_BLOCK = "note"; - public static final String MAGIC_RUNES = "enchantmenttable"; - public static final String LAVA_SPARK = "lava"; - public static final String FOOTSTEPS = "footstep"; - public static final String REDSTONE_FUMES = "reddust"; - public static final String WATER_DRIPPING = "dripWater"; - public static final String LAVA_DRIPPING = "dripLava"; - public static final String SLIME_SPLATTER = "slime"; - } - } - - /** - * Contains constant values relating to classic Minecraft protocol. - */ - public static class ClassicProtocol { - /** - * The current protocol version. - */ - public static final byte PROTOCOL_VERSION = 7; - } - - /** - * Contains constant values relating to Minecraft Pocket Edition protocol. - */ - public static class PocketProtocol { - /** - * The protocol magic value. - */ - public static final byte[] MAGIC = new byte[] { 0, -1, -1, 0, -2, -2, -2, -2, -3, -3, -3, -3, 18, 52, 86, 120 }; - } - -} diff --git a/src/main/java/ch/spacebase/mcprotocol/util/Util.java b/src/main/java/ch/spacebase/mcprotocol/util/Util.java deleted file mode 100644 index 391b2789..00000000 --- a/src/main/java/ch/spacebase/mcprotocol/util/Util.java +++ /dev/null @@ -1,135 +0,0 @@ -package ch.spacebase.mcprotocol.util; - -import java.io.UnsupportedEncodingException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.PublicKey; -import java.util.Random; -import java.util.logging.Logger; - -import javax.crypto.SecretKey; - -import ch.spacebase.mcprotocol.standard.packet.PacketPluginMessage; -import ch.spacebase.mcprotocol.standard.util.PluginMessageBuilder; - -/** - * A set of generic protocol utilities. - */ -public class Util { - - /** - * The library's logger. - */ - private static final Logger logger = Logger.getLogger("mc-protocol-lib"); - - /** - * The library's Random. - */ - private static final Random rand = new Random(); - - /** - * Gets the library's logger. - * @return The library's logger. - */ - public static Logger logger() { - return logger; - } - - /** - * Gets the library's Random. - * @return The library's Random. - */ - public static Random random() { - return rand; - } - - /** - * Strips a string of color codes. - * @param str String to strip of color. - * @return The resulting stripped string. - */ - public static String stripColor(String str) { - StringBuilder build = new StringBuilder(); - for(int index = 0; index < str.length(); index++) { - if(str.charAt(index) == '\247') { - index++; - continue; - } - - build.append(str.charAt(index)); - } - - return build.toString(); - } - - /** - * Creates encrypted server data. - * @param loginKey The login key to use. - * @param key The public key to use. - * @param secret The secret key to use. - * @return The encrypted server data. - */ - public static byte[] encrypt(String loginKey, PublicKey key, SecretKey secret) { - try { - MessageDigest digest = MessageDigest.getInstance("SHA-1"); - digest.update(loginKey.getBytes("ISO_8859_1")); - digest.update(secret.getEncoded()); - digest.update(key.getEncoded()); - return digest.digest(); - } catch(UnsupportedEncodingException e) { - e.printStackTrace(); - return null; - } catch(NoSuchAlgorithmException e) { - e.printStackTrace(); - return null; - } - } - - /** - * Formats parameters into a ping response string. - * @param motd MOTD of the server. - * @param players Number of players online. - * @param maxplayers Maximum number of players allowed online. - * @return Formatted string response. - */ - public static String formatPingResponse(String motd, int players, int maxplayers) { - return "ยง1\0" + Constants.StandardProtocol.PROTOCOL_VERSION + "\0" + Constants.StandardProtocol.MINECRAFT_VERSION + "\0" + motd + "\0" + players + "\0" + maxplayers; - } - - /** - * Prepares a plugin message packet with client data to be sent after a ping - * request packet. - * @param serverIp IP of the server. - * @param serverPort Port of the server. - * @return The prepared packet. - */ - public static PacketPluginMessage prepareClientPingData(String serverIp, int serverPort) { - PluginMessageBuilder builder = new PluginMessageBuilder(Constants.StandardProtocol.PluginChannels.CLIENT_PING_DATA); - builder.writeByte(Constants.StandardProtocol.PROTOCOL_VERSION); - builder.writeString(serverIp); - builder.writeInt(serverPort); - return builder.build(); - } - - /** - * Gets the specified bit from the given value. - * @param value Value to use. - * @param bit Bit to get. - * @return The value of the bit. - */ - public static boolean getBit(int value, int bit) { - return (value & bit) == bit; - } - - /** - * Sets the given bit in the given value. - * @param value Value to change. - * @param bit Bit to change. - * @param state New value of the bit. - * @return The resulting value. - */ - public static byte setBit(byte value, int bit, boolean state) { - return state ? (byte) (value | bit) : (byte) (value & ~bit); - } - -}