Advertisement
Guest User

Main class

a guest
Dec 12th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.76 KB | None | 0 0
  1. /*** Eclipse Class Decompiler plugin, copyright (c) 2016 Chen Chao (cnfree2000@hotmail.com) ***/
  2. package me.robifoxx.block;
  3.  
  4. import java.io.File;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.Iterator;
  8. import java.util.List;
  9.  
  10. import me.robifoxx.block.Config;
  11. import me.robifoxx.block.MySQL;
  12. import me.robifoxx.block.SQLPlayer;
  13.  
  14. import org.bukkit.Bukkit;
  15. import org.bukkit.command.Command;
  16. import org.bukkit.command.CommandSender;
  17. import org.bukkit.entity.Player;
  18. import org.bukkit.event.EventHandler;
  19. import org.bukkit.event.Listener;
  20. import org.bukkit.event.block.Action;
  21. import org.bukkit.event.player.PlayerInteractEvent;
  22. import org.bukkit.event.player.PlayerJoinEvent;
  23. import org.bukkit.event.player.PlayerQuitEvent;
  24. import org.bukkit.inventory.EquipmentSlot;
  25. import org.bukkit.plugin.java.JavaPlugin;
  26. import org.bukkit.scheduler.BukkitScheduler;
  27.  
  28. public class Main extends JavaPlugin implements Listener {
  29. public static MySQL mysql;
  30. ArrayList<String> inEdit = new ArrayList<String>();
  31. HashMap<String, List<String>> blocksss = new HashMap();
  32. HashMap<String, String> saved_x = new HashMap<String, String>();
  33. HashMap<String, String> saved_y = new HashMap<String, String>();
  34. HashMap<String, String> saved_z = new HashMap<String, String>();
  35. HashMap<String, String> saved_world = new HashMap<String, String>();
  36. public Config data;
  37. boolean useMysql = false;
  38. boolean unsafeSave = true;
  39.  
  40. public void onEnable() {
  41. if (!(new File("plugins/BlockQuest/config.yml")).exists()) {
  42. this.getConfig().options().copyDefaults(true);
  43. this.saveConfig();
  44. }
  45.  
  46. Config c = new Config("plugins/BlockQuest", "data.yml");
  47. c.create();
  48. c.setDefault("data.yml");
  49. if (!c.exists()) {
  50. c.getConfig().options().copyDefaults(true);
  51. c.saveConfig();
  52. }
  53.  
  54. this.data = c;
  55. if (this.getConfig().getString("use-mysql").equalsIgnoreCase("true")) {
  56. mysql = new MySQL(this.getConfig().getString("mysql-host"), this
  57. .getConfig().getString("mysql-database"), this.getConfig()
  58. .getString("mysql-username"), this.getConfig().getString(
  59. "mysql-password"));
  60. mysql.update("CREATE TABLE IF NOT EXISTS Games (UUID varchar(128), X varchar(2048) default \"none\", Y varchar(2048) default \"none\", Z varchar(2048) default \"none\", WORLD varchar(2048) default \"none\")");
  61. this.useMysql = true;
  62. }
  63.  
  64. Bukkit.getPluginManager().registerEvents(this, this);
  65. if (this.getConfig().getString("mysql-unsafe-save") != null
  66. && this.getConfig().getString("mysql-unsafe-save")
  67. .equalsIgnoreCase("false")) {
  68. this.unsafeSave = false;
  69. }
  70.  
  71. }
  72.  
  73. public void onDisable() {
  74. Iterator<?> arg0 = Bukkit.getOnlinePlayers().iterator();
  75.  
  76. while (arg0.hasNext()) {
  77. Player pl = (Player) arg0.next();
  78. if (this.useMysql) {
  79. SQLPlayer.setString(pl.getUniqueId().toString(), "X",
  80. (String) this.saved_x.get(pl.getName()));
  81. SQLPlayer.setString(pl.getUniqueId().toString(), "Y",
  82. (String) this.saved_y.get(pl.getName()));
  83. SQLPlayer.setString(pl.getUniqueId().toString(), "Z",
  84. (String) this.saved_z.get(pl.getName()));
  85. SQLPlayer.setString(pl.getUniqueId().toString(), "WORLD",
  86. (String) this.saved_world.get(pl.getName()));
  87. } else {
  88. this.data.getConfig().set(
  89. "data." + pl.getUniqueId().toString() + ".x",
  90. this.saved_x.get(pl.getName()));
  91. this.data.getConfig().set(
  92. "data." + pl.getUniqueId().toString() + ".y",
  93. this.saved_y.get(pl.getName()));
  94. this.data.getConfig().set(
  95. "data." + pl.getUniqueId().toString() + ".z",
  96. this.saved_z.get(pl.getName()));
  97. this.data.getConfig().set(
  98. "data." + pl.getUniqueId().toString() + ".world",
  99. this.saved_world.get(pl.getName()));
  100. this.data.saveConfig();
  101. }
  102. }
  103.  
  104. }
  105.  
  106. public boolean onCommand(CommandSender sender, Command cmd, String label,
  107. String[] args) {
  108. if (cmd.getName().equalsIgnoreCase("blockquest")) {
  109. if (!sender.hasPermission("blockquest.command")) {
  110. sender.sendMessage(this.getConfig().getString("no-permission")
  111. .replace("&", "§"));
  112. return true;
  113. }
  114.  
  115. if (args.length < 1) {
  116. if (this.inEdit.remove(sender.getName())) {
  117. sender.sendMessage("§cYou disabled edit mode.");
  118. } else {
  119. sender.sendMessage("§aYou entered edit mode!");
  120. sender.sendMessage("§aClick on blocks to add it to the config file!");
  121. sender.sendMessage("§aType §6/blockquest §ato exit edit mode.");
  122. sender.sendMessage("§a§lType §6§l/blockquest reload §a§lto reload the config!");
  123. this.inEdit.add(sender.getName());
  124. }
  125. } else if (args[0].equalsIgnoreCase("reload")) {
  126. this.reloadConfig();
  127. sender.sendMessage("§aConfigr reloaded!");
  128. }
  129. }
  130.  
  131. return true;
  132. }
  133.  
  134. @EventHandler
  135. public void join(PlayerJoinEvent e) {
  136. if (this.data.getConfig().get(
  137. "data." + e.getPlayer().getUniqueId().toString() + ".x") == null) {
  138. this.data.getConfig().set(
  139. "data." + e.getPlayer().getUniqueId().toString() + ".x",
  140. "none");
  141. this.data.getConfig().set(
  142. "data." + e.getPlayer().getUniqueId().toString() + ".y",
  143. "none");
  144. this.data.getConfig().set(
  145. "data." + e.getPlayer().getUniqueId().toString() + ".z",
  146. "none");
  147. this.data.getConfig()
  148. .set("data." + e.getPlayer().getUniqueId().toString()
  149. + ".world", "none");
  150. if (!this.data.getConfig().contains(
  151. "data." + e.getPlayer().getUniqueId() + ".finished")) {
  152. this.data.getConfig().set("data." + e.getPlayer().getUniqueId() + ".finished", false);
  153. }
  154. this.data.saveConfig();
  155. }
  156.  
  157. if (this.blocksss.get(e.getPlayer().getName()) == null) {
  158. String x;
  159. String y;
  160. String z;
  161. String world;
  162. if (this.saved_x.get(e.getPlayer().getName()) != null) {
  163. x = (String) this.saved_x.get(e.getPlayer().getName());
  164. y = (String) this.saved_z.get(e.getPlayer().getName());
  165. z = (String) this.saved_y.get(e.getPlayer().getName());
  166. world = (String) this.saved_world.get(e.getPlayer().getName());
  167. } else if (this.useMysql) {
  168. x = SQLPlayer.getString(e.getPlayer().getUniqueId().toString(),
  169. "X");
  170. y = SQLPlayer.getString(e.getPlayer().getUniqueId().toString(),
  171. "Y");
  172. z = SQLPlayer.getString(e.getPlayer().getUniqueId().toString(),
  173. "Z");
  174. world = SQLPlayer.getString(e.getPlayer().getUniqueId()
  175. .toString(), "WORLD");
  176. } else {
  177. x = this.data.getConfig()
  178. .getString(
  179. "data."
  180. + e.getPlayer().getUniqueId()
  181. .toString() + ".x");
  182. y = this.data.getConfig()
  183. .getString(
  184. "data."
  185. + e.getPlayer().getUniqueId()
  186. .toString() + ".y");
  187. z = this.data.getConfig()
  188. .getString(
  189. "data."
  190. + e.getPlayer().getUniqueId()
  191. .toString() + ".z");
  192. world = this.data.getConfig().getString(
  193. "data." + e.getPlayer().getUniqueId().toString()
  194. + ".world");
  195. }
  196.  
  197. this.saved_x.put(e.getPlayer().getName(), x);
  198. this.saved_y.put(e.getPlayer().getName(), y);
  199. this.saved_z.put(e.getPlayer().getName(), z);
  200. this.saved_world.put(e.getPlayer().getName(), world);
  201. String[] x_splt = x.split(";");
  202. String[] y_splt = y.split(";");
  203. String[] z_splt = z.split(";");
  204. String[] world_splt = world.split(";");
  205. int loc = 0;
  206. ArrayList lst = new ArrayList<>();
  207. String[] arg11 = x_splt;
  208. int arg12 = x_splt.length;
  209.  
  210. for (int arg13 = 0; arg13 < arg12; ++arg13) {
  211. String s = arg11[arg13];
  212. if (!s.equalsIgnoreCase("none")) {
  213. lst.add(x_splt[loc] + ";" + y_splt[loc] + ";" + z_splt[loc]
  214. + ";" + world_splt[loc]);
  215. }
  216.  
  217. ++loc;
  218. }
  219.  
  220. this.blocksss.put(e.getPlayer().getName(), lst);
  221. }
  222.  
  223. }
  224.  
  225. @EventHandler
  226. public void leave(PlayerQuitEvent e) {
  227. if (this.useMysql) {
  228. SQLPlayer.setString(e.getPlayer().getUniqueId().toString(), "X",
  229. (String) this.saved_x.get(e.getPlayer().getName()));
  230. SQLPlayer.setString(e.getPlayer().getUniqueId().toString(), "Y",
  231. (String) this.saved_y.get(e.getPlayer().getName()));
  232. SQLPlayer.setString(e.getPlayer().getUniqueId().toString(), "Z",
  233. (String) this.saved_z.get(e.getPlayer().getName()));
  234. SQLPlayer.setString(e.getPlayer().getUniqueId().toString(),
  235. "WORLD",
  236. (String) this.saved_world.get(e.getPlayer().getName()));
  237. } else {
  238. this.data.getConfig().set(
  239. "data." + e.getPlayer().getUniqueId().toString() + ".x",
  240. this.saved_x.get(e.getPlayer().getName()));
  241. this.data.getConfig().set(
  242. "data." + e.getPlayer().getUniqueId().toString() + ".y",
  243. this.saved_y.get(e.getPlayer().getName()));
  244. this.data.getConfig().set(
  245. "data." + e.getPlayer().getUniqueId().toString() + ".z",
  246. this.saved_z.get(e.getPlayer().getName()));
  247. this.data.getConfig()
  248. .set("data." + e.getPlayer().getUniqueId().toString()
  249. + ".world",
  250. this.saved_world.get(e.getPlayer().getName()));
  251. this.data.saveConfig();
  252. }
  253.  
  254. }
  255.  
  256. @EventHandler
  257. public void click(final PlayerInteractEvent e) {
  258. if (e.getHand() != EquipmentSlot.OFF_HAND) {
  259. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
  260. List<String> blocks = this.getConfig().getStringList("blocks");
  261. String block = e.getClickedBlock().getLocation().getBlockX()
  262. + ";"
  263. + e.getClickedBlock().getLocation().getBlockY()
  264. + ";"
  265. + e.getClickedBlock().getLocation().getBlockZ()
  266. + ";"
  267. + e.getClickedBlock().getLocation().getWorld()
  268. .getName();
  269. if (this.inEdit.contains(e.getPlayer().getName())) {
  270. if (blocks.contains(block)) {
  271. e.getPlayer().sendMessage("§cRemoved this block!");
  272. blocks.remove(block);
  273. this.getConfig().set("blocks", blocks);
  274. this.saveConfig();
  275. } else {
  276. e.getPlayer().sendMessage("§aAdded this block!");
  277. blocks.add(block);
  278. this.getConfig().set("blocks", blocks);
  279. this.saveConfig();
  280. }
  281. } else if (this.getConfig().getStringList("blocks")
  282. .contains(block)) {
  283. String s;
  284. int blocksLeft;
  285. Iterator<?> lst1;
  286. if (this.blocksss.get(e.getPlayer().getName()) != null
  287. && ((List<?>) this.blocksss.get(e.getPlayer()
  288. .getName())).contains(block)) {
  289. if (((List<?>) this.blocksss.get(e.getPlayer().getName()))
  290. .contains(block)) {
  291. lst1 = this.getConfig()
  292. .getStringList("already-found-commands")
  293. .iterator();
  294.  
  295. while (lst1.hasNext()) {
  296. s = (String) lst1.next();
  297. blocksLeft = this.getConfig()
  298. .getStringList("blocks").size()
  299. - ((List<?>) this.blocksss.get(e
  300. .getPlayer().getName())).size();
  301. Bukkit.dispatchCommand(
  302. Bukkit.getConsoleSender(),
  303. s.replace("%player%",
  304. e.getPlayer().getName())
  305. .replace(
  306. "%pLocX%",
  307. ""
  308. + e.getPlayer()
  309. .getLocation()
  310. .getX())
  311. .replace(
  312. "%pLocY%",
  313. ""
  314. + e.getPlayer()
  315. .getLocation()
  316. .getY())
  317. .replace(
  318. "%pLocZ%",
  319. ""
  320. + e.getPlayer()
  321. .getLocation()
  322. .getZ())
  323. .replace(
  324. "%locX5%",
  325. ""
  326. + (e.getClickedBlock()
  327. .getLocation()
  328. .getX() + 0.5D))
  329. .replace(
  330. "%locY5%",
  331. ""
  332. + (e.getClickedBlock()
  333. .getLocation()
  334. .getY() + 0.5D))
  335. .replace(
  336. "%locZ5%",
  337. ""
  338. + (e.getClickedBlock()
  339. .getLocation()
  340. .getZ() + 0.5D))
  341. .replace(
  342. "%locX%",
  343. ""
  344. + e.getClickedBlock()
  345. .getLocation()
  346. .getX())
  347. .replace(
  348. "%locY%",
  349. ""
  350. + e.getClickedBlock()
  351. .getLocation()
  352. .getY())
  353. .replace(
  354. "%locZ%",
  355. ""
  356. + e.getClickedBlock()
  357. .getLocation()
  358. .getZ())
  359. .replace("%blockLeft%",
  360. "" + blocksLeft)
  361. .replace("%blocksLeft%",
  362. "" + blocksLeft));
  363. }
  364. }
  365. } else {
  366. this.saved_x.put(
  367. e.getPlayer().getName(),
  368. (String) this.saved_x.get(e.getPlayer()
  369. .getName())
  370. + ";"
  371. + e.getClickedBlock().getLocation()
  372. .getBlockX());
  373. this.saved_y.put(
  374. e.getPlayer().getName(),
  375. (String) this.saved_y.get(e.getPlayer()
  376. .getName())
  377. + ";"
  378. + e.getClickedBlock().getLocation()
  379. .getBlockY());
  380. this.saved_z.put(
  381. e.getPlayer().getName(),
  382. (String) this.saved_z.get(e.getPlayer()
  383. .getName())
  384. + ";"
  385. + e.getClickedBlock().getLocation()
  386. .getBlockZ());
  387. this.saved_world.put(
  388. e.getPlayer().getName(),
  389. (String) this.saved_world.get(e.getPlayer()
  390. .getName())
  391. + ";"
  392. + e.getClickedBlock().getLocation()
  393. .getWorld().getName());
  394. if (this.blocksss.get(e.getPlayer().getName()) == null) {
  395. ArrayList<String> lst = new ArrayList<String>();
  396. lst.add(block);
  397. this.blocksss.put(e.getPlayer().getName(), lst);
  398. } else {
  399. ((List<String>) this.blocksss.get(e.getPlayer().getName()))
  400. .add(block);
  401. }
  402.  
  403. if (this.useMysql) {
  404. if (!this.unsafeSave) {
  405. SQLPlayer.setString(e.getPlayer().getUniqueId()
  406. .toString(), "X", (String) this.saved_x
  407. .get(e.getPlayer().getName()));
  408. SQLPlayer.setString(e.getPlayer().getUniqueId()
  409. .toString(), "Y", (String) this.saved_y
  410. .get(e.getPlayer().getName()));
  411. SQLPlayer.setString(e.getPlayer().getUniqueId()
  412. .toString(), "Z", (String) this.saved_z
  413. .get(e.getPlayer().getName()));
  414. SQLPlayer.setString(e.getPlayer().getUniqueId()
  415. .toString(), "WORLD",
  416. (String) this.saved_world.get(e
  417. .getPlayer().getName()));
  418. }
  419. } else {
  420. this.data.getConfig().set(
  421. "data."
  422. + e.getPlayer().getUniqueId()
  423. .toString() + ".x",
  424. this.saved_x.get(e.getPlayer().getName()));
  425. this.data.getConfig().set(
  426. "data."
  427. + e.getPlayer().getUniqueId()
  428. .toString() + ".y",
  429. this.saved_y.get(e.getPlayer().getName()));
  430. this.data.getConfig().set(
  431. "data."
  432. + e.getPlayer().getUniqueId()
  433. .toString() + ".z",
  434. this.saved_z.get(e.getPlayer().getName()));
  435. this.data.getConfig().set(
  436. "data."
  437. + e.getPlayer().getUniqueId()
  438. .toString() + ".world",
  439. this.saved_world.get(e.getPlayer()
  440. .getName()));
  441. this.data.saveConfig();
  442. }
  443.  
  444. lst1 = this.getConfig()
  445. .getStringList("find-block-commands")
  446. .iterator();
  447.  
  448. while (lst1.hasNext()) {
  449. s = (String) lst1.next();
  450. blocksLeft = this.getConfig()
  451. .getStringList("blocks").size()
  452. - ((List<?>) this.blocksss.get(e.getPlayer()
  453. .getName())).size();
  454. Bukkit.dispatchCommand(
  455. Bukkit.getConsoleSender(),
  456. s.replace("%player%",
  457. e.getPlayer().getName())
  458. .replace(
  459. "%pLocX%",
  460. ""
  461. + e.getPlayer()
  462. .getLocation()
  463. .getX())
  464. .replace(
  465. "%pLocY%",
  466. ""
  467. + e.getPlayer()
  468. .getLocation()
  469. .getY())
  470. .replace(
  471. "%pLocZ%",
  472. ""
  473. + e.getPlayer()
  474. .getLocation()
  475. .getZ())
  476. .replace(
  477. "%locX5%",
  478. ""
  479. + (e.getClickedBlock()
  480. .getLocation()
  481. .getX() + 0.5D))
  482. .replace(
  483. "%locY5%",
  484. ""
  485. + (e.getClickedBlock()
  486. .getLocation()
  487. .getY() + 0.5D))
  488. .replace(
  489. "%locZ5%",
  490. ""
  491. + (e.getClickedBlock()
  492. .getLocation()
  493. .getZ() + 0.5D))
  494. .replace(
  495. "%locX%",
  496. ""
  497. + e.getClickedBlock()
  498. .getLocation()
  499. .getX())
  500. .replace(
  501. "%locY%",
  502. ""
  503. + e.getClickedBlock()
  504. .getLocation()
  505. .getY())
  506. .replace(
  507. "%locZ%",
  508. ""
  509. + e.getClickedBlock()
  510. .getLocation()
  511. .getZ())
  512. .replace("%blockLeft%",
  513. "" + blocksLeft)
  514. .replace("%blocksLeft%",
  515. "" + blocksLeft));
  516. }
  517. if (((List<?>) this.blocksss.get(e.getPlayer().getName()))
  518. .size() >= this.getConfig()
  519. .getStringList("blocks").size()) {
  520. lst1 = this.getConfig()
  521. .getStringList("all-blocks-found-commands")
  522. .iterator();
  523.  
  524. while (lst1.hasNext()) {
  525. s = (String) lst1.next();
  526. blocksLeft = this.getConfig()
  527. .getStringList("blocks").size()
  528. - ((List<?>) this.blocksss.get(e
  529. .getPlayer().getName())).size();
  530. if ((blocksLeft == 0) && (this.data.getConfig().getBoolean("data." + e.getPlayer().getUniqueId() + ".finished") != true)) {
  531. Bukkit.dispatchCommand(
  532. Bukkit.getConsoleSender(),
  533. s.replace("%player%",
  534. e.getPlayer().getName())
  535. .replace(
  536. "%pLocX%",
  537. ""
  538. + e.getPlayer()
  539. .getLocation()
  540. .getX())
  541. .replace(
  542. "%pLocY%",
  543. ""
  544. + e.getPlayer()
  545. .getLocation()
  546. .getY())
  547. .replace(
  548. "%pLocZ%",
  549. ""
  550. + e.getPlayer()
  551. .getLocation()
  552. .getZ())
  553. .replace(
  554. "%locX5%",
  555. ""
  556. + (e.getClickedBlock()
  557. .getLocation()
  558. .getX() + 0.5D))
  559. .replace(
  560. "%locY5%",
  561. ""
  562. + (e.getClickedBlock()
  563. .getLocation()
  564. .getY() + 0.5D))
  565. .replace(
  566. "%locZ5%",
  567. ""
  568. + (e.getClickedBlock()
  569. .getLocation()
  570. .getZ() + 0.5D))
  571. .replace(
  572. "%locX%",
  573. ""
  574. + e.getClickedBlock()
  575. .getLocation()
  576. .getX())
  577. .replace(
  578. "%locY%",
  579. ""
  580. + e.getClickedBlock()
  581. .getLocation()
  582. .getY())
  583. .replace(
  584. "%locZ%",
  585. ""
  586. + e.getClickedBlock()
  587. .getLocation()
  588. .getZ())
  589. .replace("%blockLeft%",
  590. "" + blocksLeft)
  591. .replace("%blocksLeft%",
  592. "" + blocksLeft));
  593. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  594. private Config data;
  595. public void run() {
  596. this.data.getConfig().set("data." + e.getPlayer().getUniqueId() + ".finsihed", true);
  597. }
  598. }, 40L);
  599. }
  600. }
  601. }
  602. }
  603. }
  604. }
  605. }
  606. }
  607. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement