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.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.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;
|
|
|
|
|
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 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());
|
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();
|
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-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 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) {
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void loadKits(FightTeam team){
|
|
|
|
for(FightPlayer allFightPlayers : team.getPlayers()) {
|
2019-09-18 06:51:20 +02:00
|
|
|
if(allFightPlayers.getPlayer() == null)
|
|
|
|
continue;
|
2019-09-05 18:26:13 +02:00
|
|
|
allFightPlayers.getPlayer().getInventory().clear();
|
2019-10-06 17:22:23 +02:00
|
|
|
if(allFightPlayers.getKit() == null)
|
|
|
|
continue;
|
2019-09-05 18:26:13 +02:00
|
|
|
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 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
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
}
|