- * Copyright (C) Kristian S. Strangeland
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package xyz.ineanto.nicko.packet.wrapper;
-
-import com.comphenix.protocol.PacketType;
-import com.comphenix.protocol.ProtocolLibrary;
-import com.comphenix.protocol.events.PacketContainer;
-import com.google.common.base.Objects;
-import org.bukkit.entity.Player;
-
-public abstract class AbstractPacket {
- protected PacketContainer handle;
-
- /**
- * Constructs a new strongly typed wrapper for the given packet.
- *
- * @param handle - handle to the raw packet data.
- * @param type - the packet type.
- */
- protected AbstractPacket(PacketContainer handle, PacketType type) {
- // Make sure we're given a valid packet
- if (handle == null)
- throw new IllegalArgumentException("Packet handle cannot be NULL.");
- if (!Objects.equal(handle.getType(), type))
- throw new IllegalArgumentException(handle.getHandle()
- + " is not a packet of type " + type);
-
- this.handle = handle;
- }
-
- /**
- * Retrieve a handle to the raw packet data.
- *
- * @return Raw packet data.
- */
- public PacketContainer getHandle() {
- return handle;
- }
-
- /**
- * Send the current packet to the given receiver.
- *
- * @param receiver - the receiver.
- * @throws RuntimeException If the packet cannot be sent.
- */
- public void sendPacket(Player receiver) {
- ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
- getHandle());
- }
-
- /**
- * Send the current packet to all online players.
- */
- public void broadcastPacket() {
- ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
- }
-}
\ No newline at end of file
diff --git a/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayServerEntityDestroy.java b/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayServerEntityDestroy.java
deleted file mode 100644
index a23f1a6..0000000
--- a/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayServerEntityDestroy.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package xyz.ineanto.nicko.packet.wrapper;
-
-import com.comphenix.protocol.PacketType;
-import com.comphenix.protocol.events.PacketContainer;
-import com.comphenix.protocol.wrappers.Converters;
-import it.unimi.dsi.fastutil.ints.IntList;
-
-/**
- * Sent by the server to the client to remove one or more entities.
- */
-public class WrapperPlayServerEntityDestroy extends AbstractPacket {
-
- /**
- * The packet type that is wrapped by this wrapper.
- */
- public static final PacketType TYPE = PacketType.Play.Server.ENTITY_DESTROY;
-
- public WrapperPlayServerEntityDestroy() {
- super(new PacketContainer(TYPE), TYPE);
- handle.getModifier().writeDefaults();
- }
-
- /**
- * Sets the list of entity ids to remove
- *
- * @param value New value for field 'entityIds'
- */
- public void setEntityIds(IntList value) {
- this.handle.getModifier().withType(IntList.class, Converters.passthrough(IntList.class)).writeSafely(0, value);
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayServerRespawn.java b/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayServerRespawn.java
deleted file mode 100644
index dc71b1f..0000000
--- a/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayServerRespawn.java
+++ /dev/null
@@ -1,115 +0,0 @@
-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.StructureModifier;
-import com.comphenix.protocol.utility.MinecraftVersion;
-import com.comphenix.protocol.wrappers.BukkitConverters;
-import com.comphenix.protocol.wrappers.EnumWrappers;
-import com.comphenix.protocol.wrappers.MinecraftKey;
-import com.google.common.hash.Hashing;
-import org.bukkit.Bukkit;
-import org.bukkit.GameMode;
-import org.bukkit.World;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.RecordComponent;
-
-/**
- * PacketPlayServerRespawn Wrapper class (1.20.X to 1.21.X)
- *
- * In 1.20.2, all the fields were merged inside a
- * single "CommonPlayerSpawnInfo" record.
- *
- * @author inenato (w/ additional help from lukalt), based on work from dmulloy2 and Kristian S. Strangeland
- */
-public class WrapperPlayServerRespawn extends AbstractPacket {
- public static final PacketType TYPE = PacketType.Play.Server.RESPAWN;
-
- private InternalStructure spawnInfoStructure = null;
-
- public WrapperPlayServerRespawn() {
- super(new PacketContainer(TYPE), TYPE);
- handle.getModifier().writeDefaults();
- if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
- spawnInfoStructure = handle.getStructures().read(0);
- }
- }
-
- public void setDimension(World value) {
- final MinecraftVersion v1_20_5 = new MinecraftVersion(1, 20, 5);
-
- if (!MinecraftVersion.getCurrentVersion().isAtLeast(v1_20_5)) {
- // 1.20 - 1.20.4
- final StructureModifier structureModifier = spawnInfoStructure == null ?
- handle.getStructures() : spawnInfoStructure.getStructures();
-
- final StructureModifier worldStructureModifier = spawnInfoStructure == null ?
- handle.getWorldKeys() : spawnInfoStructure.getWorldKeys();
-
- final InternalStructure dimensionType = structureModifier.read(0);
- dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type"));
- dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld"));
- structureModifier.writeSafely(0, dimensionType);
- worldStructureModifier.writeSafely(0, value);
- } 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 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) {
- throw new RuntimeException();
- }
- }
- }
-
- public void setGameMode(GameMode value) {
- if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
- // 1.20 to 1.20.1
- handle.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value));
- return;
- }
-
- spawnInfoStructure.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value));
- }
-
- public void setPreviousGameMode(GameMode value) {
- if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
- // 1.20 to 1.20.1
- handle.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value));
- return;
- }
-
- spawnInfoStructure.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value));
- }
-
- public void setCopyMetadata(boolean value) {
- if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) return;
-
- // 1.20 to 1.20.1
- handle.getBooleans().writeSafely(0, value);
- }
-
- public void setSeed(long value) {
- if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
- // 1.20 to 1.20.1
- handle.getLongs().writeSafely(0, Hashing.sha256().hashLong(value).asLong());
- }
- }
-}
diff --git a/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayServerSpawnEntity.java b/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayServerSpawnEntity.java
deleted file mode 100644
index 0512717..0000000
--- a/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayServerSpawnEntity.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package xyz.ineanto.nicko.packet.wrapper;
-
-import com.comphenix.protocol.PacketType;
-import com.comphenix.protocol.events.PacketContainer;
-import org.bukkit.Location;
-import org.bukkit.entity.EntityType;
-
-import javax.annotation.Nonnull;
-import java.util.UUID;
-
-/**
- * This packet is sent by the server when a player comes into visible range, not when a player joins.
- */
-public class WrapperPlayServerSpawnEntity extends AbstractPacket {
- /**
- * The packet type that is wrapped by this wrapper.
- */
- public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY;
-
- /**
- * Constructors a new wrapper for the specified packet
- */
- public WrapperPlayServerSpawnEntity() {
- super(new PacketContainer(TYPE), TYPE);
- handle.getModifier().writeDefaults();
- }
-
- /**
- * Sets the entity id of the player
- *
- * @param value New value for field 'entityId'
- */
- public void setEntityId(int value) {
- this.handle.getIntegers().writeSafely(0, value);
- this.handle.getEntityTypeModifier().writeSafely(0, EntityType.PLAYER);
- }
-
- /**
- * Sets the unique id of the player
- *
- * @param value New value for field 'playerId'
- */
- public void setPlayerId(UUID value) {
- this.handle.getUUIDs().writeSafely(0, value);
- }
-
- /**
- * Sets the value of field 'x'
- *
- * @param value New value for field 'x'
- */
- public void setX(double value) {
- this.handle.getDoubles().writeSafely(0, value);
- }
-
- /**
- * Sets the value of field 'y'
- *
- * @param value New value for field 'y'
- */
- public void setY(double value) {
- this.handle.getDoubles().writeSafely(1, value);
- }
-
- /**
- * Sets the value of field 'z'
- *
- * @param value New value for field 'z'
- */
- public void setZ(double value) {
- this.handle.getDoubles().write(2, value);
- }
-
- /**
- * Sets the discrete rotation around the y-axis (yaw)
- *
- * @param value New value for field 'yRot'
- */
- public void setYRotRaw(byte value) {
- this.handle.getBytes().writeSafely(0, value);
- }
-
- /**
- * Sets the discrete rotation around the x-axis (pitch)
- *
- * @param value New value for field 'xRot'
- */
- public void setXRotRaw(byte value) {
- this.handle.getBytes().writeSafely(1, value);
- }
-
- public void setLocation(@Nonnull Location location) {
- setX(location.getX());
- setY(location.getY());
- setZ(location.getZ());
- setYRotRaw(degreesToAngle(location.getYaw()));
- setXRotRaw(degreesToAngle(location.getPitch()));
- }
-
- private byte degreesToAngle(float degree) {
- return (byte)((int)(degree * 256.0F / 360.0F));
- }
-}
\ No newline at end of file
diff --git a/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayerServerPlayerInfo.java b/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayerServerPlayerInfo.java
deleted file mode 100644
index ca37dc0..0000000
--- a/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayerServerPlayerInfo.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package xyz.ineanto.nicko.packet.wrapper;
-
-import com.comphenix.protocol.PacketType;
-import com.comphenix.protocol.events.PacketContainer;
-import com.comphenix.protocol.utility.MinecraftVersion;
-import com.comphenix.protocol.wrappers.EnumWrappers;
-import com.comphenix.protocol.wrappers.PlayerInfoData;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * Up-to-date version of the Wrapper class
- * for the PlayerServerPlayerInfo.
- *
- * @author ineanto, based on work from dmulloy2 and Kristian S. Strangeland
- */
-public class WrapperPlayerServerPlayerInfo extends AbstractPacket {
- public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO;
-
- public WrapperPlayerServerPlayerInfo() {
- super(new PacketContainer(TYPE), TYPE);
- handle.getModifier().writeDefaults();
- }
-
- public void setActions(Set value) {
- if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
- handle.getPlayerInfoActions().writeSafely(0, value);
- } else {
- handle.getPlayerInfoAction().writeSafely(0, value.stream().iterator().next()); // Get the first Value.
- }
- }
-
- public void setData(List value) {
- handle.getPlayerInfoDataLists().writeSafely(1, value);
- }
-}
diff --git a/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayerServerPlayerInfoRemove.java b/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayerServerPlayerInfoRemove.java
deleted file mode 100644
index 2273c48..0000000
--- a/src/main/java/xyz/ineanto/nicko/packet/wrapper/WrapperPlayerServerPlayerInfoRemove.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package xyz.ineanto.nicko.packet.wrapper;
-
-import com.comphenix.protocol.PacketType;
-import com.comphenix.protocol.events.PacketContainer;
-
-import java.util.List;
-import java.util.UUID;
-
-/**
- * Up-to-date version of the Wrapper class
- * for the PlayerServerPlayerInfoRemove.
- *
- * @author ineanto, based on work from dmulloy2 and Kristian S. Strangeland
- */
-
-public class WrapperPlayerServerPlayerInfoRemove extends AbstractPacket {
- public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO_REMOVE;
-
- public WrapperPlayerServerPlayerInfoRemove() {
- super(new PacketContainer(TYPE), TYPE);
- handle.getModifier().writeDefaults();
- }
-
- public void setUUIDs(List value) {
- handle.getUUIDLists().writeSafely(0, value);
- }
-}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/paper-plugin.yml
similarity index 56%
rename from src/main/resources/plugin.yml
rename to src/main/resources/paper-plugin.yml
index 08b70ce..89bfa52 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/paper-plugin.yml
@@ -1,17 +1,13 @@
name: Nicko
main: xyz.ineanto.nicko.Nicko
+loader: xyz.ineanto.nicko.loader.NickoLibraryLoader
version: ${version}
-author: Ineanto
+authors: [ Ineanto ]
description: "The feature packed, next generation disguise plugin for Minecraft."
-api-version: 1.21
-softdepend: [ PlaceholderAPI ]
-depend:
- - ProtocolLib
-load: POSTWORLD
-commands:
- nicko:
- description: "Opens Nicko's GUI."
- permission: nicko.use
+api-version: "1.20"
+dependencies:
+ server:
+ { "ProtocolLib" }
permissions:
nicko.*:
default: op
diff --git a/src/test/java/xyz/ineanto/nicko/test/NickoPluginTest.java b/src/test/java/xyz/ineanto/nicko/test/NickoPluginTest.java
deleted file mode 100644
index 5ce3aea..0000000
--- a/src/test/java/xyz/ineanto/nicko/test/NickoPluginTest.java
+++ /dev/null
@@ -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();
- }
-}
diff --git a/src/test/java/xyz/ineanto/nicko/test/appearance/RandomNameTest.java b/src/test/java/xyz/ineanto/nicko/test/appearance/RandomNameTest.java
deleted file mode 100644
index 057c076..0000000
--- a/src/test/java/xyz/ineanto/nicko/test/appearance/RandomNameTest.java
+++ /dev/null
@@ -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();
- }
-}
diff --git a/src/test/java/xyz/ineanto/nicko/test/config/ConfigurationTest.java b/src/test/java/xyz/ineanto/nicko/test/config/ConfigurationTest.java
deleted file mode 100644
index 4a371fa..0000000
--- a/src/test/java/xyz/ineanto/nicko/test/config/ConfigurationTest.java
+++ /dev/null
@@ -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();
- }
-}
diff --git a/src/test/java/xyz/ineanto/nicko/test/config/ConfigurationVersionTest.java b/src/test/java/xyz/ineanto/nicko/test/config/ConfigurationVersionTest.java
deleted file mode 100644
index d13fa80..0000000
--- a/src/test/java/xyz/ineanto/nicko/test/config/ConfigurationVersionTest.java
+++ /dev/null
@@ -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();
- }
-}
diff --git a/src/test/java/xyz/ineanto/nicko/test/i18n/ItemTranslationTest.java b/src/test/java/xyz/ineanto/nicko/test/i18n/ItemTranslationTest.java
deleted file mode 100644
index 3c17c5d..0000000
--- a/src/test/java/xyz/ineanto/nicko/test/i18n/ItemTranslationTest.java
+++ /dev/null
@@ -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: 1", translation.lore().get(0));
- assertEquals("Nb. de skin dans le cache: 1", translation.lore().get(1));
- assertEquals("Le cache est vidé toutes les 24 heures.", translation.lore().get(2));
- }
-
- @AfterAll
- public static void shutdown() {
- MockBukkit.unmock();
- }
-}
diff --git a/src/test/java/xyz/ineanto/nicko/test/i18n/TranslationTest.java b/src/test/java/xyz/ineanto/nicko/test/i18n/TranslationTest.java
deleted file mode 100644
index bac0c45..0000000
--- a/src/test/java/xyz/ineanto/nicko/test/i18n/TranslationTest.java
+++ /dev/null
@@ -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();
- }
-}
diff --git a/src/test/java/xyz/ineanto/nicko/test/migration/MigrationTest.java b/src/test/java/xyz/ineanto/nicko/test/migration/MigrationTest.java
deleted file mode 100644
index 170f367..0000000
--- a/src/test/java/xyz/ineanto/nicko/test/migration/MigrationTest.java
+++ /dev/null
@@ -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();
- }
-}
diff --git a/src/test/java/xyz/ineanto/nicko/test/storage/MapCacheTest.java b/src/test/java/xyz/ineanto/nicko/test/storage/MapCacheTest.java
deleted file mode 100644
index 2cc8ca7..0000000
--- a/src/test/java/xyz/ineanto/nicko/test/storage/MapCacheTest.java
+++ /dev/null
@@ -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 optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
- assertTrue(optionalProfile.isPresent());
- assertTrue(plugin.getDataStore().getCache().isCached(player.getUniqueId()));
- }
-
- @AfterAll
- public static void shutdown() {
- MockBukkit.unmock();
- }
-}
diff --git a/src/test/java/xyz/ineanto/nicko/test/storage/RedisCacheTest.java b/src/test/java/xyz/ineanto/nicko/test/storage/RedisCacheTest.java
deleted file mode 100644
index a5ce971..0000000
--- a/src/test/java/xyz/ineanto/nicko/test/storage/RedisCacheTest.java
+++ /dev/null
@@ -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 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 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 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();
- }
-}
diff --git a/src/test/java/xyz/ineanto/nicko/test/storage/SQLStorageTest.java b/src/test/java/xyz/ineanto/nicko/test/storage/SQLStorageTest.java
deleted file mode 100644
index 0bd04ba..0000000
--- a/src/test/java/xyz/ineanto/nicko/test/storage/SQLStorageTest.java
+++ /dev/null
@@ -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 optionalProfile = NickoProfile.get(uuid);
- assertTrue(optionalProfile.isPresent());
- }
-
- @Test
- @DisplayName("Update profile")
- @Order(3)
- public void updateProfile() {
- final Optional 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 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();
- }
-}
\ No newline at end of file