SteamWar/FightSystem
Archiviert
13
1

First Cleanup + hasTeamLeader Bugfix

Dieser Commit ist enthalten in:
lixfel 2019-02-23 16:07:31 +01:00
Ursprung b0f5833d59
Commit 5e8c65ea94
5 geänderte Dateien mit 68 neuen und 111 gelöschten Zeilen

Datei anzeigen

@ -10,48 +10,34 @@ public class Fight {
public static FightTeam getPlayerTeam(Player player) { public static FightTeam getPlayerTeam(Player player) {
if(redTeam.isPlayerInTeam(player)) { if(redTeam.isPlayerInTeam(player))
return redTeam; return redTeam;
} if(blueTeam.isPlayerInTeam(player))
if(blueTeam.isPlayerInTeam(player)) {
return blueTeam; return blueTeam;
}
return null; return null;
} }
public static FightTeam getOpposite(FightTeam fightTeam) { public static FightTeam getOpposite(FightTeam fightTeam) {
if(fightTeam == redTeam) { if(fightTeam == redTeam)
return blueTeam; return blueTeam;
} if(fightTeam == blueTeam)
if(fightTeam == blueTeam) {
return redTeam; return redTeam;
}
return null; return null;
} }
public static FightTeam getInvitedTeam(Player player){ public static FightTeam getInvitedTeam(Player player){
if(redTeam.getInvited().contains(player)) { if(redTeam.getInvited().contains(player))
return redTeam; return redTeam;
}else if(blueTeam.getInvited().contains(player)) { else if(blueTeam.getInvited().contains(player))
return blueTeam; return blueTeam;
}
return null; return null;
} }
public void broadcast(String message) {
blueTeam.broadcast(message);
redTeam.broadcast(message);
}
public static FightPlayer getFightPlayer(Player player) { public static FightPlayer getFightPlayer(Player player) {
if(redTeam.isPlayerInTeam(player)) { if(redTeam.isPlayerInTeam(player))
FightPlayer fightPlayer = redTeam.getFightPlayer(player); return redTeam.getFightPlayer(player);
return fightPlayer; if(blueTeam.isPlayerInTeam(player))
} return blueTeam.getFightPlayer(player);
if(blueTeam.isPlayerInTeam(player)) {
FightPlayer fightPlayer = blueTeam.getFightPlayer(player);
return fightPlayer;
}
return null; return null;
} }

Datei anzeigen

@ -8,17 +8,15 @@ public class FightPlayer {
private boolean isOut; private boolean isOut;
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof Player)) { if (!(obj instanceof Player))
return false; return false;
}
Player comp = (Player)obj; Player comp = (Player)obj;
return this.player.getUniqueId().equals(comp.getUniqueId()); return this.player.getUniqueId().equals(comp.getUniqueId());
} }
public void sendMessage(String message) { public void sendMessage(String message) {
if (this.player.isOnline()) { if (this.player != null && this.player.isOnline())
this.player.sendMessage(message); this.player.sendMessage(message);
}
} }
public FightPlayer(Player player, boolean isOut) { public FightPlayer(Player player, boolean isOut) {
@ -39,10 +37,7 @@ public class FightPlayer {
} }
public boolean isLeader() { public boolean isLeader() {
if(Fight.getPlayerTeam(player).getLeader().getPlayer() == player) { return Fight.getPlayerTeam(player).getLeader().getPlayer() == player);
return true;
} else
return false;
} }

Datei anzeigen

@ -24,88 +24,71 @@ public class FightTeam {
public FightTeam(Player leader, FightSystem plugin) { public FightTeam(Player leader, FightSystem plugin) {
this.plugin = plugin; this.plugin = plugin;
this.leader = new FightPlayer(leader, false); this.leader = new FightPlayer(leader, false);
this.players = new ArrayList<>(); players = new ArrayList<>();
this.invited = new ArrayList<>(); invited = new ArrayList<>();
} }
public FightPlayer getFightPlayer(Player player) { public FightPlayer getFightPlayer(Player player) {
if(this.leader.getPlayer().equals(player)) { if(leader.getPlayer().equals(player))
return this.leader; return leader;
} for(FightPlayer fightPlayer : players) {
for(FightPlayer fightPlayer : this.players) { if(fightPlayer.getPlayer().equals(player))
if(!fightPlayer.getPlayer().equals(player)) continue; return fightPlayer;
return fightPlayer;
} }
return null; return null;
} }
public void setPlayerOut(Player player) { public void setPlayerOut(Player player) {
this.getFightPlayer(player).setOut(true); getFightPlayer(player).setOut(true);
} }
public boolean allPlayersOut() { public boolean allPlayersOut() {
boolean allout = true;
if(!this.leader.isOut()) { if(!this.leader.isOut()) {
allout = false; return false;
} }
for(FightPlayer fightPlayer : this.players) { for(FightPlayer fightPlayer : this.players) {
if(fightPlayer.isOut()) continue; if(!fightPlayer.isOut())
allout = false; return false;
} }
return allout; return true;
} }
public boolean isPlayerInTeam(Player player) { public boolean isPlayerInTeam(Player player) {
for(FightPlayer fightPlayer : this.players) { for(FightPlayer fightPlayer : this.players) {
if(!fightPlayer.getPlayer().equals(player)) continue; if(fightPlayer.getPlayer().equals(player))
return true; return true;
} }
if(this.leader.getPlayer() == null) return false; return leader.getPlayer() != null && leader.getPlayer().equals(player);
if(this.leader.getPlayer().equals(player)) {
return true;
}
return false;
} }
public boolean isPlayerLeader(Player player) { public boolean isPlayerLeader(Player player) {
if(this.leader.getPlayer().equals(player)) { return leader.getPlayer().equals(player);
return true;
}
return false;
} }
public boolean isPlayerMember(Player player) { public boolean isPlayerMember(Player player) {
for(FightPlayer fightPlayer : this.players) { return isPlayerInTeam(player) && !isPlayerLeader(player);
if(!fightPlayer.getPlayer().equals(player)) continue;
return true;
}
return false;
} }
public void broadcast(String message) { public void broadcast(String message) {
this.leader.sendMessage(message); leader.sendMessage(message);
for(FightPlayer fightPlayer : this.players) { for(FightPlayer fightPlayer : players) {
fightPlayer.sendMessage(message); fightPlayer.sendMessage(message);
} }
} }
public void addMember(Player player) { public void addMember(Player player) {
FightPlayer fightPlayer = new FightPlayer(player, false); FightPlayer fightPlayer = new FightPlayer(player, false);
this.players.add(fightPlayer); players.add(fightPlayer);
this.invited.remove(player); invited.remove(player);
} }
public void removePlayer(Player player) { public void removePlayer(Player player) {
FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player); FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player);
this.players.remove(fightPlayer); players.remove(fightPlayer);
} }
public boolean hasTeamLeader() { public boolean hasTeamLeader() {
if(this.leader != null) { return leader.getPlayer() != null;
return true;
} else
return false;
} }
public FightPlayer getLeader() { public FightPlayer getLeader() {

Datei anzeigen

@ -28,37 +28,32 @@ public class PlayerInteractListener implements Listener {
@EventHandler @EventHandler
public void handlePlayerInteract(PlayerInteractEvent event) { public void handlePlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Material material = event.getItem().getType(); if(instance.getFightState() == FightState.SETUP &&
ItemMeta itemMeta = event.getItem().getItemMeta(); event.getItem() != null &&
String displayName = itemMeta.getDisplayName(); 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); FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player);
if(fightPlayer.isLeader()) { if(fightPlayer.isLeader() && material == Material.INK_SACK) {
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(material == null) return; switch (displayName) {
if(material == Material.INK_SACK) { case "§cNicht bereit":
fightTeam.setReady(true);
FightTeam fightTeam = Fight.getPlayerTeam(player); break;
case "§aBereit":
switch (displayName) { fightTeam.setReady(false);
case "§cNicht bereit": break;
fightTeam.setReady(true); case "§4Abbrechen":
break; Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team von §a" + fightTeam.getLeader().getPlayer().getName() + " §6hat den Kampf abgebrochen! \n Server stoppt in 30 Sekunden...");
case "§aBereit": Countdown countdown = new Countdown(20*30, new FinishNoPlayersOnline());
fightTeam.setReady(false); countdown.startTimer(instance);
break; break;
case "§4Abbrechen": default:
Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team von §a" + fightTeam.getLeader().getPlayer().getName() + " §6hat den Kampf abgebrochen! \n Server stoppt in 30 Sekunden..."); event.setCancelled(true);
Countdown countdown = new Countdown(20*30, new FinishNoPlayersOnline()); break;
countdown.startTimer(instance);
break;
default:
event.setCancelled(true);
break;
}
} }
} }
} }

Datei anzeigen

@ -47,32 +47,30 @@ public class PlayerJoinListener implements Listener {
FightTeam fightTeam = Fight.getPlayerTeam(player); FightTeam fightTeam = Fight.getPlayerTeam(player);
if(Fight.getPlayerTeam(player) != null) { if(fightTeam != null) {
FightPlayer fightPlayer = fightTeam.getFightPlayer(player); FightPlayer fightPlayer = fightTeam.getFightPlayer(player);
if(instance.getFightState() == FightState.SETUP) { if(instance.getFightState() == FightState.SETUP) {
if(fightTeam == Fight.redTeam) { if(fightTeam == Fight.redTeam)
player.teleport(instance.getFightManager().getRedTeleportLocation()); player.teleport(instance.getFightManager().getRedTeleportLocation());
} else else
player.teleport(instance.getFightManager().getBlueTeleportLocation()); player.teleport(instance.getFightManager().getBlueTeleportLocation());
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.ADVENTURE);
if(fightPlayer.isLeader()) SetupItems.giveSetupItems(player); if(fightPlayer.isLeader()) SetupItems.giveSetupItems(player);
if(fightPlayer.isOut()) { fightPlayer.setOut(false);
fightPlayer.setOut(false); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §6" + fightPlayer.getPlayer().getName() + " §aist dem Kampf wieder beigetreten!");
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §6" + fightPlayer.getPlayer().getName() + " §aist dem Kampf wieder beigetreten!");
}
} else { } else {
player.setGameMode(GameMode.SPECTATOR); player.setGameMode(GameMode.SPECTATOR);
if(fightTeam == Fight.redTeam) { if(fightTeam == Fight.redTeam)
player.teleport(FightSystem.getPlugin().getTeam1SpawnLoc()); player.teleport(FightSystem.getPlugin().getTeam1SpawnLoc());
} else else
player.teleport(FightSystem.getPlugin().getTeam2SpawnLoc()); 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"); int setupDuration = fileManager.getIntegerFromConfig("Times.SetupDuration");
Countdown countdown = new Countdown(setupDuration, new FinishSetupOver()); Countdown countdown = new Countdown(setupDuration, new FinishSetupOver());
countdown.startTimer(instance); countdown.startTimer(instance);