feat: switch to paperweight and create plugin loader
This commit is contained in:
parent
ff892a7451
commit
a996858ba9
20 changed files with 155 additions and 680 deletions
|
@ -0,0 +1,20 @@
|
|||
package xyz.ineanto.nicko.loader;
|
||||
|
||||
import io.papermc.paper.plugin.loader.PluginClasspathBuilder;
|
||||
import io.papermc.paper.plugin.loader.PluginLoader;
|
||||
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||
import org.eclipse.aether.repository.RemoteRepository;
|
||||
|
||||
public class NickoPluginLoader implements PluginLoader {
|
||||
@Override
|
||||
public void classloader(PluginClasspathBuilder pluginClasspathBuilder) {
|
||||
final MavenLibraryResolver resolver = new MavenLibraryResolver();
|
||||
resolver.addRepository(new RemoteRepository.Builder("xenondevs", "default", "https://repo.xenondevs.xyz/releases/").build());
|
||||
resolver.addRepository(new RemoteRepository.Builder("wesjd", "default", "https://repo.codemc.io/repository/maven-snapshots/").build());
|
||||
resolver.addDependency(new Dependency(new DefaultArtifact("xyz.xenondevs.invui:invui:pom:1.44"), null));
|
||||
resolver.addDependency(new Dependency(new DefaultArtifact("net:wesjd:anvilgui:1.10.4-SNAPSHOT"), null));
|
||||
pluginClasspathBuilder.addLibrary(resolver);
|
||||
}
|
||||
}
|
|
@ -149,6 +149,7 @@ public class InternalPacketSender implements PacketSender {
|
|||
serverPlayer.connection.latency(),
|
||||
serverPlayer.gameMode.getGameModeForPlayer(),
|
||||
MutableComponent.create(new PlainTextContents.LiteralContents(displayName)),
|
||||
true,
|
||||
serverPlayer.getTabListOrder(),
|
||||
Optionull.map(serverPlayer.getChatSession(), RemoteChatSession::asData)
|
||||
));
|
||||
|
@ -165,4 +166,4 @@ public class InternalPacketSender implements PacketSender {
|
|||
private void sendPacket(Packet<?> packet, Player player) {
|
||||
(((CraftPlayer) player).getHandle()).connection.send(packet);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,11 @@ package xyz.ineanto.nicko.packet.wrapper;
|
|||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.InternalStructure;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.wrappers.BukkitConverters;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
|
@ -13,8 +17,11 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.GameMode;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.RecordComponent;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* PacketPlayServerRespawn Wrapper class (1.20.X to 1.21.X)
|
||||
|
@ -56,24 +63,49 @@ public class WrapperPlayServerRespawn extends AbstractPacket {
|
|||
} else {
|
||||
// 1.20.5 to 1.21.1
|
||||
|
||||
/*
|
||||
Honestly, I've tried everything to make this work.
|
||||
Fields inside the CommonPlayerSpawnInfo are Record Components and are
|
||||
marked final.
|
||||
|
||||
This would work with some trickery involved, but here's the
|
||||
caveat: Record Components/Fields and are immutable by DESIGN.
|
||||
So... here we are now, stopped right in my track by Java's language design and Mojang themselves.
|
||||
*/
|
||||
|
||||
try {
|
||||
final Object spawnInfoStructureHandle = spawnInfoStructure.getHandle();
|
||||
final RecordComponent[] components = spawnInfoStructureHandle.getClass().getRecordComponents();
|
||||
final Class<?> spawnInfoClass = MinecraftReflection.getMinecraftClass("network.protocol.game.CommonPlayerSpawnInfo");
|
||||
|
||||
final Field levelKeyField = spawnInfoStructureHandle.getClass().getDeclaredField(components[1].getAccessor().getName());
|
||||
levelKeyField.setAccessible(true);
|
||||
levelKeyField.set(spawnInfoStructureHandle, BukkitConverters.getWorldKeyConverter().getGeneric(Bukkit.getWorld("world")));
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
Class<?>[] componentTypes = Arrays.stream(spawnInfoClass.getRecordComponents())
|
||||
.map(RecordComponent::getType)
|
||||
.toArray(Class<?>[]::new);
|
||||
final Constructor<?> spawnInfoConstructor = spawnInfoClass.getDeclaredConstructor(componentTypes);
|
||||
|
||||
/**
|
||||
* Holder<DimensionType> dimensionType,
|
||||
* ResourceKey<Level> dimension,
|
||||
* long seed,
|
||||
* GameType gameType,
|
||||
* GameType previousGameType,
|
||||
* boolean isDebug,
|
||||
* boolean isFlat,
|
||||
* Optional<GlobalPos> lastDeathLocation,
|
||||
* int portalCooldown
|
||||
*/
|
||||
|
||||
final World world = Bukkit.getWorld("world");
|
||||
|
||||
FuzzyReflection.fromClass(spawnInfoClass).getConstructor(
|
||||
FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.build()
|
||||
);
|
||||
|
||||
final Object spawnInfo = spawnInfoConstructor.newInstance(
|
||||
BukkitConverters.getDimensionConverter().getGeneric(world),
|
||||
BukkitConverters.getWorldKeyConverter().getGeneric(world),
|
||||
world.getSeed(),
|
||||
EnumWrappers.getGameModeConverter().getGeneric(EnumWrappers.NativeGameMode.fromBukkit(GameMode.SURVIVAL)),
|
||||
EnumWrappers.getGameModeConverter().getGeneric(EnumWrappers.NativeGameMode.fromBukkit(GameMode.SURVIVAL)),
|
||||
false,
|
||||
false,
|
||||
BukkitConverters.getSectionPositionConverter()
|
||||
);
|
||||
|
||||
final Field commonSpawnDataField = Accessors.getFieldAccessor(TYPE.getPacketClass(), spawnInfoClass, true).getField();
|
||||
commonSpawnDataField.set(spawnInfoStructure.getHandle(), spawnInfo);
|
||||
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException |
|
||||
InstantiationException e) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package xyz.ineanto.nicko.test;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class NickoPluginTest {
|
||||
private static Nicko plugin;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
MockBukkit.mock();
|
||||
plugin = MockBukkit.load(Nicko.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Plugin Initialization")
|
||||
public void initializePlugin() {
|
||||
assertNotNull(plugin);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package xyz.ineanto.nicko.test.appearance;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.random.RandomNameFetcher;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.mojang.MojangUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class RandomNameTest {
|
||||
private static Nicko plugin;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
MockBukkit.mock();
|
||||
plugin = MockBukkit.load(Nicko.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Get random name")
|
||||
public void getRandomName() {
|
||||
final RandomNameFetcher randomNameFetcher = new RandomNameFetcher(plugin);
|
||||
final String username = randomNameFetcher.getRandomUsername();
|
||||
assertNotNull(username);
|
||||
assertFalse(MojangUtils.isUsernameInvalid(username));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package xyz.ineanto.nicko.test.config;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
public class ConfigurationTest {
|
||||
private static Nicko plugin;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
MockBukkit.mock();
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
plugin = MockBukkit.load(Nicko.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Read configuration")
|
||||
public void readConfiguration() {
|
||||
final Configuration configuration = plugin.getNickoConfig();
|
||||
assertFalse(configuration.getSqlConfiguration().isEnabled());
|
||||
assertFalse(configuration.getRedisConfiguration().isEnabled());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package xyz.ineanto.nicko.test.config;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.config.DefaultDataSources;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ConfigurationVersionTest {
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
MockBukkit.mock();
|
||||
final Configuration configuration = Configuration.DEFAULT;
|
||||
MockBukkit.load(Nicko.class, configuration);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Compare configuration version")
|
||||
public void compareConfigurationVersion() {
|
||||
final Configuration configuration = Configuration.DEFAULT;
|
||||
assertEquals(configuration.getVersionObject().compareTo(Configuration.VERSION), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Compare newer configuration version")
|
||||
public void compareNewerConfigurationVersion() {
|
||||
final Configuration configuration = new Configuration("24.1.0",
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
false);
|
||||
assertEquals(configuration.getVersionObject().compareTo(Configuration.VERSION), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Compare older configuration version")
|
||||
public void compareOlderConfigurationVersion() {
|
||||
final Configuration configuration = new Configuration("0.23.3",
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
false);
|
||||
assertEquals(configuration.getVersionObject().compareTo(Configuration.VERSION), -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Compare unknown configuration version")
|
||||
public void compareUnknownConfigurationVersion() {
|
||||
final Configuration configuration = new Configuration(null,
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
false);
|
||||
assertEquals(configuration.getVersionObject().compareTo(Configuration.VERSION), -1);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package xyz.ineanto.nicko.test.i18n;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.language.Translation;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ItemTranslationTest {
|
||||
private static PlayerMock player;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
MockBukkit.mock();
|
||||
MockBukkit.load(Nicko.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Translate Item Without Lore")
|
||||
public void translateItemTranslationWithoutLore() {
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(Language.FRENCH);
|
||||
final Translation translation = playerLanguage.translateAndReplace(LanguageKey.GUI.GO_BACK);
|
||||
assertTrue(translation.lore().isEmpty());
|
||||
assertEquals(translation.name(), "Retour");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Translate Item")
|
||||
public void translateItemLore() {
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(Language.FRENCH);
|
||||
|
||||
final Translation test = playerLanguage.translateAndReplace(LanguageKey.GUI.Settings.TOGGLEABLE_BUTTON, "EST", "EST");
|
||||
test.lore().forEach(System.out::println);
|
||||
|
||||
final Translation translation = playerLanguage.translateAndReplace(LanguageKey.GUI.Admin.Cache.STATISTICS, "1", "1");
|
||||
assertFalse(translation.lore().isEmpty());
|
||||
assertEquals("Nombre de requêtes: <aqua>1</aqua>", translation.lore().get(0));
|
||||
assertEquals("Nb. de skin dans le cache: <aqua>1</aqua>", translation.lore().get(1));
|
||||
assertEquals("<dark_gray><i>Le cache est vidé toutes les 24 heures.</i></dark_gray>", translation.lore().get(2));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package xyz.ineanto.nicko.test.i18n;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TranslationTest {
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
MockBukkit.mock();
|
||||
MockBukkit.load(Nicko.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Translate Line With Replacement")
|
||||
public void translateItemTranslationWithoutLore() {
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(Language.FRENCH);
|
||||
final String translation = playerLanguage.translate(LanguageKey.Event.Settings.ERROR, false, "Test");
|
||||
assertEquals("§cImpossible de mettre à jour vos paramètres. §7§o(Test)", translation);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package xyz.ineanto.nicko.test.migration;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.config.DefaultDataSources;
|
||||
import xyz.ineanto.nicko.language.CustomLanguage;
|
||||
import xyz.ineanto.nicko.migration.CustomLocaleMigrator;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class MigrationTest {
|
||||
private static Nicko plugin;
|
||||
|
||||
private static File folder;
|
||||
private static File localeFile;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() throws IOException {
|
||||
MockBukkit.mock();
|
||||
final Configuration configuration = new Configuration(Configuration.VERSION.toString(),
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
true);
|
||||
plugin = MockBukkit.load(Nicko.class, configuration);
|
||||
folder = new File(plugin.getDataFolder(), "/locale/");
|
||||
localeFile = new File(folder, "locale.yml");
|
||||
folder.mkdirs();
|
||||
localeFile.createNewFile();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLanguageFileMigration() throws IOException {
|
||||
final String content = """
|
||||
# Nicko - Language File:
|
||||
|
||||
# hello I'm the invalid version
|
||||
version: "1.0.0"
|
||||
""";
|
||||
|
||||
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(localeFile));
|
||||
outputStream.write(content.getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
|
||||
// Get wrong locale
|
||||
final CustomLanguage customLanguageBeforeMigration = new CustomLanguage();
|
||||
assertEquals(customLanguageBeforeMigration.getVersion(), "1.0.0");
|
||||
|
||||
// Migrate the wrong locale to the correct one
|
||||
final CustomLocaleMigrator localeMigrator = new CustomLocaleMigrator(plugin, customLanguageBeforeMigration);
|
||||
localeMigrator.migrate();
|
||||
|
||||
// Get the migrated locale
|
||||
final CustomLanguage customLanguageMigrated = new CustomLanguage();
|
||||
assertEquals(customLanguageMigrated.getVersion(), "1.1.0");
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
MockBukkit.unmock();
|
||||
folder.delete();
|
||||
localeFile.delete();
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package xyz.ineanto.nicko.test.storage;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class MapCacheTest {
|
||||
private static Nicko plugin;
|
||||
private static PlayerMock player;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
final ServerMock server = MockBukkit.mock();
|
||||
plugin = MockBukkit.load(Nicko.class, config);
|
||||
player = server.addPlayer();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Cache Player Data")
|
||||
public void cachePlayerData() {
|
||||
final Optional<NickoProfile> optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
|
||||
assertTrue(optionalProfile.isPresent());
|
||||
assertTrue(plugin.getDataStore().getCache().isCached(player.getUniqueId()));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package xyz.ineanto.nicko.test.storage;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.jupiter.api.*;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.config.DataSourceConfiguration;
|
||||
import xyz.ineanto.nicko.config.DefaultDataSources;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.ineanto.nicko.storage.PlayerDataStore;
|
||||
import xyz.ineanto.nicko.storage.redis.RedisCacheProvider;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class RedisCacheTest {
|
||||
private static Nicko plugin;
|
||||
private static PlayerMock player;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final Configuration config = new Configuration(
|
||||
"",
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
new DataSourceConfiguration(true, "127.0.0.1", 6379, "", ""),
|
||||
false);
|
||||
final ServerMock server = MockBukkit.mock();
|
||||
plugin = MockBukkit.load(Nicko.class, config);
|
||||
player = server.addPlayer();
|
||||
assertInstanceOf(RedisCacheProvider.class, plugin.getDataStore().getCache().getProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Cache Profile")
|
||||
@Order(1)
|
||||
public void cacheProfile() {
|
||||
final Optional<NickoProfile> optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
|
||||
assertTrue(optionalProfile.isPresent());
|
||||
assertTrue(plugin.getDataStore().getCache().isCached(player.getUniqueId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Update Cache Profile")
|
||||
@Order(2)
|
||||
public void updateCache() {
|
||||
final Optional<NickoProfile> optionalProfile = NickoProfile.get(player);
|
||||
assertTrue(optionalProfile.isPresent());
|
||||
|
||||
final NickoProfile profile = optionalProfile.get();
|
||||
final PlayerDataStore dataStore = plugin.getDataStore();
|
||||
profile.setName("Notch");
|
||||
dataStore.updateCache(player.getUniqueId(), profile);
|
||||
|
||||
final Optional<NickoProfile> retrieve = dataStore.getCache().retrieve(player.getUniqueId());
|
||||
assertTrue(retrieve.isPresent());
|
||||
final NickoProfile retrieved = retrieve.get();
|
||||
assertEquals(retrieved.getName(), "Notch");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Delete Cache Profile")
|
||||
@Order(3)
|
||||
public void deleteCache() {
|
||||
final PlayerDataStore dataStore = plugin.getDataStore();
|
||||
final ActionResult cacheDelete = dataStore.getCache().delete(player.getUniqueId());
|
||||
assertFalse(cacheDelete.isError());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
package xyz.ineanto.nicko.test.storage;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import org.junit.jupiter.api.*;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.config.DefaultDataSources;
|
||||
import xyz.ineanto.nicko.config.SQLDataSourceConfiguration;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.ineanto.nicko.storage.PlayerDataStore;
|
||||
import xyz.ineanto.nicko.storage.mariadb.MariaDBStorageProvider;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class SQLStorageTest {
|
||||
private static PlayerDataStore dataStore;
|
||||
private static UUID uuid;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final Configuration config = new Configuration(
|
||||
"",
|
||||
new SQLDataSourceConfiguration(true, "127.0.0.1", 3306, "root", "12345", true),
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
false);
|
||||
|
||||
MockBukkit.mock();
|
||||
|
||||
final Nicko plugin = MockBukkit.load(Nicko.class, config);
|
||||
dataStore = plugin.getDataStore();
|
||||
uuid = UUID.randomUUID();
|
||||
assertInstanceOf(MariaDBStorageProvider.class, dataStore.getStorage().getProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Create tables")
|
||||
@Order(1)
|
||||
public void createTables() {
|
||||
assertFalse(dataStore.getStorage().isError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Store empty profile")
|
||||
@Order(2)
|
||||
public void storeEmptyProfile() {
|
||||
final Optional<NickoProfile> optionalProfile = NickoProfile.get(uuid);
|
||||
assertTrue(optionalProfile.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Update profile")
|
||||
@Order(3)
|
||||
public void updateProfile() {
|
||||
final Optional<NickoProfile> optionalProfile = NickoProfile.get(uuid);
|
||||
assertTrue(optionalProfile.isPresent());
|
||||
|
||||
final NickoProfile profile = optionalProfile.get();
|
||||
assertNull(profile.getName());
|
||||
assertNull(profile.getSkin());
|
||||
assertEquals(profile.getLocale(), Language.ENGLISH);
|
||||
assertTrue(profile.isRandomSkin());
|
||||
|
||||
profile.setName("Notch");
|
||||
profile.setSkin("Notch");
|
||||
profile.setLocale(Language.FRENCH);
|
||||
profile.setRandomSkin(false);
|
||||
|
||||
final ActionResult result = dataStore.getStorage().store(uuid, profile);
|
||||
assertFalse(result.isError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Get updated profile")
|
||||
@Order(4)
|
||||
public void hasProfileBeenUpdated() {
|
||||
final Optional<NickoProfile> optionalProfile = NickoProfile.get(uuid);
|
||||
assertTrue(optionalProfile.isPresent());
|
||||
|
||||
final NickoProfile updatedProfile = optionalProfile.get();
|
||||
assertEquals(updatedProfile.getName(), "Notch");
|
||||
assertEquals(updatedProfile.getSkin(), "Notch");
|
||||
assertEquals(updatedProfile.getLocale(), Language.FRENCH);
|
||||
assertFalse(updatedProfile.isRandomSkin());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Delete profile")
|
||||
@Order(5)
|
||||
public void deleteProfile() {
|
||||
final ActionResult sqlDelete = dataStore.getStorage().delete(uuid);
|
||||
assertFalse(sqlDelete.isError());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue