示例#1
0
 static {
   //noinspection ConstantConditions
   COAL_MAP =
       ImmutableBiMap.<CoalType, Integer>builder()
           .put(CoalTypes.COAL, 0)
           .put(CoalTypes.CHARCOAL, 1)
           .build();
   //noinspection ConstantConditions
   COOKED_FISH_MAP =
       ImmutableBiMap.<CookedFish, Integer>builder()
           .put(CookedFishes.COD, 0)
           .put(CookedFishes.SALMON, 1)
           .build();
   //noinspection deprecation, ConstantConditions
   DYE_MAP =
       ImmutableBiMap.<DyeColor, Integer>builder()
           .put(DyeColors.BLACK, (int) org.bukkit.DyeColor.BLACK.getDyeData())
           .put(DyeColors.RED, (int) org.bukkit.DyeColor.RED.getDyeData())
           .put(DyeColors.GREEN, (int) org.bukkit.DyeColor.GREEN.getDyeData())
           .put(DyeColors.BROWN, (int) org.bukkit.DyeColor.BROWN.getDyeData())
           .put(DyeColors.BLUE, (int) org.bukkit.DyeColor.BLUE.getDyeData())
           .put(DyeColors.PURPLE, (int) org.bukkit.DyeColor.PURPLE.getDyeData())
           .put(DyeColors.CYAN, (int) org.bukkit.DyeColor.CYAN.getDyeData())
           .put(DyeColors.SILVER, (int) org.bukkit.DyeColor.SILVER.getDyeData())
           .put(DyeColors.GRAY, (int) org.bukkit.DyeColor.GRAY.getDyeData())
           .put(DyeColors.PINK, (int) org.bukkit.DyeColor.PINK.getDyeData())
           .put(DyeColors.LIME, (int) org.bukkit.DyeColor.LIME.getDyeData())
           .put(DyeColors.YELLOW, (int) org.bukkit.DyeColor.YELLOW.getDyeData())
           .put(DyeColors.LIGHT_BLUE, (int) org.bukkit.DyeColor.LIGHT_BLUE.getDyeData())
           .put(DyeColors.MAGENTA, (int) org.bukkit.DyeColor.MAGENTA.getDyeData())
           .put(DyeColors.ORANGE, (int) org.bukkit.DyeColor.ORANGE.getDyeData())
           .put(DyeColors.WHITE, (int) org.bukkit.DyeColor.WHITE.getDyeData())
           .build();
   //noinspection ConstantConditions
   FISH_MAP =
       ImmutableBiMap.<Fish, Integer>builder()
           .put(Fishes.COD, 0)
           .put(Fishes.SALMON, 1)
           .put(Fishes.CLOWNFISH, 2)
           .put(Fishes.PUFFERFISH, 3)
           .build();
   //noinspection ConstantConditions
   GOLDEN_APPLE_MAP =
       ImmutableBiMap.<GoldenApple, Integer>builder()
           .put(GoldenApples.GOLDEN_APPLE, 0)
           .put(GoldenApples.ENCHANTED_GOLDEN_APPLE, 1)
           .build();
 }
示例#2
0
  @EventHandler(priority = EventPriority.HIGHEST)
  private void onInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    PlayerDataClass playerData = plugin.getPlayerHandler().findPlayer(player.getDisplayName());

    if (playerData.getType() != null) {
      if (player.getItemInHand().getType() == Material.BOW
          && event.getAction() == Action.RIGHT_CLICK_BLOCK
          && (inJump.get(player) == null || inJump.get(player).equals(Boolean.FALSE))
          && playerData.getType().equalsIgnoreCase("soldier")) {

        if (player.getInventory().contains(Material.ARROW)) {
          player.getInventory().removeItem(new ItemStack(Material.ARROW, 1));
          player.updateInventory();
          player
              .getLocation()
              .getWorld()
              .createExplosion(
                  player.getLocation().getX(),
                  player.getLocation().getY(),
                  player.getLocation().getZ(),
                  0);

          // double rotation = player.getLocation().getPitch();

          // double jumpFactor = -(rotation / 20);
          // double distanceFactor = -((90 - rotation) * 10);

          Vector newDirection = player.getVelocity();
          inJump.put(player, true);
          /*if (jumpFactor < -1) {
          	newDirection.setY(newDirection.getY() * jumpFactor);
          }
          if (distanceFactor < -1) {
          	newDirection.setX(newDirection.getX() * distanceFactor);
          	newDirection.setZ(newDirection.getZ() * distanceFactor);
          }

          player.setVelocity(newDirection);*/
          Vector jumpDirection = player.getLocation().getDirection().multiply(-1.5);
          jumpDirection.setX(jumpDirection.getX() * 1.4);
          jumpDirection.setZ(jumpDirection.getZ() * 1.4);
          newDirection.setX(newDirection.getX() * -jumpDirection.getX());
          newDirection.setY(newDirection.getY() * -jumpDirection.getY());
          newDirection.setZ(newDirection.getZ() * -jumpDirection.getZ());
          player.setVelocity(jumpDirection);
          player.damage(3);
          plugin
              .getServer()
              .getScheduler()
              .scheduleSyncDelayedTask(
                  plugin,
                  new Runnable() {
                    public void run() {
                      inJump.put(player, false);
                    }
                  },
                  10L);
          return;
        }
      }
      /* if (player.getItemInHand().getType() == Material.BOW &&
      		event.getAction() == Action.RIGHT_CLICK_AIR &&
      		playerData.getType().equalsIgnoreCase("soldier")) {

           		if (player.getInventory().contains(Material.ARROW)) {
           			player.getInventory().removeItem(new ItemStack (Material.ARROW, 1));
           			player.updateInventory();
           			//Location loc = player.getLocation(); // Get the player Location
           			//loc.add(0, 1, 0); //Add 1 to the Y, makes the arrow go at chest level instead of feet

           			Location arrowLocation = player.getEyeLocation();
        			arrowLocation.setY(arrowLocation.getY() + 0.1);
                 Arrow sniperArrow = player.getWorld().spawnArrow(arrowLocation,
                 player.getLocation().getDirection(), 0.6f, 1);
                 sniperArrow.setShooter(player);
                 sniperArrow.setBounce(false);
                 //sniperArrow.setVelocity(player.getLocation().getDirection().normalize().multiply(12));
        		}

            	return;
      }	*/

      /*if (player.getItemInHand().getType() == Material.BOW &&
      		(event.getAction() == Action.LEFT_CLICK_AIR ||
      		event.getAction() == Action.LEFT_CLICK_BLOCK) &&
      		playerData.getType().equalsIgnoreCase("soldier")) {
      	event.setCancelled(true);
      	return;
      }	*/
      if (player.getItemInHand().getType() == Material.IRON_SWORD
          && (event.getAction() == Action.RIGHT_CLICK_AIR
              || event.getAction() == Action.RIGHT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("spy")) {

        plugin
            .getServer()
            .getWorld("world")
            .playEffect(player.getLocation(), Effect.EXTINGUISH, 40);

        if (playerData.getDisguised() == null) {
          if (playerData.getTeam() == "red") {
            if (plugin.getPlayerHandler().getBluePlayers().size() > 0) {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "blue");
              Random random = new Random();
              List<PlayerDataClass> temp = plugin.getPlayerHandler().getBluePlayers();
              int randomNumber = random.nextInt(temp.size());
              playerData.setDisguised(temp.get(randomNumber).getName());
              plugin.getPlayerLocationListener().getRedPlayersOnPoint().remove(playerData);
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            } else {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "blue");
              playerData.setDisguised(playerData.getName());
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            }
          }
          if (playerData.getTeam() == "blue") {
            if (plugin.getPlayerHandler().getRedPlayers().size() > 0) {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "red");
              Random random = new Random();
              List<PlayerDataClass> temp = plugin.getPlayerHandler().getRedPlayers();
              int randomNumber = random.nextInt(temp.size());
              playerData.setDisguised(temp.get(randomNumber).getName());
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            } else {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "red");
              playerData.setDisguised(playerData.getName());
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            }
          }
          return;
        } else {
          playerData.setDisguised(null);
          plugin.getPlayerHandler().giveArmor(playerData.getName(), playerData.getTeam());
          TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
          return;
        }
      }

      if ((event.getAction() == Action.LEFT_CLICK_AIR
              || event.getAction() == Action.LEFT_CLICK_BLOCK
              || event.getAction() == Action.RIGHT_CLICK_AIR
              || event.getAction() == Action.RIGHT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("spy")
          && playerData.getDisguised() != null) {
        playerData.setDisguised(null);
        plugin.getPlayerHandler().giveArmor(playerData.getName(), playerData.getTeam());
        TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
        return;
      }

      if (player.getItemInHand().getType() == Material.BOW
          && event.getAction() == Action.LEFT_CLICK_AIR
          && playerData.getType().equalsIgnoreCase("sniper")) {
        if (playerData.isScoped() == true) {
          setUnscoped(player, playerData);
        } else {
          setScoped(player, playerData);
        }
      }

      if (player.getItemInHand().getType() == Material.getMaterial(356)
          && (event.getAction() == Action.LEFT_CLICK_AIR
              || event.getAction() == Action.LEFT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("demo")) {
        plugin.getLogger().info("demo fired");

        Location stickyLocation = player.getEyeLocation();
        stickyLocation.setY(stickyLocation.getY() + 0.1);

        Item sticky;
        if (playerData.getTeam().equals("red")) {
          sticky =
              player
                  .getWorld()
                  .dropItemNaturally(
                      stickyLocation,
                      new ItemStack(
                          Material.INK_SACK, 1, (short) 0, (byte) (15 - DyeColor.RED.getData())));
          sticky.setMetadata("redsticky", new FixedMetadataValue(plugin, true));
        } else {
          sticky =
              player
                  .getWorld()
                  .dropItemNaturally(
                      stickyLocation,
                      new ItemStack(
                          Material.INK_SACK, 1, (short) 0, (byte) (15 - DyeColor.BLUE.getData())));
          sticky.setMetadata("bluesticky", new FixedMetadataValue(plugin, true));
        }

        // stickyBomb.setData(dye);
        // Item sticky = player.getWorld().dropItem(stickyLocation, stickyBomb);

        sticky.setVelocity(player.getEyeLocation().getDirection());

        StickyDataClass stickyData = new StickyDataClass();
        stickyData.setOwner(playerData.getName());
        stickyData.setSticky(sticky);
        stickyData.setTeam(playerData.getTeam());
        plugin.getStickysFired().add(stickyData);
      }

      if (player.getItemInHand().getType() == Material.getMaterial(356)
          && (event.getAction() == Action.RIGHT_CLICK_AIR
              || event.getAction() == Action.RIGHT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("demo")) {
        plugin.getLogger().info("demo triggered");
        event.setCancelled(true);
        for (int i = 0; i < plugin.getStickysFired().size(); i++) {
          StickyDataClass temp = plugin.getStickysFired().get(i);
          plugin.getLogger().info(i + " Owner/Team " + temp.getOwner() + "/" + temp.getTeam());
          if (temp.getOwner() == playerData.getName()) {
            plugin
                .getServer()
                .getWorld("world")
                .createExplosion(
                    temp.getSticky().getLocation().getX(),
                    temp.getSticky().getLocation().getY(),
                    temp.getSticky().getLocation().getZ(),
                    5,
                    false,
                    false);

            for (Entity nearby : temp.getSticky().getNearbyEntities(3, 3, 3)) {
              if (nearby instanceof Player) {
                Player nearbyPlayer = (Player) nearby;
                nearbyPlayer.damage(8, player);
              }
            }
            temp.getSticky().remove();
            plugin.getStickysFired().remove(i);
          }
        }
      }

    } else {
      return;
    }
  }
  @SuppressWarnings("deprecation")
  public static Inventory constructInventory(
      TitlesPlugin plugin, Player player, String cat, boolean owned) {
    DataContainer dataContainer = plugin.getDataContainer();
    Inventory inv = null;
    // if there are titles, construct category inventory
    if (!dataContainer.getTitles().isEmpty()) {
      List<String> categories = GetCommands.getCategories(dataContainer);
      List<ItemStack> clickables = new ArrayList<>();

      // get inventory with categories.
      if (cat == null) {

        if (owned) {
          List<Title> unlocked = dataContainer.getUnlockedTitles(player);
          for (Title title : unlocked) {
            ItemStack is;
            String name = title.getName();
            String description = title.getDescription();
            String status;

            if (dataContainer.getCurrentTitle(player) != null
                && dataContainer.getCurrentTitle(player).equals(title)) {
              is = new ItemStack(Material.WOOL, 1, DyeColor.LIME.getData());
              status = "Current";
            } else {
              is = new ItemStack(Material.WOOL, 1, DyeColor.GREEN.getData());
              status = "Unlocked";
            }
            ItemMeta meta = is.getItemMeta();
            meta.setDisplayName(name);
            meta.setLore(
                Arrays.asList(
                    "Description: " + description,
                    "Category: " + title.getCategory().getName(),
                    "Status: " + status));
            is.setItemMeta(meta);
            clickables.add(is);
          }

          int size = ((clickables.size() / 9) + 1) * 9;
          inv =
              Bukkit.createInventory(
                  null, size, ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Unlocked Titles");

          for (int i = 0; i < clickables.size(); i++) inv.setItem(i, clickables.get(i));

          // back button
          ItemStack is = new ItemStack(Material.WOOL, 1, DyeColor.GRAY.getData());
          ItemMeta meta = is.getItemMeta();
          meta.setDisplayName("Back");
          is.setItemMeta(meta);
          inv.setItem(inv.getSize() - 1, is);
          return inv;
        }

        for (String category : categories) {
          ItemStack is = new ItemStack(Material.WOOL, 1, DyeColor.GRAY.getData());
          ItemMeta meta = is.getItemMeta();
          meta.setDisplayName(category);
          is.setItemMeta(meta);
          clickables.add(is);
        }
        int size = ((clickables.size() / 9) + 1) * 9;
        inv =
            Bukkit.createInventory(
                null, size, ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Title categories");

        // get inventory with titles from category.
      } else {
        Category category = dataContainer.getCategory(cat);
        if (category == null) return null;
        List<Title> titles = dataContainer.getTitlesFromCategory(category);
        List<Title> ownedTitles = dataContainer.getUnlockedTitles(player);

        for (Title title : titles) {
          ItemStack is;
          String name = title.getName();
          String description = title.getDescription();
          String status;

          if (ownedTitles.contains(title)) {
            if (dataContainer.getCurrentTitle(player) != null
                && dataContainer.getCurrentTitle(player).equals(title)) {
              is = new ItemStack(Material.WOOL, 1, DyeColor.LIME.getData());
              status = "Current";
            } else {
              is = new ItemStack(Material.WOOL, 1, DyeColor.GREEN.getData());
              status = "Unlocked";
            }
          } else {
            Request request = dataContainer.getRequest(player);
            if (request != null
                && request.getTitle().equals(title)
                && request.getStatus() == RequestStatus.pending) {
              is = new ItemStack(Material.WOOL, 1, DyeColor.ORANGE.getData());
              status = "Pending";
            } else {
              is = new ItemStack(Material.WOOL, 1, DyeColor.RED.getData());
              status = "Locked";
            }
          }

          ItemMeta meta = is.getItemMeta();
          meta.setDisplayName(name);
          meta.setLore(
              Arrays.asList(
                  "Description: " + description,
                  "Category: " + category.getName(),
                  "Status: " + status));
          is.setItemMeta(meta);
          clickables.add(is);
        }
        int size = ((clickables.size() / 9) + 1) * 9;
        inv =
            Bukkit.createInventory(
                null, size, ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Titles in category");
      }

      for (int i = 0; i < clickables.size(); i++) inv.setItem(i, clickables.get(i));

      // back button
      if (cat != null) {
        ItemStack is = new ItemStack(Material.WOOL, 1, DyeColor.GRAY.getData());
        ItemMeta meta = is.getItemMeta();
        meta.setDisplayName("Back");
        is.setItemMeta(meta);
        inv.setItem(inv.getSize() - 1, is);

        // player's unlocked titles
      } else {
        ItemStack is = new ItemStack(Material.WOOL, 1, DyeColor.GREEN.getData());
        ItemMeta meta = is.getItemMeta();
        meta.setDisplayName("Unlocked");
        is.setItemMeta(meta);
        inv.setItem(inv.getSize() - 1, is);
      }

    } else Utils.sendError(player, "There are no titles yet.");
    return inv;
  }