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-03-09 19:40:12 +01:00
|
|
|
import me.yaruma.fightsystem.commands.AkCommand;
|
|
|
|
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-03-09 19:40:12 +01:00
|
|
|
import me.yaruma.fightsystem.utils.WorldEdit;
|
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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
public class FightSystem extends JavaPlugin {
|
|
|
|
|
2019-03-26 12:00:56 +01:00
|
|
|
public static final String PREFIX = "§6Arena§8» ";
|
2019-03-09 19:40:12 +01:00
|
|
|
|
|
|
|
private static FightSystem plugin;
|
|
|
|
private Scoreboard scoreboard;
|
|
|
|
private WaterRemover waterRemover;
|
|
|
|
|
2019-04-23 18:33:18 +02:00
|
|
|
private static FightState fightState;
|
2019-03-09 19:40:12 +01:00
|
|
|
public int fightTime = 0;
|
|
|
|
|
|
|
|
|
|
|
|
public boolean entern = false;
|
|
|
|
|
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
|
|
|
|
|
|
|
public void onEnable() {
|
|
|
|
|
|
|
|
plugin = this;
|
2019-04-05 19:32:59 +02:00
|
|
|
Config.load();
|
|
|
|
|
2019-03-09 19:40:12 +01:00
|
|
|
this.scoreboard = new Scoreboard(plugin);
|
|
|
|
this.waterRemover = new WaterRemover();
|
|
|
|
|
|
|
|
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
|
|
|
init();
|
|
|
|
|
|
|
|
fightState = FightState.SETUP;
|
2019-04-14 12:24:10 +02:00
|
|
|
Countdown countdown = new Countdown(Config.NoPlayerOnlineDuration, new FinishNoPlayersOnline());
|
2019-03-09 19:40:12 +01:00
|
|
|
countdown.startTimer(getPlugin());
|
2019-04-23 18:33:18 +02:00
|
|
|
|
|
|
|
/*ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.MAP_CHUNK) {
|
|
|
|
@Override
|
|
|
|
public void onPacketSending(PacketEvent e) {
|
|
|
|
e.getPacket();
|
|
|
|
}
|
|
|
|
});*/
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onDisable() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
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-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());
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04-05 19:32:59 +02:00
|
|
|
Countdown countdown = new Countdown(Config.PreFightDuration, new FinishPreRunning());
|
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-04-05 19:32:59 +02:00
|
|
|
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);
|
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-04-14 01:07:38 +02:00
|
|
|
Bukkit.getScheduler().cancelTask(WinconditionTechKO.taskID);
|
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-04-05 19:32:59 +02:00
|
|
|
Countdown countdown = new Countdown(Config.SpectatorDuration, new FinishSpectateOver());
|
2019-03-09 19:40:12 +01:00
|
|
|
countdown.startTimer(FightSystem.getPlugin());
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getFightTime() {
|
|
|
|
return fightTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|