Jump to content

Checking to see if the owner of (x) is logged in?


Cyan

Recommended Posts

Hello,

 

So I have some various timers and such running through OnLivingUpdate() for tamed entities, and I ran into a problem with these timers running even when the owner is not on.

 

So my question is, would there be a way to check to see if the owner is online so that they only run while the player is there? I'm currently using the vanilla taming method, as well as for getting the owner. Just need to figure out how to check to see if the owner is online.

 

Thanks,

Cyan.

Link to comment
Share on other sites

So, let me see if I understand.

a) You want these tamed beasts to despawn when the owner logs out?

b) You want the creatures to become still and inert when the owner logs out?

c) You want the creatures to revert to wild(untamed) vanilla status when the owner logs out?

d) Something else entirely?

Link to comment
Share on other sites

..None of the above.

 

I'm just looking for something I can use as a condition to check if the entities owner is online. That way I can make certain things in OnLivingUpdate() only run when the player is online.

Link to comment
Share on other sites

That way I can make certain things in OnUpdate() only run when the player is online.

Okay, just curious. Carry on then.

Link to comment
Share on other sites

That way I can make certain things in OnUpdate() only run when the player is online.

Okay, just curious. Carry on then.

 

If you wanted more details, you could have asked for more details. Communication makes the world go round. I'm looking for a condition to check if a player is online, nothing else. The details of the function are not really important to answering the question.

 

But since you asked so nicely..

What I'm aiming for is:

public void onLivingUpdate()
{
super.onLivingUpdate();

if (!this.worldObj.isRemote && isTamed() && CONDITIONTOCHECKIFOWNERISONLILNEHERE)
    {
    	energyticker++;
    
    	if (energyticker >700)
    	{
    		setEnergy(getEnergy() - 1);
    		if(getEnergy() < 0)
        	{
    			setEnergy(0);
        	}
    		
        energyticker = 0;
        System.out.println("Energy went down.");
    	}
    	}


 

Like I mentioned in the first post. Its just a simple timer. But it keeps decrementing on servers when the player is offline, SO I am trying to figure if there is a condition somewhere that I have missed to check to see if the owner of the entity is online. But after reading through your previous two posts, it is becoming a little more obvious that you really only skimmed my original post, and then decided to post a snide quip.

 

But for anyone else who may be able to help me out(or you should you decide knock off the snide comments), that is what I am trying to do.

Link to comment
Share on other sites

I have a lead for you. Something like this could help you out. This is completely untested and only based upon what I've found in the source code... you may have to adapt some changes.

 

function isOwnerOnline( String owner ) {
  // playerEntityList is a generic list containing EntityPlayerMP. This cast is just for convenience...
  List<EntityPlayerMP> players = (List<EntityPlayerMP)MinecraftServer.getServer().getConfigurationManager().playerEntityList;
  
  for( Iterator<EntityPlayerMP> it = players.iterator(); it.hasNext(); ) {
    EntityPlayerMP curr = it.next();
    if( curr.username == owner ) {
      return true;
    }
  }
  return false;
}

Link to comment
Share on other sites

Never use @SideOnly (*). It does not, what you think it does.

At the moment you are thinking of Server vs. Client as Server Thread vs. Client Thread (Server Thread may be on a different machine when using a dedicated server, but is on the same machine when playing Singleplayer).

@SideOnly though differentiates between Minecraft Client vs. Dedicated Server. That means: A method with @SideOnly(Side.SERVER) will not be present at all in the Minecraft Client and also not be present in the Integrated Server (because they are running on the same JVM). It will only exist on a Dedicated server.

To check for client thread vs. server thread use world.isRemote. You almost always got a world instance somewhere, every entity has one, every TileEntity has one, etc.

Also: Never use Minecraft.getMinecraft (or any other client-only stuff) in common code.

 

(*) Except on methods that override a method which already has @SideOnly (e.g. Block#registerIcons), then it is actually quite important to add it.

 

To be fair: I use @SideOnly(Side.CLIENT) on my client-sided classes/methods/fields to make sure they are really client-sided (helps to figure out if you use any client references where they shouldn't be while testing on the dedicated server)

 

B2T: To check if an user is currently logged into the server, use this:

Arrays.asList(MinecraftServer.getServer().getAllUsernames()).contains("USERNAME")

So in my case (sanandreasMC) you replace "USERNAME" with "sanandreasMC"

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Arrays.asList(MinecraftServer.getServer().getAllUsernames()).contains("USERNAME")

That is a horrible idea (especially if you check it every tick, like the OP plans to.

getAllUsernames needs to iterate the whole player list and copy the username into a (newly allocated) array. Then you convert that array to a list again, just to iterate it once again (that's what Arrays.asList().contains) does. If you really need to do this, iterate ServerConfigurationManager#playerEntityList directly and check for the username.

 

oooh, I thought the getAllUsernames uses a pre-defined array already... yeah than this is not at all a good idea, scratch that.

But there is the PlayerLoggedInEvent / PlayerLoggedOutEvent, as GotoLink mentioned, and it actually does fire on the server and client AFAIK

 

edit: Or you could always use the IPlayerTracker interface, It does the same things as the events do. Make a class which implements it and register a new instance of that class with GameRegistry.registerPlayerTracker()

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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

    • 🤑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.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Slot Aster88 adalah bocoran slot rekomendasi gacor dari Aster88 yang bisa anda temukan di SLOT Aster88. Situs SLOT Aster88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Aster88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Aster88 merupakan SLOT Aster88 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 Aster88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Aster88 hari ini yang telah disediakan SLOT Aster88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Aster88 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 Aster88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Aster88 di link SLOT Aster88.
    • 🚀Link Daftar Klik Disini🚀 Tips Bermain Slot Bank Jago agar Meraih Maxwin dan Jackpot di MAXWINBET77 Bermain slot online Bank jago adalah cara yang seru dan mengasyikkan untuk mencari keuntungan besar di MAXWINBET77. Jika kamu ingin meningkatkan peluangmu untuk meraih maxwin dan jackpot secara terus-menerus, ada beberapa tips dan strategi yang bisa kamu terapkan. Berikut adalah panduan lengkapnya: Pilih Slot dengan RTP Tinggi: RTP (Return to Player) adalah persentase rata-rata dari total taruhan yang dikembalikan kepada pemain sebagai kemenangan. Pilihlah mesin slot Bank jago yang memiliki RTP tinggi, karena ini meningkatkan peluangmu untuk meraih kemenangan dalam jangka panjang. Kenali Fitur Bonus: Setiap slot Bank jago memiliki fitur bonus yang berbeda, seperti putaran gratis, simbol liar (wild), dan bonus game. Pelajari dengan baik fitur-fitur ini karena mereka dapat membantu meningkatkan peluang meraih kemenangan besar. Kelola Taruhan dengan Bijak: Tentukan batasan taruhan yang sesuai dengan budget dan jangan tergoda untuk bertaruh melebihi kemampuan finansialmu. Terapkan strategi taruhan yang bijak untuk memaksimalkan penggunaan saldo. Mainkan Slot Bank jago Progresif: Jika tujuanmu adalah meraih jackpot besar, coba mainkan slot Bank jago progresif di MAXWINBET77. Jackpot pada jenis slot Bank ini terus bertambah seiring dengan taruhan pemain lainnya, sehingga dapat mencapai jumlah yang sangat besar. Manfaatkan Promosi dan Bonus: MAXWINBET77 sering kali menawarkan promosi dan bonus kepada pemainnya. Manfaatkan bonus-bonus ini untuk meningkatkan peluangmu meraih kemenangan tanpa menggunakan modal tambahan. Berkonsentrasi dan Bersabar: Fokuslah saat bermain slot bank jago dan jangan terburu-buru. Bersabarlah meskipun tidak langsung mendapatkan hasil yang diharapkan. Kadang-kadang diperlukan waktu dan keberuntungan untuk mencapai maxwin atau jackpot. Baca Aturan Permainan: Sebelum bermain, pastikan untuk membaca aturan dan pembayaran pada slot Bank Jago yang dipilih. Mengetahui cara kerja mesin slot akan membantu mengoptimalkan strategi bermainmu. Dengan menerapkan tips-tips di atas dan tetap bermain secara bertanggung jawab, kamu dapat meningkatkan peluang meraih maxwin dan jackpot di Slot Bank Jago MAXWINBET77. Selamat bermain dan semoga sukses meraih kemenangan besar Anda Hari Ini.
  • Topics

×
×
  • Create New...

Important Information

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