Posted August 23, 20223 yr im modding a server side mod i need to ban a player who has reached the time limit player, im counting player ticks and then kick him but idk how ban him
August 23, 20223 yr look at the code in BanPlayerCommands.banPlayers() 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 24, 20223 yr Author I need help to do this well, I have managed to get the program to ban when a specific time passes but it works 1 in 1 and I need it to count the time players spend on the server and if he exceeds a certain number of hours temporarily ban him. I got the ban but it doesn't control more than one player at a time
August 24, 20223 yr Show what you tried. "It doesn't work" type statements are useless. We are not psychic. 🙂 I don't know if these are useful to you, but every player has a number of Stats that keep track of durations (in ticks). e.g. Stats.PLAY_TIME or Stats.TIME_SINCE_DEATH You could also make your own Stat using a PlayerTickEvent if these are not what you want. Edited August 24, 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.
August 24, 20223 yr Author @SubscribeEvent public static void timerEventKick(TickEvent.PlayerTickEvent event) throws ParseException { ServerPlayer player = (ServerPlayer) event.player; System.err.println(timerToKick); if (event.phase == TickEvent.Phase.END){ timerToKick++; System.err.println(timerToKick); } if (event.phase == TickEvent.Phase.END && timerToKick == 200) { timerToKick = 0; UserBanList userbanlist = player.getServer().getPlayerList().getBans(); GameProfile gameprofile = player.getGameProfile(); Date date = date(); UserBanListEntry userbanlistentry = new UserBanListEntry(gameprofile, null, player.getName().getContents(), (Date)date, ""); userbanlist.add(userbanlistentry); player.connection.disconnect(new TextComponent("SE TE ACABO EL TIEMPO").withStyle(ChatFormatting.RED)); }
August 24, 20223 yr The most important part of that code for your question is "timerToKick" and yet you don't show how it is defined? I can deduce it must be a static field somewhere which means every player is updating/checking the same timer. Also, I guess you never tested this code on a client? It would crash on that unchecked cast to a ServerPlayer. 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 24, 20223 yr Author how i create a timer for every player?, i use value = Dist.Dedicated_Server, i dont need it in local player. but it works in Servers but only in 1 player because all players re updating the same timer
August 24, 20223 yr You can use one of those player stats I suggested. Or you can attach a player capability that holds the data. Look at "DataStorage" here: https://forge.gemwire.uk/wiki/Main_Page Edited August 24, 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.
August 24, 20223 yr Author if i use player stats i need to set a value. how i setvalue? im using player.getstats().setvalue(What i put here?); i need Play Time = 0
August 24, 20223 yr I don't think you want to reset the vanilla stat. Some other mod might be using for some other processing. You should make your own stat, something like: // Registration public static final DeferredRegister<ResourceLocation> STATS = DeferredRegister.create(Registry.CUSTOM_STAT_REGISTRY, MODID); public static final RegistryObject<ResourceLocation> MY_PLAY_TIME = STATS.register("my_play_time", () -> new ResourceLocation(MODID, "my_play_time")); @SubscribeEvent public static void tickHandler(TickEvent.PlayerTickEvent event) { if (event.side.isServer() && event.phase == Phase.END) { ServerPlayer player = (ServerPlayer) event.player; ServerStatsCounter stats = player.getStats(); // Increment the stat Stat<ResourceLocation> stat = Stats.CUSTOM.get(MY_PLAY_TIME.get()); player.awardStat(stat); // Check the stat int playTime = stats.getValue(stat); if (playTime >= 200) { player.resetStat(stat); // Your ban code here } } } You obviously need to register the STATS registry like other DeferredRegisters. And you will want to add something to your language file so the stat has a proper description in the stats screen. That way the players can see how long they have until they get banned. 🙂 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.