Résolu Liste, tableau?
-
Bonjour! Mon titre n’est peut-être pas très clair donc je vais expliqué:
J’ai une liste de neufs permis et je dois les enregistrer dans mon extended entity properties pour pouvoir ensuite les lister. Donc au début, je me suis dit que j’allais créer 9 boolean et les mettres à true si il le possède, mais je ne pourrais pas faire de boucle for pour les lister. Ma deuxième solution, était d’utiliser un tableau pour le faire, ce n’était pas une mauvaise idée, mais j’ai un crash au moment de la synchronisation client/serveur. Ensuite, Julot m’a proposé d’utiliser une liste mais je ne m’en suis jamais servi donc je n’ai aucune idée comment ça fonctionne.
Quelle serait selon vous la meilleur méthode?
Ensuite viens le problème de l’identification, je dois les lister, mais il faut que ce soit propre, dans le sens qu’ils doivent avoir un nom localisé, encore là je ne connais pas la meilleure façon de le faire
-
Plusieurs boolean = pas une bonne idée.
Ensuite pour la question liste ou tableau c’est simple.
Si la taille est fixe → tableau.
Si la taille est variable → liste. -
La dimension n’est pas variable.
Que veux-tu dire pas une bonne idée?
-
Car pour les listes ça va être plus compliqué.
-
Que tu utilises un tableau ou plusieurs boolean, si ça crash c’est pas la structure de données qui est foireuse, c’est ton code.
Créer plusieurs boolean n’est pas une bonne idée, car d’un point de vue programmation tu ne pourra pas faire de boucle, tu ne pourra pas retourner l’ensemble de tes permis via un getter etc… Bref, ça t’impose énormément de limite. D’un point de vue JVM, tu fragmentes la mémoire inutilement.Un tableau c’est bien si tu connais d’avance sa taille.
Une List, se décompose en 2 implémentations : l’ArrayList et la LinkedList.
Une ArrayList se base sur un tableau dont la taille est multiplié par 2 dès qu’un ajout dépasse le nombre de case.
Une LinkedList c’est une chaine d’élément. C’est a dire que l’élément 1 possède un lien vers l’élément 0 et l’élément 2 etc…ArrayList ou LinkedList ? ça dépend :
- Si tu veux accédez a l’élément i et qu’il est au milieu de ta liste
ArrayList : Tu peux y accéder directement.
LinkedList : Tu dois parcourir la moitié de ta liste.- Si tu ajoute un élément à la moitié de ta liste (idem pour la suppression)
ArrayList : Tu recopies les éléments suivant a la case n+1, un par un.
LinkedList : Tu insert directement l’élément en modifiant juste le chainageEn gros :
Structure de donnée : Accès random / Modification
ArrayList : +++ / +
LinkedList : + / +++ -
En fait, la taille n’est pas variable dans je n’ai techniquement pas besoin d’une liste sinon, mon code crashait au niveau de mon buf.readBoolean(); car en fait j’utilisait un boucle pour parcourir le tableau et buf chacun de mes valeurs, mais je crois que pour le récupérer je dois utiliser une boucle pour les récupérer un par un?
Bref, je crois que l’utilisation d’un tableau serait moins complexe et je vais réessayer et renvoyer le crash si il y en a un.
Sinon, un autre problème dont je n’ai aucune idée, comment je pourrais récupérer le nom de la valeur en fait, il me faudrait un nom localisé pour chaque permis et lister les permis qu’il possède.
EDIT: J’ai fait un système avec des tableau et cette façon m’a semblé la meilleure mais je dois avoir fait une erreur.
Le crash:
[19:51:47] [Client thread/ERROR] [FML]: FMLIndexedMessageCodec exception caught io.netty.handler.codec.DecoderException: java.lang.NullPointerException at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:2152) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.NullPointerException at diabolicatrix.project.PacketRestrainClientServer.fromBytes(PacketRestrainClientServer.java:43) ~[PacketRestrainClientServer.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:17) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:7) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:17) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?] … 19 more [19:51:47] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception io.netty.handler.codec.DecoderException: java.lang.NullPointerException at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:2152) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.NullPointerException at diabolicatrix.project.PacketRestrainClientServer.fromBytes(PacketRestrainClientServer.java:43) ~[PacketRestrainClientServer.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:17) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:7) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:17) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?] … 19 more [19:51:47] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception io.netty.handler.codec.DecoderException: java.lang.NullPointerException at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:2152) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.NullPointerException at diabolicatrix.project.PacketRestrainClientServer.fromBytes(PacketRestrainClientServer.java:43) ~[PacketRestrainClientServer.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:17) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:7) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:17) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?] … 19 more [19:51:47] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception io.netty.handler.codec.DecoderException: java.lang.NullPointerException at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:2152) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.NullPointerException at diabolicatrix.project.PacketRestrainClientServer.fromBytes(PacketRestrainClientServer.java:43) ~[PacketRestrainClientServer.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:17) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:7) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:17) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?] … 19 more [19:51:47] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception io.netty.handler.codec.DecoderException: java.lang.NullPointerException at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:2152) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.NullPointerException at diabolicatrix.project.PacketRestrainClientServer.fromBytes(PacketRestrainClientServer.java:43) ~[PacketRestrainClientServer.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:17) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:7) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:17) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?] … 19 more [19:51:47] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception io.netty.handler.codec.DecoderException: java.lang.NullPointerException at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:2152) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.NullPointerException at diabolicatrix.project.PacketRestrainClientServer.fromBytes(PacketRestrainClientServer.java:43) ~[PacketRestrainClientServer.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:17) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:7) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:17) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?] … 19 more [19:51:47] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception io.netty.handler.codec.DecoderException: java.lang.NullPointerException at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:2152) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.NullPointerException at diabolicatrix.project.PacketRestrainClientServer.fromBytes(PacketRestrainClientServer.java:43) ~[PacketRestrainClientServer.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:17) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:7) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:17) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?] … 19 more [19:51:47] [Client thread/ERROR] [FML]: There was a critical exception handling a packet on channel T4Channel io.netty.handler.codec.DecoderException: java.lang.NullPointerException at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:2152) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.NullPointerException at diabolicatrix.project.PacketRestrainClientServer.fromBytes(PacketRestrainClientServer.java:43) ~[PacketRestrainClientServer.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:17) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:7) ~[SimpleIndexedCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:17) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?] … 19 more [19:51:47] [Server thread/INFO]: Player445 lost connection: TextComponent{text='Disconnected', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null}} [19:51:47] [Server thread/INFO]: Player445 a quitté la partie [19:51:47] [Server thread/INFO]: Stopping singleplayer server as player logged out [19:51:48] [Server thread/INFO]: Stopping server [19:51:48] [Server thread/INFO]: Saving players [19:51:48] [Server thread/INFO]: Saving worlds [19:51:48] [Server thread/INFO]: Saving chunks for level 'Nouveau monde'/Overworld [19:51:49] [Server thread/INFO]: Saving chunks for level 'Nouveau monde'/Nether [19:51:49] [Server thread/INFO]: Saving chunks for level 'Nouveau monde'/The End [19:51:51] [Server thread/INFO] [FML]: Unloading dimension 0 [19:51:51] [Server thread/INFO] [FML]: Unloading dimension -1 [19:51:51] [Server thread/INFO] [FML]: Unloading dimension 1 [19:51:51] [Server thread/INFO] [FML]: Applying holder lookups [19:51:51] [Server thread/INFO] [FML]: Holder lookups applied
Mes classes:
EEPRestrained:
package diabolicatrix.project; import java.awt.List; import java.util.LinkedList; import diabolicatrix.project.proxy.CommonProxy; import net.minecraft.client.resources.I18n; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; public class EEPRestrained implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "EEPRestrained"; public boolean[] licenses; private EntityPlayer player; public long cash; public long money; public boolean escorted = false; public EntityPlayer escorter; public boolean restrained = false; public EEPRestrained(EntityPlayer player) { this.player = player; this.restrained = false; this.cash = 0; this.money = 0; this.licenses = new boolean[] {false, false, false, false, false, false, false, false, false}; } public static final void register(EntityPlayer player) { player.registerExtendedProperties(EEPRestrained.EXT_PROP_NAME, new EEPRestrained(player)); } public static final EEPRestrained get(EntityPlayer player) { return (EEPRestrained)player.getExtendedProperties(EXT_PROP_NAME); } @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setBoolean("Restrained", this.restrained); properties.setBoolean("Escorted", this.escorted); properties.setLong("Cash", this.cash); properties.setLong("Money", this.money); for(int i = 0; i < this.licenses.length; i++) { properties.setBoolean("License" + i, this.licenses*); } compound.setTag(EXT_PROP_NAME, properties); } public void saveNBTDataMoney(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setLong("Money", this.money); compound.setTag(EXT_PROP_NAME, properties); } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.restrained = properties.getBoolean("Restrained"); this.escorted = properties.getBoolean("Escorted"); this.cash = properties.getLong("Cash"); this.money = properties.getLong("Money"); for(int i = 0; i < this.licenses.length; i++) { this.licenses* = properties.getBoolean("License" + i); } } @Override public void init(Entity entity, World world) { } public final void sync() { if (player.worldObj.isRemote) { Base.instance.network.sendToServer(new PacketRestrainServer(this.restrained, this.cash, this.money, this.escorted, this.licenses)); } if (!player.worldObj.isRemote) { EntityPlayerMP player1 = (EntityPlayerMP) player; Base.instance.network.sendTo(new PacketRestrainClientServer(this.restrained, this.cash, this.money, this.escorted, this.licenses), player1); } } private static String getSaveKey(EntityPlayer player) { return player.getDisplayName() + ":" + EXT_PROP_NAME; } public static void saveProxyData(EntityPlayer player) { EEPRestrained playerData = EEPRestrained.get(player); NBTTagCompound savedData = new NBTTagCompound(); playerData.saveNBTData(savedData); CommonProxy.storeEntityData(getSaveKey(player), savedData); } public static void loadProxyData(EntityPlayer player) { EEPRestrained playerData = EEPRestrained.get(player); NBTTagCompound savedData = CommonProxy.getEntityData(getSaveKey(player)); if (savedData != null) { playerData.loadNBTData(savedData); } playerData.sync(); } public void restrain() { this.restrained = true; this.sync(); } public void unrestrain() { this.restrained = false; this.sync(); } public boolean isRestrained() { return restrained; } public void pay() { this.sync(); } public void addCash(long amount) { boolean sufficient = amount <= this.getMoney(); if(sufficient) { this.cash += amount; this.money -= amount; this.sync(); } } public boolean sufficient(long amount) { boolean sufficient = amount <= this.getCash(); if(sufficient) { return true; } else { return false; } } public boolean sufficientm(long amount) { boolean sufficient = amount <= this.getMoney(); if(sufficient) { return true; } else { return false; } } public String buyCashTest(long amount, ItemStack item) { boolean sufficient = amount <= this.getCash(); if(sufficient) { if(item != null) { boolean isEmpty = false; for (int i=0; i<= player.inventory.getSizeInventory() - 5; i++) { //System.out.println(i); if(player.inventory.mainInventory* == item || player.inventory.mainInventory* == null) { isEmpty = true; break; } } if(isEmpty) { //this.delCash2(amount); //player.inventory.addItemStackToInventory(item); return "t4.boughtitem"; } else { return "t4.notenoughspace"; } } else { } } else { return "t4.notenoughmoney"; } return null; } public void buyCash(long amount, ItemStack item) { boolean sufficient = amount <= this.getCash(); if(sufficient) { if(item != null) { boolean isEmpty = false; for (int i=0; i<= player.inventory.getSizeInventory() - 5; i++) { if(player.inventory.mainInventory* == item || player.inventory.mainInventory* == null) { isEmpty = true; break; } } if(isEmpty) { this.delCash2(amount); player.inventory.addItemStackToInventory(item); } else { } } else { } } else { } } public void addCashRaw(long amount) { this.cash += amount; this.sync(); } public void delCash(long amount) { boolean sufficient = amount <= this.getCash(); if(sufficient) { this.cash -= amount; this.money += amount; this.sync(); } } public void delCash2(long amount) { boolean sufficient = amount <= this.getCash(); if(sufficient) { this.cash -= amount; this.sync(); } } public void delMoney(long amount) { boolean sufficient = amount <= this.getMoney(); if(sufficient) { this.money -= amount; this.sync(); } } public long getCash() { return this.cash; } public void addMoney(long amount) { this.money += amount; this.sync(); } public void setMoney(long amount) { this.money = amount; this.sync(); } public void setCash(long amount) { this.cash = amount; this.sync(); } public long getMoney() { return this.money; } public boolean isEscorted() { return escorted; } public void setEscorted(boolean escorted) { this.escorted = escorted; } }
PacketRestrainServer:
package diabolicatrix.project; import java.util.List; import java.util.UUID; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.MinecraftServer; public class PacketRestrainServer implements IMessage { private boolean restrained; private long money; private long cash; private boolean isMoney; private boolean escorted; private boolean[] licenses; public PacketRestrainServer(boolean restrained, long cash, long money, boolean escorted, boolean[] licenses) { this.restrained = restrained; this.cash = cash; this.money = money; this.escorted = escorted; this.licenses = licenses; } public PacketRestrainServer() {} @Override public void fromBytes(ByteBuf buf) { this.escorted = buf.readBoolean(); this.restrained = buf.readBoolean(); this.money = buf.readLong(); this.cash = buf.readLong(); for(int i = 0; i < this.licenses.length; i++) { this.licenses* = buf.readBoolean(); } } @Override public void toBytes(ByteBuf buf) { buf.writeBoolean(this.escorted); buf.writeBoolean(this.restrained); buf.writeLong(this.money); buf.writeLong(this.cash); for(int i = 0; i < this.licenses.length; i++) { buf.writeBoolean(this.licenses*); } } public static class Handler implements IMessageHandler <packetrestrainserver, imessage="">{ @Override public IMessage onMessage(PacketRestrainServer message, MessageContext ctx) { EntityPlayer player = ctx.getServerHandler().playerEntity; EEPRestrained props = EEPRestrained.get(player); props.money = message.money; props.cash = message.cash; props.restrained = message.restrained; props.escorted = message.escorted; props.licenses = message.licenses; return null; } } }
PacketRestrainClientServer:
package diabolicatrix.project; import java.util.List; import java.util.UUID; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.MinecraftServer; public class PacketRestrainClientServer implements IMessage { private boolean restrained; private long money; private long cash; private boolean isMoney; private boolean escorted; private boolean[] licenses; public PacketRestrainClientServer(boolean restrained, long cash, long money, boolean escorted, boolean[] licenses) { this.restrained = restrained; this.cash = cash; this.money = money; this.escorted = escorted; this.licenses = licenses; } public PacketRestrainClientServer() {} @Override public void fromBytes(ByteBuf buf) { this.escorted = buf.readBoolean(); this.restrained = buf.readBoolean(); this.money = buf.readLong(); this.cash = buf.readLong(); for(int i = 0; i < this.licenses.length; i++) { this.licenses* = buf.readBoolean(); } } @Override public void toBytes(ByteBuf buf) { buf.writeBoolean(this.escorted); buf.writeBoolean(this.restrained); buf.writeLong(this.money); buf.writeLong(this.cash); for(int i = 0; i < this.licenses.length; i++) { buf.writeBoolean(this.licenses*); } } public static class Handler implements IMessageHandler <packetrestrainclientserver, imessage="">{ @Override @SideOnly(Side.CLIENT) public IMessage onMessage(PacketRestrainClientServer message, MessageContext ctx) { EntityPlayer player = Minecraft.getMinecraft().thePlayer; EEPRestrained props = EEPRestrained.get(player); props.money = message.money; props.cash = message.cash; props.restrained = message.restrained; props.escorted = message.escorted; props.licenses = message.licenses; return null; } } } ```</packetrestrainclientserver,></packetrestrainserver,>
-
Tu dois initialiser ton tableau
-
Il est initialisé son tableau, regarde sa variable licenses
-
Non.
private boolean[] licenses;
licenses est null.
Cette variable n’est que initialisé dans le constructeur utilisé pour l’envoie du paquet :
public PacketRestrainServer(boolean restrained, long cash, long money, boolean escorted, boolean[] licenses) { this.restrained = restrained; this.cash = cash; this.money = money; this.escorted = escorted; this.licenses = licenses; }
Dans le constructeur utilisé à l’arrivé du paquet, il n’y a rien :
public PacketRestrainServer() {}
Pour la gestion des noms, afin d’éviter de faire un tableau avec des booleans et un autre avec des Strings pour le nom non localisé, ce que je ferai c’est utiliser un seul tableau. Seulement celui avec les strings et j’utiliserai un string null (ou un qui vaut “”) pour l’équivalent de false, dans les autres cas true.
-
A oui mal vu…
Au pire, si il l avait initialisé en même temps que la déclaration y aurait pas eu ce genre de soucis ^^’ -
Pour les nom localisé, c’est une bonne idée, par contre pour le reste normalement je ne crois pas que le fait qu’il soit null cause un problème car elles le sont toutes et je n’ai pas de problème.
private boolean restrained; private long money; private long cash; private boolean isMoney; private boolean escorted; private boolean[] licenses;
Sinon, je n’ai pas trop compris, tu veux que je mettes quoi dans l’arrivée du packet?
-
Tu utilises le field length du tableau licences, or comme licences est null ça cause un NPE.
-
Ah d’accord, je dois donc l’initialisé là à la place du constructeur.