コード例 #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);
  }
コード例 #2
0
  public void setup() {
    baseDir = new File(SurvivalGames.getPluginDataFolder() + "/ArenaData/");
    try {
      if (!baseDir.exists()) {
        baseDir.mkdirs();
      }
      for (Game g : GameManager.getInstance().getGames()) {
        ensureFile(g.getID());
      }

    } catch (Exception e) {
    }

    Bukkit.getScheduler()
        .runTaskTimerAsynchronously(
            GameManager.getInstance().getPlugin(), new DataDumper(), 100, 100);
  }
コード例 #3
0
    public void run() {

      ArrayList<BlockData> data = queue.get(id);
      if (data != null) {
        int a = data.size() - 1;
        int rb = 0;
        while (a >= 0 && (rb < 100 || shutdown)) {
          SurvivalGames.debug("Reseting " + a);
          BlockData result = data.get(a);
          if (result.getGameId() == game.getID()) {

            data.remove(a);
            Location l =
                new Location(
                    Bukkit.getWorld(result.getWorld()),
                    result.getX(),
                    result.getY(),
                    result.getZ());
            Block b = l.getBlock();
            b.setTypeIdAndData(result.getPrevid(), result.getPrevdata(), false);
            b.getState().update();

            /*	if(result.getItems() != null){
            	Chest c = (Chest)b;
            	c.getBlockInventory().setContents(result.getItems());
            }
             */

            rb++;
          }
          a--;
        }

        if (a != -1) {
          Bukkit.getScheduler()
              .scheduleSyncDelayedTask(
                  GameManager.getInstance().getPlugin(), new Rollback(id, shutdown), 1);
        } else {
          SurvivalGames.$("Arena " + id + " reset. ");
          game.resetCallback();
        }
      } else {
        SurvivalGames.$(" Arena " + id + " reset. ");
        game.resetCallback();
      }
    }
コード例 #4
0
  public void saveGame(int arenaid, Player winner, int players, long time) {
    if (!enabled) return;
    int gameno = 0;
    Game g = GameManager.getInstance().getGame(arenaid);

    try {
      long time1 = new Date().getTime();
      PreparedStatement s2 =
          dbman.createStatement(
              "SELECT * FROM "
                  + SettingsManager.getSqlPrefix()
                  + "gamestats ORDER BY gameno DESC LIMIT 1");
      ResultSet rs = s2.executeQuery();
      rs.next();
      gameno = rs.getInt(1) + 1;

      if (time1 + 5000 < new Date().getTime())
        System.out.println(
            "Your database took a long time to respond. Check the connection between the server and database");
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      g.setRBStatus("Error: getno");
    }

    addSQL(
        "INSERT INTO "
            + SettingsManager.getSqlPrefix()
            + "gamestats VALUES(NULL,"
            + arenaid
            + ","
            + players
            + ",'"
            + winner.getName()
            + "',"
            + time
            + ")");

    for (PlayerStatsSession s : arenas.get(arenaid).values()) {
      s.setGameID(gameno);
      addSQL(s.createQuery());
    }
    arenas.get(arenaid).clear();
  }
コード例 #5
0
  public void onDisable() {
    disabling = false;
    PluginDescriptionFile pdfFile = p.getDescription();
    SettingsManager.getInstance().saveSpawns();
    SettingsManager.getInstance().saveSystemConfig();
    for (Game g : GameManager.getInstance().getGames()) {
      try {
        g.disable();
      } catch (Exception e) {
        // will throw useless "tried to register task blah blah error." Use the method below to
        // reset the arena without a task.
      }
      QueueManager.getInstance().rollback(g.getID(), true);
    }

    logger.info(
        pdfFile.getName()
            + " version "
            + pdfFile.getVersion()
            + " has now been disabled and reset");
  }
コード例 #6
0
  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;
  }
コード例 #7
0
 @Override
 public boolean onCommand(Player player, String[] args) {
   if (!player.hasPermission(permission()) && !player.isOp()) {
     MessageManager.getInstance()
         .sendFMessage(MessageManager.PrefixType.ERROR, "error.nopermission", player.getName());
     return true;
   }
   try {
     if (args.length == 0) {
       for (Game g : GameManager.getInstance().getGames()) {
         QueueManager.getInstance().rollback(g.getID(), true);
         g.disable();
       }
       MessageManager.getInstance()
           .sendFMessage(
               MessageManager.PrefixType.INFO, "game.all", player.getName(), "input-disabled");
     } else {
       Game g = GameManager.getInstance().getGame(Integer.parseInt(args[0]));
       g.disable();
       QueueManager.getInstance().rollback(g.getID(), true);
       MessageManager.getInstance()
           .sendFMessage(
               MessageManager.PrefixType.INFO,
               "game.state",
               player.getName(),
               "arena-" + args[0],
               "input-disabled");
     }
   } catch (NumberFormatException e) {
     MessageManager.getInstance()
         .sendFMessage(
             MessageManager.PrefixType.ERROR, "error.notanumber", player.getName(), "input-Arena");
   } catch (NullPointerException e) {
     MessageManager.getInstance()
         .sendFMessage(
             MessageManager.PrefixType.ERROR,
             "error.gamedoesntexist",
             player.getName(),
             "arena-" + args[0]);
   }
   return true;
 }