Skip to content

Commit

Permalink
Fix TPS slow down counter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SkinnyDevi committed Jul 11, 2023
1 parent 14363c9 commit 56b7db4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

mod_version=1.1.0-1.19.2
mod_version=1.1.1-1.19.2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.skinnydevi.playtimelimiter.PlaytimeLimiter;
import com.skinnydevi.playtimelimiter.config.ConfigManager;
import com.skinnydevi.playtimelimiter.playtime.PlaytimeDataManager;

import net.minecraft.ChatFormatting;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
Expand All @@ -13,11 +14,11 @@

import java.text.DecimalFormat;
import java.time.Duration;
import java.time.LocalTime;
import java.util.concurrent.TimeUnit;


public class PlayerJoinListener {

@SubscribeEvent
public void onMPPlayerJoin(PlayerEvent.PlayerLoggedInEvent e) {
if (!(e.getEntity() instanceof ServerPlayer))
Expand All @@ -39,6 +40,7 @@ public void onMPPlayerLeave(PlayerEvent.PlayerLoggedOutEvent e) {
}

private int tick;
private LocalTime oldTrackerTime = LocalTime.now();

@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent e) {
Expand All @@ -47,6 +49,11 @@ public void onServerTick(TickEvent.ServerTickEvent e) {
tick++;

if (tick % 20 == 0) {
LocalTime newTrackerTime = LocalTime.now();
float diff = Duration.between(oldTrackerTime, newTrackerTime).toMillis() / 1000f;
oldTrackerTime = newTrackerTime;
int workingSecond = Math.round(diff);

PlaytimeDataManager.getTrackedPlayers().forEach(playerMP -> {
if (playerMP.hasDisconnected()) {
PlaytimeDataManager.savePlayer(playerMP);
Expand All @@ -61,14 +68,14 @@ public void onServerTick(TickEvent.ServerTickEvent e) {
*/
if (ConfigManager.TRACK_TOTAL_PLAYTIME.get()) {
PlaytimeDataManager.setTotalPlayedTime(
playerMP, PlaytimeDataManager.getTotalPlayedTime(playerMP) + 1
playerMP, PlaytimeDataManager.getTotalPlayedTime(playerMP) + workingSecond
);
}

/*
Playtime Logic
*/
int newTime = PlaytimeDataManager.getRemainingTime(playerMP) - 1;
int newTime = PlaytimeDataManager.getRemainingTime(playerMP) - workingSecond;
PlaytimeDataManager.setRemainingTime(playerMP, newTime);

if (!compound.contains("timeout")) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ loaderVersion="[43,)" #mandatory This is typically bumped every Minecraft versio
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license="MIT"
# A URL to refer people to when problems occur with this mod
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
issueTrackerURL="https://github.com/SkinnyDevi/playtimelimiter/issues" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
Expand All @@ -25,7 +25,7 @@ displayName="§c§lPlaytime Limiter" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional
displayURL="https://www.curseforge.com/minecraft/mc-mods/skdvs-playtime-limiter-port-upgrade" #optional
# A file name (in the root of the mod JAR) containing a logo for display
logoFile="playtimelimiter-icon.png" #optional
# A text field displayed in the mod UI
Expand Down

0 comments on commit 56b7db4

Please sign in to comment.