PageRenderTime 652ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/ONetServerHandler.java

http://github.com/traitor/Minecraft-Server-Mod
Java | 617 lines | 484 code | 87 blank | 46 comment | 165 complexity | df48daa890ddababdbd11beff99c07ee MD5 | raw file
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.logging.Logger;
  6. import net.minecraft.server.MinecraftServer;
  7. public class ONetServerHandler extends ONetHandler implements OICommandListener {
  8. public static Logger a = Logger.getLogger("Minecraft");
  9. public ONetworkManager b;
  10. public boolean c = false;
  11. private MinecraftServer d;
  12. private OEntityPlayerMP e;
  13. private int f;
  14. private int g;
  15. private boolean h;
  16. private double i;
  17. private double j;
  18. private double k;
  19. private boolean l = true;
  20. private Map m = new HashMap();
  21. public ONetServerHandler(MinecraftServer paramMinecraftServer, ONetworkManager paramONetworkManager, OEntityPlayerMP paramOEntityPlayerMP) {
  22. d = paramMinecraftServer;
  23. b = paramONetworkManager;
  24. paramONetworkManager.a(this);
  25. e = paramOEntityPlayerMP;
  26. paramOEntityPlayerMP.a = this;
  27. }
  28. /**
  29. * Returns the item in player's hand
  30. *
  31. * @return
  32. */
  33. public int getItemInHand() {
  34. if (e.i.b() != null)
  35. return e.i.b().c;
  36. return -1;
  37. }
  38. public Player getPlayer() {
  39. return e.getPlayer();
  40. }
  41. /**
  42. * Sends a message to the player
  43. *
  44. * @param msg
  45. */
  46. public void msg(String msg) {
  47. b(new OPacket3Chat(msg));
  48. }
  49. public void a() {
  50. h = false;
  51. b.a();
  52. if (f - g > 20)
  53. b(new OPacket0KeepAlive());
  54. }
  55. public void a(String paramString) {
  56. b(new OPacket255KickDisconnect(paramString));
  57. b.c();
  58. d.f.a(new OPacket3Chat("§e" + e.r + " left the game."));
  59. d.f.c(e);
  60. c = true;
  61. }
  62. @Override
  63. public void a(OPacket27 paramOPacket27) {
  64. e.a(paramOPacket27.c(), paramOPacket27.e(), paramOPacket27.g(), paramOPacket27.h(), paramOPacket27.d(), paramOPacket27.f());
  65. }
  66. @Override
  67. public void a(OPacket10Flying paramOPacket10Flying) {
  68. h = true;
  69. double d1;
  70. if (!l) {
  71. d1 = paramOPacket10Flying.b - j;
  72. if ((paramOPacket10Flying.a == i) && (d1 * d1 < 0.01D) && (paramOPacket10Flying.c == k))
  73. l = true;
  74. }
  75. // hMod: Notice player movement
  76. if (etc.floor(i) != etc.floor(getPlayer().getX()) || etc.floor(j) != etc.floor(getPlayer().getY()) || etc.floor(k) != etc.floor(getPlayer().getZ())) {
  77. Location from = new Location();
  78. from.x = etc.floor(i);
  79. from.y = etc.floor(j);
  80. from.z = etc.floor(k);
  81. from.rotX = getPlayer().getRotation();
  82. from.rotY = getPlayer().getPitch();
  83. Location to = new Location();
  84. to.x = etc.floor(e.aK);
  85. to.y = etc.floor(e.aL);
  86. to.z = etc.floor(e.aM);
  87. to.rotX = getPlayer().getRotation();
  88. to.rotY = getPlayer().getPitch();
  89. OEntity.manager.callHook(PluginLoader.Hook.PLAYER_MOVE, getPlayer(), from, to);
  90. }
  91. if (l) {
  92. if (e.aF != null) {
  93. float f1 = e.aQ;
  94. float f2 = e.aR;
  95. e.aF.h_();
  96. double d2 = e.aK;
  97. double d3 = e.aL;
  98. double d4 = e.aM;
  99. double d5 = 0.0D;
  100. double d6 = 0.0D;
  101. if (paramOPacket10Flying.i) {
  102. f1 = paramOPacket10Flying.e;
  103. f2 = paramOPacket10Flying.f;
  104. }
  105. if ((paramOPacket10Flying.h) && (paramOPacket10Flying.b == -999.0D) && (paramOPacket10Flying.d == -999.0D)) {
  106. d5 = paramOPacket10Flying.a;
  107. d6 = paramOPacket10Flying.c;
  108. }
  109. e.aV = paramOPacket10Flying.g;
  110. e.a(true);
  111. e.c(d5, 0.0D, d6);
  112. e.b(d2, d3, d4, f1, f2);
  113. e.aN = d5;
  114. e.aP = d6;
  115. if (e.aF != null)
  116. d.e.b(e.aF, true);
  117. if (e.aF != null)
  118. e.aF.h_();
  119. d.f.b(e);
  120. i = e.aK;
  121. j = e.aL;
  122. k = e.aM;
  123. d.e.f(e);
  124. return;
  125. }
  126. d1 = e.aL;
  127. i = e.aK;
  128. j = e.aL;
  129. k = e.aM;
  130. double d2 = e.aK;
  131. double d3 = e.aL;
  132. double d4 = e.aM;
  133. float f3 = e.aQ;
  134. float f4 = e.aR;
  135. if ((paramOPacket10Flying.h) && (paramOPacket10Flying.b == -999.0D) && (paramOPacket10Flying.d == -999.0D))
  136. paramOPacket10Flying.h = false;
  137. if (paramOPacket10Flying.h) {
  138. d2 = paramOPacket10Flying.a;
  139. d3 = paramOPacket10Flying.b;
  140. d4 = paramOPacket10Flying.c;
  141. double d6 = paramOPacket10Flying.d - paramOPacket10Flying.b;
  142. if ((d6 > 1.65D) || (d6 < 0.1D)) {
  143. a("Illegal stance");
  144. a.warning(e.r + " had an illegal stance: " + d6);
  145. }
  146. }
  147. if (paramOPacket10Flying.i) {
  148. f3 = paramOPacket10Flying.e;
  149. f4 = paramOPacket10Flying.f;
  150. }
  151. e.a(true);
  152. e.bl = 0.0F;
  153. e.b(i, j, k, f3, f4);
  154. double d6 = d2 - e.aK;
  155. double d7 = d3 - e.aL;
  156. double d8 = d4 - e.aM;
  157. float f5 = 0.0625F;
  158. int n = d.e.a(e, e.aU.b().e(f5, f5, f5)).size() == 0 ? 1 : 0;
  159. e.c(d6, d7, d8);
  160. d6 = d2 - e.aK;
  161. d7 = d3 - e.aL;
  162. if ((d7 > -0.5D) || (d7 < 0.5D))
  163. d7 = 0.0D;
  164. d8 = d4 - e.aM;
  165. double d9 = d6 * d6 + d7 * d7 + d8 * d8;
  166. int i1 = 0;
  167. if ((d9 > 0.0625D) && (!e.F())) {
  168. i1 = 1;
  169. a.warning(e.r + " moved wrongly!");
  170. System.out.println("Got position " + d2 + ", " + d3 + ", " + d4);
  171. System.out.println("Expected " + e.aK + ", " + e.aL + ", " + e.aM);
  172. }
  173. e.b(d2, d3, d4, f3, f4);
  174. int i2 = d.e.a(e, e.aU.b().e(f5, f5, f5)).size() == 0 ? 1 : 0;
  175. if ((n != 0) && ((i1 != 0) || (i2 == 0)) && (!e.F())) {
  176. a(i, j, k, f3, f4);
  177. return;
  178. }
  179. e.aV = paramOPacket10Flying.g;
  180. d.f.b(e);
  181. e.b(e.aL - d1, paramOPacket10Flying.g);
  182. }
  183. }
  184. public void a(double paramDouble1, double paramDouble2, double paramDouble3, float paramFloat1, float paramFloat2) {
  185. // hMod: Teleportation hook
  186. Location from = new Location();
  187. from.x = paramDouble1;
  188. from.y = paramDouble2;
  189. from.z = paramDouble3;
  190. from.rotX = paramFloat1;
  191. from.rotY = paramFloat2;
  192. Player player = getPlayer();
  193. if ((Boolean) OEntity.manager.callHook(PluginLoader.Hook.TELEPORT, player, player.getLocation(), from))
  194. return;
  195. l = false;
  196. i = paramDouble1;
  197. j = paramDouble2;
  198. k = paramDouble3;
  199. e.b(paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2);
  200. e.a.b(new OPacket13PlayerLookMove(paramDouble1, paramDouble2 + 1.620000004768372D, paramDouble2, paramDouble3, paramFloat1, paramFloat2, false));
  201. }
  202. // hMod: Store x/y/z
  203. int x, y, z, type;
  204. @Override
  205. public void a(OPacket14BlockDig paramOPacket14BlockDig) {
  206. if (paramOPacket14BlockDig.e == 4) {
  207. e.z();
  208. return;
  209. }
  210. boolean bool = d.e.v = d.f.h(e.r) || getPlayer().isAdmin();
  211. int n = 0;
  212. if (paramOPacket14BlockDig.e == 0)
  213. n = 1;
  214. if (paramOPacket14BlockDig.e == 2)
  215. n = 1;
  216. int i1 = paramOPacket14BlockDig.a;
  217. int i2 = paramOPacket14BlockDig.b;
  218. int i3 = paramOPacket14BlockDig.c;
  219. if (n != 0) {
  220. double d1 = e.aK - (i1 + 0.5D);
  221. double d2 = e.aL - (i2 + 0.5D);
  222. double d3 = e.aM - (i3 + 0.5D);
  223. double d4 = d1 * d1 + d2 * d2 + d3 * d3;
  224. if (d4 > 36.0D)
  225. return;
  226. }
  227. OChunkCoordinates localOChunkCoordinates = d.e.m();
  228. int i4 = (int) OMathHelper.e(i1 - localOChunkCoordinates.a);
  229. int i5 = (int) OMathHelper.e(i3 - localOChunkCoordinates.c);
  230. if (i4 > i5)
  231. i5 = i4;
  232. // hMod: the player
  233. Player player = getPlayer();
  234. if (paramOPacket14BlockDig.e == 0) {
  235. // hMod: Start digging
  236. // No buildrights
  237. if (!getPlayer().canBuild())
  238. return;
  239. // hMod: Custom spawn prot size
  240. if ((i5 > etc.getInstance().getSpawnProtectionSize()) || (bool)) {
  241. // hMod: Dig hooks
  242. Block block = etc.getServer().getBlockAt(i1, i2, i3);
  243. block.setStatus(0); // Started digging
  244. x = block.getX();
  245. y = block.getY();
  246. z = block.getZ();
  247. type = block.getType();
  248. if (!(Boolean) OEntity.manager.callHook(PluginLoader.Hook.BLOCK_DESTROYED, player, block))
  249. e.c.a(i1, i2, i3);
  250. }
  251. } else if (paramOPacket14BlockDig.e == 2)
  252. e.c.b(i1, i2, i3);
  253. else if (paramOPacket14BlockDig.e == 3) {
  254. // hMod: Break block
  255. Block block = new Block(type, x, y, z);
  256. block.setStatus(3);
  257. OEntity.manager.callHook(PluginLoader.Hook.BLOCK_DESTROYED, player, block);
  258. double d5 = e.aK - (i1 + 0.5D);
  259. double d6 = e.aL - (i2 + 0.5D);
  260. double d7 = e.aM - (i3 + 0.5D);
  261. double d8 = d5 * d5 + d6 * d6 + d7 * d7;
  262. if (d8 < 256.0D)
  263. e.a.b(new OPacket53BlockChange(i1, i2, i3, d.e));
  264. }
  265. d.e.v = false;
  266. }
  267. // hMod: Store the blocks between blockPlaced packets
  268. Block lastRightClicked;
  269. @Override
  270. public void a(OPacket15Place paramOPacket15Place) {
  271. OItemStack localOItemStack = e.i.b();
  272. // hMod: Store block data to call hooks
  273. // hMod START
  274. Block blockClicked = null;
  275. Block blockPlaced = null;
  276. boolean bool = d.e.v = d.f.h(e.r) || getPlayer().isAdmin();
  277. if (paramOPacket15Place.d == 255) {
  278. // ITEM_USE -- if we have a lastRightClicked then it could be a
  279. // usable location
  280. blockClicked = lastRightClicked;
  281. lastRightClicked = null;
  282. } else {
  283. // RIGHTCLICK or BLOCK_PLACE .. or nothing
  284. blockClicked = new Block(etc.getServer().getBlockIdAt(paramOPacket15Place.a, paramOPacket15Place.b, paramOPacket15Place.c), paramOPacket15Place.a, paramOPacket15Place.b, paramOPacket15Place.c);
  285. blockClicked.setFaceClicked(Block.Face.fromId(paramOPacket15Place.d));
  286. lastRightClicked = blockClicked;
  287. }
  288. // If we clicked on something then we also have a location to place the
  289. // block
  290. if (blockClicked != null && localOItemStack != null) {
  291. blockPlaced = new Block(localOItemStack.c, blockClicked.getX(), blockClicked.getY(), blockClicked.getZ());
  292. switch (paramOPacket15Place.d) {
  293. case 0:
  294. blockPlaced.setY(blockPlaced.getY() - 1);
  295. break;
  296. case 1:
  297. blockPlaced.setY(blockPlaced.getY() + 1);
  298. break;
  299. case 2:
  300. blockPlaced.setZ(blockPlaced.getZ() - 1);
  301. break;
  302. case 3:
  303. blockPlaced.setZ(blockPlaced.getZ() + 1);
  304. break;
  305. case 4:
  306. blockPlaced.setX(blockPlaced.getX() - 1);
  307. break;
  308. case 5:
  309. blockPlaced.setX(blockPlaced.getX() + 1);
  310. break;
  311. }
  312. }
  313. // hMod: END
  314. if (paramOPacket15Place.d == 255) {
  315. // hMod: call our version with extra blockClicked/blockPlaced
  316. if (blockPlaced != null)
  317. // Set the type of block to what it currently is
  318. blockPlaced.setType(etc.getServer().getBlockIdAt(blockPlaced.getX(), blockPlaced.getY(), blockPlaced.getZ()));
  319. if (localOItemStack == null)
  320. return;
  321. ((Digging) e.c).a(e, d.e, localOItemStack, blockPlaced, blockClicked);
  322. } else {
  323. int n = paramOPacket15Place.a;
  324. int i1 = paramOPacket15Place.b;
  325. int i2 = paramOPacket15Place.c;
  326. int i3 = paramOPacket15Place.d;
  327. OChunkCoordinates localOChunkCoordinates = d.e.m();
  328. // hMod : Fix stupid buggy spawn protection.
  329. int i4 = (int) OMathHelper.e((i3 == 4 ? n - 1 : (i3 == 5 ? (n + 1) : n)) - localOChunkCoordinates.a);
  330. // hMod : Fix stupid buggy spawn protection.
  331. int i5 = (int) OMathHelper.e((i3 == 2 ? i2 - 1 : (i3 == 3 ? (i2 + 1) : i2)) - localOChunkCoordinates.c);
  332. if (i4 > i5)
  333. i5 = i4;
  334. // hMod: call BLOCK_RIGHTCLICKED
  335. Item item = (localOItemStack != null) ? new Item(localOItemStack) : new Item(Item.Type.Air);
  336. Player player = getPlayer();
  337. OEntity.manager.callHook(PluginLoader.Hook.BLOCK_RIGHTCLICKED, player, blockClicked, item);
  338. // hMod: call original BLOCK_CREATED
  339. OEntity.manager.callHook(PluginLoader.Hook.BLOCK_CREATED, player, blockPlaced, blockClicked, item.getItemId());
  340. // hMod: If we were building inside spawn, bail! (unless ops/admin)
  341. if (((i5 > etc.getInstance().getSpawnProtectionSize() && !etc.getInstance().isOnItemBlacklist(item.getItemId())) || bool) && player.canBuild())
  342. e.c.a(e, d.e, localOItemStack, n, i1, i2, i3);
  343. else {
  344. // hMod: No point sending the client to update the blocks, you
  345. // weren't allowed to place!
  346. d.e.v = false;
  347. return;
  348. }
  349. e.a.b(new OPacket53BlockChange(n, i1, i2, d.e));
  350. if (i3 == 0)
  351. i1--;
  352. if (i3 == 1)
  353. i1++;
  354. if (i3 == 2)
  355. i2--;
  356. if (i3 == 3)
  357. i2++;
  358. if (i3 == 4)
  359. n--;
  360. if (i3 == 5)
  361. n++;
  362. e.a.b(new OPacket53BlockChange(n, i1, i2, d.e));
  363. }
  364. if ((localOItemStack != null) && (localOItemStack.a == 0))
  365. e.i.a[e.i.c] = null;
  366. e.h = true;
  367. e.i.a[e.i.c] = OItemStack.b(e.i.a[e.i.c]);
  368. OSlot localOSlot = e.k.a(e.i, e.i.c);
  369. e.k.a();
  370. e.h = false;
  371. if (!OItemStack.a(e.i.b(), paramOPacket15Place.e))
  372. b(new OPacket103(e.k.f, localOSlot.a, e.i.b()));
  373. d.e.v = false;
  374. }
  375. @Override
  376. public void a(String paramString, Object[] paramArrayOfObject) {
  377. // hMod: disconnect!
  378. OEntity.manager.callHook(PluginLoader.Hook.DISCONNECT, getPlayer());
  379. a.info(e.r + " lost connection: " + paramString);
  380. d.f.a(new OPacket3Chat("§e" + e.r + " left the game."));
  381. d.f.c(e);
  382. c = true;
  383. }
  384. @Override
  385. public void a(OPacket paramOPacket) {
  386. a.warning(getClass() + " wasn't prepared to deal with a " + paramOPacket.getClass());
  387. a("Protocol error, unexpected packet");
  388. }
  389. public void b(OPacket paramOPacket) {
  390. b.a(paramOPacket);
  391. g = f;
  392. }
  393. @Override
  394. public void a(OPacket16BlockItemSwitch paramOPacket16BlockItemSwitch) {
  395. if ((paramOPacket16BlockItemSwitch.a < 0) || (paramOPacket16BlockItemSwitch.a > OInventoryPlayer.e())) {
  396. a.warning(e.r + " tried to set an invalid carried item");
  397. return;
  398. }
  399. e.i.c = paramOPacket16BlockItemSwitch.a;
  400. }
  401. @Override
  402. public void a(OPacket3Chat paramOPacket3Chat) {
  403. String str = paramOPacket3Chat.a;
  404. // hMod: redirect chathandling to player class
  405. getPlayer().chat(str);
  406. }
  407. private void c(String paramString) {
  408. }
  409. @Override
  410. public void a(OPacket18ArmAnimation paramOPacket18ArmAnimation) {
  411. if (paramOPacket18ArmAnimation.b == 1) {
  412. // hMod: Swing the arm!
  413. OEntity.manager.callHook(PluginLoader.Hook.ARM_SWING, getPlayer());
  414. e.m_();
  415. }
  416. }
  417. @Override
  418. public void a(OPacket19 paramOPacket19) {
  419. if (paramOPacket19.b == 1)
  420. e.e(true);
  421. else if (paramOPacket19.b == 2)
  422. e.e(false);
  423. else if (paramOPacket19.b == 3) {
  424. e.a(false, true, true);
  425. l = false;
  426. }
  427. }
  428. @Override
  429. public void a(OPacket255KickDisconnect paramOPacket255KickDisconnect) {
  430. b.a("disconnect.quitting", new Object[0]);
  431. }
  432. public int b() {
  433. return b.d();
  434. }
  435. public void b(String paramString) {
  436. b(new OPacket3Chat("§7" + paramString));
  437. }
  438. public String c() {
  439. return e.r;
  440. }
  441. @Override
  442. public void a(OPacket7 paramOPacket7) {
  443. OEntity localOEntity = d.e.a(paramOPacket7.b);
  444. if ((localOEntity != null) && (e.e(localOEntity)) && (e.f(localOEntity) < 4.0F))
  445. if (paramOPacket7.c == 0)
  446. e.c(localOEntity);
  447. else if (paramOPacket7.c == 1)
  448. e.d(localOEntity);
  449. }
  450. @Override
  451. public void a(OPacket9 paramOPacket9) {
  452. if (e.W > 0)
  453. return;
  454. e = d.f.d(e);
  455. }
  456. @Override
  457. public void a(OPacket101 paramOPacket101) {
  458. e.w();
  459. }
  460. @Override
  461. public void a(OPacket102 paramOPacket102) {
  462. if ((e.k.f == paramOPacket102.a) && (e.k.c(e))) {
  463. OItemStack localOItemStack = e.k.a(paramOPacket102.b, paramOPacket102.c, e);
  464. if (OItemStack.a(paramOPacket102.e, localOItemStack)) {
  465. e.a.b(new OPacket106(paramOPacket102.a, paramOPacket102.d, true));
  466. e.h = true;
  467. e.k.a();
  468. e.v();
  469. e.h = false;
  470. } else {
  471. m.put(Integer.valueOf(e.k.f), Short.valueOf(paramOPacket102.d));
  472. e.a.b(new OPacket106(paramOPacket102.a, paramOPacket102.d, false));
  473. e.k.a(e, false);
  474. ArrayList localArrayList = new ArrayList();
  475. for (int n = 0; n < e.k.e.size(); n++)
  476. localArrayList.add(((OSlot) e.k.e.get(n)).a());
  477. e.a(e.k, localArrayList);
  478. }
  479. }
  480. }
  481. @Override
  482. public void a(OPacket106 paramOPacket106) {
  483. Short localShort = (Short) m.get(Integer.valueOf(e.k.f));
  484. if ((localShort != null) && (paramOPacket106.b == localShort.shortValue()) && (e.k.f == paramOPacket106.a) && (!e.k.c(e)))
  485. e.k.a(e, true);
  486. }
  487. @Override
  488. public void a(OPacket130 paramOPacket130) {
  489. if (d.e.f(paramOPacket130.a, paramOPacket130.b, paramOPacket130.c)) {
  490. OTileEntity localOTileEntity = d.e.m(paramOPacket130.a, paramOPacket130.b, paramOPacket130.c);
  491. if ((localOTileEntity instanceof OTileEntitySign)) {
  492. OTileEntitySign localOTileEntitySign1 = (OTileEntitySign) localOTileEntity;
  493. if (!localOTileEntitySign1.a()) {
  494. d.c("Player " + e.r + " just tried to change non-editable sign");
  495. return;
  496. }
  497. }
  498. int i1;
  499. int i2;
  500. for (int n = 0; n < 4; n++) {
  501. i1 = 1;
  502. // hMod: Remove the char limit, for plugins.
  503. // if (paramOPacket130.d[n].length() > 15) {
  504. // i1 = 0;
  505. // } else {
  506. for (i2 = 0; i2 < paramOPacket130.d[n].length(); i2++)
  507. if (OFontAllowedCharacters.a.indexOf(paramOPacket130.d[n].charAt(i2)) < 0)
  508. i1 = 0;
  509. if (i1 == 0)
  510. paramOPacket130.d[n] = "!?";
  511. }
  512. if ((localOTileEntity instanceof OTileEntitySign)) {
  513. int n = paramOPacket130.a;
  514. i1 = paramOPacket130.b;
  515. i2 = paramOPacket130.c;
  516. OTileEntitySign localOTileEntitySign2 = (OTileEntitySign) localOTileEntity;
  517. // hMod: Copy the old line text
  518. String[] old = Arrays.copyOf(localOTileEntitySign2.a, localOTileEntitySign2.a.length);
  519. // hMod: Check if we can change it
  520. Sign sign = new Sign(localOTileEntitySign2);
  521. if ((Boolean) OEntity.manager.callHook(PluginLoader.Hook.SIGN_CHANGE, getPlayer(), sign))
  522. localOTileEntitySign2.a = Arrays.copyOf(old, old.length);
  523. for (int i3 = 0; i3 < 4; i3++)
  524. localOTileEntitySign2.a[i3] = paramOPacket130.d[i3];
  525. localOTileEntitySign2.i();
  526. d.e.g(n, i1, i2);
  527. }
  528. }
  529. }
  530. }