Skip to content

Commit

Permalink
Customization support
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaCartes committed Nov 27, 2023
1 parent 30546b7 commit 5c253fe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 40 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ Fabric mod that color nicknames based on their dimension.
Compatible with VT AFK Display and [Sessility](https://modrinth.com/mod/sessility) Mod.

Green = Overworld
Red = Nether
Purple = End
Red = The Nether
Purple = The End

This mod utilizes vanilla scoreboard teams to color nicknames.
To opt-out of detection you can join any other team.
This mod utilizes vanilla scoreboard teams to color nicknames.

## Customization
If you don't want to be detected, simply join a different team.
You can modify your team's color, add a prefix or suffix using the standard Minecraft [`/team` command](https://minecraft.wiki/w/Commands/team).
To add support for non-vanilla dimensions, create a team named `dimTracker.<dimension_name>`.

## [CurseForge](https://legacy.curseforge.com/minecraft/mc-mods/dimensional-tracker), [Modrinth](https://modrinth.com/mod/dimensionaltracker)

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.2+build.1
loader_version=0.14.22

# Mod Properties
mod_version=1.1.0
mod_version=1.2.0
maven_group=xyz.nikitacartes
archives_base_name=dimensionalTracker

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.scoreboard.ServerScoreboard;
import net.minecraft.scoreboard.Team;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -15,17 +16,12 @@
import java.util.LinkedHashSet;

public class DimensionalTracker implements ModInitializer {

private Team overworldTeam;
private Team netherTeam;
private Team endTeam;
public static LinkedHashSet<String> playerCache = new LinkedHashSet<>();

@Override
public void onInitialize() {
ServerLifecycleEvents.SERVER_STARTED.register(this::onServerStarted);
ServerTickEvents.END_SERVER_TICK.register(this::onServerTick);
ServerLifecycleEvents.SERVER_STOPPED.register(this::onServerStopped);

ServerPlayConnectionEvents.JOIN.register((netHandler, packetSender, server) -> playerCache.add(netHandler.getPlayer().getEntityName()));
ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> playerCache.add(newPlayer.getEntityName()));
Expand All @@ -41,17 +37,12 @@ private void onServerTick(MinecraftServer server) {
temp.forEach(playerName -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(playerName);
if (player != null) {
if (server.getScoreboard().getTeam(player.getEntityName()) == null) {
switch (player.getServerWorld().getRegistryKey().getValue().toString()) {
case "minecraft:overworld":
server.getScoreboard().addPlayerToTeam(player.getEntityName(), overworldTeam);
break;
case "minecraft:the_nether":
server.getScoreboard().addPlayerToTeam(player.getEntityName(), netherTeam);
break;
case "minecraft:the_end":
server.getScoreboard().addPlayerToTeam(player.getEntityName(), endTeam);
break;
ServerScoreboard scoreboard = server.getScoreboard();
Team playerTeam = scoreboard.getPlayerTeam(playerName);
if (playerTeam == null || playerTeam.getName().startsWith("dimTracker")) {
Team team = server.getScoreboard().getTeam("dimTracker." + player.getServerWorld().getRegistryKey().getValue().getPath());
if (team != null) {
scoreboard.addPlayerToTeam(playerName, team);
}
}
}
Expand All @@ -60,28 +51,15 @@ private void onServerTick(MinecraftServer server) {

private void onServerStarted(MinecraftServer minecraftServer) {
Scoreboard scoreboard = minecraftServer.getScoreboard();
overworldTeam = scoreboard.getTeam("dimTracker.overworld");
if (overworldTeam == null) {
overworldTeam = scoreboard.addTeam("dimTracker.overworld");
overworldTeam.setColor(Formatting.DARK_GREEN);
if (scoreboard.getTeam("dimTracker.overworld") == null) {
scoreboard.addTeam("dimTracker.overworld").setColor(Formatting.DARK_GREEN);
}
netherTeam = scoreboard.getTeam("dimTracker.nether");
if (netherTeam == null) {
netherTeam = scoreboard.addTeam("dimTracker.nether");
netherTeam.setColor(Formatting.DARK_RED);
if (scoreboard.getTeam("dimTracker.the_nether") == null) {
scoreboard.addTeam("dimTracker.the_nether").setColor(Formatting.DARK_RED);
}
endTeam = scoreboard.getTeam("dimTracker.end");
if (endTeam == null) {
endTeam = scoreboard.addTeam("dimTracker.end");
endTeam.setColor(Formatting.DARK_PURPLE);
if (scoreboard.getTeam("dimTracker.the_end") == null) {
scoreboard.addTeam("dimTracker.the_end").setColor(Formatting.DARK_PURPLE);
}
}

private void onServerStopped(MinecraftServer server) {
Scoreboard scoreboard = server.getScoreboard();
scoreboard.removeTeam(overworldTeam);
scoreboard.removeTeam(netherTeam);
scoreboard.removeTeam(endTeam);
}

}

0 comments on commit 5c253fe

Please sign in to comment.