Pre-1.7 misc. fixes (Waiting for 1.7.2 MCP update)

This commit is contained in:
Steveice10 2013-11-01 17:43:53 -07:00
parent 435a20230e
commit 7112e67607
115 changed files with 945 additions and 934 deletions

View file

@ -11,12 +11,12 @@ public class DisconnectEvent extends ProtocolEvent<ProtocolListener> {
* The connection that was disconnected. * The connection that was disconnected.
*/ */
private Connection conn; private Connection conn;
/** /**
* The given reason for disconnecting. * The given reason for disconnecting.
*/ */
private String reason; private String reason;
/** /**
* Creates a new disconnect event instance. * Creates a new disconnect event instance.
* @param conn Connection that is disconnecting. * @param conn Connection that is disconnecting.
@ -34,7 +34,7 @@ public class DisconnectEvent extends ProtocolEvent<ProtocolListener> {
public Connection getConnection() { public Connection getConnection() {
return this.conn; return this.conn;
} }
/** /**
* Gets the given reason for disconnecting. * Gets the given reason for disconnecting.
* @return The reason for disconnecting. * @return The reason for disconnecting.
@ -42,7 +42,7 @@ public class DisconnectEvent extends ProtocolEvent<ProtocolListener> {
public String getReason() { public String getReason() {
return this.reason; return this.reason;
} }
@Override @Override
public void call(ProtocolListener listener) { public void call(ProtocolListener listener) {
listener.onDisconnect(this); listener.onDisconnect(this);

View file

@ -5,7 +5,7 @@ import ch.spacebase.mcprotocol.packet.Packet;
/** /**
* Called when a packet is received. * Called when a packet is received.
*/ */
public class PacketRecieveEvent extends ProtocolEvent<ProtocolListener> { public class PacketReceiveEvent extends ProtocolEvent<ProtocolListener> {
/** /**
* The received packet. * The received packet.
@ -16,7 +16,7 @@ public class PacketRecieveEvent extends ProtocolEvent<ProtocolListener> {
* Creates a new packet receive event instance. * Creates a new packet receive event instance.
* @param packet Packet being received. * @param packet Packet being received.
*/ */
public PacketRecieveEvent(Packet packet) { public PacketReceiveEvent(Packet packet) {
this.packet = packet; this.packet = packet;
} }
@ -37,7 +37,7 @@ public class PacketRecieveEvent extends ProtocolEvent<ProtocolListener> {
public <T extends Packet> T getPacket(Class<T> clazz) { public <T extends Packet> T getPacket(Class<T> clazz) {
try { try {
return (T) this.packet; return (T) this.packet;
} catch (ClassCastException e) { } catch(ClassCastException e) {
return null; return null;
} }
} }

View file

@ -37,7 +37,7 @@ public class PacketSendEvent extends ProtocolEvent<ProtocolListener> {
public <T extends Packet> T getPacket(Class<T> clazz) { public <T extends Packet> T getPacket(Class<T> clazz) {
try { try {
return (T) this.packet; return (T) this.packet;
} catch (ClassCastException e) { } catch(ClassCastException e) {
return null; return null;
} }
} }

View file

@ -7,5 +7,5 @@ package ch.spacebase.mcprotocol.event;
*/ */
public interface PacketVisitable { public interface PacketVisitable {
public void accept(PacketVisitor visitor); public void accept(PacketVisitor visitor);
} }

View file

@ -9,167 +9,167 @@ import ch.spacebase.mcprotocol.standard.packet.*;
*/ */
public interface PacketVisitor { public interface PacketVisitor {
public void visit(PacketKeepAlive packet); public void visit(PacketKeepAlive packet);
public void visit(PacketLogin packet); public void visit(PacketLogin packet);
public void visit(PacketHandshake packet); public void visit(PacketHandshake packet);
public void visit(PacketChat packet); public void visit(PacketChat packet);
public void visit(PacketTimeUpdate packet); public void visit(PacketTimeUpdate packet);
public void visit(PacketEntityEquipment packet); public void visit(PacketEntityEquipment packet);
public void visit(PacketSpawnPosition packet); public void visit(PacketSpawnPosition packet);
public void visit(PacketUseEntity packet); public void visit(PacketUseEntity packet);
public void visit(PacketHealthUpdate packet); public void visit(PacketHealthUpdate packet);
public void visit(PacketRespawn packet); public void visit(PacketRespawn packet);
public void visit(PacketPlayer packet); public void visit(PacketPlayer packet);
public void visit(PacketPlayerPosition packet); public void visit(PacketPlayerPosition packet);
public void visit(PacketPlayerLook packet); public void visit(PacketPlayerLook packet);
public void visit(PacketPlayerPositionLook packet); public void visit(PacketPlayerPositionLook packet);
public void visit(PacketPlayerDigging packet); public void visit(PacketPlayerDigging packet);
public void visit(PacketPlayerBlockPlace packet); public void visit(PacketPlayerBlockPlace packet);
public void visit(PacketHeldItemChange packet); public void visit(PacketHeldItemChange packet);
public void visit(PacketUseBed packet); public void visit(PacketUseBed packet);
public void visit(PacketAnimation packet); public void visit(PacketAnimation packet);
public void visit(PacketEntityAction packet); public void visit(PacketEntityAction packet);
public void visit(PacketSpawnNamedEntity packet); public void visit(PacketSpawnNamedEntity packet);
public void visit(PacketCollectItem packet); public void visit(PacketCollectItem packet);
public void visit(PacketSpawnObject packet); public void visit(PacketSpawnObject packet);
public void visit(PacketSpawnMob packet); public void visit(PacketSpawnMob packet);
public void visit(PacketSpawnPainting packet); public void visit(PacketSpawnPainting packet);
public void visit(PacketSpawnExpOrb packet); public void visit(PacketSpawnExpOrb packet);
public void visit(PacketSteerVehicle packet); public void visit(PacketSteerVehicle packet);
public void visit(PacketEntityVelocity packet); public void visit(PacketEntityVelocity packet);
public void visit(PacketDestroyEntity packet); public void visit(PacketDestroyEntity packet);
public void visit(PacketEntity packet); public void visit(PacketEntity packet);
public void visit(PacketEntityRelativeMove packet); public void visit(PacketEntityRelativeMove packet);
public void visit(PacketEntityLook packet); public void visit(PacketEntityLook packet);
public void visit(PacketEntityLookRelativeMove packet); public void visit(PacketEntityLookRelativeMove packet);
public void visit(PacketEntityTeleport packet); public void visit(PacketEntityTeleport packet);
public void visit(PacketEntityHeadYaw packet); public void visit(PacketEntityHeadYaw packet);
public void visit(PacketEntityStatus packet); public void visit(PacketEntityStatus packet);
public void visit(PacketAttachEntity packet); public void visit(PacketAttachEntity packet);
public void visit(PacketEntityMetadata packet); public void visit(PacketEntityMetadata packet);
public void visit(PacketEntityEffect packet); public void visit(PacketEntityEffect packet);
public void visit(PacketRemoveEntityEffect packet); public void visit(PacketRemoveEntityEffect packet);
public void visit(PacketSetExperience packet); public void visit(PacketSetExperience packet);
public void visit(PacketEntityAttributes packet); public void visit(PacketEntityAttributes packet);
public void visit(PacketMapChunk packet); public void visit(PacketMapChunk packet);
public void visit(PacketMultiBlockChange packet); public void visit(PacketMultiBlockChange packet);
public void visit(PacketBlockChange packet); public void visit(PacketBlockChange packet);
public void visit(PacketBlockAction packet); public void visit(PacketBlockAction packet);
public void visit(PacketBlockBreakAnimation packet); public void visit(PacketBlockBreakAnimation packet);
public void visit(PacketMapChunkBulk packet); public void visit(PacketMapChunkBulk packet);
public void visit(PacketExplosion packet); public void visit(PacketExplosion packet);
public void visit(PacketEffect packet); public void visit(PacketEffect packet);
public void visit(PacketNamedSound packet); public void visit(PacketNamedSound packet);
public void visit(PacketSpawnParticle packet); public void visit(PacketSpawnParticle packet);
public void visit(PacketGameState packet); public void visit(PacketGameState packet);
public void visit(PacketLightning packet); public void visit(PacketLightning packet);
public void visit(PacketOpenWindow packet); public void visit(PacketOpenWindow packet);
public void visit(PacketCloseWindow packet); public void visit(PacketCloseWindow packet);
public void visit(PacketWindowClick packet); public void visit(PacketWindowClick packet);
public void visit(PacketSetSlot packet); public void visit(PacketSetSlot packet);
public void visit(PacketWindowItems packet); public void visit(PacketWindowItems packet);
public void visit(PacketWindowProperty packet); public void visit(PacketWindowProperty packet);
public void visit(PacketConfirmTransaction packet); public void visit(PacketConfirmTransaction packet);
public void visit(PacketCreativeSlot packet); public void visit(PacketCreativeSlot packet);
public void visit(PacketEnchantItem packet); public void visit(PacketEnchantItem packet);
public void visit(PacketUpdateSign packet); public void visit(PacketUpdateSign packet);
public void visit(PacketItemData packet); public void visit(PacketItemData packet);
public void visit(PacketUpdateTileEntity packet); public void visit(PacketUpdateTileEntity packet);
public void visit(PacketOpenTileEditor packet); public void visit(PacketOpenTileEditor packet);
public void visit(PacketIncrementStatistic packet); public void visit(PacketIncrementStatistic packet);
public void visit(PacketPlayerListItem packet); public void visit(PacketPlayerListItem packet);
public void visit(PacketPlayerAbilities packet); public void visit(PacketPlayerAbilities packet);
public void visit(PacketTabComplete packet); public void visit(PacketTabComplete packet);
public void visit(PacketClientInfo packet); public void visit(PacketClientInfo packet);
public void visit(PacketClientStatus packet); public void visit(PacketClientStatus packet);
public void visit(PacketScoreboardObjective packet); public void visit(PacketScoreboardObjective packet);
public void visit(PacketUpdateScoreboard packet); public void visit(PacketUpdateScoreboard packet);
public void visit(PacketDisplayScoreboard packet); public void visit(PacketDisplayScoreboard packet);
public void visit(PacketTeam packet); public void visit(PacketTeam packet);
public void visit(PacketPluginMessage packet); public void visit(PacketPluginMessage packet);
public void visit(PacketKeyResponse packet); public void visit(PacketKeyResponse packet);
public void visit(PacketKeyRequest packet); public void visit(PacketKeyRequest packet);
public void visit(PacketServerPing packet); public void visit(PacketServerPing packet);
public void visit(PacketDisconnect packet); public void visit(PacketDisconnect packet);
} }

View file

@ -84,256 +84,256 @@ import ch.spacebase.mcprotocol.standard.packet.PacketWindowItems;
import ch.spacebase.mcprotocol.standard.packet.PacketWindowProperty; import ch.spacebase.mcprotocol.standard.packet.PacketWindowProperty;
/** /**
* Empty implementation of the PacketVisitor interface for convenience. * Empty implementation of the PacketVisitor interface for convenience. Usually
* Usually used when most methods are not implemented. * used when most methods are not implemented.
* *
* @author dconnor * @author dconnor
*/ */
public class PacketVisitorAdapter implements PacketVisitor { public class PacketVisitorAdapter implements PacketVisitor {
public void visit(PacketKeepAlive packet) { public void visit(PacketKeepAlive packet) {
} }
public void visit(PacketLogin packet) { public void visit(PacketLogin packet) {
} }
public void visit(PacketHandshake packet) { public void visit(PacketHandshake packet) {
} }
public void visit(PacketChat packet) { public void visit(PacketChat packet) {
} }
public void visit(PacketTimeUpdate packet) { public void visit(PacketTimeUpdate packet) {
} }
public void visit(PacketEntityEquipment packet) { public void visit(PacketEntityEquipment packet) {
} }
public void visit(PacketSpawnPosition packet) { public void visit(PacketSpawnPosition packet) {
} }
public void visit(PacketUseEntity packet) { public void visit(PacketUseEntity packet) {
} }
public void visit(PacketHealthUpdate packet) { public void visit(PacketHealthUpdate packet) {
} }
public void visit(PacketRespawn packet) { public void visit(PacketRespawn packet) {
} }
public void visit(PacketPlayer packet) { public void visit(PacketPlayer packet) {
} }
public void visit(PacketPlayerPosition packet) { public void visit(PacketPlayerPosition packet) {
} }
public void visit(PacketPlayerLook packet) { public void visit(PacketPlayerLook packet) {
} }
public void visit(PacketPlayerPositionLook packet) { public void visit(PacketPlayerPositionLook packet) {
} }
public void visit(PacketPlayerDigging packet) { public void visit(PacketPlayerDigging packet) {
} }
public void visit(PacketPlayerBlockPlace packet) { public void visit(PacketPlayerBlockPlace packet) {
} }
public void visit(PacketHeldItemChange packet) { public void visit(PacketHeldItemChange packet) {
} }
public void visit(PacketUseBed packet) { public void visit(PacketUseBed packet) {
} }
public void visit(PacketAnimation packet) { public void visit(PacketAnimation packet) {
} }
public void visit(PacketEntityAction packet) { public void visit(PacketEntityAction packet) {
} }
public void visit(PacketSpawnNamedEntity packet) { public void visit(PacketSpawnNamedEntity packet) {
} }
public void visit(PacketCollectItem packet) { public void visit(PacketCollectItem packet) {
} }
public void visit(PacketSpawnObject packet) { public void visit(PacketSpawnObject packet) {
} }
public void visit(PacketSpawnMob packet) { public void visit(PacketSpawnMob packet) {
} }
public void visit(PacketSpawnPainting packet) { public void visit(PacketSpawnPainting packet) {
} }
public void visit(PacketSpawnExpOrb packet) { public void visit(PacketSpawnExpOrb packet) {
} }
public void visit(PacketSteerVehicle packet) { public void visit(PacketSteerVehicle packet) {
} }
public void visit(PacketEntityVelocity packet) { public void visit(PacketEntityVelocity packet) {
} }
public void visit(PacketDestroyEntity packet) { public void visit(PacketDestroyEntity packet) {
} }
public void visit(PacketEntity packet) { public void visit(PacketEntity packet) {
} }
public void visit(PacketEntityRelativeMove packet) { public void visit(PacketEntityRelativeMove packet) {
} }
public void visit(PacketEntityLook packet) { public void visit(PacketEntityLook packet) {
} }
public void visit(PacketEntityLookRelativeMove packet) { public void visit(PacketEntityLookRelativeMove packet) {
} }
public void visit(PacketEntityTeleport packet) { public void visit(PacketEntityTeleport packet) {
} }
public void visit(PacketEntityHeadYaw packet) { public void visit(PacketEntityHeadYaw packet) {
} }
public void visit(PacketEntityStatus packet) { public void visit(PacketEntityStatus packet) {
} }
public void visit(PacketAttachEntity packet) { public void visit(PacketAttachEntity packet) {
} }
public void visit(PacketEntityMetadata packet) { public void visit(PacketEntityMetadata packet) {
} }
public void visit(PacketEntityEffect packet) { public void visit(PacketEntityEffect packet) {
} }
public void visit(PacketRemoveEntityEffect packet) { public void visit(PacketRemoveEntityEffect packet) {
} }
public void visit(PacketSetExperience packet) { public void visit(PacketSetExperience packet) {
} }
public void visit(PacketEntityAttributes packet) { public void visit(PacketEntityAttributes packet) {
} }
public void visit(PacketMapChunk packet) { public void visit(PacketMapChunk packet) {
} }
public void visit(PacketMultiBlockChange packet) { public void visit(PacketMultiBlockChange packet) {
} }
public void visit(PacketBlockChange packet) { public void visit(PacketBlockChange packet) {
} }
public void visit(PacketBlockAction packet) { public void visit(PacketBlockAction packet) {
} }
public void visit(PacketBlockBreakAnimation packet) { public void visit(PacketBlockBreakAnimation packet) {
} }
public void visit(PacketMapChunkBulk packet) { public void visit(PacketMapChunkBulk packet) {
} }
public void visit(PacketExplosion packet) { public void visit(PacketExplosion packet) {
} }
public void visit(PacketEffect packet) { public void visit(PacketEffect packet) {
} }
public void visit(PacketNamedSound packet) { public void visit(PacketNamedSound packet) {
} }
public void visit(PacketSpawnParticle packet) { public void visit(PacketSpawnParticle packet) {
} }
public void visit(PacketGameState packet) { public void visit(PacketGameState packet) {
} }
public void visit(PacketLightning packet) { public void visit(PacketLightning packet) {
} }
public void visit(PacketOpenWindow packet) { public void visit(PacketOpenWindow packet) {
} }
public void visit(PacketCloseWindow packet) { public void visit(PacketCloseWindow packet) {
} }
public void visit(PacketWindowClick packet) { public void visit(PacketWindowClick packet) {
} }
public void visit(PacketSetSlot packet) { public void visit(PacketSetSlot packet) {
} }
public void visit(PacketWindowItems packet) { public void visit(PacketWindowItems packet) {
} }
public void visit(PacketWindowProperty packet) { public void visit(PacketWindowProperty packet) {
} }
public void visit(PacketConfirmTransaction packet) { public void visit(PacketConfirmTransaction packet) {
} }
public void visit(PacketCreativeSlot packet) { public void visit(PacketCreativeSlot packet) {
} }
public void visit(PacketEnchantItem packet) { public void visit(PacketEnchantItem packet) {
} }
public void visit(PacketUpdateSign packet) { public void visit(PacketUpdateSign packet) {
} }
public void visit(PacketItemData packet) { public void visit(PacketItemData packet) {
} }
public void visit(PacketUpdateTileEntity packet) { public void visit(PacketUpdateTileEntity packet) {
} }
public void visit(PacketOpenTileEditor packet) { public void visit(PacketOpenTileEditor packet) {
} }
public void visit(PacketIncrementStatistic packet) { public void visit(PacketIncrementStatistic packet) {
} }
public void visit(PacketPlayerListItem packet) { public void visit(PacketPlayerListItem packet) {
} }
public void visit(PacketPlayerAbilities packet) { public void visit(PacketPlayerAbilities packet) {
} }
public void visit(PacketTabComplete packet) { public void visit(PacketTabComplete packet) {
} }
public void visit(PacketClientInfo packet) { public void visit(PacketClientInfo packet) {
} }
public void visit(PacketClientStatus packet) { public void visit(PacketClientStatus packet) {
} }
public void visit(PacketScoreboardObjective packet) { public void visit(PacketScoreboardObjective packet) {
} }
public void visit(PacketUpdateScoreboard packet) { public void visit(PacketUpdateScoreboard packet) {
} }
public void visit(PacketDisplayScoreboard packet) { public void visit(PacketDisplayScoreboard packet) {
} }
public void visit(PacketTeam packet) { public void visit(PacketTeam packet) {
} }
public void visit(PacketPluginMessage packet) { public void visit(PacketPluginMessage packet) {
} }
public void visit(PacketKeyResponse packet) { public void visit(PacketKeyResponse packet) {
} }
public void visit(PacketKeyRequest packet) { public void visit(PacketKeyRequest packet) {
} }
public void visit(PacketServerPing packet) { public void visit(PacketServerPing packet) {
} }
public void visit(PacketDisconnect packet) { public void visit(PacketDisconnect packet) {
} }
} }

View file

@ -9,14 +9,14 @@ public abstract class ProtocolListener {
* Called when a packet is received. * Called when a packet is received.
* @param event The called event. * @param event The called event.
*/ */
public abstract void onPacketReceive(PacketRecieveEvent event); public abstract void onPacketReceive(PacketReceiveEvent event);
/** /**
* Called when a packet is sent. * Called when a packet is sent.
* @param event The called event. * @param event The called event.
*/ */
public abstract void onPacketSend(PacketSendEvent event); public abstract void onPacketSend(PacketSendEvent event);
/** /**
* Called when a connection is disconnected. * Called when a connection is disconnected.
* @param event The called event. * @param event The called event.

View file

@ -10,5 +10,5 @@ public abstract class ServerListener {
* @param event The called event. * @param event The called event.
*/ */
public abstract void onConnect(ConnectEvent event); public abstract void onConnect(ConnectEvent event);
} }

View file

@ -15,17 +15,17 @@ public abstract class BaseConnection implements Connection {
* The connection's remote host. * The connection's remote host.
*/ */
private String host; private String host;
/** /**
* The connection's remote port. * The connection's remote port.
*/ */
private int port; private int port;
/** /**
* The connection's username. * The connection's username.
*/ */
private String username; private String username;
/** /**
* The connection's packets. * The connection's packets.
*/ */
@ -35,7 +35,7 @@ public abstract class BaseConnection implements Connection {
* Listeners listening to this connection. * Listeners listening to this connection.
*/ */
private List<ProtocolListener> listeners = new ArrayList<ProtocolListener>(); private List<ProtocolListener> listeners = new ArrayList<ProtocolListener>();
/** /**
* Creates a new connection. * Creates a new connection.
* @param host Host to connect to. * @param host Host to connect to.
@ -56,26 +56,26 @@ public abstract class BaseConnection implements Connection {
public int getRemotePort() { public int getRemotePort() {
return this.port; return this.port;
} }
@Override @Override
public PacketRegistry getPacketRegistry() { public PacketRegistry getPacketRegistry() {
return this.packets; return this.packets;
} }
@Override @Override
public String getUsername() { public String getUsername() {
return this.username; return this.username;
} }
@Override @Override
public void setUsername(String name) { public void setUsername(String name) {
if(this.username != null) { if(this.username != null) {
return; return;
} }
this.username = name; this.username = name;
} }
@Override @Override
public void listen(ProtocolListener listener) { public void listen(ProtocolListener listener) {
this.listeners.add(listener); this.listeners.add(listener);
@ -89,5 +89,5 @@ public abstract class BaseConnection implements Connection {
return event; return event;
} }
} }

View file

@ -15,7 +15,7 @@ public interface Connection {
* @return The connection's protocol type. * @return The connection's protocol type.
*/ */
public abstract PacketRegistry getPacketRegistry(); public abstract PacketRegistry getPacketRegistry();
/** /**
* Gets the remote host of this connection. * Gets the remote host of this connection.
* @return The connection's remote host. * @return The connection's remote host.
@ -27,7 +27,7 @@ public interface Connection {
* @return The connection's remote port. * @return The connection's remote port.
*/ */
public int getRemotePort(); public int getRemotePort();
/** /**
* Adds a listener to listen to this connection. * Adds a listener to listen to this connection.
* @param listener Listener to add. * @param listener Listener to add.
@ -40,48 +40,49 @@ public interface Connection {
* @return The event called. * @return The event called.
*/ */
public <T extends ProtocolEvent<ProtocolListener>> T call(T event); public <T extends ProtocolEvent<ProtocolListener>> T call(T event);
/** /**
* Gets the connection's username. * Gets the connection's username.
* @return The connection's username. * @return The connection's username.
*/ */
public String getUsername(); public String getUsername();
/** /**
* Sets the connection's username if it isn't already set, ignoring any authentication. * Sets the connection's username if it isn't already set, ignoring any
* authentication.
* @param name The new username. * @param name The new username.
*/ */
public void setUsername(String name); public void setUsername(String name);
/** /**
* Gets whether the connection is connected. * Gets whether the connection is connected.
* @return True if the connection is connected. * @return True if the connection is connected.
*/ */
public boolean isConnected(); public boolean isConnected();
/** /**
* Connects this connection. * Connects this connection.
* @throws ConnectException If a connection error occurs. * @throws ConnectException If a connection error occurs.
*/ */
public void connect() throws ConnectException; public void connect() throws ConnectException;
/** /**
* Disconnects this connection, sending a packet with a reason. * Disconnects this connection, sending a packet with a reason.
* @param reason Reason to disconnect. * @param reason Reason to disconnect.
*/ */
public void disconnect(String reason); public void disconnect(String reason);
/** /**
* Disconnects this connection, sending a packet with a reason. * Disconnects this connection, sending a packet with a reason.
* @param reason Reason to disconnect. * @param reason Reason to disconnect.
* @param packet Whether a disconnect packet is necessary. * @param packet Whether a disconnect packet is necessary.
*/ */
public void disconnect(String reason, boolean packet); public void disconnect(String reason, boolean packet);
/** /**
* Sends a packet. * Sends a packet.
* @param packet Packet to send. * @param packet Packet to send.
*/ */
public void send(Packet packet); public void send(Packet packet);
} }

View file

@ -27,9 +27,9 @@ public abstract class PacketRegistry {
public Class<? extends Packet> getPacket(int id) { public Class<? extends Packet> getPacket(int id) {
try { try {
return this.packets[id]; return this.packets[id];
} catch (ArrayIndexOutOfBoundsException e) { } catch(ArrayIndexOutOfBoundsException e) {
return null; return null;
} }
} }
} }

View file

@ -15,33 +15,33 @@ public abstract class Server {
* The server's host to listen on. * The server's host to listen on.
*/ */
private String host; private String host;
/** /**
* The server's port to listen on. * The server's port to listen on.
*/ */
private int port; private int port;
/** /**
* Whether auth is enabled. * Whether auth is enabled.
*/ */
private boolean auth; private boolean auth;
/** /**
* Listeners listening to this server. * Listeners listening to this server.
*/ */
private List<ServerListener> listeners = new ArrayList<ServerListener>(); private List<ServerListener> listeners = new ArrayList<ServerListener>();
/** /**
* Creates a new server instance. * Creates a new server instance.
* @param host Host to listen on. * @param host Host to listen on.
* @param port Port to listen on. * @param port Port to listen on.
*/ */
public Server(String host, int port, boolean auth) { public Server(String host, int port, boolean auth) {
this.host = host; this.host = host;
this.port = port; this.port = port;
this.auth = auth; this.auth = auth;
} }
/** /**
* Gets the host of this server. * Gets the host of this server.
* @return The server's host. * @return The server's host.
@ -57,7 +57,7 @@ public abstract class Server {
public int getPort() { public int getPort() {
return this.port; return this.port;
} }
/** /**
* Gets whether authentication is enabled. * Gets whether authentication is enabled.
* @return Whether auth is enabled. * @return Whether auth is enabled.
@ -65,7 +65,7 @@ public abstract class Server {
public boolean isAuthEnabled() { public boolean isAuthEnabled() {
return this.auth; return this.auth;
} }
/** /**
* Adds a listener to listen to this server. * Adds a listener to listen to this server.
* @param listener Listener to add. * @param listener Listener to add.
@ -86,27 +86,27 @@ public abstract class Server {
return event; return event;
} }
/** /**
* Gets whether the server is active. * Gets whether the server is active.
* @return Whether the server is active. * @return Whether the server is active.
*/ */
public abstract boolean isActive(); public abstract boolean isActive();
/** /**
* Binds the server to its host and port. * Binds the server to its host and port.
*/ */
public abstract void bind(); public abstract void bind();
/** /**
* Shuts the server down. * Shuts the server down.
*/ */
public abstract void shutdown(); public abstract void shutdown();
/** /**
* Gets a list of connections connected to this server. * Gets a list of connections connected to this server.
* @return The server's connections. * @return The server's connections.
*/ */
public abstract List<ServerConnection> getConnections(); public abstract List<ServerConnection> getConnections();
} }

View file

@ -13,70 +13,70 @@ public interface NetInput {
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public boolean readBoolean() throws IOException; public boolean readBoolean() throws IOException;
/** /**
* Reads the next byte. * Reads the next byte.
* @return The next byte. * @return The next byte.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public byte readByte() throws IOException; public byte readByte() throws IOException;
/** /**
* Reads the next unsigned byte. * Reads the next unsigned byte.
* @return The next unsigned byte. * @return The next unsigned byte.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public int readUnsignedByte() throws IOException; public int readUnsignedByte() throws IOException;
/** /**
* Reads the next short. * Reads the next short.
* @return The next short. * @return The next short.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public short readShort() throws IOException; public short readShort() throws IOException;
/** /**
* Reads the next unsigned short. * Reads the next unsigned short.
* @return The next unsigned short. * @return The next unsigned short.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public int readUnsignedShort() throws IOException; public int readUnsignedShort() throws IOException;
/** /**
* Reads the next char. * Reads the next char.
* @return The next char. * @return The next char.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public char readChar() throws IOException; public char readChar() throws IOException;
/** /**
* Reads the next integer. * Reads the next integer.
* @return The next integer. * @return The next integer.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public int readInt() throws IOException; public int readInt() throws IOException;
/** /**
* Reads the next long. * Reads the next long.
* @return The next long. * @return The next long.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public long readLong() throws IOException; public long readLong() throws IOException;
/** /**
* Reads the next float. * Reads the next float.
* @return The next float. * @return The next float.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public float readFloat() throws IOException; public float readFloat() throws IOException;
/** /**
* Reads the next double. * Reads the next double.
* @return The next double. * @return The next double.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public double readDouble() throws IOException; public double readDouble() throws IOException;
/** /**
* Reads the next byte array. * Reads the next byte array.
* @param The length of the byte array. * @param The length of the byte array.
@ -84,18 +84,18 @@ public interface NetInput {
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public byte[] readBytes(int length) throws IOException; public byte[] readBytes(int length) throws IOException;
/** /**
* Reads the next string. * Reads the next string.
* @return The next string. * @return The next string.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public String readString() throws IOException; public String readString() throws IOException;
/** /**
* Gets the number of available bytes. * Gets the number of available bytes.
* @return The number of available bytes. * @return The number of available bytes.
*/ */
public int available() throws IOException; public int available() throws IOException;
} }

View file

@ -10,63 +10,63 @@ public interface NetOutput {
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void writeBoolean(boolean b) throws IOException; public void writeBoolean(boolean b) throws IOException;
/** /**
* Writes a byte. * Writes a byte.
* @param b Byte to write. * @param b Byte to write.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void writeByte(int b) throws IOException; public void writeByte(int b) throws IOException;
/** /**
* Writes a short. * Writes a short.
* @param s Short to write. * @param s Short to write.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void writeShort(int s) throws IOException; public void writeShort(int s) throws IOException;
/** /**
* Writes a char. * Writes a char.
* @param c Char to write. * @param c Char to write.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void writeChar(int c) throws IOException; public void writeChar(int c) throws IOException;
/** /**
* Writes a integer. * Writes a integer.
* @param i Integer to write. * @param i Integer to write.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void writeInt(int i) throws IOException; public void writeInt(int i) throws IOException;
/** /**
* Writes a long. * Writes a long.
* @param l Long to write. * @param l Long to write.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void writeLong(long l) throws IOException; public void writeLong(long l) throws IOException;
/** /**
* Writes a float. * Writes a float.
* @param f Float to write. * @param f Float to write.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void writeFloat(float f) throws IOException; public void writeFloat(float f) throws IOException;
/** /**
* Writes a double. * Writes a double.
* @param d Double to write. * @param d Double to write.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void writeDouble(double d) throws IOException; public void writeDouble(double d) throws IOException;
/** /**
* Writes a byte array. * Writes a byte array.
* @param b Byte array to write. * @param b Byte array to write.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void writeBytes(byte b[]) throws IOException; public void writeBytes(byte b[]) throws IOException;
/** /**
* Writes a byte array, using the given amount of bytes. * Writes a byte array, using the given amount of bytes.
* @param b Byte array to write. * @param b Byte array to write.
@ -74,18 +74,18 @@ public interface NetOutput {
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void writeBytes(byte b[], int length) throws IOException; public void writeBytes(byte b[], int length) throws IOException;
/** /**
* Writes a string. * Writes a string.
* @param s String to write. * @param s String to write.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void writeString(String s) throws IOException; public void writeString(String s) throws IOException;
/** /**
* Flushes the output. * Flushes the output.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public void flush() throws IOException; public void flush() throws IOException;
} }

View file

@ -48,6 +48,6 @@ public abstract class Packet implements PacketVisitable {
* Gets the id of this packet. * Gets the id of this packet.
* @return The packet's id. * @return The packet's id.
*/ */
public abstract int getId(); public abstract int getId();
} }

View file

@ -30,12 +30,12 @@ public class StandardClient extends StandardConnection implements Client {
* The client's session id. * The client's session id.
*/ */
private String sessionId; private String sessionId;
/** /**
* Whether the client is logged in. * Whether the client is logged in.
*/ */
private boolean loggedIn; private boolean loggedIn;
/** /**
* Creates a new standard client. * Creates a new standard client.
* @param host Host to connect to. * @param host Host to connect to.
@ -44,7 +44,7 @@ public class StandardClient extends StandardConnection implements Client {
public StandardClient(String host, int port) { public StandardClient(String host, int port) {
super(host, port); super(host, port);
} }
/** /**
* Gets the client's session id. * Gets the client's session id.
* @return The client's session id. * @return The client's session id.
@ -58,12 +58,12 @@ public class StandardClient extends StandardConnection implements Client {
if(this.loggedIn || this.getUsername() != null) { if(this.loggedIn || this.getUsername() != null) {
throw new IllegalStateException("Already logged in with username: " + this.getUsername()); throw new IllegalStateException("Already logged in with username: " + this.getUsername());
} }
URL url = null; URL url = null;
try { try {
url = new URL("https://login.minecraft.net/"); url = new URL("https://login.minecraft.net/");
} catch (MalformedURLException e) { } catch(MalformedURLException e) {
throw new LoginException("Login URL is malformed?", e); throw new LoginException("Login URL is malformed?", e);
} }
@ -71,7 +71,7 @@ public class StandardClient extends StandardConnection implements Client {
try { try {
params = "user=" + URLEncoder.encode(username, "UTF-8") + "&password=" + URLEncoder.encode(password, "UTF-8") + "&version=" + Constants.LAUNCHER_VERSION; params = "user=" + URLEncoder.encode(username, "UTF-8") + "&password=" + URLEncoder.encode(password, "UTF-8") + "&version=" + Constants.LAUNCHER_VERSION;
} catch (UnsupportedEncodingException e) { } catch(UnsupportedEncodingException e) {
throw new LoginException("UTF-8 unsupported", e); throw new LoginException("UTF-8 unsupported", e);
} }
@ -119,7 +119,7 @@ public class StandardClient extends StandardConnection implements Client {
this.loggedIn = true; this.loggedIn = true;
new Thread(new KeepAliveTask()).start(); new Thread(new KeepAliveTask()).start();
} catch (ArrayIndexOutOfBoundsException e) { } catch(ArrayIndexOutOfBoundsException e) {
throw new LoginException("Response contained incorrect amount of parameters: " + result); throw new LoginException("Response contained incorrect amount of parameters: " + result);
} }
@ -132,20 +132,20 @@ public class StandardClient extends StandardConnection implements Client {
throw new LoginException(result.trim()); throw new LoginException(result.trim());
} }
} }
} catch (IOException e) { } catch(IOException e) {
throw new LoginException("Failed to login", e); throw new LoginException("Failed to login", e);
} finally { } finally {
if(conn != null) conn.disconnect(); if(conn != null) conn.disconnect();
conn = null; conn = null;
} }
} }
@Override @Override
public void disconnect(String reason, boolean packet) { public void disconnect(String reason, boolean packet) {
this.loggedIn = false; this.loggedIn = false;
super.disconnect(reason, packet); super.disconnect(reason, packet);
} }
/** /**
* A task that keeps the client's minecraft.net session alive. * A task that keeps the client's minecraft.net session alive.
*/ */
@ -154,7 +154,7 @@ public class StandardClient extends StandardConnection implements Client {
* The minecraft.net session URL. * The minecraft.net session URL.
*/ */
private URL url; private URL url;
/** /**
* The time when a keep alive was last sent. * The time when a keep alive was last sent.
*/ */
@ -167,7 +167,7 @@ public class StandardClient extends StandardConnection implements Client {
public KeepAliveTask() throws LoginException { public KeepAliveTask() throws LoginException {
try { try {
this.url = new URL("https://login.minecraft.net/"); this.url = new URL("https://login.minecraft.net/");
} catch (MalformedURLException e) { } catch(MalformedURLException e) {
throw new LoginException("Failed to create keep alive URL!", e); throw new LoginException("Failed to create keep alive URL!", e);
} }
} }
@ -187,7 +187,7 @@ public class StandardClient extends StandardConnection implements Client {
conn.setDoOutput(true); conn.setDoOutput(true);
conn.setReadTimeout(1000 * 60 * 10); conn.setReadTimeout(1000 * 60 * 10);
conn.connect(); conn.connect();
} catch (IOException e) { } catch(IOException e) {
Util.logger().severe("Failed to send keep alive to login.minecraft.net!"); Util.logger().severe("Failed to send keep alive to login.minecraft.net!");
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
@ -195,10 +195,10 @@ public class StandardClient extends StandardConnection implements Client {
conn = null; conn = null;
} }
} }
try { try {
Thread.sleep(2); Thread.sleep(2);
} catch (InterruptedException e) { } catch(InterruptedException e) {
} }
} }
} }
@ -212,11 +212,11 @@ public class StandardClient extends StandardConnection implements Client {
sock.setTrafficClass(24); sock.setTrafficClass(24);
super.connect(sock); super.connect(sock);
this.send(new PacketHandshake(this.getUsername(), this.getRemoteHost(), this.getRemotePort())); this.send(new PacketHandshake(this.getUsername(), this.getRemoteHost(), this.getRemotePort()));
} catch (UnknownHostException e) { } catch(UnknownHostException e) {
throw new ConnectException("Unknown host: " + this.getRemoteHost()); throw new ConnectException("Unknown host: " + this.getRemoteHost());
} catch (IOException e) { } catch(IOException e) {
throw new ConnectException("Failed to open stream: " + this.getRemoteHost(), e); throw new ConnectException("Failed to open stream: " + this.getRemoteHost(), e);
} }
} }
} }

View file

@ -18,7 +18,7 @@ import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV; import org.bouncycastle.crypto.params.ParametersWithIV;
import ch.spacebase.mcprotocol.event.DisconnectEvent; import ch.spacebase.mcprotocol.event.DisconnectEvent;
import ch.spacebase.mcprotocol.event.PacketRecieveEvent; import ch.spacebase.mcprotocol.event.PacketReceiveEvent;
import ch.spacebase.mcprotocol.event.PacketSendEvent; import ch.spacebase.mcprotocol.event.PacketSendEvent;
import ch.spacebase.mcprotocol.exception.ConnectException; import ch.spacebase.mcprotocol.exception.ConnectException;
import ch.spacebase.mcprotocol.net.BaseConnection; import ch.spacebase.mcprotocol.net.BaseConnection;
@ -35,42 +35,42 @@ import ch.spacebase.mcprotocol.util.Util;
* A connection implementing standard Minecraft protocol. * A connection implementing standard Minecraft protocol.
*/ */
public abstract class StandardConnection extends BaseConnection { public abstract class StandardConnection extends BaseConnection {
/** /**
* The connection's socket. * The connection's socket.
*/ */
private Socket sock; private Socket sock;
/** /**
* The connection's input stream. * The connection's input stream.
*/ */
private StandardInput input; private StandardInput input;
/** /**
* The connection's output stream. * The connection's output stream.
*/ */
private StandardOutput output; private StandardOutput output;
/** /**
* The connection's packet write queue. * The connection's packet write queue.
*/ */
private Queue<Packet> packets = new ConcurrentLinkedQueue<Packet>(); private Queue<Packet> packets = new ConcurrentLinkedQueue<Packet>();
/** /**
* Whether the connection is writing. * Whether the connection is writing.
*/ */
private boolean writing = false; private boolean writing = false;
/** /**
* Whether the connection is connected. * Whether the connection is connected.
*/ */
private boolean connected = false; private boolean connected = false;
/** /**
* The connection's secret key. * The connection's secret key.
*/ */
private SecretKey key; private SecretKey key;
/** /**
* Creates a new standard connection. * Creates a new standard connection.
* @param host Host to connect to. * @param host Host to connect to.
@ -98,13 +98,13 @@ public abstract class StandardConnection extends BaseConnection {
this.connected = true; this.connected = true;
new ListenThread().start(); new ListenThread().start();
new WriteThread().start(); new WriteThread().start();
} catch (UnknownHostException e) { } catch(UnknownHostException e) {
throw new ConnectException("Unknown host: " + this.getRemoteHost()); throw new ConnectException("Unknown host: " + this.getRemoteHost());
} catch (IOException e) { } catch(IOException e) {
throw new ConnectException("Failed to open stream: " + this.getRemoteHost(), e); throw new ConnectException("Failed to open stream: " + this.getRemoteHost(), e);
} }
} }
@Override @Override
public void disconnect(String reason) { public void disconnect(String reason) {
this.disconnect(reason, true); this.disconnect(reason, true);
@ -116,7 +116,7 @@ public abstract class StandardConnection extends BaseConnection {
if(packet && this.isConnected()) { if(packet && this.isConnected()) {
this.send(new PacketDisconnect(reason)); this.send(new PacketDisconnect(reason));
} }
new CloseThread().start(); new CloseThread().start();
this.connected = false; this.connected = false;
this.call(new DisconnectEvent(this, reason)); this.call(new DisconnectEvent(this, reason));
@ -126,7 +126,7 @@ public abstract class StandardConnection extends BaseConnection {
public void send(Packet packet) { public void send(Packet packet) {
this.packets.add(packet); this.packets.add(packet);
} }
/** /**
* Gets the protocol's secret key. * Gets the protocol's secret key.
* @return The protocol's secret key. * @return The protocol's secret key.
@ -142,7 +142,7 @@ public abstract class StandardConnection extends BaseConnection {
public void setSecretKey(SecretKey key) { public void setSecretKey(SecretKey key) {
this.key = key; this.key = key;
} }
/** /**
* Enabled AES encryption on the connection. * Enabled AES encryption on the connection.
* @param conn Connection to enable AES on. * @param conn Connection to enable AES on.
@ -156,7 +156,7 @@ public abstract class StandardConnection extends BaseConnection {
this.input = new StandardInput(new CipherInputStream(this.input.getStream(), in)); this.input = new StandardInput(new CipherInputStream(this.input.getStream(), in));
this.output = new StandardOutput(new CipherOutputStream(this.output.getStream(), out)); this.output = new StandardOutput(new CipherOutputStream(this.output.getStream(), out));
} }
/** /**
* A thread listening for incoming packets. * A thread listening for incoming packets.
*/ */
@ -175,10 +175,10 @@ public abstract class StandardConnection extends BaseConnection {
disconnect("Bad packet ID: " + opcode); disconnect("Bad packet ID: " + opcode);
return; return;
} }
Packet packet = getPacketRegistry().getPacket(opcode).newInstance(); Packet packet = getPacketRegistry().getPacket(opcode).newInstance();
packet.read(input); packet.read(input);
call(new PacketRecieveEvent(packet)); call(new PacketReceiveEvent(packet));
if(StandardConnection.this instanceof Client) { if(StandardConnection.this instanceof Client) {
packet.handleClient((Client) StandardConnection.this); packet.handleClient((Client) StandardConnection.this);
} else if(StandardConnection.this instanceof ServerConnection) { } else if(StandardConnection.this instanceof ServerConnection) {
@ -186,15 +186,15 @@ public abstract class StandardConnection extends BaseConnection {
} }
} catch(EOFException e) { } catch(EOFException e) {
disconnect("End of Stream"); disconnect("End of Stream");
} catch (Exception e) { } catch(Exception e) {
Util.logger().severe("Error while listening to connection!"); Util.logger().severe("Error while listening to connection!");
e.printStackTrace(); e.printStackTrace();
disconnect("Error while listening to connection!"); disconnect("Error while listening to connection!");
} }
try { try {
Thread.sleep(2); Thread.sleep(2);
} catch (InterruptedException e) { } catch(InterruptedException e) {
} }
} }
} }
@ -211,32 +211,33 @@ public abstract class StandardConnection extends BaseConnection {
writing = true; writing = true;
Packet packet = packets.poll(); Packet packet = packets.poll();
call(new PacketSendEvent(packet)); call(new PacketSendEvent(packet));
try { try {
output.writeByte(packet.getId()); output.writeByte(packet.getId());
packet.write(output); packet.write(output);
output.flush(); output.flush();
} catch (Exception e) { } catch(Exception e) {
Util.logger().severe("Error while writing packet \"" + packet.getId() + "\"!"); Util.logger().severe("Error while writing packet \"" + packet.getId() + "\"!");
e.printStackTrace(); e.printStackTrace();
disconnect("Error while writing packet."); disconnect("Error while writing packet.");
} }
writing = false; writing = false;
} }
try { try {
Thread.sleep(2); Thread.sleep(2);
} catch (InterruptedException e) { } catch(InterruptedException e) {
} }
writing = false; writing = false;
} }
} }
} }
/** /**
* A thread that waits for the connection to finish writing before closing it. * A thread that waits for the connection to finish writing before closing
* it.
*/ */
private class CloseThread extends Thread { private class CloseThread extends Thread {
@Override @Override
@ -244,17 +245,17 @@ public abstract class StandardConnection extends BaseConnection {
while(writing) { while(writing) {
try { try {
Thread.sleep(2); Thread.sleep(2);
} catch (InterruptedException e) { } catch(InterruptedException e) {
} }
} }
try { try {
sock.close(); sock.close();
} catch (IOException e) { } catch(IOException e) {
System.err.println("Failed to close socket."); System.err.println("Failed to close socket.");
e.printStackTrace(); e.printStackTrace();
} }
connected = false; connected = false;
} }
} }

View file

@ -173,5 +173,5 @@ public class StandardPackets extends PacketRegistry {
this.registerPacket(254, PacketServerPing.class); this.registerPacket(254, PacketServerPing.class);
this.registerPacket(255, PacketDisconnect.class); this.registerPacket(255, PacketDisconnect.class);
} }
} }

View file

@ -29,12 +29,12 @@ public class StandardServer extends Server {
* The connections connected to the server. * The connections connected to the server.
*/ */
private List<ServerConnection> connections = new CopyOnWriteArrayList<ServerConnection>(); private List<ServerConnection> connections = new CopyOnWriteArrayList<ServerConnection>();
/** /**
* The server's key pair. * The server's key pair.
*/ */
private KeyPair keys; private KeyPair keys;
/** /**
* Creates a new standard server. * Creates a new standard server.
* @param host Host to listen on. * @param host Host to listen on.
@ -47,11 +47,10 @@ public class StandardServer extends Server {
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA"); KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
gen.initialize(1024); gen.initialize(1024);
this.keys = gen.generateKeyPair(); this.keys = gen.generateKeyPair();
} catch (NoSuchAlgorithmException e) { } catch(NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
/** /**
* Gets the server's key pair. * Gets the server's key pair.
@ -72,7 +71,7 @@ public class StandardServer extends Server {
ServerSocket sock = new ServerSocket(); ServerSocket sock = new ServerSocket();
sock.bind(new InetSocketAddress(this.getHost(), this.getPort())); sock.bind(new InetSocketAddress(this.getHost(), this.getPort()));
new ServerConnectionThread(sock).start(); new ServerConnectionThread(sock).start();
} catch (IOException e) { } catch(IOException e) {
Util.logger().severe("Failed to bind to " + this.getHost() + ":" + this.getPort() + "!"); Util.logger().severe("Failed to bind to " + this.getHost() + ":" + this.getPort() + "!");
e.printStackTrace(); e.printStackTrace();
} }
@ -91,7 +90,7 @@ public class StandardServer extends Server {
public List<ServerConnection> getConnections() { public List<ServerConnection> getConnections() {
return this.connections; return this.connections;
} }
/** /**
* Listens for new server connections. * Listens for new server connections.
*/ */
@ -119,19 +118,19 @@ public class StandardServer extends Server {
conn.connect(); conn.connect();
connections.add(conn); connections.add(conn);
call(new ConnectEvent(conn)); call(new ConnectEvent(conn));
} catch (Exception e) { } catch(Exception e) {
Util.logger().severe("Failed to create server connection!"); Util.logger().severe("Failed to create server connection!");
e.printStackTrace(); e.printStackTrace();
} }
} catch (IOException e) { } catch(IOException e) {
Util.logger().severe("Failed to accept connection from client!"); Util.logger().severe("Failed to accept connection from client!");
e.printStackTrace(); e.printStackTrace();
continue; continue;
} }
try { try {
Thread.sleep(2); Thread.sleep(2);
} catch (InterruptedException e) { } catch(InterruptedException e) {
} }
} }
} }

View file

@ -12,37 +12,37 @@ import ch.spacebase.mcprotocol.util.Util;
* A server connection for the standard minecraft protocol. * A server connection for the standard minecraft protocol.
*/ */
public class StandardServerConnection extends StandardConnection implements ServerConnection { public class StandardServerConnection extends StandardConnection implements ServerConnection {
/** /**
* The server this connection belongs to. * The server this connection belongs to.
*/ */
private Server server; private Server server;
/** /**
* The connection's temporary socket variable. * The connection's temporary socket variable.
*/ */
private Socket sock; private Socket sock;
/** /**
* The last time a keep alive was sent. * The last time a keep alive was sent.
*/ */
private long aliveTime = System.currentTimeMillis(); private long aliveTime = System.currentTimeMillis();
/** /**
* The last sent server keep alive id. * The last sent server keep alive id.
*/ */
private int aliveId; private int aliveId;
/** /**
* The protocol's login key. * The protocol's login key.
*/ */
private String loginKey; private String loginKey;
/** /**
* The protocol's security token. * The protocol's security token.
*/ */
private byte token[]; private byte token[];
/** /**
* Creates a new server connection. * Creates a new server connection.
* @param server Server the connection belongs to. * @param server Server the connection belongs to.
@ -53,7 +53,7 @@ public class StandardServerConnection extends StandardConnection implements Serv
this.server = server; this.server = server;
this.sock = sock; this.sock = sock;
} }
/** /**
* Gets the last id used in a keep alive to this connection. * Gets the last id used in a keep alive to this connection.
* @return The last keep alive id. * @return The last keep alive id.
@ -61,7 +61,7 @@ public class StandardServerConnection extends StandardConnection implements Serv
public int getLastAliveId() { public int getLastAliveId() {
return this.aliveId; return this.aliveId;
} }
/** /**
* Gets the last time a keep alive was performed. * Gets the last time a keep alive was performed.
* @return The last keep alive time. * @return The last keep alive time.
@ -81,7 +81,7 @@ public class StandardServerConnection extends StandardConnection implements Serv
this.sock = null; this.sock = null;
new KeepAliveThread().start(); new KeepAliveThread().start();
} }
/** /**
* Gets the connection's login key. * Gets the connection's login key.
* @return The connection's login key. * @return The connection's login key.
@ -113,7 +113,7 @@ public class StandardServerConnection extends StandardConnection implements Serv
public void setToken(byte token[]) { public void setToken(byte token[]) {
this.token = token; this.token = token;
} }
/** /**
* A thread that keeps the connection alive. * A thread that keeps the connection alive.
*/ */
@ -126,13 +126,13 @@ public class StandardServerConnection extends StandardConnection implements Serv
aliveId = Util.random().nextInt(); aliveId = Util.random().nextInt();
send(new PacketKeepAlive(aliveId)); send(new PacketKeepAlive(aliveId));
} }
try { try {
Thread.sleep(2); Thread.sleep(2);
} catch (InterruptedException e) { } catch(InterruptedException e) {
} }
} }
} }
} }
} }

View file

@ -19,7 +19,7 @@ public class AttributeModifier {
* The modifier's operation. * The modifier's operation.
*/ */
private int operation; private int operation;
/** /**
* Creates a new modifier. * Creates a new modifier.
* @param uid Unique id of the modifier. * @param uid Unique id of the modifier.
@ -31,7 +31,7 @@ public class AttributeModifier {
this.amount = amount; this.amount = amount;
this.operation = operation; this.operation = operation;
} }
/** /**
* Gets the modifier's unique id. * Gets the modifier's unique id.
* @return The modifier's unique id. * @return The modifier's unique id.
@ -39,7 +39,7 @@ public class AttributeModifier {
public UUID getUID() { public UUID getUID() {
return this.uid; return this.uid;
} }
/** /**
* Gets the modifier's amount. * Gets the modifier's amount.
* @return The modifier's amount. * @return The modifier's amount.
@ -47,7 +47,7 @@ public class AttributeModifier {
public double getAmount() { public double getAmount() {
return this.amount; return this.amount;
} }
/** /**
* Gets the modifier's operation. * Gets the modifier's operation.
* @return The modifier's operation. * @return The modifier's operation.
@ -55,5 +55,5 @@ public class AttributeModifier {
public int getOperation() { public int getOperation() {
return this.operation; return this.operation;
} }
} }

View file

@ -9,12 +9,12 @@ public class Coordinates {
* The X coordinate. * The X coordinate.
*/ */
private int x; private int x;
/** /**
* The Y coordinate. * The Y coordinate.
*/ */
private int y; private int y;
/** /**
* The Z coordinate. * The Z coordinate.
*/ */

View file

@ -20,7 +20,7 @@ public class EntityAttribute {
* The attribute's modifiers. * The attribute's modifiers.
*/ */
private List<AttributeModifier> modifiers; private List<AttributeModifier> modifiers;
/** /**
* Creates a new entity attribute instance. * Creates a new entity attribute instance.
* @param name Name of the attribute. * @param name Name of the attribute.
@ -29,7 +29,7 @@ public class EntityAttribute {
public EntityAttribute(String name, double value) { public EntityAttribute(String name, double value) {
this(name, value, new ArrayList<AttributeModifier>()); this(name, value, new ArrayList<AttributeModifier>());
} }
/** /**
* Creates a new entity attribute instance. * Creates a new entity attribute instance.
* @param name Name of the attribute. * @param name Name of the attribute.
@ -41,7 +41,7 @@ public class EntityAttribute {
this.value = value; this.value = value;
this.modifiers = modifiers; this.modifiers = modifiers;
} }
/** /**
* Gets the attribute's name. * Gets the attribute's name.
* @return The attribute's name. * @return The attribute's name.
@ -49,7 +49,7 @@ public class EntityAttribute {
public String getName() { public String getName() {
return this.name; return this.name;
} }
/** /**
* Gets the attribute's value. * Gets the attribute's value.
* @return The attribute's value. * @return The attribute's value.
@ -57,7 +57,7 @@ public class EntityAttribute {
public double getValue() { public double getValue() {
return this.value; return this.value;
} }
/** /**
* Gets the attribute's modifiers. * Gets the attribute's modifiers.
* @return The attribute's modifiers. * @return The attribute's modifiers.
@ -65,7 +65,7 @@ public class EntityAttribute {
public List<AttributeModifier> getModifiers() { public List<AttributeModifier> getModifiers() {
return this.modifiers; return this.modifiers;
} }
/** /**
* Adds a modifier to the attribute. * Adds a modifier to the attribute.
* @param mod Modifier to add. * @param mod Modifier to add.
@ -73,5 +73,5 @@ public class EntityAttribute {
public void addModifier(AttributeModifier mod) { public void addModifier(AttributeModifier mod) {
this.modifiers.add(mod); this.modifiers.add(mod);
} }
} }

View file

@ -9,17 +9,17 @@ public class StandardItemStack {
* Id of the items in the stack. * Id of the items in the stack.
*/ */
private short item; private short item;
/** /**
* The size of the item stack. * The size of the item stack.
*/ */
private byte stackSize; private byte stackSize;
/** /**
* The damage value of the items in the stack. * The damage value of the items in the stack.
*/ */
private short damage; private short damage;
/** /**
* The compressed NBT data of the item stack. * The compressed NBT data of the item stack.
*/ */
@ -53,7 +53,8 @@ public class StandardItemStack {
} }
/** /**
* Creates an item stack with the given id, size, damage value, and compressed NBT data. * Creates an item stack with the given id, size, damage value, and
* compressed NBT data.
* @param item Item id of the stack. * @param item Item id of the stack.
* @param stackSize Size of the stack. * @param stackSize Size of the stack.
* @param damage Damage value of the stack. * @param damage Damage value of the stack.
@ -73,7 +74,7 @@ public class StandardItemStack {
public short getItem() { public short getItem() {
return this.item; return this.item;
} }
/** /**
* Sets the item id of the stack. * Sets the item id of the stack.
* @param item New item id of the stack. * @param item New item id of the stack.

View file

@ -9,12 +9,12 @@ public class WatchableObject {
* The type id of the object. * The type id of the object.
*/ */
private int type; private int type;
/** /**
* The id of the object. * The id of the object.
*/ */
private int id; private int id;
/** /**
* The value of the object. * The value of the object.
*/ */

View file

@ -3,7 +3,7 @@ package ch.spacebase.mcprotocol.standard.example;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import ch.spacebase.mcprotocol.event.DisconnectEvent; import ch.spacebase.mcprotocol.event.DisconnectEvent;
import ch.spacebase.mcprotocol.event.PacketRecieveEvent; import ch.spacebase.mcprotocol.event.PacketReceiveEvent;
import ch.spacebase.mcprotocol.event.PacketSendEvent; import ch.spacebase.mcprotocol.event.PacketSendEvent;
import ch.spacebase.mcprotocol.event.ProtocolListener; import ch.spacebase.mcprotocol.event.ProtocolListener;
import ch.spacebase.mcprotocol.exception.ConnectException; import ch.spacebase.mcprotocol.exception.ConnectException;
@ -37,7 +37,7 @@ public class ChatBot {
try { try {
this.client.connect(); this.client.connect();
} catch (ConnectException e) { } catch(ConnectException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -56,20 +56,20 @@ public class ChatBot {
private class Listener extends ProtocolListener { private class Listener extends ProtocolListener {
@Override @Override
public void onPacketReceive(PacketRecieveEvent event) { public void onPacketReceive(PacketReceiveEvent event) {
Packet packet = event.getPacket(); Packet packet = event.getPacket();
switch(event.getPacket().getId()) { switch(event.getPacket().getId()) {
case 0x0D: case 0x0D:
onPositionLook((PacketPlayerPositionLook) packet); onPositionLook((PacketPlayerPositionLook) packet);
break; break;
} }
} }
@Override @Override
public void onPacketSend(PacketSendEvent event) { public void onPacketSend(PacketSendEvent event) {
} }
@Override @Override
public void onDisconnect(DisconnectEvent event) { public void onDisconnect(DisconnectEvent event) {
Util.logger().info("Disconnected: " + event.getReason()); Util.logger().info("Disconnected: " + event.getReason());

View file

@ -5,7 +5,7 @@ import ch.spacebase.mcprotocol.exception.OutdatedLibraryException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import ch.spacebase.mcprotocol.event.DisconnectEvent; import ch.spacebase.mcprotocol.event.DisconnectEvent;
import ch.spacebase.mcprotocol.event.PacketRecieveEvent; import ch.spacebase.mcprotocol.event.PacketReceiveEvent;
import ch.spacebase.mcprotocol.event.PacketSendEvent; import ch.spacebase.mcprotocol.event.PacketSendEvent;
import ch.spacebase.mcprotocol.event.PacketVisitor; import ch.spacebase.mcprotocol.event.PacketVisitor;
import ch.spacebase.mcprotocol.event.PacketVisitorAdapter; import ch.spacebase.mcprotocol.event.PacketVisitorAdapter;
@ -28,78 +28,77 @@ import java.util.logging.Logger;
*/ */
public class ChatBotVisitor { public class ChatBotVisitor {
private static final String USERNAME = ""; private static final String USERNAME = "";
private static final String PASSWORD = ""; private static final String PASSWORD = "";
private static final String HOST = "127.0.0.1"; private static final String HOST = "127.0.0.1";
private static final int PORT = 25565; private static final int PORT = 25565;
private Client client; private Client client;
private Listener listener; private Listener listener;
private PacketVisitor visitor; private PacketVisitor visitor;
public ChatBotVisitor(String host, int port) { public ChatBotVisitor(String host, int port) {
this.client = new StandardClient(host, port); this.client = new StandardClient(host, port);
this.listener = new Listener(); this.listener = new Listener();
this.client.listen(this.listener); this.client.listen(this.listener);
this.visitor = new Visitor();
}
public void login(String username, String password) { this.visitor = new Visitor();
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) { public void login(String username, String password) {
PacketChat chat = new PacketChat(); try {
chat.message = text; this.client.login(username, password);
this.client.send(chat); } 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 static void main(String[] args) { public void say(String text) {
ChatBotVisitor bot = new ChatBotVisitor(HOST, PORT); PacketChat chat = new PacketChat();
Util.logger().info("Logging in..."); chat.message = text;
bot.login(USERNAME, PASSWORD); this.client.send(chat);
} }
private class Visitor extends PacketVisitorAdapter { public static void main(String[] args) {
ChatBotVisitor bot = new ChatBotVisitor(HOST, PORT);
Util.logger().info("Logging in...");
bot.login(USERNAME, PASSWORD);
}
@Override private class Visitor extends PacketVisitorAdapter {
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) + ")"); @Override
} public void visit(PacketPlayerPositionLook packet) {
} client.send(packet);
DecimalFormat format = new DecimalFormat("#.00");
private class Listener extends ProtocolListener { ChatBotVisitor.this.say("Hello, this is " + USERNAME + " at coordinate (" + format.format(packet.x) + ", " + format.format(packet.y) + ", " + format.format(packet.z) + ")");
}
}
@Override private class Listener extends ProtocolListener {
public void onPacketReceive(PacketRecieveEvent event) {
Packet packet = event.getPacket();
packet.accept(visitor);
}
@Override @Override
public void onPacketSend(PacketSendEvent event) { public void onPacketReceive(PacketReceiveEvent event) {
} Packet packet = event.getPacket();
packet.accept(visitor);
}
@Override @Override
public void onDisconnect(DisconnectEvent event) { public void onPacketSend(PacketSendEvent event) {
Util.logger().info("Disconnected: " + event.getReason()); }
}
} @Override
public void onDisconnect(DisconnectEvent event) {
Util.logger().info("Disconnected: " + event.getReason());
}
}
} }

View file

@ -15,11 +15,11 @@ import ch.spacebase.mcprotocol.util.Constants;
public class StandardInput implements NetInput { public class StandardInput implements NetInput {
private InputStream in; private InputStream in;
public StandardInput(InputStream in) { public StandardInput(InputStream in) {
this.in = in; this.in = in;
} }
public InputStream getStream() { public InputStream getStream() {
return this.in; return this.in;
} }
@ -28,7 +28,7 @@ public class StandardInput implements NetInput {
public boolean readBoolean() throws IOException { public boolean readBoolean() throws IOException {
return this.readByte() == 1; return this.readByte() == 1;
} }
@Override @Override
public byte readByte() throws IOException { public byte readByte() throws IOException {
return (byte) this.readUnsignedByte(); return (byte) this.readUnsignedByte();
@ -40,7 +40,7 @@ public class StandardInput implements NetInput {
if(b < 0) { if(b < 0) {
throw new EOFException(); throw new EOFException();
} }
return b; return b;
} }
@ -94,17 +94,17 @@ public class StandardInput implements NetInput {
if(length < 0) { if(length < 0) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
int n = 0; int n = 0;
while(n < length) { while(n < length) {
int count = this.in.read(b, n, length - n); int count = this.in.read(b, n, length - n);
if(count < 0) { if(count < 0) {
throw new EOFException(); throw new EOFException();
} }
n += count; n += count;
} }
return b; return b;
} }
@ -118,12 +118,12 @@ public class StandardInput implements NetInput {
return new String(characters); return new String(characters);
} }
@Override @Override
public int available() throws IOException { public int available() throws IOException {
return this.in.available(); return this.in.available();
} }
/** /**
* Reads an entity's metadata. * Reads an entity's metadata.
* @return The read metadata objects. * @return The read metadata objects.
@ -166,7 +166,7 @@ public class StandardInput implements NetInput {
return objects.toArray(new WatchableObject[objects.size()]); return objects.toArray(new WatchableObject[objects.size()]);
} }
/** /**
* Reads an item stack. * Reads an item stack.
* @return The read item stack. * @return The read item stack.
@ -185,10 +185,10 @@ public class StandardInput implements NetInput {
nbt = this.readBytes(length); nbt = this.readBytes(length);
} }
} }
return new StandardItemStack(item, stackSize, damage, nbt); return new StandardItemStack(item, stackSize, damage, nbt);
} }
/** /**
* Reads a coordinate group. * Reads a coordinate group.
* @return The read coordinates. * @return The read coordinates.
@ -200,5 +200,5 @@ public class StandardInput implements NetInput {
int z = this.readInt(); int z = this.readInt();
return new Coordinates(x, y, z); return new Coordinates(x, y, z);
} }
} }

View file

@ -11,15 +11,15 @@ import ch.spacebase.mcprotocol.util.Constants;
public class StandardOutput implements NetOutput { public class StandardOutput implements NetOutput {
private OutputStream out; private OutputStream out;
public StandardOutput(OutputStream out) { public StandardOutput(OutputStream out) {
this.out = out; this.out = out;
} }
public OutputStream getStream() { public OutputStream getStream() {
return this.out; return this.out;
} }
@Override @Override
public void writeBoolean(boolean b) throws IOException { public void writeBoolean(boolean b) throws IOException {
this.writeByte(b ? 1 : 0); this.writeByte(b ? 1 : 0);
@ -76,7 +76,7 @@ public class StandardOutput implements NetOutput {
public void writeBytes(byte b[]) throws IOException { public void writeBytes(byte b[]) throws IOException {
this.writeBytes(b, b.length); this.writeBytes(b, b.length);
} }
@Override @Override
public void writeBytes(byte b[], int length) throws IOException { public void writeBytes(byte b[], int length) throws IOException {
this.out.write(b, 0, length); this.out.write(b, 0, length);
@ -87,7 +87,7 @@ public class StandardOutput implements NetOutput {
if(s == null) { if(s == null) {
throw new IllegalArgumentException("String cannot be null!"); throw new IllegalArgumentException("String cannot be null!");
} }
int len = s.length(); int len = s.length();
if(len >= 65536) { if(len >= 65536) {
throw new IllegalArgumentException("String too long."); throw new IllegalArgumentException("String too long.");
@ -98,12 +98,12 @@ public class StandardOutput implements NetOutput {
this.writeChar(s.charAt(i)); this.writeChar(s.charAt(i));
} }
} }
@Override @Override
public void flush() throws IOException { public void flush() throws IOException {
this.out.flush(); this.out.flush();
} }
/** /**
* Writes an entity's metadata. * Writes an entity's metadata.
* @param data Metadata objects to write. * @param data Metadata objects to write.
@ -140,7 +140,7 @@ public class StandardOutput implements NetOutput {
this.writeByte(127); this.writeByte(127);
} }
/** /**
* Writes an item stack. * Writes an item stack.
* @param item Item stack to write. * @param item Item stack to write.
@ -159,7 +159,7 @@ public class StandardOutput implements NetOutput {
} }
} }
} }
/** /**
* Writes a coordinate group. * Writes a coordinate group.
* @param coords Coordinates to write. * @param coords Coordinates to write.
@ -170,5 +170,5 @@ public class StandardOutput implements NetOutput {
this.writeInt(coords.getY()); this.writeInt(coords.getY());
this.writeInt(coords.getZ()); this.writeInt(coords.getZ());
} }
} }

View file

@ -47,9 +47,9 @@ public class PacketAnimation extends Packet {
return 18; return 18;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -51,9 +51,9 @@ public class PacketAttachEntity extends Packet {
return 39; return 39;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -63,9 +63,9 @@ public class PacketBlockAction extends Packet {
return 54; return 54;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -59,9 +59,9 @@ public class PacketBlockBreakAnimation extends Packet {
return 55; return 55;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -59,9 +59,9 @@ public class PacketBlockChange extends Packet {
return 53; return 53;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -47,9 +47,9 @@ public class PacketChat extends Packet {
return 3; return 3;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -59,9 +59,9 @@ public class PacketClientInfo extends Packet {
return 204; return 204;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -57,7 +57,7 @@ public class PacketClientStatus extends Packet {
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
response = reader.readLine(); response = reader.readLine();
reader.close(); reader.close();
} catch (IOException e) { } catch(IOException e) {
response = e.toString(); response = e.toString();
} }
@ -80,9 +80,9 @@ public class PacketClientStatus extends Packet {
return 205; return 205;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -43,9 +43,9 @@ public class PacketCloseWindow extends Packet {
return 101; return 101;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -46,10 +46,10 @@ public class PacketCollectItem extends Packet {
public int getId() { public int getId() {
return 22; return 22;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -51,9 +51,9 @@ public class PacketConfirmTransaction extends Packet {
return 106; return 106;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -52,9 +52,9 @@ public class PacketCreativeSlot extends Packet {
return 107; return 107;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -17,12 +17,12 @@ public class PacketDestroyEntity extends Packet {
} }
public PacketDestroyEntity(int... entityIds) { public PacketDestroyEntity(int... entityIds) {
this.entityIds = entityIds; this.entityIds = entityIds.clone();
} }
@Override @Override
public void read(NetInput in) throws IOException { public void read(NetInput in) throws IOException {
this.entityIds = new int[in.readByte()]; this.entityIds = new int[in.readUnsignedByte()];
for(int count = 0; count < this.entityIds.length; count++) { for(int count = 0; count < this.entityIds.length; count++) {
this.entityIds[count] = in.readInt(); this.entityIds[count] = in.readInt();
} }
@ -49,9 +49,9 @@ public class PacketDestroyEntity extends Packet {
return 29; return 29;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -49,9 +49,9 @@ public class PacketDisconnect extends Packet {
return 255; return 255;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -46,9 +46,9 @@ public class PacketDisplayScoreboard extends Packet {
return 208; return 208;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -63,9 +63,9 @@ public class PacketEffect extends Packet {
return 61; return 61;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -47,9 +47,9 @@ public class PacketEnchantItem extends Packet {
return 108; return 108;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -43,9 +43,9 @@ public class PacketEntity extends Packet {
return 30; return 30;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -21,7 +21,7 @@ public class PacketEntityAction extends Packet {
public PacketEntityAction(int entityId, byte action) { public PacketEntityAction(int entityId, byte action) {
this(entityId, action, 0); this(entityId, action, 0);
} }
public PacketEntityAction(int entityId, byte action, int jumpBar) { public PacketEntityAction(int entityId, byte action, int jumpBar) {
this.entityId = entityId; this.entityId = entityId;
this.action = action; this.action = action;
@ -55,9 +55,9 @@ public class PacketEntityAction extends Packet {
return 19; return 19;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -74,9 +74,9 @@ public class PacketEntityAttributes extends Packet {
return 44; return 44;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -55,9 +55,9 @@ public class PacketEntityEffect extends Packet {
return 41; return 41;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -66,9 +66,9 @@ public class PacketEntityEquipment extends Packet {
return 5; return 5;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -47,9 +47,9 @@ public class PacketEntityHeadYaw extends Packet {
return 35; return 35;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -51,9 +51,9 @@ public class PacketEntityLook extends Packet {
return 32; return 32;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -63,9 +63,9 @@ public class PacketEntityLookRelativeMove extends Packet {
return 33; return 33;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -50,9 +50,9 @@ public class PacketEntityMetadata extends Packet {
return 40; return 40;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -55,9 +55,9 @@ public class PacketEntityRelativeMove extends Packet {
return 31; return 31;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -47,9 +47,9 @@ public class PacketEntityStatus extends Packet {
return 38; return 38;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -63,10 +63,9 @@ public class PacketEntityTeleport extends Packet {
return 34; return 34;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -55,9 +55,9 @@ public class PacketEntityVelocity extends Packet {
return 28; return 28;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -72,9 +72,9 @@ public class PacketExplosion extends Packet {
return 60; return 60;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -47,9 +47,9 @@ public class PacketGameState extends Packet {
return 70; return 70;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -78,9 +78,9 @@ public class PacketHandshake extends Packet {
return 2; return 2;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -51,9 +51,9 @@ public class PacketHealthUpdate extends Packet {
return 8; return 8;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -43,9 +43,9 @@ public class PacketHeldItemChange extends Packet {
return 16; return 16;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -47,9 +47,9 @@ public class PacketIncrementStatistic extends Packet {
return 200; return 200;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -52,9 +52,9 @@ public class PacketItemData extends Packet {
return 131; return 131;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -44,9 +44,9 @@ public class PacketKeepAlive extends Packet {
return 0; return 0;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -111,15 +111,15 @@ public class PacketKeyRequest extends Packet {
Cipher cipher = Cipher.getInstance(key.getAlgorithm()); Cipher cipher = Cipher.getInstance(key.getAlgorithm());
cipher.init(1, key); cipher.init(1, key);
return cipher.doFinal(bytes); return cipher.doFinal(bytes);
} catch (InvalidKeyException e) { } catch(InvalidKeyException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchAlgorithmException e) { } catch(NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchPaddingException e) { } catch(NoSuchPaddingException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalBlockSizeException e) { } catch(IllegalBlockSizeException e) {
e.printStackTrace(); e.printStackTrace();
} catch (BadPaddingException e) { } catch(BadPaddingException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -137,11 +137,11 @@ public class PacketKeyRequest extends Packet {
X509EncodedKeySpec spec = new X509EncodedKeySpec(key); X509EncodedKeySpec spec = new X509EncodedKeySpec(key);
KeyFactory factory = KeyFactory.getInstance("RSA"); KeyFactory factory = KeyFactory.getInstance("RSA");
return factory.generatePublic(spec); return factory.generatePublic(spec);
} catch (NoSuchAlgorithmException e) { } catch(NoSuchAlgorithmException e) {
Util.logger().warning("Failed to get public key from array!"); Util.logger().warning("Failed to get public key from array!");
e.printStackTrace(); e.printStackTrace();
return null; return null;
} catch (InvalidKeySpecException e) { } catch(InvalidKeySpecException e) {
Util.logger().warning("Failed to get public key from array!"); Util.logger().warning("Failed to get public key from array!");
e.printStackTrace(); e.printStackTrace();
return null; return null;
@ -155,14 +155,14 @@ public class PacketKeyRequest extends Packet {
String response = reader.readLine(); String response = reader.readLine();
reader.close(); reader.close();
return response; return response;
} catch (IOException e) { } catch(IOException e) {
return e.toString(); return e.toString();
} }
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -90,24 +90,24 @@ public class PacketKeyResponse extends Packet {
Cipher cipher = Cipher.getInstance(key.getAlgorithm()); Cipher cipher = Cipher.getInstance(key.getAlgorithm());
cipher.init(2, key); cipher.init(2, key);
return cipher.doFinal(bytes); return cipher.doFinal(bytes);
} catch (InvalidKeyException e) { } catch(InvalidKeyException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchAlgorithmException e) { } catch(NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchPaddingException e) { } catch(NoSuchPaddingException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalBlockSizeException e) { } catch(IllegalBlockSizeException e) {
e.printStackTrace(); e.printStackTrace();
} catch (BadPaddingException e) { } catch(BadPaddingException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -59,9 +59,9 @@ public class PacketLightning extends Packet {
return 71; return 71;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -12,7 +12,7 @@ import ch.spacebase.mcprotocol.packet.Packet;
public class PacketLogin extends Packet { public class PacketLogin extends Packet {
public static boolean FORGE = false; public static boolean FORGE = false;
public int entityId; public int entityId;
public String levelType; public String levelType;
public byte gameMode; public byte gameMode;
@ -44,7 +44,7 @@ public class PacketLogin extends Packet {
} else { } else {
this.dimension = in.readByte(); this.dimension = in.readByte();
} }
this.difficulty = in.readByte(); this.difficulty = in.readByte();
this.unused = in.readByte(); this.unused = in.readByte();
this.maxPlayers = in.readByte(); this.maxPlayers = in.readByte();
@ -78,9 +78,9 @@ public class PacketLogin extends Packet {
return 1; return 1;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -62,7 +62,7 @@ public class PacketMapChunk extends Packet {
try { try {
inflater.inflate(this.data); inflater.inflate(this.data);
} catch (DataFormatException e) { } catch(DataFormatException e) {
throw new IOException("Bad compressed data format"); throw new IOException("Bad compressed data format");
} finally { } finally {
inflater.end(); inflater.end();
@ -82,7 +82,7 @@ public class PacketMapChunk extends Packet {
} finally { } finally {
deflater.end(); deflater.end();
} }
out.writeInt(this.x); out.writeInt(this.x);
out.writeInt(this.z); out.writeInt(this.z);
out.writeBoolean(this.groundUp); out.writeBoolean(this.groundUp);
@ -105,9 +105,9 @@ public class PacketMapChunk extends Packet {
return 51; return 51;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -65,7 +65,7 @@ public class PacketMapChunkBulk extends Packet {
try { try {
inflater.inflate(decompressed); inflater.inflate(decompressed);
} catch (DataFormatException e) { } catch(DataFormatException e) {
throw new IOException("Bad compressed data format"); throw new IOException("Bad compressed data format");
} finally { } finally {
inflater.end(); inflater.end();
@ -117,9 +117,9 @@ public class PacketMapChunkBulk extends Packet {
return 56; return 56;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -63,9 +63,9 @@ public class PacketMultiBlockChange extends Packet {
return 52; return 52;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -63,9 +63,9 @@ public class PacketNamedSound extends Packet {
return 62; return 62;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -55,9 +55,9 @@ public class PacketOpenTileEditor extends Packet {
return 133; return 133;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -21,7 +21,7 @@ public class PacketOpenWindow extends Packet {
public PacketOpenWindow() { public PacketOpenWindow() {
} }
public PacketOpenWindow(byte id, byte type, String name, byte slots, boolean useTitle) { public PacketOpenWindow(byte id, byte type, String name, byte slots, boolean useTitle) {
this(id, type, name, slots, useTitle, 0); this(id, type, name, slots, useTitle, 0);
} }
@ -72,9 +72,9 @@ public class PacketOpenWindow extends Packet {
return 100; return 100;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -43,9 +43,9 @@ public class PacketPlayer extends Packet {
return 10; return 10;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -67,9 +67,9 @@ public class PacketPlayerAbilities extends Packet {
return 202; return 202;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -59,7 +59,7 @@ public class PacketPlayerBlockPlace extends Packet {
if(this.item != null) { if(this.item != null) {
((StandardOutput) out).writeItem(this.item); ((StandardOutput) out).writeItem(this.item);
} }
out.writeByte(this.cursorX); out.writeByte(this.cursorX);
out.writeByte(this.cursorY); out.writeByte(this.cursorY);
out.writeByte(this.cursorZ); out.writeByte(this.cursorZ);
@ -78,9 +78,9 @@ public class PacketPlayerBlockPlace extends Packet {
return 15; return 15;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -59,9 +59,9 @@ public class PacketPlayerDigging extends Packet {
return 14; return 14;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -51,9 +51,9 @@ public class PacketPlayerListItem extends Packet {
return 201; return 201;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -51,9 +51,9 @@ public class PacketPlayerLook extends Packet {
return 12; return 12;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -59,9 +59,9 @@ public class PacketPlayerPosition extends Packet {
return 11; return 11;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -67,9 +67,9 @@ public class PacketPlayerPositionLook extends Packet {
return 13; return 13;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -48,9 +48,9 @@ public class PacketPluginMessage extends Packet {
return 250; return 250;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -47,9 +47,9 @@ public class PacketRemoveEntityEffect extends Packet {
return 42; return 42;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -59,9 +59,9 @@ public class PacketRespawn extends Packet {
return 9; return 9;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -50,9 +50,9 @@ public class PacketScoreboardObjective extends Packet {
return 206; return 206;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -1,6 +1,5 @@
package ch.spacebase.mcprotocol.standard.packet; package ch.spacebase.mcprotocol.standard.packet;
import ch.spacebase.mcprotocol.event.PacketVisitor;
import ch.spacebase.mcprotocol.event.PacketVisitor; import ch.spacebase.mcprotocol.event.PacketVisitor;
import ch.spacebase.mcprotocol.net.io.NetInput; import ch.spacebase.mcprotocol.net.io.NetInput;
import ch.spacebase.mcprotocol.net.io.NetOutput; import ch.spacebase.mcprotocol.net.io.NetOutput;
@ -41,9 +40,9 @@ public class PacketServerPing extends Packet {
return 254; return 254;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -51,9 +51,9 @@ public class PacketSetExperience extends Packet {
return 43; return 43;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -56,9 +56,9 @@ public class PacketSetSlot extends Packet {
return 103; return 103;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -59,9 +59,9 @@ public class PacketSpawnExpOrb extends Packet {
return 26; return 26;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -90,9 +90,9 @@ public class PacketSpawnMob extends Packet {
return 24; return 24;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -78,9 +78,9 @@ public class PacketSpawnNamedEntity extends Packet {
return 20; return 20;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -87,9 +87,9 @@ public class PacketSpawnObject extends Packet {
return 23; return 23;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -63,9 +63,9 @@ public class PacketSpawnPainting extends Packet {
return 25; return 25;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -72,9 +72,9 @@ public class PacketSpawnParticle extends Packet {
return 63; return 63;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -51,9 +51,9 @@ public class PacketSpawnPosition extends Packet {
return 6; return 6;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View file

@ -55,9 +55,9 @@ public class PacketSteerVehicle extends Packet {
return 27; return 27;
} }
@Override @Override
public void accept(PacketVisitor visitor) { public void accept(PacketVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

Some files were not shown because too many files have changed in this diff Show more