예제 #1
0
  private void inGameInteractEntity(PlayerInteractEntityEvent iee, Game game, Player player) {

    if (iee.getPlayer().getItemInHand().getType().equals(Material.MONSTER_EGG)
        || iee.getPlayer().getItemInHand().getType().equals(Material.MONSTER_EGGS)
        || iee.getPlayer().getItemInHand().getType().equals(Material.DRAGON_EGG)) {
      iee.setCancelled(true);
      return;
    }

    if (iee.getRightClicked() != null) {
      if (!iee.getRightClicked().getType().equals(EntityType.VILLAGER)) {
        List<EntityType> preventClickTypes = Arrays.asList(EntityType.ITEM_FRAME);

        // armor stand in 1.8
        try {
          preventClickTypes.add(EntityType.valueOf("ARMOR_STAND"));
        } catch (Exception ex) {
          // nothing will happen, just not supported
        }

        if (preventClickTypes.contains(iee.getRightClicked().getType())) {
          iee.setCancelled(true);
        }

        return;
      }
    }

    iee.setCancelled(true);

    if (game.isSpectator(player)) {
      return;
    }

    BedwarsOpenShopEvent openShopEvent =
        new BedwarsOpenShopEvent(game, player, game.getItemShopCategories(), iee.getRightClicked());
    Main.getInstance().getServer().getPluginManager().callEvent(openShopEvent);

    if (openShopEvent.isCancelled()) {
      return;
    }

    if (game.isUsingOldShop(player)) {
      MerchantCategory.openCategorySelection(player, game);
    } else {
      NewItemShop itemShop = game.getNewItemShop(player);
      if (itemShop == null) {
        itemShop = game.openNewItemShop(player);
      }

      itemShop.setCurrentCategory(null);
      itemShop.openCategoryInventory(player);
    }
  }
예제 #2
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  private void onIngameInventoryClick(InventoryClickEvent ice, Player player, Game game) {
    if (!ice.getInventory().getName().equals(Main._l("ingame.shop.name"))) {
      if (game.isSpectator(player)) {
        ItemStack clickedStack = ice.getCurrentItem();
        if (clickedStack == null) {
          return;
        }

        if (ice.getInventory().getName().equals(Main._l("ingame.spectator"))) {
          ice.setCancelled(true);
          if (!clickedStack.getType().equals(Material.SKULL_ITEM)) {
            return;
          }

          SkullMeta meta = (SkullMeta) clickedStack.getItemMeta();
          Player pl = Main.getInstance().getServer().getPlayer(meta.getOwner());
          if (pl == null) {
            return;
          }

          if (!game.isInGame(pl)) {
            return;
          }

          player.teleport(pl);
          player.closeInventory();
          return;
        }

        Material clickedMat = ice.getCurrentItem().getType();
        if (clickedMat.equals(Material.SLIME_BALL)) {
          game.playerLeave(player, false);
        }

        if (clickedMat.equals(Material.COMPASS)) {
          game.openSpectatorCompass(player);
        }
      }
      return;
    }

    ice.setCancelled(true);
    ItemStack clickedStack = ice.getCurrentItem();

    if (clickedStack == null) {
      return;
    }

    if (game.isUsingOldShop(player)) {
      try {
        if (clickedStack.getType() == Material.SNOW_BALL) {
          game.notUseOldShop(player);

          // open new shop
          NewItemShop itemShop = game.openNewItemShop(player);
          itemShop.setCurrentCategory(null);
          itemShop.openCategoryInventory(player);
          return;
        }

        MerchantCategory cat = game.getItemShopCategories().get(clickedStack.getType());
        if (cat == null) {
          return;
        }

        Class clazz =
            Class.forName(
                "io.github.yannici.bedwars.Com."
                    + Main.getInstance().getCurrentVersion()
                    + ".VillagerItemShop");
        Object villagerItemShop =
            clazz
                .getDeclaredConstructor(Game.class, Player.class, MerchantCategory.class)
                .newInstance(game, player, cat);

        Method openTrade = clazz.getDeclaredMethod("openTrading", new Class[] {});
        openTrade.invoke(villagerItemShop, new Object[] {});
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    } else {
      game.getNewItemShop(player).handleInventoryClick(ice, game, player);
    }
  }