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/me/yaruma/fightsystem/FightSystem.java

255 Zeilen
9.1 KiB
Java

package me.yaruma.fightsystem;
import de.warking.hunjy.CoinSystem.CoinSystem;
import me.yaruma.fightsystem.commands.*;
import me.yaruma.fightsystem.fight.*;
import me.yaruma.fightsystem.kit.KitManager;
import me.yaruma.fightsystem.listener.*;
import me.yaruma.fightsystem.utils.Config;
import me.yaruma.fightsystem.utils.TechHider;
import me.yaruma.fightsystem.utils.WorldEdit;
import me.yaruma.fightsystem.utils.countdown.Countdown;
import me.yaruma.fightsystem.utils.countdown.FinishNoPlayersOnline;
import me.yaruma.fightsystem.utils.countdown.FinishPreRunning;
import me.yaruma.fightsystem.utils.countdown.FinishSpectateOver;
import me.yaruma.fightsystem.utils.scoreboard.Scoreboard;
import me.yaruma.fightsystem.winconditions.*;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public class FightSystem extends JavaPlugin {
public static final String PREFIX = "§eArena§8» ";
private static FightSystem plugin;
private static Scoreboard scoreboard;
private static WaterRemover waterRemover;
private static FightState fightState = FightState.SETUP;
private static int fightTime = 0;
private static boolean entern = false;
private final File kits = new File("plugins/" + this.getName(), "kits.data");
private final FileConfiguration getKitData = YamlConfiguration.loadConfiguration(kits);
private void saveKitData() {
try { getKitData.save(kits); } catch (Exception ignored) { }
}
public FileConfiguration getKitData() {
return getKitData;
}
@Override
public void onEnable() {
plugin = this;
Config.load();
scoreboard = new Scoreboard();
waterRemover = new WaterRemover();
entern = false;
loadConfig();
KitManager.loadAllKits();
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new PlayerJoinListener(), plugin);
pm.registerEvents(new PlayerQuitListener(), plugin);
pm.registerEvents(new PlayerDeathListener(), plugin);
pm.registerEvents(new PlayerInteractListener(), plugin);
pm.registerEvents(new PlayerChatListener(), plugin);
pm.registerEvents(new BlockPlaceListener(), plugin);
pm.registerEvents(new BlockBreakListener(), plugin);
pm.registerEvents(new PlayerMoveListener(), plugin);
pm.registerEvents(new EntityDamageByEntityListener(), plugin);
pm.registerEvents(new FoodLevelChangeListener(), plugin);
pm.registerEvents(new PlayerRespawnListener(), plugin);
pm.registerEvents(new EntityDamageListener(), plugin);
pm.registerEvents(new EntityExplodeListener(), plugin);
pm.registerEvents(new PlayerTeleportListener(), plugin);
pm.registerEvents(new ProjectileLaunchListener(), plugin);
pm.registerEvents(new PistonListener(), plugin);
//WinConditions
if(Config.AllDead) pm.registerEvents(new WinconditionAllDead(), plugin);
if(Config.CaptainDead) pm.registerEvents(new WinconditionCaptainDead(), plugin);
if(Config.PercentSystem) pm.registerEvents(new WinconditionPercentSystem(), plugin);
getCommand("ak").setExecutor(new AkCommand());
getCommand("invite").setExecutor(new InviteCommand());
getCommand("leave").setExecutor(new LeaveCommand());
getCommand("accept").setExecutor(new AcceptCommand());
getCommand("decline").setExecutor(new DeclineCommand());
getCommand("ready").setExecutor(new ReadyCommand());
getCommand("kit").setExecutor(new KitCommand());
Countdown countdown = new Countdown(Config.NoPlayerOnlineDuration, new FinishNoPlayersOnline());
countdown.startTimer(getPlugin());
TechHider.init();
}
@Override
public void onDisable() {}
private void loadConfig() {
if(!new File("plugins/" + this.getName() + "/kits.data").exists()) {
saveKitData();
System.out.println(PREFIX + "kits.data erstellt und geladen!");
Bukkit.shutdown();
}
}
public static FightSystem getPlugin() {
return plugin;
}
public static FightState getFightState() {
return fightState;
}
public Scoreboard getScoreboard() {
return scoreboard;
}
public WaterRemover getWaterRemover() {
return waterRemover;
}
public void setPreRunningState() {
if(fightState != FightState.SETUP)
return;
fightState = FightState.PRE_RUNNING;
Countdown.cancelAllTimers();
Countdown countdown = new Countdown(Config.PreFightDuration, new FinishPreRunning());
countdown.startTimer(this);
for(FightPlayer allFightPlayers : Fight.getBlueTeam().getPlayers()) {
allFightPlayers.getPlayer().getInventory().clear();
allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer());
}
for(FightPlayer allFightPlayers : Fight.getRedTeam().getPlayers()) {
allFightPlayers.getPlayer().getInventory().clear();
allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer());
}
teleportAllToFightSpawn();
setAllPlayersGM(GameMode.SURVIVAL);
WorldEdit.replace(Fight.getBlueTeam().getLeader().getPlayer(),
Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ,
Config.TeamBlueCornerX + Config.SchemsizeX,
Config.TeamBlueCornerY + Config.SchemsizeY,
Config.TeamBlueCornerZ + Config.SchemsizeZ);
WorldEdit.replace(Fight.getRedTeam().getLeader().getPlayer(),
Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ,
Config.TeamRedCornerX + Config.SchemsizeX,
Config.TeamRedCornerY + Config.SchemsizeY,
Config.TeamRedCornerZ + Config.SchemsizeZ);
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
WinconditionTechKO.startAutoChecker();
}
private void setAllPlayersGM(GameMode gm) {
for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){
fightPlayer.getPlayer().setGameMode(gm);
}
for(FightPlayer fightPlayer: Fight.getRedTeam().getPlayers()){
fightPlayer.getPlayer().setGameMode(gm);
}
}
public void setRunningState() {
if(fightState != FightState.PRE_RUNNING)
return;
fightState = FightState.RUNNING;
Countdown.cancelAllTimers();
getWaterRemover().start();
setAllPlayersGM(GameMode.SURVIVAL);
WinconditionTimeout.timeout();
WinconditionEntern.entern();
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
}
public void setSpectateState(FightTeam winFightTeam) {
if(fightState != FightState.RUNNING)
return;
fightState = FightState.SPECTATE;
Countdown.cancelAllTimers();
Bukkit.getScheduler().cancelTask(WinconditionTechKO.getTaskID());
setAllPlayersGM(GameMode.SPECTATOR);
for(Player p : Bukkit.getOnlinePlayers()){
p.getInventory().clear();
}
Bukkit.broadcastMessage(" ");
if(winFightTeam != null) {
Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getName() + " §ahat gewonnen!");
teleportAllToFightSpawn();
for(FightPlayer fightPlayer : winFightTeam.getPlayers()) {
CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyWin);
}
for(FightPlayer fightPlayer : Fight.getOpposite(winFightTeam).getPlayers()) {
CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyLose);
}
} else {
Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!");
for(FightPlayer fightPlayer : Fight.getBlueTeam().getPlayers()) {
CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyDraw);
}
for(FightPlayer fightPlayer : Fight.getRedTeam().getPlayers()) {
CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyDraw);
}
}
Countdown countdown = new Countdown(Config.SpectatorDuration, new FinishSpectateOver());
countdown.startTimer(FightSystem.getPlugin());
}
public int getFightTime() {
return fightTime;
}
public static boolean isEntern() {
return entern;
}
private void teleportAllToFightSpawn() {
Fight.getBlueTeam().teleportToSpawn();
Fight.getRedTeam().teleportToSpawn();
for(Player player : Bukkit.getServer().getOnlinePlayers()) {
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam == null) player.teleport(Config.SpecSpawn);
}
}
public static void setFightTime(int fightTime) {
FightSystem.fightTime = fightTime;
}
public static void setEntern(boolean entern) {
FightSystem.entern = entern;
}
}