Skip to content

Commit cd7feaa

Browse files
Pablete1234Electroid
authored andcommitted
Make wither bossbars less annoying
Signed-off-by: Pablete1234 <pabloherrerapalacio@gmail.com>
1 parent c48a339 commit cd7feaa

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/main/java/tc/oc/bossbar/BossBarView.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class BossBarView implements BossBarObserver {
1515

1616
public static final float BOSS_18_HEALTH = 300;
1717
public static final double BOSS_18_DISTANCE = 50;
18+
public static final float BOSS_18_ANGLE = 20;
1819
public static final int MAX_TEXT_LENGTH = 64;
1920

2021
private final Plugin plugin;
@@ -72,14 +73,15 @@ private String renderText() {
7273
}
7374

7475
private void spawnBoss() {
75-
resetBossLocation();
76+
resetBossLocation(viewer.getLocation());
7677
NMSHacks.spawnWither(viewer, entityId, location, renderText(), renderMeter());
7778
spawned = true;
7879
}
7980

80-
private void resetBossLocation() {
81-
location = viewer.getLocation();
82-
// Keep the boss in the center of the player's view
81+
private void resetBossLocation(Location pos) {
82+
location = pos;
83+
// Keep the boss a few degrees up from the center of the player's view
84+
location.setPitch(location.getPitch() - BOSS_18_ANGLE);
8385
location.add(location.getDirection().multiply(BOSS_18_DISTANCE));
8486
}
8587

@@ -104,7 +106,7 @@ public void run() {
104106
// Dispatched from elsewhere
105107
public void onPlayerMove(PlayerMoveEvent event) {
106108
if (viewer == event.getPlayer() && spawned) {
107-
resetBossLocation();
109+
resetBossLocation(event.getTo().clone());
108110
NMSHacks.teleportEntity(viewer, entityId, location);
109111
}
110112
}

src/main/java/tc/oc/pgm/bossbar/BossBarMatchModule.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.bukkit.event.player.PlayerInitialSpawnEvent;
1010
import org.bukkit.event.player.PlayerMoveEvent;
1111
import org.bukkit.event.player.PlayerRespawnEvent;
12+
import org.bukkit.event.player.PlayerTeleportEvent;
1213
import tc.oc.bossbar.BossBar;
1314
import tc.oc.bossbar.BossBarStack;
1415
import tc.oc.bossbar.BossBarView;
@@ -89,6 +90,12 @@ public void onPlayerMove(PlayerMoveEvent event) {
8990
if (view != null) view.onPlayerMove(event);
9091
}
9192

93+
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
94+
public void onPlayerMove(PlayerTeleportEvent event) {
95+
BossBarView view = views.get(event.getPlayer());
96+
if (view != null) view.onPlayerMove(event);
97+
}
98+
9299
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
93100
public void onPlayerRespawn(PlayerInitialSpawnEvent event) {
94101
BossBarView view = views.get(event.getPlayer());

src/main/java/tc/oc/world/NMSHacks.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ static EntityMetadata createBossMetadata(String name, float health) {
393393

394394
static EntityMetadata createWitherMetadata(String name, float health) {
395395
EntityMetadata data = createBossMetadata(name, health);
396-
DataWatcher watcher = ((EntityMetadata) data).dataWatcher;
397-
watcher.a(20, (int) 1000); // Invulnerability countdown
396+
DataWatcher watcher = data.dataWatcher;
397+
watcher.a(20, 890); // Invulnerability countdown
398398
return data;
399399
}
400400

0 commit comments

Comments
 (0)