SteamWar/MissileWars
Archiviert
13
0

Add FightInfoPacketSender

Dieser Commit ist enthalten in:
yoyosource 2021-10-04 10:42:26 +02:00
Ursprung b0bef0f778
Commit 2d927792e4
5 geänderte Dateien mit 84 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,75 @@
/*
*
* 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;
import de.steamwar.comms.packets.FightInfoPacket;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.List;
import java.util.stream.Collectors;
public class FightInfoPacketSender extends BukkitRunnable {
private final World world = Bukkit.getWorlds().get(0);
private final String serverName = Bukkit.getServer().getName();
private final String gameMode = "missilewars";
private final String worldName = world.getName();
private final String blueName = "§3blue";
private final String redName = "§cred";
private final int blueLeader = Config.BlueLeader != null ? SteamwarUser.get(Config.BlueLeader).getId() : 0;
private final int redLeader = Config.RedLeader != null ? SteamwarUser.get(Config.RedLeader).getId() : 0;
@Override
public void run() {
if (Bukkit.getOnlinePlayers().isEmpty()) {
return;
}
if (Config.test()) {
return;
}
int countdown;
if (FightScoreboard.getStartTime() == 0) {
countdown = 0;
} else {
countdown = (int) ((System.currentTimeMillis() - FightScoreboard.getStartTime()) / 1000);
}
List<Integer> bluePlayers = MissileWars.getBlueTeam().getPlayers().stream()
.map(player -> SteamwarUser.get(player.getUniqueId()).getId())
.collect(Collectors.toList());
List<Integer> redPlayers = MissileWars.getRedTeam().getPlayers().stream()
.map(player -> SteamwarUser.get(player.getUniqueId()).getId())
.collect(Collectors.toList());
List<Integer> spectatorPlayers = Bukkit.getOnlinePlayers().stream()
.map(player -> SteamwarUser.get(player.getUniqueId()).getId())
.filter(integer -> !(bluePlayers.contains(integer) || redPlayers.contains(integer)))
.collect(Collectors.toList());
new FightInfoPacket(serverName, gameMode, worldName, blueName, redName, MissileWars.getFightState().name().toLowerCase(), countdown, blueLeader, redLeader, 0, 0, bluePlayers, redPlayers, spectatorPlayers)
.send(Bukkit.getOnlinePlayers().iterator().next());
}
}

Datei anzeigen

@ -19,13 +19,13 @@
package de.steamwar.misslewars;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.bukkit.Bukkit;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
/**
@ -41,6 +41,10 @@ class FightScoreboard {
private static long startTime = 0;
public static long getStartTime() {
return startTime;
}
static{
if(scoreboard.getObjective("AAA") == null)
objective = scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.misslewars;
import de.steamwar.comms.packets.FightInfoPacket;
import de.steamwar.comms.packets.TablistNamePacket;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.*;
@ -139,9 +140,6 @@ public class MWTeam {
p.setDisplayName(color + p.getName());
if (MissileWars.getFightState() == FightState.WAITING && !enemy().players.isEmpty())
MissileWars.startRound();
if (!Config.test())
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(p.getUniqueId()).getId(), color + p.getName()).send(p), 5);
}
public void leave(Player p) {
@ -161,9 +159,6 @@ public class MWTeam {
sbteam.removePlayer(p);
if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING)
MissileWars.end(WinReasons.NO_ENEMY, enemy());
if (!Config.test())
new TablistNamePacket(SteamwarUser.get(p.getUniqueId()).getId(), "§7§o" + p.getName()).send(p);
}
public void invitePlayer(Player p) {

Datei anzeigen

@ -84,6 +84,8 @@ public class MissileWars extends JavaPlugin {
CustomItem.init();
StateDependent.setupState(fightState);
Bukkit.getScheduler().runTaskTimer(this, new FightInfoPacketSender(), 20, 20);
}
/**
@ -163,10 +165,6 @@ public class MissileWars extends JavaPlugin {
}
}
public static void spectateJoin(Player p) {
p.teleport(MissileWars.getRedTeam().getSpawn().toVector().midpoint(MissileWars.getBlueTeam().getSpawn().toVector()).toLocation(p.getWorld()));
}
public static void leave(Player p) {
MissileWars.getBlueTeam().leave(p);
MissileWars.getRedTeam().leave(p);

Datei anzeigen

@ -19,12 +19,9 @@
package de.steamwar.misslewars.listener;
import de.steamwar.comms.packets.TablistNamePacket;
import de.steamwar.misslewars.Config;
import de.steamwar.misslewars.FightState;
import de.steamwar.misslewars.MissileWars;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
@ -46,12 +43,7 @@ public class JoinListener extends BasicListener {
} else if (Config.BlueLeader.equals(e.getPlayer().getUniqueId())) {
MissileWars.getBlueTeam().join(e.getPlayer());
} else {
if (!Config.test()) {
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> {
new TablistNamePacket(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), "§7" + e.getPlayer().getName()).send(e.getPlayer());
}, 5);
}
MissileWars.spectateJoin(e.getPlayer());
e.getPlayer().teleport(MissileWars.getRedTeam().getSpawn().toVector().midpoint(MissileWars.getBlueTeam().getSpawn().toVector()).toLocation(e.getPlayer().getWorld()));
}
return;
}