mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
#40: Start games after 30s if enough players joined (UNTESTED)
This commit is contained in:
parent
7716ed0cad
commit
4766790cab
@ -25,6 +25,7 @@ import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.task.AnnouncerStartGameTask;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -66,6 +67,8 @@ public class Announcer {
|
||||
private List<DGroup> dGroups;
|
||||
private List<ItemStack> buttons;
|
||||
|
||||
private AnnouncerStartGameTask startTask;
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* the script file
|
||||
@ -265,6 +268,20 @@ public class Announcer {
|
||||
return maxPlayersPerGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the DGroups
|
||||
*/
|
||||
public List<DGroup> getDGroups() {
|
||||
return dGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the buttons that represent the DGroups
|
||||
*/
|
||||
public List<ItemStack> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount
|
||||
* the amount to set
|
||||
@ -273,6 +290,21 @@ public class Announcer {
|
||||
maxPlayersPerGroup = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the start task
|
||||
*/
|
||||
public AnnouncerStartGameTask getStartTask() {
|
||||
return startTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the start task and sets it to null.
|
||||
*/
|
||||
public void endStartTask() {
|
||||
startTask.cancel();
|
||||
startTask = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the announcement
|
||||
*/
|
||||
@ -359,7 +391,12 @@ public class Announcer {
|
||||
}
|
||||
|
||||
if (i >= minGroupsPerGame) {
|
||||
|
||||
if (startTask == null) {
|
||||
startTask = new AnnouncerStartGameTask(this);
|
||||
startTask.runTaskLater(plugin, 20 * 30L);
|
||||
} else {
|
||||
startTask.getProgressBar().addPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.task;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.announcer.Announcer;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.util.ProgressBar;
|
||||
import java.util.HashSet;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class AnnouncerStartGameTask extends BukkitRunnable {
|
||||
|
||||
private Announcer announcer;
|
||||
private ProgressBar bar;
|
||||
|
||||
public AnnouncerStartGameTask(Announcer announcer) {
|
||||
this.announcer = announcer;
|
||||
|
||||
HashSet<Player> players = new HashSet<>();
|
||||
for (DGroup dGroup : announcer.getDGroups()) {
|
||||
for (Player player : dGroup.getPlayers()) {
|
||||
players.add(player);
|
||||
}
|
||||
}
|
||||
bar = new ProgressBar(players, 30);
|
||||
bar.runTaskTimer(DungeonsXL.getInstance(), 0L, 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the progress bar the players see until they get teleported
|
||||
*/
|
||||
public ProgressBar getProgressBar() {
|
||||
return bar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Game game = new Game(announcer.getDGroups().get(0), announcer.getMapName());
|
||||
|
||||
for (DGroup dGroup : announcer.getDGroups()) {
|
||||
game.getDGroups().set(announcer.getDGroups().indexOf(dGroup), dGroup);
|
||||
}
|
||||
|
||||
for (Player player : game.getPlayers()) {
|
||||
new DGamePlayer(player, game.getWorld());
|
||||
}
|
||||
|
||||
announcer.endStartTask();
|
||||
}
|
||||
|
||||
}
|
@ -20,6 +20,8 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -32,29 +34,50 @@ public class ProgressBar extends BukkitRunnable {
|
||||
|
||||
public static final String BAR = "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
|
||||
|
||||
private Set<Player> players = new HashSet<>();
|
||||
private Set<UUID> players = new HashSet<>();
|
||||
private int seconds;
|
||||
private int secondsLeft;
|
||||
|
||||
public ProgressBar(Set<Player> players, int seconds) {
|
||||
this.players = players;
|
||||
for (Player player : players) {
|
||||
this.players.add(player.getUniqueId());
|
||||
}
|
||||
this.seconds = seconds;
|
||||
this.secondsLeft = seconds;
|
||||
}
|
||||
|
||||
public ProgressBar(Player player, int seconds) {
|
||||
this.players.add(player);
|
||||
this.players.add(player.getUniqueId());
|
||||
this.seconds = seconds;
|
||||
this.secondsLeft = seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* the player to add
|
||||
*/
|
||||
public void addPlayer(Player player) {
|
||||
players.add(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* the player to remove
|
||||
*/
|
||||
public void removePlayer(Player player) {
|
||||
players.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int i = (int) Math.round(((double) secondsLeft / (double) seconds) * 10);
|
||||
StringBuilder bar = new StringBuilder(BAR);
|
||||
bar.insert(10 - i, ChatColor.DARK_RED.toString());
|
||||
for (Player player : players) {
|
||||
MessageUtil.sendActionBarMessage(player, ChatColor.GREEN.toString() + bar.toString());
|
||||
for (UUID uuid : players) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null && player.isOnline()) {
|
||||
MessageUtil.sendActionBarMessage(player, ChatColor.GREEN.toString() + bar.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (secondsLeft == 0) {
|
||||
@ -68,14 +91,14 @@ public class ProgressBar extends BukkitRunnable {
|
||||
* Send the progress bar to a player
|
||||
*/
|
||||
public static BukkitTask sendProgressBar(Player player, int seconds) {
|
||||
return new ProgressBar(player, seconds).runTaskTimer(DungeonsXL.getInstance(), 0, 20);
|
||||
return new ProgressBar(player, seconds).runTaskTimer(DungeonsXL.getInstance(), 0L, 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the progress bar to multiple players
|
||||
*/
|
||||
public static BukkitTask sendProgressBar(Set<Player> players, int seconds) {
|
||||
return new ProgressBar(players, seconds).runTaskTimer(DungeonsXL.getInstance(), 0, 20);
|
||||
return new ProgressBar(players, seconds).runTaskTimer(DungeonsXL.getInstance(), 0L, 20L);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user