2019-03-09 19:40:12 +01:00
|
|
|
package me.yaruma.fightsystem;
|
|
|
|
|
2019-03-25 22:04:02 +01:00
|
|
|
import de.warking.hunjy.CoinSystem.CoinSystem;
|
2019-06-08 12:57:58 +02:00
|
|
|
import javafx.util.Pair;
|
2019-06-04 18:22:29 +02:00
|
|
|
import me.yaruma.fightsystem.commands.*;
|
2019-03-09 19:40:12 +01:00
|
|
|
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;
|
2019-03-09 19:40:12 +01:00
|
|
|
import me.yaruma.fightsystem.utils.scoreboard.Scoreboard;
|
2019-03-24 00:43:05 +01:00
|
|
|
import me.yaruma.fightsystem.winconditions.*;
|
2019-03-09 19:40:12 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.GameMode;
|
2019-07-02 22:56:58 +02:00
|
|
|
import org.bukkit.Sound;
|
2019-03-09 19:40:12 +01:00
|
|
|
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;
|
2019-03-09 19:40:12 +01:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
import java.io.File;
|
2019-06-08 12:57:58 +02:00
|
|
|
import java.util.List;
|
2019-03-09 19:40:12 +01:00
|
|
|
|
|
|
|
public class FightSystem extends JavaPlugin {
|
|
|
|
|
2019-06-05 22:14:27 +02:00
|
|
|
public static final String PREFIX = "§eArena§8» ";
|
2019-03-09 19:40:12 +01:00
|
|
|
|
|
|
|
private static FightSystem plugin;
|
2019-06-05 22:14:27 +02:00
|
|
|
private static Scoreboard scoreboard;
|
|
|
|
private static WaterRemover waterRemover;
|
2019-03-09 19:40:12 +01:00
|
|
|
|
2019-06-05 22:14:27 +02:00
|
|
|
private static FightState fightState = FightState.SETUP;
|
|
|
|
private static int fightTime = 0;
|
2019-03-09 19:40:12 +01:00
|
|
|
|
|
|
|
|
2019-06-05 22:14:27 +02:00
|
|
|
private static boolean entern = false;
|
2019-03-09 19:40:12 +01:00
|
|
|
|
2019-03-26 12:33:33 +01:00
|
|
|
private final File kits = new File("plugins/" + this.getName(), "kits.data");
|
|
|
|
private final FileConfiguration getKitData = YamlConfiguration.loadConfiguration(kits);
|
2019-03-09 19:40:12 +01:00
|
|
|
|
2019-04-23 18:33:18 +02:00
|
|
|
private void saveKitData() {
|
2019-03-26 12:33:33 +01:00
|
|
|
try { getKitData.save(kits); } catch (Exception ignored) { }
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|
|
|
|
|
2019-03-26 22:59:47 +01:00
|
|
|
public FileConfiguration getKitData() {
|
|
|
|
return getKitData;
|
|
|
|
}
|
2019-03-09 19:40:12 +01:00
|
|
|
|
2019-06-05 22:14:27 +02:00
|
|
|
@Override
|
2019-03-09 19:40:12 +01:00
|
|
|
public void onEnable() {
|
|
|
|
|
|
|
|
plugin = this;
|
2019-04-05 19:32:59 +02:00
|
|
|
Config.load();
|
|
|
|
|
2019-06-05 22:14:27 +02:00
|
|
|
scoreboard = new Scoreboard();
|
|
|
|
waterRemover = new WaterRemover();
|
2019-06-08 12:57:08 +02:00
|
|
|
entern = false;
|
2019-03-09 19:40:12 +01:00
|
|
|
|
|
|
|
loadConfig();
|
|
|
|
|
2019-04-13 15:17:58 +02:00
|
|
|
KitManager.loadAllKits();
|
2019-03-26 22:59:47 +01:00
|
|
|
|
2019-03-09 19:40:12 +01:00
|
|
|
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);
|
2019-04-14 00:02:33 +02:00
|
|
|
pm.registerEvents(new PlayerTeleportListener(), plugin);
|
2019-04-15 18:40:47 +02:00
|
|
|
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);
|
2019-03-09 19:40:12 +01:00
|
|
|
|
|
|
|
//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);
|
2019-03-09 19:40:12 +01:00
|
|
|
|
|
|
|
getCommand("ak").setExecutor(new AkCommand());
|
2019-06-04 18:22:29 +02:00
|
|
|
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());
|
2019-06-05 22:14:27 +02:00
|
|
|
getCommand("kit").setExecutor(new KitCommand());
|
|
|
|
|
2019-07-02 22:56:58 +02:00
|
|
|
Countdown countdown = new Countdown(Config.NoPlayerOnlineDuration, new FinishNoPlayersOnline(), null);
|
2019-06-05 22:14:27 +02:00
|
|
|
countdown.startTimer(getPlugin());
|
|
|
|
|
|
|
|
TechHider.init();
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2019-03-09 19:40:12 +01:00
|
|
|
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)
|
2019-03-09 19:40:12 +01:00
|
|
|
return;
|
2019-04-23 18:33:18 +02:00
|
|
|
fightState = FightState.PRE_RUNNING;
|
2019-03-09 19:40:12 +01:00
|
|
|
Countdown.cancelAllTimers();
|
|
|
|
|
2019-07-02 22:56:58 +02:00
|
|
|
Countdown countdown = new Countdown(Config.PreFightDuration, new FinishPreRunning(), Sound.BLOCK_NOTE_PLING);
|
2019-03-09 19:40:12 +01:00
|
|
|
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());
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|
|
|
|
for(FightPlayer allFightPlayers : Fight.getRedTeam().getPlayers()) {
|
|
|
|
allFightPlayers.getPlayer().getInventory().clear();
|
2019-04-13 15:17:58 +02:00
|
|
|
allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer());
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|
2019-03-25 22:04:02 +01:00
|
|
|
|
2019-04-05 19:32:59 +02:00
|
|
|
teleportAllToFightSpawn();
|
2019-04-20 16:39:24 +02:00
|
|
|
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();
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2019-03-09 19:40:12 +01:00
|
|
|
return;
|
2019-04-23 18:33:18 +02:00
|
|
|
fightState = FightState.RUNNING;
|
2019-03-09 19:40:12 +01:00
|
|
|
Countdown.cancelAllTimers();
|
|
|
|
|
|
|
|
getWaterRemover().start();
|
|
|
|
|
|
|
|
setAllPlayersGM(GameMode.SURVIVAL);
|
|
|
|
|
2019-03-25 22:04:02 +01:00
|
|
|
WinconditionTimeout.timeout();
|
|
|
|
WinconditionEntern.entern();
|
|
|
|
|
2019-03-26 12:00:56 +01:00
|
|
|
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setSpectateState(FightTeam winFightTeam) {
|
2019-04-23 18:33:18 +02:00
|
|
|
if(fightState != FightState.RUNNING)
|
2019-03-09 19:40:12 +01:00
|
|
|
return;
|
2019-04-23 18:33:18 +02:00
|
|
|
fightState = FightState.SPECTATE;
|
2019-03-09 19:40:12 +01:00
|
|
|
Countdown.cancelAllTimers();
|
2019-06-05 22:14:27 +02:00
|
|
|
Bukkit.getScheduler().cancelTask(WinconditionTechKO.getTaskID());
|
2019-03-09 19:40:12 +01:00
|
|
|
|
|
|
|
setAllPlayersGM(GameMode.SPECTATOR);
|
2019-04-23 18:33:18 +02:00
|
|
|
for(Player p : Bukkit.getOnlinePlayers()){
|
|
|
|
p.getInventory().clear();
|
2019-04-14 12:16:28 +02:00
|
|
|
}
|
2019-03-09 19:40:12 +01:00
|
|
|
Bukkit.broadcastMessage(" ");
|
|
|
|
|
|
|
|
if(winFightTeam != null) {
|
2019-04-05 19:32:59 +02:00
|
|
|
Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getName() + " §ahat gewonnen!");
|
|
|
|
teleportAllToFightSpawn();
|
2019-03-09 19:40:12 +01:00
|
|
|
|
|
|
|
for(FightPlayer fightPlayer : winFightTeam.getPlayers()) {
|
2019-04-05 19:32:59 +02:00
|
|
|
CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyWin);
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for(FightPlayer fightPlayer : Fight.getOpposite(winFightTeam).getPlayers()) {
|
2019-04-05 19:32:59 +02:00
|
|
|
CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyLose);
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|
|
|
|
} 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-09 19:40:12 +01:00
|
|
|
}
|
|
|
|
|
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);
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 22:56:58 +02:00
|
|
|
Countdown countdown = new Countdown(Config.SpectatorDuration, new FinishSpectateOver(), Sound.BLOCK_NOTE_PLING);
|
2019-03-09 19:40:12 +01:00
|
|
|
countdown.startTimer(FightSystem.getPlugin());
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getFightTime() {
|
|
|
|
return fightTime;
|
|
|
|
}
|
|
|
|
|
2019-06-08 12:57:08 +02:00
|
|
|
public static boolean isEntern() {
|
2019-03-09 19:40:12 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-06-05 22:14:27 +02:00
|
|
|
|
|
|
|
public static void setFightTime(int fightTime) {
|
|
|
|
FightSystem.fightTime = fightTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setEntern(boolean entern) {
|
2019-06-08 12:57:58 +02:00
|
|
|
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());
|
2019-06-05 22:14:27 +02:00
|
|
|
FightSystem.entern = entern;
|
2019-06-08 12:57:58 +02:00
|
|
|
for(FightPlayer player : Fight.getBlueTeam().getPlayers()){
|
|
|
|
TechHider.reloadChunks(player.getPlayer(), chunksBlue);
|
|
|
|
}
|
|
|
|
for(FightPlayer player : Fight.getRedTeam().getPlayers()){
|
|
|
|
TechHider.reloadChunks(player.getPlayer(), chunksRed);
|
|
|
|
}
|
2019-06-05 22:14:27 +02:00
|
|
|
}
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|