Jump to content

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


Recommended Posts

Posted

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);
        }
	}
}

 

Posted (edited)

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

Edited by Cadiboo

About Me

  Reveal hidden contents

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)

Posted
  On 12/27/2018 at 3:51 PM, 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.

Expand  

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

Posted
  On 12/27/2018 at 3:51 PM, 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.

Expand  

No,I bought Minecraft.

Posted

send your code and the error

About Me

  Reveal hidden contents

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)

Posted
  On 12/29/2018 at 2:04 PM, diesieben07 said:

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

Expand  

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

Posted (edited)

What are you trying to do with that code?

Edited by Cadiboo

About Me

  Reveal hidden contents

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)

Posted
  On 12/30/2018 at 7:49 PM, 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.

Expand  

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

I only want to solve NullPointerException.

Posted
  On 12/31/2018 at 1:32 AM, diesieben07 said:

Pirating the game is not a secondary problem.

Please clearly state why that isRegistered option is present. If not I will assume it is for enabling pirated "accounts", in which case you will receive a ban.

Expand  

A bukkit plugin named Authme.

Posted
  On 12/27/2018 at 3:51 PM, 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.

Expand  

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.

  • 3 weeks later...
Posted
  On 12/31/2018 at 3: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.

Expand  

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");
	}
}
Posted
  On 12/31/2018 at 6:24 AM, 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.

Expand  

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

  • 2 years later...
Posted
  On 1/16/2019 at 1:34 PM, 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).

 

Expand  

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.

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

    • Add crash-reports with sites like https://mclo.gs/ Make a test without createaddition
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • my server is running perfectly fine but the problem is I can't connect to it. https://drive.google.com/file/d/1pn3oyAoS6J9mYVQlTJs7nKSSOHRo-9NX/view?usp=sharing. Here is the bug report when I tried to join the server.  
    • I'm trying to create split out some common code from my current mod project into a new library. For dependency management, I'm attempting to use AWS S3 as a Maven repo. I've done this successfully with other projects in the past, but ForgeGradle doesn't seem to like the s3:// URL for my repository. Specifically, it's throwing the following exception when trying to resolve the net.minecraftforge:forge:1.21.1-52.1.0:userdev dependency:   My understanding is that modern versions of Gradle support this use case. Does ForgeGradle not? Is there a way that I can make this work? Thank you for any help you can offer.
    • Codice Sconto Temu 100$ DI SCONTO → [acu639380] per Clienti Esistenti   Ottieni  100$ di sconto con il Codice Promozionale Temu (acu639380) Temu continua a dominare il mondo dell’e-commerce con sconti imbattibili e prodotti di tendenza – e giugno 2025 non fa eccezione. Con il codice sconto Temu (acu639380), puoi ottenere fino a  100$ di sconto, sia che tu sia un nuovo cliente sia che tu stia tornando a fare acquisti. Grazie alla consegna ultra-rapida, spedizione gratuita in 67 paesi e sconti fino al 90%, Temu propone pacchetti esclusivi e codici promozionali imperdibili questo giugno. Ecco come sfruttare al meglio il codice (acu639380) e iniziare subito a risparmiare. Perché Giugno 2025 è il Momento Migliore per Acquistare su Temu Giugno è ricco di offerte a tempo limitato, nuovi arrivi di tendenza e sconti nascosti in tutte le categorie. Dalla moda all’elettronica, dalla bellezza agli articoli per la casa, Temu offre prodotti indispensabili a prezzi imbattibili. Usa il codice (acu639380) per accedere a:  100$ di sconto per nuovi utenti  100$ di sconto per clienti esistenti 40% di sconto extra su categorie selezionate Pacchetto di buoni da  100$ per nuovi e vecchi clienti Regalo di benvenuto gratuito per chi acquista per la prima volta Vantaggi Esclusivi dei Codici Sconto Temu Questi sconti sono pensati per ogni tipo di acquirente. Ottieni il massimo con: Codice Temu (acu639380)  100$ di sconto – Riduci il totale sui tuoi acquisti in blocco Codice Temu per utenti esistenti – Offerte premium riservate ai clienti fedeli Codice Temu per nuovi utenti – Grandi risparmi sul primo ordine Codice Temu 40% di sconto – Perfetto per moda e prodotti stagionali Pacchetto coupon da  100$ Temu – Risparmia su più ordini Coupon per nuovi utenti Temu – Inizia con un regalo + sconto Offerte Localizzate con il Codice Temu (acu639380) Grazie alla presenza globale di Temu, puoi accedere a offerte personalizzate ovunque ti trovi: Codice Temu  100$ di sconto – USA Codice Temu  100$ di sconto – Canada Codice Temu  100$ di sconto – Regno Unito Codice Temu  100$ di sconto – Giappone Codice Temu 40% di sconto – Messico Codice Temu 40% di sconto – Brasile Codice Temu  100$ di sconto – Germania Codice Temu  100$ di sconto – Francia Codice Temu per nuovi utenti – Argentina Coupon Temu per utenti esistenti – Italia Codice promozionale Temu (acu639380) – Spagna, giugno 2025 Cosa Comprare su Temu a Giugno 2025 L’ampio catalogo Temu include migliaia di categorie. Ecco alcuni articoli su cui usare il codice sconto (acu639380): Gadget intelligenti e accessori Moda per tutte le età Decorazioni per la casa e soluzioni salvaspazio Prodotti per il benessere, fitness e bellezza Utensili da cucina e pentolame Articoli per ufficio, giochi e regali La Mia Esperienza Risparmiando  100$ con il Codice Temu (acu639380) Quando ho usato il codice (acu639380) da cliente abituale, ho ricevuto immediatamente  100$ di sconto. Combinandolo con la promozione del 40% e il pacchetto da  100$, ho ottenuto oltre 200 $ di valore per meno di 80 $. Anche tu puoi farlo. Ti basta inserire (acu639380) al checkout, e lo sconto si applica automaticamente – con spedizione gratuita in tutto il mondo inclusa. Altri Sconti Temu per Giugno 2025 Questo mese è pieno di offerte a rotazione, pacchetti a sorpresa e vendite flash giornaliere. Resta aggiornato su: Nuove uscite con il coupon per nuovi utenti Temu Aggiornamenti settimanali dei codici per clienti esistenti Promozioni regionali con il codice (acu639380) per giugno 2025 Conclusione Ovunque ti trovi – in Nord America, Europa o Sud America – il codice Temu (acu639380) è la chiave per risparmiare alla grande. Con offerte per nuovi utenti e clienti fedeli, questo è il momento perfetto per approfittare dei prezzi imbattibili di Temu. Usa il codice acu639380 oggi stesso per ottenere vantaggi esclusivi e trasformare il tuo shopping in un’esperienza smart e conveniente.      
  • Topics

×
×
  • Create New...

Important Information

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