diff --git a/src/config.yml b/src/config.yml index 49abd82..df837d4 100644 --- a/src/config.yml +++ b/src/config.yml @@ -4,6 +4,9 @@ ShieldFlyTime: 100 PlatformTime: 30 EndTime: 600 +MissileCount: 4 +MissileChance: 0.6 + Arena: MinX: 0 MaxX: 0 diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index 9e72528..08cc17e 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; @@ -60,6 +61,8 @@ public class MissileWars extends JavaPlugin { new WaitingListener(); new FightListener(); new ChatListener(); + new GamemodeListener(); + getCommand("spectate").setExecutor(new CommandSpectate()); new WaitingCountdown(); new ItemCountdown(); @@ -139,4 +142,18 @@ public class MissileWars extends JavaPlugin { return null; } + 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..a58233f --- /dev/null +++ b/src/de/steamwar/misslewars/commands/CommandSpectate.java @@ -0,0 +1,39 @@ +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