-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
现在TimeRecorder会综合多个指标统计活跃度。活跃度权重可在配置文件中调整。
- Loading branch information
Showing
7 changed files
with
206 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/top/infsky/timerecorder/data/mcstats/McStatsManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package top.infsky.timerecorder.data.mcstats; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.stats.*; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.item.BlockItem; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.block.Block; | ||
|
||
import java.util.List; | ||
|
||
public class McStatsManager { | ||
public static final List<ResourceLocation> moveList = List.of(Stats.WALK_ONE_CM, Stats.SPRINT_ONE_CM, Stats.CROUCH_ONE_CM, | ||
Stats.SWIM_ONE_CM, Stats.WALK_ON_WATER_ONE_CM, Stats.WALK_UNDER_WATER_ONE_CM); | ||
|
||
public static double getMoveDistance(ServerStatsCounter stats) { | ||
double distance = 0; | ||
for (ResourceLocation stat : moveList) { | ||
distance += stats.getValue(Stats.CUSTOM.get(stat)); | ||
} | ||
return distance / 100; // 转换到block | ||
} | ||
|
||
public static long getItemPick(ServerStatsCounter stats) { | ||
long count = 0; | ||
for (Stat<Item> stat : Stats.ITEM_PICKED_UP) { | ||
count += stats.getValue(stat); | ||
} | ||
return count; | ||
} | ||
|
||
public static long getBlockBreak(ServerStatsCounter stats) { | ||
long count = 0; | ||
for (Stat<Block> stat : Stats.BLOCK_MINED) { | ||
count += stats.getValue(stat); | ||
} | ||
return count; | ||
} | ||
|
||
public static long getBlockPlace(ServerStatsCounter stats) { | ||
long count = 0; | ||
for (Stat<Item> stat : Stats.ITEM_USED) { | ||
if (stat.getValue() instanceof BlockItem) | ||
count += stats.getValue(stat); | ||
} | ||
return count; | ||
} | ||
|
||
public static long getEntityKilled(ServerStatsCounter stats) { | ||
long count = 0; | ||
for (Stat<EntityType<?>> stat : Stats.ENTITY_KILLED) { | ||
count += stats.getValue(stat); | ||
} | ||
return count; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/top/infsky/timerecorder/data/mcstats/StatsObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package top.infsky.timerecorder.data.mcstats; | ||
|
||
import lombok.Getter; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.stats.ServerStatsCounter; | ||
import top.infsky.timerecorder.config.ModConfig; | ||
|
||
@Getter | ||
public class StatsObject { | ||
private final ServerPlayer player; | ||
private final double startMoveDistance; | ||
private double cachedMoveDistance = 0; | ||
private final long startItemPick; | ||
private long cachedItemPick = 0; | ||
private final long startBlockBreak; | ||
private long cachedBlockBreak = 0; | ||
private final long startBlockPlace; | ||
private long cachedBlockPlace = 0; | ||
private final long startEntityKilled; | ||
private long cachedEntityKilled = 0; | ||
|
||
public StatsObject(ServerPlayer player, double startMoveDistance, long startItemPick, long startBlockBreak, long startBlockPlace, long startEntityKilled) { | ||
this.player = player; | ||
this.startMoveDistance = startMoveDistance; | ||
this.startItemPick = startItemPick; | ||
this.startBlockBreak = startBlockBreak; | ||
this.startBlockPlace = startBlockPlace; | ||
this.startEntityKilled = startEntityKilled; | ||
} | ||
|
||
public StatsObject(ServerPlayer player, ServerStatsCounter statsCounter) { | ||
this(player, McStatsManager.getMoveDistance(statsCounter), | ||
McStatsManager.getItemPick(statsCounter), | ||
McStatsManager.getBlockBreak(statsCounter), | ||
McStatsManager.getBlockPlace(statsCounter), | ||
McStatsManager.getEntityKilled(statsCounter) | ||
); | ||
} | ||
|
||
private boolean disabled() { | ||
return !ModConfig.INSTANCE.getAddon().isAllowOPActiveCount() && player.hasPermissions(2); | ||
} | ||
|
||
public double getMoveDistance(ServerStatsCounter statsCounter) { | ||
if (disabled()) return 0; | ||
cachedMoveDistance = McStatsManager.getMoveDistance(statsCounter) - startMoveDistance; | ||
return cachedMoveDistance; | ||
} | ||
|
||
public long getItemPick(ServerStatsCounter statsCounter) { | ||
if (disabled()) return 0; | ||
cachedItemPick = McStatsManager.getItemPick(statsCounter) - startItemPick; | ||
return cachedItemPick; | ||
} | ||
|
||
public long getBlockBreak(ServerStatsCounter statsCounter) { | ||
if (disabled()) return 0; | ||
cachedBlockBreak = McStatsManager.getBlockBreak(statsCounter) - startBlockBreak; | ||
return cachedBlockBreak; | ||
} | ||
|
||
public long getBlockPlace(ServerStatsCounter statsCounter) { | ||
if (disabled()) return 0; | ||
cachedBlockPlace = McStatsManager.getBlockPlace(statsCounter) - startBlockPlace; | ||
return cachedBlockPlace; | ||
} | ||
|
||
public long getEntityKilled(ServerStatsCounter statsCounter) { | ||
if (disabled()) return 0; | ||
cachedEntityKilled = McStatsManager.getEntityKilled(statsCounter) - startEntityKilled; | ||
return cachedEntityKilled; | ||
} | ||
} |