SteamWar/MissileWars
Archiviert
13
0

Fix ItemCountdown for uneven Teams

Dieser Commit ist enthalten in:
yoyosource 2021-08-16 16:08:07 +02:00
Ursprung 42d2be974a
Commit b0bef0f778
2 geänderte Dateien mit 35 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -71,6 +71,21 @@ public class MWTeam {
sbteam.setColor(color);
}
public void countdown(int timeDelay, int offset) {
if (players.isEmpty()) {
return;
}
int i = 0;
for (Player p : players) {
int time = timeDelay * (i + 1) - offset;
i++;
p.setExp(time / (float) Config.ItemTime);
p.setLevel(0);
}
}
public void givePlayerItem(ItemStack item) {
if (players.isEmpty()) {
return;

Datei anzeigen

@ -33,25 +33,40 @@ import java.util.EnumSet;
public class ItemCountdown extends StateDependent {
private BukkitTask task;
private int lastTime = 0;
private int currenTime = 0;
public ItemCountdown() {
super(EnumSet.of(FightState.FIGHTING));
}
private void run() {
int itemCount = Math.max(MissileWars.getBlueTeam().size(), MissileWars.getRedTeam().size());
for (int i = 0; i < itemCount; i++) {
if (currenTime == 0) {
ItemStack itemStack = SpecialItem.getRandomItem();
MissileWars.getBlueTeam().givePlayerItem(itemStack);
MissileWars.getRedTeam().givePlayerItem(itemStack);
}
currenTime++;
int teamCount = Math.max(MissileWars.getBlueTeam().size(), MissileWars.getRedTeam().size());
if (teamCount == 0) return;
int timeDelay = Config.ItemTime / teamCount;
if (lastTime + timeDelay < currenTime) {
lastTime = currenTime;
ItemStack itemStack = SpecialItem.getRandomItem();
MissileWars.getBlueTeam().givePlayerItem(itemStack);
MissileWars.getRedTeam().givePlayerItem(itemStack);
}
MissileWars.getBlueTeam().countdown(timeDelay, currenTime - lastTime);
MissileWars.getRedTeam().countdown(timeDelay, currenTime - lastTime);
}
@Override
public void enable() {
task = Bukkit.getScheduler().runTaskTimer(MissileWars.getPlugin(), this::run, 0, Config.ItemTime);
task = Bukkit.getScheduler().runTaskTimer(MissileWars.getPlugin(), this::run, 0, 1);
}
@Override