Пример #1
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onBlockBreak(BlockBreakEvent event) {
    Player p = event.getPlayer();
    int pid = GameManager.getInstance().getPlayerGameId(p);

    if (pid == -1) {
      int blockgameid = GameManager.getInstance().getBlockGameId(event.getBlock().getLocation());

      if (blockgameid != -1) {
        if (GameManager.getInstance().getGame(blockgameid).getGameMode()
            != Game.GameMode.DISABLED) {
          event.setCancelled(true);
        }
      }
      return;
    }

    Game g = GameManager.getInstance().getGame(pid);

    if (g.getMode() == Game.GameMode.DISABLED) {
      return;
    }
    if (g.getMode() != Game.GameMode.INGAME) {
      event.setCancelled(true);
      return;
    }

    if (!allowedBreak.contains(event.getBlock().getTypeId())) event.setCancelled(true);
  }
  public boolean onCommand(Player player, String[] args) {

    if (!player.hasPermission("sg.staff.forcestart") && !player.isOp()) {
      player.sendMessage(ChatColor.RED + "No Permission");
      return true;
    }
    int game = -1;
    int seconds = 10;
    if (args.length == 2) {
      seconds = Integer.parseInt(args[1]);
    }
    if (args.length >= 1) {
      game = Integer.parseInt(args[0]);

    } else game = GameManager.getInstance().getPlayerGameId(player);
    if (game == -1) {
      player.sendMessage(ChatColor.RED + "Must be in a game!");
      return true;
    }
    if (GameManager.getInstance().getGame(game).getActivePlayers() < 2) {
      player.sendMessage(ChatColor.RED + "Needs at least 2 players to start!");
      return true;
    }

    Game g = GameManager.getInstance().getGame(game);
    if (g.getMode() != Game.GameMode.WAITING && !player.hasPermission("sg.arena.restart")) {
      player.sendMessage(ChatColor.RED + "Game Already Starting!");
      return true;
    }
    g.countdown(seconds);
    for (Player pl : g.getAllPlayers()) {
      msgmgr.sendMessage(PrefixType.INFO, "Game starting in " + seconds + " seconds!", pl);
    }
    player.sendMessage(ChatColor.GREEN + "Started arena " + game);

    return true;
  }