SteamWar/FightSystem
Archiviert
13
1

Multiling (nur Multling) #294

Zusammengeführt
Lixfel hat 10 Commits von multiling nach master 2021-10-24 19:38:35 +02:00 zusammengeführt
13 geänderte Dateien mit 121 neuen und 111 gelöschten Zeilen
Nur Änderungen aus Commit 9eefaf9e6b werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.fightsystem.utils;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.listener.Recording;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.record.REntity;
@ -150,49 +151,24 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
}
}
private final Map<FightUI.BossBarType, PacketPlayOutEntityMetadata> barMap = new HashMap<>();
private final Set<Player> seesDragon = new HashSet<>();
private final PacketPlayOutSpawnEntityLiving spawnDragon;
private final int spawnDragonId;
@Override
public void setBossbar(double leftBlueProgress, double leftRedProgress, String leftBlueText, String leftRedText) {
barMap.clear();
barMap.put(FightUI.BossBarType.BLUE_LEFT, createPacket(leftBlueProgress, leftBlueText));
barMap.put(FightUI.BossBarType.RED_LEFT, createPacket(leftRedProgress, leftRedText));
public void sendBar(Player player, FightTeam team, double progress, String text) {
seesDragon.removeIf(p -> !p.isOnline());
if(!seesDragon.contains(player)) {
((CraftPlayer)player).getHandle().playerConnection.sendPacket(spawnDragon);
seesDragon.add(player);
}
private PacketPlayOutEntityMetadata createPacket(double progress, String text) {
DataWatcher watcher = new DataWatcher(null);
watcher.a(0, (byte) 0x20);
watcher.a(2, text);
watcher.a(3, (byte) 1);
watcher.a(4, (byte) 1);
watcher.a(6, (float)(progress * 200));
//watcher.a(10, text);
//watcher.a(11, (byte) 1);
return new PacketPlayOutEntityMetadata(spawnDragonId, watcher, true);
}
@Override
public void removeFromBar(Player player, FightUI.BossBarType type) {
// not used
}
@Override
public void addToBar(Player player, FightUI.BossBarType type) {
// not used
}
private final Set<Player> 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(barMap.get(FightUI.getInstance().bossBarType(player)));
});
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(spawnDragonId, watcher, true));
}
}

Datei anzeigen

@ -20,7 +20,6 @@
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;
@ -51,12 +50,6 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
private static final Object mainHand = enumHand.getEnumConstants()[0];
private static final Reflection.FieldAccessor<?> blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0);
public BountifulWrapper9() {
for(FightUI.BossBarType type : FightUI.BossBarType.values()) {
barMap.put(type, Bukkit.createBossBar(type.name(), BarColor.WHITE, BarStyle.SOLID));
}
}
@Override
public boolean mainHand(Object packet) {
return blockPlaceHand.get(packet) == mainHand;
@ -193,14 +186,15 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
}
}
private final Map<FightUI.BossBarType, BossBar> barMap = new HashMap<>();
private final Map<Player, BossBar> barMap = new HashMap<>();
@Override
public void setBossbar(double leftBlueProgress, double leftRedProgress, String leftBlueText, String leftRedText) {
setupTeamBar(Fight.getBlueTeam(), barMap.get(FightUI.BossBarType.BLUE_LEFT), leftBlueProgress, leftBlueText);
setupTeamBar(Fight.getRedTeam(), barMap.get(FightUI.BossBarType.RED_LEFT), leftRedProgress, leftRedText);
}
public void sendBar(Player player, FightTeam team, double progress, String text) {
barMap.keySet().removeIf(p -> !p.isOnline());
private void setupTeamBar(FightTeam team, BossBar bar, double progress, String title) {
if(!barMap.containsKey(player))
barMap.put(player, Bukkit.createBossBar(player.getName(), BarColor.WHITE, BarStyle.SOLID));
BossBar bar = barMap.get(player);
BarColor color = chat2bar(team.getColor());
if(bar.getColor() != color)
bar.setColor(color);
@ -208,7 +202,8 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
if(bar.getProgress() != progress)
bar.setProgress(progress);
bar.setTitle(title);
if(!bar.getTitle().equals(text))
bar.setTitle(text);
}
private BarColor chat2bar(ChatColor color) {
@ -239,19 +234,4 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
return BarColor.WHITE;
}
}
@Override
public void removeFromBar(Player player, FightUI.BossBarType type) {
barMap.get(type).removePlayer(player);
}
@Override
public void addToBar(Player player, FightUI.BossBarType type) {
barMap.get(type).addPlayer(player);
}
@Override
public void broadcastBossbar() {
// Handled by Spigot BossBarAPI
}
}

Datei anzeigen

@ -184,6 +184,20 @@ UI_ELO=
UI_WIN={0}Sieg {1}
UI_DRAW=§7Unentschieden
BAR_PRE_LEADER=§7Warten auf Teamleader
BAR_PRE_SCHEM={1} §7Schemauswahl {0} {2}
BAR_PREPARE={1} {3} §7Vorbereitung {0} {4} {2}
BAR_PRE_RUNNING={1} {3} §7Kampfbeginn in {0} {4} {2}
BAR_RUNNING0={1} {3} lW {0} rW {4} {2}
BAR_RUNNING1={1} {3} {5} {0} {6} {4} {2}
BAR_RUNNING2={1} {3} {5} {7} {0} {6} {8} {4} {2}
BAR_RUNNING3={1} {3} {5} {7} {9} {0} {6} {8} {10} {4} {2}
BAR_SPECTATE={1} §7Kampf vorbei {0} {2}
BAR_POINTS={0} §8Punkte
BAR_PERCENT={0}§8%
BAR_CANNONS={0} §8Kanonen
BAR_WATER={0} §8Wasser
# Winconditions
HELLS_BELLS_COUNTDOWN=bis die Bomben fallen

Datei anzeigen

@ -120,6 +120,7 @@ public class PacketProcessor {
packetDecoder[0xc4] = this::printWin;
packetDecoder[0xc5] = this::messageSubtitle;
packetDecoder[0xc6] = this::winMessage;
packetDecoder[0xc7] = this::bossBarMessage;
packetDecoder[0xef] = source::readUTF;
packetDecoder[0xff] = this::tick;
@ -421,6 +422,15 @@ public class PacketProcessor {
FightUI.getInstance().setBossbar(leftBlueProgress, leftRedProgress, leftBlueText, leftRedText);
}
private void bossBarMessage() throws IOException {
double leftBlueProgress = source.readDouble();
double leftRedProgress = source.readDouble();
Message leftBlueText = readMessage();
Message leftRedText = readMessage();
FightUI.getInstance().setBossbar(leftBlueProgress, leftRedProgress, leftBlueText, leftRedText);
}
private void subtitle() throws IOException {
String subtitle = source.readUTF();
@ -534,6 +544,9 @@ public class PacketProcessor {
case 0x07:
params.add(source.readUTF());
break;
case 0x08:
params.add(readMessage());
break;
default:
throw new IOException("Unknown message param type " + type);
}

Datei anzeigen

@ -123,11 +123,12 @@ public interface Recorder {
*
* DEPRECATED ScoreboardTitlePacket (0xc0) + String scoreboardTitle
* DEPRECATED ScoreboardDataPacket (0xc1) + String key + int value
* BossBarPacket (0xc2) + double leftBlueProgress, leftRedProgress + String leftBlueText, leftRedText
* DEPRECATED BossBarPacket (0xc2) + double leftBlueProgress, leftRedProgress + String leftBlueText, leftRedText
* DEPRECATED SubtitlePacket (0xc3) + String subtitle
* DEPRECATED PrintWinPacket (0xc4) + String title, subtitle
* SubtitlePacket (0xc5) + Message
* WinPacket (0xc6) + byte team + Message subtitle
* BossBarPacket (0xc7) + double leftBlueProgress, leftRedProgress + Message leftBlueText, leftRedText
*
* CommentPacket (0xfe) + String comment
* TickPacket (0xff)
@ -142,6 +143,7 @@ public interface Recorder {
* 0x05: float following
* 0x06: double following
* 0x07: String following
* 0x08: Message following
* */
default void playerJoins(Player p){
@ -292,8 +294,8 @@ public interface Recorder {
}
}
default void bossBar(double leftBlueProgress, double leftRedProgress, String leftBlueText, String leftRedText) {
write(0xc2, leftBlueProgress, leftRedProgress, leftBlueText, leftRedText);
default void bossBar(double leftBlueProgress, double leftRedProgress, Message leftBlueText, Message leftRedText) {
write(0xc7, leftBlueProgress, leftRedProgress, leftBlueText, leftRedText);
}
default void subtitle(Message subtitle) {
@ -366,6 +368,8 @@ public interface Recorder {
stream.writeByte(0x06);
else if(o instanceof String)
stream.writeByte(0x07);
else if(o instanceof Message)
stream.writeByte(0x08);
else
throw new SecurityException("Undefined message serialization for: " + o.getClass().getName());
writeObject(stream, o);

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.fightsystem.utils;
import de.steamwar.fightsystem.VersionDependent;
import de.steamwar.fightsystem.fight.FightTeam;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
@ -54,9 +55,6 @@ public class BountifulWrapper {
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, FightUI.BossBarType type);
void addToBar(Player player, FightUI.BossBarType type);
void broadcastBossbar();
void sendBar(Player player, FightTeam team, double progress, String text);
}
}

Datei anzeigen

@ -33,9 +33,9 @@ import de.steamwar.fightsystem.winconditions.Wincondition;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Map;
import java.util.List;
import java.util.Queue;
import java.util.logging.Level;
import java.util.stream.Collectors;
@ -47,8 +47,6 @@ public class FightUI {
return instance;
}
private final Map<Player, BossBarType> currentBarType = new HashMap<>();
public FightUI() {
new StateDependentTask(ArenaMode.AntiReplay, FightState.All, this::update, 20, 20);
new StateDependentTask(ArenaMode.All, FightState.All, this::sendToPlayers, 5, 5);
@ -73,29 +71,41 @@ public class FightUI {
String time = "§7" + (timeLeft/60) + "§8:§7" + (timeLeft%60<10 ? "0" : "") + (timeLeft%60);
String bluePlayers = blue.getPrefix() + blue.getAlivePlayers() + "§8/§7" + blue.getPlayerCount();
String redPlayers = red.getPrefix() + red.getAlivePlayers() + "§8/§7" + red.getPlayerCount();
String redAdditional = Wincondition.getPrintableWinconditions().stream().map(w -> w.getDisplay(red)).collect(Collectors.joining(" "));
String blueAdditional = Wincondition.getPrintableWinconditions().stream().map(w -> w.getDisplay(blue)).collect(Collectors.joining(" "));
List<Message> redAdditional = Wincondition.getPrintableWinconditions().stream().map(w -> w.getDisplay(red)).collect(Collectors.toList());
List<Message> blueAdditional = Wincondition.getPrintableWinconditions().stream().map(w -> w.getDisplay(blue)).collect(Collectors.toList());
Generator generator;
switch(FightState.getFightState()){
case PRE_LEADER_SETUP:
generator = (l, r, lP, rP, lW, rW) -> "§7Warten auf Teamleader";
generator = (l, r, lP, rP, lW, rW) -> new Message("BAR_PRE_LEADER");
break;
case PRE_SCHEM_SETUP:
generator = (l, r, lP, rP, lW, rW) -> l.getColoredName() + " §7Schemauswahl " + time + " " + r.getColoredName();
generator = (l, r, lP, rP, lW, rW) -> new Message("BAR_PRE_SCHEM", time, l.getColoredName(), r.getColoredName());
break;
case POST_SCHEM_SETUP:
generator = (l, r, lP, rP, lW, rW) -> l.getColoredName() + " " + lP + " §7Vorbereitung " + time + " " + rP + " " + r.getColoredName();
generator = (l, r, lP, rP, lW, rW) -> new Message("BAR_PREPARE", time, l.getColoredName(), r.getColoredName(), lP, rP);
break;
case PRE_RUNNING:
generator = (l, r, lP, rP, lW, rW) -> l.getColoredName() + " " + lP + " §7Kampfbeginn in " + time + " " + rP + " " + r.getColoredName();
generator = (l, r, lP, rP, lW, rW) -> new Message("BAR_PRE_RUNNING", time, l.getColoredName(), r.getColoredName(), lP, rP);
break;
case RUNNING:
generator = (l, r, lP, rP, lW, rW) -> l.getColoredName() + " " + lP + " " + lW + " " + time + " " + rW + " " + rP + " " + r.getColoredName();
generator = (l, r, lP, rP, lW, rW) -> {
List<Object> params = new ArrayList<>();
params.add(time);
params.add(l.getColoredName());
params.add(r.getColoredName());
params.add(lP);
params.add(rP);
for(int i = 0; i < lW.size(); i++) {
params.add(lW.get(i));
params.add(rW.get(i));
}
return new Message("BAR_RUNNING" + lW.size(), params.toArray());
};
break;
case SPECTATE:
default:
generator = (l, r, lP, rP, lW, rW) -> l.getColoredName() + " §7Kampf vorbei " + time + " " + r.getColoredName();
generator = (l, r, lP, rP, lW, rW) -> new Message("BAR_SPECTATE", time, l.getColoredName(), r.getColoredName());
break;
}
@ -107,31 +117,35 @@ public class FightUI {
}
private interface Generator {
String gen(FightTeam l, FightTeam r, String lPlayers, String rPlayers, String lWinconditions, String rWinconditions);
Message gen(FightTeam l, FightTeam r, String lPlayers, String rPlayers, List<Message> lWinconditions, List<Message> rWinconditions);
}
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);
setBossbar(leftBlueProgress, leftRedProgress, new Message("OLD_STRING", leftBlueText), new Message("OLD_STRING", leftRedText));
}
public BossBarType bossBarType(Player player) {
return currentBarType.get(player);
public void setBossbar(double leftBlueProgress, double leftRedProgress, Message leftBlueText, Message leftRedText) {
GlobalRecorder.getInstance().bossBar(leftBlueProgress, leftRedProgress, leftBlueText, leftRedText);
BossBarType.BLUE_LEFT.progress = leftBlueProgress;
BossBarType.RED_LEFT.progress = leftRedProgress;
BossBarType.BLUE_LEFT.text = leftBlueText;
BossBarType.RED_LEFT.text = leftRedText;
}
private void sendToPlayers() {
Bukkit.getOnlinePlayers().forEach(player -> {
BossBarType type = BossBarType.byAngle(CraftbukkitWrapper.impl.headRotation(player));
BossBarType current = currentBarType.get(player);
BossBarType bar = BossBarType.byAngle(CraftbukkitWrapper.impl.headRotation(player));
if(type != current) {
if(current != null)
BountifulWrapper.impl.removeFromBar(player, current);
BountifulWrapper.impl.addToBar(player, type);
currentBarType.put(player, type);
Object[] params = bar.text.getParams().clone();
for(int i = 0; i < params.length; i++) {
if(params[i] instanceof Message) {
Message msg = (Message) params[i];
params[i] = FightSystem.getMessage().parse(msg.getMsg(), player, msg.getParams());
}
}
BountifulWrapper.impl.sendBar(player, bar.team, bar.progress, FightSystem.getMessage().parse(bar.text.getMsg(), player, params));
});
BountifulWrapper.impl.broadcastBossbar();
}
private void tpsWatcher() {
@ -141,15 +155,20 @@ public class FightUI {
}
public enum BossBarType {
BLUE_LEFT(345, 165),
RED_LEFT(165, 345);
BLUE_LEFT(Fight.getBlueTeam(), 345, 165),
RED_LEFT(Fight.getRedTeam(), 165, 345);
private static final boolean BLUE_NEG_Z = Config.blueNegZ();
private final double minAngle;
private final double maxAngle;
BossBarType(double minAngle, double maxAngle) {
private final FightTeam team;
private double progress;
private Message text;
BossBarType(FightTeam team, double minAngle, double maxAngle) {
this.team = team;
this.minAngle = minAngle;
this.maxAngle = maxAngle;
}

Datei anzeigen

@ -20,7 +20,8 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.utils.Message;
public interface PrintableWincondition {
String getDisplay(FightTeam team);
Message getDisplay(FightTeam team);
}

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.Message;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
@ -62,8 +63,8 @@ public class WinconditionPercentSystem extends Wincondition implements Listener,
}
@Override
public String getDisplay(FightTeam team) {
return team.getPrefix() + (Math.round(100.0 * getPercent(team)) / 100.0) + "§8%";
public Message getDisplay(FightTeam team) {
return new Message("BAR_PERCENT", team.getPrefix() + (Math.round(100.0 * getPercent(team)) / 100.0));
}
@Override

Datei anzeigen

@ -27,6 +27,7 @@ import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.states.StateDependentCountdown;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.Message;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -104,8 +105,8 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
}
@Override
public String getDisplay(FightTeam team) {
return team.getPrefix() + teamMap.get(team).getPoints() + " §8Punkte";
public Message getDisplay(FightTeam team) {
return new Message("BAR_POINTS", team.getPrefix() + teamMap.get(team).getPoints());
}
private class TeamPoints {

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.inventory.SWItem;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -55,8 +56,8 @@ public class WinconditionPumpkinTechKO extends Wincondition implements Printable
}
@Override
public String getDisplay(FightTeam team) {
return team.getPrefix() + teamMap.get(team).pumpkins + " §8Kanonen";
public Message getDisplay(FightTeam team) {
return new Message("BAR_CANNONS", team.getPrefix() + teamMap.get(team).pumpkins);
}
private class TeamPumpkin {

Datei anzeigen

@ -25,6 +25,7 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.Message;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
@ -63,8 +64,8 @@ public class WinconditionRelativePercent extends Wincondition implements Printab
}
@Override
public String getDisplay(FightTeam team) {
return team.getPrefix() + (Math.round(100.0 * getPercent(team)) / 100.0) + "§8%";
public Message getDisplay(FightTeam team) {
return new Message("BAR_PERCENT", team.getPrefix() + (Math.round(100.0 * getPercent(team)) / 100.0));
}
public static class TeamPercent extends StateDependent {

Datei anzeigen

@ -25,6 +25,7 @@ import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.utils.FlatteningWrapper;
import de.steamwar.fightsystem.utils.Message;
import org.bukkit.Bukkit;
import org.bukkit.World;
@ -53,8 +54,8 @@ public class WinconditionWaterTechKO extends Wincondition implements PrintableWi
}
@Override
public String getDisplay(FightTeam team) {
return team.getPrefix() + teamMap.get(team).water + " §8Wasser";
public Message getDisplay(FightTeam team) {
return new Message("BAR_WATER", team.getPrefix() + teamMap.get(team).water);
}
private class TeamWater {