From cd5a780f5ec0a61a09b029ff81d2a734551a590a Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 11:29:24 +0200 Subject: [PATCH 1/5] Add Spectate Command for YouTuber+ --- src/de/steamwar/misslewars/MissileWars.java | 34 ++++++----- .../misslewars/commands/CommandSpectate.java | 56 +++++++++++++++++++ .../listener/ConnectionListener.java | 7 +-- .../misslewars/listener/JoinListener.java | 6 +- src/plugin.yml | 5 +- 5 files changed, 84 insertions(+), 24 deletions(-) create mode 100644 src/de/steamwar/misslewars/commands/CommandSpectate.java diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index ac2bbf8..590423a 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -19,6 +19,7 @@ package de.steamwar.misslewars; +import de.steamwar.misslewars.commands.CommandSpectate; import de.steamwar.misslewars.countdowns.EndCountdown; import de.steamwar.misslewars.countdowns.ItemCountdown; import de.steamwar.misslewars.countdowns.WaitingCountdown; @@ -36,8 +37,7 @@ public class MissileWars extends JavaPlugin { private static MWTeam redTeam; //red has South side -> spawns missles towards north private static MWTeam blueTeam; private static FightState fightState; - private static long startTime; //timestamp when the fight starts - + /** * create teams, ect */ @@ -45,7 +45,6 @@ public class MissileWars extends JavaPlugin { public void onLoad() { plugin = this; fightState = FightState.WAITING; - startTime = System.currentTimeMillis(); } @Override @@ -62,6 +61,7 @@ public class MissileWars extends JavaPlugin { new WaitingListener(); new FightListener(); new ChatListener(); + getCommand("spectate").setExecutor(new CommandSpectate()); new WaitingCountdown(); new ItemCountdown(); @@ -87,8 +87,6 @@ public class MissileWars extends JavaPlugin { return; fightState = FightState.FIGHTING; StateDependent.setupState(fightState); - - startTime = System.currentTimeMillis(); } /** @@ -102,7 +100,7 @@ public class MissileWars extends JavaPlugin { fightState = FightState.END; StateDependent.setupState(fightState); - for(Player player : Bukkit.getOnlinePlayers()){ + for(Player player : Bukkit.getOnlinePlayers()) { player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_DEATH, 100f, 1f); player.setGameMode(GameMode.SPECTATOR); } @@ -126,15 +124,15 @@ public class MissileWars extends JavaPlugin { return fightState; } - public static MWTeam getRedTeam(){ + public static MWTeam getRedTeam() { return redTeam; } - public static MWTeam getBlueTeam(){ + public static MWTeam getBlueTeam() { return blueTeam; } - public static MWTeam getTeam(Player p){ + public static MWTeam getTeam(Player p) { if(blueTeam.hasPlayer(p)) return blueTeam; if(redTeam.hasPlayer(p)) @@ -142,10 +140,18 @@ public class MissileWars extends JavaPlugin { return null; } - /** - * @return seconds since start - */ - public static int getFightTime() { - return Math.floorDiv((int) (System.currentTimeMillis() - startTime), 60); + public static void join(Player p) { + if (MissileWars.getTeam(p) != null) return; + if (MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size()) { + MissileWars.getRedTeam().join(p); + } else { + MissileWars.getBlueTeam().join(p); + } } + + public static void leave(Player p) { + MissileWars.getBlueTeam().leave(p); + MissileWars.getRedTeam().leave(p); + } + } diff --git a/src/de/steamwar/misslewars/commands/CommandSpectate.java b/src/de/steamwar/misslewars/commands/CommandSpectate.java new file mode 100644 index 0000000..3ebae21 --- /dev/null +++ b/src/de/steamwar/misslewars/commands/CommandSpectate.java @@ -0,0 +1,56 @@ +/* + 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.MWTeam; +import de.steamwar.misslewars.MissileWars; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandSpectate implements CommandExecutor { + + public boolean hasPermissions(Player p) { + if (p.hasPermission("bungeecore.group.admin")) return true; + if (p.hasPermission("bungeecore.group.developer")) return true; + if (p.hasPermission("bungeecore.group.moderator")) return true; + if (p.hasPermission("bungeecore.group.supporter")) return true; + if (p.hasPermission("bungeecore.group.builder")) return true; + if (p.hasPermission("bungeecore.group.youtuber")) return true; + return false; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) return false; + Player player = (Player) sender; + if (!hasPermissions(player)) return false; + + MWTeam mwTeam = MissileWars.getTeam(player); + if (mwTeam == null) return false; + if (mwTeam.getPlayers().size() == 1) return false; + MissileWars.leave(player); + player.setGameMode(GameMode.SPECTATOR); + return true; + } + +} diff --git a/src/de/steamwar/misslewars/listener/ConnectionListener.java b/src/de/steamwar/misslewars/listener/ConnectionListener.java index 3d7f273..7c556ed 100644 --- a/src/de/steamwar/misslewars/listener/ConnectionListener.java +++ b/src/de/steamwar/misslewars/listener/ConnectionListener.java @@ -22,7 +22,6 @@ package de.steamwar.misslewars.listener; import de.steamwar.misslewars.FightState; import de.steamwar.misslewars.MissileWars; import org.bukkit.GameMode; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerJoinEvent; @@ -43,9 +42,7 @@ public class ConnectionListener extends BasicListener{ @EventHandler public void onLeave(PlayerQuitEvent e) { - Player p = e.getPlayer(); - - MissileWars.getBlueTeam().leave(p); - MissileWars.getRedTeam().leave(p); + MissileWars.leave(e.getPlayer()); } + } diff --git a/src/de/steamwar/misslewars/listener/JoinListener.java b/src/de/steamwar/misslewars/listener/JoinListener.java index 8aaeb7f..83a9bd7 100644 --- a/src/de/steamwar/misslewars/listener/JoinListener.java +++ b/src/de/steamwar/misslewars/listener/JoinListener.java @@ -35,10 +35,8 @@ public class JoinListener extends BasicListener { @EventHandler(priority = EventPriority.HIGHEST) public void onJoin(PlayerJoinEvent e){ - if(MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size()) - MissileWars.getRedTeam().join(e.getPlayer()); - else - MissileWars.getBlueTeam().join(e.getPlayer()); + MissileWars.join(e.getPlayer()); e.setJoinMessage("§a» " + e.getPlayer().getDisplayName()); } + } diff --git a/src/plugin.yml b/src/plugin.yml index e046845..452b135 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -4,8 +4,11 @@ main: de.steamwar.misslewars.MissileWars authors: - Jan9103 - Lixfel + - YoyoNow version: "1.0" api-version: "1.13" depend: - WorldEdit - - SpigotCore \ No newline at end of file + - SpigotCore +commands: + spectate: \ No newline at end of file From 016ea28b8782c66bb67a2f6a6b5e515fd1383d58 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 12:20:56 +0200 Subject: [PATCH 2/5] Remove MissileWars.join check --- src/de/steamwar/misslewars/MissileWars.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index 590423a..24c576c 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -141,7 +141,6 @@ public class MissileWars extends JavaPlugin { } public static void join(Player p) { - if (MissileWars.getTeam(p) != null) return; if (MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size()) { MissileWars.getRedTeam().join(p); } else { From b5237557ec22d88c095c9ffcd1d3d389a372d838 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 12:23:56 +0200 Subject: [PATCH 3/5] Add CommandSpectate message --- src/de/steamwar/misslewars/commands/CommandSpectate.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/misslewars/commands/CommandSpectate.java b/src/de/steamwar/misslewars/commands/CommandSpectate.java index 3ebae21..ed7d149 100644 --- a/src/de/steamwar/misslewars/commands/CommandSpectate.java +++ b/src/de/steamwar/misslewars/commands/CommandSpectate.java @@ -21,6 +21,7 @@ package de.steamwar.misslewars.commands; import de.steamwar.misslewars.MWTeam; import de.steamwar.misslewars.MissileWars; +import de.steamwar.misslewars.items.Missile; import org.bukkit.GameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -47,7 +48,10 @@ public class CommandSpectate implements CommandExecutor { MWTeam mwTeam = MissileWars.getTeam(player); if (mwTeam == null) return false; - if (mwTeam.getPlayers().size() == 1) return false; + if (mwTeam.getPlayers().size() == 1) { + player.sendMessage("Das spectaten einer MissileWars runde ist nicht möglich, wenn du alleine in einem Team bist."); + return false; + } MissileWars.leave(player); player.setGameMode(GameMode.SPECTATOR); return true; From 3a92106559fa9fe5b1fa4e0fd29f950f94d1ab2e Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 12:42:10 +0200 Subject: [PATCH 4/5] Add error message in Spectate Command --- src/de/steamwar/misslewars/commands/CommandSpectate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/misslewars/commands/CommandSpectate.java b/src/de/steamwar/misslewars/commands/CommandSpectate.java index ed7d149..acdbdc4 100644 --- a/src/de/steamwar/misslewars/commands/CommandSpectate.java +++ b/src/de/steamwar/misslewars/commands/CommandSpectate.java @@ -49,7 +49,7 @@ public class CommandSpectate implements CommandExecutor { MWTeam mwTeam = MissileWars.getTeam(player); if (mwTeam == null) return false; if (mwTeam.getPlayers().size() == 1) { - player.sendMessage("Das spectaten einer MissileWars runde ist nicht möglich, wenn du alleine in einem Team bist."); + player.sendMessage("§cDu bist alleine im Team, zuschauen ist daher nicht möglich."); return false; } MissileWars.leave(player); From 31f1d912547c5d74891ab33536008103bd908442 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 12:42:51 +0200 Subject: [PATCH 5/5] Remove PermissionCheck for Spectate Command --- .../misslewars/commands/CommandSpectate.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/de/steamwar/misslewars/commands/CommandSpectate.java b/src/de/steamwar/misslewars/commands/CommandSpectate.java index acdbdc4..ded0a44 100644 --- a/src/de/steamwar/misslewars/commands/CommandSpectate.java +++ b/src/de/steamwar/misslewars/commands/CommandSpectate.java @@ -21,7 +21,6 @@ package de.steamwar.misslewars.commands; import de.steamwar.misslewars.MWTeam; import de.steamwar.misslewars.MissileWars; -import de.steamwar.misslewars.items.Missile; import org.bukkit.GameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -30,21 +29,10 @@ import org.bukkit.entity.Player; public class CommandSpectate implements CommandExecutor { - public boolean hasPermissions(Player p) { - if (p.hasPermission("bungeecore.group.admin")) return true; - if (p.hasPermission("bungeecore.group.developer")) return true; - if (p.hasPermission("bungeecore.group.moderator")) return true; - if (p.hasPermission("bungeecore.group.supporter")) return true; - if (p.hasPermission("bungeecore.group.builder")) return true; - if (p.hasPermission("bungeecore.group.youtuber")) return true; - return false; - } - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return false; Player player = (Player) sender; - if (!hasPermissions(player)) return false; MWTeam mwTeam = MissileWars.getTeam(player); if (mwTeam == null) return false;