Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.aidan.coordinateheads;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.UUID;
- import org.bukkit.ChatColor;
- import org.bukkit.Material;
- import org.bukkit.Server;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.command.ConsoleCommandSender;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.inventory.EquipmentSlot;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.Plugin;
- public class CoordinateListener implements Listener {
- private Plugin plugin = HeadQuest.getPlugin(HeadQuest.class);
- static int[] blockCoords = new int [3];
- @EventHandler
- public void listener(PlayerInteractEvent e) {
- onPlayerInteract(e, blockCoords);
- }
- public void onPlayerInteract(PlayerInteractEvent event, int [] chosenBlock) {
- EquipmentSlot e = event.getHand();
- if (e.equals(EquipmentSlot.HAND)) {
- if (event.getPlayer().getItemInHand().getType() == Material.GOLDEN_SWORD && event.getPlayer().isOp()) {
- String targetSeries = event.getPlayer().getItemInHand().getItemMeta().getDisplayName().substring(14);
- if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
- int x = event.getClickedBlock().getX();
- int y = event.getClickedBlock().getY();
- int z = event.getClickedBlock().getZ();
- boolean foundSeries = false;
- boolean foundBlock = false;
- if (plugin.getConfig().contains("seriesList." + targetSeries)) {
- foundSeries = true;
- int numberOfElements = plugin.getConfig().getInt("seriesList." + targetSeries + ".numberOfBlocks");
- for (int i = 0; i < plugin.getConfig().getInt("seriesList." + targetSeries + ".numberOfBlocks"); i++) {
- if ((plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +i + ".x") == x) &&
- (plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +i + ".y") == y) &&
- (plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +i + ".z") == z)) {
- foundBlock = true;
- event.getPlayer().sendMessage(ChatColor.BOLD + "Block " + ChatColor.RED + x + ", " + y + ", " + z + ChatColor.RESET + "" + ChatColor.BOLD + " already in series ");
- }
- }
- if (!foundBlock) {
- ArrayList<UUID> tempList = new ArrayList<UUID>();
- plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + numberOfElements +".id", numberOfElements);
- plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + numberOfElements +".x", x);
- plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + numberOfElements +".y", y);
- plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + numberOfElements +".z", z);
- plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + numberOfElements +".clickedPlayers", tempList);
- numberOfElements++;
- plugin.getConfig().set("seriesList." + targetSeries + ".numberOfBlocks", numberOfElements);
- plugin.saveConfig();
- event.getPlayer().sendMessage(ChatColor.BOLD + "Added " + ChatColor.GREEN + x + ", " + y + ", " + z + ChatColor.RESET + "" + ChatColor.BOLD + " to series "+ ChatColor.GREEN + targetSeries);
- ConfigurationSection config4 = plugin.getConfig().getConfigurationSection("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo");
- }
- }
- if (!foundSeries) {
- event.getPlayer().sendMessage("Series " + ChatColor.RED + targetSeries + ChatColor.RESET + " not found");
- }
- } else if (event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
- int x = event.getClickedBlock().getX();
- int y = event.getClickedBlock().getY();
- int z = event.getClickedBlock().getZ();
- boolean foundSeries = false;
- boolean foundBlock = false;
- if (plugin.getConfig().contains("seriesList." + targetSeries)) {
- foundSeries = true;
- int numberOfElements = plugin.getConfig().getInt("seriesList." + targetSeries + ".numberOfBlocks");
- ConfigurationSection config2 = plugin.getConfig().getConfigurationSection("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo");
- for (String bob : config2.getKeys(false)) {
- if ((plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +bob + ".x") == x) &&
- (plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +bob + ".y") == y) &&
- (plugin.getConfig().getInt("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +bob + ".z") == z)) {
- foundBlock = true;
- plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +bob, null);
- int tempDeleted = plugin.getConfig().getInt("seriesList." + targetSeries + ".deletedBlocks");
- tempDeleted++;
- plugin.getConfig().set("seriesList." + targetSeries + ".deletedBlocks", tempDeleted);
- plugin.getConfig().set("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." +bob, null);
- plugin.saveConfig();
- plugin.saveConfig();
- event.getPlayer().sendMessage(ChatColor.BOLD + "Deleted " + ChatColor.GREEN + x + ", " + y + ", " + z + ChatColor.RESET + "" + ChatColor.BOLD + " from series "+ ChatColor.GREEN + targetSeries);
- ConfigurationSection config3 = plugin.getConfig().getConfigurationSection("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo");
- String clickerUUID = event.getPlayer().getUniqueId().toString();
- ConfigurationSection config = plugin.getConfig().getConfigurationSection("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + bob + ".clickedPlayers");
- List tempList = plugin.getConfig().getList("seriesList." + targetSeries + ".arrayOfBlocks.BlockInfo." + bob +".clickedPlayers");
- for (int p = 0; p <tempList.size();p++) {
- if (tempList.get(p).equals(clickerUUID)){
- int number = plugin.getConfig().getInt("playerProgress.seriesProgress." + tempList.get(p) + "." + targetSeries);
- number--;
- plugin.getConfig().set("playerProgress.seriesProgress." + tempList.get(p) + "." + targetSeries,number);
- }
- }
- }
- }
- if (!foundBlock) {
- event.getPlayer().sendMessage("Block " + ChatColor.RED + x + ", " + y + ", " + z + ChatColor.RESET + " not found within series");
- }
- }
- if (!foundSeries) {
- event.getPlayer().sendMessage("Series " + ChatColor.RED + targetSeries + ChatColor.RESET + " not found");
- }
- }
- }
- } else {
- if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getPlayer().getItemInHand().getType() != Material.GOLDEN_SWORD) {
- int x = event.getClickedBlock().getX();
- int y = event.getClickedBlock().getY();
- int z = event.getClickedBlock().getZ();
- ConfigurationSection config = plugin.getConfig().getConfigurationSection("seriesList");
- for (String key : config.getKeys(false)) {
- int seriesProgressCount = plugin.getConfig().getInt("playerProgress.seriesProgress." + event.getPlayer().getUniqueId().toString() + "."+ key);
- int numberOfElements = plugin.getConfig().getInt("seriesList." + key + ".numberOfBlocks");
- for (int i = 0; i < plugin.getConfig().getInt("seriesList." + key + ".numberOfBlocks"); i++) {
- int k = plugin.getConfig().getInt("seriesList." + key + ".arrayOfBlocks.BlockInfo." + i +".id");
- if ((plugin.getConfig().getInt("seriesList." + key + ".arrayOfBlocks.BlockInfo." +i + ".x") == x) &&
- (plugin.getConfig().getInt("seriesList." + key + ".arrayOfBlocks.BlockInfo." +i + ".y") == y) &&
- (plugin.getConfig().getInt("seriesList." + key + ".arrayOfBlocks.BlockInfo." +i + ".z") == z)) {
- String clickerUUID = event.getPlayer().getUniqueId().toString();
- List tempList = plugin.getConfig().getList("seriesList." + key + ".arrayOfBlocks.BlockInfo." + i +".clickedPlayers");
- boolean alreadyClicked = false;
- for (int p = 0; p <tempList.size();p++) {
- if (tempList.get(p).equals(clickerUUID)){
- alreadyClicked = true;
- }
- }
- ConfigurationSection config5 = plugin.getConfig().getConfigurationSection("seriesList." + key + ".arrayOfBlocks.BlockInfo");
- int count = 0;
- for (String key3 : config5.getKeys(false)) {
- count++;
- }
- int realNumberofElements = count;
- if (!alreadyClicked) {
- int deletedBlocks = plugin.getConfig().getInt("seriesList." + key + ".deletedBlocks");
- int outOf = plugin.getConfig().getInt("seriesList." + key + ".numberOfBlocks") - plugin.getConfig().getInt
- ("seriesList." + key + ".deletedBlocks");
- if (k==0) {
- event.getPlayer().sendMessage("You found a block in the "
- + ChatColor.GREEN + key + ChatColor.RESET + " series! That's " + ChatColor.BLUE + (seriesProgressCount+1 - deletedBlocks) + "/" + realNumberofElements + ChatColor.RESET + "!");
- } else if (k==1) {
- event.getPlayer().sendMessage("You found a block in the "
- + ChatColor.GREEN + key + ChatColor.RESET + " series! That's " + ChatColor.BLUE + (seriesProgressCount+1 - deletedBlocks) + "/" + realNumberofElements + ChatColor.RESET + "!");
- } else if (k==2) {
- event.getPlayer().sendMessage("You found a block in the "
- + ChatColor.GREEN + key + ChatColor.RESET + " series! That's " + ChatColor.BLUE + (seriesProgressCount+1 - deletedBlocks) + "/" + realNumberofElements + ChatColor.RESET + "!");
- } else {
- event.getPlayer().sendMessage("You found a block in the "
- + ChatColor.GREEN + key + ChatColor.RESET + " series! That's " + ChatColor.BLUE + (seriesProgressCount+1 - deletedBlocks) + "/" + realNumberofElements + ChatColor.RESET + "!");
- }
- if ((seriesProgressCount+1)/realNumberofElements == 1) {
- String completionString = plugin.getConfig().getString("seriesList." + key + ".completionCommand");
- completionString = completionString.replaceAll("player", event.getPlayer().getName());
- ConsoleCommandSender console = plugin.getServer().getConsoleSender();
- plugin.getServer().dispatchCommand(console, completionString);
- event.getPlayer().sendMessage("Congratulations. You found all the blocks in the " + ChatColor.GREEN + key + ChatColor.RESET + " series!");
- }
- seriesProgressCount++;
- plugin.getConfig().set("playerProgress.seriesProgress." + event.getPlayer().getUniqueId().toString() + "."+ key, seriesProgressCount);
- tempList.add(clickerUUID);
- plugin.getConfig().set("seriesList." + key + ".arrayOfBlocks.BlockInfo." + i +".clickedPlayers", tempList);
- plugin.saveConfig();
- } else {
- event.getPlayer().sendMessage(ChatColor.RED + "You've already found this " + key + "!");
- }
- }
- }
- }
- }
- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement