SteamWar/FightSystem
Archiviert
13
1
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
FightSystem/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java

274 Zeilen
8.9 KiB
Java

2019-09-05 18:26:13 +02:00
package de.steamwar.fightsystem;
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.*;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
2019-09-05 18:26:13 +02:00
import de.steamwar.fightsystem.utils.FightScoreboard;
import de.steamwar.fightsystem.utils.TechHider;
import de.steamwar.fightsystem.utils.WaterRemover;
import de.steamwar.fightsystem.winconditions.*;
2019-11-10 17:29:59 +01:00
import de.steamwar.sql.EventFight;
2019-09-05 18:26:13 +02:00
import javafx.util.Pair;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.*;
2019-09-05 18:26:13 +02:00
public class FightSystem extends JavaPlugin {
public static final String PREFIX = "§eArena§8» ";
private static FightSystem plugin;
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;
2019-11-16 08:37:33 +01:00
@Override
public void onLoad() {
setPlugin(this);
IFightSystem.init(this, PREFIX);
}
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();
new EntityDamageListener();
new EntityExplodeListener();
new FoodLevelChangeListener();
new PistonListener();
new PlayerChatListener();
new HotbarGUIListener();
new PlayerMoveListener();
new PlayerStateListener();
2019-09-05 18:26:13 +02:00
new ProjectileLaunchListener();
new InFightDamageListener();
2019-09-05 18:26:13 +02:00
if(!Config.test()){
new FreezeWorldStateListener();
2019-09-05 18:26:13 +02:00
TechHider.init();
}
FightScoreboard.init();
getCommand("leave").setExecutor(new LeaveCommand());
getCommand("kit").setExecutor(new KitCommand());
getCommand("remove").setExecutor(new RemoveCommand());
getCommand("accept").setExecutor(new AcceptCommand());
getCommand("decline").setExecutor(new DeclineCommand());
getCommand("invite").setExecutor(new InviteCommand());
getCommand("ready").setExecutor(new ReadyCommand());
getCommand("ak").setExecutor(new AkCommand());
getCommand("leader").setExecutor(new LeaderCommand());
2019-11-21 16:20:57 +01:00
getCommand("lockschem").setExecutor(new LockschemCommand());
2019-09-05 18:26:13 +02:00
if(Config.event()) {
new EventJoinListener();
getCommand("invite").setExecutor(new EventDummyCommand());
getCommand("ready").setExecutor(new EventDummyCommand());
getCommand("ak").setExecutor(new EventDummyCommand());
getCommand("leader").setExecutor(new EventDummyCommand());
new EventStartCountdown();
}else if(Config.test()){
new TestListener();
Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0);
Bukkit.getScheduler().runTaskLater(this, Fight.getRedTeam()::pasteDummy, 0);
new NoPlayersOnlineCountdown();
}else{
new NormalJoinListener();
new NoPlayersOnlineCountdown();
}
}
public static void setPreRunningState() {
if(fightState != FightState.PRE_LEADER_SETUP) //TODO
2019-09-05 18:26:13 +02:00
return;
setFightState(FightState.PRE_RUNNING);
Countdown.cancelAllTimers();
loadKits(Fight.getBlueTeam());
loadKits(Fight.getRedTeam());
setAllPlayersGM(GameMode.SURVIVAL);
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
2019-09-06 20:06:05 +02:00
new PreRunningCountdown();
2019-12-09 20:37:18 +01:00
Fight.replaceSync();
2019-12-06 22:51:26 +01:00
2019-09-05 18:26:13 +02:00
new WinconditionAllDead();
new WinconditionCaptainDead();
new WinconditionPumpkinTechKO();
2019-09-05 18:26:13 +02:00
new WinconditionWaterTechKO();
new WinconditionPercentSystem();
new WinconditionRelativePercent();
new WinconditionPoints();
2019-09-05 18:26:13 +02:00
if(Config.event()){
new EventTeamOffWincondition();
}
}
public static void setRunningState() {
if(fightState != FightState.PRE_RUNNING)
return;
setFightState(FightState.RUNNING);
Countdown.cancelAllTimers();
setAllPlayersGM(GameMode.SURVIVAL);
new WinconditionTimeout();
new WinconditionHeartRatioTimeout();
2019-09-05 18:26:13 +02:00
new WinconditionEntern();
new WinconditionTechKO();
2019-09-05 18:26:13 +02:00
WaterRemover.init();
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
}
public static void setSpectateState(FightTeam winFightTeam) {
if(fightState != FightState.RUNNING && fightState != FightState.PRE_RUNNING)
return;
setFightState(FightState.SPECTATE);
Countdown.cancelAllTimers();
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!");
}
2019-11-10 17:29:59 +01:00
if(Config.event()){
if(winFightTeam == null)
2019-11-16 08:37:33 +01:00
getEventFight().setErgebnis(0);
2019-11-10 17:29:59 +01: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
if(!Config.test())
new SpectateOverCountdown();
}
public static void setFightTime(int fightTime) {
FightSystem.fightTime = fightTime;
}
public static void setEntern(boolean entern) {
final List<Pair<Integer, Integer>> chunksBlue = TechHider.prepareChunkReload(Fight.getBlueTeam().getPlayers().iterator().next().getPlayer());
final List<Pair<Integer, Integer>> chunksRed = TechHider.prepareChunkReload(Fight.getRedTeam().getPlayers().iterator().next().getPlayer());
2019-11-16 08:37:33 +01:00
IFightSystem.setEntern(entern);
2019-09-05 18:26:13 +02:00
for(FightPlayer player : Fight.getBlueTeam().getPlayers()){
TechHider.reloadChunks(player.getPlayer(), chunksBlue);
}
for(FightPlayer player : Fight.getRedTeam().getPlayers()){
TechHider.reloadChunks(player.getPlayer(), chunksRed);
}
}
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;
}
public static boolean isEntern() {
2019-11-16 08:37:33 +01:00
return IFightSystem.isEntern();
2019-09-05 18:26:13 +02:00
}
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
}
public static void registerStateDependent(StateDependent stateDependent){
stateDependentFeatures.put(stateDependent, false);
}
private static void loadKits(FightTeam team){
for(FightPlayer allFightPlayers : team.getPlayers()) {
if(allFightPlayers.getPlayer() == null)
continue;
allFightPlayers.getPlayer().getInventory().clear();
if(allFightPlayers.getKit() == null)
continue;
allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer());
}
}
private static void setAllPlayersGM(GameMode gm) {
for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){
fightPlayer.getPlayer().setGameMode(gm);
}
for(FightPlayer fightPlayer: Fight.getRedTeam().getPlayers()){
fightPlayer.getPlayer().setGameMode(gm);
}
}
private static void setFightState(FightState state){
fightState = state;
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);
}
//Disable feature if should be disabled and currently enabled
if(!feature.getKey().enabled().contains(fightState) && feature.getValue()){
feature.getKey().disable();
feature.setValue(false);
}
}
}
2019-09-05 18:26:13 +02:00
}