Skip to content

Commit

Permalink
Add /npc bossbar --viewpermission
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jun 24, 2023
1 parent 6d6cc40 commit 053438b
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class BossBarTrait extends Trait {
@Persist
private String track;
@Persist
private String viewPermission;
@Persist
private boolean visible = true;

public BossBarTrait() {
Expand Down Expand Up @@ -91,6 +93,10 @@ public String getTrackingVariable() {
return track;
}

public String getViewPermission() {
return viewPermission;
}

private boolean isBoss(Entity entity) {
boolean isBoss = entity.getType() == EntityType.ENDER_DRAGON || entity.getType() == EntityType.WITHER
|| entity.getType() == EntityType.GUARDIAN;
Expand Down Expand Up @@ -168,6 +174,8 @@ public void run() {
barCache.removeAll();
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(npc.getEntity().getLocation(),
range > 0 ? range : Setting.BOSSBAR_RANGE.asInt())) {
if (viewPermission != null && !player.hasPermission(viewPermission))
continue;
barCache.addPlayer(player);
}
}
Expand Down Expand Up @@ -201,22 +209,26 @@ public void setTrackVariable(String variable) {
this.track = variable;
}

public void setViewPermission(String viewpermission) {
this.viewPermission = viewpermission;
}

public void setVisible(boolean visible) {
this.visible = visible;
}

@Command(
aliases = { "npc" },
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags] --track [health | placeholder] --range [range]",
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --viewpermission [permission] --flags [flags] --track [health | placeholder] --range [range]",
desc = "Edit bossbar properties",
modifiers = { "bossbar" },
min = 1,
max = 1)
@Requirements(selected = true, ownership = true)
public static void bossbar(CommandContext args, CommandSender sender, NPC npc, @Flag("style") BarStyle style,
@Flag("track") String track, @Flag("color") BarColor color, @Flag("visible") Boolean visible,
@Flag("range") Integer range, @Flag("title") String title, @Flag("flags") String flags)
throws CommandException {
@Flag("range") Integer range, @Flag("title") String title, @Flag("flags") String flags,
@Flag("viewpermission") String viewpermission) throws CommandException {
BossBarTrait trait = npc.getOrAddTrait(BossBarTrait.class);
if (style != null) {
trait.setStyle(style);
Expand All @@ -236,6 +248,9 @@ public static void bossbar(CommandContext args, CommandSender sender, NPC npc, @
if (range != null) {
trait.setRange(range);
}
if (viewpermission != null) {
trait.setViewPermission(viewpermission);
}
if (flags != null) {
List<BarFlag> parsed = Lists.newArrayList();
for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(flags)) {
Expand Down

0 comments on commit 053438b

Please sign in to comment.