Résolu Ouvrir un GUI quand un texte apparait dans le chat
-
Bonjour,
J’ai fait pas mal de recherches et je ne trouve que ce code.
Qui de mon coté ne fonctionne pas.Je voudrais ouvrir un GUI quand un texte apparait dans le chat.
Je me connecte a un serveur et la par exemple il y a “Please register ……”
Et dés que le message apparait, ça ouvre le menu GUI@SideOnly(Side.CLIENT) @SubscribeEvent public void onClientChatMessage(ClientChatReceivedEvent event) { if(event.message.getFormattedText().startsWith("/login")) { Minecraft.getMinecraft().displayGuiScreen(new GuiLogin()); } }
-
Salut, qu’est-ce qui ne va pas avec le code actuel ?
-
Bha en fait sa n’ouvre pas le gui…
Alors que sur mon serveur j’ai mon plugin qui envoi le message dans le chat. C’est justement pour sa que je ne comprend pas…Envoyé de mon ZTE BLADE V7 LITE en utilisant Tapatalk
-
Peint dans ton Event le String donné par event.message.getFormattedText() afin de voir s’il commencé réellement par “/login”. De mémoire, je crois qu’il commencé d’abord par un crochet suivis du pseudo du sender.
-
Comment je peut faire ça ?
Je suis pas douer dans ce genre de chose…Envoyé de mon ZTE BLADE V7 LITE en utilisant Tapatalk
Edit:
J’ai réussi grace atoi, MERCI beaucoup !Editx2:
J’ai un crash lorsque je clique sur le bouton qui exécute la commande /login ******
Crash report:–-- Minecraft Crash Report ---- // Surprise! Haha. Well, this is awkward. Time: 28/07/17 12:51 Description: Unexpected error java.lang.StringIndexOutOfBoundsException: String index out of range: -5 at java.lang.String.substring(Unknown Source) at fr.playflop.legitium.common.MainClass.onClientChatMessage(MainClass.java:273) at cpw.mods.fml.common.eventhandler.ASMEventHandler_35_MainClass_onClientChatMessage_ClientChatReceivedEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140) at net.minecraft.client.network.NetHandlerPlayClient.handleChat(NetHandlerPlayClient.java:793) at net.minecraft.network.play.server.S02PacketChat.processPacket(S02PacketChat.java:56) at net.minecraft.network.play.server.S02PacketChat.processPacket(S02PacketChat.java:83) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1694) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1040) at net.minecraft.client.Minecraft.run(Minecraft.java:962) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at java.lang.String.substring(Unknown Source) at fr.playflop.legitium.common.MainClass.onClientChatMessage(MainClass.java:273) at cpw.mods.fml.common.eventhandler.ASMEventHandler_35_MainClass_onClientChatMessage_ClientChatReceivedEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140) at net.minecraft.client.network.NetHandlerPlayClient.handleChat(NetHandlerPlayClient.java:793) at net.minecraft.network.play.server.S02PacketChat.processPacket(S02PacketChat.java:56) at net.minecraft.network.play.server.S02PacketChat.processPacket(S02PacketChat.java:83) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['PlayFlop'/366, l='MpServer', x=119,50, y=82,62, z=252,50]] Chunk stats: MultiplayerChunkCache: 441, 441 Level seed: 0 Level generator: ID 00 - default, ver 1\. Features enabled: false Level generator options: Level spawn location: World: (112,64,256), Chunk: (at 0,4,0 in 7,16; contains blocks 112,0,256 to 127,255,271), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Level time: 5466227 game time, 39606228 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false Forced entities: 15 total; [EntityClientPlayerMP['PlayFlop'/366, l='MpServer', x=119,50, y=82,62, z=252,50], EntitySpider['Spider'/130, l='MpServer', x=118,00, y=13,00, z=274,28], EntityZombie['Zombie'/108, l='MpServer', x=76,50, y=22,00, z=273,97], EntityChicken['Chicken'/142, l='MpServer', x=165,75, y=66,00, z=220,89], EntitySkeleton['Skeleton'/430, l='MpServer', x=90,50, y=50,00, z=280,50], EntitySkeleton['Skeleton'/432, l='MpServer', x=83,50, y=43,00, z=257,50], EntityCreeper['Creeper'/148, l='MpServer', x=166,00, y=10,00, z=232,50], EntitySkeleton['Skeleton'/118, l='MpServer', x=80,66, y=13,00, z=291,50], EntityZombie['Zombie'/217, l='MpServer', x=80,50, y=51,00, z=229,50], EntitySkeleton['Skeleton'/121, l='MpServer', x=86,50, y=35,00, z=288,50], EntityZombie['Zombie'/122, l='MpServer', x=85,50, y=35,00, z=288,50], EntitySkeleton['Skeleton'/285, l='MpServer', x=79,69, y=17,00, z=265,72], EntitySkeleton['Skeleton'/286, l='MpServer', x=85,50, y=18,00, z=270,50], EntityZombie['Zombie'/127, l='MpServer', x=111,47, y=15,00, z=273,97], EntityEnderman['Enderman'/415, l='MpServer', x=133,50, y=31,00, z=274,50]] Retry entities: 0 total; [] Server brand: Spigot Server type: Non-integrated multiplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2567) at net.minecraft.client.Minecraft.run(Minecraft.java:991) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) – System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 8.1 (amd64) version 6.3 Java Version: 1.8.0_131, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 856543456 bytes (816 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1614 7 mods loaded, 7 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored UCHIJA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) UCHIJA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar) UCHIJA Forge{10.13.4.1614} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar) UCHIJA CodeChickenCore{1.0.7.47} [CodeChicken Core] (minecraft.jar) UCHIJA EraKnight{1.0} [EraKnight] (bin) UCHIJA craftguide{1.6.8.1} [CraftGuide] (c.zip) UCHIJA reachdisplaymod{1.0} [Reach Display Mod] ([1.7.10]ReachDisplayMod-1.0.jar) GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 381.65' Renderer: 'GeForce GT 740M/PCIe/SSE2' Launched Version: 1.7.10 LWJGL: 2.9.1 OpenGL: GeForce GT 740M/PCIe/SSE2 GL version 4.5.0 NVIDIA 381.65, NVIDIA Corporation GL Caps: Using GL 1.3 multitexturing. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Anisotropic filtering is supported and maximum anisotropy is 16. Shaders are available because OpenGL 2.1 is supported. Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [] Current Language: English (US) Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Anisotropic Filtering: Off (1)
Eclipse:
Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2567) at net.minecraft.client.Minecraft.run(Minecraft.java:991) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source)
GuiLogin
package fr.playflop.legitium.proxy; import java.util.Map.Entry; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.resources.I18n; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import cpw.mods.fml.client.config.GuiSlider; import fr.playflop.legitium.client.radio.RadioHandler; public class GuiLogin extends GuiScreen { private GuiTextField textfield; int guiWidth= 250; // Taille du gui (largeur) int guiHeight= 250;// Taille du gui (hauteur) public void initGui() { int posX = (this.width - guiWidth) / 2; int posY = (this.height - guiHeight) / 2; this.textfield = new GuiTextField(this.fontRendererObj, this.width / 2 - 78, this.height / 2 - 75, 150, 20); this.buttonList.add(new GuiButton(10, this.width / 2 - 80, this.height / 2 - 45, 155, 20, I18n.format(EnumChatFormatting.GOLD + "Connection"))); textfield.setMaxStringLength(16); textfield.setText(""); this.textfield.setFocused(false); } protected void actionPerformed(GuiButton button) { switch (button.id) { case 10: String mdp = textfield.getText(); Minecraft.getMinecraft().thePlayer.sendChatMessage("/login " + mdp); this.mc.displayGuiScreen((GuiScreen) null); this.mc.setIngameFocus(); //System.out.println("/login " + mdp); break; } } @Override public void drawScreen(int x, int y, float ticks ) { int guix =(width - guiWidth) /2 ; int guiy =(height - guiHeight) /2; GL11.glColor4f(1,1,1,1); drawDefaultBackground(); mc.renderEngine.bindTexture(new ResourceLocation("eraknight:textures/gui/guilogin.png")); // Le chemin de ton GUI drawTexturedModalRect(guix, guiy, 0, 0, guiWidth, guiHeight); this.drawDefaultBackground(); this.textfield.drawTextBox(); // On met ton textfield ici super.drawScreen(x, y, ticks); } @Override public boolean doesGuiPauseGame() { return false; } protected void keyTyped(char par1, int par2) { super.keyTyped(par1, par2); this.textfield.textboxKeyTyped(par1, par2); } public void updateScreen() { super.updateScreen(); } protected void mouseClicked(int x, int y, int btn) { super.mouseClicked(x, y, btn); this.textfield.mouseClicked(x, y, btn); } //Minecraft.getMinecraft().displayGuiScreen(null); }
-
Le problème est ici : at fr.playflop.legitium.common.MainClass.onClientChatMessage(MainClass.java:273)
Il nous faudrait cette ligne -
@‘robin4002’:
Le problème est ici : at fr.playflop.legitium.common.MainClass.onClientChatMessage(MainClass.java:273)
Il nous faudrait cette ligneLa voici:
String message = event.message.getUnformattedText().substring(Minecraft.getMinecraft().getSession().getUsername().length() + 3, event.message.getUnformattedText().length());
-
Tu essaies de coupe une partie de chaine plus grande que la chaine elle même.
Avant de faire ce code il faudrait la condition suivante :
if(message.length() > Minecraft.getMinecraft().getSession().getUsername().length() + 3)pour éviter ce crash;
-
@‘robin4002’:
Tu essaies de coupe une partie de chaine plus grande que la chaine elle même.
Avant de faire ce code il faudrait la condition suivante :
if(message.length() > Minecraft.getMinecraft().getSession().getUsername().length() + 3)pour éviter ce crash;
Le truc c’est que je veux pas diviser la ligne
-
Hein ? Je ne comprends pas le problème.
-
J’ai réglé mon souci, merci !