SteamWar/MissileWars
Archiviert
13
0

Add Spectate Command for YouTuber+

Dieser Commit ist enthalten in:
jojo 2020-09-26 11:29:24 +02:00
Ursprung 81a0e3a412
Commit cd5a780f5e
5 geänderte Dateien mit 84 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.misslewars; package de.steamwar.misslewars;
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;
import de.steamwar.misslewars.countdowns.WaitingCountdown; 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 redTeam; //red has South side -> spawns missles towards north
private static MWTeam blueTeam; private static MWTeam blueTeam;
private static FightState fightState; private static FightState fightState;
private static long startTime; //timestamp when the fight starts
/** /**
* create teams, ect * create teams, ect
*/ */
@ -45,7 +45,6 @@ public class MissileWars extends JavaPlugin {
public void onLoad() { public void onLoad() {
plugin = this; plugin = this;
fightState = FightState.WAITING; fightState = FightState.WAITING;
startTime = System.currentTimeMillis();
} }
@Override @Override
@ -62,6 +61,7 @@ public class MissileWars extends JavaPlugin {
new WaitingListener(); new WaitingListener();
new FightListener(); new FightListener();
new ChatListener(); new ChatListener();
getCommand("spectate").setExecutor(new CommandSpectate());
new WaitingCountdown(); new WaitingCountdown();
new ItemCountdown(); new ItemCountdown();
@ -87,8 +87,6 @@ public class MissileWars extends JavaPlugin {
return; return;
fightState = FightState.FIGHTING; fightState = FightState.FIGHTING;
StateDependent.setupState(fightState); StateDependent.setupState(fightState);
startTime = System.currentTimeMillis();
} }
/** /**
@ -102,7 +100,7 @@ public class MissileWars extends JavaPlugin {
fightState = FightState.END; fightState = FightState.END;
StateDependent.setupState(fightState); 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.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_DEATH, 100f, 1f);
player.setGameMode(GameMode.SPECTATOR); player.setGameMode(GameMode.SPECTATOR);
} }
@ -126,15 +124,15 @@ public class MissileWars extends JavaPlugin {
return fightState; return fightState;
} }
public static MWTeam getRedTeam(){ public static MWTeam getRedTeam() {
return redTeam; return redTeam;
} }
public static MWTeam getBlueTeam(){ public static MWTeam getBlueTeam() {
return blueTeam; return blueTeam;
} }
public static MWTeam getTeam(Player p){ public static MWTeam getTeam(Player p) {
if(blueTeam.hasPlayer(p)) if(blueTeam.hasPlayer(p))
return blueTeam; return blueTeam;
if(redTeam.hasPlayer(p)) if(redTeam.hasPlayer(p))
@ -142,10 +140,18 @@ public class MissileWars extends JavaPlugin {
return null; return null;
} }
/** public static void join(Player p) {
* @return seconds since start if (MissileWars.getTeam(p) != null) return;
*/ if (MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size()) {
public static int getFightTime() { MissileWars.getRedTeam().join(p);
return Math.floorDiv((int) (System.currentTimeMillis() - startTime), 60); } else {
MissileWars.getBlueTeam().join(p);
}
} }
public static void leave(Player p) {
MissileWars.getBlueTeam().leave(p);
MissileWars.getRedTeam().leave(p);
}
} }

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}

Datei anzeigen

@ -22,7 +22,6 @@ package de.steamwar.misslewars.listener;
import de.steamwar.misslewars.FightState; import de.steamwar.misslewars.FightState;
import de.steamwar.misslewars.MissileWars; import de.steamwar.misslewars.MissileWars;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
@ -43,9 +42,7 @@ public class ConnectionListener extends BasicListener{
@EventHandler @EventHandler
public void onLeave(PlayerQuitEvent e) { public void onLeave(PlayerQuitEvent e) {
Player p = e.getPlayer(); MissileWars.leave(e.getPlayer());
MissileWars.getBlueTeam().leave(p);
MissileWars.getRedTeam().leave(p);
} }
} }

Datei anzeigen

@ -35,10 +35,8 @@ public class JoinListener extends BasicListener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onJoin(PlayerJoinEvent e){ public void onJoin(PlayerJoinEvent e){
if(MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size()) MissileWars.join(e.getPlayer());
MissileWars.getRedTeam().join(e.getPlayer());
else
MissileWars.getBlueTeam().join(e.getPlayer());
e.setJoinMessage("§a» " + e.getPlayer().getDisplayName()); e.setJoinMessage("§a» " + e.getPlayer().getDisplayName());
} }
} }

Datei anzeigen

@ -4,8 +4,11 @@ main: de.steamwar.misslewars.MissileWars
authors: authors:
- Jan9103 - Jan9103
- Lixfel - Lixfel
- YoyoNow
version: "1.0" version: "1.0"
api-version: "1.13" api-version: "1.13"
depend: depend:
- WorldEdit - WorldEdit
- SpigotCore - SpigotCore
commands:
spectate: