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/src/de/steamwar/fightsystem/FightSystem.java

235 Zeilen
7.4 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.FightState;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.listener.*;
import de.steamwar.fightsystem.utils.Config;
import de.steamwar.fightsystem.utils.FightScoreboard;
import de.steamwar.fightsystem.utils.TechHider;
import de.steamwar.fightsystem.utils.WaterRemover;
import de.steamwar.fightsystem.utils.sql.EventFight;
import de.steamwar.fightsystem.winconditions.*;
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.List;
public class FightSystem extends JavaPlugin {
public static final String PREFIX = "§eArena§8» ";
private static FightSystem plugin;
private static FightState fightState = FightState.SETUP;
private static int fightTime = 0;
private static boolean entern = false;
private static EventFight eventFight;
private static Player eventLeiter;
@Override
public void onEnable() {
setPlugin(this);
Config.load();
KitManager.loadAllKits();
new EntityDamageListener();
new EntityExplodeListener();
new FoodLevelChangeListener();
new PistonListener();
new PlayerChatListener();
new PlayerDeathListener();
new HotbarGUIListener();
new PlayerMoveListener();
new PlayerConnectionListener();
new PlayerRespawnListener();
new PlayerTeleportListener();
new ProjectileLaunchListener();
if(!Config.test()){
new BlockListener();
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());
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();
2019-09-06 18:39:32 +02:00
new InventoryListener();
2019-09-05 18:26:13 +02:00
new NoPlayersOnlineCountdown();
}
}
public static void setPreRunningState() {
if(fightState != FightState.SETUP)
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-09-05 18:26:13 +02:00
new WinconditionAllDead();
new WinconditionCaptainDead();
new WinconditionWaterTechKO();
new WinconditionPercentSystem();
if(Config.event()){
new EventTeamOffWincondition();
}
}
public static void setRunningState() {
if(fightState != FightState.PRE_RUNNING)
return;
setFightState(FightState.RUNNING);
Countdown.cancelAllTimers();
setAllPlayersGM(GameMode.SURVIVAL);
new WinconditionTechKO();
new WinconditionTimeout();
new WinconditionEntern();
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) {
Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getName() + " §ahat gewonnen!");
} else {
Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!");
}
if(Config.event())
eventFight.setErgebnis(winFightTeam);
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());
FightSystem.entern = entern;
for(FightPlayer player : Fight.getBlueTeam().getPlayers()){
TechHider.reloadChunks(player.getPlayer(), chunksBlue);
}
for(FightPlayer player : Fight.getRedTeam().getPlayers()){
TechHider.reloadChunks(player.getPlayer(), chunksRed);
}
}
private static void loadKits(FightTeam team){
for(FightPlayer allFightPlayers : team.getPlayers()) {
allFightPlayers.getPlayer().getInventory().clear();
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;
BasicListener.fightStateChange(state);
}
public static void setEventFight(EventFight ef){
eventFight = ef;
}
public static void setEventLeiter(Player el){
eventLeiter = el;
}
public static Player getEventLeiter(){
return eventLeiter;
}
public static EventFight getEventFight(){
return eventFight;
}
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() {
return entern;
}
}