Jump to content

Reset all player stat when servers start


3mptysl

Recommended Posts

Im using this but doesnt work

@SubscribeEvent
    public static void serverStart(ServerStartedEvent event) {
        MinecraftServer server = event.getServer();
        Stat<ResourceLocation> stat = Stats.CUSTOM.get(StatsInit.MY_PLAY_TIME.get());
        server.getPlayerList().getPlayers().forEach(serverPlayer -> serverPlayer.resetStat(stat));
    }

 

Link to comment
Share on other sites

I need to ban a person when they have played 6 hours in a day and when the day is over, reset the time played so that they can play again. I have done it through a stats timeplayed when it reaches 6h it bans you and resets your time played but I don't know how to make it unban you when the day is over and also if you haven't been banned I reset your stat

Link to comment
Share on other sites

Subscribe to ServerTickEvent, in the Event you need to check the Time, you can get it from LocalTime#now.
Then check if the hour is 0 and if the second is 0, if this is the case clear the banned Players.

Note 1: Checking the second could lead problems if the server is laggy.
Note 2: You should not forget to reset the played time of all Players.

Link to comment
Share on other sites

To answer the original question.

Try something like this **untested** code in your server starting event:

        MinecraftServer server = event.getServer();
        File statsDir = server.getWorldPath(LevelResource.PLAYER_STATS_DIR).toFile();
        
        // Needs an access transformer
        PlayerDataStorage storage = server.playerDataStorage;

        // For each player with an entry in the playerdata folder
        String[] uuids = storage.getSeenPlayers();
        for (String uuid : uuids) {
            
            // Load, change and save the stats
            File playerStats = new File(statsDir, uuid + ".json");
            ServerStatsCounter stats = new ServerStatsCounter(server, playerStats);
            // YOUR CODE HERE
            stats.save();
        }

As it says, you will need an access transformer to make the playerDataStorage field in MinecraftServer public.

https://forge.gemwire.uk/wiki/Access_Transformers

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

I don't know how to use accesstransformers, I have put this in my accesstransformer.cfg:

public net.minecraft.world.level.storage.PlayerDataStorage <init>(Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;Lcom/mojang/datafixers/DataFixer;)V # PlayerDataStorage

but I still don't know what I should do since the server.playerDataStorage doesn't exist idk. what i need to put in accesstranformer.cfg? and how do i get playerDataStorage?

Link to comment
Share on other sites

You changed the **constructor** of PlayerDataStorage to public.

You want to change the playerDataStorage field of MinecraftServer.

 

The link I posted above shows an example of changing a field:

Quote

# Makes protected the 'COLOR_WHITE' field in Gui

protected net.minecraft.client.gui.Gui f_168667_ # COLOR_WHITE

So you need know what forge calls your field

 

There is probably a more efficient way to do this, but this is how I do it:

1) Look at Mojang's deobfuscation mapping to see what they call field:

https://piston-data.mojang.com/v1/objects/8e8c9be5dc27802caba47053d4fdea328f7f89bd/client.txt

With some searching you will find:

Quote

net.minecraft.server.MinecraftServer -> net.minecraft.server.MinecraftServer: 

 

     net.minecraft.world.level.storage.PlayerDataStorage playerDataStorage -> i

This tells you Mojang call the field "i"

 

Now you need to find out what forge calls it:

https://raw.githubusercontent.com/MinecraftForge/MCPConfig/master/versions/release/1.19.2/joined.tsrg

and again some searching is required

Quote

net/minecraft/server/MinecraftServer net/minecraft/src/C_4977_ 4977

 

    i f_129745_ 129745

 

Now you have all the information you need:

public net.minecraft.server.MinecraftServer f_129745_ # playerDataStorage

Double check my logic is correct, I haven't tested this.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

1 hour ago, warjort said:

There is probably a more efficient way to do this, but this is how I do it:

You should use the Forge Bot on the Forge Discord server.
Command:

!moj <class_name>.<field_name> <version> // The version is optional if you use the latest version (currently 1.19.2)

Use the command in #bot-commands channel

Link to comment
Share on other sites

No, you don't create the player, that will cause all kinds of issues.

You update the ServerStatsCounter directly. e.g. the equivalent of your player.resetStat(stat) is

stats.setValue(null, stat, 0);

Although setValue() takes a player as the first parameter, you can see in the code it doesn't actually use it. So you can pass "null".

 

The idea of using the ServerStatsCounter to update the value is so you don't have worry about the correct handling of the json format.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Is that a serious question? Did you even look at that class?

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Yes idk. i look TickEvent.ServerTickEvent class and i didnt see how i take MinecraftServer, because if i use WorldTickEvent i can take server with event.world.getServer()

maybe i'm tired and i don't see it.

Edited by 3mptysl
Link to comment
Share on other sites

Quote

I suspect the @warjortthought that you are using 1.19 since in 1.19 there is ServerTickEvent#getServer.

Correct.

It was also frustration at having to "spoon feed" every single line of code to the original poster.

I am not sure how much of this feature they have actually written for themselves. 🙂

 

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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

    • Halo para penggemar slot online! Apakah Anda mencari pengalaman bermain slot yang seru dan menguntungkan? Apakah Anda ingin menikmati slot gacor dari server Thailand sambil melakukan deposit melalui Mandiri dengan kesempatan meraih kemenangan besar? Anda telah sampai di tempat yang tepat! Kami di WINNING303 siap memberikan Anda pengalaman bermain yang mengasyikkan dan menguntungkan. Mengapa Memilih WINNING303? WINNING303 telah dikenal sebagai salah satu platform terbaik untuk bermain slot dengan berbagai keunggulan yang kami tawarkan kepada para pemain kami. Berikut adalah beberapa alasan mengapa Anda harus memilih WINNING303: Slot Gacor dari Server Thailand Kami menyajikan koleksi slot gacor terbaik dari server Thailand yang pastinya akan memberikan Anda pengalaman bermain yang menarik dan menguntungkan. Nikmati berbagai jenis permainan slot dengan tingkat kemenangan yang tinggi dan jackpot yang menarik. Deposit Mudah Melalui Mandiri Kami memahami pentingnya kemudahan dalam bertransaksi bagi para pemain kami. Oleh karena itu, kami menyediakan layanan deposit melalui bank Mandiri, salah satu bank terbesar di Indonesia. Proses depositnya cepat, mudah, dan aman, sehingga Anda dapat langsung memulai petualangan bermain tanpa hambatan. Peluang Maxwin Besar Di WINNING303, kami selalu memberikan peluang untuk meraih kemenangan besar. Dengan berbagai promosi dan bonus menarik yang kami sediakan, Anda memiliki kesempatan untuk memenangkan hadiah-hadiah yang fantastis dan meraih maxwin dalam bermain slot.  
    • SLOT Ratubet77 adalah bocoran slot gacor rekomendasi dari Ratubet77 yang bisa anda temukan di SLOT Ratubet77. Situs SLOT Ratubet77 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ratubet77 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ratubet77 merupakan SLOT Ratubet77 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 Ratubet77. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ratubet77 hari ini yang telah disediakan SLOT Ratubet77. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ratubet77 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 Ratubet77 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ratubet77 di link SLOT Ratubet77. DAFTAR SEKARANG DAFTAR SEKARANG DAFTAR SEKARANG
    • I am currently running the 1.20.1 Occultcraft modpack in Curseforge and am having numerous troubles making a mob farm with the apotheosis mod. When trying to modify the stats of the spawners specific stats such as the range, spawn count, and max entities reset to default after every spawn. When the spawners spawn boss mobs with certain attributes, that I'm not sure of, the building it is in explode even with mob griefing turned off. This has happened multiple times with varying sizes for the explosions. I was wonder if there is any way to disable these explosions from happening or disable boss abilities with something in the game. I also wanted to know a fix for the resetting stats on spawners and why this is happening.
    • SLOT Bank BSI adalah pilihan terbaik untuk Anda yang ingin merasakan sensasi bermain slot dengan layanan dari Bank BSI. Dengan keamanan terjamin, beragam pilihan permainan, kemudahan deposit via Bank BSI, dan berbagai bonus menarik, kami siap memberikan Anda pengalaman bermain yang tak terlupakan. Bergabunglah dengan kami sekarang dan mulailah petualangan seru Anda!    
    • Mengapa Memilih WINNING303? WINNING303 telah dikenal sebagai salah satu platform terbaik untuk bermain slot Pragmatic di Indonesia. Apa yang membuat kami unggul? Kami memiliki sejumlah keunggulan yang akan membuat pengalaman bermain Anda lebih menyenangkan. Keamanan Terjamin Keamanan adalah prioritas utama kami di WINNING303. Kami menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan Anda. Dengan begitu, Anda dapat bermain dengan tenang tanpa perlu khawatir tentang keamanan informasi Anda. Beragam Pilihan Permainan Kami menyediakan berbagai macam permainan slot Pragmatic yang menarik dan menghibur. Mulai dari tema klasik hingga yang paling modern, Anda pasti akan menemukan permainan yang sesuai dengan selera Anda di WINNING303. Selain itu, kami juga secara teratur memperbarui koleksi permainan kami untuk memberikan pengalaman bermain yang segar dan menarik setiap saat. Kemudahan Deposit Via Bank Niaga 24 Jam Kami mengerti bahwa kenyamanan dalam bertransaksi sangatlah penting bagi para pemain. Oleh karena itu, kami menyediakan layanan deposit melalui Bank Niaga yang dapat diakses 24 jam sehari, 7 hari seminggu. Prosesnya cepat dan mudah, sehingga Anda dapat langsung memulai permainan tanpa menunggu waktu lama. Bonus dan Promosi Menarik Di WINNING303, kami selalu memberikan bonus dan promosi yang menggiurkan bagi para pemain setia kami. Mulai dari bonus selamat datang hingga bonus deposit, ada banyak penawaran menarik yang dapat Anda manfaatkan untuk meningkatkan peluang kemenangan Anda.         
  • Topics

×
×
  • Create New...

Important Information

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