HellsBells #275
@ -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;
|
package de.steamwar.fightsystem.event;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
@ -17,6 +36,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
|
||||||
public class HellsBells {
|
public class HellsBells {
|
||||||
@ -66,59 +86,21 @@ public class HellsBells {
|
|||||||
public HellsBells() {
|
public HellsBells() {
|
||||||
new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) {
|
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 World world = Bukkit.getWorlds().get(0);
|
||||||
private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX();
|
private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX();
|
||||||
private final int zLength = Config.RedPasteRegion.getMaxZ() - Config.RedPasteRegion.getMinZ();
|
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 int currentDrops = 0;
|
||||||
private HellsBellsCountdown currentCountdown;
|
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.",
|
||||||
Zeanon markierte diese Unterhaltung als gelöst
|
|||||||
"§cBomber im Anflug, 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.",
|
"§cBomber auf dem Radar gesichtet, geschätzte Ankunftszeit: eine Minute.",
|
||||||
"§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.",
|
"§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.",
|
||||||
"§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.",
|
"§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.",
|
||||||
"§cBomber erschienen, Ankunft ca. eine 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() {
|
public void startCountdown() {
|
||||||
if (current != State.NONE) {
|
|
||||||
if (current == State.PRE) {
|
if (current == State.PRE) {
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size()))));
|
Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size()))));
|
||||||
current = current.getNext();
|
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 = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME), SWSound.BLOCK_NOTE_BASS, true);
|
||||||
currentCountdown.enable();
|
currentCountdown.enable();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void drop() {
|
public void drop() {
|
||||||
Direction direction = Direction.getRandom();
|
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);
|
blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
new BukkitRunnable() {
|
currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (int w = 0; w < width; w++) {
|
for (int w = 0; w < width; w++) {
|
||||||
if (direction == Direction.NORTH || direction == Direction.WEST) {
|
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);
|
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);
|
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) {
|
if (length.addAndGet(-2) <= 0) {
|
||||||
cancel();
|
currentDropping.cancel();
|
||||||
}
|
}
|
||||||
}
|
}, 0L, 4L);
|
||||||
}.runTaskTimer(FightSystem.getPlugin(), 0, 4L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getLengthStart(int regionSize, int length) {
|
private int getLengthStart(int regionSize, int length) {
|
||||||
@ -187,7 +164,7 @@ public class HellsBells {
|
|||||||
return 5 + random.nextInt(15);
|
return 5 + random.nextInt(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class HellsBellsCountdown extends Countdown {
|
class HellsBellsCountdown extends Countdown {
|
||||||
|
|
||||||
public HellsBellsCountdown(int time, SWSound sound, boolean level) {
|
public HellsBellsCountdown(int time, SWSound sound, boolean level) {
|
||||||
super(time, sound, 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 static class Point {
|
||||||
|
|
||||||
private final int x;
|
private final int x;
|
||||||
@ -268,4 +257,3 @@ public class HellsBells {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
In neuem Issue referenzieren
Einen Benutzer sperren
Das StateDependent sollte nur die Sachen (de-)aktivieren, nicht das ganze Behaviour innehaben. Um die Nestung zu verringern: Nimm den ganzen Code bis auf die Enable und Disable und bewege den in die HellsBells-Klasse. (Also die übergeordnete)