Jump to content

[1.12.2]How to send command when player join a game?


mlgmxyysd

Recommended Posts

I use 

Minecraft.getMinecraft().player.sendChatMessage("/login " + password);

then game throw a NullPointerException.

Context:

package org.meowcat.autocommadner;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.io.*;
import java.lang.reflect.Method;
import java.util.Properties;
public class JoinEvent {
	private Properties prop = new Properties();
	JoinEvent() {
		MinecraftForge.EVENT_BUS.register(this);
		FMLCommonHandler.instance().bus().register(this);
	}
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void PlayerJoinGame(PlayerEvent.PlayerLoggedInEvent event) throws IOException {
	    try{
	        Class mc = Class.forName(Minecraft.class.getName());
	        Method[] methods = mc.getMethods();
	        for (Method method : methods){
                Main.logger.info(method.getName());
            }
        } catch (ClassNotFoundException e ) {
            e.printStackTrace();
        }
		File file = new File("config/user.properties");
		if (!file.exists()) {
            Minecraft.getMinecraft().shutdown();
		}
        InputStream in = new BufferedInputStream(new FileInputStream("config/user.properties"));
        prop.load(in);
        String password = prop.getProperty("Password");
        String registered = prop.getProperty("IsRegistered");
        if (!registered.equals("true")) {
           Minecraft.getMinecraft().player.sendChatMessage("/register " + password + " " + password);
        } else {
           Minecraft.getMinecraft().player.sendChatMessage("/login " + password);
        }
	}
}

 

Link to comment
Share on other sites

What exactly are you trying to do? From an end-user persective

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

9 hours ago, diesieben07 said:

It might not be. Still, why? This usually means you are pirating the game.

 

You need to use ClientTickEvent, PlayedLoggedInEvent is server-side only. And that is not how @SideOnly works.

The mod is a client mod,not a server mod.

Link to comment
Share on other sites

send your code and the error

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

13 hours ago, diesieben07 said:

The code above has not changed. No error was posted.

It may cause by network problem.

package org.meowcat.autocommadner;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.io.*;
import java.lang.reflect.Method;
import java.util.Properties;
public class JoinEvent {
	private Properties prop = new Properties();
	JoinEvent() {
		MinecraftForge.EVENT_BUS.register(this);
		FMLCommonHandler.instance().bus().register(this);
	}
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void PlayerJoinGame(TickEvent.ClientTickEvent event) throws IOException {
	    try{
	        Class mc = Class.forName(Minecraft.class.getName());
	        Method[] methods = mc.getMethods();
	        for (Method method : methods){
                Main.logger.info(method.getName());
            }
        } catch (ClassNotFoundException e ) {
            e.printStackTrace();
        }
		File file = new File("config/user.properties");
		if (!file.exists()) {
            Minecraft.getMinecraft().shutdown();
		}
        InputStream in = new BufferedInputStream(new FileInputStream("config/user.properties"));
        prop.load(in);
        String password = prop.getProperty("Password");
        String registered = prop.getProperty("IsRegistered");
        if (!registered.equals("true")) {
           Minecraft.getMinecraft().player.sendChatMessage("/register " + password + " " + password);
        } else {
           Minecraft.getMinecraft().player.sendChatMessage("/login " + password);
        }
	}
}
java.lang.NullPointerException: Unexpected error
	at org.meowcat.autocommadner.JoinEvent.PlayerJoinGame(JoinEvent.java:42)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_18_JoinEvent_PlayerJoinGame_ClientTickEvent.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
	at net.minecraftforge.fml.common.FMLCommonHandler.onPreClientTick(FMLCommonHandler.java:344)
	at net.minecraft.client.Minecraft.func_71407_l(Minecraft.java:1708)
	at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:1098)
	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:398)
	at net.minecraft.client.main.Main.main(SourceFile:123)
	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)

These are codes & errors

Link to comment
Share on other sites

What are you trying to do with that code?

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

5 hours ago, diesieben07 said:

Why on earth is this here? And blindly catching ClassNotFoundException and ignoring it is a bad idea. Handle exceptions properly.

 

Why on earth are you doing this every tick?! And registered should not be an option. Do not pirate the game.

 

You can only do this when the game is actually connected to a server. ClientTickEvent fires every client tick (duh), which is also during e.g. the main menu.

Please don't get caught up in the secondary problem.

I only want to solve NullPointerException.

Link to comment
Share on other sites

On 12/27/2018 at 10:51 AM, diesieben07 said:

It might not be. Still, why? This usually means you are pirating the game.

 

You need to use ClientTickEvent, PlayedLoggedInEvent is server-side only. And that is not how @SideOnly works.

Not to go too off topic, but /login can be used on servers as a staff security measure as well as for cracked server auth. So, it's not always malicious. I once had to use it on my online mode server because we had this hacker who somehow figured out that commands could be run by staff before they were authenticated (I have no idea how, but I'm not lying, he'd done it) and so I had to add a login command for staff to counteract it.

Link to comment
Share on other sites

  • 3 weeks later...
On 12/31/2018 at 11:20 PM, diesieben07 said:

I know, and this is the only reason this thread is not locked yet.

 

This explains nothing.

 

As far as the cause of your exception goes, I have already explained that above.

OKAY, I does not use /login command, replace /login to /exp ok?

IS THIS OK?

package org.meowcat.autocommadner;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.io.*;
import java.lang.reflect.Method;
import java.util.Properties;
public class JoinEvent {
	private Properties prop = new Properties();
	JoinEvent() {
		MinecraftForge.EVENT_BUS.register(this);
		FMLCommonHandler.instance().bus().register(this);
	}
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void PlayerJoinGame(TickEvent.ClientTickEvent event) throws IOException {
	    try{
	        Class mc = Class.forName(Minecraft.class.getName());
	        Method[] methods = mc.getMethods();
	        for (Method method : methods){
                Main.logger.info(method.getName());
            }
        } catch (ClassNotFoundException e ) {
            e.printStackTrace();
        }
            Minecraft.getMinecraft().player.sendChatMessage("/exp");
	}
}
Link to comment
Share on other sites

On 12/31/2018 at 2:24 PM, hiotewdew said:

Not to go too off topic, but /login can be used on servers as a staff security measure as well as for cracked server auth. So, it's not always malicious. I once had to use it on my online mode server because we had this hacker who somehow figured out that commands could be run by staff before they were authenticated (I have no idea how, but I'm not lying, he'd done it) and so I had to add a login command for staff to counteract it.

Yes, it is necessary to use unofficial login system in offline-mode server.

Link to comment
Share on other sites

  • 2 years later...
On 1/16/2019 at 8:34 AM, diesieben07 said:

Why do you want an offline-mode server?

There is no reason except:

  1. To allow pirating the game, in which case that is not allowed.
  2. For a local network, in which case there i no need for whitelisting (you are already in a local network, noone can join from outside).

 

This is an old discussion, but after reading through it seems you've been unfair to @mlgmxyysd and wrong to assume that there are only two reasons why someone might want an offline mode server. I can give you a couple more valid and legitimate reasons:

1. The local network point is valid, and yes nobody can join from outside, but he could be running his server on a university network in which case custom authentication would be useful. It could be that nobody could join from outside, but 30 thousand people could join from inside.

2. He could be running his server on a network where Minecraft's authentication endpoint is blocked.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I was just trying to play my modded world when i randomly got this crash for no reason. I sorted through like every mod and eventually I realized it was LLibrary but I can't seem to find a solution to fix the crashing. I can't lose the world that I have that uses this mod please help me. Here's the report: https://pastebin.com/0D00B79i If anyone has a solution please let me know.  
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ligawin88 adalah bocoran slot rekomendasi gacor dari Ligawin88 yang bisa anda temukan di SLOT Ligawin88. Situs SLOT Ligawin88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ligawin88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ligawin88 merupakan SLOT Ligawin88 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ligawin88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ligawin88 hari ini yang telah disediakan SLOT Ligawin88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ligawin88 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ligawin88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ligawin88 di link SLOT Ligawin88.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Asusslot adalah bocoran slot rekomendasi gacor dari Asusslot yang bisa anda temukan di SLOT Asusslot. Situs SLOT Asusslot hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Asusslot terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Asusslot merupakan SLOT Asusslot hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Asusslot. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Asusslot hari ini yang telah disediakan SLOT Asusslot. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Asusslot terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Asusslot terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Asusslot di link SLOT Asusslot.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Galeri555 adalah bocoran slot rekomendasi gacor dari Galeri555 yang bisa anda temukan di SLOT Galeri555. Situs SLOT Galeri555 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Galeri555 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Galeri555 merupakan SLOT Galeri555 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Galeri555. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Galeri555 hari ini yang telah disediakan SLOT Galeri555. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Galeri555 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Galeri555 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Galeri555 di link SLOT Galeri555.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Kocok303 adalah bocoran slot rekomendasi gacor dari Kocok303 yang bisa anda temukan di SLOT Kocok303. Situs SLOT Kocok303 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Kocok303 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Kocok303 merupakan SLOT Kocok303 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Kocok303. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Kocok303 hari ini yang telah disediakan SLOT Kocok303. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Kocok303 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Kocok303 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Kocok303 di link SLOT Kocok303.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.