From da68b5672f5220c0f3202e9a3a19dbed6a5c7db8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 30 Sep 2021 17:32:32 +0200 Subject: [PATCH] Current state, 1.8 support Signed-off-by: Lixfel --- .../utils/WorldOfColorWrapper12.java | 6 + .../fightsystem/utils/BountifulWrapper8.java | 68 +++++++++- .../utils/WorldOfColorWrapper8.java | 7 + .../fightsystem/utils/BountifulWrapper9.java | 73 +++++++++- .../de/steamwar/fightsystem/FightSystem.java | 1 - .../fightsystem/commands/Commands.java | 3 +- .../commands/LockschemCommand.java | 2 +- .../fightsystem/fight/FightSchematic.java | 2 +- .../steamwar/fightsystem/fight/FightTeam.java | 51 ++++--- .../steamwar/fightsystem/listener/Chat.java | 5 +- .../fightsystem/listener/FightScoreboard.java | 74 +--------- .../fightsystem/record/PacketProcessor.java | 30 ++++- .../steamwar/fightsystem/record/Recorder.java | 21 ++- .../fightsystem/utils/BountifulWrapper.java | 5 + .../steamwar/fightsystem/utils/FightUI.java | 126 ++++++++---------- .../utils/WorldOfColorWrapper.java | 3 + 16 files changed, 291 insertions(+), 186 deletions(-) diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java index deef5e6..b8f46e4 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java @@ -24,6 +24,7 @@ import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.SoundCategory; import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; import org.bukkit.scoreboard.Team; public class WorldOfColorWrapper12 implements WorldOfColorWrapper.IWorldOfColorWrapper { @@ -41,4 +42,9 @@ public class WorldOfColorWrapper12 implements WorldOfColorWrapper.IWorldOfColorW public void playSound(Location location, Sound sound, String soundCategory, float volume, float pitch) { location.getWorld().playSound(location, sound, SoundCategory.valueOf(soundCategory), volume, pitch); } + + @Override + public void sendTitle(Player player, String title, String subtitle, int start, int hold, int stop) { + player.sendTitle(title, subtitle, start, hold, stop); + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java index c5b5801..6ab78fa 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java @@ -20,28 +20,32 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.listener.Recording; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.record.REntity; import net.md_5.bungee.api.chat.BaseComponent; -import net.minecraft.server.v1_8_R3.ChatComponentText; -import net.minecraft.server.v1_8_R3.PacketPlayOutChat; +import net.minecraft.server.v1_8_R3.*; import net.royawesome.jlibnoise.MathHelper; -import org.bukkit.Effect; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.*; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.scoreboard.Team; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { + public BountifulWrapper8() { + EntityEnderDragon dragon = new EntityEnderDragon(null); + dragon.setLocation(Config.ArenaRegion.centerX(), 0, Config.ArenaRegion.centerZ(), 0, 0); + this.spawnDragonId = dragon.getId(); + this.spawnDragon = new PacketPlayOutSpawnEntityLiving(dragon); + } + @Override public boolean mainHand(Object packet) { return true; @@ -157,4 +161,54 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { equipmentSlot.set(packet, 0); } } + + private PacketPlayOutEntityMetadata leftBlue; + private PacketPlayOutEntityMetadata leftRed; + + @Override + public void setBossbar(double leftBlueProgress, double leftRedProgress, String leftBlueText, String leftRedText) { + DataWatcher leftBlueWatcher = new DataWatcher(null); + leftBlueWatcher.a(0, (byte) 0x20); + leftBlueWatcher.a(6, (float)(leftBlueProgress * 200)); + leftBlueWatcher.a(10, leftBlueText); + leftBlueWatcher.a(2, leftBlueText); + leftBlueWatcher.a(11, (byte) 1); + leftBlueWatcher.a(3, (byte) 1); + leftBlue = new PacketPlayOutEntityMetadata(spawnDragonId, leftBlueWatcher, true); + + DataWatcher leftRedWatcher = new DataWatcher(null); + leftRedWatcher.a(0, (byte) 0x20); + leftRedWatcher.a(6, (float)(leftRedProgress * 200)); + leftRedWatcher.a(10, leftRedText); + leftRedWatcher.a(2, leftRedText); + leftRedWatcher.a(11, (byte) 1); + leftRedWatcher.a(3, (byte) 1); + leftRed = new PacketPlayOutEntityMetadata(spawnDragonId, leftRedWatcher, true); + } + + @Override + public void removeFromBar(Player player, boolean leftBlueBar) { + // not used + } + + @Override + public void addToBar(Player player, boolean leftBlueBar) { + // not used + } + + private final Set seesDragon = new HashSet<>(); + private final PacketPlayOutSpawnEntityLiving spawnDragon; + private final int spawnDragonId; + @Override + public void broadcastBossbar() { + seesDragon.removeIf(player -> !player.isOnline()); + Bukkit.getOnlinePlayers().forEach(player -> { + if(!seesDragon.contains(player)) { + ((CraftPlayer)player).getHandle().playerConnection.sendPacket(spawnDragon); + seesDragon.add(player); + } + + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(FightUI.getInstance().hasBlueLeft(player) ? leftBlue : leftRed); + }); + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java index dfe0228..96e8665 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java @@ -23,6 +23,7 @@ import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; import org.bukkit.scoreboard.Team; public class WorldOfColorWrapper8 implements WorldOfColorWrapper.IWorldOfColorWrapper { @@ -40,4 +41,10 @@ public class WorldOfColorWrapper8 implements WorldOfColorWrapper.IWorldOfColorWr public void playSound(Location location, Sound sound, String soundCategory, float volume, float pitch) { location.getWorld().playSound(location, sound, volume, pitch); } + + @SuppressWarnings("deprecation") + @Override + public void sendTitle(Player player, String title, String subtitle, int start, int hold, int stop) { + player.sendTitle(title, subtitle); + } } diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index dc7dbee..b8eb5d8 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -20,16 +20,19 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.listener.Recording; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.record.REntity; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; -import org.bukkit.Material; -import org.bukkit.Particle; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -193,4 +196,68 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { equipmentSlot.set(packet, itemSlots[0]); } } + + private final BossBar leftBlue = Bukkit.createBossBar("Blue", BarColor.BLUE, BarStyle.SOLID); + private final BossBar leftRed = Bukkit.createBossBar("Red", BarColor.RED, BarStyle.SOLID); + @Override + public void setBossbar(double leftBlueProgress, double leftRedProgress, String leftBlueText, String leftRedText) { + setupTeamBar(Fight.getBlueTeam(), leftBlue, leftBlueProgress); + setupTeamBar(Fight.getRedTeam(), leftRed, leftRedProgress); + + leftBlue.setTitle(leftBlueText); + leftRed.setTitle(leftRedText); + } + + private void setupTeamBar(FightTeam team, BossBar bar, double progress) { + BarColor color = chat2bar(team.getColor()); + if(bar.getColor() != color) + bar.setColor(color); + + if(bar.getProgress() != progress) + bar.setProgress(progress); + } + + private BarColor chat2bar(ChatColor color) { + switch(color) { + case DARK_BLUE: + case DARK_AQUA: + case BLUE: + case AQUA: + return BarColor.BLUE; + case GREEN: + case DARK_GREEN: + return BarColor.GREEN; + case DARK_RED: + case RED: + return BarColor.RED; + case DARK_PURPLE: + return BarColor.PURPLE; + case GOLD: + case YELLOW: + return BarColor.YELLOW; + case LIGHT_PURPLE: + return BarColor.PINK; + case BLACK: + case WHITE: + case GRAY: + case DARK_GRAY: + default: + return BarColor.WHITE; + } + } + + @Override + public void removeFromBar(Player player, boolean leftBlueBar) { + (leftBlueBar ? leftBlue : leftRed).removePlayer(player); + } + + @Override + public void addToBar(Player player, boolean leftBlueBar) { + (leftBlueBar ? leftBlue : leftRed).addPlayer(player); + } + + @Override + public void broadcastBossbar() { + // Handled by Spigot BossBarAPI + } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 673c90b..0e18eca 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -81,7 +81,6 @@ public class FightSystem extends JavaPlugin { new NormalJoin(); new RankedJoin(); new PersonalKitCreator(); - new FightScoreboard(); new ArrowStopper(); new ArrowPickup(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java index 26bed7c..ed0d06d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java @@ -112,7 +112,6 @@ public class Commands { return; p.sendMessage(FightSystem.PREFIX + "§aDu bist Team " + team.getColoredName() + " §abeigetreten!"); - team.broadcast(FightSystem.PREFIX + "§aDer Spieler §e" + p.getName() + " §aist dem Team beigetreten!"); team.addMember(p); } @@ -125,7 +124,7 @@ public class Commands { return; p.sendMessage(FightSystem.PREFIX + "§aDu hast die Einladung von " + team.getColoredName() + " §aabgelehnt!"); - team.broadcast(FightSystem.PREFIX + "§cDer Spieler §e" + p.getName() + " §chat die Einladung abgelehnt!"); + team.broadcast("§e" + p.getName() + " §chat die Einladung abgelehnt"); team.getInvited().remove(p); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java index 27dbb97..ebb172e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java @@ -70,7 +70,7 @@ public class LockschemCommand implements CommandExecutor { } Schematic.getSchemFromDB(fightTeam.getSchematic()).setSchemType(SchematicType.Normal); player.sendMessage(FightSystem.PREFIX + "Schematic von " + fightTeam.getColoredName() + " §cgesperrt!"); - fightTeam.broadcast(FightSystem.PREFIX + "§cDie Schematic wurde von " + player.getName() + " gesperrt!"); + fightTeam.broadcast("§cDie Schematic wurde von " + player.getName() + " gesperrt"); return false; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 159317d..2c91709 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -72,7 +72,7 @@ public class FightSchematic extends StateDependent { try { clipboard = schem.load(); } catch (IOException e) { - team.broadcast(FightSystem.PREFIX + "§cSchematic konnte nicht geladen werden!"); + team.broadcast("§cSchematic konnte nicht geladen werden"); Bukkit.getLogger().log(Level.SEVERE, e, () -> "Couldn't load Schematic " + schem.getSchemName()); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 063eb42..092a399 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -34,6 +34,8 @@ import de.steamwar.fightsystem.utils.*; import de.steamwar.inventory.SWItem; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.*; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -42,6 +44,7 @@ import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.Team; import java.util.*; +import java.util.logging.Level; public class FightTeam { @@ -184,7 +187,14 @@ public class FightTeam { } public void broadcast(String message) { - players.forEach((player, fp) -> player.sendMessage(message)); + BaseComponent[] msg = TextComponent.fromLegacyText(message); + players.forEach((player, fp) -> BountifulWrapper.impl.toActionbar(player, msg)); + } + + public void broadcastChat(String message) { + FightSystem.getPlugin().getLogger().log(Level.INFO, message); + BaseComponent[] msg = TextComponent.fromLegacyText(message); + players.forEach((player, fp) -> BountifulWrapper.impl.toChat(player, msg)); } public void addMember(Player player) { @@ -210,6 +220,8 @@ public class FightTeam { if(isLeaderless()) setLeader(fightPlayer); + else + FightUI.addSubtitle("§a§l» " + prefix + player.getName()); } public void removePlayer(Player player) { @@ -220,8 +232,10 @@ public class FightTeam { players.remove(player); team.removeEntry(player.getName()); + FightUI.addSubtitle("§c§l« " + prefix + player.getName()); + if(fightPlayer.equals(leader)) - setLeader(null); + removeLeader(); GlobalRecorder.getInstance().entityDespawns(player); Fight.setPlayerGamemode(player, GameMode.SPECTATOR); @@ -247,17 +261,16 @@ public class FightTeam { return leader; } - private void setLeader(FightPlayer leader) { - if (leader == null) { - this.leader = null; - if(!players.isEmpty()) { - setLeader(players.values().iterator().next()); - FightUI.addSubtitle(getPrefix() + "Neuer Leader: " + this.leader.getPlayer().getName()); - }else if(FightState.getFightState() != FightState.PRE_LEADER_SETUP && !ArenaMode.RankedEvent.contains(Config.mode)){ - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), FightSystem::setPreLeaderState, 1); - } - return; + private void removeLeader() { + this.leader = null; + if(!players.isEmpty()) { + setLeader(players.values().iterator().next()); + }else if(FightState.getFightState() != FightState.PRE_LEADER_SETUP && !ArenaMode.RankedEvent.contains(Config.mode)){ + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), FightSystem::setPreLeaderState, 1); } + } + + private void setLeader(FightPlayer leader) { PersonalKitCreator.closeIfInKitCreator(leader.getPlayer()); this.leader = leader; @@ -265,6 +278,8 @@ public class FightTeam { if(ready) setReady(false); + FightUI.addSubtitle("§a§l» " + prefix + "Leader " + leader.getPlayer().getName()); + Optional maxRank = Schematic.getSchemsOfType(leader.getPlayer().getUniqueId(), Config.SchematicType).stream().map(Schematic::getRank).max(Integer::compare); if(Config.RanksEnabled) schemRank = maxRank.orElse(1); @@ -329,40 +344,40 @@ public class FightTeam { public void setSchem(Schematic schematic){ this.schematic.setSchematic(schematic); - broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!"); + broadcast("§e" + Config.GameName + " " + schematic.getSchemName() + " §7gewählt"); } public void setReady(boolean ready) { Player l = leader.getPlayer(); if(!schematic.hasSchematic()){ - l.sendMessage(FightSystem.PREFIX + "§cZuerst muss eine Schematic gewählt sein!"); + BountifulWrapper.impl.toActionbar(l, TextComponent.fromLegacyText("§cZuerst muss eine Schematic gewählt sein!")); return; } this.ready = ready; if(ready) { l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributs().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName("§aBereit").build()); - broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit!"); + broadcast("§aTeam bereit"); if(Fight.getOpposite(this).isReady() || ArenaMode.SoloLeader.contains(Config.mode)) FightSystem.setPreRunningState(); } else { l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); - broadcast(FightSystem.PREFIX + "§cEuer Team ist nicht mehr bereit!"); + broadcast("§c§mTeam bereit"); } } public void skip(){ this.skip = !skip; if(skip){ - broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit, zum nächsten Event zu beschleunigen!"); + broadcast("§aBeschleunigung zum nächsten Event"); if(Fight.getOpposite(this).skip || Config.test()){ skip = false; Fight.getOpposite(this).skip = false; Countdown.skip(); } }else{ - broadcast(FightSystem.PREFIX + "§cEuer Team ist nicht mehr bereit, zum nächsten Event zu beschleunigen!"); + broadcast("§c§mBeschleunigung zum nächsten Event"); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java index 21fdd77..ec5ee6b 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java @@ -36,6 +36,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; +import java.util.logging.Level; + public class Chat implements Listener { public Chat(){ @@ -51,7 +53,7 @@ public class Chat implements Listener { if(fightTeam != null) { String teamName = fightTeam.getColoredName(); if(message.startsWith(Config.TeamChatDetection)) { - fightTeam.broadcast(teamName + " " + player.getName() + "» " + message.substring(1)); + fightTeam.broadcastChat(teamName + " " + player.getName() + "» " + message.substring(1)); } else { broadcastChat(teamName + " " + player.getName() + "§8» §7" + message); } @@ -66,6 +68,7 @@ public class Chat implements Listener { private void broadcastChat(String message) { GlobalRecorder.getInstance().chat(message); + FightSystem.getPlugin().getLogger().log(Level.INFO, message); BaseComponent[] msg = TextComponent.fromLegacyText(message); for(Player p : Bukkit.getOnlinePlayers()) BountifulWrapper.impl.toChat(p, msg); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java index c747520..957f085 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java @@ -19,18 +19,9 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.core.TPSWatcher; import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.countdown.Countdown; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.record.GlobalRecorder; -import de.steamwar.fightsystem.record.PacketProcessor; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import de.steamwar.fightsystem.states.StateDependentTask; -import de.steamwar.fightsystem.winconditions.PrintableWincondition; -import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; import org.bukkit.Bukkit; @@ -40,7 +31,8 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scoreboard.Scoreboard; -import java.util.*; +import java.util.HashMap; +import java.util.Objects; public class FightScoreboard implements Listener, ScoreboardCallback { @@ -48,23 +40,21 @@ public class FightScoreboard implements Listener, ScoreboardCallback { return Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); } - private static final Set fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE); private static FightScoreboard scoreboard; public static FightScoreboard getScoreboard(){ + if(scoreboard == null) + scoreboard = new FightScoreboard(); return scoreboard; } - private int index = 0; - private String title = ""; private final HashMap scores = new HashMap<>(); - public FightScoreboard(){ - new StateDependentListener(ArenaMode.AntiReplay, FightState.All, this); - new StateDependentTask(ArenaMode.AntiReplay, FightState.All, this::updateScoreboard, 0, 20); - scoreboard = this; + private FightScoreboard(){ + new StateDependentListener(ArenaMode.Replay, FightState.All, this); + Bukkit.getOnlinePlayers().forEach(player -> SWScoreboard.createScoreboard(player, this)); } @EventHandler @@ -77,63 +67,13 @@ public class FightScoreboard implements Listener, ScoreboardCallback { SWScoreboard.removeScoreboard(event.getPlayer()); } - private void generalScoreboard(){ - setTitle("§eKampf"); - List scoreList = new ArrayList<>(); - - Countdown timeOverCountdown = Wincondition.getTimeOverCountdown(); - if(timeOverCountdown != null){ - int fightTime = timeOverCountdown.getTimeLeft(); - if (fightTime >= 60) - scoreList.add("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s"); - else - scoreList.add("§7Zeit: §a" + fightTime + "s"); - } - - scoreList.add("§7TPS: §e" + TPSWatcher.getTPS()); - - if(fullScoreboard.contains(FightState.getFightState())){ - for(PrintableWincondition wincondition : Wincondition.getPrintableWinconditions()){ - scoreList.add(wincondition.getDisplay(Fight.getRedTeam())); - scoreList.add(wincondition.getDisplay(Fight.getBlueTeam())); - } - } - - int value = scoreList.size(); - for(String score : scoreList){ - addScore(score, value--); - } - } - - private void teamScoreboard(FightTeam fightTeam){ - fightTeam.getPlayers().forEach(fp -> { - if(fp.isLiving()) - addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth())); - }); - } - - private void updateScoreboard() { - if(PacketProcessor.isReplaying()) - return; - - if ((index++ / 5) % 2 == 0) { - generalScoreboard(); - } else { - setTitle(Fight.getBlueTeam().getColoredName() + " " + Fight.getRedTeam().getColoredName()); - teamScoreboard(Fight.getBlueTeam()); - teamScoreboard(Fight.getRedTeam()); - } - } - public void setTitle(String t) { scores.clear(); title = t; - GlobalRecorder.getInstance().scoreboardTitle(t); } public void addScore(String string, int i) { scores.put(string, i); - GlobalRecorder.getInstance().scoreboardData(string, i); } @Override diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 10a194e..6324d15 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -30,10 +30,7 @@ import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FreezeWorld; import de.steamwar.fightsystem.listener.BasicListener; import de.steamwar.fightsystem.listener.FightScoreboard; -import de.steamwar.fightsystem.utils.BlockIdWrapper; -import de.steamwar.fightsystem.utils.BountifulWrapper; -import de.steamwar.fightsystem.utils.TechHider; -import de.steamwar.fightsystem.utils.WorldOfColorWrapper; +import de.steamwar.fightsystem.utils.*; import de.steamwar.sql.Schematic; import de.steamwar.sql.Team; import net.md_5.bungee.api.ChatMessageType; @@ -112,6 +109,9 @@ public class PacketProcessor { packetDecoder[0xb4] = () -> pasteEmbeddedSchem(Fight.getRedTeam()); packetDecoder[0xc0] = this::scoreboardTitle; packetDecoder[0xc1] = this::scoreboardData; + packetDecoder[0xc2] = this::bossBar; + packetDecoder[0xc3] = this::subtitle; + packetDecoder[0xc4] = this::printWin; packetDecoder[0xef] = source::readUTF; packetDecoder[0xff] = this::tick; @@ -373,6 +373,28 @@ public class PacketProcessor { FightScoreboard.getScoreboard().addScore(key, value); } + private void bossBar() throws IOException { + double leftBlueProgress = source.readDouble(); + double leftRedProgress = source.readDouble(); + String leftBlueText = source.readUTF(); + String leftRedText = source.readUTF(); + + FightUI.getInstance().setBossbar(leftBlueProgress, leftRedProgress, leftBlueText, leftRedText); + } + + private void subtitle() throws IOException { + String subtitle = source.readUTF(); + + FightUI.addSubtitle(subtitle); + } + + private void printWin() throws IOException { + String title = source.readUTF(); + String subtitle = source.readUTF(); + + FightUI.printWin(title, subtitle); + } + private void endReplay(){ REntity.dieAll(); freezer.disable(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index c98e21d..e75a016 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -102,7 +102,7 @@ public interface Recorder { * BlockPacket (0x30) + pos int, byte, int + int BlockState * ParticlePacket (0x31) + double x, y, z + string particleType * SoundPacket (0x32) + int x, y, z + string soundType + string soundCategory + float volume, pitch - * ShortBlockPacket (0x33) + pos relative to ArenaMinX,ArenaMinZ byte, byte, byte + short BlockState + * DEPRECATED ShortBlockPacket (0x33) + pos relative to ArenaMinX,ArenaMinZ byte, byte, byte + short BlockState * SoundAtPlayerPacket (0x34) + string (soundType, soundCategory) + float volume, pitch * ShortBlockPacket (0x35) + pos relative to ArenaMinX,BluePasteY,ArenaMinZ byte, byte, byte + short BlockState * @@ -117,8 +117,11 @@ public interface Recorder { * BlueEmbeddedSchemPacket (0xB3) + int blueSchemId + gzipt NBT blob * RedEmbeddedSchemPacket (0xB4) + int redSchemId + gzipt NBT blob * - * ScoreboardTitlePacket (0xC0) + String scoreboardTitle - * ScoreboardDataPacket (0xC1) + String key + int value + * DEPRECATED ScoreboardTitlePacket (0xC0) + String scoreboardTitle + * DEPRECATED ScoreboardDataPacket (0xC1) + String key + int value + * BossBarPacket (0xC2) + double leftBlueProgress, leftRedProgress + String leftBlueText, leftRedText + * SubtitlePacket (0xC3) + String subtitle + * PrintWinPacket (0xC4) + String title, subtitle * * CommentPacket (0xfe) + String comment * TickPacket (0xff) @@ -265,12 +268,16 @@ public interface Recorder { write(embedId, schemId, buffer.toByteArray()); } - default void scoreboardTitle(String title){ - write(0xc0, title); + default void bossBar(double leftBlueProgress, double leftRedProgress, String leftBlueText, String leftRedText) { + write(0xc2, leftBlueProgress, leftRedProgress, leftBlueText, leftRedText); } - default void scoreboardData(String key, int value){ - write(0xc1, key, value); + default void subtitle(String subtitle) { + write(0xc3, subtitle); + } + + default void printWin(String title, String subtitle) { + write(0xc4, title, subtitle); } default void tick(){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java index 2fa5cba..bf23ea1 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java @@ -57,5 +57,10 @@ public class BountifulWrapper { void setTeleportPacketPosition(Object packet, double x, double y, double z); void setSpawnPacketUUID(Object packet, UUID uuid); void setEquipmentPacketSlot(Object packet, String slot); + + void setBossbar(double leftBlueProgress, double leftRedProgress, String leftBlueText, String leftRedText); + void removeFromBar(Player player, boolean leftBlueBar); + void addToBar(Player player, boolean leftBlueBar); + void broadcastBossbar(); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java index 3fa9084..aada2c2 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java @@ -24,31 +24,34 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.winconditions.Wincondition; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.boss.BarColor; -import org.bukkit.boss.BarStyle; -import org.bukkit.boss.BossBar; import org.bukkit.entity.Player; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.Queue; +import java.util.logging.Level; import java.util.stream.Collectors; public class FightUI { - private final BossBar leftBlue = Bukkit.createBossBar("Blue", BarColor.BLUE, BarStyle.SOLID); - private final BossBar leftRed = Bukkit.createBossBar("Red", BarColor.RED, BarStyle.SOLID); - private final Map players = new HashMap<>(); + private static FightUI instance; + public static FightUI getInstance() { + return instance; + } + + private final boolean blueNegZ = Config.blueNegZ(); + private final Map hasBlueLeft = new HashMap<>(); public FightUI() { new StateDependentTask(ArenaMode.AntiReplay, FightState.All, this::update, 20, 20); + instance = this; } private void update() { @@ -60,8 +63,6 @@ public class FightUI { double totalHearts = blueHearts + redHearts; if(totalHearts == 0.0) totalHearts = 1.0; - setupTeamBar(blue, leftBlue, blueHearts / totalHearts); - setupTeamBar(red, leftRed, redHearts / totalHearts); int timeLeft = StateDependentCountdown.getMainCountdown() != null ? StateDependentCountdown.getMainCountdown().getTimeLeft() : 0; String time = "§7" + (timeLeft/60) + "§8:§7" + (timeLeft%60<10 ? "0" : "") + (timeLeft%60); @@ -92,87 +93,62 @@ public class FightUI { generator = (l, r, lP, rP, lW, rW) -> l.getColoredName() + " §7Kampf vorbei " + time + " " + r.getColoredName(); break; } - leftBlue.setTitle(generator.gen(blue, red, bluePlayers, redPlayers, blueAdditional, redAdditional)); - leftRed.setTitle(generator.gen(red, blue, redPlayers, bluePlayers, redAdditional, blueAdditional)); - BossBar negZ = Config.blueNegZ() ? leftBlue : leftRed; - BossBar posZ = Config.blueNegZ() ? leftRed : leftBlue; - - for(Player player : Bukkit.getOnlinePlayers()) { - float headRot = CraftbukkitWrapper.impl.headRotation(player) % 360; - if(headRot < 0) - headRot += 360; - BossBar current = players.remove(player); - - if(headRot >= 180){ //negZ links - if(negZ != current){ - if(current != null) - current.removePlayer(player); - negZ.addPlayer(player); - current = negZ; - } - }else{ //posZ links - if(posZ != current){ - if(current != null) - current.removePlayer(player); - posZ.addPlayer(player); - current = posZ; - } - } - players.put(player, current); - } + setBossbar( + blueHearts / totalHearts, redHearts / totalHearts, + generator.gen(blue, red, bluePlayers, redPlayers, blueAdditional, redAdditional), + generator.gen(red, blue, redPlayers, bluePlayers, redAdditional, blueAdditional) + ); } private interface Generator { String gen(FightTeam l, FightTeam r, String lPlayers, String rPlayers, String lWinconditions, String rWinconditions); } - private void setupTeamBar(FightTeam team, BossBar bar, double progress) { - BarColor color = chat2bar(team.getColor()); - if(bar.getColor() != color) - bar.setColor(color); - - if(bar.getProgress() != progress) - bar.setProgress(progress); + public void setBossbar(double leftBlueProgress, double leftRedProgress, String leftBlueText, String leftRedText) { + GlobalRecorder.getInstance().bossBar(leftBlueProgress, leftRedProgress, leftBlueText, leftRedText); + BountifulWrapper.impl.setBossbar(leftBlueProgress, leftRedProgress, leftBlueText, leftRedText); + sendToPlayers(); } - private BarColor chat2bar(ChatColor color) { - switch(color) { - case DARK_BLUE: - case DARK_AQUA: - case BLUE: - case AQUA: - return BarColor.BLUE; - case GREEN: - case DARK_GREEN: - return BarColor.GREEN; - case DARK_RED: - case RED: - return BarColor.RED; - case DARK_PURPLE: - return BarColor.PURPLE; - case GOLD: - case YELLOW: - return BarColor.YELLOW; - case LIGHT_PURPLE: - return BarColor.PINK; - case BLACK: - case WHITE: - case GRAY: - case DARK_GRAY: - default: - return BarColor.WHITE; - } + public boolean hasBlueLeft(Player player) { + return hasBlueLeft.get(player); } + private void sendToPlayers() { + Bukkit.getOnlinePlayers().forEach(player -> { + float headRot = CraftbukkitWrapper.impl.headRotation(player) % 360; + if(headRot < 0) + headRot += 360; + + //TODO: Rotation did not work + boolean useNegZ = headRot >= 180; + Boolean current = hasBlueLeft.get(player); + boolean flip = current == null || useNegZ == (current == blueNegZ); + + if(flip) { + if(current != null) + BountifulWrapper.impl.removeFromBar(player, current); + current = (useNegZ == blueNegZ); + BountifulWrapper.impl.addToBar(player, current); + hasBlueLeft.put(player, current); + } + }); + BountifulWrapper.impl.broadcastBossbar(); + } + + private static final Queue queue = new LinkedList<>(); private static boolean subtitleScheduled = false; public static void printWin(String title, String winreason) { queue.clear(); + + FightSystem.getPlugin().getLogger().log(Level.INFO, title + " " + winreason); + GlobalRecorder.getInstance().printWin(title, winreason); Bukkit.getOnlinePlayers().forEach(p -> { p.resetTitle(); - p.sendTitle(title, winreason, 10, 80, 10); + WorldOfColorWrapper.impl.sendTitle(p, title, winreason, 5, 40, 5); }); } @@ -181,6 +157,9 @@ public class FightUI { return; queue.add(message); + GlobalRecorder.getInstance().subtitle(message); + FightSystem.getPlugin().getLogger().log(Level.INFO, message); + if(!subtitleScheduled) printSubtitle(); } @@ -192,8 +171,7 @@ public class FightUI { } String message = queue.poll(); - //TODO: Sendtitle so nicht in <1.10 verfügbar! - Bukkit.getOnlinePlayers().forEach(p -> p.sendTitle("", message, 10, 80, 10)); + Bukkit.getOnlinePlayers().forEach(p -> WorldOfColorWrapper.impl.sendTitle(p, "", message, 5, 40, 5)); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), FightUI::printSubtitle, 100); subtitleScheduled = true; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java index 6d17a26..2bd0c37 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java @@ -24,6 +24,7 @@ import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; import org.bukkit.scoreboard.Team; public class WorldOfColorWrapper { @@ -36,5 +37,7 @@ public class WorldOfColorWrapper { boolean isInBlock(Arrow e); void playSound(Location location, Sound sound, String soundCategory, float volume, float pitch); + + void sendTitle(Player player, String title, String subtitle, int start, int hold, int stop); } }