SteamWar/FightSystem
Archiviert
13
1
Dieser Commit ist enthalten in:
Zeanon 2021-05-18 19:58:31 +02:00
Ursprung 2c981f29ce
Commit 25190098d6

Datei anzeigen

@ -1,3 +1,22 @@
/*
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/>.
*/
package de.steamwar.fightsystem.event;
import de.steamwar.fightsystem.Config;
@ -17,6 +36,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import org.bukkit.scheduler.BukkitTask;
public class HellsBells {
@ -66,59 +86,21 @@ public class HellsBells {
public HellsBells() {
new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) {
private HellsBellsEvent event = null;
@Override
public void enable() {
if (event != null) {
event.terminate();
}
event = new HellsBellsEvent();
event.init();
}
@Override
public void disable() {
if (event != null) {
event.terminate();
}
event = null;
}
}.register();
}
private static class HellsBellsEvent {
private final World world = Bukkit.getWorlds().get(0);
private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX();
private final int zLength = Config.RedPasteRegion.getMaxZ() - Config.RedPasteRegion.getMinZ();
private State current = State.NONE;
private State current = State.PRE;
private int currentDrops = 0;
private HellsBellsCountdown currentCountdown;
private static final List<String> startMessages = Arrays.asList("§c!!Achtung!! Bomber im Anflug, noch ca. eine Minute bis zur Ankunft.",
private BukkitTask currentDropping;
private final List<String> startMessages = Arrays.asList("§c!!Achtung!! Bomber im Anflug, noch ca. eine Minute bis zur Ankunft.",
"§cBomber im Anflug, ca. eine Minute bis zur Ankunft.",
"§cBomber auf dem Radar gesichtet, geschätzte Ankunftszeit: eine Minute.",
"§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.",
"§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.",
"§cBomber erschienen, Ankunft ca. eine Minute.");
public void init() {
current = State.PRE;
currentDrops = 0;
currentCountdown = null;
startCountdown();
}
public void terminate() {
current = State.NONE;
if (currentCountdown != null) {
currentCountdown.disable();
}
}
public void startCountdown() {
if (current != State.NONE) {
if (current == State.PRE) {
Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size()))));
current = current.getNext();
@ -131,7 +113,6 @@ public class HellsBells {
currentCountdown = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME), SWSound.BLOCK_NOTE_BASS, true);
currentCountdown.enable();
}
}
public void drop() {
Direction direction = Direction.getRandom();
@ -153,9 +134,7 @@ public class HellsBells {
blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset);
}
new BukkitRunnable() {
@Override
public void run() {
currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> {
for (int w = 0; w < width; w++) {
if (direction == Direction.NORTH || direction == Direction.WEST) {
world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT);
@ -167,12 +146,10 @@ public class HellsBells {
world.spawnEntity(blueStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT);
}
}
if (length.addAndGet(-2) <= 0) {
cancel();
currentDropping.cancel();
}
}
}.runTaskTimer(FightSystem.getPlugin(), 0, 4L);
}, 0L, 4L);
}
private int getLengthStart(int regionSize, int length) {
@ -187,7 +164,7 @@ public class HellsBells {
return 5 + random.nextInt(15);
}
private class HellsBellsCountdown extends Countdown {
class HellsBellsCountdown extends Countdown {
public HellsBellsCountdown(int time, SWSound sound, boolean level) {
super(time, sound, level);
@ -206,6 +183,18 @@ public class HellsBells {
}
}
@Override
public void enable() {
startCountdown();
}
@Override
public void disable() {
currentCountdown.disable();
}
}.register();
}
private static class Point {
private final int x;
@ -267,5 +256,4 @@ public class HellsBells {
}
}
}
}
}