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:
parent
4ab638814f
commit
158c6eea21
@ -91,7 +91,10 @@ public class PlayerProfile {
|
|||||||
* Only intended for internal usage.
|
* Only intended for internal usage.
|
||||||
*
|
*
|
||||||
* @return The {@link Config} associated with this {@link PlayerProfile}
|
* @return The {@link Config} associated with this {@link PlayerProfile}
|
||||||
|
*
|
||||||
|
* @deprecated Look at {@link PlayerProfile#getPlayerData()} instead for reading data.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public @Nonnull Config getConfig() {
|
public @Nonnull Config getConfig() {
|
||||||
return configFile;
|
return configFile;
|
||||||
}
|
}
|
||||||
@ -245,10 +248,9 @@ public class PlayerProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public @Nonnull PlayerBackpack createBackpack(int size) {
|
public @Nonnull PlayerBackpack createBackpack(int size) {
|
||||||
IntStream stream = IntStream.iterate(0, i -> i + 1).filter(i -> !configFile.contains("backpacks." + i + ".size"));
|
int nextId = this.data.getBackpacks().size(); // Size is not 0 indexed so next ID can just be the current size
|
||||||
int id = stream.findFirst().getAsInt();
|
|
||||||
|
|
||||||
PlayerBackpack backpack = PlayerBackpack.newBackpack(this.ownerId, id, size);
|
PlayerBackpack backpack = PlayerBackpack.newBackpack(this.ownerId, nextId, size);
|
||||||
this.data.addBackpack(backpack);
|
this.data.addBackpack(backpack);
|
||||||
|
|
||||||
markDirty();
|
markDirty();
|
||||||
|
@ -47,6 +47,21 @@ class TestPlayerBackpacks {
|
|||||||
Assertions.assertEquals(18, backpack.getInventory().getSize());
|
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
|
@Test
|
||||||
@DisplayName("Test upgrading the backpack size")
|
@DisplayName("Test upgrading the backpack size")
|
||||||
void testChangeSize() throws InterruptedException {
|
void testChangeSize() throws InterruptedException {
|
||||||
|
Loading…
Reference in New Issue
Block a user