Posted August 26, 20223 yr 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)); }
August 26, 20223 yr There are no Players on there server in ServerStartedEvent. You should reset the Stat in EntityJoinLevelEvent PlayerLoggedInEvent (might be the better Event). Edited August 26, 20223 yr by Luis_ST
August 26, 20223 yr Statistics are loaded for a player when they first join the server. If you wanted to reset a stat, you should either do it when the player first joins after the restart via `PlayerLoggedInEvent` or read all JSONs in the player stats directory, reset the stat value, and write them back.
August 26, 20223 yr Author 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
August 26, 20223 yr 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.
August 26, 20223 yr 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.
August 27, 20223 yr Author 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?
August 27, 20223 yr 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.
August 27, 20223 yr 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
August 27, 20223 yr Author Okay, i did the access transformer and now how i get the player by uuids, because i need to restart a stats and i need a player parameter, i try to create a Player.createPlayerUUID(uuids) but i think is not the correct form.
August 27, 20223 yr 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.
August 27, 20223 yr Author Okayy, thats works perfect and how can i get MinecraftServer in ServerTickEvent, its possible?
August 27, 20223 yr 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.
August 27, 20223 yr Author 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 August 27, 20223 yr by 3mptysl
August 27, 20223 yr You then can use ServerLifecycleHooks#getCurrentServer, I suspect the @warjortthought that you are using 1.19 since in 1.19 there is ServerTickEvent#getServer.
August 27, 20223 yr 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 August 27, 20223 yr 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.
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.