Skip to content

Commit

Permalink
Updated PersistentItem references
Browse files Browse the repository at this point in the history
  • Loading branch information
fulminazzo committed Apr 13, 2024
1 parent e7a399f commit 2ad40ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static Item[] testItems() {
mockItem(Item.newRecipeItem()),
mockItem(BukkitItem.newItem()),
mockItem(BukkitItem.newRecipeItem()),
mockItem(new PersistentItem())
mockItem(PersistentItem.newItem())
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ void setUp() {

@Test
void testNullInteractAction() {
PersistentItem persistentItem = new PersistentItem("stone");
PersistentItem persistentItem = PersistentItem.newItem("stone");
Player player = mock(Player.class);
ItemStack itemStack = mock(ItemStack.class);
assertDoesNotThrow(() -> persistentItem.interact(player, itemStack, Action.LEFT_CLICK_AIR));
}

@Test
void testNullClickAction() {
PersistentItem persistentItem = new PersistentItem("stone");
PersistentItem persistentItem = PersistentItem.newItem("stone");
Player player = mock(Player.class);
ItemStack itemStack = mock(ItemStack.class);
assertDoesNotThrow(() -> persistentItem.click(player, itemStack, ClickType.DOUBLE_CLICK));
Expand All @@ -43,7 +43,7 @@ void testClearPersistentItem() {
// Clear previous
PersistentItem.clearPersistentItems();

PersistentItem persistentItem = new PersistentItem(Material.STONE);
PersistentItem persistentItem = PersistentItem.newItem(Material.STONE);
ItemStack itemStack = persistentItem.create();
PersistentItem.clearPersistentItems();

Expand All @@ -53,7 +53,7 @@ void testClearPersistentItem() {
@Test
void testGetPersistentItem() {
BukkitUtils.setupEnchantments();
PersistentItem expected = new PersistentItem(Material.DIAMOND_SWORD, 1)
PersistentItem expected = PersistentItem.newItem(Material.DIAMOND_SWORD, 1)
.addLore("Extremely deep lore").setDisplayName("Cool sword")
.addEnchantment("flame", 3).addItemFlags(ItemFlag.HIDE_ATTRIBUTES)
.setCustomModelData(3);
Expand All @@ -65,7 +65,7 @@ void testGetPersistentItem() {
@Test
void testInteract() {
AtomicBoolean value = new AtomicBoolean(false);
PersistentItem persistentItem = new PersistentItem().setMaterial("STONE")
PersistentItem persistentItem = PersistentItem.newItem().setMaterial("STONE")
.onInteract((i, p, a) -> value.set(true))
.onClick((i, p, a) -> value.set(false));
persistentItem.click(mock(Player.class), persistentItem.create(), ClickType.DOUBLE_CLICK);
Expand All @@ -77,7 +77,7 @@ void testInteract() {
@Test
void testClick() {
AtomicBoolean value = new AtomicBoolean(false);
PersistentItem persistentItem = new PersistentItem().setMaterial("STONE")
PersistentItem persistentItem = PersistentItem.newItem().setMaterial("STONE")
.onClick((i, p, a) -> value.set(true))
.onInteract((i, p, a) -> value.set(false));
persistentItem.interact(mock(Player.class), persistentItem.create(), Action.LEFT_CLICK_AIR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class PersistentListenerTest {
@BeforeAll
static void setAllUp() {
BukkitUtils.setupServer();
maintain = new PersistentItem(Material.DIAMOND_SWORD, 1).setDisplayName("Maintain").setDeathAction(DeathAction.MAINTAIN);
disappear = new PersistentItem(Material.IRON_SWORD, 1).setDisplayName("Disappear").setDeathAction(DeathAction.DISAPPEAR);
none = new PersistentItem(Material.STONE_SWORD, 1).setDisplayName("None").setDeathAction(null);
maintain = PersistentItem.newItem(Material.DIAMOND_SWORD, 1).setDisplayName("Maintain").setDeathAction(DeathAction.MAINTAIN);
disappear = PersistentItem.newItem(Material.IRON_SWORD, 1).setDisplayName("Disappear").setDeathAction(DeathAction.DISAPPEAR);
none = PersistentItem.newItem(Material.STONE_SWORD, 1).setDisplayName("None").setDeathAction(null);
listener = new PersistentListener();
}

Expand Down Expand Up @@ -149,7 +149,7 @@ void testClickPersistentItem() {
List<PersistentItem> items = new ArrayList<>();
for (int i = 0; i < itemSize; i++) {
int finalI = i;
items.add(new PersistentItem().setMaterial(Material.values()[13 + i]).onClick((p, s, c) -> clickedItems.add(finalI)));
items.add(PersistentItem.newItem().setMaterial(Material.values()[13 + i]).onClick((p, s, c) -> clickedItems.add(finalI)));
}
assertTrue(listener.clickPersistentItem(mock(Player.class), ClickType.DOUBLE_CLICK, null,
items.stream().map(BukkitItem::create).collect(Collectors.toList())), "Should have been true for found");
Expand All @@ -163,7 +163,7 @@ void testInteractPersistentItem() {
List<PersistentItem> items = new ArrayList<>();
for (int i = 0; i < itemSize; i++) {
int finalI = i;
items.add(new PersistentItem().setMaterial(Material.values()[3 + i]).onInteract((p, s, c) -> interactItems.add(finalI)));
items.add(PersistentItem.newItem().setMaterial(Material.values()[3 + i]).onInteract((p, s, c) -> interactItems.add(finalI)));
}
assertTrue(listener.interactPersistentItem(mock(Player.class), Action.LEFT_CLICK_AIR, null,
items.stream().map(BukkitItem::create).collect(Collectors.toList())), "Should have been true for found");
Expand Down Expand Up @@ -261,8 +261,8 @@ void simulateInventoryClick(InventoryClickEvent event) {

private Object[] notMovableItems() {
return new Object[]{
new PersistentItem(Material.IRON_HOE).setMobility(Mobility.INTERNAL),
new PersistentItem(Material.GOLDEN_HOE).setMobility(Mobility.STATIC)
PersistentItem.newItem(Material.IRON_HOE).setMobility(Mobility.INTERNAL),
PersistentItem.newItem(Material.GOLDEN_HOE).setMobility(Mobility.STATIC)
};
}

Expand Down Expand Up @@ -296,7 +296,7 @@ void testItemInsideShouldNotBeMoved(PersistentItem persistentItem) {

@Test
void testClickInBottomInventoryWithNoKeyPress() {
PersistentItem persistentItem = new PersistentItem(Material.ACACIA_BOAT);
PersistentItem persistentItem = PersistentItem.newItem(Material.ACACIA_BOAT);
InventoryView view = setupInventoryClickEventView();
int slot = view.getTopInventory().getSize();
view.getBottomInventory().setItem(0, persistentItem.create());
Expand Down

0 comments on commit 2ad40ae

Please sign in to comment.