예제 #1
0
  @SuppressWarnings("deprecation")
  private void onLobbyInventoryClick(InventoryClickEvent ice, Player player, Game game) {
    Inventory inv = ice.getInventory();
    ItemStack clickedStack = ice.getCurrentItem();

    if (!inv.getTitle().equals(Main._l("lobby.chooseteam"))) {
      ice.setCancelled(true);
      return;
    }

    if (clickedStack == null) {
      ice.setCancelled(true);
      return;
    }

    if (clickedStack.getType() != Material.WOOL) {
      return;
    }

    ice.setCancelled(true);
    Team team = game.getTeamByDyeColor(DyeColor.getByData(clickedStack.getData().getData()));
    if (team == null) {
      return;
    }

    game.playerJoinTeam(player, team);
    player.closeInventory();
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onInteractEntity(PlayerInteractEntityEvent event) {
    if (event.getRightClicked() == null) {
      return;
    }

    Entity entity = event.getRightClicked();
    Player player = event.getPlayer();
    if (!player.hasMetadata("bw-addteamjoin")) {
      if (!(entity instanceof LivingEntity)) {
        return;
      }

      LivingEntity livEntity = (LivingEntity) entity;
      Game game = Main.getInstance().getGameManager().getGameOfPlayer(player);
      if (game == null) {
        return;
      }

      if (game.getState() != GameState.WAITING) {
        return;
      }

      Team team = game.getTeam(ChatColor.stripColor(livEntity.getCustomName()));
      if (team == null) {
        return;
      }

      game.playerJoinTeam(player, team);
      event.setCancelled(true);
      return;
    }

    List<MetadataValue> values = player.getMetadata("bw-addteamjoin");
    if (values == null || values.size() == 0) {
      return;
    }

    event.setCancelled(true);
    TeamJoinMetaDataValue value = (TeamJoinMetaDataValue) values.get(0);
    if (!((boolean) value.value())) {
      return;
    }

    if (!(entity instanceof LivingEntity)) {
      player.sendMessage(
          ChatWriter.pluginMessage(ChatColor.RED + Main._l("errors.entitynotcompatible")));
      return;
    }

    LivingEntity living = (LivingEntity) entity;
    living.setRemoveWhenFarAway(false);
    living.setCanPickupItems(false);
    living.setCustomName(value.getTeam().getChatColor() + value.getTeam().getDisplayName());
    living.setCustomNameVisible(
        Main.getInstance().getBooleanConfig("jointeam-entity.show-name", true));

    if (Utils.isSupportingTitles()) {
      if (living.getType().equals(EntityType.valueOf("ARMOR_STAND"))) {
        Utils.equipArmorStand(living, value.getTeam());
      }
    }

    player.removeMetadata("bw-addteamjoin", Main.getInstance());
    player.sendMessage(
        ChatWriter.pluginMessage(
            ChatColor.GREEN
                + Main._l(
                    "success.teamjoinadded",
                    ImmutableMap.of(
                        "team",
                        value.getTeam().getChatColor()
                            + value.getTeam().getDisplayName()
                            + ChatColor.GREEN))));
  }