Skip to content

Commit

Permalink
Make wither bossbars less annoying
Browse files Browse the repository at this point in the history
Signed-off-by: Pablete1234 <[email protected]>
  • Loading branch information
Pablete1234 authored and Electroid committed Nov 2, 2019
1 parent c48a339 commit cd7feaa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/main/java/tc/oc/bossbar/BossBarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand All @@ -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);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/tc/oc/pgm/bossbar/BossBarMatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tc/oc/world/NMSHacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit cd7feaa

Please sign in to comment.