public boolean startRound() { /// trying to start when we havent created anything yet /// or event was canceled/closed if (round < 0 || state == EventState.CLOSED) { return false; } announceRound(); Plugin plugin = BattleArena.getSelf(); /// Section to start the match curTimer = plugin .getServer() .getScheduler() .scheduleSyncDelayedTask( plugin, new Runnable() { public void run() { Round tr = rounds.get(round); for (Matchup m : tr.getMatchups()) { ac.addMatchup(m); } } }, (long) (timeBetweenRounds * 20L * Defaults.TICK_MULT)); return true; }
public void start() { System.out.println("Arena::onStart " + timedSpawns); if (timedSpawns != null && !timedSpawns.isEmpty()) { Plugin plugin = BattleArena.getSelf(); /// Create our Q, with a descending Comparator spawnQ = new PriorityQueue<NextSpawn>( timedSpawns.size(), new Comparator<NextSpawn>() { public int compare(NextSpawn o1, NextSpawn o2) { return (o1.timeToNext.compareTo(o2.timeToNext)); } }); /// TeamJoinResult our items into the Q ArrayList<NextSpawn> nextspawns = new ArrayList<NextSpawn>(); for (TimedSpawn is : timedSpawns.values()) { // System.out.println("itemSpawns = " + timedSpawns.size() + " " + // is.getFirstSpawnTime()+ " ts=" + is); long tts = is.getFirstSpawnTime(); if (tts == 0) is.spawn(); NextSpawn ns = new NextSpawn(is, tts); spawnQ.add(ns); nextspawns.add(ns); } timerId = plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new SpawnNextEvent(0L)); } }
private static BaseSerializer getSerializer(String name) { BaseSerializer bs = new BaseSerializer(); File dir = new File(BattleArena.getSelf().getDataFolder() + "/inventories/"); if (!dir.exists()) { dir.mkdirs(); } return bs.setConfig(dir.getPath() + "/" + name + ".yml") ? bs : null; }
public static void saveInventory(final String name, final PInv pinv) { if (Defaults.NUM_INV_SAVES <= 0) { return; } Bukkit.getScheduler() .scheduleAsyncDelayedTask( BattleArena.getSelf(), new Runnable() { @Override public void run() { BaseSerializer serializer = getSerializer(name); if (serializer == null) return; Date now = new Date(); String date = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(now); int curSection = serializer.config.getInt("curSection", 0); serializer.config.set("curSection", (curSection + 1) % Defaults.NUM_INV_SAVES); ConfigurationSection pcs = serializer.config.createSection(curSection + ""); pcs.set("storedDate", date); List<String> stritems = new ArrayList<String>(); for (ItemStack is : pinv.armor) { if (is == null || is.getType() == Material.AIR) continue; stritems.add(InventoryUtil.getItemString(is)); } pcs.set("armor", stritems); stritems = new ArrayList<String>(); for (ItemStack is : pinv.contents) { if (is == null || is.getType() == Material.AIR) continue; stritems.add(InventoryUtil.getItemString(is)); } pcs.set("contents", stritems); serializer.save(); } }); }
public TournamentEvent(EventParams params) { super(params); oParms = params; Bukkit.getPluginManager().registerEvents(this, BattleArena.getSelf()); }
public SpawnController(Map<Long, TimedSpawn> spawnGroups) { this.timedSpawns = spawnGroups; plugin = BattleArena.getSelf(); }
@ArenaEventHandler(bukkitPriority = org.bukkit.event.EventPriority.MONITOR) public void onPlayerDeath(ArenaPlayerDeathEvent event) { final ArenaPlayer target = event.getPlayer(); if (state == MatchState.ONCANCEL || state == MatchState.ONCOMPLETE) { return; } final ArenaTeam t = event.getTeam(); Integer nDeaths = t.addDeath(target); boolean exiting = event.isExiting() || !respawns || nDeaths >= nLivesPerPlayer; event.setExiting(exiting); final boolean trueDeath = event.getPlayerDeathEvent() != null; if (nLivesPerPlayer != ArenaSize.MAX) { int curLives = nLivesPerPlayer - nDeaths; SEntry e = scoreboard.getEntry(target.getPlayer()); if (e != null) scoreboard.setEntryNameSuffix(e, curLives <= 1 ? "" : "&4(" + curLives + ")"); } if (trueDeath) { PlayerDeathEvent pde = event.getPlayerDeathEvent(); if (cancelExpLoss) pde.setKeepLevel(true); /// Handle Drops from bukkitEvent if (clearsInventoryOnDeath || keepsInventory) { // / clear the drops try { pde.getDrops().clear(); } catch (Exception e) { if (!Defaults.DEBUG_VIRTUAL) Log.printStackTrace(e); } } else if (woolTeams) { /// Get rid of the wool from teams so it doesnt drop final int index = t.getIndex(); ItemStack teamHead = TeamUtil.getTeamHead(index); List<ItemStack> items = pde.getDrops(); for (ItemStack is : items) { if (is.getType() == teamHead.getType() && is.getDurability() == teamHead.getDurability()) { final int amt = is.getAmount(); if (amt > 1) is.setAmount(amt - 1); else is.setType(Material.AIR); break; } } } /// If keepInventory is specified, but not restoreAll, then we have a case /// where we need to give them back the current Inventory they have on them /// even if they log out if (keepsInventory) { boolean restores = getParams().hasOptionAt(MatchState.ONLEAVE, TransitionOption.RESTOREITEMS); /// Restores and exiting, means clear their match inventory so they won't /// get their match and their already stored inventory if (restores && exiting) { psc.clearMatchItems(target); } else { /// keep their current inv psc.storeMatchItems(target); } } /// We can't let them just sit on the respawn screen... schedule them to lose /// We will cancel this onRespawn final ArenaMatch am = this; Integer timer = deathTimer.get(target.getName()); if (timer != null) { Bukkit.getScheduler().cancelTask(timer); } timer = Bukkit.getScheduler() .scheduleSyncDelayedTask( BattleArena.getSelf(), new Runnable() { @Override public void run() { PerformTransition.transition(am, MatchState.ONCOMPLETE, target, t, true); checkAndHandleIfTeamDead(t); } }, 15 * 20L); deathTimer.put(target.getName(), timer); } if (exiting) { PerformTransition.transition(this, MatchState.ONCOMPLETE, target, t, true); checkAndHandleIfTeamDead(t); } }
@ArenaEventHandler(priority = EventPriority.HIGH) public void onPlayerRespawn(PlayerRespawnEvent event, final ArenaPlayer p) { if (Defaults.DEBUG_TRACE) MessageUtil.sendMessage(p, " -onPlayerRespawn t=" + p.getTeam()); if (isWon()) { return; } final TransitionOptions mo = tops.getOptions(MatchState.ONDEATH); if (mo == null) return; if (respawns) { final boolean randomRespawn = mo.randomRespawn(); /// Lets cancel our death respawn timer Integer timer = deathTimer.get(p.getName()); if (timer != null) { Bukkit.getScheduler().cancelTask(timer); } final Location loc; final ArenaTeam t = getTeam(p); if (mo.hasAnyOption( TransitionOption.TELEPORTLOBBY, TransitionOption.TELEPORTMAINLOBBY, TransitionOption.TELEPORTWAITROOM, TransitionOption.TELEPORTMAINWAITROOM)) { final int index = t.getIndex(); if (mo.hasOption(TransitionOption.TELEPORTLOBBY)) { loc = RoomController.getLobbySpawn(index, getParams().getType(), randomRespawn); } else if (mo.hasOption(TransitionOption.TELEPORTMAINLOBBY)) { loc = RoomController.getLobbySpawn( Defaults.MAIN_SPAWN, getParams().getType(), randomRespawn); } else if (mo.hasOption(TransitionOption.TELEPORTMAINWAITROOM)) { loc = this.getWaitRoomSpawn(Defaults.MAIN_SPAWN, randomRespawn); } else { loc = this.getWaitRoomSpawn(index, randomRespawn); } /// Should we respawn the player to the team spawn after a certain amount of time if (mo.hasOption(TransitionOption.RESPAWNTIME)) { int id = Bukkit.getScheduler() .scheduleSyncDelayedTask( BattleArena.getSelf(), new Runnable() { @Override public void run() { Integer id = respawnTimer.remove(p.getName()); Bukkit.getScheduler().cancelTask(id); Location loc = getTeamSpawn( index, tops.hasOptionAt( MatchState.ONSPAWN, TransitionOption.RANDOMRESPAWN)); TeleportController.teleport(p.getPlayer(), loc); } }, mo.getRespawnTime() * 20); respawnTimer.put(p.getName(), id); } } else { loc = getTeamSpawn(getTeam(p), randomRespawn); } event.setRespawnLocation(loc); /// For some reason, the player from onPlayerRespawn Event isnt the one in the main thread, so // we need to /// resync before doing any effects final Match am = this; Bukkit.getScheduler() .scheduleSyncDelayedTask( BattleArena.getSelf(), new Runnable() { public void run() { ArenaTeam t = getTeam(p); PerformTransition.transition(am, MatchState.ONDEATH, p, t, false); PerformTransition.transition(am, MatchState.ONSPAWN, p, t, false); if (respawnsWithClass) { ArenaClass ac = null; if (p.getPreferredClass() != null) { ac = p.getPreferredClass(); } else if (p.getCurrentClass() != null) { ac = p.getCurrentClass(); } if (ac != null) { ArenaClassController.giveClass(p, ac); } } if (keepsInventory) { psc.restoreMatchItems(p); } if (woolTeams) { TeamUtil.setTeamHead(t.getIndex(), p); } } }); } else { /// This player is now out of the system now that we have given the ondeath effects Location l = tops.hasOptionAt(MatchState.ONLEAVE, TransitionOption.TELEPORTTO) ? tops.getOptions(MatchState.ONLEAVE).getTeleportToLoc() : oldlocs.get(p.getName()); if (l != null) event.setRespawnLocation(l); } }