SteamWar/FightSystem
Archiviert
13
1

Merge branch 'master' into spectate2.0

Dieser Commit ist enthalten in:
Lixfel 2021-08-21 10:25:53 +02:00
Commit 84577ccae9
5 geänderte Dateien mit 273 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -30,5 +30,6 @@ public enum Winconditions {
POINTS,
TIME_TECH_KO,
WATER_TECH_KO,
PUMPKIN_TECH_KO
PUMPKIN_TECH_KO,
HELLS_BELLS
}

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.core.CommandRemover;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.commands.*;
import de.steamwar.fightsystem.countdown.*;
import de.steamwar.fightsystem.event.HellsBells;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.fight.FightWorld;
@ -76,7 +77,7 @@ public class FightSystem extends JavaPlugin {
new DenyWorldInteraction();
new EventJoin();
new Recording();
//new ResourcePack();
// new ResourcePack();
new Check();
new Shutdown();
new SetupQuit();
@ -108,6 +109,9 @@ public class FightSystem extends JavaPlugin {
new RankedPlayerLeftWincondition();
new WinconditionPercentTimeout();
//noinspection InstantiationOfUtilityClass
new HellsBells();
new NoPlayersOnlineCountdown();
new PreSchemCountdown();
new PostSchemCountdown();

Datei anzeigen

@ -0,0 +1,263 @@
/*
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;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.countdown.SWSound;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.winconditions.Winconditions;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.scheduler.BukkitTask;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
public class HellsBells {
public static final Random random = new Random();
private final World world = Bukkit.getWorlds().get(0);
private final int xLength = Config.RedExtendRegion.getMaxX() - Config.RedExtendRegion.getMinX();
private final int zLength = Config.RedExtendRegion.getMaxZ() - Config.RedExtendRegion.getMinZ();
private State current = State.PRE;
private int currentDrops = 0;
private HellsBellsCountdown currentCountdown;
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.");
private final List<String> stateSwapMessages = Arrays.asList("§aDie Bomben fallen nun schneller.",
"§aMehr Bomber im Anflug.",
"§aZusätzliche Bomber gesichtet.",
"§aDas Bombardement scheint sich zu erhöhen.");
public void startCountdown() {
if (current == State.PRE) {
Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size()))));
current = current.getNext();
} else if (current != State.LAST && currentDrops >= current.SWITCH_AFTER) {
Bukkit.broadcastMessage(FightSystem.PREFIX + (stateSwapMessages.get(random.nextInt(stateSwapMessages.size()))));
currentDrops = 0;
}
currentDrops++;
currentCountdown = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME));
currentCountdown.enable();
}
public void drop() {
Direction direction = Direction.getRandom();
AtomicInteger length = new AtomicInteger(20 + random.nextInt(direction.getLength(zLength, xLength) - 20));
int width = 5 + random.nextInt(5);
Bukkit.getLogger().log(Level.INFO, "Calculating Starts");
int xOffset = getStart(direction.getLength(xLength, zLength), direction.getLength(length.get(), width));
int zOffset = getStart(direction.getLength(zLength, xLength), direction.getLength(width, length.get()));
int yOffset = getHeightStart();
Point redStart;
Point blueStart;
if (direction.isNorthOrWest()) {
redStart = new Point(Config.RedExtendRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedExtendRegion.getMaxZ() - zOffset);
blueStart = new Point(Config.BlueExtendRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BlueExtendRegion.getMinZ() + zOffset);
} else {
redStart = new Point(Config.RedExtendRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedExtendRegion.getMinZ() + zOffset);
blueStart = new Point(Config.BlueExtendRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BlueExtendRegion.getMaxZ() - zOffset);
}
currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> {
for (int w = 0; w < width; w++) {
if (direction.isNorthOrWest()) {
world.spawnEntity(redStart.addAndToLocation(world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (direction.dz * length.get() + w * direction.other().dz)), EntityType.PRIMED_TNT);
world.spawnEntity(blueStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT);
} else {
world.spawnEntity(redStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT);
world.spawnEntity(blueStart.addAndToLocation(world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (direction.dz * length.get() + w * direction.other().dz)), EntityType.PRIMED_TNT);
}
}
if (length.addAndGet(-2) <= 0) {
currentDropping.cancel();
}
}, 0L, 4L);
}
private int getStart(int regionSize, int length) {
double randomNumber = (random.nextDouble() - random.nextDouble()) / 2 + 0.5;
Bukkit.getLogger().log(Level.INFO, "Calculated Start: " + (int) (randomNumber * (regionSize - length)));
return Math.max(Math.min((int) (randomNumber * (regionSize - length)), regionSize - length), 0);
}
private int getHeightStart() {
return 5 + random.nextInt(15);
}
public HellsBells() {
new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) {
@Override
public void enable() {
startCountdown();
}
@Override
public void disable() {
currentCountdown.disable();
}
}.register();
}
private class HellsBellsCountdown extends Countdown {
public HellsBellsCountdown(int time) {
super(time, SWSound.BLOCK_NOTE_BASS, true);
}
@Override
public String countdownCounting() {
return "bis die Bomben fallen";
}
@Override
public void countdownFinished() {
drop();
startCountdown();
}
}
private static class Point {
private final int x;
private final int y;
private final int z;
public Point(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public Location addAndToLocation(World world, int x, int y, int z) {
return new Location(world, this.x + x, this.y + y, this.z + z); //NOSONAR
}
}
private enum State {
PRE(60, 80, 1),
FIRST(40, 60, 3),
SECOND(30, 40, 4),
THIRD(20, 30, 4),
FOURTH(10, 20, 5),
LAST(5, 10, 0);
State(int minTime, int maxTime, int switchAfter) {
this.MIN_TIME = minTime;
this.MAX_TIME = maxTime;
this.SWITCH_AFTER = switchAfter;
}
private final int MIN_TIME; //NOSONAR
private final int MAX_TIME; //NOSONAR
private final int SWITCH_AFTER; //NOSONAR
public State getNext() {
switch (this) {
case PRE:
return FIRST;
case FIRST:
return SECOND;
case SECOND:
return THIRD;
case THIRD:
return FOURTH;
case FOURTH:
case LAST:
return LAST;
default:
return PRE;
}
}
}
private enum Direction {
NORTH(0, 0, 1),
SOUTH(0, 0, -1),
EAST(1, 0, 0),
WEST(-1, 0, 0);
int dx;
int dy;
int dz;
Direction(int dx, int dy, int dz) {
this.dx = dx;
this.dy = dy;
this.dz = dz;
}
public static Direction getRandom() {
return Direction.values()[random.nextInt(Direction.values().length)];
}
Direction other() {
switch (this) {
case NORTH:
return EAST;
case SOUTH:
return WEST;
case EAST:
return NORTH;
case WEST:
return SOUTH;
default:
return this;
}
}
public int getLength(int length1, int length2) {
return isNorthOrSouth() ? length1 : length2;
}
public boolean isNorthOrSouth() {
return this == NORTH || this == SOUTH;
}
public boolean isNorthOrWest() {
return this == NORTH || this == WEST;
}
}
}

Datei anzeigen

@ -21,7 +21,6 @@ package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -29,17 +28,15 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
public class ArrowStopper implements Listener {
public class ArrowStopper {
private static final Vector NULL_VECTOR = new Vector(0, 0, 0);
private static final BlockFace[] BLOCK_FACES = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
public ArrowStopper() {
new StateDependentListener(Config.TechhiderActive, FightState.Running, this);
new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1);
}
@ -85,7 +82,7 @@ public class ArrowStopper implements Listener {
}
private boolean checkBlock(Block block) {
return Config.HiddenBlocks.contains(block.getType().name());
return Config.HiddenBlocks.contains(block.getType().name().toLowerCase());
}
private boolean invalidEntity(Arrow entity) {

Datei anzeigen

@ -82,7 +82,7 @@ public class TechHider extends StateDependent {
public void onPacketReceiving(PacketEvent e) {
Player p = e.getPlayer();
if(p.getGameMode() == GameMode.SPECTATOR)
if(p == null || p.getGameMode() == GameMode.SPECTATOR)
e.setCancelled(true);
}
});