2020-08-26 18:24:44 +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/>.
|
|
|
|
*/
|
|
|
|
|
2019-09-05 18:26:13 +02:00
|
|
|
package de.steamwar.fightsystem;
|
|
|
|
|
2020-05-31 18:56:50 +02:00
|
|
|
import de.steamwar.core.CommandRemover;
|
2020-02-01 14:28:46 +01:00
|
|
|
import de.steamwar.core.Core;
|
2019-09-05 18:26:13 +02:00
|
|
|
import de.steamwar.fightsystem.commands.*;
|
|
|
|
import de.steamwar.fightsystem.countdown.*;
|
|
|
|
import de.steamwar.fightsystem.fight.Fight;
|
|
|
|
import de.steamwar.fightsystem.fight.FightPlayer;
|
|
|
|
import de.steamwar.fightsystem.fight.FightTeam;
|
|
|
|
import de.steamwar.fightsystem.kit.KitManager;
|
|
|
|
import de.steamwar.fightsystem.listener.*;
|
2020-07-11 07:17:10 +02:00
|
|
|
import de.steamwar.fightsystem.record.RecordSystem;
|
2020-08-22 19:18:11 +02:00
|
|
|
import de.steamwar.fightsystem.record.Recorder;
|
2020-01-11 12:53:31 +01:00
|
|
|
import de.steamwar.fightsystem.states.FightState;
|
|
|
|
import de.steamwar.fightsystem.states.StateDependent;
|
2020-11-02 18:07:09 +01:00
|
|
|
import de.steamwar.fightsystem.utils.EnterHandler;
|
|
|
|
import de.steamwar.fightsystem.utils.FightScoreboard;
|
|
|
|
import de.steamwar.fightsystem.utils.FightStatistics;
|
|
|
|
import de.steamwar.fightsystem.utils.TechHider;
|
2019-09-05 18:26:13 +02:00
|
|
|
import de.steamwar.fightsystem.winconditions.*;
|
2019-11-10 17:29:59 +01:00
|
|
|
import de.steamwar.sql.EventFight;
|
2020-04-30 16:09:24 +02:00
|
|
|
import de.steamwar.sql.Schematic;
|
2019-09-05 18:26:13 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Objects;
|
2020-05-31 18:56:50 +02:00
|
|
|
import java.util.logging.Level;
|
2019-09-05 18:26:13 +02:00
|
|
|
|
|
|
|
public class FightSystem extends JavaPlugin {
|
|
|
|
|
|
|
|
public static final String PREFIX = "§eArena§8» ";
|
|
|
|
private static FightSystem plugin;
|
|
|
|
|
2020-01-11 12:53:31 +01:00
|
|
|
private static FightState fightState = FightState.PRE_LEADER_SETUP;
|
|
|
|
private static Map<StateDependent, Boolean> stateDependentFeatures = new HashMap<>();
|
2019-09-05 18:26:13 +02:00
|
|
|
private static int fightTime = 0;
|
2020-01-11 15:44:40 +01:00
|
|
|
private static Countdown mainCountdown;
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2019-11-16 08:37:33 +01:00
|
|
|
@Override
|
|
|
|
public void onLoad() {
|
|
|
|
setPlugin(this);
|
2020-09-08 09:52:25 +02:00
|
|
|
IFightSystem.init(this);
|
2019-11-16 08:37:33 +01:00
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2019-11-16 08:37:33 +01:00
|
|
|
Fight.init();
|
2019-09-05 18:26:13 +02:00
|
|
|
KitManager.loadAllKits();
|
2020-01-11 15:44:40 +01:00
|
|
|
TechHider.init();
|
|
|
|
FightScoreboard.init();
|
2020-11-02 18:07:09 +01:00
|
|
|
RecordSystem.init();
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-05-31 18:56:50 +02:00
|
|
|
try {
|
|
|
|
CommandRemover.removeAll("gamemode");
|
|
|
|
CommandInjector.injectCommand(new GamemodeCommand());
|
|
|
|
} catch (Exception e) {
|
|
|
|
getLogger().log(Level.SEVERE, "Failed to replace commands", e);
|
|
|
|
Bukkit.shutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-05 18:26:13 +02:00
|
|
|
new EntityDamageListener();
|
|
|
|
new EntityExplodeListener();
|
|
|
|
new FoodLevelChangeListener();
|
|
|
|
new PistonListener();
|
|
|
|
new PlayerChatListener();
|
|
|
|
new HotbarGUIListener();
|
|
|
|
new PlayerMoveListener();
|
2020-01-11 12:53:31 +01:00
|
|
|
new PlayerStateListener();
|
2019-09-05 18:26:13 +02:00
|
|
|
new ProjectileLaunchListener();
|
2020-01-11 12:53:31 +01:00
|
|
|
new InFightDamageListener();
|
2020-05-22 16:40:27 +02:00
|
|
|
new InFightInventoryListener();
|
2020-01-11 15:44:40 +01:00
|
|
|
new FreezeWorldStateListener();
|
|
|
|
new EventJoinListener();
|
2020-07-04 10:49:49 +02:00
|
|
|
new EventRecordListener();
|
2020-04-30 16:09:24 +02:00
|
|
|
new CheckListener();
|
2020-01-11 15:44:40 +01:00
|
|
|
new TestListener();
|
|
|
|
new NormalJoinListener();
|
2020-07-19 15:55:16 +02:00
|
|
|
new RankedJoinListener();
|
2020-09-08 15:58:56 +02:00
|
|
|
new GameplayListener();
|
2020-08-18 17:31:05 +02:00
|
|
|
new PersonalKitCreator();
|
2020-02-01 14:28:46 +01:00
|
|
|
if(Core.getVersion() > 8)
|
2020-09-08 15:58:56 +02:00
|
|
|
new VersionDependentListener();
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-06-22 09:40:29 +02:00
|
|
|
new EnterHandler();
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
new WinconditionAllDead();
|
|
|
|
new WinconditionCaptainDead();
|
|
|
|
new WinconditionPumpkinTechKO();
|
|
|
|
new WinconditionWaterTechKO();
|
|
|
|
new WinconditionPercentSystem();
|
|
|
|
new WinconditionRelativePercent();
|
|
|
|
new WinconditionPoints();
|
|
|
|
new WinconditionTimeout();
|
|
|
|
new WinconditionHeartRatioTimeout();
|
|
|
|
new WinconditionTechKO();
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
Objects.requireNonNull(getCommand("leave")).setExecutor(new LeaveCommand());
|
|
|
|
Objects.requireNonNull(getCommand("kit")).setExecutor(new KitCommand());
|
|
|
|
Objects.requireNonNull(getCommand("remove")).setExecutor(new RemoveCommand());
|
|
|
|
Objects.requireNonNull(getCommand("accept")).setExecutor(new AcceptCommand());
|
|
|
|
Objects.requireNonNull(getCommand("decline")).setExecutor(new DeclineCommand());
|
|
|
|
Objects.requireNonNull(getCommand("invite")).setExecutor(new InviteCommand());
|
|
|
|
Objects.requireNonNull(getCommand("ready")).setExecutor(new ReadyCommand());
|
|
|
|
Objects.requireNonNull(getCommand("ak")).setExecutor(new AkCommand());
|
|
|
|
Objects.requireNonNull(getCommand("leader")).setExecutor(new LeaderCommand());
|
|
|
|
Objects.requireNonNull(getCommand("lockschem")).setExecutor(new LockschemCommand());
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
mainCountdown = new NoPlayersOnlineCountdown();
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-07-07 17:56:35 +02:00
|
|
|
if(Config.event() || Config.Ranked) {
|
2020-01-11 15:44:40 +01:00
|
|
|
Objects.requireNonNull(getCommand("invite")).setExecutor(new EventDummyCommand());
|
|
|
|
Objects.requireNonNull(getCommand("ready")).setExecutor(new EventDummyCommand());
|
|
|
|
Objects.requireNonNull(getCommand("ak")).setExecutor(new EventDummyCommand());
|
|
|
|
Objects.requireNonNull(getCommand("leader")).setExecutor(new EventDummyCommand());
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
setPreSchemState();
|
2019-09-05 18:26:13 +02:00
|
|
|
}else if(Config.test()){
|
2020-04-30 16:09:24 +02:00
|
|
|
if(Config.check()){
|
|
|
|
Bukkit.getScheduler().runTaskLater(this, () -> Fight.getBlueTeam().setSchematic(Schematic.getSchemFromDB(Config.CheckSchemID)), 0);
|
|
|
|
}else{
|
|
|
|
Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0);
|
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
Bukkit.getScheduler().runTaskLater(this, Fight.getRedTeam()::pasteDummy, 0);
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
setPreSchemState();
|
|
|
|
setPostSchemState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-22 19:18:11 +02:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
|
|
|
|
|
|
|
Recorder.closeAll();
|
|
|
|
}
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
public static void setPreSchemState() {
|
|
|
|
if(fightState != FightState.PRE_LEADER_SETUP)
|
|
|
|
throw new SecurityException(fightState.name());
|
|
|
|
setFightState(FightState.PRE_SCHEM_SETUP);
|
|
|
|
|
2020-01-18 08:31:13 +01:00
|
|
|
Fight.calcAvailibleSchemTypes();
|
2020-01-11 15:56:31 +01:00
|
|
|
mainCountdown = new PreSchemPasteCountdown();
|
2020-01-11 15:44:40 +01:00
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
public static void setPostSchemState() {
|
|
|
|
if(fightState != FightState.PRE_SCHEM_SETUP)
|
|
|
|
throw new SecurityException(fightState.name());
|
|
|
|
setFightState(FightState.POST_SCHEM_SETUP);
|
|
|
|
|
2020-04-11 12:06:01 +02:00
|
|
|
TechHider.start();
|
2020-01-11 15:44:40 +01:00
|
|
|
if(!Config.test()){
|
|
|
|
Fight.getBlueTeam().pasteSchematic();
|
|
|
|
Fight.getRedTeam().pasteSchematic();
|
2019-09-05 18:26:13 +02:00
|
|
|
}
|
2020-01-11 15:44:40 +01:00
|
|
|
|
2020-02-10 14:31:37 +01:00
|
|
|
if(Config.test())
|
2020-01-11 15:44:40 +01:00
|
|
|
mainCountdown = null;
|
|
|
|
else
|
|
|
|
mainCountdown = new SetupOverCountdown();
|
2019-09-05 18:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void setPreRunningState() {
|
2020-01-11 15:44:40 +01:00
|
|
|
if(fightState != FightState.POST_SCHEM_SETUP)
|
|
|
|
throw new SecurityException(fightState.name());
|
2019-09-05 18:26:13 +02:00
|
|
|
setFightState(FightState.PRE_RUNNING);
|
|
|
|
|
2020-01-23 17:40:48 +01:00
|
|
|
Fight.getBlueTeam().loadKits();
|
|
|
|
Fight.getRedTeam().loadKits();
|
2019-09-05 18:26:13 +02:00
|
|
|
setAllPlayersGM(GameMode.SURVIVAL);
|
|
|
|
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
mainCountdown = new PreRunningCountdown();
|
2019-09-06 20:06:05 +02:00
|
|
|
|
2019-12-09 20:37:18 +01:00
|
|
|
Fight.replaceSync();
|
2019-12-06 22:51:26 +01:00
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
if(Config.event())
|
2019-09-05 18:26:13 +02:00
|
|
|
new EventTeamOffWincondition();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setRunningState() {
|
|
|
|
if(fightState != FightState.PRE_RUNNING)
|
2020-01-11 15:44:40 +01:00
|
|
|
throw new SecurityException(fightState.name());
|
2019-09-05 18:26:13 +02:00
|
|
|
setFightState(FightState.RUNNING);
|
|
|
|
setAllPlayersGM(GameMode.SURVIVAL);
|
|
|
|
|
2020-01-23 17:33:29 +01:00
|
|
|
FightStatistics.start();
|
2019-09-05 18:26:13 +02:00
|
|
|
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
|
|
|
|
}
|
|
|
|
|
2020-01-23 17:33:29 +01:00
|
|
|
public static void setSpectateState(FightTeam winFightTeam, String windescription) {
|
2020-07-07 19:36:56 +02:00
|
|
|
if(fightState == FightState.SPECTATE)
|
|
|
|
return;
|
2019-09-05 18:26:13 +02:00
|
|
|
setFightState(FightState.SPECTATE);
|
|
|
|
|
|
|
|
setAllPlayersGM(GameMode.SPECTATOR);
|
|
|
|
Fight.getBlueTeam().teleportToSpawn();
|
|
|
|
Fight.getRedTeam().teleportToSpawn();
|
|
|
|
Bukkit.getOnlinePlayers().forEach(player -> player.getInventory().clear());
|
|
|
|
|
|
|
|
Bukkit.broadcastMessage(" ");
|
|
|
|
|
|
|
|
if(winFightTeam != null) {
|
2019-11-21 16:09:58 +01:00
|
|
|
Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!");
|
2019-09-05 18:26:13 +02:00
|
|
|
} else {
|
|
|
|
Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!");
|
|
|
|
}
|
|
|
|
|
2020-07-07 19:07:11 +02:00
|
|
|
if(Config.event()) {
|
|
|
|
if (winFightTeam == null)
|
2019-11-16 08:37:33 +01:00
|
|
|
getEventFight().setErgebnis(0);
|
2020-07-07 19:07:11 +02:00
|
|
|
else if (winFightTeam.isBlue())
|
2019-11-16 08:37:33 +01:00
|
|
|
getEventFight().setErgebnis(1);
|
2019-11-10 17:29:59 +01:00
|
|
|
else
|
2019-11-16 08:37:33 +01:00
|
|
|
getEventFight().setErgebnis(2);
|
2019-11-10 17:29:59 +01:00
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-01-23 17:33:29 +01:00
|
|
|
if(!Config.test()){
|
2019-09-05 18:26:13 +02:00
|
|
|
new SpectateOverCountdown();
|
2020-01-23 17:33:29 +01:00
|
|
|
FightStatistics.saveStats(winFightTeam, windescription);
|
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void setFightTime(int fightTime) {
|
|
|
|
FightSystem.fightTime = fightTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setEventLeiter(Player el){
|
2019-11-16 08:37:33 +01:00
|
|
|
IFightSystem.setEventLeiter(el);
|
2019-09-05 18:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Player getEventLeiter(){
|
2019-11-16 08:37:33 +01:00
|
|
|
return IFightSystem.getEventLeiter();
|
2019-09-05 18:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static EventFight getEventFight(){
|
2019-11-16 08:37:33 +01:00
|
|
|
return IFightSystem.getEventFight();
|
2019-09-05 18:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void setPlugin(FightSystem pl){
|
|
|
|
plugin = pl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static FightSystem getPlugin() {
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static FightState getFightState() {
|
|
|
|
return fightState;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getFightTime() {
|
|
|
|
return fightTime;
|
|
|
|
}
|
|
|
|
|
2019-09-18 06:51:20 +02:00
|
|
|
public static void shutdown(String reason){
|
2019-11-16 08:37:33 +01:00
|
|
|
IFightSystem.shutdown(reason);
|
2019-09-18 06:51:20 +02:00
|
|
|
}
|
2020-01-11 12:53:31 +01:00
|
|
|
|
|
|
|
public static void registerStateDependent(StateDependent stateDependent){
|
2020-01-11 15:44:40 +01:00
|
|
|
if(stateDependent.enabled().isEmpty())
|
|
|
|
return;
|
|
|
|
boolean enabled = stateDependent.enabled().contains(fightState);
|
|
|
|
stateDependentFeatures.put(stateDependent, enabled);
|
|
|
|
if(enabled)
|
|
|
|
stateDependent.enable();
|
2020-01-11 12:53:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void setAllPlayersGM(GameMode gm) {
|
|
|
|
for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){
|
2020-01-13 21:37:36 +01:00
|
|
|
Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm);
|
2020-01-11 12:53:31 +01:00
|
|
|
}
|
|
|
|
for(FightPlayer fightPlayer: Fight.getRedTeam().getPlayers()){
|
2020-01-13 21:37:36 +01:00
|
|
|
Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm);
|
2020-01-11 12:53:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void setFightState(FightState state){
|
|
|
|
fightState = state;
|
2020-01-11 15:56:31 +01:00
|
|
|
if(mainCountdown != null){
|
2020-01-11 15:44:40 +01:00
|
|
|
mainCountdown.disable();
|
2020-01-11 15:56:31 +01:00
|
|
|
mainCountdown = null;
|
|
|
|
}
|
2020-01-11 12:53:31 +01:00
|
|
|
postStateChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void postStateChange(){
|
|
|
|
for(Map.Entry<StateDependent, Boolean> feature : stateDependentFeatures.entrySet()){
|
|
|
|
//Enable feature if should be enabled and currently disabled
|
|
|
|
if(feature.getKey().enabled().contains(fightState)){
|
|
|
|
if(!feature.getValue()){
|
|
|
|
feature.getKey().enable();
|
|
|
|
feature.setValue(true);
|
|
|
|
}
|
|
|
|
feature.getKey().stateChange(fightState);
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:53:57 +02:00
|
|
|
|
2020-01-11 12:53:31 +01:00
|
|
|
//Disable feature if should be disabled and currently enabled
|
|
|
|
if(!feature.getKey().enabled().contains(fightState) && feature.getValue()){
|
|
|
|
feature.getKey().disable();
|
|
|
|
feature.setValue(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-26 18:24:44 +02:00
|
|
|
}
|