Skip to content

Commit

Permalink
Fix null check in age
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jun 14, 2022
1 parent 2e2a837 commit 138aaac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.google.common.collect.Maps;

import net.citizensnpcs.api.gui.CitizensInventoryClickEvent;
import net.citizensnpcs.api.gui.InputMenu;
import net.citizensnpcs.api.gui.InputMenus;
import net.citizensnpcs.api.gui.InventoryMenuPage;
import net.citizensnpcs.api.gui.InventoryMenuSlot;
import net.citizensnpcs.api.gui.Menu;
Expand Down Expand Up @@ -72,8 +72,8 @@ public ConfiguratorInfo(Material mat, Consumer<ConfiguratorEvent> con) {
SLOT_MAP.put(0, new ConfiguratorInfo(Util.getFallbackMaterial("OAK_SIGN", "SIGN"), (evt) -> {
evt.slot.setDescription("Edit NPC name\n" + evt.npc.getName());
if (evt.event != null) {
evt.ctx.getMenu()
.transition(InputMenu.setter(() -> evt.npc.getName(), (input) -> evt.npc.setName(input)));
evt.ctx.getMenu().transition(
InputMenus.stringSetter(() -> evt.npc.getName(), (input) -> evt.npc.setName(input)));
}
}));

Expand Down
2 changes: 1 addition & 1 deletion main/src/main/java/net/citizensnpcs/trait/Age.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void onSpawn() {
} else if (npc.getEntity() instanceof Zombie) {
((Zombie) npc.getEntity()).setBaby(age < 0);
ageable = null;
} else if (npc.getEntity().getType().name().equals("TADPOLE")) {
} else if (npc.isSpawned() && npc.getEntity().getType().name().equals("TADPOLE")) {
((Tadpole) npc.getEntity()).setAge(age);
ageable = null;
} else {
Expand Down
15 changes: 11 additions & 4 deletions main/src/main/java/net/citizensnpcs/trait/ShopTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

import net.citizensnpcs.api.gui.CitizensInventoryClickEvent;
import net.citizensnpcs.api.gui.ClickHandler;
import net.citizensnpcs.api.gui.InputMenu;
import net.citizensnpcs.api.gui.InputMenus;
import net.citizensnpcs.api.gui.InputMenus.Choice;
import net.citizensnpcs.api.gui.InventoryMenu;
import net.citizensnpcs.api.gui.InventoryMenuPage;
import net.citizensnpcs.api.gui.InventoryMenuSlot;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static class NPCShop {
@Persist
private String requiredPermission;
@Persist
private final ShopType type = ShopType.VIEW;
private ShopType type = ShopType.VIEW;

private NPCShop(String name) {
this.name = name;
Expand Down Expand Up @@ -99,13 +100,19 @@ public void initialise(MenuContext ctx) {
@ClickHandler(slot = { 0, 2 })
public void onPermissionChange(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
ctx.getMenu()
.transition(InputMenu.setter(() -> shop.getRequiredPermission(), (p) -> shop.setPermission(p)));
ctx.getMenu().transition(
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) -> {
shop.type = chosen.getValue();
}, Choice.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)));
}
}

Expand Down

0 comments on commit 138aaac

Please sign in to comment.