Add CommandAccept
Add CommandDecline Add CommandInvite Add InvitationSystem
Dieser Commit ist enthalten in:
Ursprung
e7d27fc133
Commit
828406220f
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.misslewars;
|
package de.steamwar.misslewars;
|
||||||
|
|
||||||
|
import de.steamwar.misslewars.items.Missile;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -133,6 +134,17 @@ public class MWTeam {
|
|||||||
MissileWars.end(WinReasons.NO_ENEMY, enemy());
|
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() {
|
private MWTeam enemy() {
|
||||||
if (this == MissileWars.getRedTeam())
|
if (this == MissileWars.getRedTeam())
|
||||||
return MissileWars.getBlueTeam();
|
return MissileWars.getBlueTeam();
|
||||||
@ -148,8 +160,17 @@ public class MWTeam {
|
|||||||
return players.contains(p);
|
return players.contains(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasInvite(Player p) {
|
||||||
|
return openInvitations.contains(p);
|
||||||
|
}
|
||||||
|
|
||||||
public String getColoredName() {
|
public String getColoredName() {
|
||||||
return color.toString() + teamName;
|
return color.toString() + teamName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void removeInvitations(Player p) {
|
||||||
|
MissileWars.getRedTeam().openInvitations.remove(p);
|
||||||
|
MissileWars.getBlueTeam().openInvitations.remove(p);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
package de.steamwar.misslewars;
|
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.commands.CommandSpectate;
|
||||||
import de.steamwar.misslewars.countdowns.EndCountdown;
|
import de.steamwar.misslewars.countdowns.EndCountdown;
|
||||||
import de.steamwar.misslewars.countdowns.ItemCountdown;
|
import de.steamwar.misslewars.countdowns.ItemCountdown;
|
||||||
@ -29,6 +32,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -62,7 +66,14 @@ public class MissileWars extends JavaPlugin {
|
|||||||
new FightListener();
|
new FightListener();
|
||||||
new ChatListener();
|
new ChatListener();
|
||||||
getCommand("spectate").setExecutor(new CommandSpectate());
|
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 WaitingCountdown();
|
||||||
new ItemCountdown();
|
new ItemCountdown();
|
||||||
@ -137,6 +148,14 @@ public class MissileWars extends JavaPlugin {
|
|||||||
return null;
|
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) {
|
public static void join(Player p) {
|
||||||
if (MissileWars.getRedTeam().size() < MissileWars.getBlueTeam().size()) {
|
if (MissileWars.getRedTeam().size() < MissileWars.getBlueTeam().size()) {
|
||||||
MissileWars.getRedTeam().join(p);
|
MissileWars.getRedTeam().join(p);
|
||||||
|
53
src/de/steamwar/misslewars/commands/CommandAccept.java
Normale Datei
53
src/de/steamwar/misslewars/commands/CommandAccept.java
Normale Datei
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
54
src/de/steamwar/misslewars/commands/CommandDecline.java
Normale Datei
54
src/de/steamwar/misslewars/commands/CommandDecline.java
Normale Datei
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -22,12 +22,19 @@
|
|||||||
package de.steamwar.misslewars.commands;
|
package de.steamwar.misslewars.commands;
|
||||||
|
|
||||||
import de.steamwar.misslewars.Config;
|
import de.steamwar.misslewars.Config;
|
||||||
|
import de.steamwar.misslewars.MissileWars;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
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
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
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.");
|
player.sendMessage("§cDieser Command ist deaktiviert.");
|
||||||
return false;
|
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;
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.misslewars.listener;
|
package de.steamwar.misslewars.listener;
|
||||||
|
|
||||||
import de.steamwar.misslewars.FightState;
|
import de.steamwar.misslewars.FightState;
|
||||||
|
import de.steamwar.misslewars.MWTeam;
|
||||||
import de.steamwar.misslewars.MissileWars;
|
import de.steamwar.misslewars.MissileWars;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -42,6 +43,7 @@ public class ConnectionListener extends BasicListener{
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLeave(PlayerQuitEvent e) {
|
public void onLeave(PlayerQuitEvent e) {
|
||||||
|
MWTeam.removeInvitations(e.getPlayer());
|
||||||
MissileWars.leave(e.getPlayer());
|
MissileWars.leave(e.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,3 +13,5 @@ depend:
|
|||||||
commands:
|
commands:
|
||||||
spectate:
|
spectate:
|
||||||
invite:
|
invite:
|
||||||
|
accept:
|
||||||
|
decline:
|
In neuem Issue referenzieren
Einen Benutzer sperren