Add Spectate Command for YouTuber+ #15
@ -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;
|
||||
Lixfel
hat
Wenn jemand joint, ist er immer in keinem Team Wenn jemand joint, ist er immer in keinem Team
YoyoNow
hat
Da hast du recht werde ich rausnehmen Da hast du recht werde ich rausnehmen
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
56
src/de/steamwar/misslewars/commands/CommandSpectate.java
Normale Datei
56
src/de/steamwar/misslewars/commands/CommandSpectate.java
Normale Datei
@ -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;
|
||||
Lixfel
hat
Warum nur für YouTuber+ und nicht für alle? Warum nur für YouTuber+ und nicht für alle?
YoyoNow
hat
Damit es erstens kein Spotting gibt, und das Feature war mehr für aufnahmen gedacht Damit es erstens kein Spotting gibt, und das Feature war mehr für aufnahmen gedacht
Lixfel
hat
Spotting dürfte in MW kein Problem sein, und warum sollten auch nicht andere Aufnahmen machen dürfen? Spotting dürfte in MW kein Problem sein, und warum sollten auch nicht andere Aufnahmen machen dürfen?
|
||||
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;
|
||||
Lixfel
hat
Bitte nicht still und heimlich abbrechen, sondern mit Fehlermeldung! Bitte nicht still und heimlich abbrechen, sondern mit Fehlermeldung!
YoyoNow
hat
Welchen Präfix sollte ich denn nehmen? Welchen Präfix sollte ich denn nehmen?
YoyoNow
hat
player.sendMessage("Das spectaten einer MissileWars runde ist nicht möglich, wenn du alleine in einem Team bist."); player.sendMessage("Das spectaten einer MissileWars runde ist nicht möglich, wenn du alleine in einem Team bist.");
Lixfel
hat
player.sendMessage("§cDu bist alleine im Team, zuschauen ist daher nicht möglich."); player.sendMessage("§cDu bist alleine im Team, zuschauen ist daher nicht möglich.");
|
||||
MissileWars.leave(player);
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,8 +4,11 @@ main: de.steamwar.misslewars.MissileWars
|
||||
authors:
|
||||
- Jan9103
|
||||
- Lixfel
|
||||
- YoyoNow
|
||||
version: "1.0"
|
||||
api-version: "1.13"
|
||||
depend:
|
||||
- WorldEdit
|
||||
- SpigotCore
|
||||
- SpigotCore
|
||||
commands:
|
||||
spectate:
|
In neuem Issue referenzieren
Einen Benutzer sperren
Warum kann die Funktionalität nicht im JoinListener bleiben?
Ich wollte sowohl Leave als auch Join an einer weiteren Stelle benutzen, nämlich im Spectate Command, und hatte dann die Idee das in einer Klasse zu bündeln.