2020-08-26 18:24:44 +02:00
|
|
|
/*
|
|
|
|
This file is a part of the SteamWar software.
|
|
|
|
|
|
|
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-09-05 18:26:13 +02:00
|
|
|
package de.steamwar.fightsystem.fight;
|
2019-02-14 18:37:38 +01:00
|
|
|
|
2019-11-16 08:37:33 +01:00
|
|
|
import de.steamwar.fightsystem.Config;
|
2020-01-18 08:31:13 +01:00
|
|
|
import de.steamwar.sql.Schematic;
|
2019-07-04 22:07:12 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2020-01-13 21:37:36 +01:00
|
|
|
import org.bukkit.GameMode;
|
2019-12-09 20:37:18 +01:00
|
|
|
import org.bukkit.Material;
|
2019-07-04 22:07:12 +02:00
|
|
|
import org.bukkit.Sound;
|
2019-02-14 18:37:38 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2020-05-16 16:39:16 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-02-14 18:37:38 +01:00
|
|
|
public class Fight {
|
2019-09-05 18:26:13 +02:00
|
|
|
private Fight(){}
|
2019-02-14 18:37:38 +01:00
|
|
|
|
2019-11-23 18:15:45 +01:00
|
|
|
public static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedPrefix, Config.TeamRedSpawn, Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.TeamRedRotate, false, Config.RedLeader);
|
|
|
|
public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBluePrefix, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader);
|
2020-05-16 16:39:16 +02:00
|
|
|
private static int schemRank;
|
2019-02-14 18:37:38 +01:00
|
|
|
|
2019-11-16 08:37:33 +01:00
|
|
|
public static void init(){
|
|
|
|
IFight.init(redTeam, blueTeam);
|
|
|
|
}
|
|
|
|
|
2019-02-14 18:37:38 +01:00
|
|
|
public static FightTeam getPlayerTeam(Player player) {
|
2019-02-23 16:07:31 +01:00
|
|
|
if(redTeam.isPlayerInTeam(player))
|
2019-02-14 18:37:38 +01:00
|
|
|
return redTeam;
|
2019-02-23 16:07:31 +01:00
|
|
|
if(blueTeam.isPlayerInTeam(player))
|
2019-02-14 18:37:38 +01:00
|
|
|
return blueTeam;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static FightTeam getOpposite(FightTeam fightTeam) {
|
2019-09-05 18:26:13 +02:00
|
|
|
if(fightTeam == null){
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:07:31 +01:00
|
|
|
if(fightTeam == redTeam)
|
2019-02-14 18:37:38 +01:00
|
|
|
return blueTeam;
|
2019-09-05 18:26:13 +02:00
|
|
|
else
|
2019-02-14 18:37:38 +01:00
|
|
|
return redTeam;
|
|
|
|
}
|
|
|
|
|
2019-02-15 16:04:50 +01:00
|
|
|
public static FightTeam getInvitedTeam(Player player){
|
2019-02-23 16:07:31 +01:00
|
|
|
if(redTeam.getInvited().contains(player))
|
2019-02-15 16:04:50 +01:00
|
|
|
return redTeam;
|
2019-02-23 16:07:31 +01:00
|
|
|
else if(blueTeam.getInvited().contains(player))
|
2019-02-15 16:04:50 +01:00
|
|
|
return blueTeam;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-02-17 20:29:32 +01:00
|
|
|
public static FightPlayer getFightPlayer(Player player) {
|
2019-02-23 16:07:31 +01:00
|
|
|
if(redTeam.isPlayerInTeam(player))
|
|
|
|
return redTeam.getFightPlayer(player);
|
|
|
|
if(blueTeam.isPlayerInTeam(player))
|
|
|
|
return blueTeam.getFightPlayer(player);
|
2019-02-17 20:29:32 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-02-14 18:37:38 +01:00
|
|
|
public static FightTeam getRedTeam() {
|
|
|
|
return redTeam;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static FightTeam getBlueTeam() {
|
|
|
|
return blueTeam;
|
|
|
|
}
|
2019-07-04 22:07:12 +02:00
|
|
|
|
|
|
|
public static void playSound(Sound sound, float volume, float pitch) {
|
2019-09-05 18:26:13 +02:00
|
|
|
//volume: max. 100, pitch: max. 2
|
|
|
|
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch));
|
2019-07-04 22:07:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void setLevel(int level) {
|
2019-09-05 18:26:13 +02:00
|
|
|
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(level));
|
2019-07-04 22:07:12 +02:00
|
|
|
}
|
2019-11-21 16:09:58 +01:00
|
|
|
|
|
|
|
public static FightTeam getTeamByName(String name) {
|
|
|
|
if(redTeam.getName().equalsIgnoreCase(name))
|
|
|
|
return redTeam;
|
|
|
|
if(blueTeam.getName().equalsIgnoreCase(name))
|
|
|
|
return blueTeam;
|
|
|
|
return null;
|
|
|
|
}
|
2019-12-09 20:52:18 +01:00
|
|
|
|
2019-12-09 20:37:18 +01:00
|
|
|
public static void replaceSync() {
|
2019-12-09 20:40:07 +01:00
|
|
|
Fight.getRedTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT);
|
|
|
|
Fight.getBlueTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT);
|
|
|
|
|
|
|
|
Fight.getRedTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK);
|
|
|
|
Fight.getBlueTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK);
|
2019-12-09 20:37:18 +01:00
|
|
|
}
|
2020-01-13 21:37:36 +01:00
|
|
|
|
|
|
|
public static void setPlayerGamemode(Player player, GameMode gameMode) {
|
|
|
|
player.setGameMode(gameMode);
|
|
|
|
|
|
|
|
if(gameMode == GameMode.SPECTATOR) {
|
|
|
|
for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) {
|
|
|
|
if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) {
|
2020-01-15 18:44:34 +01:00
|
|
|
currentPlayer.hidePlayer(player);
|
|
|
|
player.hidePlayer(currentPlayer);
|
2020-01-13 21:37:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(gameMode == GameMode.SURVIVAL) {
|
|
|
|
for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) {
|
|
|
|
if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) {
|
2020-01-15 18:44:34 +01:00
|
|
|
currentPlayer.showPlayer(player);
|
|
|
|
player.showPlayer(currentPlayer);
|
2020-01-13 21:37:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-18 08:31:13 +01:00
|
|
|
|
2020-05-16 16:39:16 +02:00
|
|
|
public static int getMaxRank(){
|
2020-05-22 10:09:34 +02:00
|
|
|
/* MaxRank of 0 is Pubonly*/
|
2020-05-16 16:39:16 +02:00
|
|
|
return schemRank;
|
2020-01-18 08:31:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void calcAvailibleSchemTypes() {
|
2020-01-19 17:32:29 +01:00
|
|
|
if(Config.OnlyPublicSchematics){
|
2020-05-22 10:09:34 +02:00
|
|
|
schemRank = 0;
|
2020-01-19 17:32:29 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-07 17:56:35 +02:00
|
|
|
if(Config.IgnorePublicOnly || Config.event() || Config.Ranked){
|
2020-05-16 16:39:16 +02:00
|
|
|
schemRank = 1000;
|
2020-04-11 12:26:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-19 07:23:02 +01:00
|
|
|
if(redTeam.getLeader() == null || redTeam.getLeader().getPlayer() == null ||
|
|
|
|
blueTeam.getLeader() == null || blueTeam.getLeader().getPlayer() == null){
|
2020-05-16 16:39:16 +02:00
|
|
|
schemRank = 1000;
|
2020-01-19 07:23:02 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-22 10:09:34 +02:00
|
|
|
if(Config.RanksEnabled)
|
|
|
|
schemRank = Math.min(schemRank(redTeam.getLeader()), schemRank(blueTeam.getLeader()));
|
|
|
|
else if(Schematic.getSchemsOfType(redTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty() ||
|
|
|
|
Schematic.getSchemsOfType(blueTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty())
|
|
|
|
schemRank = 0;
|
|
|
|
else
|
|
|
|
schemRank = 1;
|
2020-05-16 16:39:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static int schemRank(FightPlayer fightPlayer){
|
|
|
|
int rank = 1;
|
|
|
|
List<Schematic> schematics = Schematic.getSchemsOfType(fightPlayer.getPlayer().getUniqueId(), Config.SchematicType);
|
|
|
|
for(Schematic schem : schematics){
|
|
|
|
if(schem.getRank() > rank)
|
|
|
|
rank = schem.getRank();
|
|
|
|
}
|
|
|
|
return rank;
|
2020-01-18 08:31:13 +01:00
|
|
|
}
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|