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/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java

174 Zeilen
6.2 KiB
Java

/*
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-11-16 08:37:33 +01:00
import de.steamwar.fightsystem.Config;
import de.steamwar.sql.Schematic;
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;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import java.util.List;
public class Fight {
2019-09-05 18:26:13 +02:00
private Fight(){}
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);
private static int schemRank;
2019-11-16 08:37:33 +01:00
public static void init(){
IFight.init(redTeam, blueTeam);
}
public static FightTeam getPlayerTeam(Player player) {
2019-02-23 16:07:31 +01:00
if(redTeam.isPlayerInTeam(player))
return redTeam;
2019-02-23 16:07:31 +01:00
if(blueTeam.isPlayerInTeam(player))
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)
return blueTeam;
2019-09-05 18:26:13 +02:00
else
return redTeam;
}
public static FightTeam getInvitedTeam(Player player){
2019-02-23 16:07:31 +01:00
if(redTeam.getInvited().contains(player))
return redTeam;
2019-02-23 16:07:31 +01:00
else if(blueTeam.getInvited().contains(player))
return blueTeam;
return null;
}
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);
return null;
}
public static FightTeam getRedTeam() {
return redTeam;
}
public static FightTeam getBlueTeam() {
return blueTeam;
}
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));
}
public static void setLevel(int level) {
2019-09-05 18:26:13 +02:00
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(level));
}
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: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
}
}
}
}
public static int getMaxRank(){
/* MaxRank of 0 is Pubonly*/
return schemRank;
}
public static void calcAvailibleSchemTypes() {
if(Config.OnlyPublicSchematics){
schemRank = 0;
return;
}
if(Config.IgnorePublicOnly || Config.event() || Config.Ranked){
schemRank = 1000;
return;
}
if(redTeam.getLeader() == null || redTeam.getLeader().getPlayer() == null ||
blueTeam.getLeader() == null || blueTeam.getLeader().getPlayer() == null){
schemRank = 1000;
return;
}
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;
}
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;
}
}