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

/mcp/temp/src/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java

https://bitbucket.org/vkorolik/twoleanfour-client
Java | 486 lines | 457 code | 21 blank | 8 comment | 94 complexity | 1b5e7a85371a80259495bf898d084caf MD5 | raw file
  1. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  2. // Jad home page: http://www.kpdus.com/jad.html
  3. // Decompiler options: packimports(3) braces deadcode fieldsfirst
  4. package net.minecraft.src;
  5. import java.util.*;
  6. import java.util.logging.Logger;
  7. import net.minecraft.server.MinecraftServer;
  8. // Referenced classes of package net.minecraft.src:
  9. // ServerCommand, ICommandListener, ServerConfigurationManager, WorldServer,
  10. // EntityPlayerMP, NetServerHandler, Item, ItemStack,
  11. // WorldSettings, ItemInWorldManager, Packet70Bed, Packet3Chat,
  12. // PropertyManager
  13. public class ConsoleCommandHandler
  14. {
  15. private static Logger field_22117_a = Logger.getLogger("Minecraft");
  16. private MinecraftServer field_22116_b;
  17. public ConsoleCommandHandler(MinecraftServer p_i461_1_)
  18. {
  19. field_22116_b = p_i461_1_;
  20. }
  21. public synchronized void func_22114_a(ServerCommand p_22114_1_)
  22. {
  23. String s = p_22114_1_.field_1060_a;
  24. String as[] = s.split(" ");
  25. String s1 = as[0];
  26. String s2 = s.substring(s1.length()).trim();
  27. ICommandListener icommandlistener = p_22114_1_.field_1059_b;
  28. String s3 = icommandlistener.func_1_c();
  29. ServerConfigurationManager serverconfigurationmanager = field_22116_b.field_6033_f;
  30. if(s1.equalsIgnoreCase("help") || s1.equalsIgnoreCase("?"))
  31. {
  32. func_22111_a(icommandlistener);
  33. } else
  34. if(s1.equalsIgnoreCase("list"))
  35. {
  36. icommandlistener.func_2_b((new StringBuilder()).append("Connected players: ").append(serverconfigurationmanager.func_633_c()).toString());
  37. } else
  38. if(s1.equalsIgnoreCase("stop"))
  39. {
  40. func_22115_a(s3, "Stopping the server..");
  41. field_22116_b.func_6016_a();
  42. } else
  43. if(s1.equalsIgnoreCase("save-all"))
  44. {
  45. func_22115_a(s3, "Forcing save..");
  46. if(serverconfigurationmanager != null)
  47. {
  48. serverconfigurationmanager.func_617_d();
  49. }
  50. for(int i = 0; i < field_22116_b.field_6034_e.length; i++)
  51. {
  52. WorldServer worldserver = field_22116_b.field_6034_e[i];
  53. boolean flag = worldserver.field_816_A;
  54. worldserver.field_816_A = false;
  55. worldserver.func_485_a(true, null);
  56. worldserver.field_816_A = flag;
  57. }
  58. func_22115_a(s3, "Save complete.");
  59. } else
  60. if(s1.equalsIgnoreCase("save-off"))
  61. {
  62. func_22115_a(s3, "Disabling level saving..");
  63. for(int j = 0; j < field_22116_b.field_6034_e.length; j++)
  64. {
  65. WorldServer worldserver1 = field_22116_b.field_6034_e[j];
  66. worldserver1.field_816_A = true;
  67. }
  68. } else
  69. if(s1.equalsIgnoreCase("save-on"))
  70. {
  71. func_22115_a(s3, "Enabling level saving..");
  72. for(int k = 0; k < field_22116_b.field_6034_e.length; k++)
  73. {
  74. WorldServer worldserver2 = field_22116_b.field_6034_e[k];
  75. worldserver2.field_816_A = false;
  76. }
  77. } else
  78. if(s1.equalsIgnoreCase("op"))
  79. {
  80. serverconfigurationmanager.func_35479_e(s2);
  81. func_22115_a(s3, (new StringBuilder()).append("Opping ").append(s2).toString());
  82. serverconfigurationmanager.func_628_a(s2, "\247eYou are now op!");
  83. } else
  84. if(s1.equalsIgnoreCase("deop"))
  85. {
  86. String s4 = s2;
  87. serverconfigurationmanager.func_35478_f(s4);
  88. serverconfigurationmanager.func_628_a(s4, "\247eYou are no longer op!");
  89. func_22115_a(s3, (new StringBuilder()).append("De-opping ").append(s4).toString());
  90. } else
  91. if(s1.equalsIgnoreCase("ban-ip"))
  92. {
  93. String s5 = s2;
  94. serverconfigurationmanager.func_22162_c(s5);
  95. func_22115_a(s3, (new StringBuilder()).append("Banning ip ").append(s5).toString());
  96. } else
  97. if(s1.equalsIgnoreCase("pardon-ip"))
  98. {
  99. String s6 = s2;
  100. serverconfigurationmanager.func_22163_d(s6);
  101. func_22115_a(s3, (new StringBuilder()).append("Pardoning ip ").append(s6).toString());
  102. } else
  103. if(s1.equalsIgnoreCase("ban"))
  104. {
  105. String s7 = s2;
  106. serverconfigurationmanager.func_22159_a(s7);
  107. func_22115_a(s3, (new StringBuilder()).append("Banning ").append(s7).toString());
  108. EntityPlayerMP entityplayermp1 = serverconfigurationmanager.func_620_h(s7);
  109. if(entityplayermp1 != null)
  110. {
  111. entityplayermp1.field_20908_a.func_43_c("Banned by admin");
  112. }
  113. } else
  114. if(s1.equalsIgnoreCase("pardon"))
  115. {
  116. String s8 = s2;
  117. serverconfigurationmanager.func_22161_b(s8);
  118. func_22115_a(s3, (new StringBuilder()).append("Pardoning ").append(s8).toString());
  119. } else
  120. if(s1.equalsIgnoreCase("kick"))
  121. {
  122. String s9 = s2;
  123. EntityPlayerMP entityplayermp2 = null;
  124. for(int i1 = 0; i1 < serverconfigurationmanager.field_924_b.size(); i1++)
  125. {
  126. EntityPlayerMP entityplayermp7 = (EntityPlayerMP)serverconfigurationmanager.field_924_b.get(i1);
  127. if(entityplayermp7.field_409_aq.equalsIgnoreCase(s9))
  128. {
  129. entityplayermp2 = entityplayermp7;
  130. }
  131. }
  132. if(entityplayermp2 != null)
  133. {
  134. entityplayermp2.field_20908_a.func_43_c("Kicked by admin");
  135. func_22115_a(s3, (new StringBuilder()).append("Kicking ").append(entityplayermp2.field_409_aq).toString());
  136. } else
  137. {
  138. icommandlistener.func_2_b((new StringBuilder()).append("Can't find user ").append(s9).append(". No kick.").toString());
  139. }
  140. } else
  141. if(s1.equalsIgnoreCase("tp"))
  142. {
  143. if(as.length == 3)
  144. {
  145. EntityPlayerMP entityplayermp = serverconfigurationmanager.func_620_h(as[1]);
  146. EntityPlayerMP entityplayermp3 = serverconfigurationmanager.func_620_h(as[2]);
  147. if(entityplayermp == null)
  148. {
  149. icommandlistener.func_2_b((new StringBuilder()).append("Can't find user ").append(as[1]).append(". No tp.").toString());
  150. } else
  151. if(entityplayermp3 == null)
  152. {
  153. icommandlistener.func_2_b((new StringBuilder()).append("Can't find user ").append(as[2]).append(". No tp.").toString());
  154. } else
  155. if(entityplayermp.field_4110_as != entityplayermp3.field_4110_as)
  156. {
  157. icommandlistener.func_2_b((new StringBuilder()).append("User ").append(as[1]).append(" and ").append(as[2]).append(" are in different dimensions. No tp.").toString());
  158. } else
  159. {
  160. entityplayermp.field_20908_a.func_41_a(entityplayermp3.field_322_l, entityplayermp3.field_321_m, entityplayermp3.field_320_n, entityplayermp3.field_316_r, entityplayermp3.field_315_s);
  161. func_22115_a(s3, (new StringBuilder()).append("Teleporting ").append(as[1]).append(" to ").append(as[2]).append(".").toString());
  162. }
  163. } else
  164. {
  165. icommandlistener.func_2_b("Syntax error, please provide a source and a target.");
  166. }
  167. } else
  168. if(s1.equalsIgnoreCase("give"))
  169. {
  170. if(as.length != 3 && as.length != 4 && as.length != 5)
  171. {
  172. return;
  173. }
  174. String s10 = as[1];
  175. EntityPlayerMP entityplayermp4 = serverconfigurationmanager.func_620_h(s10);
  176. if(entityplayermp4 != null)
  177. {
  178. try
  179. {
  180. int j1 = Integer.parseInt(as[2]);
  181. if(Item.field_176_c[j1] != null)
  182. {
  183. func_22115_a(s3, (new StringBuilder()).append("Giving ").append(entityplayermp4.field_409_aq).append(" some ").append(j1).toString());
  184. int k2 = 1;
  185. int l2 = 0;
  186. if(as.length > 3)
  187. {
  188. k2 = func_22112_a(as[3], 1);
  189. }
  190. if(as.length > 4)
  191. {
  192. l2 = func_22112_a(as[4], 1);
  193. }
  194. if(k2 < 1)
  195. {
  196. k2 = 1;
  197. }
  198. if(k2 > 64)
  199. {
  200. k2 = 64;
  201. }
  202. entityplayermp4.func_48348_b(new ItemStack(j1, k2, l2));
  203. } else
  204. {
  205. icommandlistener.func_2_b((new StringBuilder()).append("There's no item with id ").append(j1).toString());
  206. }
  207. }
  208. catch(NumberFormatException numberformatexception1)
  209. {
  210. icommandlistener.func_2_b((new StringBuilder()).append("There's no item with id ").append(as[2]).toString());
  211. }
  212. } else
  213. {
  214. icommandlistener.func_2_b((new StringBuilder()).append("Can't find user ").append(s10).toString());
  215. }
  216. } else
  217. if(s1.equalsIgnoreCase("xp"))
  218. {
  219. if(as.length != 3)
  220. {
  221. return;
  222. }
  223. String s11 = as[1];
  224. EntityPlayerMP entityplayermp5 = serverconfigurationmanager.func_620_h(s11);
  225. if(entityplayermp5 != null)
  226. {
  227. try
  228. {
  229. int k1 = Integer.parseInt(as[2]);
  230. k1 = k1 <= 5000 ? k1 : 5000;
  231. func_22115_a(s3, (new StringBuilder()).append("Giving ").append(k1).append(" orbs to ").append(entityplayermp5.field_409_aq).toString());
  232. entityplayermp5.func_35195_d(k1);
  233. }
  234. catch(NumberFormatException numberformatexception2)
  235. {
  236. icommandlistener.func_2_b((new StringBuilder()).append("Invalid orb count: ").append(as[2]).toString());
  237. }
  238. } else
  239. {
  240. icommandlistener.func_2_b((new StringBuilder()).append("Can't find user ").append(s11).toString());
  241. }
  242. } else
  243. if(s1.equalsIgnoreCase("gamemode"))
  244. {
  245. if(as.length != 3)
  246. {
  247. return;
  248. }
  249. String s12 = as[1];
  250. EntityPlayerMP entityplayermp6 = serverconfigurationmanager.func_620_h(s12);
  251. if(entityplayermp6 != null)
  252. {
  253. try
  254. {
  255. int l1 = Integer.parseInt(as[2]);
  256. l1 = WorldSettings.func_35037_a(l1);
  257. if(entityplayermp6.field_425_ad.func_35697_a() != l1)
  258. {
  259. func_22115_a(s3, (new StringBuilder()).append("Setting ").append(entityplayermp6.field_409_aq).append(" to game mode ").append(l1).toString());
  260. entityplayermp6.field_425_ad.func_35696_a(l1);
  261. entityplayermp6.field_20908_a.func_39_b(new Packet70Bed(3, l1));
  262. } else
  263. {
  264. func_22115_a(s3, (new StringBuilder()).append(entityplayermp6.field_409_aq).append(" already has game mode ").append(l1).toString());
  265. }
  266. }
  267. catch(NumberFormatException numberformatexception3)
  268. {
  269. icommandlistener.func_2_b((new StringBuilder()).append("There's no game mode with id ").append(as[2]).toString());
  270. }
  271. } else
  272. {
  273. icommandlistener.func_2_b((new StringBuilder()).append("Can't find user ").append(s12).toString());
  274. }
  275. } else
  276. if(s1.equalsIgnoreCase("time"))
  277. {
  278. if(as.length != 3)
  279. {
  280. return;
  281. }
  282. String s13 = as[1];
  283. try
  284. {
  285. int l = Integer.parseInt(as[2]);
  286. if("add".equalsIgnoreCase(s13))
  287. {
  288. for(int i2 = 0; i2 < field_22116_b.field_6034_e.length; i2++)
  289. {
  290. WorldServer worldserver3 = field_22116_b.field_6034_e[i2];
  291. worldserver3.func_32005_b(worldserver3.func_22080_k() + (long)l);
  292. }
  293. func_22115_a(s3, (new StringBuilder()).append("Added ").append(l).append(" to time").toString());
  294. } else
  295. if("set".equalsIgnoreCase(s13))
  296. {
  297. for(int j2 = 0; j2 < field_22116_b.field_6034_e.length; j2++)
  298. {
  299. WorldServer worldserver4 = field_22116_b.field_6034_e[j2];
  300. worldserver4.func_32005_b(l);
  301. }
  302. func_22115_a(s3, (new StringBuilder()).append("Set time to ").append(l).toString());
  303. } else
  304. {
  305. icommandlistener.func_2_b("Unknown method, use either \"add\" or \"set\"");
  306. }
  307. }
  308. catch(NumberFormatException numberformatexception)
  309. {
  310. icommandlistener.func_2_b((new StringBuilder()).append("Unable to convert time value, ").append(as[2]).toString());
  311. }
  312. } else
  313. if(s1.equalsIgnoreCase("say") && s2.length() > 0)
  314. {
  315. field_22117_a.info((new StringBuilder()).append("[").append(s3).append("] ").append(s2).toString());
  316. serverconfigurationmanager.func_631_a(new Packet3Chat((new StringBuilder()).append("\247d[Server] ").append(s2).toString()));
  317. } else
  318. if(s1.equalsIgnoreCase("tell"))
  319. {
  320. if(as.length >= 3)
  321. {
  322. s = s.substring(s.indexOf(" ")).trim();
  323. s = s.substring(s.indexOf(" ")).trim();
  324. field_22117_a.info((new StringBuilder()).append("[").append(s3).append("->").append(as[1]).append("] ").append(s).toString());
  325. s = (new StringBuilder()).append("\2477").append(s3).append(" whispers ").append(s).toString();
  326. field_22117_a.info(s);
  327. if(!serverconfigurationmanager.func_621_a(as[1], new Packet3Chat(s)))
  328. {
  329. icommandlistener.func_2_b("There's no player by that name online.");
  330. }
  331. }
  332. } else
  333. if(s1.equalsIgnoreCase("whitelist"))
  334. {
  335. func_22113_a(s3, s, icommandlistener);
  336. } else
  337. if(s1.equalsIgnoreCase("toggledownfall"))
  338. {
  339. field_22116_b.field_6034_e[0].func_40218_j();
  340. icommandlistener.func_2_b("Toggling rain and snow, hold on...");
  341. } else
  342. if(s1.equalsIgnoreCase("banlist"))
  343. {
  344. if(as.length == 2)
  345. {
  346. if(as[1].equals("ips"))
  347. {
  348. icommandlistener.func_2_b((new StringBuilder()).append("IP Ban list:").append(func_40648_a(field_22116_b.func_40026_q(), ", ")).toString());
  349. }
  350. } else
  351. {
  352. icommandlistener.func_2_b((new StringBuilder()).append("Ban list:").append(func_40648_a(field_22116_b.func_40025_r(), ", ")).toString());
  353. }
  354. } else
  355. {
  356. field_22117_a.info("Unknown console command. Type \"help\" for help.");
  357. }
  358. }
  359. private void func_22113_a(String p_22113_1_, String p_22113_2_, ICommandListener p_22113_3_)
  360. {
  361. String as[] = p_22113_2_.split(" ");
  362. if(as.length < 2)
  363. {
  364. return;
  365. }
  366. String s = as[1].toLowerCase();
  367. if("on".equals(s))
  368. {
  369. func_22115_a(p_22113_1_, "Turned on white-listing");
  370. field_22116_b.field_6035_d.func_22118_b("white-list", true);
  371. } else
  372. if("off".equals(s))
  373. {
  374. func_22115_a(p_22113_1_, "Turned off white-listing");
  375. field_22116_b.field_6035_d.func_22118_b("white-list", false);
  376. } else
  377. if("list".equals(s))
  378. {
  379. Set set = field_22116_b.field_6033_f.func_22167_e();
  380. String s3 = "";
  381. for(Iterator iterator = set.iterator(); iterator.hasNext();)
  382. {
  383. String s4 = (String)iterator.next();
  384. s3 = (new StringBuilder()).append(s3).append(s4).append(" ").toString();
  385. }
  386. p_22113_3_.func_2_b((new StringBuilder()).append("White-listed players: ").append(s3).toString());
  387. } else
  388. if("add".equals(s) && as.length == 3)
  389. {
  390. String s1 = as[2].toLowerCase();
  391. field_22116_b.field_6033_f.func_22169_k(s1);
  392. func_22115_a(p_22113_1_, (new StringBuilder()).append("Added ").append(s1).append(" to white-list").toString());
  393. } else
  394. if("remove".equals(s) && as.length == 3)
  395. {
  396. String s2 = as[2].toLowerCase();
  397. field_22116_b.field_6033_f.func_22170_l(s2);
  398. func_22115_a(p_22113_1_, (new StringBuilder()).append("Removed ").append(s2).append(" from white-list").toString());
  399. } else
  400. if("reload".equals(s))
  401. {
  402. field_22116_b.field_6033_f.func_22171_f();
  403. func_22115_a(p_22113_1_, "Reloaded white-list from file");
  404. }
  405. }
  406. private void func_22111_a(ICommandListener p_22111_1_)
  407. {
  408. p_22111_1_.func_2_b("To run the server without a gui, start it like this:");
  409. p_22111_1_.func_2_b(" java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui");
  410. p_22111_1_.func_2_b("Console commands:");
  411. p_22111_1_.func_2_b(" help or ? shows this message");
  412. p_22111_1_.func_2_b(" kick <player> removes a player from the server");
  413. p_22111_1_.func_2_b(" ban <player> bans a player from the server");
  414. p_22111_1_.func_2_b(" pardon <player> pardons a banned player so that they can connect again");
  415. p_22111_1_.func_2_b(" ban-ip <ip> bans an IP address from the server");
  416. p_22111_1_.func_2_b(" pardon-ip <ip> pardons a banned IP address so that they can connect again");
  417. p_22111_1_.func_2_b(" op <player> turns a player into an op");
  418. p_22111_1_.func_2_b(" deop <player> removes op status from a player");
  419. p_22111_1_.func_2_b(" tp <player1> <player2> moves one player to the same location as another player");
  420. p_22111_1_.func_2_b(" give <player> <id> [num] gives a player a resource");
  421. p_22111_1_.func_2_b(" tell <player> <message> sends a private message to a player");
  422. p_22111_1_.func_2_b(" stop gracefully stops the server");
  423. p_22111_1_.func_2_b(" save-all forces a server-wide level save");
  424. p_22111_1_.func_2_b(" save-off disables terrain saving (useful for backup scripts)");
  425. p_22111_1_.func_2_b(" save-on re-enables terrain saving");
  426. p_22111_1_.func_2_b(" list lists all currently connected players");
  427. p_22111_1_.func_2_b(" say <message> broadcasts a message to all players");
  428. p_22111_1_.func_2_b(" time <add|set> <amount> adds to or sets the world time (0-24000)");
  429. p_22111_1_.func_2_b(" gamemode <player> <mode> sets player's game mode (0 or 1)");
  430. p_22111_1_.func_2_b(" toggledownfall toggles rain on or off");
  431. p_22111_1_.func_2_b(" xp <player> <amount> gives the player the amount of xp (0-5000)");
  432. }
  433. private void func_22115_a(String p_22115_1_, String p_22115_2_)
  434. {
  435. String s = (new StringBuilder()).append(p_22115_1_).append(": ").append(p_22115_2_).toString();
  436. field_22116_b.field_6033_f.func_630_i((new StringBuilder()).append("\2477(").append(s).append(")").toString());
  437. field_22117_a.info(s);
  438. }
  439. private int func_22112_a(String p_22112_1_, int p_22112_2_)
  440. {
  441. try
  442. {
  443. return Integer.parseInt(p_22112_1_);
  444. }
  445. catch(NumberFormatException numberformatexception)
  446. {
  447. return p_22112_2_;
  448. }
  449. }
  450. private String func_40648_a(String p_40648_1_[], String p_40648_2_)
  451. {
  452. int i = p_40648_1_.length;
  453. if(0 == i)
  454. {
  455. return "";
  456. }
  457. StringBuilder stringbuilder = new StringBuilder();
  458. stringbuilder.append(p_40648_1_[0]);
  459. for(int j = 1; j < i; j++)
  460. {
  461. stringbuilder.append(p_40648_2_).append(p_40648_1_[j]);
  462. }
  463. return stringbuilder.toString();
  464. }
  465. }