Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
da68b5672f
Commit
e8e6b5fcfd
@ -41,7 +41,7 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
|
||||
|
||||
public BountifulWrapper8() {
|
||||
EntityEnderDragon dragon = new EntityEnderDragon(null);
|
||||
dragon.setLocation(Config.ArenaRegion.centerX(), 0, Config.ArenaRegion.centerZ(), 0, 0);
|
||||
dragon.setLocation(Config.ArenaRegion.centerX(), -100, Config.ArenaRegion.centerZ(), 0, 0);
|
||||
this.spawnDragonId = dragon.getId();
|
||||
this.spawnDragon = new PacketPlayOutSpawnEntityLiving(dragon);
|
||||
}
|
||||
@ -162,37 +162,33 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
private PacketPlayOutEntityMetadata leftBlue;
|
||||
private PacketPlayOutEntityMetadata leftRed;
|
||||
|
||||
private final Map<FightUI.BossBarType, PacketPlayOutEntityMetadata> barMap = new HashMap<>();
|
||||
@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);
|
||||
barMap.clear();
|
||||
barMap.put(FightUI.BossBarType.BLUE_LEFT, createPacket(leftBlueProgress, leftBlueText));
|
||||
barMap.put(FightUI.BossBarType.RED_LEFT, createPacket(leftRedProgress, leftRedText));
|
||||
}
|
||||
|
||||
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);
|
||||
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, boolean leftBlueBar) {
|
||||
public void removeFromBar(Player player, FightUI.BossBarType type) {
|
||||
// not used
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToBar(Player player, boolean leftBlueBar) {
|
||||
public void addToBar(Player player, FightUI.BossBarType type) {
|
||||
// not used
|
||||
}
|
||||
|
||||
@ -208,7 +204,7 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
|
||||
seesDragon.add(player);
|
||||
}
|
||||
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(FightUI.getInstance().hasBlueLeft(player) ? leftBlue : leftRed);
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(barMap.get(FightUI.getInstance().bossBarType(player)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
|
||||
@ -51,6 +53,12 @@ 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;
|
||||
@ -197,24 +205,22 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
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<FightUI.BossBarType, BossBar> barMap = new HashMap<>();
|
||||
@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);
|
||||
setupTeamBar(Fight.getBlueTeam(), barMap.get(FightUI.BossBarType.BLUE_LEFT), leftBlueProgress, leftBlueText);
|
||||
setupTeamBar(Fight.getRedTeam(), barMap.get(FightUI.BossBarType.RED_LEFT), leftRedProgress, leftRedText);
|
||||
}
|
||||
|
||||
private void setupTeamBar(FightTeam team, BossBar bar, double progress) {
|
||||
private void setupTeamBar(FightTeam team, BossBar bar, double progress, String title) {
|
||||
BarColor color = chat2bar(team.getColor());
|
||||
if(bar.getColor() != color)
|
||||
bar.setColor(color);
|
||||
|
||||
if(bar.getProgress() != progress)
|
||||
bar.setProgress(progress);
|
||||
|
||||
bar.setTitle(title);
|
||||
}
|
||||
|
||||
private BarColor chat2bar(ChatColor color) {
|
||||
@ -247,13 +253,13 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromBar(Player player, boolean leftBlueBar) {
|
||||
(leftBlueBar ? leftBlue : leftRed).removePlayer(player);
|
||||
public void removeFromBar(Player player, FightUI.BossBarType type) {
|
||||
barMap.get(type).removePlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToBar(Player player, boolean leftBlueBar) {
|
||||
(leftBlueBar ? leftBlue : leftRed).addPlayer(player);
|
||||
public void addToBar(Player player, FightUI.BossBarType type) {
|
||||
barMap.get(type).addPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,8 +59,8 @@ public class BountifulWrapper {
|
||||
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 removeFromBar(Player player, FightUI.BossBarType type);
|
||||
void addToBar(Player player, FightUI.BossBarType type);
|
||||
void broadcastBossbar();
|
||||
}
|
||||
}
|
||||
|
@ -46,11 +46,11 @@ public class FightUI {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final boolean blueNegZ = Config.blueNegZ();
|
||||
private final Map<Player, Boolean> hasBlueLeft = new HashMap<>();
|
||||
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);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@ -61,8 +61,11 @@ public class FightUI {
|
||||
double blueHearts = blue.getCurrentHearts();
|
||||
double redHearts = red.getCurrentHearts();
|
||||
double totalHearts = blueHearts + redHearts;
|
||||
if(totalHearts == 0.0)
|
||||
if(redHearts == 0.0 || blueHearts == 0.0) {
|
||||
blueHearts = 0.5;
|
||||
redHearts = 0.5;
|
||||
totalHearts = 1.0;
|
||||
}
|
||||
|
||||
int timeLeft = StateDependentCountdown.getMainCountdown() != null ? StateDependentCountdown.getMainCountdown().getTimeLeft() : 0;
|
||||
String time = "§7" + (timeLeft/60) + "§8:§7" + (timeLeft%60<10 ? "0" : "") + (timeLeft%60);
|
||||
@ -108,35 +111,55 @@ public class FightUI {
|
||||
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();
|
||||
}
|
||||
|
||||
public boolean hasBlueLeft(Player player) {
|
||||
return hasBlueLeft.get(player);
|
||||
public BossBarType bossBarType(Player player) {
|
||||
return currentBarType.get(player);
|
||||
}
|
||||
|
||||
private void sendToPlayers() {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
float headRot = CraftbukkitWrapper.impl.headRotation(player) % 360;
|
||||
if(headRot < 0)
|
||||
headRot += 360;
|
||||
BossBarType type = BossBarType.byAngle(CraftbukkitWrapper.impl.headRotation(player));
|
||||
BossBarType current = currentBarType.get(player);
|
||||
|
||||
//TODO: Rotation did not work
|
||||
boolean useNegZ = headRot >= 180;
|
||||
Boolean current = hasBlueLeft.get(player);
|
||||
boolean flip = current == null || useNegZ == (current == blueNegZ);
|
||||
|
||||
if(flip) {
|
||||
if(type != current) {
|
||||
if(current != null)
|
||||
BountifulWrapper.impl.removeFromBar(player, current);
|
||||
current = (useNegZ == blueNegZ);
|
||||
BountifulWrapper.impl.addToBar(player, current);
|
||||
hasBlueLeft.put(player, current);
|
||||
BountifulWrapper.impl.addToBar(player, type);
|
||||
currentBarType.put(player, type);
|
||||
}
|
||||
});
|
||||
BountifulWrapper.impl.broadcastBossbar();
|
||||
}
|
||||
|
||||
public enum BossBarType {
|
||||
BLUE_LEFT(345, 165),
|
||||
RED_LEFT(165, 345);
|
||||
|
||||
private static final boolean blueNegZ = Config.blueNegZ();
|
||||
|
||||
private final double minAngle;
|
||||
private final double maxAngle;
|
||||
|
||||
BossBarType(double minAngle, double maxAngle) {
|
||||
this.minAngle = minAngle;
|
||||
this.maxAngle = maxAngle;
|
||||
}
|
||||
|
||||
private static BossBarType byAngle(double angle) {
|
||||
if(blueNegZ)
|
||||
angle += 180;
|
||||
angle = ((angle % 360) + 360) % 360;
|
||||
|
||||
for(BossBarType type : values()) {
|
||||
if(type.minAngle < type.maxAngle ? type.minAngle <= angle && angle < type.maxAngle : type.minAngle < angle || angle <= type.maxAngle)
|
||||
return type;
|
||||
}
|
||||
|
||||
throw new SecurityException("No boss bar for angle " + angle + " found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final Queue<String> queue = new LinkedList<>();
|
||||
private static boolean subtitleScheduled = false;
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren