SteamWar/MissileWars
Archiviert
13
0

Add CommandAccept

Add CommandDecline
Add CommandInvite
Add InvitationSystem
Dieser Commit ist enthalten in:
jojo 2020-12-19 11:38:38 +01:00
Ursprung e7d27fc133
Commit 828406220f
7 geänderte Dateien mit 203 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.misslewars;
import de.steamwar.misslewars.items.Missile;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -132,6 +133,17 @@ public class MWTeam {
if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING)
MissileWars.end(WinReasons.NO_ENEMY, enemy());
}
public void invitePlayer(Player p) {
if (enemy().openInvitations.contains(p)) return;
openInvitations.add(p);
}
public void acceptInvite(Player p) {
removeInvitations(p);
join(p);
}
private MWTeam enemy() {
if (this == MissileWars.getRedTeam())
@ -144,12 +156,21 @@ public class MWTeam {
return "§" + color.getChar();
}
public boolean hasPlayer (Player p) {
public boolean hasPlayer(Player p) {
return players.contains(p);
}
public boolean hasInvite(Player p) {
return openInvitations.contains(p);
}
public String getColoredName() {
return color.toString() + teamName;
}
public static void removeInvitations(Player p) {
MissileWars.getRedTeam().openInvitations.remove(p);
MissileWars.getBlueTeam().openInvitations.remove(p);
}
}

Datei anzeigen

@ -19,6 +19,9 @@
package de.steamwar.misslewars;
import de.steamwar.misslewars.commands.CommandAccept;
import de.steamwar.misslewars.commands.CommandDecline;
import de.steamwar.misslewars.commands.CommandInvite;
import de.steamwar.misslewars.commands.CommandSpectate;
import de.steamwar.misslewars.countdowns.EndCountdown;
import de.steamwar.misslewars.countdowns.ItemCountdown;
@ -29,6 +32,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@ -62,7 +66,14 @@ public class MissileWars extends JavaPlugin {
new FightListener();
new ChatListener();
getCommand("spectate").setExecutor(new CommandSpectate());
getCommand("invite").setExecutor(new CommandSpectate());
// Invitation Commands
CommandInvite commandInvite = new CommandInvite();
getCommand("invite").setExecutor(commandInvite);
getCommand("invite").setTabCompleter(commandInvite);
getCommand("accept").setExecutor(new CommandAccept());
getCommand("decline").setExecutor(new CommandDecline());
new WaitingCountdown();
new ItemCountdown();
@ -137,6 +148,14 @@ public class MissileWars extends JavaPlugin {
return null;
}
public static MWTeam getInvitation(Player p) {
if(blueTeam.hasInvite(p))
return blueTeam;
if(redTeam.hasInvite(p))
return redTeam;
return null;
}
public static void join(Player p) {
if (MissileWars.getRedTeam().size() < MissileWars.getBlueTeam().size()) {
MissileWars.getRedTeam().join(p);

Datei anzeigen

@ -0,0 +1,53 @@
/*
*
* 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/>.
* /
*/
package de.steamwar.misslewars.commands;
import de.steamwar.misslewars.Config;
import de.steamwar.misslewars.MWTeam;
import de.steamwar.misslewars.MissileWars;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandAccept implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) return false;
Player player = (Player) sender;
if (!Config.isChallenge()) {
player.sendMessage("§cDieser Command ist deaktiviert.");
return false;
}
MWTeam teamInvitation = MissileWars.getInvitation(player);
if (teamInvitation == null) {
player.sendMessage("§cDu wurdest nicht eingeladen.");
return false;
}
teamInvitation.acceptInvite(player);
return false;
}
}

Datei anzeigen

@ -0,0 +1,54 @@
/*
*
* 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/>.
* /
*/
package de.steamwar.misslewars.commands;
import de.steamwar.misslewars.Config;
import de.steamwar.misslewars.MWTeam;
import de.steamwar.misslewars.MissileWars;
import de.steamwar.misslewars.items.Missile;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandDecline implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) return false;
Player player = (Player) sender;
if (!Config.isChallenge()) {
player.sendMessage("§cDieser Command ist deaktiviert.");
return false;
}
MWTeam teamInvitation = MissileWars.getInvitation(player);
if (teamInvitation == null) {
player.sendMessage("§cDu wurdest nicht eingeladen.");
return false;
}
MWTeam.removeInvitations(player);
return false;
}
}

Datei anzeigen

@ -22,12 +22,19 @@
package de.steamwar.misslewars.commands;
import de.steamwar.misslewars.Config;
import de.steamwar.misslewars.MissileWars;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
public class CommandInvite implements CommandExecutor {
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class CommandInvite implements CommandExecutor, TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -37,7 +44,48 @@ public class CommandInvite implements CommandExecutor {
player.sendMessage("§cDieser Command ist deaktiviert.");
return false;
}
if (!Config.RedLeader.equals(player.getUniqueId()) && !Config.BlueLeader.equals(player.getUniqueId())) {
player.sendMessage("§cDu kannst keine Spieler einladen.");
return false;
}
if (MissileWars.getTeam(player) == null) {
player.sendMessage("§cDu kannst keine Spieler einladen.");
return false;
}
if (args.length != 1) {
player.sendMessage("§c/invite <PLAYER>");
return false;
}
Player invitedPlayer = Bukkit.getPlayer(args[0]);
if (MissileWars.getTeam(invitedPlayer) != null) {
player.sendMessage("§cDieser Spieler ist bereits in einem Team.");
return false;
}
if (MissileWars.getInvitation(invitedPlayer) != null) {
player.sendMessage("§cDieser Spieler wurde bereits eingeladen.");
return false;
}
MissileWars.getTeam(player).invitePlayer(invitedPlayer);
invitedPlayer.sendMessage("§7Du wurdest von §6" + player.getName() + "§7 in das Team §6" + MissileWars.getTeam(player).getColoredName() + "§7 eingeladen.");
invitedPlayer.sendMessage("§8/§6accept §8- §7Zum akzeptieren.");
invitedPlayer.sendMessage("§8/§6decline §8- §7Zum ablehnen.");
return false;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (args.length != 1) return new ArrayList<>();
return Bukkit.getOnlinePlayers()
.stream()
.filter(p -> MissileWars.getTeam(p) != null)
.filter(p -> MissileWars.getInvitation(p) != null)
.map(Player::getName)
.filter(s -> s.startsWith(args[0]))
.collect(Collectors.toList());
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.misslewars.listener;
import de.steamwar.misslewars.FightState;
import de.steamwar.misslewars.MWTeam;
import de.steamwar.misslewars.MissileWars;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
@ -42,6 +43,7 @@ public class ConnectionListener extends BasicListener{
@EventHandler
public void onLeave(PlayerQuitEvent e) {
MWTeam.removeInvitations(e.getPlayer());
MissileWars.leave(e.getPlayer());
}

Datei anzeigen

@ -12,4 +12,6 @@ depend:
- SpigotCore
commands:
spectate:
invite:
invite:
accept:
decline: