2019-09-05 18:26:13 +02:00
|
|
|
package de.steamwar.fightsystem.commands;
|
|
|
|
|
|
|
|
import de.steamwar.fightsystem.FightSystem;
|
|
|
|
import de.steamwar.fightsystem.fight.Fight;
|
|
|
|
import de.steamwar.fightsystem.fight.FightPlayer;
|
|
|
|
import de.steamwar.fightsystem.fight.FightState;
|
|
|
|
import de.steamwar.fightsystem.fight.FightTeam;
|
|
|
|
import de.steamwar.fightsystem.kit.Kit;
|
|
|
|
import de.steamwar.fightsystem.kit.KitManager;
|
2019-06-04 18:22:29 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2019-06-05 22:14:27 +02:00
|
|
|
class Commands {
|
|
|
|
|
|
|
|
private Commands(){}
|
2019-06-04 18:22:29 +02:00
|
|
|
|
|
|
|
private static void errNoTeam(Player p){
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§cDu bist in keinem Team!");
|
|
|
|
}
|
|
|
|
|
2019-09-05 18:26:13 +02:00
|
|
|
static boolean checkSetup(Player p){
|
2019-06-04 18:22:29 +02:00
|
|
|
if(FightSystem.getFightState() != FightState.SETUP){
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§cDer Kampf hat bereits begonnen!");
|
2019-09-05 18:26:13 +02:00
|
|
|
return true;
|
2019-06-04 18:22:29 +02:00
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
return false;
|
2019-06-04 18:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static FightTeam checkGetInvitedTeam(Player p){
|
|
|
|
FightTeam fightTeam = Fight.getInvitedTeam(p);
|
|
|
|
if(fightTeam == null){
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§cDu wurdest von keinem Team eingeladen!");
|
|
|
|
}
|
|
|
|
return fightTeam;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static FightPlayer checkGetPlayer(Player p){
|
|
|
|
FightPlayer fightPlayer = Fight.getFightPlayer(p);
|
|
|
|
if(fightPlayer == null){
|
|
|
|
errNoTeam(p);
|
|
|
|
}
|
|
|
|
return fightPlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static FightPlayer checkGetLeader(Player p){
|
|
|
|
FightPlayer fightPlayer = checkGetPlayer(p);
|
|
|
|
if(fightPlayer != null && !fightPlayer.isLeader()){
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§cDu bist kein Leader!");
|
|
|
|
fightPlayer = null;
|
|
|
|
}
|
|
|
|
return fightPlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static FightTeam checkGetTeam(Player p){
|
|
|
|
FightTeam fightTeam = Fight.getPlayerTeam(p);
|
|
|
|
if(fightTeam == null){
|
|
|
|
errNoTeam(p);
|
|
|
|
}
|
|
|
|
return fightTeam;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Player checkGetPlayer(Player p, String t){
|
|
|
|
Player target = Bukkit.getPlayer(t);
|
|
|
|
if(target == null) {
|
2019-06-05 22:14:27 +02:00
|
|
|
p.sendMessage(FightSystem.PREFIX + "§cDer Spieler ist nicht in der Arena!");
|
2019-06-04 18:22:29 +02:00
|
|
|
}
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void toggleReady(Player p){
|
2019-09-05 18:26:13 +02:00
|
|
|
if(checkSetup(p))
|
2019-06-04 18:22:29 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
FightTeam fightTeam = checkGetTeam(p);
|
|
|
|
if(fightTeam == null || checkGetLeader(p) == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fightTeam.setReady(!fightTeam.isReady());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void acceptInvitation(Player p){
|
2019-09-05 18:26:13 +02:00
|
|
|
if(checkSetup(p))
|
2019-06-04 18:22:29 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
FightTeam team = checkGetInvitedTeam(p);
|
|
|
|
if(team == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
FightPlayer leader = team.getLeader();
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§aDu bist Team " + team.getName() + " §abeigetreten!");
|
2019-06-05 22:14:27 +02:00
|
|
|
leader.sendMessage(FightSystem.PREFIX + "§aDer Spieler §e" + p.getName() + " §aist deinem Team beigetreten!");
|
|
|
|
team.addMember(p);
|
2019-06-04 18:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void declineInvitation(Player p){
|
2019-09-05 18:26:13 +02:00
|
|
|
if(checkSetup(p))
|
2019-06-04 18:22:29 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
FightTeam team = checkGetInvitedTeam(p);
|
|
|
|
if(team == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
FightPlayer leader = team.getLeader();
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§aDu hast die Einladung von " + team.getName() + " §aabgelehnt!");
|
2019-06-05 22:14:27 +02:00
|
|
|
leader.sendMessage(FightSystem.PREFIX + "§cDer Spieler §e" + p.getName() + " §chat deine Einladung abgelehnt!");
|
|
|
|
team.getInvited().remove(p);
|
2019-06-04 18:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void leaveTeam(Player p){
|
2019-09-05 18:26:13 +02:00
|
|
|
if(checkSetup(p))
|
2019-06-04 18:22:29 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
FightTeam fightTeam = checkGetTeam(p);
|
|
|
|
if(fightTeam == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§aDu hast das Team " + fightTeam.getName() + " §averlassen!");
|
2019-06-05 22:14:27 +02:00
|
|
|
fightTeam.removePlayer(p);
|
2019-06-04 18:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void invite(Player p, String invited){
|
2019-09-05 18:26:13 +02:00
|
|
|
if(checkSetup(p))
|
2019-06-04 18:22:29 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
FightTeam fightTeam = checkGetTeam(p);
|
|
|
|
if(fightTeam == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
FightPlayer fightPlayer = checkGetLeader(p);
|
|
|
|
if(fightPlayer == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player target = checkGetPlayer(p, invited);
|
|
|
|
if(target == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(Fight.getPlayerTeam(target) != null) {
|
2019-06-05 22:14:27 +02:00
|
|
|
p.sendMessage(FightSystem.PREFIX + "§cDer Spieler §e" + target.getName() + " §cist bereits in einem Team!");
|
2019-06-04 18:22:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Fight.getOpposite(fightTeam).getInvited().contains(target) || fightTeam.getInvited().contains(target)) {
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§cDieser Spieler wurde bereits eingeladen!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-05 22:14:27 +02:00
|
|
|
target.sendMessage(FightSystem.PREFIX + "§aDu wurdest in das Team von §e" + p.getName() + " §aeingeladen!");
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§aDu hast den Spieler §e" + target.getName() + " §ain dein Team eingeladen!");
|
2019-06-04 18:22:29 +02:00
|
|
|
fightTeam.getInvited().add(target);
|
|
|
|
GUI.invitation(p, target);
|
|
|
|
}
|
|
|
|
|
2019-06-05 22:14:27 +02:00
|
|
|
static void kick(Player p, String kicked){
|
2019-09-05 18:26:13 +02:00
|
|
|
if(checkSetup(p))
|
2019-06-05 22:14:27 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
FightTeam fightTeam = checkGetTeam(p);
|
|
|
|
if(fightTeam == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
FightPlayer fightPlayer = checkGetLeader(p);
|
|
|
|
if(fightPlayer == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player target = checkGetPlayer(p, kicked);
|
|
|
|
if(target == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!fightTeam.isPlayerInTeam(target)){
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§cDer Spieler " + target.getName() + " §cist nicht in deinem Team§c!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§aDu hast den Spieler §e" + target.getName() + " §aaus dem Team entfernt!");
|
|
|
|
target.sendMessage(FightSystem.PREFIX + "§cDu wurdest aus dem Team entfernt!");
|
|
|
|
fightTeam.removePlayer(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kit(Player p, String kitName){
|
2019-09-05 18:26:13 +02:00
|
|
|
if(checkSetup(p))
|
2019-06-05 22:14:27 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
FightPlayer fightPlayer = checkGetPlayer(p);
|
|
|
|
if(fightPlayer == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Kit k = KitManager.getKitByName(kitName);
|
|
|
|
if(k == null){
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§cDieses Kit gibt es nicht!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((fightPlayer.isLeader() && !k.isLeaderAllowed()) ||
|
|
|
|
(!fightPlayer.isLeader() && !k.isMemberAllowed())){
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§cDu darfst dieses Kit nicht verwenden!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§aDu spielst nun mit dem Kit §e" + kitName + "§a!");
|
|
|
|
fightPlayer.setKit(k);
|
|
|
|
}
|
|
|
|
|
2019-06-04 18:22:29 +02:00
|
|
|
static void sendHelp(Player p) {
|
|
|
|
p.sendMessage(FightSystem.PREFIX + "§7Hilfe für das Kampfsystem");
|
|
|
|
|
2019-06-05 22:14:27 +02:00
|
|
|
FightPlayer fightPlayer = Fight.getFightPlayer(p);
|
|
|
|
if(fightPlayer == null){
|
|
|
|
p.sendMessage("§8/§eaccept §8- §7Einladung annehmen");
|
|
|
|
p.sendMessage("§8/§edecline §8- §7Einladung ablehnen");
|
2019-09-05 18:26:13 +02:00
|
|
|
p.sendMessage("§8/§eleader §8- §7Werde der Leader eines Teams");
|
2019-06-05 22:14:27 +02:00
|
|
|
}else{
|
|
|
|
if(fightPlayer.isLeader()){
|
|
|
|
p.sendMessage("§8/§eak schem §8<§eSchematic§8> - §7Setze deine Schematic");
|
|
|
|
p.sendMessage("§8/§eready §8- §7Setzt das eigene Team auf bereit");
|
|
|
|
p.sendMessage("§8/§einvite §8<§eSpieler§8> - §7Lade einen Spieler in dein Team ein");
|
2019-09-05 18:26:13 +02:00
|
|
|
p.sendMessage("§8/§eremove §8<§eSpieler§8> - §7Wirft einen Spieler aus dem Team");
|
2019-06-05 22:14:27 +02:00
|
|
|
}
|
|
|
|
p.sendMessage("§8/§ekit §8<§eKit§8> - §7Wähle ein Kit");
|
|
|
|
p.sendMessage("§8/§eleave §8- §7Team verlassen");
|
|
|
|
}
|
2019-06-04 18:22:29 +02:00
|
|
|
}
|
|
|
|
}
|