First Cleanup + hasTeamLeader Bugfix
Dieser Commit ist enthalten in:
Ursprung
b0f5833d59
Commit
5e8c65ea94
@ -10,48 +10,34 @@ public class Fight {
|
||||
|
||||
|
||||
public static FightTeam getPlayerTeam(Player player) {
|
||||
if(redTeam.isPlayerInTeam(player)) {
|
||||
if(redTeam.isPlayerInTeam(player))
|
||||
return redTeam;
|
||||
}
|
||||
if(blueTeam.isPlayerInTeam(player)) {
|
||||
if(blueTeam.isPlayerInTeam(player))
|
||||
return blueTeam;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FightTeam getOpposite(FightTeam fightTeam) {
|
||||
if(fightTeam == redTeam) {
|
||||
if(fightTeam == redTeam)
|
||||
return blueTeam;
|
||||
}
|
||||
if(fightTeam == blueTeam) {
|
||||
if(fightTeam == blueTeam)
|
||||
return redTeam;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FightTeam getInvitedTeam(Player player){
|
||||
if(redTeam.getInvited().contains(player)) {
|
||||
if(redTeam.getInvited().contains(player))
|
||||
return redTeam;
|
||||
}else if(blueTeam.getInvited().contains(player)) {
|
||||
else if(blueTeam.getInvited().contains(player))
|
||||
return blueTeam;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void broadcast(String message) {
|
||||
blueTeam.broadcast(message);
|
||||
redTeam.broadcast(message);
|
||||
}
|
||||
|
||||
public static FightPlayer getFightPlayer(Player player) {
|
||||
if(redTeam.isPlayerInTeam(player)) {
|
||||
FightPlayer fightPlayer = redTeam.getFightPlayer(player);
|
||||
return fightPlayer;
|
||||
}
|
||||
if(blueTeam.isPlayerInTeam(player)) {
|
||||
FightPlayer fightPlayer = blueTeam.getFightPlayer(player);
|
||||
return fightPlayer;
|
||||
}
|
||||
if(redTeam.isPlayerInTeam(player))
|
||||
return redTeam.getFightPlayer(player);
|
||||
if(blueTeam.isPlayerInTeam(player))
|
||||
return blueTeam.getFightPlayer(player);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -8,18 +8,16 @@ public class FightPlayer {
|
||||
private boolean isOut;
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Player)) {
|
||||
if (!(obj instanceof Player))
|
||||
return false;
|
||||
}
|
||||
Player comp = (Player)obj;
|
||||
return this.player.getUniqueId().equals(comp.getUniqueId());
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
if (this.player.isOnline()) {
|
||||
if (this.player != null && this.player.isOnline())
|
||||
this.player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public FightPlayer(Player player, boolean isOut) {
|
||||
this.player = player;
|
||||
@ -39,10 +37,7 @@ public class FightPlayer {
|
||||
}
|
||||
|
||||
public boolean isLeader() {
|
||||
if(Fight.getPlayerTeam(player).getLeader().getPlayer() == player) {
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
return Fight.getPlayerTeam(player).getLeader().getPlayer() == player);
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,88 +24,71 @@ public class FightTeam {
|
||||
public FightTeam(Player leader, FightSystem plugin) {
|
||||
this.plugin = plugin;
|
||||
this.leader = new FightPlayer(leader, false);
|
||||
this.players = new ArrayList<>();
|
||||
this.invited = new ArrayList<>();
|
||||
players = new ArrayList<>();
|
||||
invited = new ArrayList<>();
|
||||
}
|
||||
|
||||
public FightPlayer getFightPlayer(Player player) {
|
||||
if(this.leader.getPlayer().equals(player)) {
|
||||
return this.leader;
|
||||
}
|
||||
for(FightPlayer fightPlayer : this.players) {
|
||||
if(!fightPlayer.getPlayer().equals(player)) continue;
|
||||
if(leader.getPlayer().equals(player))
|
||||
return leader;
|
||||
for(FightPlayer fightPlayer : players) {
|
||||
if(fightPlayer.getPlayer().equals(player))
|
||||
return fightPlayer;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPlayerOut(Player player) {
|
||||
this.getFightPlayer(player).setOut(true);
|
||||
getFightPlayer(player).setOut(true);
|
||||
}
|
||||
|
||||
public boolean allPlayersOut() {
|
||||
boolean allout = true;
|
||||
if(!this.leader.isOut()) {
|
||||
allout = false;
|
||||
return false;
|
||||
}
|
||||
for(FightPlayer fightPlayer : this.players) {
|
||||
if(fightPlayer.isOut()) continue;
|
||||
allout = false;
|
||||
if(!fightPlayer.isOut())
|
||||
return false;
|
||||
}
|
||||
return allout;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isPlayerInTeam(Player player) {
|
||||
for(FightPlayer fightPlayer : this.players) {
|
||||
if(!fightPlayer.getPlayer().equals(player)) continue;
|
||||
if(fightPlayer.getPlayer().equals(player))
|
||||
return true;
|
||||
}
|
||||
if(this.leader.getPlayer() == null) return false;
|
||||
|
||||
if(this.leader.getPlayer().equals(player)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return leader.getPlayer() != null && leader.getPlayer().equals(player);
|
||||
}
|
||||
|
||||
public boolean isPlayerLeader(Player player) {
|
||||
if(this.leader.getPlayer().equals(player)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return leader.getPlayer().equals(player);
|
||||
}
|
||||
|
||||
public boolean isPlayerMember(Player player) {
|
||||
for(FightPlayer fightPlayer : this.players) {
|
||||
if(!fightPlayer.getPlayer().equals(player)) continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return isPlayerInTeam(player) && !isPlayerLeader(player);
|
||||
}
|
||||
|
||||
public void broadcast(String message) {
|
||||
this.leader.sendMessage(message);
|
||||
for(FightPlayer fightPlayer : this.players) {
|
||||
leader.sendMessage(message);
|
||||
for(FightPlayer fightPlayer : players) {
|
||||
fightPlayer.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void addMember(Player player) {
|
||||
FightPlayer fightPlayer = new FightPlayer(player, false);
|
||||
this.players.add(fightPlayer);
|
||||
this.invited.remove(player);
|
||||
players.add(fightPlayer);
|
||||
invited.remove(player);
|
||||
}
|
||||
|
||||
public void removePlayer(Player player) {
|
||||
FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player);
|
||||
this.players.remove(fightPlayer);
|
||||
players.remove(fightPlayer);
|
||||
}
|
||||
|
||||
public boolean hasTeamLeader() {
|
||||
if(this.leader != null) {
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
return leader.getPlayer() != null;
|
||||
}
|
||||
|
||||
public FightPlayer getLeader() {
|
||||
|
@ -28,18 +28,15 @@ public class PlayerInteractListener implements Listener {
|
||||
@EventHandler
|
||||
public void handlePlayerInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(instance.getFightState() == FightState.SETUP &&
|
||||
event.getItem() != null &&
|
||||
Fight.getPlayerTeam(player) != null) {
|
||||
Material material = event.getItem().getType();
|
||||
ItemMeta itemMeta = event.getItem().getItemMeta();
|
||||
String displayName = itemMeta.getDisplayName();
|
||||
|
||||
if(instance.getFightState() == FightState.SETUP) {
|
||||
if(Fight.getPlayerTeam(player) == null) return;
|
||||
FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player);
|
||||
if(fightPlayer.isLeader()) {
|
||||
|
||||
if(material == null) return;
|
||||
if(material == Material.INK_SACK) {
|
||||
|
||||
if(fightPlayer.isLeader() && material == Material.INK_SACK) {
|
||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
||||
|
||||
switch (displayName) {
|
||||
@ -54,7 +51,6 @@ public class PlayerInteractListener implements Listener {
|
||||
Countdown countdown = new Countdown(20*30, new FinishNoPlayersOnline());
|
||||
countdown.startTimer(instance);
|
||||
break;
|
||||
|
||||
default:
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
@ -62,7 +58,6 @@ public class PlayerInteractListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -47,32 +47,30 @@ public class PlayerJoinListener implements Listener {
|
||||
|
||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
||||
|
||||
if(Fight.getPlayerTeam(player) != null) {
|
||||
if(fightTeam != null) {
|
||||
FightPlayer fightPlayer = fightTeam.getFightPlayer(player);
|
||||
|
||||
if(instance.getFightState() == FightState.SETUP) {
|
||||
if(fightTeam == Fight.redTeam) {
|
||||
if(fightTeam == Fight.redTeam)
|
||||
player.teleport(instance.getFightManager().getRedTeleportLocation());
|
||||
} else
|
||||
else
|
||||
player.teleport(instance.getFightManager().getBlueTeleportLocation());
|
||||
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
if(fightPlayer.isLeader()) SetupItems.giveSetupItems(player);
|
||||
if(fightPlayer.isOut()) {
|
||||
fightPlayer.setOut(false);
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §6" + fightPlayer.getPlayer().getName() + " §aist dem Kampf wieder beigetreten!");
|
||||
}
|
||||
} else {
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
if(fightTeam == Fight.redTeam) {
|
||||
if(fightTeam == Fight.redTeam)
|
||||
player.teleport(FightSystem.getPlugin().getTeam1SpawnLoc());
|
||||
} else
|
||||
else
|
||||
player.teleport(FightSystem.getPlugin().getTeam2SpawnLoc());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(Fight.getRedTeam().getLeader().getPlayer() != null && Fight.getBlueTeam().getLeader().getPlayer() != null) {
|
||||
if(Fight.getRedTeam().hasTeamLeader() && Fight.getBlueTeam().hasTeamLeader()) {
|
||||
int setupDuration = fileManager.getIntegerFromConfig("Times.SetupDuration");
|
||||
Countdown countdown = new Countdown(setupDuration, new FinishSetupOver());
|
||||
countdown.startTimer(instance);
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren