From e7d27fc1338be000859a3ddc5272f2fc305d21d7 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 18 Dec 2020 23:33:29 +0100 Subject: [PATCH] Add CommandInvite Add CommandSpectate disable while challenge Add openInvitation HashSet --- src/de/steamwar/misslewars/Config.java | 2 +- src/de/steamwar/misslewars/MWTeam.java | 12 ++++-- src/de/steamwar/misslewars/MissileWars.java | 1 + .../misslewars/commands/CommandInvite.java | 43 +++++++++++++++++++ .../misslewars/commands/CommandSpectate.java | 9 +++- src/plugin.yml | 3 +- 6 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 src/de/steamwar/misslewars/commands/CommandInvite.java diff --git a/src/de/steamwar/misslewars/Config.java b/src/de/steamwar/misslewars/Config.java index da66400..b56c7cc 100644 --- a/src/de/steamwar/misslewars/Config.java +++ b/src/de/steamwar/misslewars/Config.java @@ -100,7 +100,7 @@ public class Config { RedLeader = null; } - public boolean isChallenge() { + public static boolean isChallenge() { return BlueLeader != null && RedLeader != null; } diff --git a/src/de/steamwar/misslewars/MWTeam.java b/src/de/steamwar/misslewars/MWTeam.java index 82be00a..59e189b 100644 --- a/src/de/steamwar/misslewars/MWTeam.java +++ b/src/de/steamwar/misslewars/MWTeam.java @@ -19,9 +19,10 @@ package de.steamwar.misslewars; -import de.steamwar.comms.packets.TablistNamePacket; -import de.steamwar.sql.SteamwarUser; -import org.bukkit.*; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -30,8 +31,10 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; +import java.util.HashSet; import java.util.LinkedList; import java.util.Objects; +import java.util.Set; public class MWTeam { private static final ItemStack bow = new ItemStack(Material.BOW); @@ -52,7 +55,8 @@ public class MWTeam { private final Location spawn; private final int portalZ; - private LinkedList players = new LinkedList<>(); + private final LinkedList players = new LinkedList<>(); + private final Set openInvitations = new HashSet<>(); MWTeam(ChatColor color, Location spawn, String teamName, int portalZ) { this.teamName = teamName; diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index f48e70a..ad90c0c 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -62,6 +62,7 @@ public class MissileWars extends JavaPlugin { new FightListener(); new ChatListener(); getCommand("spectate").setExecutor(new CommandSpectate()); + getCommand("invite").setExecutor(new CommandSpectate()); new WaitingCountdown(); new ItemCountdown(); diff --git a/src/de/steamwar/misslewars/commands/CommandInvite.java b/src/de/steamwar/misslewars/commands/CommandInvite.java new file mode 100644 index 0000000..8126ca8 --- /dev/null +++ b/src/de/steamwar/misslewars/commands/CommandInvite.java @@ -0,0 +1,43 @@ +/* + * + * 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 . + * / + */ + +package de.steamwar.misslewars.commands; + +import de.steamwar.misslewars.Config; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandInvite 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; + } + return false; + } + +} diff --git a/src/de/steamwar/misslewars/commands/CommandSpectate.java b/src/de/steamwar/misslewars/commands/CommandSpectate.java index 6efa06f..4a8c1f2 100644 --- a/src/de/steamwar/misslewars/commands/CommandSpectate.java +++ b/src/de/steamwar/misslewars/commands/CommandSpectate.java @@ -19,6 +19,7 @@ package de.steamwar.misslewars.commands; +import de.steamwar.misslewars.Config; import de.steamwar.misslewars.MWTeam; import de.steamwar.misslewars.MissileWars; import org.bukkit.GameMode; @@ -31,8 +32,12 @@ public class CommandSpectate implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) return false; + if (!(sender instanceof Player)) return false; Player player = (Player) sender; + if (Config.isChallenge()) { + player.sendMessage("§cDieser Command ist deaktiviert."); + return false; + } MWTeam mwTeam = MissileWars.getTeam(player); if (mwTeam == null) return false; @@ -42,6 +47,8 @@ public class CommandSpectate implements CommandExecutor { } MissileWars.leave(player); player.setGameMode(GameMode.SPECTATOR); + player.getInventory().clear(); + player.updateInventory(); return true; } diff --git a/src/plugin.yml b/src/plugin.yml index 452b135..c95edb1 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -11,4 +11,5 @@ depend: - WorldEdit - SpigotCore commands: - spectate: \ No newline at end of file + spectate: + invite: \ No newline at end of file