SteamWar/MissileWars
Archiviert
13
0
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
MissileWars/src/de/steamwar/misslewars/countdowns/ItemCountdown.java

63 Zeilen
1.9 KiB
Java

2020-09-04 16:12:14 +02:00
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2020-06-24 15:26:10 +02:00
package de.steamwar.misslewars.countdowns;
2020-09-26 11:39:25 +02:00
import de.steamwar.misslewars.Config;
import de.steamwar.misslewars.FightState;
import de.steamwar.misslewars.MissileWars;
import de.steamwar.misslewars.StateDependent;
2020-06-24 15:26:10 +02:00
import de.steamwar.misslewars.items.SpecialItem;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
2020-09-26 11:39:25 +02:00
import java.util.EnumSet;
2020-06-24 15:26:10 +02:00
public class ItemCountdown extends StateDependent {
private BukkitTask task;
public ItemCountdown() {
super(EnumSet.of(FightState.FIGHTING));
}
2020-11-01 13:24:11 +01:00
private void run() {
2020-09-26 20:45:37 +02:00
int itemCount = Math.max(MissileWars.getBlueTeam().size(), MissileWars.getRedTeam().size());
2020-09-26 11:39:25 +02:00
2020-09-26 20:45:37 +02:00
for (int i = 0; i < itemCount; i++) {
2020-09-26 11:39:25 +02:00
ItemStack itemStack = SpecialItem.getRandomItem();
2020-06-24 15:26:10 +02:00
2020-09-26 20:43:50 +02:00
MissileWars.getBlueTeam().givePlayerItem(itemStack);
MissileWars.getRedTeam().givePlayerItem(itemStack);
2020-06-24 15:26:10 +02:00
}
}
@Override
public void enable() {
2020-06-24 18:24:00 +02:00
task = Bukkit.getScheduler().runTaskTimer(MissileWars.getPlugin(), this::run, 0, Config.ItemTime);
2020-06-24 15:26:10 +02:00
}
@Override
public void disable() {
2020-06-24 18:24:00 +02:00
if(task != null && !task.isCancelled())
2020-06-24 15:26:10 +02:00
task.cancel();
}
}