Advertisement
Guest User

Untitled

a guest
May 26th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.42 KB | None | 0 0
  1. package com.culleystudios.proquests.quests.external;
  2.  
  3. import com.culleystudios.proquests.ProQuests;
  4. import com.culleystudios.proquests.QMessage;
  5. import com.culleystudios.proquests.compatibility.CompatibilityVersion;
  6. import com.culleystudios.proquests.creator.CreationType;
  7. import com.culleystudios.proquests.creator.Creator;
  8. import com.culleystudios.proquests.creator.creators.QuestCreator;
  9. import com.culleystudios.proquests.players.QPlayer;
  10. import com.culleystudios.proquests.plugins.PluginHookType;
  11. import com.culleystudios.proquests.plugins.hooks.WorldGuardHook;
  12. import com.culleystudios.proquests.quests.NumericQuest;
  13. import com.culleystudios.proquests.quests.Quest;
  14. import com.culleystudios.proquests.quests.QuestType;
  15. import com.culleystudios.proquests.util.EligibilityUtil;
  16. import com.culleystudios.proquests.util.FormatUtil;
  17. import com.culleystudios.proquests.util.Items;
  18. import com.culleystudios.proquests.util.Messages;
  19. import com.vk2gpz.tokenenchant.event.TEBlockExplodeEvent;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Set;
  24. import java.util.UUID;
  25. import java.util.stream.Collectors;
  26. import org.bukkit.Bukkit;
  27. import org.bukkit.Location;
  28. import org.bukkit.OfflinePlayer;
  29. import org.bukkit.block.Block;
  30. import org.bukkit.configuration.file.YamlConfiguration;
  31. import org.bukkit.entity.Player;
  32. import org.bukkit.event.EventHandler;
  33. import org.bukkit.event.EventPriority;
  34. import org.bukkit.event.HandlerList;
  35. import org.bukkit.event.Listener;
  36. import org.bukkit.event.block.BlockBreakEvent;
  37. import org.bukkit.event.inventory.InventoryClickEvent;
  38. import org.bukkit.event.player.AsyncPlayerChatEvent;
  39. import org.bukkit.inventory.Inventory;
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. public class TokenEnchantBreakQuest
  51. extends NumericQuest
  52. implements Listener
  53. {
  54. private static final long serialVersionUID = 1L;
  55. private ArrayList<String> materials;
  56. private HashMap<String, Double> required;
  57. private HashMap<String, Double> brokenBlocks;
  58.  
  59. public TokenEnchantBreakQuest(Quest paramQuest, int paramInt, ArrayList<String> paramArrayList, HashMap<String, Double> paramHashMap) {
  60. super(paramQuest, QuestType.TOKEN_ENCHANT_BREAK_QUEST);
  61.  
  62. setTotal(paramInt);
  63. this.materials = paramArrayList;
  64. this.required = paramHashMap;
  65. }
  66.  
  67.  
  68. public ArrayList<String> getMaterials() { return this.materials; }
  69.  
  70.  
  71.  
  72. public HashMap<String, Double> getRequired() { return this.required; }
  73.  
  74.  
  75.  
  76. public HashMap<String, Double> getBlocksBroken() { return this.brokenBlocks; }
  77.  
  78.  
  79.  
  80. public void setMaterials(ArrayList<String> paramArrayList) { this.materials = paramArrayList; }
  81.  
  82.  
  83.  
  84. public void setRequired(HashMap<String, Double> paramHashMap) { this.required = paramHashMap; }
  85.  
  86.  
  87.  
  88. public void registerEvent() {
  89. ProQuests proQuests = ProQuests.getInstance();
  90. proQuests.getServer().getPluginManager().registerEvents(this, proQuests);
  91. }
  92.  
  93.  
  94.  
  95. public void unregisterEvent() { HandlerList.unregisterAll(this); }
  96.  
  97.  
  98.  
  99. public YamlConfiguration saveQuest(YamlConfiguration paramYamlConfiguration, String paramString) {
  100. paramYamlConfiguration = super.saveQuest(paramYamlConfiguration, paramString);
  101. paramYamlConfiguration.set(String.valueOf(paramString) + "total", Double.valueOf(getTotal()));
  102. paramYamlConfiguration.set(String.valueOf(paramString) + "allowed_materials", this.materials);
  103.  
  104. if (this.required != null && !this.required.isEmpty()) {
  105.  
  106. Set set = this.required.keySet();
  107. ArrayList arrayList = new ArrayList();
  108.  
  109. for (String str : set)
  110. {
  111. arrayList.add(String.valueOf(str) + ";" + this.required.get(str));
  112. }
  113.  
  114. paramYamlConfiguration.set(String.valueOf(paramString) + "required_materials", arrayList);
  115. }
  116.  
  117. return paramYamlConfiguration;
  118. }
  119.  
  120.  
  121.  
  122. public Quest loadQuest(YamlConfiguration paramYamlConfiguration, String paramString) {
  123. setTotal(FormatUtil.stringToDouble(paramYamlConfiguration.getString(String.valueOf(paramString) + "total"), this));
  124. this.materials = (ArrayList)paramYamlConfiguration.getStringList(String.valueOf(paramString) + "allowed_materials");
  125.  
  126. if (this.materials != null && !this.materials.isEmpty()) {
  127. this.materials = (ArrayList)this.materials.stream().map(String::toUpperCase).collect(Collectors.toList());
  128. }
  129. List list = paramYamlConfiguration.getStringList(String.valueOf(paramString) + "required_materials");
  130. HashMap hashMap = null;
  131.  
  132. if (list != null && !list.isEmpty()) {
  133. hashMap = new HashMap();
  134.  
  135. for (String str1 : list) {
  136.  
  137. String[] arrayOfString = str1.split(";");
  138.  
  139. String str2 = arrayOfString[0].toUpperCase();
  140. int i = Integer.parseInt(arrayOfString[1]);
  141. double d = Double.parseDouble(arrayOfString[2]);
  142.  
  143. if (CompatibilityVersion.getMaterial(str2, false) != null && d > 0.0D) {
  144. hashMap.put(String.valueOf(str2) + ";" + i, Double.valueOf(d));
  145. }
  146. }
  147. }
  148.  
  149. this.required = hashMap;
  150. return this;
  151. }
  152.  
  153.  
  154.  
  155.  
  156. public Inventory setCreatorMenuItems(Inventory paramInventory) {
  157. ArrayList arrayList1 = new ArrayList();
  158. arrayList1.add("&7The amount of blocks the player");
  159. arrayList1.add("&7must break using Token Enchant enchants");
  160. arrayList1.add("&7to complete the quest");
  161. arrayList1.add("&8&m-----------------");
  162. arrayList1.add("&bTotal: &f" + getTotal());
  163.  
  164. paramInventory.setItem(12, Items.getItem(CompatibilityVersion.getMaterial("EMERALD", 0), 1, 0, Messages.setColour("&bTotal"), arrayList1, false));
  165.  
  166.  
  167. ArrayList arrayList2 = new ArrayList();
  168. arrayList2.add("&7The materials that the quest will");
  169. arrayList2.add("&7check for (leave empty for any)");
  170. arrayList2.add("&8&m-----------------");
  171.  
  172. if (this.materials == null || this.materials.isEmpty()) {
  173. arrayList2.add("&bAllowed Materials: &fN/A");
  174. }
  175. else {
  176.  
  177. arrayList2.add("&bAllowed Materials:");
  178.  
  179. for (String str : this.materials) {
  180. arrayList2.add("&7- &f" + str);
  181. }
  182. }
  183.  
  184. arrayList2.add("&8&m-----------------");
  185. arrayList2.add("&7[Shift-Click] to remove last entry");
  186.  
  187. paramInventory.setItem(13, Items.getItem(CompatibilityVersion.getMaterial("STONE", 0), 1, 0, Messages.setColour("&bAllowed Materials"), arrayList2, false));
  188.  
  189.  
  190. ArrayList arrayList3 = new ArrayList();
  191. arrayList3.add("&7The specfic amount of each");
  192. arrayList3.add("&7block the player must break");
  193. arrayList3.add("&7to complete the quest");
  194. arrayList3.add("&8&m-----------------");
  195.  
  196. if (this.required == null || this.required.isEmpty()) {
  197. arrayList3.add("&bRequired Materials: &fN/A");
  198. }
  199. else {
  200.  
  201. arrayList3.add("&bRequired Materials:");
  202.  
  203. Set set = this.required.keySet();
  204.  
  205. for (String str : set) {
  206.  
  207. double d = ((Double)this.required.get(str)).doubleValue();
  208. arrayList3.add("&7- &f" + str + ";" + Messages.numberFormat(d));
  209. }
  210. }
  211.  
  212. arrayList3.add("&8&m-----------------");
  213. arrayList3.add("&7[Shift-Click] to clear entries");
  214.  
  215. paramInventory.setItem(14, Items.getItem(CompatibilityVersion.getMaterial("DIAMOND_BLOCK", 0), 1, 0, Messages.setColour("&bRequired Materials"), arrayList3, false));
  216. return paramInventory;
  217. }
  218.  
  219.  
  220.  
  221. public void creatorChatResponse(Player paramPlayer, Creator paramCreator, AsyncPlayerChatEvent paramAsyncPlayerChatEvent, ProQuests paramProQuests) {
  222. UUID uUID = paramPlayer.getUniqueId();
  223. String str = paramAsyncPlayerChatEvent.getMessage();
  224.  
  225. if (paramCreator.getCreationType().equals(CreationType.QUEST_CREATOR_1)) {
  226. try {
  227. setTotal(Integer.parseInt(str));
  228. } catch (Exception exception) {
  229. Messages.sms(paramPlayer, QMessage.INVALID_NUMBER.message());
  230.  
  231. return;
  232. }
  233. ((QuestCreator)paramCreator).setQuest(this);
  234. paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
  235.  
  236. paramProQuests.MenuManager.getCreatorMenu().openMenu(paramPlayer, 3, 0);
  237. return;
  238. }
  239. if (paramCreator.getCreationType().equals(CreationType.QUEST_CREATOR_2)) {
  240.  
  241. if (!str.contains(";")) {
  242.  
  243. Messages.sms(paramPlayer, QMessage.INVALID_ENTRY.message());
  244.  
  245. return;
  246. }
  247. String[] arrayOfString = str.split(";");
  248. try {
  249. CompatibilityVersion.getMaterial(arrayOfString[0], 0);
  250. } catch (Exception exception) {
  251. Messages.sms(paramPlayer, QMessage.INVALID_ENTRY.message());
  252. return;
  253. }
  254. try {
  255. Integer.parseInt(arrayOfString[1]);
  256. } catch (Exception exception) {
  257. Messages.sms(paramPlayer, QMessage.INVALID_NUMBER.message());
  258.  
  259. return;
  260. }
  261. if (this.materials == null || this.materials.isEmpty()) {
  262. this.materials = new ArrayList();
  263. }
  264.  
  265. if (!this.materials.contains(str)) {
  266. this.materials.add(str);
  267. }
  268.  
  269. ((QuestCreator)paramCreator).setQuest(this);
  270. paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
  271.  
  272. paramProQuests.MenuManager.getCreatorMenu().openMenu(paramPlayer, 3, 0);
  273. return;
  274. }
  275. if (paramCreator.getCreationType().equals(CreationType.QUEST_CREATOR_3)) {
  276.  
  277. if (!str.contains(";")) {
  278.  
  279. Messages.sms(paramPlayer, QMessage.INVALID_ENTRY.message());
  280.  
  281. return;
  282. }
  283. String[] arrayOfString = str.split(";");
  284. int i = 0;
  285. double d = 0.0D;
  286. try {
  287. CompatibilityVersion.getMaterial(arrayOfString[0], 0);
  288. } catch (Exception exception) {
  289. Messages.sms(paramPlayer, QMessage.INVALID_ENTRY.message());
  290.  
  291. return;
  292. }
  293. try {
  294. i = Integer.parseInt(arrayOfString[1]);
  295. d = Double.parseDouble(arrayOfString[2]);
  296. } catch (Exception exception) {
  297. Messages.sms(paramPlayer, QMessage.INVALID_NUMBER.message());
  298.  
  299. return;
  300. }
  301. if (this.required == null || this.required.isEmpty()) {
  302. this.required = new HashMap();
  303. }
  304.  
  305. this.required.put(String.valueOf(arrayOfString[0]) + ";" + i, Double.valueOf(d));
  306.  
  307. ((QuestCreator)paramCreator).setQuest(this);
  308. paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
  309.  
  310. paramProQuests.MenuManager.getCreatorMenu().openMenu(paramPlayer, 3, 0);
  311. return;
  312. }
  313. }
  314.  
  315.  
  316.  
  317.  
  318. public void creatorInventoryClick(Player paramPlayer, Creator paramCreator, InventoryClickEvent paramInventoryClickEvent, ProQuests paramProQuests) {
  319. UUID uUID = paramPlayer.getUniqueId();
  320. int i = paramInventoryClickEvent.getRawSlot();
  321.  
  322. if (i == 12) {
  323.  
  324. paramCreator.setCreationType(CreationType.QUEST_CREATOR_1);
  325.  
  326. Messages.sms(paramPlayer, "&aEnter the amount of blocks the player must break to complete the quest");
  327.  
  328. paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
  329. paramPlayer.closeInventory();
  330. return;
  331. }
  332. if (i == 13) {
  333.  
  334.  
  335. paramCreator.setCreationType(CreationType.QUEST_CREATOR_2);
  336.  
  337. if (paramInventoryClickEvent.isShiftClick())
  338. {
  339. if (this.materials != null && !this.materials.isEmpty()) {
  340. this.materials.remove(this.materials.size() - 1);
  341.  
  342. ((QuestCreator)paramCreator).setQuest(this);
  343.  
  344. paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
  345. paramProQuests.MenuManager.getCreatorMenu().openMenu(paramPlayer, 3, 0);
  346.  
  347. return;
  348. }
  349. }
  350. Messages.sms(paramPlayer, "&aEnter one of the valid materials for this quest. Format: &7<Material>;<Data>");
  351.  
  352. paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
  353. paramPlayer.closeInventory();
  354. return;
  355. }
  356. if (i == 14) {
  357.  
  358.  
  359. paramCreator.setCreationType(CreationType.QUEST_CREATOR_3);
  360.  
  361. if (paramInventoryClickEvent.isShiftClick())
  362. {
  363. if (this.required != null && !this.required.isEmpty()) {
  364.  
  365. this.required.clear();
  366.  
  367. ((QuestCreator)paramCreator).setQuest(this);
  368. paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
  369. paramProQuests.MenuManager.getCreatorMenu().openMenu(paramPlayer, 3, 0);
  370.  
  371. return;
  372. }
  373. }
  374. Messages.sms(paramPlayer, "&aEnter one of the required materials & amount for completion. Format: &7<Material>;<Data>;<Amount>");
  375.  
  376. paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
  377. paramPlayer.closeInventory();
  378. return;
  379. }
  380. }
  381.  
  382.  
  383.  
  384.  
  385. public boolean isEligble() {
  386. if (getString(Quest.StringAttribute.IDENTIFIER) != null && getTotal() > 0.0D) {
  387. return true;
  388. }
  389. return false;
  390. }
  391.  
  392.  
  393.  
  394. public String setPlaceholders(OfflinePlayer paramOfflinePlayer, String paramString) {
  395. if (paramString == null) {
  396. return paramString;
  397. }
  398.  
  399. if (this.brokenBlocks != null) {
  400. for (String str : this.brokenBlocks.keySet()) {
  401.  
  402. double d = 0.0D;
  403. d = ((Double)this.brokenBlocks.get(str)).doubleValue();
  404.  
  405. paramString = paramString.replace("%quest_progress_" + str + "%", String.valueOf(d));
  406. }
  407. }
  408.  
  409. if (this.required != null) {
  410. for (String str : this.required.keySet()) {
  411.  
  412. double d = 0.0D;
  413. d = ((Double)this.required.get(str)).doubleValue();
  414.  
  415. paramString = paramString.replace("%quest_total_" + str + "%", String.valueOf(d));
  416. paramString = paramString.replace("%quest_progress_" + str + "%", "0");
  417. }
  418. }
  419.  
  420. return super.setPlaceholders(paramOfflinePlayer, paramString);
  421. }
  422.  
  423.  
  424.  
  425. public Quest clone() { return new TokenEnchantBreakQuest(this, (int)getTotal(), this.materials, this.required); }
  426.  
  427.  
  428.  
  429. @EventHandler
  430. public void breakList(BlockBreakEvent paramBlockBreakEvent) {
  431. ArrayList arrayList = new ArrayList();
  432. Location location = paramBlockBreakEvent.getPlayer().getLocation();
  433. int i = location.getBlockX();
  434. int j = location.getBlockY();
  435. int k = location.getBlockZ();
  436.  
  437. for (int m = 0; m < 40; m++) {
  438. for (int n = 0; n < 40; n++) {
  439. for (int i1 = 0; i1 < 20; i1++)
  440. {
  441. arrayList.add(location.getWorld().getBlockAt(i + m, j - i1, k + n));
  442. }
  443. }
  444. }
  445.  
  446.  
  447. TEBlockExplodeEvent tEBlockExplodeEvent = new TEBlockExplodeEvent(paramBlockBreakEvent.getPlayer(), paramBlockBreakEvent.getBlock(), arrayList, 0.0F);
  448. Bukkit.getPluginManager().callEvent(tEBlockExplodeEvent);
  449. }
  450.  
  451.  
  452.  
  453. @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
  454. public void onBreak(TEBlockExplodeEvent paramTEBlockExplodeEvent) {
  455. Block block = paramTEBlockExplodeEvent.getBlock();
  456. List list = paramTEBlockExplodeEvent.blockList();
  457.  
  458. if (block == null || list == null || list.isEmpty()) {
  459. return;
  460. }
  461.  
  462. if (getToggle(Quest.ToggleAttribute.COMPLETED)) {
  463. unregisterEvent();
  464.  
  465. return;
  466. }
  467. if (paramTEBlockExplodeEvent.getPlayer() == null || getPlayers() == null || getPlayers().isEmpty()) {
  468. return;
  469. }
  470.  
  471. Player player = paramTEBlockExplodeEvent.getPlayer();
  472. QPlayer qPlayer = (ProQuests.getInstance()).QPlayerManager.getPlayer(player.getUniqueId());
  473.  
  474. for (Block block1 : list) {
  475.  
  476. if (!EligibilityUtil.isEligble(this, qPlayer, player, block1.getLocation())) {
  477. return;
  478. }
  479.  
  480. if (PluginHookType.WORLD_GUARD.isEnabled() &&
  481. !((WorldGuardHook)PluginHookType.WORLD_GUARD.getHook()).canBuild(player, block1)) {
  482. return;
  483. }
  484.  
  485.  
  486. String str = String.valueOf(block1.getType().toString()) + ";" + block1.getData();
  487.  
  488. if (this.materials != null && !this.materials.isEmpty() && !this.materials.contains(str)) {
  489. return;
  490. }
  491.  
  492. if (this.required != null && !this.required.isEmpty()) {
  493.  
  494. if (!this.required.containsKey(str)) {
  495. return;
  496. }
  497.  
  498. if (this.brokenBlocks == null) {
  499. this.brokenBlocks = new HashMap();
  500. }
  501.  
  502. double d = 0.0D;
  503.  
  504. if (this.brokenBlocks.containsKey(str)) {
  505. d = ((Double)this.brokenBlocks.get(str)).doubleValue();
  506. }
  507.  
  508. if (d >= ((Double)this.required.get(str)).doubleValue()) {
  509. return;
  510. }
  511.  
  512. this.brokenBlocks.put(str, Double.valueOf(d + 1.0D));
  513. }
  514.  
  515. setProgress(qPlayer, this, getProgress() + 1.0D);
  516.  
  517. if (this.required != null && !this.required.isEmpty()) {
  518.  
  519. Set set = this.required.keySet();
  520. for (String str1 : set) {
  521.  
  522. double d1 = 0.0D;
  523.  
  524. if (this.brokenBlocks != null && !this.brokenBlocks.isEmpty() && this.brokenBlocks.containsKey(str1)) {
  525. d1 = ((Double)this.brokenBlocks.get(str1)).doubleValue();
  526. }
  527.  
  528. double d2 = ((Double)this.required.get(str1)).doubleValue();
  529.  
  530. if (d1 < d2) {
  531. return;
  532. }
  533. }
  534. }
  535. }
  536.  
  537. if (getProgress() >= getTotal())
  538. QuestUtil().completeEvents(this, false);
  539. }
  540. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement