Skip to content

Commit

Permalink
make compatible with 1.19+
Browse files Browse the repository at this point in the history
no more fabric.mod.json updates!!! yipeeee
(requires Fabric API tho)
- 1.16+ coming soon (fabric-command-api-v1)
  • Loading branch information
not-coded committed May 8, 2024
1 parent a055e70 commit 13fdb9a
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 94 deletions.
60 changes: 60 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# gradle

.gradle/
Expand Down
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# NameFabric

![Fabric](https://raw.githubusercontent.com/intergrav/devins-badges/1a0c6742ac5929b4597b417a74a124a30cf3461f/assets/cozy/supported/fabric_vector.svg) ![Minecraft](https://notcoded.needs.rest/r/badge_minecraft_1.16plus.svg)
---------------------------------------
[![Fabric](https://raw.githubusercontent.com/intergrav/devins-badges/1a0c6742ac5929b4597b417a74a124a30cf3461f/assets/cozy/supported/fabric_vector.svg)](https://fabricmc.net/use/installer) [![Quilt](https://raw.githubusercontent.com/intergrav/devins-badges/1aec26abb75544baec37249f42008b2fcc0e731f/assets/cozy/supported/quilt_vector.svg)](https://quiltmc.org/en/install/) [![Minecraft](https://notcoded.needs.rest/r/badge_minecraft_1.16plus.svg)](https://minecraft.net)

NameFabric, the mod that shows you public player data like past usernames, current skin, and more using LabyNet's and Mojang's API.

## Download
[Modrinth](https://modrinth.com/mod/namefabric) - [CurseForge](https://www.curseforge.com/minecraft/mc-mods/namefabric/) - [GitHub](https://github.com/not-coded/NameFabric/releases/)
This mod allows you to get public player data like past usernames, current skin, and more using [LabyNet's](https://laby.net) and [Mojang's API](https://api.mojang.com).

## Features
- /namehistory | Gets the past names of the specified player
- /getuuid | Gets the uuid of the specified player
- /getskin | Gets the current skin of the specified player
- /getcape | Gets the current cape of the specified player

## Known Issues:
- If you put anything with the same length as 32 or 36 it will cause an error in the commands.
- **/namehistory** | Gets the past names of a player.
- **/getuuid** | Gets the uuid of a player.
- **/getskin** | Gets the current skin of a player.
- **/getcape** | Gets the current cape of a player.
19 changes: 10 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
plugins {
id 'fabric-loom' version '0.13.20'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version + "+" + project.minecraft_version
version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

include(modApi(fabricApi.module("fabric-command-api-v2", project.fabric_version)))
include(modApi(fabricApi.module("fabric-api-base", project.fabric_version)))
include(modApi(fabricApi.module("fabric-resource-loader-v0", project.fabric_version)))
modImplementation("net.fabricmc.fabric-api:fabric-api:$project.fabric_version")
}

processResources {
Expand All @@ -38,6 +36,9 @@ java {
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

jar {
Expand Down
17 changes: 9 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.14.21
# check these on https://fabricmc.net/develop
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
loader_version=0.14.21


# Mod Properties
mod_version = 1.0.3
maven_group = net.notcoded
archives_base_name = namefabric
mod_version = 1.0.4
maven_group = net.notcoded
archives_base_name = namefabric

# Dependencies
fabric_version=0.91.1+1.20.4
fabric_version=0.97.5+1.20.5
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue May 07 15:32:39 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 6 additions & 4 deletions src/main/java/net/notcoded/namefabric/Main.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.notcoded.namefabric;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.notcoded.namefabric.loaders.CommandLoader;

public class Main implements ModInitializer {
public class Main implements ClientModInitializer {
@Override
public void onInitialize() {
ClientCommandRegistrationCallback.EVENT.register(CommandLoader::registerCommands);
public void onInitializeClient() {
if(FabricLoader.getInstance().isModLoaded("fabric-command-api-v2"))
ClientCommandRegistrationCallback.EVENT.register(CommandLoader::registerCommands);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GetCapeCommand {
private static final HttpClient httpClient = HttpClient.newHttpClient();
private static final int DURATION = 5; // seconds

private static String PlayerName;
private static String playerName;
private static boolean isUsingPlayerName = false;
public static HashMap<String, String> capes = new HashMap<>();
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
Expand Down Expand Up @@ -74,7 +74,7 @@ private static int getCapesUUID(@NotNull FabricClientCommandSource source, @NotN
JsonElement result = JsonParser.parseString(response);
if(!isUsingPlayerName){
JsonElement result1 = JsonParser.parseString(response);
PlayerName = result1.getAsJsonObject().get("name").getAsString();
playerName = result1.getAsJsonObject().get("name").getAsString();
}
try {
if (result.getAsJsonObject().getAsJsonArray("properties").get(0).getAsJsonObject().get("value").getAsString() != null) {
Expand All @@ -91,14 +91,14 @@ private static int getCapesUUID(@NotNull FabricClientCommandSource source, @NotN
} catch (Exception ignored){
}

source.sendFeedback(Text.translatable("command.getcape.success", PlayerName, identifyCape(capeurl)));
source.sendFeedback(Text.translatable("command.getcape.success", playerName, identifyCape(capeurl)));
}));


} else {
source.sendError(Text.translatable("command.all.invalid.uuid"));
}
PlayerName = null;
playerName = null;
isUsingPlayerName = false;
return Command.SINGLE_SUCCESS;
}
Expand All @@ -108,7 +108,7 @@ public static int getCapesPlayer(FabricClientCommandSource source, @NotNull Stri

if (uuid != null && (uuid.length() == 32 || uuid.length() == 36)) {
try {
PlayerName = name;
playerName = name;
isUsingPlayerName = true;
getCapesUUID(source, uuid);
} catch (Exception e) {
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/net/notcoded/namefabric/command/GetSkinCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Text;
import net.notcoded.namefabric.Main;
import net.notcoded.namefabric.utils.MinecraftAPI;

import java.net.URI;
Expand All @@ -26,7 +24,7 @@

public class GetSkinCommand {

private static String PlayerName;
private static String playerName;
private static boolean isUsingPlayerName = false;

private static final HttpClient httpClient = HttpClient.newHttpClient();
Expand Down Expand Up @@ -67,14 +65,15 @@ private static int getSkinsUUID(FabricClientCommandSource source, String uuid) {
JsonElement result = JsonParser.parseString(response);
if(!isUsingPlayerName){
JsonElement result1 = JsonParser.parseString(response);
PlayerName = result1.getAsJsonObject().get("name").getAsString();
playerName = result1.getAsJsonObject().get("name").getAsString();
}
try {
if (result.getAsJsonObject().getAsJsonArray("properties").get(0).getAsJsonObject().get("value").getAsString() != null) {
skinurl = new String(Base64.getDecoder().decode(result.getAsJsonObject().getAsJsonArray("properties").get(0).getAsJsonObject().get("value").getAsString()));
}
} catch (Exception e) {
source.sendError(Text.translatable("command.all.error"));
return;
}
try{
if(skinurl != null && !skinurl.trim().isEmpty()){
Expand All @@ -83,31 +82,38 @@ private static int getSkinsUUID(FabricClientCommandSource source, String uuid) {
}
} catch (Exception e){
source.sendError(Text.translatable("command.all.error"));
return;
}

String finalSkinurl = skinurl;

if(finalSkinurl == null) {
source.sendError(Text.translatable("command.all.error"));
return;
}

Text skinText = Text.literal(finalSkinurl).styled(style -> style
.withUnderline(true)
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal("Click to open the link!")))
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, finalSkinurl))
);
source.sendFeedback(Text.translatable("command.getskin.success", PlayerName, skinText));
source.sendFeedback(Text.translatable("command.getskin.success", playerName, skinText));
});
});


} else {
source.sendError(Text.translatable("command.all.invalid.uuid"));
}
PlayerName = null;
playerName = null;
isUsingPlayerName = false;
return Command.SINGLE_SUCCESS;
}
public static int getSkinsPlayer(FabricClientCommandSource source, String name) {
String uuid = MinecraftAPI.getUUID(name);
if(uuid != null && !uuid.trim().isEmpty()){
try {
PlayerName = name;
playerName = name;
isUsingPlayerName = true;
getSkinsUUID(source, uuid);
} catch (Exception e) {
Expand Down
57 changes: 21 additions & 36 deletions src/main/java/net/notcoded/namefabric/command/GetUuidCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.notcoded.namefabric.command;


import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;

import net.minecraft.text.ClickEvent;
Expand All @@ -18,50 +18,35 @@

public class GetUuidCommand {


public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(ClientCommandManager.literal("getname")
.then(ClientCommandManager.argument("player/uuid", string())
.suggests((context, builder) -> suggestMatching(context.getSource().getPlayerNames(), builder))
.executes(ctx -> {
if (getString(ctx, "player/uuid").length() == 32 || getString(ctx, "player/uuid").length() == 36) {
try {
return getNamesUUID(ctx.getSource(), getString(ctx, "player/uuid"));
} catch (Exception e) {
ctx.getSource().sendError(Text.translatable("command.all.error"));
return Command.SINGLE_SUCCESS;
}
} else {
try {
return getUuidName(ctx.getSource(), getString(ctx, "player/uuid"));
} catch (Exception e) {
ctx.getSource().sendError(Text.translatable("command.all.error"));
return Command.SINGLE_SUCCESS;
}
}
})));
.executes(GetUuidCommand::execute)));

dispatcher.register(ClientCommandManager.literal("getuuid")
.then(ClientCommandManager.argument("player/uuid", string())
.suggests((context, builder) -> suggestMatching(context.getSource().getPlayerNames(), builder))
.executes(ctx -> {
if (getString(ctx, "player/uuid").length() == 32 || getString(ctx, "player/uuid").length() == 36) {
try {
return getNamesUUID(ctx.getSource(), getString(ctx, "player/uuid"));
} catch (Exception e) {
ctx.getSource().sendError(Text.translatable("command.all.error"));
return Command.SINGLE_SUCCESS;
}
} else {
try {
return getUuidName(ctx.getSource(), getString(ctx, "player/uuid"));
} catch (Exception e) {
ctx.getSource().sendError(Text.translatable("command.all.error"));
return Command.SINGLE_SUCCESS;
}
}
})));
.executes(GetUuidCommand::execute)));
}

private static int execute(CommandContext<FabricClientCommandSource> ctx) {
if (getString(ctx, "player/uuid").length() == 32 || getString(ctx, "player/uuid").length() == 36) {
try {
return getNamesUUID(ctx.getSource(), getString(ctx, "player/uuid"));
} catch (Exception e) {
ctx.getSource().sendError(Text.translatable("command.all.error"));
return Command.SINGLE_SUCCESS;
}
} else {
try {
return getUuidName(ctx.getSource(), getString(ctx, "player/uuid"));
} catch (Exception e) {
ctx.getSource().sendError(Text.translatable("command.all.error"));
return Command.SINGLE_SUCCESS;
}
}
}

private static int getNamesUUID(FabricClientCommandSource source, @NotNull String uuid) {
String name = MinecraftAPI.getName(uuid);
Expand Down
Loading

0 comments on commit 13fdb9a

Please sign in to comment.