diff --git a/src/main/java/tc/oc/bossbar/BossBarView.java b/src/main/java/tc/oc/bossbar/BossBarView.java index be45cc8115..debb389289 100644 --- a/src/main/java/tc/oc/bossbar/BossBarView.java +++ b/src/main/java/tc/oc/bossbar/BossBarView.java @@ -15,6 +15,7 @@ public class BossBarView implements BossBarObserver { public static final float BOSS_18_HEALTH = 300; public static final double BOSS_18_DISTANCE = 50; + public static final float BOSS_18_ANGLE = 20; public static final int MAX_TEXT_LENGTH = 64; private final Plugin plugin; @@ -72,14 +73,15 @@ private String renderText() { } private void spawnBoss() { - resetBossLocation(); + resetBossLocation(viewer.getLocation()); NMSHacks.spawnWither(viewer, entityId, location, renderText(), renderMeter()); spawned = true; } - private void resetBossLocation() { - location = viewer.getLocation(); - // Keep the boss in the center of the player's view + private void resetBossLocation(Location pos) { + location = pos; + // Keep the boss a few degrees up from the center of the player's view + location.setPitch(location.getPitch() - BOSS_18_ANGLE); location.add(location.getDirection().multiply(BOSS_18_DISTANCE)); } @@ -104,7 +106,7 @@ public void run() { // Dispatched from elsewhere public void onPlayerMove(PlayerMoveEvent event) { if (viewer == event.getPlayer() && spawned) { - resetBossLocation(); + resetBossLocation(event.getTo().clone()); NMSHacks.teleportEntity(viewer, entityId, location); } } diff --git a/src/main/java/tc/oc/pgm/bossbar/BossBarMatchModule.java b/src/main/java/tc/oc/pgm/bossbar/BossBarMatchModule.java index 1c7a6f10f0..2bdf9541bb 100644 --- a/src/main/java/tc/oc/pgm/bossbar/BossBarMatchModule.java +++ b/src/main/java/tc/oc/pgm/bossbar/BossBarMatchModule.java @@ -9,6 +9,7 @@ import org.bukkit.event.player.PlayerInitialSpawnEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent; import tc.oc.bossbar.BossBar; import tc.oc.bossbar.BossBarStack; import tc.oc.bossbar.BossBarView; @@ -89,6 +90,12 @@ public void onPlayerMove(PlayerMoveEvent event) { if (view != null) view.onPlayerMove(event); } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerMove(PlayerTeleportEvent event) { + BossBarView view = views.get(event.getPlayer()); + if (view != null) view.onPlayerMove(event); + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerRespawn(PlayerInitialSpawnEvent event) { BossBarView view = views.get(event.getPlayer()); diff --git a/src/main/java/tc/oc/world/NMSHacks.java b/src/main/java/tc/oc/world/NMSHacks.java index 661d100541..5cd7a25aaa 100644 --- a/src/main/java/tc/oc/world/NMSHacks.java +++ b/src/main/java/tc/oc/world/NMSHacks.java @@ -393,8 +393,8 @@ static EntityMetadata createBossMetadata(String name, float health) { static EntityMetadata createWitherMetadata(String name, float health) { EntityMetadata data = createBossMetadata(name, health); - DataWatcher watcher = ((EntityMetadata) data).dataWatcher; - watcher.a(20, (int) 1000); // Invulnerability countdown + DataWatcher watcher = data.dataWatcher; + watcher.a(20, 890); // Invulnerability countdown return data; }