Null check bossbar style

This commit is contained in:
fullwall 2022-07-17 02:10:38 +08:00
parent 58b53174c8
commit a81d8db87d
4 changed files with 37 additions and 22 deletions

View File

@ -443,7 +443,7 @@ public class NPCCommands {
} else if (args.getString(1).equalsIgnoreCase("itemcost")) {
if (!(sender instanceof Player))
throw new CommandException(Messages.COMMAND_MUST_BE_INGAME);
InventoryMenu.create(new ItemRequirementGUI(commands)).present(((Player) sender));
InventoryMenu.createSelfRegistered(new ItemRequirementGUI(commands)).present(((Player) sender));
} else {
throw new CommandUsageException();
}

View File

@ -402,7 +402,6 @@ public class CommandTrait extends Trait {
@Menu(title = "Drag items for requirements", type = InventoryType.CHEST, dimensions = { 5, 9 })
public static class ItemRequirementGUI extends InventoryMenuPage {
private Inventory inventory;
private int taskId;
private CommandTrait trait;
private ItemRequirementGUI() {
@ -415,7 +414,6 @@ public class CommandTrait extends Trait {
@Override
public void initialise(MenuContext ctx) {
this.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(CitizensAPI.getPlugin(), this, 0, 1);
this.inventory = ctx.getInventory();
for (ItemStack stack : trait.itemRequirements) {
inventory.addItem(stack.clone());
@ -424,11 +422,6 @@ public class CommandTrait extends Trait {
@Override
public void onClose(HumanEntity player) {
Bukkit.getScheduler().cancelTask(taskId);
}
@Override
public void run() {
List<ItemStack> requirements = Lists.newArrayList();
for (ItemStack stack : inventory.getContents()) {
if (stack != null && stack.getType() != Material.AIR) {

View File

@ -48,16 +48,16 @@ public class ShopTrait extends Trait {
@Persist(reify = true)
private final List<NPCShopPage> pages = Lists.newArrayList();
@Persist
private String requiredPermission;
@Persist
private ShopType type = ShopType.VIEW;
@Persist
private String viewPermission;
private NPCShop(String name) {
this.name = name;
}
public void display(Player sender) {
if (requiredPermission != null && !sender.hasPermission(requiredPermission))
if (viewPermission != null && !sender.hasPermission(viewPermission))
return;
}
@ -70,13 +70,13 @@ public class ShopTrait extends Trait {
}
public String getRequiredPermission() {
return requiredPermission;
return viewPermission;
}
public void setPermission(String permission) {
this.requiredPermission = permission;
if (requiredPermission != null && requiredPermission.isEmpty()) {
requiredPermission = null;
this.viewPermission = permission;
if (viewPermission != null && viewPermission.isEmpty()) {
viewPermission = null;
}
}
}
@ -84,6 +84,7 @@ public class ShopTrait extends Trait {
@Menu(title = "NPC Shop Editor", type = InventoryType.HOPPER, dimensions = { 0, 5 })
@MenuSlot(slot = { 0, 0 }, material = Material.BOOK, amount = 1, lore = "Edit shop type")
@MenuSlot(slot = { 0, 2 }, material = Material.OAK_SIGN, amount = 1, lore = "Edit shop permission")
@MenuSlot(slot = { 0, 4 }, material = Material.FEATHER, amount = 1, lore = "Edit shop items")
public static class NPCShopEditor extends InventoryMenuPage {
private MenuContext ctx;
private final NPCShop shop;
@ -97,19 +98,25 @@ public class ShopTrait extends Trait {
this.ctx = ctx;
}
@ClickHandler(slot = { 0, 4 })
public void onEditItems(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
ctx.getMenu().transition(new NPCShopItemEditor(shop));
}
@ClickHandler(slot = { 0, 2 })
public void onPermissionChange(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
ctx.getMenu().transition(
InputMenus.stringSetter(() -> shop.getRequiredPermission(), (p) -> shop.setPermission(p)));
InputMenus.stringSetter(() -> shop.getRequiredPermission(), p -> shop.setPermission(p)));
}
@ClickHandler(slot = { 0, 0 })
public void onShopTypeChange(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
ctx.getMenu().transition(InputMenus.<ShopType> picker("Edit shop type", (chosen) -> {
ctx.getMenu().transition(InputMenus.<ShopType> picker("Edit shop type", chosen -> {
shop.type = chosen.getValue();
}, Choice.of(ShopType.BUY, Material.DIAMOND, "Players buy items", shop.type == ShopType.BUY),
}, Choice.<ShopType> of(ShopType.BUY, Material.DIAMOND, "Players buy items", shop.type == ShopType.BUY),
Choice.of(ShopType.SELL, Material.EMERALD, "Players sell items", shop.type == ShopType.SELL),
Choice.of(ShopType.VIEW, Material.ENDER_EYE, "Players view items only",
shop.type == ShopType.VIEW)));
@ -123,6 +130,21 @@ public class ShopTrait extends Trait {
private ItemStack display;
}
@Menu(title = "NPC Shop Item Editor", type = InventoryType.CHEST, dimensions = { 5, 9 })
public static class NPCShopItemEditor extends InventoryMenuPage {
private MenuContext ctx;
private final NPCShop shop;
public NPCShopItemEditor(NPCShop shop) {
this.shop = shop;
}
@Override
public void initialise(MenuContext ctx) {
this.ctx = ctx;
}
}
public static class NPCShopPage {
@Persist("")
private int index;

View File

@ -135,14 +135,14 @@ public class BossBarTrait extends Trait {
}
}
}
bar.setStyle(style);
bar.setTitle(title);
bar.setVisible(visible);
if (style != null) {
bar.setStyle(style);
}
if (color != null) {
bar.setColor(color);
}
if (title != null) {
bar.setTitle(title);
}
for (BarFlag flag : BarFlag.values()) {
bar.removeFlag(flag);
}