Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.98 KB | None | 0 0
  1. package com.aidan.coordinateheads;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.UUID;
  6.  
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Material;
  9. import org.bukkit.Server;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandExecutor;
  12. import org.bukkit.command.CommandSender;
  13. import org.bukkit.command.ConsoleCommandSender;
  14. import org.bukkit.configuration.ConfigurationSection;
  15. import org.bukkit.entity.Player;
  16. import org.bukkit.event.EventHandler;
  17. import org.bukkit.event.Listener;
  18. import org.bukkit.event.block.Action;
  19. import org.bukkit.event.player.PlayerInteractEvent;
  20. import org.bukkit.inventory.EquipmentSlot;
  21. import org.bukkit.inventory.ItemStack;
  22. import org.bukkit.inventory.meta.ItemMeta;
  23. import org.bukkit.plugin.Plugin;
  24.  
  25.  
  26. public class CoordinateListener implements Listener {
  27.     private Plugin plugin = HeadQuest.getPlugin(HeadQuest.class);
  28.    
  29.     static int[] blockCoords = new int [3];
  30.     @EventHandler
  31.     public void listener(PlayerInteractEvent e) {
  32.         onPlayerInteract(e, blockCoords);
  33.     }
  34.  
  35.     public void onPlayerInteract(PlayerInteractEvent event, int [] chosenBlock) {
  36.         EquipmentSlot e = event.getHand();
  37.         if (e.equals(EquipmentSlot.HAND)) {    
  38.         if (event.getPlayer().getItemInHand().getType() == Material.GOLDEN_SWORD && event.getPlayer().isOp()) {
  39.             String targetSeries = event.getPlayer().getItemInHand().getItemMeta().getDisplayName().substring(14);
  40.             if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
  41.                 int x = event.getClickedBlock().getX();
  42.                 int y = event.getClickedBlock().getY();
  43.                 int z = event.getClickedBlock().getZ();
  44.                 boolean foundSeries = false;
  45.                 boolean foundBlock = false;
  46.            
  47.                     if (plugin.getConfig().contains("seriesList." + targetSeries)) {
  48.                         foundSeries = true;
  49.                         int numberOfElements = plugin.getConfig().getInt("seriesList." + targetSeries + ".numberOfBlocks");
  50.                         for (int i = 0; i < plugin.getConfig().getInt("seriesList." + targetSeries + ".numberOfBlocks"); i++) {
  51.                             if ((plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +i  + ".x") == x) &&
  52.                                     (plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +i  + ".y") == y) &&
  53.                                     (plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +i  + ".z") == z)) {
  54.                                 foundBlock = true;
  55.                                 event.getPlayer().sendMessage(ChatColor.BOLD + "Block " + ChatColor.RED + x + ", " + y + ", " + z + ChatColor.RESET + "" + ChatColor.BOLD + " already in series ");
  56.  
  57.                             }
  58.                         }
  59.                         if (!foundBlock) {
  60.                             ArrayList<UUID> tempList = new ArrayList<UUID>();
  61.                             plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + numberOfElements +".id", numberOfElements);
  62.                             plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + numberOfElements +".x", x);
  63.                             plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + numberOfElements +".y", y);
  64.                             plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + numberOfElements +".z", z);
  65.                             plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + numberOfElements +".clickedPlayers", tempList);
  66.                             numberOfElements++;
  67.                             plugin.getConfig().set("seriesList." + targetSeries + ".numberOfBlocks", numberOfElements);
  68.                             plugin.saveConfig();
  69.                             event.getPlayer().sendMessage(ChatColor.BOLD + "Added " + ChatColor.GREEN + x + ", " + y + ", " + z + ChatColor.RESET + "" + ChatColor.BOLD + " to series "+ ChatColor.GREEN + targetSeries);
  70.                             ConfigurationSection config4 = plugin.getConfig().getConfigurationSection("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo");
  71.                    
  72.                         }
  73.                        
  74.                     }
  75.                        
  76.                    
  77.                     if (!foundSeries) {
  78.                         event.getPlayer().sendMessage("Series " + ChatColor.RED + targetSeries + ChatColor.RESET + " not found");
  79.                     }
  80.                
  81.             } else if (event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
  82.                 int x = event.getClickedBlock().getX();
  83.                 int y = event.getClickedBlock().getY();
  84.                 int z = event.getClickedBlock().getZ();
  85.                 boolean foundSeries = false;
  86.                 boolean foundBlock = false;
  87.                
  88.                     if (plugin.getConfig().contains("seriesList." + targetSeries)) {
  89.                         foundSeries = true;
  90.                         int numberOfElements = plugin.getConfig().getInt("seriesList." + targetSeries + ".numberOfBlocks");
  91.                         ConfigurationSection config2 = plugin.getConfig().getConfigurationSection("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo");
  92.                        
  93.                         for (String bob : config2.getKeys(false)) {
  94.                             if ((plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +bob  + ".x") == x) &&
  95.                                     (plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +bob  + ".y") == y) &&
  96.                                     (plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +bob  + ".z") == z)) {
  97.                                 foundBlock = true;
  98.                                 plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +bob, null);
  99.                                 int tempDeleted = plugin.getConfig().getInt("seriesList." + targetSeries + ".deletedBlocks");
  100.                                 tempDeleted++;
  101.                                 plugin.getConfig().set("seriesList." + targetSeries + ".deletedBlocks", tempDeleted);
  102.                                 plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +bob, null);
  103.                                 plugin.saveConfig();
  104.  
  105.                                 plugin.saveConfig();
  106.                                 event.getPlayer().sendMessage(ChatColor.BOLD + "Deleted " + ChatColor.GREEN + x + ", " + y + ", " + z + ChatColor.RESET + "" + ChatColor.BOLD + " from series "+ ChatColor.GREEN + targetSeries);
  107.                                 ConfigurationSection config3 = plugin.getConfig().getConfigurationSection("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo");
  108.                                 String clickerUUID = event.getPlayer().getUniqueId().toString();    
  109.                                
  110.                                 ConfigurationSection config = plugin.getConfig().getConfigurationSection("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + bob + ".clickedPlayers");
  111.                                
  112.                                  List tempList = plugin.getConfig().getList("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + bob +".clickedPlayers");          
  113.                                  for (int p = 0; p <tempList.size();p++) {
  114.                                      if (tempList.get(p).equals(clickerUUID)){
  115.                                          int number = plugin.getConfig().getInt("playerProgress.seriesProgress." + tempList.get(p) + "." + targetSeries);
  116.                                          number--;
  117.                                          plugin.getConfig().set("playerProgress.seriesProgress." + tempList.get(p) + "." + targetSeries,number);
  118.                                      }
  119.                                  }
  120.                                    
  121.                                     }
  122.                                 }
  123.                         if (!foundBlock) {
  124.                             event.getPlayer().sendMessage("Block " + ChatColor.RED + x + ", " + y + ", " + z +  ChatColor.RESET + " not found within series");
  125.                         }
  126.                            
  127.  
  128.                             }
  129.                     if (!foundSeries) {
  130.                         event.getPlayer().sendMessage("Series " + ChatColor.RED + targetSeries + ChatColor.RESET + " not found");
  131.                     }
  132.                
  133.                
  134.                        
  135.                        
  136.                         }
  137.                        
  138.                
  139.                
  140.             }
  141.         } else {
  142.             if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getPlayer().getItemInHand().getType() != Material.GOLDEN_SWORD) {
  143.                 int x = event.getClickedBlock().getX();
  144.                 int y = event.getClickedBlock().getY();
  145.                 int z = event.getClickedBlock().getZ();
  146.                 ConfigurationSection config = plugin.getConfig().getConfigurationSection("seriesList");
  147.                
  148.                 for (String key : config.getKeys(false)) {
  149.                                                                                
  150.                     int seriesProgressCount = plugin.getConfig().getInt("playerProgress.seriesProgress." + event.getPlayer().getUniqueId().toString() + "."+ key);
  151.                    
  152.                         int numberOfElements = plugin.getConfig().getInt("seriesList." + key + ".numberOfBlocks");
  153.                         for (int i = 0; i < plugin.getConfig().getInt("seriesList." + key + ".numberOfBlocks"); i++) {
  154.                             int k = plugin.getConfig().getInt("seriesList." + key + ".arrayOfBlocks.BlockInfo." + i +".id");
  155.                        
  156.                            
  157.                             if ((plugin.getConfig().getInt("seriesList." + key + ".arrayOfBlocks.BlockInfo." +i  + ".x") == x) &&
  158.                                     (plugin.getConfig().getInt("seriesList." + key + ".arrayOfBlocks.BlockInfo." +i  + ".y") == y) &&
  159.                                     (plugin.getConfig().getInt("seriesList." + key + ".arrayOfBlocks.BlockInfo." +i  + ".z") == z)) {
  160.                                 String clickerUUID = event.getPlayer().getUniqueId().toString();                       
  161.                                  List tempList = plugin.getConfig().getList("seriesList." + key + ".arrayOfBlocks.BlockInfo." + i +".clickedPlayers");
  162.                                  boolean alreadyClicked = false;
  163.                                  for (int p = 0; p <tempList.size();p++) {
  164.                                      if (tempList.get(p).equals(clickerUUID)){
  165.                                          alreadyClicked = true;
  166.                                      }
  167.                                  }
  168.                                 ConfigurationSection config5 = plugin.getConfig().getConfigurationSection("seriesList." + key + ".arrayOfBlocks.BlockInfo");
  169.  
  170.                                  int count = 0;
  171.                                 for (String key3 : config5.getKeys(false)) {
  172.                                     count++;
  173.                                 }
  174.                                 int realNumberofElements = count;
  175.                                  if (!alreadyClicked) {
  176.                                      int deletedBlocks = plugin.getConfig().getInt("seriesList." + key + ".deletedBlocks");
  177.                                      
  178.                                      int outOf = plugin.getConfig().getInt("seriesList." + key + ".numberOfBlocks") - plugin.getConfig().getInt
  179.                                             ("seriesList." + key + ".deletedBlocks");
  180.                                     if (k==0) {
  181.                                         event.getPlayer().sendMessage("You found a block in the "
  182.                                                 + ChatColor.GREEN + key  + ChatColor.RESET + " series! That's " + ChatColor.BLUE + (seriesProgressCount+1 - deletedBlocks) + "/" + realNumberofElements + ChatColor.RESET + "!");
  183.                                     } else if (k==1) {
  184.                                         event.getPlayer().sendMessage("You found a block in the "
  185.                                                 + ChatColor.GREEN + key  + ChatColor.RESET + " series! That's " + ChatColor.BLUE + (seriesProgressCount+1 - deletedBlocks) + "/" + realNumberofElements + ChatColor.RESET + "!");
  186.                                        
  187.                                     } else if (k==2) {
  188.                                         event.getPlayer().sendMessage("You found a block in the "  
  189.                                                 + ChatColor.GREEN + key  + ChatColor.RESET + " series! That's " + ChatColor.BLUE + (seriesProgressCount+1 - deletedBlocks) + "/" + realNumberofElements + ChatColor.RESET + "!");
  190.                                     } else {
  191.                                         event.getPlayer().sendMessage("You found a block in the "
  192.                                                 + ChatColor.GREEN + key  + ChatColor.RESET + " series! That's " + ChatColor.BLUE + (seriesProgressCount+1 - deletedBlocks) + "/" + realNumberofElements + ChatColor.RESET + "!");
  193.                                     }
  194.                                    
  195.                                     if ((seriesProgressCount+1)/realNumberofElements == 1) {
  196.                                      String completionString = plugin.getConfig().getString("seriesList." + key + ".completionCommand");
  197.                                     completionString = completionString.replaceAll("player", event.getPlayer().getName());
  198.                                      ConsoleCommandSender console = plugin.getServer().getConsoleSender();
  199.                                       plugin.getServer().dispatchCommand(console, completionString);
  200.                                      event.getPlayer().sendMessage("Congratulations. You found all the blocks in the " + ChatColor.GREEN + key + ChatColor.RESET + " series!");
  201.                                  }
  202.                                    
  203.                                    
  204.                                      
  205.                                      seriesProgressCount++;
  206.                                      plugin.getConfig().set("playerProgress.seriesProgress." + event.getPlayer().getUniqueId().toString() + "."+ key, seriesProgressCount);
  207.                                      tempList.add(clickerUUID);
  208.                                      plugin.getConfig().set("seriesList." + key + ".arrayOfBlocks.BlockInfo." + i +".clickedPlayers", tempList);
  209.                                      plugin.saveConfig();
  210.                                  } else {
  211.                                      event.getPlayer().sendMessage(ChatColor.RED + "You've already found this " + key + "!");
  212.                                  }
  213.                                  
  214.                                  
  215.                        
  216.                                    
  217.                                     }
  218.                                 }
  219.                        
  220.  
  221.             }
  222.  
  223.         }
  224.     }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement