Skip to content

Commit ef3e08f

Browse files
chore: fix offline player name fetching
1 parent 71d5bb4 commit ef3e08f

3 files changed

Lines changed: 43 additions & 4 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package net.swofty.type.generic.command.commands;
2+
3+
import net.minestom.server.command.builder.arguments.ArgumentString;
4+
import net.minestom.server.command.builder.arguments.ArgumentType;
5+
import net.swofty.type.generic.command.CommandParameters;
6+
import net.swofty.type.generic.command.HypixelCommand;
7+
import net.swofty.type.generic.data.HypixelDataHandler;
8+
import net.swofty.type.generic.user.HypixelPlayer;
9+
import net.swofty.type.generic.user.categories.Rank;
10+
11+
import java.util.UUID;
12+
13+
@CommandParameters(aliases = "getnameformatted",
14+
description = "Gets the format of a players name from their username",
15+
usage = "/formatname <name>",
16+
permission = Rank.ADMIN,
17+
allowsConsole = false)
18+
public class FormatNameCommand extends HypixelCommand {
19+
@Override
20+
public void registerUsage(MinestomCommand command) {
21+
ArgumentString playerArgument = ArgumentType.String("player");
22+
23+
command.addSyntax((sender, context) -> {
24+
if (!permissionCheck(sender)) return;
25+
26+
String playerName = context.get(playerArgument);
27+
HypixelPlayer player = (HypixelPlayer) sender;
28+
UUID uuid = HypixelDataHandler.getPotentialUUIDFromName(playerName);
29+
30+
if (uuid == null) {
31+
player.sendMessage("Nope doesn't exist");
32+
return;
33+
}
34+
35+
player.sendMessage(HypixelPlayer.getDisplayName(uuid));
36+
player.sendMessage(HypixelPlayer.getRawName(uuid));
37+
}, playerArgument);
38+
}
39+
}

type.generic/src/main/java/net/swofty/type/generic/data/HypixelDataHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public static HypixelDataHandler getOfOfflinePlayer(UUID uuid) throws RuntimeExc
135135
if (userCache.containsKey(uuid))
136136
return (HypixelDataHandler) userCache.get(uuid);
137137

138-
ProfilesDatabase profilesDatabase = new ProfilesDatabase(uuid.toString());
139-
Document doc = profilesDatabase.getDocument();
138+
UserDatabase userDatabase = new UserDatabase(uuid.toString());
139+
Document doc = userDatabase.getHypixelData();
140140
return createFromDocument(doc);
141141
}
142142

type.generic/src/main/java/net/swofty/type/generic/user/HypixelPlayer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static String getDisplayName(UUID uuid) {
5252
return HypixelGenericLoader.getLoadedPlayers().stream().filter(player -> player.getUuid().equals(uuid)).findFirst().get().getFullDisplayName();
5353
} else {
5454
// Fallback for offline name display: use Hypixel account data (rank + ign)
55-
HypixelDataHandler account = HypixelDataHandler.getUser(uuid);
55+
HypixelDataHandler account = HypixelDataHandler.getOfOfflinePlayer(uuid);
5656
return account.get(HypixelDataHandler.Data.RANK, DatapointRank.class).getValue().getPrefix() +
5757
account.get(HypixelDataHandler.Data.IGN, DatapointString.class).getValue();
5858
}
@@ -62,7 +62,7 @@ public static String getRawName(UUID uuid) {
6262
if (HypixelGenericLoader.getLoadedPlayers().stream().anyMatch(player -> player.getUuid().equals(uuid))) {
6363
return HypixelGenericLoader.getLoadedPlayers().stream().filter(player -> player.getUuid().equals(uuid)).findFirst().get().getUsername();
6464
} else {
65-
HypixelDataHandler account = HypixelDataHandler.getUser(uuid);
65+
HypixelDataHandler account = HypixelDataHandler.getOfOfflinePlayer(uuid);
6666
return account.get(HypixelDataHandler.Data.IGN, DatapointString.class).getValue();
6767
}
6868
}

0 commit comments

Comments
 (0)