Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

 

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.

  • 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

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 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.

  • 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));


        }

 

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.

  • 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

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 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.

  • 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

 

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.