Jump to content

ban a player who has reached the time limit played


3mptysl

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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


        }

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.



×
×
  • Create New...

Important Information

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