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

252 Zeilen
9.1 KiB
Java

package me.yaruma.fightsystem;
import de.warking.hunjy.CoinSystem.CoinSystem;
import javafx.util.Pair;
import me.yaruma.fightsystem.commands.*;
import me.yaruma.fightsystem.fight.*;
import me.yaruma.fightsystem.kit.KitManager;
import me.yaruma.fightsystem.listener.*;
2019-04-05 19:32:59 +02:00
import me.yaruma.fightsystem.utils.Config;
2019-04-25 20:33:36 +02:00
import me.yaruma.fightsystem.utils.TechHider;
2019-04-05 19:32:59 +02:00
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.Sound;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
2019-04-05 19:32:59 +02:00
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.List;
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);
2019-04-23 18:33:18 +02:00
private void saveKitData() {
try { getKitData.save(kits); } catch (Exception ignored) { }
}
public FileConfiguration getKitData() {
return getKitData;
}
@Override
public void onEnable() {
plugin = this;
2019-04-05 19:32:59 +02:00
Config.load();
scoreboard = new Scoreboard();
waterRemover = new WaterRemover();
2019-06-08 12:57:08 +02:00
entern = false;
loadConfig();
2019-04-13 15:17:58 +02:00
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);
2019-06-08 12:57:08 +02:00
pm.registerEvents(new PistonListener(), plugin);
2019-06-14 21:51:06 +02:00
pm.registerEvents(new InventoryListener(), plugin);
//WinConditions
2019-04-05 19:32:59 +02:00
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(), null);
countdown.startTimer(getPlugin());
TechHider.init();
}
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;
}
2019-04-23 18:33:18 +02:00
public static FightState getFightState() {
return fightState;
}
public Scoreboard getScoreboard() {
return scoreboard;
}
public WaterRemover getWaterRemover() {
return waterRemover;
}
public void setPreRunningState() {
2019-04-23 18:33:18 +02:00
if(fightState != FightState.SETUP)
return;
2019-04-23 18:33:18 +02:00
fightState = FightState.PRE_RUNNING;
Countdown.cancelAllTimers();
Countdown countdown = new Countdown(Config.PreFightDuration, new FinishPreRunning(), Sound.BLOCK_NOTE_PLING);
countdown.startTimer(this);
for(FightPlayer allFightPlayers : Fight.getBlueTeam().getPlayers()) {
allFightPlayers.getPlayer().getInventory().clear();
2019-04-13 15:17:58 +02:00
allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer());
}
for(FightPlayer allFightPlayers : Fight.getRedTeam().getPlayers()) {
allFightPlayers.getPlayer().getInventory().clear();
2019-04-13 15:17:58 +02:00
allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer());
}
2019-04-05 19:32:59 +02:00
teleportAllToFightSpawn();
setAllPlayersGM(GameMode.SURVIVAL);
2019-03-26 12:00:56 +01:00
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
2019-04-14 21:22:53 +02:00
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() {
2019-04-23 18:33:18 +02:00
if(fightState != FightState.PRE_RUNNING)
return;
2019-04-23 18:33:18 +02:00
fightState = FightState.RUNNING;
Countdown.cancelAllTimers();
getWaterRemover().start();
setAllPlayersGM(GameMode.SURVIVAL);
WinconditionTimeout.timeout();
WinconditionEntern.entern();
2019-03-26 12:00:56 +01:00
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
}
public void setSpectateState(FightTeam winFightTeam) {
2019-04-23 18:33:18 +02:00
if(fightState != FightState.RUNNING)
return;
2019-04-23 18:33:18 +02:00
fightState = FightState.SPECTATE;
Countdown.cancelAllTimers();
Bukkit.getScheduler().cancelTask(WinconditionTechKO.getTaskID());
setAllPlayersGM(GameMode.SPECTATOR);
2019-04-23 18:33:18 +02:00
for(Player p : Bukkit.getOnlinePlayers()){
p.getInventory().clear();
}
Bukkit.broadcastMessage(" ");
if(winFightTeam != null) {
2019-04-05 19:32:59 +02:00
Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getName() + " §ahat gewonnen!");
teleportAllToFightSpawn();
for(FightPlayer fightPlayer : winFightTeam.getPlayers()) {
2019-04-05 19:32:59 +02:00
CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyWin);
}
for(FightPlayer fightPlayer : Fight.getOpposite(winFightTeam).getPlayers()) {
2019-04-05 19:32:59 +02:00
CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyLose);
}
} else {
2019-03-26 12:00:56 +01:00
Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!");
for(FightPlayer fightPlayer : Fight.getBlueTeam().getPlayers()) {
2019-04-05 19:32:59 +02:00
CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyDraw);
}
2019-03-26 12:00:56 +01:00
for(FightPlayer fightPlayer : Fight.getRedTeam().getPlayers()) {
2019-04-05 19:32:59 +02:00
CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyDraw);
}
}
Countdown countdown = new Countdown(Config.SpectatorDuration, new FinishSpectateOver(), Sound.BLOCK_NOTE_PLING);
countdown.startTimer(FightSystem.getPlugin());
}
public int getFightTime() {
return fightTime;
}
2019-06-08 12:57:08 +02:00
public static boolean isEntern() {
return entern;
}
2019-04-05 19:32:59 +02:00
private void teleportAllToFightSpawn() {
2019-04-13 16:30:25 +02:00
Fight.getBlueTeam().teleportToSpawn();
Fight.getRedTeam().teleportToSpawn();
2019-04-05 19:32:59 +02:00
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) {
final List<Pair<Integer, Integer>> chunksBlue = TechHider.prepareChunkReload(Fight.getBlueTeam().getPlayers().get(0).getPlayer());
final List<Pair<Integer, Integer>> chunksRed = TechHider.prepareChunkReload(Fight.getRedTeam().getPlayers().get(0).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);
}
}
}