Exemple #1
0
 @Override
 public void run() {
   if (this.plugin.getBrManager().getGameStatus().equals(BRGameStatus.END)) {
     Bukkit.shutdown();
     return;
   }
   this.plugin.getBrManager().setGameStatus(BRGameStatus.END);
   BRUtils.announce(plugin, "¥µ©`¥Ð¤ò10Ãëáá¤ËÔÙÆð„Ó¤·¤Þ¤¹¡£");
   Player[] players = CommonUtil.getOnlinePlayers();
   for (int i = 0; i < players.length; i++) {
     for (int j = 0; j < players.length; j++) {
       players[i].showPlayer(players[j]);
     }
   }
   for (int i = 10; i > 0; i--) {
     try {
       if (i <= 5 || i == 10) BRUtils.announce(plugin, String.format("ÔÙÆð„Ó¤Þ¤Ç%dÃë", i));
       Thread.sleep(1000);
     } catch (InterruptedException e) {
       System.out.println(e);
     }
   }
   // Bukkit.shutdown();
   stopServer();
 }
  @Override
  public void onEnable() {
    this.log = this.getLogger();
    this.log.info("BattleRoyale configre preparing....");
    this.config = new File(this.getDataFolder(), "config.yml");
    if (!config.exists()) {
      this.saveDefaultConfig();
    }
    this.brManager = new BRManager();
    this.brManager.setGameStatus(BRGameStatus.OPENING);
    this.brConfig = new BRConfig();

    this.randomMapBlocks = BRUtils.getRundumMRMapBlocks();
    nextAreaBlocks = new ArrayList<String>();
    deadAreaBlocks = new ArrayList<String>();
    votemap = new HashMap<String, String>();
    this.createdBrBuilds = new ArrayList<String>();

    setBrBuilding(new HashMap<String, BRBuilding>());
    this.playerStat = new HashMap<String, BRPlayer>();
    this.setPlayerTask(new HashMap<String, BukkitTask>());

    // ¶ÁÈ¡´óÌÓɱ½¨ÖþÎï
    loadBRBuildings();

    // Ëæ»ú½¨ÖþÎï
    int buildNum = this.getConfig().getInt("brbuild.num");
    if (buildNum == 0) {
      this.getConfig().set("brbuild.num", 15);
      buildNum = 15;
      this.saveConfig();
    }
    createRundomBuild(buildNum);

    // Ö¸ÁîÔØÈë
    this.log.info("BattleRoyale commands preparing....");
    this.getCommand("setroom").setExecutor(new StartPosCmd(this));
    this.getCommand("brgame").setExecutor(new BrGame(this));
    this.getCommand("setbrarea").setExecutor(new GameArea(this));
    this.getCommand("brbuild").setExecutor(new BRBuildCmd(this));
    this.getCommand("brblist").setExecutor(new BRBuildList(this));
    this.getCommand("brvotemap").setExecutor(new BRMapChange(this));

    // ¼àÌýÔØÈë
    PluginManager pm = this.getServer().getPluginManager();
    pm.registerEvents(new BRPlayerListener(this), this);
    pm.registerEvents(new MapListener(this), this);

    this.log.info("BattleRoyale Enabled.");
  }
  public void createRundomBuild(int buildNum) {
    if (this.brBuilding.isEmpty()) {
      return;
    }

    World w = this.getServer().getWorlds().get(0);
    int hugo = 1;
    Random rand = new Random();
    for (int i = buildNum; i > 0; i--) {
      int x =
          w.getSpawnLocation().getBlockX()
              + ((rand.nextInt(360) + 60) * ((rand.nextInt(10) % 2) == 0 ? -1 : 1));
      int y = 64;
      int z =
          w.getSpawnLocation().getBlockZ()
              + ((rand.nextInt(360) + 60) * ((rand.nextInt(10) % 2) == 0 ? -1 : 1));

      // int bItem = (int)Math.floor(Math.random() * (this.brBuilding.size()-1)) ;
      int bItem = rand.nextInt(this.brBuilding.size());
      int j = 0;
      for (BRBuilding brb : this.brBuilding.values()) {
        if (j++ == bItem) {
          if ("classroom".equals(brb.getName()) || "lastbattle".equals(brb.getName())) {
            buildNum++;
            break;
          }
          y = w.getHighestBlockYAt(x, z);
          brb.create(w, new Location(w, x, y, z), true);
          System.out.println(String.format("%s¤ò×ù˜Ë£¨X:%d Y:%d Z:%d£©", brb.getName(), x, y, z));
          // this.createdBrBuilds.add(ChatColor.AQUA+brb.getName()+" -
          // "+ChatColor.GOLD+"×ù˜Ë(X:"+Integer.toString(x)+" Y:"+Integer.toString(y)+"
          // Z:"+Integer.toString(z)+")");
          this.createdBrBuilds.add(
              String.format("%s,%d,%d,%d", BRUtils.removeSuffixint(brb.getName()), x, y, z));
          break;
        }
      }
      hugo = hugo * -1;
    }
  }