Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.culleystudios.proquests.quests.external;
- import com.culleystudios.proquests.ProQuests;
- import com.culleystudios.proquests.QMessage;
- import com.culleystudios.proquests.compatibility.CompatibilityVersion;
- import com.culleystudios.proquests.creator.CreationType;
- import com.culleystudios.proquests.creator.Creator;
- import com.culleystudios.proquests.creator.creators.QuestCreator;
- import com.culleystudios.proquests.players.QPlayer;
- import com.culleystudios.proquests.plugins.PluginHookType;
- import com.culleystudios.proquests.plugins.hooks.WorldGuardHook;
- import com.culleystudios.proquests.quests.NumericQuest;
- import com.culleystudios.proquests.quests.Quest;
- import com.culleystudios.proquests.quests.QuestType;
- import com.culleystudios.proquests.util.EligibilityUtil;
- import com.culleystudios.proquests.util.FormatUtil;
- import com.culleystudios.proquests.util.Items;
- import com.culleystudios.proquests.util.Messages;
- import com.vk2gpz.tokenenchant.event.TEBlockExplodeEvent;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Set;
- import java.util.UUID;
- import java.util.stream.Collectors;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.block.Block;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.HandlerList;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.player.AsyncPlayerChatEvent;
- import org.bukkit.inventory.Inventory;
- public class TokenEnchantBreakQuest
- extends NumericQuest
- implements Listener
- {
- private static final long serialVersionUID = 1L;
- private ArrayList<String> materials;
- private HashMap<String, Double> required;
- private HashMap<String, Double> brokenBlocks;
- public TokenEnchantBreakQuest(Quest paramQuest, int paramInt, ArrayList<String> paramArrayList, HashMap<String, Double> paramHashMap) {
- super(paramQuest, QuestType.TOKEN_ENCHANT_BREAK_QUEST);
- setTotal(paramInt);
- this.materials = paramArrayList;
- this.required = paramHashMap;
- }
- public ArrayList<String> getMaterials() { return this.materials; }
- public HashMap<String, Double> getRequired() { return this.required; }
- public HashMap<String, Double> getBlocksBroken() { return this.brokenBlocks; }
- public void setMaterials(ArrayList<String> paramArrayList) { this.materials = paramArrayList; }
- public void setRequired(HashMap<String, Double> paramHashMap) { this.required = paramHashMap; }
- public void registerEvent() {
- ProQuests proQuests = ProQuests.getInstance();
- proQuests.getServer().getPluginManager().registerEvents(this, proQuests);
- }
- public void unregisterEvent() { HandlerList.unregisterAll(this); }
- public YamlConfiguration saveQuest(YamlConfiguration paramYamlConfiguration, String paramString) {
- paramYamlConfiguration = super.saveQuest(paramYamlConfiguration, paramString);
- paramYamlConfiguration.set(String.valueOf(paramString) + "total", Double.valueOf(getTotal()));
- paramYamlConfiguration.set(String.valueOf(paramString) + "allowed_materials", this.materials);
- if (this.required != null && !this.required.isEmpty()) {
- Set set = this.required.keySet();
- ArrayList arrayList = new ArrayList();
- for (String str : set)
- {
- arrayList.add(String.valueOf(str) + ";" + this.required.get(str));
- }
- paramYamlConfiguration.set(String.valueOf(paramString) + "required_materials", arrayList);
- }
- return paramYamlConfiguration;
- }
- public Quest loadQuest(YamlConfiguration paramYamlConfiguration, String paramString) {
- setTotal(FormatUtil.stringToDouble(paramYamlConfiguration.getString(String.valueOf(paramString) + "total"), this));
- this.materials = (ArrayList)paramYamlConfiguration.getStringList(String.valueOf(paramString) + "allowed_materials");
- if (this.materials != null && !this.materials.isEmpty()) {
- this.materials = (ArrayList)this.materials.stream().map(String::toUpperCase).collect(Collectors.toList());
- }
- List list = paramYamlConfiguration.getStringList(String.valueOf(paramString) + "required_materials");
- HashMap hashMap = null;
- if (list != null && !list.isEmpty()) {
- hashMap = new HashMap();
- for (String str1 : list) {
- String[] arrayOfString = str1.split(";");
- String str2 = arrayOfString[0].toUpperCase();
- int i = Integer.parseInt(arrayOfString[1]);
- double d = Double.parseDouble(arrayOfString[2]);
- if (CompatibilityVersion.getMaterial(str2, false) != null && d > 0.0D) {
- hashMap.put(String.valueOf(str2) + ";" + i, Double.valueOf(d));
- }
- }
- }
- this.required = hashMap;
- return this;
- }
- public Inventory setCreatorMenuItems(Inventory paramInventory) {
- ArrayList arrayList1 = new ArrayList();
- arrayList1.add("&7The amount of blocks the player");
- arrayList1.add("&7must break using Token Enchant enchants");
- arrayList1.add("&7to complete the quest");
- arrayList1.add("&8&m-----------------");
- arrayList1.add("&bTotal: &f" + getTotal());
- paramInventory.setItem(12, Items.getItem(CompatibilityVersion.getMaterial("EMERALD", 0), 1, 0, Messages.setColour("&bTotal"), arrayList1, false));
- ArrayList arrayList2 = new ArrayList();
- arrayList2.add("&7The materials that the quest will");
- arrayList2.add("&7check for (leave empty for any)");
- arrayList2.add("&8&m-----------------");
- if (this.materials == null || this.materials.isEmpty()) {
- arrayList2.add("&bAllowed Materials: &fN/A");
- }
- else {
- arrayList2.add("&bAllowed Materials:");
- for (String str : this.materials) {
- arrayList2.add("&7- &f" + str);
- }
- }
- arrayList2.add("&8&m-----------------");
- arrayList2.add("&7[Shift-Click] to remove last entry");
- paramInventory.setItem(13, Items.getItem(CompatibilityVersion.getMaterial("STONE", 0), 1, 0, Messages.setColour("&bAllowed Materials"), arrayList2, false));
- ArrayList arrayList3 = new ArrayList();
- arrayList3.add("&7The specfic amount of each");
- arrayList3.add("&7block the player must break");
- arrayList3.add("&7to complete the quest");
- arrayList3.add("&8&m-----------------");
- if (this.required == null || this.required.isEmpty()) {
- arrayList3.add("&bRequired Materials: &fN/A");
- }
- else {
- arrayList3.add("&bRequired Materials:");
- Set set = this.required.keySet();
- for (String str : set) {
- double d = ((Double)this.required.get(str)).doubleValue();
- arrayList3.add("&7- &f" + str + ";" + Messages.numberFormat(d));
- }
- }
- arrayList3.add("&8&m-----------------");
- arrayList3.add("&7[Shift-Click] to clear entries");
- paramInventory.setItem(14, Items.getItem(CompatibilityVersion.getMaterial("DIAMOND_BLOCK", 0), 1, 0, Messages.setColour("&bRequired Materials"), arrayList3, false));
- return paramInventory;
- }
- public void creatorChatResponse(Player paramPlayer, Creator paramCreator, AsyncPlayerChatEvent paramAsyncPlayerChatEvent, ProQuests paramProQuests) {
- UUID uUID = paramPlayer.getUniqueId();
- String str = paramAsyncPlayerChatEvent.getMessage();
- if (paramCreator.getCreationType().equals(CreationType.QUEST_CREATOR_1)) {
- try {
- setTotal(Integer.parseInt(str));
- } catch (Exception exception) {
- Messages.sms(paramPlayer, QMessage.INVALID_NUMBER.message());
- return;
- }
- ((QuestCreator)paramCreator).setQuest(this);
- paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
- paramProQuests.MenuManager.getCreatorMenu().openMenu(paramPlayer, 3, 0);
- return;
- }
- if (paramCreator.getCreationType().equals(CreationType.QUEST_CREATOR_2)) {
- if (!str.contains(";")) {
- Messages.sms(paramPlayer, QMessage.INVALID_ENTRY.message());
- return;
- }
- String[] arrayOfString = str.split(";");
- try {
- CompatibilityVersion.getMaterial(arrayOfString[0], 0);
- } catch (Exception exception) {
- Messages.sms(paramPlayer, QMessage.INVALID_ENTRY.message());
- return;
- }
- try {
- Integer.parseInt(arrayOfString[1]);
- } catch (Exception exception) {
- Messages.sms(paramPlayer, QMessage.INVALID_NUMBER.message());
- return;
- }
- if (this.materials == null || this.materials.isEmpty()) {
- this.materials = new ArrayList();
- }
- if (!this.materials.contains(str)) {
- this.materials.add(str);
- }
- ((QuestCreator)paramCreator).setQuest(this);
- paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
- paramProQuests.MenuManager.getCreatorMenu().openMenu(paramPlayer, 3, 0);
- return;
- }
- if (paramCreator.getCreationType().equals(CreationType.QUEST_CREATOR_3)) {
- if (!str.contains(";")) {
- Messages.sms(paramPlayer, QMessage.INVALID_ENTRY.message());
- return;
- }
- String[] arrayOfString = str.split(";");
- int i = 0;
- double d = 0.0D;
- try {
- CompatibilityVersion.getMaterial(arrayOfString[0], 0);
- } catch (Exception exception) {
- Messages.sms(paramPlayer, QMessage.INVALID_ENTRY.message());
- return;
- }
- try {
- i = Integer.parseInt(arrayOfString[1]);
- d = Double.parseDouble(arrayOfString[2]);
- } catch (Exception exception) {
- Messages.sms(paramPlayer, QMessage.INVALID_NUMBER.message());
- return;
- }
- if (this.required == null || this.required.isEmpty()) {
- this.required = new HashMap();
- }
- this.required.put(String.valueOf(arrayOfString[0]) + ";" + i, Double.valueOf(d));
- ((QuestCreator)paramCreator).setQuest(this);
- paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
- paramProQuests.MenuManager.getCreatorMenu().openMenu(paramPlayer, 3, 0);
- return;
- }
- }
- public void creatorInventoryClick(Player paramPlayer, Creator paramCreator, InventoryClickEvent paramInventoryClickEvent, ProQuests paramProQuests) {
- UUID uUID = paramPlayer.getUniqueId();
- int i = paramInventoryClickEvent.getRawSlot();
- if (i == 12) {
- paramCreator.setCreationType(CreationType.QUEST_CREATOR_1);
- Messages.sms(paramPlayer, "&aEnter the amount of blocks the player must break to complete the quest");
- paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
- paramPlayer.closeInventory();
- return;
- }
- if (i == 13) {
- paramCreator.setCreationType(CreationType.QUEST_CREATOR_2);
- if (paramInventoryClickEvent.isShiftClick())
- {
- if (this.materials != null && !this.materials.isEmpty()) {
- this.materials.remove(this.materials.size() - 1);
- ((QuestCreator)paramCreator).setQuest(this);
- paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
- paramProQuests.MenuManager.getCreatorMenu().openMenu(paramPlayer, 3, 0);
- return;
- }
- }
- Messages.sms(paramPlayer, "&aEnter one of the valid materials for this quest. Format: &7<Material>;<Data>");
- paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
- paramPlayer.closeInventory();
- return;
- }
- if (i == 14) {
- paramCreator.setCreationType(CreationType.QUEST_CREATOR_3);
- if (paramInventoryClickEvent.isShiftClick())
- {
- if (this.required != null && !this.required.isEmpty()) {
- this.required.clear();
- ((QuestCreator)paramCreator).setQuest(this);
- paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
- paramProQuests.MenuManager.getCreatorMenu().openMenu(paramPlayer, 3, 0);
- return;
- }
- }
- Messages.sms(paramPlayer, "&aEnter one of the required materials & amount for completion. Format: &7<Material>;<Data>;<Amount>");
- paramProQuests.CreatorManager.setCreating(uUID, paramCreator);
- paramPlayer.closeInventory();
- return;
- }
- }
- public boolean isEligble() {
- if (getString(Quest.StringAttribute.IDENTIFIER) != null && getTotal() > 0.0D) {
- return true;
- }
- return false;
- }
- public String setPlaceholders(OfflinePlayer paramOfflinePlayer, String paramString) {
- if (paramString == null) {
- return paramString;
- }
- if (this.brokenBlocks != null) {
- for (String str : this.brokenBlocks.keySet()) {
- double d = 0.0D;
- d = ((Double)this.brokenBlocks.get(str)).doubleValue();
- paramString = paramString.replace("%quest_progress_" + str + "%", String.valueOf(d));
- }
- }
- if (this.required != null) {
- for (String str : this.required.keySet()) {
- double d = 0.0D;
- d = ((Double)this.required.get(str)).doubleValue();
- paramString = paramString.replace("%quest_total_" + str + "%", String.valueOf(d));
- paramString = paramString.replace("%quest_progress_" + str + "%", "0");
- }
- }
- return super.setPlaceholders(paramOfflinePlayer, paramString);
- }
- public Quest clone() { return new TokenEnchantBreakQuest(this, (int)getTotal(), this.materials, this.required); }
- @EventHandler
- public void breakList(BlockBreakEvent paramBlockBreakEvent) {
- ArrayList arrayList = new ArrayList();
- Location location = paramBlockBreakEvent.getPlayer().getLocation();
- int i = location.getBlockX();
- int j = location.getBlockY();
- int k = location.getBlockZ();
- for (int m = 0; m < 40; m++) {
- for (int n = 0; n < 40; n++) {
- for (int i1 = 0; i1 < 20; i1++)
- {
- arrayList.add(location.getWorld().getBlockAt(i + m, j - i1, k + n));
- }
- }
- }
- TEBlockExplodeEvent tEBlockExplodeEvent = new TEBlockExplodeEvent(paramBlockBreakEvent.getPlayer(), paramBlockBreakEvent.getBlock(), arrayList, 0.0F);
- Bukkit.getPluginManager().callEvent(tEBlockExplodeEvent);
- }
- @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
- public void onBreak(TEBlockExplodeEvent paramTEBlockExplodeEvent) {
- Block block = paramTEBlockExplodeEvent.getBlock();
- List list = paramTEBlockExplodeEvent.blockList();
- if (block == null || list == null || list.isEmpty()) {
- return;
- }
- if (getToggle(Quest.ToggleAttribute.COMPLETED)) {
- unregisterEvent();
- return;
- }
- if (paramTEBlockExplodeEvent.getPlayer() == null || getPlayers() == null || getPlayers().isEmpty()) {
- return;
- }
- Player player = paramTEBlockExplodeEvent.getPlayer();
- QPlayer qPlayer = (ProQuests.getInstance()).QPlayerManager.getPlayer(player.getUniqueId());
- for (Block block1 : list) {
- if (!EligibilityUtil.isEligble(this, qPlayer, player, block1.getLocation())) {
- return;
- }
- if (PluginHookType.WORLD_GUARD.isEnabled() &&
- !((WorldGuardHook)PluginHookType.WORLD_GUARD.getHook()).canBuild(player, block1)) {
- return;
- }
- String str = String.valueOf(block1.getType().toString()) + ";" + block1.getData();
- if (this.materials != null && !this.materials.isEmpty() && !this.materials.contains(str)) {
- return;
- }
- if (this.required != null && !this.required.isEmpty()) {
- if (!this.required.containsKey(str)) {
- return;
- }
- if (this.brokenBlocks == null) {
- this.brokenBlocks = new HashMap();
- }
- double d = 0.0D;
- if (this.brokenBlocks.containsKey(str)) {
- d = ((Double)this.brokenBlocks.get(str)).doubleValue();
- }
- if (d >= ((Double)this.required.get(str)).doubleValue()) {
- return;
- }
- this.brokenBlocks.put(str, Double.valueOf(d + 1.0D));
- }
- setProgress(qPlayer, this, getProgress() + 1.0D);
- if (this.required != null && !this.required.isEmpty()) {
- Set set = this.required.keySet();
- for (String str1 : set) {
- double d1 = 0.0D;
- if (this.brokenBlocks != null && !this.brokenBlocks.isEmpty() && this.brokenBlocks.containsKey(str1)) {
- d1 = ((Double)this.brokenBlocks.get(str1)).doubleValue();
- }
- double d2 = ((Double)this.required.get(str1)).doubleValue();
- if (d1 < d2) {
- return;
- }
- }
- }
- }
- if (getProgress() >= getTotal())
- QuestUtil().completeEvents(this, false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement