retrieve(UUID uuid) {
try (Jedis jedis = provider.getJedis()) {
// 08/29/23: what the fuck was I talking about?
- // TODO (Ineanto, 05/20/23): Check if cached before because Jedis returns a bulk reply so this is unsafe
+ // old_todo (Ineanto, 05/20/23): Check if cached before because Jedis returns a bulk reply so this is unsafe
final String data = jedis.get("nicko:" + uuid.toString());
final NickoProfile profile = gson.fromJson(data, NickoProfile.class);
return Optional.of(profile);
diff --git a/src/main/java/xyz/ineanto/nicko/wrapper/AbstractPacket.java b/src/main/java/xyz/ineanto/nicko/wrapper/AbstractPacket.java
index 57b8598..1d90240 100644
--- a/src/main/java/xyz/ineanto/nicko/wrapper/AbstractPacket.java
+++ b/src/main/java/xyz/ineanto/nicko/wrapper/AbstractPacket.java
@@ -70,19 +70,4 @@ public abstract class AbstractPacket {
public void broadcastPacket() {
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
}
-
- /**
- * Simulate receiving the current packet from the given sender.
- *
- * @param sender - the sender.
- * @throws RuntimeException if the packet cannot be received.
- */
- public void receivePacket(Player sender) {
- try {
- ProtocolLibrary.getProtocolManager().receiveClientPacket(sender,
- getHandle());
- } catch (Exception e) {
- throw new RuntimeException("Cannot receive packet.", e);
- }
- }
}
\ No newline at end of file
diff --git a/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerEntityDestroy.java b/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerEntityDestroy.java
index 1af54f7..bc94876 100644
--- a/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerEntityDestroy.java
+++ b/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerEntityDestroy.java
@@ -20,15 +20,6 @@ public class WrapperPlayServerEntityDestroy extends AbstractPacket {
handle.getModifier().writeDefaults();
}
- /**
- * Gets a list of entity ids to remove
- *
- * @return 'entityIds' to remove
- */
- public IntList getEntityIds() {
- return this.handle.getModifier().withType(IntList.class, Converters.passthrough(IntList.class)).read(0);
- }
-
/**
* Sets the list of entity ids to remove
*
diff --git a/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerRespawn.java b/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerRespawn.java
index 9082ad1..18aea0f 100644
--- a/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerRespawn.java
+++ b/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerRespawn.java
@@ -3,37 +3,21 @@ package xyz.ineanto.nicko.wrapper;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.InternalStructure;
import com.comphenix.protocol.events.PacketContainer;
-import com.comphenix.protocol.utility.MinecraftReflection;
+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.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.World;
/**
- * Up-to-date version of the Wrapper class
- * for the PacketPlayServerRespawn.
+ * PacketPlayServerRespawn Wrapper class (1.19 to 1.20.2)
*
* @author ineanto, based on work from dmulloy2 and Kristian S. Strangeland
*
- *
- * Packet changes history (not accurate)
- *
* In 1.20.2, all the fields were replaced with a
* single "CommonPlayerSpawnInfo" record object.
- *
- * The dimension field was changed numerous times:
- * - 1.8 through 1.17 (?) required an integer,
- * - 1.18 need an instance of a Holder of a ResourceKey,
- * - 1.19 and after dropped this requirement.
- * N.b.: this field is a nightmare please mojang stop refactoring
- * your code to change things that were working perfectly fine before
- *
- * The Seed field was added in 1.15.
- * The Difficulty field was removed in 1.14.
*/
public class WrapperPlayServerRespawn extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.RESPAWN;
@@ -51,28 +35,10 @@ public class WrapperPlayServerRespawn extends AbstractPacket {
public void setDimension(World value) {
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
// 1.20.2
- final InternalStructure dimensionType = commonPlayerSpawnInfoStructure.getStructures().read(0);
- dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type"));
- dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld"));
- commonPlayerSpawnInfoStructure.getStructures().writeSafely(0, dimensionType);
- commonPlayerSpawnInfoStructure.getWorldKeys().writeSafely(0, value);
+ writeDimensionToStructure(value, commonPlayerSpawnInfoStructure.getStructures(), commonPlayerSpawnInfoStructure.getWorldKeys());
} else if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
- // 1.19 to 1.20.1
- // Thank you lukalt!
- final InternalStructure dimensionType = handle.getStructures().read(0);
- dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type"));
- dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld"));
- handle.getStructures().writeSafely(0, dimensionType);
- handle.getWorldKeys().writeSafely(0, value);
- } else if (MinecraftVersion.CAVES_CLIFFS_2.atOrAbove()) {
- // 1.18
- handle.getHolders(
- MinecraftReflection.getDimensionManager(),
- BukkitConverters.getDimensionConverter()
- ).writeSafely(0, value);
- } else {
- // 1.17 and below (untested)
- handle.getDimensions().writeSafely(0, value.getEnvironment().ordinal());
+ // 1.19 to 1.20.1, props to lukalt for helping me figure this out.
+ writeDimensionToStructure(value, handle.getStructures(), handle.getWorldKeys());
}
}
@@ -81,7 +47,6 @@ public class WrapperPlayServerRespawn extends AbstractPacket {
commonPlayerSpawnInfoStructure.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value));
return;
}
-
handle.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value));
}
@@ -103,14 +68,16 @@ public class WrapperPlayServerRespawn extends AbstractPacket {
}
public void setSeed(long value) {
- if (MinecraftVersion.BEE_UPDATE.atOrAbove() && !MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
+ if (MinecraftVersion.WILD_UPDATE.atOrAbove() && !MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
handle.getLongs().writeSafely(0, Hashing.sha256().hashLong(value).asLong());
}
}
- public void setDifficulty(Difficulty difficulty) {
- if (difficulty != null && !MinecraftVersion.VILLAGE_UPDATE.atOrAbove()) {
- handle.getDifficulties().writeSafely(0, EnumWrappers.Difficulty.valueOf(difficulty.name()));
- }
+ private void writeDimensionToStructure(World value, StructureModifier structures, StructureModifier worldKeys) {
+ final InternalStructure dimensionType = structures.read(0);
+ dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type"));
+ dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld"));
+ structures.writeSafely(0, dimensionType);
+ worldKeys.writeSafely(0, value);
}
}
diff --git a/src/test/java/xyz/ineanto/nicko/test/i18n/ItemTranslationTest.java b/src/test/java/xyz/ineanto/nicko/test/i18n/ItemTranslationTest.java
index 5f77ade..6ee6905 100644
--- a/src/test/java/xyz/ineanto/nicko/test/i18n/ItemTranslationTest.java
+++ b/src/test/java/xyz/ineanto/nicko/test/i18n/ItemTranslationTest.java
@@ -35,8 +35,8 @@ public class ItemTranslationTest {
public void translateItemTranslationWithoutLore() {
final I18N i18n = new I18N(Locale.FRENCH);
final ItemTranslation translation = i18n.fetchTranslation(I18NDict.GUI.GO_BACK);
- assertTrue(translation.getLore().isEmpty());
- assertEquals(translation.getName(), "Retour");
+ assertTrue(translation.lore().isEmpty());
+ assertEquals(translation.name(), "Retour");
}
@Test
@@ -44,10 +44,10 @@ public class ItemTranslationTest {
public void translateItemLore() {
final I18N i18n = new I18N(Locale.FRENCH);
final ItemTranslation translation = i18n.fetchTranslation(I18NDict.GUI.Admin.Cache.STATISTICS, "1", "1");
- assertFalse(translation.getLore().isEmpty());
- assertEquals("§fNombre de requêtes: §b1", translation.getLore().get(0));
- assertEquals("§fNb. de skin dans le cache: §b1", translation.getLore().get(1));
- assertEquals("§8§oLe cache est vidé toutes les 24 heures.", translation.getLore().get(2));
+ assertFalse(translation.lore().isEmpty());
+ assertEquals("§fNombre de requêtes: §b1", translation.lore().get(0));
+ assertEquals("§fNb. de skin dans le cache: §b1", translation.lore().get(1));
+ assertEquals("§8§oLe cache est vidé toutes les 24 heures.", translation.lore().get(2));
}
@AfterAll
diff --git a/src/test/java/xyz/ineanto/nicko/test/i18n/TranslationTest.java b/src/test/java/xyz/ineanto/nicko/test/i18n/TranslationTest.java
index 59a8705..4f0c937 100644
--- a/src/test/java/xyz/ineanto/nicko/test/i18n/TranslationTest.java
+++ b/src/test/java/xyz/ineanto/nicko/test/i18n/TranslationTest.java
@@ -1,7 +1,6 @@
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;
@@ -16,8 +15,6 @@ import xyz.ineanto.nicko.i18n.Locale;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TranslationTest {
- private static PlayerMock player;
-
@BeforeAll
public static void setup() {
final Configuration config = new Configuration(