spenk

Untitled

Apr 15th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import java.io.UnsupportedEncodingException;
  7.  
  8. public class Packet250CustomPayload extends Packet
  9. {
  10. /** Name of the 'channel' used to send data */
  11. public String channel;
  12.  
  13. /** Length of the data to be read */
  14. public int length;
  15.  
  16. /** Any data */
  17. public byte[] data;
  18.  
  19. public Packet250CustomPayload() {}
  20.  
  21. public Packet250CustomPayload(String par1Str, byte[] par2ArrayOfByte)
  22. {
  23. this.channel = par1Str;
  24. this.data = par2ArrayOfByte;
  25. //System.out.println(channel);
  26. if (par2ArrayOfByte != null)
  27. {
  28. this.length = par2ArrayOfByte.length;
  29.  
  30. if (this.length > 32767)
  31. {
  32. throw new IllegalArgumentException("Payload may not be larger than 32k");
  33. }
  34. }
  35. }
  36.  
  37. /**
  38. * Abstract. Reads the raw packet data from the data stream.
  39. */
  40. public void readPacketData(DataInputStream par1DataInputStream) throws IOException
  41. {
  42. this.channel = readString(par1DataInputStream, 20);
  43. this.length = par1DataInputStream.readShort();
  44. //System.out.println(channel);
  45. if (this.length > 0 && this.length < 32767)
  46. {
  47. this.data = new byte[this.length];
  48. par1DataInputStream.readFully(this.data);
  49. }
  50. }
  51.  
  52. /**
  53. * Abstract. Writes the raw packet data to the data stream.
  54. */
  55. public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
  56. {
  57. writeString(this.channel, par1DataOutputStream);
  58. par1DataOutputStream.writeShort((short)this.length);
  59.  
  60. if (this.data != null)
  61. {
  62. par1DataOutputStream.write(this.data);
  63. }
  64. }
  65.  
  66. /**
  67. * Passes this Packet on to the NetHandler for processing.
  68. */
  69. public void processPacket(NetHandler par1NetHandler)
  70. {
  71. par1NetHandler.handleCustomPayload(this);
  72. handleCustomPayload();
  73. }
  74.  
  75. /**
  76. * Abstract. Return the size of the packet (not counting the header).
  77. */
  78. public int getPacketSize()
  79. {
  80. return 2 + this.channel.length() * 2 + 2 + this.length;
  81. }
  82.  
  83. public void handleCustomPayload() {
  84. System.out.println(channel);
  85. if (!channel.equals("CustomGui")) return;
  86. String data = new String(this.data);
  87. System.out.println(data);
  88. String[] args = data.split(":");
  89. String command = args[0];
  90. if (command.equals("OpenGui")) {
  91. mod_CustomGui.openGui(mod_CustomGui.minecraft.thePlayer);
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment