Résolu Packet Commands
-
Bonsoir,
je cherche à faire un Packet pour executer des commande depuis un gui-client à la console du serveur mais je ne sais pas trop quoi mettre dans mon packet …
Qui aurait une classe ou un boût de code pour m’aider, où même une explication ?
Cordialement, AsKip_p
-
Salut,
Si tu n’as aucune donné à envoyer, tu peux laisser fromBytes et toBytes vide, tu as juste à faire l’action dans l’handler. -
Bonsoir, c’est encore moi
J’ai créer mon packet, mais je bloque, je sais pas comment faire pour envoyer la commande à la console,
Qui pourrait m’aider et au passe si j’ai mal fais quelque chose me le dire ?package fr.askip.testing.packets; 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; public class PacketCmdServer implements IMessage { private Integer integer; public PacketCmdServer(Integer i) { this.integer = i; } @Override public void fromBytes(ByteBuf buf) { this.integer = Integer.valueOf(buf.readInt()); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(this.integer.intValue()); } public static class Handler implements IMessageHandler <packetcmdserver, imessage="">{ @Override public IMessage onMessage(PacketCmdServer message, MessageContext ctx) { switch (message.integer.intValue()) { case 0: //envoyer la commande dans la console ICI break; } return null; } } }
Cordialement, AzTick</packetcmdserver,>
-
J’ai déplacé ton message dans l’autre discussion existante, ça ne sert à rien de créer deux discussions pour un même problème …
Il y a une fonction dans MinecraftServer pour exécuter une commande, par contre de tête je n’ai plus le nom.
-
@‘robin4002’:
J’ai déplacé ton message dans l’autre discussion existante, ça ne sert à rien de créer deux discussions pour un même problème …
Il y a une fonction dans MinecraftServer pour exécuter une commande, par contre de tête je n’ai plus le nom.
Il me semble que je peut faire avec message context mais je n’ai plus la fonction en tête
Re re bonsoir,
Grosse erreur, du sale :
[22:05:07] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: AsKip_p joined the game [22:05:10] [Server thread/WARN] [net.minecraft.server.MinecraftServer]: Can't keep up! Did the system time change, or is the server overloaded? Running 2883ms behind, skipping 57 tick(s) [22:05:54] [Server thread/ERROR] [FML]: FMLIndexedMessageCodec exception caught io.netty.handler.codec.DecoderException: java.lang.InstantiationException: fr.askip.testing.packets.PacketCmdServer 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.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?] at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:349) [DedicatedServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] Caused by: java.lang.InstantiationException: fr.askip.testing.packets.PacketCmdServer at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_161] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:75) ~[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:?] … 13 more Caused by: java.lang.NoSuchMethodException: fr.askip.testing.packets.PacketCmdServer.<init>() at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.8.0_161] at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_161] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:75) ~[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:?] … 13 more [22:05:54] [Server thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception io.netty.handler.codec.DecoderException: java.lang.InstantiationException: fr.askip.testing.packets.PacketCmdServer 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.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?] at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:349) [DedicatedServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] Caused by: java.lang.InstantiationException: fr.askip.testing.packets.PacketCmdServer at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_161] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:75) ~[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:?] … 13 more Caused by: java.lang.NoSuchMethodException: fr.askip.testing.packets.PacketCmdServer.<init>() at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.8.0_161] at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_161] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:75) ~[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:?] … 13 more [22:05:54] [Server thread/ERROR] [FML]: There was a critical exception handling a packet on channel combinedrp: io.netty.handler.codec.DecoderException: java.lang.InstantiationException: fr.askip.testing.packets.PacketCmdServer 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.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?] at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:349) [DedicatedServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] Caused by: java.lang.InstantiationException: fr.askip.testing.packets.PacketCmdServer at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_161] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:75) ~[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:?] … 13 more Caused by: java.lang.NoSuchMethodException: fr.askip.testing.packets.PacketCmdServer.<init>() at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.8.0_161] at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_161] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:75) ~[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:?] … 13 more [22:05:54] [Server thread/INFO] [net.minecraft.network.NetHandlerPlayServer]: AsKip_p lost connection: TextComponent{text='A fatal error has occured, this connection is terminated', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null}} [22:05:54] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: AsKip_p left the game
Je comprend pas trop pourquoi, y’a pas de ligne indiqué alors je comprend pas vraiment, voici mes classes:
Class PackServerCmd :
package fr.askip.testing.packets; 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.server.MinecraftServer; public class PacketCmdServer implements IMessage { private Integer integer; public PacketCmdServer(Integer i) { this.integer = i; } @Override public void fromBytes(ByteBuf buf) { this.integer = Integer.valueOf(buf.readInt()); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(this.integer.intValue()); } public static class Handler implements IMessageHandler <packetcmdserver, imessage="">{ @Override public IMessage onMessage(PacketCmdServer message, MessageContext ctx) { switch (message.integer.intValue()) { case 0: MinecraftServer.getServer().getCommandManager().executeCommand(MinecraftServer.getServer(), "say Salut petit, " + ctx.getServerHandler().playerEntity.getDisplayName()); break; } return null; } } }
La ou j’execute le packet (dans un gui)
if(button.id == this.citoyen) { Main.network.sendToServer(new PacketCmdServer(0)); }
Class Main :
package fr.askip.testing; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; import cpw.mods.fml.relauncher.Side; import fr.askip.testing.commands.AhAhAhCmd; import fr.askip.testing.init.CombinedBlocks; import fr.askip.testing.init.CombinedItems; import fr.askip.testing.packets.PacketCmdServer; import fr.askip.testing.packets.PacketSounds; import fr.askip.testing.proxy.CommonProxy; import fr.askip.testing.utils.Refs; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; @Mod(modid = Refs.MODID, name = Refs.MOD_NAME, version = Refs.VERSION) public class Main { @SidedProxy(clientSide = Refs.CLIENT_PROXY, serverSide = Refs.SERVER_PROXY) public static CommonProxy proxy; public static SimpleNetworkWrapper network; public static CreativeTabs CombinedTabs = new CreativeTabs("Combined RP") { @Override public Item getTabIconItem() { return CombinedItems.combine_key; } }; @Mod.EventHandler public void onServerStarting(FMLServerStartingEvent e) { e.registerServerCommand(new AhAhAhCmd()); } @Mod.EventHandler public void preInit(FMLPreInitializationEvent e) { proxy.preInit(e.getSuggestedConfigurationFile()); CombinedBlocks.init(); CombinedBlocks.register(); CombinedItems.init(); CombinedItems.register(); network = NetworkRegistry.INSTANCE.newSimpleChannel("combinedrp:"); network.registerMessage(PacketSounds.Handler.class, PacketSounds.class, 0, Side.CLIENT); network.registerMessage(PacketCmdServer.Handler.class, PacketCmdServer.class, 0, Side.SERVER); } @Mod.EventHandler public void init(FMLInitializationEvent e) { proxy.init(); } @Mod.EventHandler public void postInit(FMLPostInitializationEvent e) { } } ```</packetcmdserver,></init></init></init>
-
Il te manque un constructeur sans argument dans la classe de ton paquet (obligatoire pour tous les paquets).