303 Zeilen
11 KiB
Java
303 Zeilen
11 KiB
Java
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;
|
|
import de.steamwar.fightsystem.utils.*;
|
|
import de.steamwar.fightsystem.winconditions.*;
|
|
import de.steamwar.sql.EventFight;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.GameMode;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
|
|
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<>();
|
|
private static int fightTime = 0;
|
|
private static Countdown mainCountdown;
|
|
|
|
@Override
|
|
public void onLoad() {
|
|
setPlugin(this);
|
|
IFightSystem.init(this, PREFIX);
|
|
}
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
Fight.init();
|
|
KitManager.loadAllKits();
|
|
TechHider.init();
|
|
FightScoreboard.init();
|
|
|
|
new EntityDamageListener();
|
|
new EntityExplodeListener();
|
|
new FoodLevelChangeListener();
|
|
new PistonListener();
|
|
new PlayerChatListener();
|
|
new HotbarGUIListener();
|
|
new PlayerMoveListener();
|
|
new PlayerStateListener();
|
|
new ProjectileLaunchListener();
|
|
new InFightDamageListener();
|
|
new FreezeWorldStateListener();
|
|
new EventJoinListener();
|
|
new TestListener();
|
|
new NormalJoinListener();
|
|
|
|
new WinconditionAllDead();
|
|
new WinconditionCaptainDead();
|
|
new WinconditionPumpkinTechKO();
|
|
new WinconditionWaterTechKO();
|
|
new WinconditionPercentSystem();
|
|
new WinconditionRelativePercent();
|
|
new WinconditionPoints();
|
|
new WinconditionTimeout();
|
|
new WinconditionHeartRatioTimeout();
|
|
new WinconditionTechKO();
|
|
|
|
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());
|
|
|
|
mainCountdown = new NoPlayersOnlineCountdown();
|
|
|
|
if(Config.event()) {
|
|
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());
|
|
|
|
setPreSchemState();
|
|
}else if(Config.test()){
|
|
Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0);
|
|
Bukkit.getScheduler().runTaskLater(this, Fight.getRedTeam()::pasteDummy, 0);
|
|
|
|
setPreSchemState();
|
|
setPostSchemState();
|
|
}
|
|
}
|
|
|
|
public static void setPreSchemState() {
|
|
if(fightState != FightState.PRE_LEADER_SETUP)
|
|
throw new SecurityException(fightState.name());
|
|
setFightState(FightState.PRE_SCHEM_SETUP);
|
|
|
|
Fight.calcAvailibleSchemTypes();
|
|
mainCountdown = new PreSchemPasteCountdown();
|
|
}
|
|
|
|
public static void setPostSchemState() {
|
|
if(fightState != FightState.PRE_SCHEM_SETUP)
|
|
throw new SecurityException(fightState.name());
|
|
setFightState(FightState.POST_SCHEM_SETUP);
|
|
|
|
if(!Config.test()){
|
|
TechHider.start();
|
|
Fight.getBlueTeam().pasteSchematic();
|
|
Fight.getRedTeam().pasteSchematic();
|
|
}
|
|
|
|
if(Config.event())
|
|
mainCountdown = new EventStartCountdown();
|
|
else if(Config.test())
|
|
mainCountdown = null;
|
|
else
|
|
mainCountdown = new SetupOverCountdown();
|
|
}
|
|
|
|
public static void setPreRunningState() {
|
|
if(fightState != FightState.POST_SCHEM_SETUP)
|
|
throw new SecurityException(fightState.name());
|
|
setFightState(FightState.PRE_RUNNING);
|
|
|
|
loadKits(Fight.getBlueTeam());
|
|
loadKits(Fight.getRedTeam());
|
|
setAllPlayersGM(GameMode.SURVIVAL);
|
|
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
|
|
|
|
mainCountdown = new PreRunningCountdown();
|
|
Fight.replaceSync();
|
|
|
|
if(Config.event())
|
|
new EventTeamOffWincondition();
|
|
}
|
|
|
|
public static void setRunningState() {
|
|
if(fightState != FightState.PRE_RUNNING)
|
|
throw new SecurityException(fightState.name());
|
|
setFightState(FightState.RUNNING);
|
|
setAllPlayersGM(GameMode.SURVIVAL);
|
|
|
|
if(Config.Entern)
|
|
mainCountdown = new EnternCountdown();
|
|
|
|
FightStatistics.start();
|
|
WaterRemover.init();
|
|
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
|
|
}
|
|
|
|
public static void setEntern() {
|
|
if(fightState != FightState.RUNNING)
|
|
throw new SecurityException(fightState.name());
|
|
setFightState(FightState.ENTERN);
|
|
|
|
final List<ITechHider.ChunkPos> chunksBlue = TechHider.prepareChunkReload(Fight.getBlueTeam().getPlayers().iterator().next().getPlayer());
|
|
final List<ITechHider.ChunkPos> chunksRed = TechHider.prepareChunkReload(Fight.getRedTeam().getPlayers().iterator().next().getPlayer());
|
|
IFightSystem.setEntern(true);
|
|
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 setSpectateState(FightTeam winFightTeam, String windescription) {
|
|
if(!fightState.ingame())
|
|
throw new SecurityException(fightState.name());
|
|
setFightState(FightState.SPECTATE);
|
|
|
|
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.getColoredName() + " §ahat gewonnen!");
|
|
} else {
|
|
Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!");
|
|
}
|
|
|
|
if(Config.event()){
|
|
if(winFightTeam == null)
|
|
getEventFight().setErgebnis(0);
|
|
else if(winFightTeam.isBlue())
|
|
getEventFight().setErgebnis(1);
|
|
else
|
|
getEventFight().setErgebnis(2);
|
|
}
|
|
|
|
if(!Config.test()){
|
|
new SpectateOverCountdown();
|
|
FightStatistics.saveStats(winFightTeam, windescription);
|
|
}
|
|
}
|
|
|
|
public static void setFightTime(int fightTime) {
|
|
FightSystem.fightTime = fightTime;
|
|
}
|
|
|
|
public static void setEventLeiter(Player el){
|
|
IFightSystem.setEventLeiter(el);
|
|
}
|
|
|
|
public static Player getEventLeiter(){
|
|
return IFightSystem.getEventLeiter();
|
|
}
|
|
|
|
public static EventFight getEventFight(){
|
|
return IFightSystem.getEventFight();
|
|
}
|
|
|
|
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 void shutdown(String reason){
|
|
IFightSystem.shutdown(reason);
|
|
}
|
|
|
|
public static void registerStateDependent(StateDependent stateDependent){
|
|
if(stateDependent.enabled().isEmpty())
|
|
return;
|
|
boolean enabled = stateDependent.enabled().contains(fightState);
|
|
stateDependentFeatures.put(stateDependent, enabled);
|
|
if(enabled)
|
|
stateDependent.enable();
|
|
}
|
|
|
|
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()){
|
|
Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm);
|
|
}
|
|
for(FightPlayer fightPlayer: Fight.getRedTeam().getPlayers()){
|
|
Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm);
|
|
}
|
|
}
|
|
|
|
private static void setFightState(FightState state){
|
|
fightState = state;
|
|
if(mainCountdown != null){
|
|
mainCountdown.disable();
|
|
mainCountdown = null;
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |