1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Fix backpack IDs not incrementing (#4081)

This commit is contained in:
Daniel Walsh 2024-01-07 09:19:51 +00:00 committed by GitHub
parent 4ab638814f
commit 158c6eea21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -91,7 +91,10 @@ public class PlayerProfile {
* Only intended for internal usage.
*
* @return The {@link Config} associated with this {@link PlayerProfile}
*
* @deprecated Look at {@link PlayerProfile#getPlayerData()} instead for reading data.
*/
@Deprecated
public @Nonnull Config getConfig() {
return configFile;
}
@ -245,10 +248,9 @@ public class PlayerProfile {
}
public @Nonnull PlayerBackpack createBackpack(int size) {
IntStream stream = IntStream.iterate(0, i -> i + 1).filter(i -> !configFile.contains("backpacks." + i + ".size"));
int id = stream.findFirst().getAsInt();
int nextId = this.data.getBackpacks().size(); // Size is not 0 indexed so next ID can just be the current size
PlayerBackpack backpack = PlayerBackpack.newBackpack(this.ownerId, id, size);
PlayerBackpack backpack = PlayerBackpack.newBackpack(this.ownerId, nextId, size);
this.data.addBackpack(backpack);
markDirty();

View File

@ -47,6 +47,21 @@ class TestPlayerBackpacks {
Assertions.assertEquals(18, backpack.getInventory().getSize());
}
@Test
@DisplayName("Test creating a new backpack will increment the id")
void testCreateBackpackIncrementsId() throws InterruptedException {
Player player = server.addPlayer();
PlayerProfile profile = TestUtilities.awaitProfile(player);
PlayerBackpack backpackOne = profile.createBackpack(18);
PlayerBackpack backpackTwo = profile.createBackpack(18);
PlayerBackpack backpackThree = profile.createBackpack(18);
Assertions.assertEquals(0, backpackOne.getId());
Assertions.assertEquals(1, backpackTwo.getId());
Assertions.assertEquals(2, backpackThree.getId());
}
@Test
@DisplayName("Test upgrading the backpack size")
void testChangeSize() throws InterruptedException {