Add Spectate Command for YouTuber+ #15
@ -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,7 +37,6 @@ 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;
|
||||||
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()) {
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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.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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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:
|
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.