Fix ItemCountdown for uneven Teams
Dieser Commit ist enthalten in:
Ursprung
42d2be974a
Commit
b0bef0f778
@ -71,6 +71,21 @@ public class MWTeam {
|
|||||||
sbteam.setColor(color);
|
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) {
|
public void givePlayerItem(ItemStack item) {
|
||||||
if (players.isEmpty()) {
|
if (players.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -33,25 +33,40 @@ import java.util.EnumSet;
|
|||||||
public class ItemCountdown extends StateDependent {
|
public class ItemCountdown extends StateDependent {
|
||||||
|
|
||||||
private BukkitTask task;
|
private BukkitTask task;
|
||||||
|
private int lastTime = 0;
|
||||||
|
private int currenTime = 0;
|
||||||
|
|
||||||
public ItemCountdown() {
|
public ItemCountdown() {
|
||||||
super(EnumSet.of(FightState.FIGHTING));
|
super(EnumSet.of(FightState.FIGHTING));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void run() {
|
private void run() {
|
||||||
int itemCount = Math.max(MissileWars.getBlueTeam().size(), MissileWars.getRedTeam().size());
|
if (currenTime == 0) {
|
||||||
|
|
||||||
for (int i = 0; i < itemCount; i++) {
|
|
||||||
ItemStack itemStack = SpecialItem.getRandomItem();
|
ItemStack itemStack = SpecialItem.getRandomItem();
|
||||||
|
|
||||||
MissileWars.getBlueTeam().givePlayerItem(itemStack);
|
MissileWars.getBlueTeam().givePlayerItem(itemStack);
|
||||||
MissileWars.getRedTeam().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
|
@Override
|
||||||
public void enable() {
|
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
|
@Override
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren