CommandPlot.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. package me.km.plots;
  2. import com.mojang.authlib.GameProfile;
  3. import java.util.HashMap;
  4. import java.util.UUID;
  5. import me.km.KajetansMod;
  6. import me.km.api.GlobalText;
  7. import me.km.api.Module;
  8. import me.km.api.ModuleCommand;
  9. import me.km.api.Utils;
  10. import me.km.chatmanager.ChatManager;
  11. import me.km.dimensions.ModDimensions;
  12. import me.km.permissions.Permissions;
  13. import me.km.playerbank.PlayerBank;
  14. import me.km.utils.SpecialBlockUtils;
  15. import net.minecraft.block.Block;
  16. import net.minecraft.command.ICommandSender;
  17. import net.minecraft.entity.player.EntityPlayer;
  18. import net.minecraft.init.Blocks;
  19. import net.minecraft.tileentity.TileEntitySign;
  20. import net.minecraft.util.math.BlockPos;
  21. import net.minecraft.world.World;
  22. public class CommandPlot extends ModuleCommand
  23. {
  24. public final HashMap<UUID, BlockPos> coord1;
  25. public final HashMap<UUID, BlockPos> coord2;
  26. private final ProtectionBank bank;
  27. public CommandPlot(Module m)
  28. {
  29. super("plot", m);
  30. super.setDescription("Zeigt alles für die Plot-Verwaltung");
  31. super.setUsage("/plot für die Hilfe");
  32. super.setPermission(Permissions.PLOT);
  33. super.addAlias("p");
  34. super.addAlias("pl");
  35. super.addAlias("plo");
  36. coord1 = new HashMap<>();
  37. coord2 = new HashMap<>();
  38. bank = KajetansMod.plots.getDataBank(ProtectionBank.class);
  39. }
  40. @Override
  41. public boolean execute(ICommandSender cs, String[] arg)
  42. {
  43. Module m = this.getModule();
  44. if(arg.length >= 1)
  45. {
  46. // Abkürzungen
  47. switch(arg[0].toLowerCase())
  48. {
  49. case "a":
  50. case "c":
  51. case "create":
  52. case "add":
  53. {
  54. if(!KajetansMod.perms.has(cs, Permissions.PLOT_CREATE))
  55. {
  56. break;
  57. }
  58. if(!(cs instanceof EntityPlayer))
  59. {
  60. this.getModule().send(cs, GlobalText.onlyPlayer());
  61. return true;
  62. }
  63. EntityPlayer p = (EntityPlayer) cs;
  64. if(coord1.containsKey(p.getUniqueID()) && coord2.containsKey(p.getUniqueID()))
  65. {
  66. BlockPos l1 = coord1.get(p.getUniqueID());
  67. BlockPos l2 = coord2.get(p.getUniqueID());
  68. bank.addPlot(Math.min(l1.getX(), l2.getX()),
  69. 30,
  70. Math.min(l1.getZ(), l2.getZ()),
  71. Math.max(l1.getX(), l2.getX()),
  72. 255,
  73. Math.max(l1.getZ(), l2.getZ()),
  74. ModDimensions.getWorldName(p.world), p, arg.length >= 2 ? arg[1] : null);
  75. return true;
  76. }
  77. m.send(cs, "Du musst zwei Punkte wählen. (Holzschwert + Creative)");
  78. return true;
  79. }
  80. case "create3d":
  81. case "add3d":
  82. {
  83. if(!KajetansMod.perms.has(cs, Permissions.PLOT_CREATE))
  84. {
  85. break;
  86. }
  87. if(!(cs instanceof EntityPlayer))
  88. {
  89. this.getModule().send(cs, GlobalText.onlyPlayer());
  90. return true;
  91. }
  92. EntityPlayer p = (EntityPlayer) cs;
  93. if(coord1.containsKey(p.getUniqueID()) && coord2.containsKey(p.getUniqueID()))
  94. {
  95. BlockPos l1 = coord1.get(p.getUniqueID());
  96. BlockPos l2 = coord2.get(p.getUniqueID());
  97. bank.addPlot(Math.min(l1.getX(), l2.getX()),
  98. Math.min(l1.getY(), l2.getY()),
  99. Math.min(l1.getZ(), l2.getZ()),
  100. Math.max(l1.getX(), l2.getX()),
  101. Math.max(l1.getY(), l2.getY()),
  102. Math.max(l1.getZ(), l2.getZ()),
  103. ModDimensions.getWorldName(p.world), p, arg.length >= 2 ? arg[1] : null);
  104. return true;
  105. }
  106. m.send(cs, "Du musst zwei Punkte wählen. (Holzschwert + Creative)");
  107. return true;
  108. }
  109. case "e":
  110. case "expand":
  111. {
  112. if(!KajetansMod.perms.has(cs, Permissions.PLOT_CREATE) || arg.length < 2)
  113. {
  114. break;
  115. }
  116. if(!(cs instanceof EntityPlayer))
  117. {
  118. this.getModule().send(cs, GlobalText.onlyPlayer());
  119. return true;
  120. }
  121. EntityPlayer p = (EntityPlayer) cs;
  122. if(coord1.containsKey(p.getUniqueID()) && coord2.containsKey(p.getUniqueID()))
  123. {
  124. UUID uuid = p.getUniqueID();
  125. BlockPos l1 = coord1.get(uuid);
  126. BlockPos l2 = coord2.get(uuid);
  127. int x1 = l1.getX();
  128. int y1 = l1.getY();
  129. int z1 = l1.getZ();
  130. int x2 = l2.getX();
  131. int y2 = l2.getY();
  132. int z2 = l2.getZ();
  133. int helper;
  134. if(x1 > x2)
  135. {
  136. helper = x1;
  137. x1 = x2;
  138. x2 = helper;
  139. }
  140. if(y1 > y2)
  141. {
  142. helper = y1;
  143. y1 = y2;
  144. y2 = helper;
  145. }
  146. if(z1 > z2)
  147. {
  148. helper = z1;
  149. z1 = z2;
  150. z2 = helper;
  151. }
  152. float yaw = p.rotationYaw;
  153. float pitch = p.rotationPitch;
  154. int expandRate;
  155. try
  156. {
  157. expandRate = Integer.parseInt(arg[1]);
  158. if(expandRate <= 0)
  159. {
  160. throw new NumberFormatException();
  161. }
  162. }
  163. catch(NumberFormatException ex)
  164. {
  165. m.send(cs, GlobalText.noPositiveNaturalNumber());
  166. return true;
  167. }
  168. String richtung = "FEHLER";
  169. if(pitch >= 75)
  170. {
  171. y1 -= expandRate;
  172. if( y1 < 0)
  173. {
  174. y1 = 0;
  175. }
  176. richtung = "unten";
  177. }
  178. else if(pitch <= -75)
  179. {
  180. y2 += expandRate;
  181. if(y2 > 255)
  182. {
  183. y2 = 255;
  184. }
  185. richtung = "oben";
  186. }
  187. else if(yaw >= 45 && yaw < 135)
  188. {
  189. x1 -= expandRate;
  190. richtung = "Westen";
  191. }
  192. else if(yaw >= 135 && yaw < 225)
  193. {
  194. z1 -= expandRate;
  195. richtung = "Norden";
  196. }
  197. else if(yaw >= 225 && yaw < 315)
  198. {
  199. x2 += expandRate;
  200. richtung = "Osten";
  201. }
  202. else if(yaw >= 315 || yaw < 45)
  203. {
  204. z2 += expandRate;
  205. richtung = "Süden";
  206. }
  207. coord1.put(uuid, new BlockPos(x1, y1, z1));
  208. coord2.put(uuid, new BlockPos(x2, y2, z2));
  209. m.send(cs, "Der Plot wurde um " + expandRate + " nach " + richtung + " erweitert.");
  210. return true;
  211. }
  212. m.send(cs, "Du musst zwei Punkte wählen. (Holzschwert + Creative)");
  213. return true;
  214. }
  215. case "name":
  216. {
  217. if(!KajetansMod.perms.has(cs, Permissions.PLOT_CREATE) || arg.length < 2)
  218. {
  219. break;
  220. }
  221. int id;
  222. try
  223. {
  224. id = Integer.parseInt(arg[1]);
  225. if(id < 0)
  226. {
  227. m.send(cs, GlobalText.noNaturalNumber());
  228. return true;
  229. }
  230. bank.changeName(id, ChatManager.colorMessage(Utils.connectSpaces(arg, 2), cs), cs);
  231. }
  232. catch(NumberFormatException ex)
  233. {
  234. if(!(cs instanceof EntityPlayer))
  235. {
  236. this.getModule().send(cs, GlobalText.missingParameter());
  237. return true;
  238. }
  239. EntityPlayer p = (EntityPlayer) cs;
  240. bank.changeName(bank.getFirstRegionId(p), ChatManager.colorMessage(Utils.connectSpaces(arg, 1), p), p);
  241. }
  242. return true;
  243. }
  244. case "i":
  245. case "info":
  246. {
  247. if(KajetansMod.perms.has(cs, Permissions.PLOT_INFO))
  248. {
  249. if(!(cs instanceof EntityPlayer))
  250. {
  251. this.getModule().send(cs, GlobalText.onlyPlayer());
  252. return true;
  253. }
  254. EntityPlayer p = (EntityPlayer) cs;
  255. bank.printInfo(p);
  256. return true;
  257. }
  258. break;
  259. }
  260. case "r":
  261. case "remove":
  262. case "delete":
  263. {
  264. if(KajetansMod.perms.has(cs, Permissions.PLOT_CREATE))
  265. {
  266. Integer id;
  267. if(arg.length >= 2)
  268. {
  269. try
  270. {
  271. id = Integer.parseInt(arg[1]);
  272. if(id < 0)
  273. {
  274. throw new NumberFormatException();
  275. }
  276. }
  277. catch(NumberFormatException ex)
  278. {
  279. m.send(cs, GlobalText.noNaturalNumber());
  280. return true;
  281. }
  282. }
  283. else
  284. {
  285. if(!(cs instanceof EntityPlayer))
  286. {
  287. this.getModule().send(cs, GlobalText.missingParameter());
  288. return true;
  289. }
  290. EntityPlayer p = (EntityPlayer) cs;
  291. id = bank.getFirstRegionId(p);
  292. }
  293. bank.removePlot(id, cs);
  294. return true;
  295. }
  296. break;
  297. }
  298. case "at":
  299. case "addtag":
  300. {
  301. if(KajetansMod.perms.has(cs, Permissions.PLOT_TAG) && arg.length >= 2)
  302. {
  303. Integer id;
  304. if(arg.length >= 3)
  305. {
  306. try
  307. {
  308. id = Integer.parseInt(arg[2]);
  309. if(id < 0)
  310. {
  311. throw new NumberFormatException();
  312. }
  313. }
  314. catch(NumberFormatException ex)
  315. {
  316. m.send(cs, GlobalText.noNaturalNumber());
  317. return true;
  318. }
  319. }
  320. else
  321. {
  322. if(!(cs instanceof EntityPlayer))
  323. {
  324. this.getModule().send(cs, GlobalText.missingParameter());
  325. return true;
  326. }
  327. EntityPlayer p = (EntityPlayer) cs;
  328. id = bank.getFirstRegionId(p);
  329. }
  330. bank.addTag(id, arg[1], cs);
  331. return true;
  332. }
  333. break;
  334. }
  335. case "rt":
  336. case "removetag":
  337. {
  338. if(KajetansMod.perms.has(cs, Permissions.PLOT_TAG) && arg.length >= 2)
  339. {
  340. Integer id;
  341. if(arg.length >= 3)
  342. {
  343. try
  344. {
  345. id = Integer.parseInt(arg[2]);
  346. if(id < 0)
  347. {
  348. throw new NumberFormatException();
  349. }
  350. }
  351. catch(NumberFormatException ex)
  352. {
  353. m.send(cs, GlobalText.noNaturalNumber());
  354. return true;
  355. }
  356. }
  357. else
  358. {
  359. if(!(cs instanceof EntityPlayer))
  360. {
  361. this.getModule().send(cs, GlobalText.missingParameter());
  362. return true;
  363. }
  364. EntityPlayer p = (EntityPlayer) cs;
  365. id = bank.getFirstRegionId(p);
  366. }
  367. bank.removeTag(id, arg[1], cs);
  368. return true;
  369. }
  370. break;
  371. }
  372. case "share":
  373. {
  374. if(KajetansMod.perms.has(cs, Permissions.PLOT_SHARE) && arg.length >= 2)
  375. {
  376. Integer id;
  377. if(arg.length >= 3)
  378. {
  379. try
  380. {
  381. id = Integer.parseInt(arg[2]);
  382. if(id < 0)
  383. {
  384. throw new NumberFormatException();
  385. }
  386. }
  387. catch(NumberFormatException ex)
  388. {
  389. m.send(cs, GlobalText.noNaturalNumber());
  390. return true;
  391. }
  392. }
  393. else
  394. {
  395. if(!(cs instanceof EntityPlayer))
  396. {
  397. this.getModule().send(cs, GlobalText.missingParameter());
  398. return true;
  399. }
  400. EntityPlayer p = (EntityPlayer) cs;
  401. id = bank.getFirstRegionId(p);
  402. }
  403. GameProfile player = KajetansMod.playerbank.getDataBank().getOfflinePlayer(arg[1]);
  404. if(player == null)
  405. {
  406. m.send(cs, GlobalText.cantFindPlayer(arg[1]));
  407. return true;
  408. }
  409. bank.addPlayer(id, player, cs);
  410. return true;
  411. }
  412. break;
  413. }
  414. case "kick":
  415. {
  416. if(KajetansMod.perms.has(cs, Permissions.PLOT_SHARE) && arg.length >= 2)
  417. {
  418. Integer id;
  419. if(arg.length >= 3)
  420. {
  421. try
  422. {
  423. id = Integer.parseInt(arg[2]);
  424. if(id < 0)
  425. {
  426. throw new NumberFormatException();
  427. }
  428. }
  429. catch(NumberFormatException ex)
  430. {
  431. m.send(cs, GlobalText.noNaturalNumber());
  432. return true;
  433. }
  434. }
  435. else
  436. {
  437. if(!(cs instanceof EntityPlayer))
  438. {
  439. this.getModule().send(cs, GlobalText.missingParameter());
  440. return true;
  441. }
  442. EntityPlayer p = (EntityPlayer) cs;
  443. id = bank.getFirstRegionId(p);
  444. }
  445. GameProfile player = KajetansMod.playerbank.getDataBank(PlayerBank.class).getOfflinePlayer(arg[1]);
  446. if(player == null)
  447. {
  448. m.send(cs, GlobalText.cantFindPlayer(arg[1]));
  449. return true;
  450. }
  451. bank.removePlayer(id, player, cs);
  452. return true;
  453. }
  454. break;
  455. }
  456. case "sign":
  457. {
  458. if(KajetansMod.perms.has(cs, Permissions.PLOT_SIGN) && arg.length >= 3)
  459. {
  460. if(!(cs instanceof EntityPlayer))
  461. {
  462. this.getModule().send(cs, GlobalText.onlyPlayer());
  463. return true;
  464. }
  465. EntityPlayer p = (EntityPlayer) cs;
  466. World w = p.world;
  467. BlockPos pos = Utils.getPlayerTarget(p, 20, true);
  468. Block b = w.getBlockState(pos).getBlock();
  469. if(b == Blocks.STANDING_SIGN || b == Blocks.WALL_SIGN)
  470. {
  471. TileEntitySign sign = (TileEntitySign) w.getTileEntity(pos);
  472. if(sign == null)
  473. {
  474. this.getModule().send(cs, GlobalText.shouldNotHappen());
  475. return true;
  476. }
  477. int i;
  478. try
  479. {
  480. i = Integer.parseInt(arg[1]);
  481. if(i < 0)
  482. {
  483. throw new NumberFormatException();
  484. }
  485. }
  486. catch(NumberFormatException ex)
  487. {
  488. m.send(cs, GlobalText.cantFindPlayer(GlobalText.noNaturalNumber()));
  489. return true;
  490. }
  491. try
  492. {
  493. int id = Integer.parseInt(arg[2]);
  494. if(id < 0)
  495. {
  496. throw new NumberFormatException();
  497. }
  498. if(!bank.doesPlotExist(id))
  499. {
  500. m.send(p, "Der Plot mit der ID '" + id + "' ist nicht vorhanden.");
  501. return true;
  502. }
  503. SpecialBlockUtils.setSignLine(sign, 0, "§0[§6Plot§0]", false);
  504. SpecialBlockUtils.setSignLine(sign, 1, "§2" + arg[1] + " Emeralds", false);
  505. SpecialBlockUtils.setSignLine(sign, 1, arg[2], true);
  506. return true;
  507. }
  508. catch(NumberFormatException ex)
  509. {
  510. m.send(cs, GlobalText.noNaturalNumber());
  511. return true;
  512. }
  513. }
  514. m.send(cs, "Du bist nicht auf ein Schild gerichtet.");
  515. return true;
  516. }
  517. break;
  518. }
  519. }
  520. }
  521. // Help Menu
  522. m.send(cs, "/plot ...");
  523. if(KajetansMod.perms.has(cs, Permissions.PLOT_INFO))
  524. {
  525. m.sendHelpListElement(cs, "info", "Gibt Infos über die aktuelle Position");
  526. }
  527. if(KajetansMod.perms.has(cs, Permissions.PLOT_CREATE))
  528. {
  529. m.sendHelpListElement(cs, "create [player]", "Erstellt ein Plot (30 - 255)");
  530. m.sendHelpListElement(cs, "create3D [player]", "Erstellt ein Plot");
  531. m.sendHelpListElement(cs, "remove [id]", "Entfernt ein Plot");
  532. m.sendHelpListElement(cs, "expand <blocks>", "Erweitert die aktuelle Auswahl");
  533. m.sendHelpListElement(cs, "name [id] <name>", "Gibt einem Plot einen Namen");
  534. }
  535. if(KajetansMod.perms.has(cs, Permissions.PLOT_TAG))
  536. {
  537. m.sendHelpListElement(cs, "addtag <tag> [id]", "Fügt einen Tag hinzu");
  538. m.sendHelpListElement(cs, "removetag <tag> [id]", "Entfernt einen Tag");
  539. }
  540. if(KajetansMod.perms.has(cs, Permissions.PLOT_SHARE))
  541. {
  542. m.sendHelpListElement(cs, "share <player> [id]", "Fügt einen Spieler hinzu");
  543. m.sendHelpListElement(cs, "kick <player> [id]", "Entfernt einen Spieler");
  544. }
  545. if(KajetansMod.perms.has(cs, Permissions.PLOT_SIGN))
  546. {
  547. m.sendHelpListElement(cs, "sign <price> <id>", "Ändert ein Schild zum Verkaufsschild");
  548. }
  549. return true;
  550. }
  551. }