Jump to content

[SOLVED] [1.10] Player connect event ?


DBLouis

Recommended Posts

Hi,

 

I'm looking for an event that Forge is firing when a player connect to the server. Everything I found on Google is old stuffs ...

 

EDIT :

 

I found this : FMLServerAboutToStartEvent

It says "Called after FMLPostInitializationEvent on the dedicated server, and after the player has hit "Play Selected World" in the client", but I wanna be sure if this is also fired when connecting to a server.

 

Link to comment
Share on other sites

No, that is only fired when the server initially starts.

 

You can subscribe to

PlayerEvent.PlayerLoggedInEvent

alt either

FMLNetworkEvent.ClientConnectedToServerEvent

or

FMLNetworkEvent.ServerConnectionFromClientEvent

.

ClientConnectedToServerEvent

is only fired on the client, and

ServerConnectionFromClientEvent

is thus, only fired on the server.

 

I've also heard that the

PlayerEvent.PlayerLoggedInEvent

requires you to wait a tick before doing anything, as the event is fired before the player-entity is created.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

How can I get the PlayerLoggedInEvent from ServerConnectionFromClientEvent ?

 

EDIT: Like this ?

 

@SubscribeEvent

public void onPlayerLoggedIn(PlayerLoggedInEvent event) {

    if (event.player.isServerWorld()) {

        EntityPlayerMP player = (EntityPlayerMP) event.player;

        ...

    }

}

Link to comment
Share on other sites

How can I get the PlayerLoggedInEvent from ServerConnectionFromClientEvent ?

Those are 2 different events altogether. They both fire when the player connects to the server, but in different places.

 

Don't cast the Player to EntityPlayerMP or EntityPlayerSP unless you really do have to. Most if not all you really need exist in EntityPlayer already, which is what the event#player is.

Entity->EntityLivingBase->EntityPlayer-> [EntityPlayerSp | EntityPlayerMP]. SP/MP are the same thing, just on the opposite sides of the server/client coin.

 

If you only want to do something server-side, check if

event#player#worldObj#isRemote

returns false, and then do something, instead of checking

isServerWorld()

.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

I don't need ServerConnectionFromClientEvent then.

How can I check that the server is dedicated ? I want to exclude the integrated server case.

 

I need an EntityPlayerMP to call a method, so I have to cast, but I think it's safe if I checked on what side I am before.

Link to comment
Share on other sites

Aaaaah. My bad then.

You can simply skip checking what side you are on, and focus directly on the player instead.

Your previous code-snippet should be fine to run, however, it is not explicitly safe.

If you are on a server, the player should be EntityPlayerMP, yes, however, you never actually check if the player IS EntityPlayer first.

You can cast classes to equal or super classes. You cannot cast it to another forked class like EntityPlayerMP/SP are.

 

You can simply check:

if(event.player instanceof EntityPlayerMP){
   EntityplayerMP player = (EntityPlayerMP) event.player;
   //Rest of your code.
}

That is explicitly safe casting. Only cast to what you know you are casting to.

Who knows, with the power of Java, pigs can easily fly. A mod spawning an EntityPlayerSP on a server wouldn't be too hard to imagine, bar for what possible reason.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

No.

 

There are always 2 sides. There is one Entity for each side.

Client + Integrated (also integrated LAN)

Client + Dedicated (or other non-integrated, like outside LAN).

 

EntityPlayer is a special Entity where Client thread uses AbstractClientPlayer (for EntityPlayer you control, Minecraft#thePlayer, it's EntityPlayerSP), server thread uses EntityPlayerMP.

So to answer your question - "if (player instanceof EntityPlayerMP)" is almost same check as "if (!World#isRemote)" - where remote means that code is ran on client (so negative is server). you can sue Entity#worldObj to check logical side.

More here: http://mcforge.readthedocs.io/en/latest/concepts/sides/

 

Now - you shouldn't create mods that are physical-side specific (meaning they work differently on dedic and integrated). It will get messy for a novice. If you are planning on writing sided mods you should be writing two mods such as one for ONLY dedic, and one for ONLY client.

Otherwise you should write universal mod (and for real - dedic and integrated is the same thing, so it's easier this way).

 

To solve your problem in best possible way - please describe the goal you are after, including on what side what should happen. Some of code/events are reserved for specific sides so it's important to state end-goal (like e.g: checking if server is dedic looks different for server and different for client that connects to it).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I probably should have explain the purpose of this at the beginning  ;D

The dedicated server must send some settings to the connected clients : recipes, block hardness and resistance ...

This is dedicated server behavior only, not integrated.

Link to comment
Share on other sites

If you want your mod to be "universal" (keep it in one .jar), this is step by step on how I'd do it:

 

Events part:

1. Create DedicatedServerEvents.class. Mark it with @SideOnly(Side.SERVER).

2. @SubscribeEvent to PlayerLoggedInEvent in class above.

3. Register class above from ServerProxy (call during preInit).

4. At this point whenever mod is ran on dedicated server (so ServerProxy is fired), you will be firing event for all players that log in on this server.

 

Dedicated part:

1. In ServerProxy load (during preInit) your data from files (using forge config or configs of your design).

2. Place loaded data in @SideOnly(Side.SERVER) static storage - it could be for example Map<Block, Double> for block hardness or other ways for different values.

3. Use loaded data to change vanilla values. In mod's init (ServerProxy) call Block#setHardness and other methods you want and use data you loaded from config.

4. At this point whenever mod is ran on dedicated server (so ServerProxy is fired), you will be modifying vanilla properties with stuff loaded from configs while storing this data in static maps. @SideOnly also prevents those classes/fields from existing on Client.jar, so there is that.

 

Syncing stuff:

1. Create SimpleNetworkWrapper and proper IMessages (remember about thread safety).

2. In PlayerLoggedInEvent send data from server's static maps to client (serialize them into something and deserialize on receiving client).

3. On receiver client modify proper Blocks by puling them from registry by names (So e.g: in your packet you send arrays of stuff like: "modid:blockname"=5.0D).

 

This should work assuming vanilla allows such hot-modifications to hardness values.

 

Note that similar effects (for only some of block properties) can be achieved with HarvestSpeed (or whetever the name was) and some other events.

 

BIG NOTE: Mind EVERY word I wrote - each one of them is important as they directly describe possible design approach.

 

Questions?

1.7.10 is no longer supported by forge, you are on your own.

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

    • LINK DAFTAR : https://bit.ly/daftarpaguyuban4d Paguyuban4d💎⚡Demo 88 Slot Dewa Gacor Malam Ini: Raih Jackpot Besar dan Sensasi Seru! Sensasi Seru Bermain Slot di Paguyuban4d💎⚡Demo 88 Bro, sist, mas, adek, gokil banget nih kalo lo lagi main slot di Paguyuban4d💎⚡Demo 88! Menurut Google, tempat ini bener-bener dewa gacor malam ini. Gak percaya? Baca terus yuk! Keuntungan Bermain di Paguyuban4d💎⚡Demo 88 Kalo lo pengen jackpot besar dan sensasi seru, main di Paguyuban4d💎⚡Demo 88 adalah pilihan yang tepat! Mereka punya RTP (Return to Player) tinggi dan jackpotnya gacor banget, bro! Jadi kesempatan lo buat menang besar tuh lebih besar! Cara Deposit, Withdraw, dan Dapatkan Bonus Gimana sih cara deposit, withdraw, dan dapetin bonus di Paguyuban4d💎⚡Demo 88? Gampang bro! Cukup masukin duit ke akun lo, main sepuasnya, terus kalo menang, langsung aja tarik duitnya. Bonusnya? Wah, banyak banget, lo! Pola Bermain yang Bikin Nagih Pola bermain di Paguyuban4d💎⚡Demo 88 emang bikin nagih, bro! Setiap putaran bener-bener seru dan nggak bikin bosen. Dan yang paling asik, lo bisa main kapan aja dan di mana aja, asal ada koneksi internet! FAQ (Frequently Asked Questions): Apakah Paguyuban4d💎⚡Demo 88 aman buat dimainin? Absolut aman, bro! Mereka punya sistem keamanan yang super canggih! Bagaimana cara mendaftar jadi member? Caranya simpel banget, bro! Kunjungi situs resminya, isi data diri, dan ikuti langkah-langkahnya. Apa saja game lain yang tersedia di Paguyuban4d💎⚡Demo 88? Mereka punya berbagai macam game, termasuk slot, togel, dan live casino yang nggak kalah seru! Bagaimana cara dapetin bonus new member? Tinggal daftar, deposit, dan bonusnya langsung masuk ke akun lo. Mudah banget kan? Kesimpulan Pokoknya, kalo lo lagi nyari sensasi bermain slot yang bener-bener asli dan menguntungkan, langsung aja ke Paguyuban4d💎⚡Demo 88. Dijamin nggak nyesel, bro! Yuk, buruan gabung dan raih kemenanganmu sekarang juga!
    • EXTRAWD : Daftar Bandar Togel Online Resmi Bet 100 Perak Terbaik! Situs EXTRAWD telah memperkenalkan konsep taruhan togel online resmi termurah dari semua situs dengan hanya bet 100 perak terjangkau dengan bet 100 perak ini dunia togel online resmi yang semakin berkembang telah menjawab bahwa EXTRAWD memberikan alternatif menarik bagi para penikmat situs togel resmi tuk mencari pengalaman bermain togel online resmi terjangkau bet 100 perak tanpa mengorbankan kualitas dan keamanan. Dengan bet 100 perak termurah ini, EXTRAWD selaku situs bandar togel resmi terbaik memberikan kesempatan bagi berbagai kalangan untuk ikut serta dalam permainan togel resmi tanpa harus mengeluarkan modal besar tetapi gampang meraup cuan besar dari hadiah togel terbesar ditawarkan EXTRAWD. Sebagai bandar togel resmi, EXTRAWD menjaga reputasi dan menjunjung keadilan dengan menawarkan layanan live chat EXTRAWD transparan dan terpercaya kepada para pelanggan togel online resmi dengan sistem keamanan yang canggih, EXTRAWD memastikan bahwa setiap taruhan togel online resmi diproses dengan aman dan hasilnya benar diacak dan adil. Hal ini memberikan kepercayaan kepada para pemain dari situs bandar togel terbaik bahwa mereka bermain di situs bandar togel terbaik aman dan dapat diandalkan. Dengan taruhan di EXTRAWD selaku penyedia situs togel resmi sekaligus bandar togel resmi terjangkau bet 100 perak telah membawa permainan togel online resmi menjadi solusi situs bandar togel terbaik kepada semua pemain togel online resmi tanpa harus mengeluarkan modal besar untuk bermain togel online resmi, Ini membuka pintu bagi banyak orang sebelumnya mungkin merasa enggan mencoba peruntungan permainan di situs togel resmi, Bet 100 perak membuka kesempatan besar bagi setiap pemain untuk meraih hadiah togel terbesar di berbagai pasaran togel daftar togel resmi, merasakan hadiah togel terbesar dari hasil bet 100 perak di togel online resmi EXTRAWD dengan resiko minim namun berpotensi, Buruan nikmati kesempatan ini dan daftar togel resmi.
    • Paguyuban4d💎⚡Rtp Slot 100 Asli Orang Dalam Bocoran Admin Jarwo Bermain Slot di Paguyuban4d: Sensasi Seru dan Keuntungan Nyata Bro, sist, mas, adek, wakgenk, atau siapapun yang doyan main slot online, kalian harus tau nih tentang Paguyuban4d💎⚡Rtp Slot 100 Asli. Menurut Google, Paguyuban4d adalah tempat yang paling oke buat main slot dengan sensasi seru dan keuntungan nyata yang bener-bener asli. Keuntungan Bermain di Paguyuban4d💎⚡ Dari pada main slot di tempat lain yang cuma bikin frustasi, mendingan main di Paguyuban4d💎⚡. Mereka punya RTP (Return to Player) tinggi, jadi kesempatan menang lo lebih besar. Plus, jackpotnya gacor banget, bro! Cara Deposit, Withdraw, dan Bonus di Paguyuban4d💎⚡ Gimana sih cara deposit, withdraw, dan dapetin bonus di Paguyuban4d💎⚡? Gampang bro, lo cukup masukin duit ke akun lo, main sepuasnya, terus kalo menang, langsung aja tarik duitnya. Bonusnya? Dijamin nggak nyesel deh, banyak banget! Pola Bermain yang Bikin Nagih Pola bermain di Paguyuban4d💎⚡ emang bikin nagih, bro! Setiap putaran bener-bener seru dan nggak bikin bosen. Dan yang paling asik, lo bisa main kapan aja dan di mana aja, asal ada koneksi internet! FAQ (Frequently Asked Questions): Apakah Paguyuban4d💎⚡ aman buat dimainin? Yup, gak usah khawatir, mereka punya sistem keamanan yang super canggih! Bagaimana cara mendaftar jadi member? Caranya simpel banget, bro! Kunjungi situs resminya, isi data diri, dan ikuti langkah-langkahnya. Apa saja game lain yang tersedia di Paguyuban4d💎⚡? Mereka punya berbagai macam game, termasuk slot, togel, dan live casino yang nggak kalah seru! Bagaimana cara dapetin bonus new member? Tinggal daftar, deposit, dan bonusnya langsung masuk ke akun lo. Mudah banget kan? Kesimpulan Pokoknya, kalo lo lagi nyari sensasi bermain slot yang bener-bener asli dan menguntungkan, langsung aja ke Paguyuban4d💎⚡. Dijamin nggak nyesel, bro! Yuk, buruan gabung dan raih kemenanganmu sekarang juga!
    • Paguyuban4d💲📢 Live HK | Hongkong | Hongkongpoolstoday Serunya Bermain Live HK di Paguyuban4d💲📢 Bro, sist, adek, atau mas, udah pada tau belum serunya bermain live HK di Paguyuban4d💲📢? Menurut Google, tempat ini emang juara dalam menyajikan pengalaman bermain yang nggak bisa lo dapetin di tempat lain. Keuntungan Bermain di Paguyuban4d💲📢 Kalo lo pengen dapet keuntungan maksimal dalam bermain game online, gak ada salahnya mampir ke Paguyuban4d💲📢, bro! Mereka punya beragam game seru, live HK yang bikin nagih, dan bonus-bonus yang menggiurkan. Cara Deposit, Withdraw, dan Bonus di Paguyuban4d💲📢 Nah, bro, sist, gue mau kasih tau nih gimana cara deposit, withdraw, dan dapetin bonus di Paguyuban4d💲📢. Pertama-tama, lo cukup daftar jadi member, lalu deposit dana ke akun lo. Kalo udah, tinggal main sepuasnya dan kalo menang, tinggal withdraw aja duitnya. Plus, jangan lupa dapetin bonus new member yang bikin semangat! Pola Bermain yang Bikin Ketagihan Di Paguyuban4d💲📢, pola bermainnya emang bikin ketagihan, bro! Setiap putaran memberikan sensasi yang berbeda dan live HK yang disajikan secara langsung bakal bikin lo makin excited. Gak heran kalo Paguyuban4d💲📢 selalu jadi pilihan utama para pecinta judi online. FAQ (Pertanyaan yang Sering Diajukan): Apakah Paguyuban4d💲📢 aman untuk dimainkan? Yup, tentu aja! Mereka udah punya reputasi bagus dan sistem keamanan yang canggih. Bagaimana cara mendaftar menjadi member? Caranya simpel, bro! Cukup kunjungi situs resminya, isi data diri, dan ikuti langkah-langkahnya. Apa saja permainan yang tersedia di Paguyuban4d💲📢? Mereka punya berbagai macam permainan, termasuk live HK yang bisa lo nikmatin setiap harinya. Bagaimana cara mendapatkan bonus new member? Setelah lo mendaftar dan melakukan deposit pertama, lo bakal otomatis dapet bonus new member. Seru kan? Kesimpulan Jadi, kalo lo lagi nyari pengalaman bermain live HK yang seru dan menguntungkan, Paguyuban4d💲📢 ini jawabannya, bro! Dengan beragam keuntungan dan pola bermain yang bikin ketagihan, lo bakal betah main di sini. Yuk, buruan gabung dan raih kemenanganmu!
  • Topics

×
×
  • Create New...

Important Information

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