Merge pull request #30 from SunNetservers/dev

Arena saving bugfix
This commit is contained in:
Kristian Knarvik 2024-04-04 03:07:30 +02:00 committed by GitHub
commit 09f29e5f67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 56 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.knarcraft</groupId>
<artifactId>MiniGames</artifactId>
<version>1.1</version>
<version>1.2</version>
<packaging>jar</packaging>
<name>MiniGames</name>

View File

@ -109,8 +109,11 @@ public final class DropperArenaStorageHelper {
* @throws IOException <p>If unable to write to the file</p>
*/
public static void saveSingleDropperArena(DropperArena arena) throws IOException {
YamlConfiguration configuration = new YamlConfiguration();
ConfigurationSection arenaSection = configuration.createSection(dropperArenasConfigurationSection);
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(dropperArenaFile);
ConfigurationSection arenaSection = configuration.getConfigurationSection(dropperArenasConfigurationSection);
if (arenaSection == null) {
arenaSection = configuration.createSection(dropperArenasConfigurationSection);
}
saveDropperArena(arenaSection, arena);
configuration.save(dropperArenaFile);
}

View File

@ -111,8 +111,11 @@ public final class ParkourArenaStorageHelper {
* @throws IOException <p>If unable to write to the file</p>
*/
public static void saveSingleParkourArena(ParkourArena arena) throws IOException {
YamlConfiguration configuration = new YamlConfiguration();
ConfigurationSection arenaSection = configuration.createSection(parkourArenasConfigurationSection);
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(parkourArenaFile);
ConfigurationSection arenaSection = configuration.getConfigurationSection(parkourArenasConfigurationSection);
if (arenaSection == null) {
arenaSection = configuration.createSection(parkourArenasConfigurationSection);
}
saveParkourArena(arenaSection, arena);
configuration.save(parkourArenaFile);
}

View File

@ -1,51 +0,0 @@
package net.knarcraft.minigames.arena;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Tests for arena dropper groups
*/
public class MiniGamesArenaGroupTest {
@Test
public void swapTest() {
/*
This test makes sure the order of arenas is as expected when the arenas are added to a group. It also makes
sure that swapping two items works as expected.
*/
DropperArenaGroup arenaGroup = new DropperArenaGroup("test");
UUID arena1Id = UUID.randomUUID();
UUID arena2Id = UUID.randomUUID();
UUID arena3Id = UUID.randomUUID();
UUID arena4Id = UUID.randomUUID();
arenaGroup.addArena(arena1Id);
arenaGroup.addArena(arena2Id);
arenaGroup.addArena(arena3Id);
arenaGroup.addArena(arena4Id);
List<UUID> initialOrder = new ArrayList<>();
initialOrder.add(arena1Id);
initialOrder.add(arena2Id);
initialOrder.add(arena3Id);
initialOrder.add(arena4Id);
Assertions.assertEquals(initialOrder, arenaGroup.getArenas());
arenaGroup.swapArenas(1, 3);
List<UUID> swapped = new ArrayList<>();
swapped.add(arena1Id);
swapped.add(arena4Id);
swapped.add(arena3Id);
swapped.add(arena2Id);
Assertions.assertEquals(swapped, arenaGroup.getArenas());
}
}