From 7798b6fe95bdeabc8dcb9b5cda0ed905c5b180dc Mon Sep 17 00:00:00 2001 From: NotCoded <66999075+not-coded@users.noreply.github.com> Date: Mon, 26 Aug 2024 21:21:05 +0200 Subject: [PATCH] 0.0001ms optimization!!! --- .../namefabric/command/GetCapeCommand.java | 12 +++++------- .../namefabric/command/GetSkinCommand.java | 15 +++++++-------- .../namefabric/command/GetUuidCommand.java | 9 ++++----- .../namefabric/command/NameHistoryCommand.java | 9 ++++----- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/notcoded/namefabric/command/GetCapeCommand.java b/src/main/java/net/notcoded/namefabric/command/GetCapeCommand.java index 1be86d4..4937698 100644 --- a/src/main/java/net/notcoded/namefabric/command/GetCapeCommand.java +++ b/src/main/java/net/notcoded/namefabric/command/GetCapeCommand.java @@ -42,17 +42,15 @@ public static void register(CommandDispatcher dispatc .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){ - return getCapesUUID(ctx.getSource(), getString(ctx, "player/uuid")); + String playerOrUUID = getString(ctx, "player/uuid"); + if(playerOrUUID.length() == 32 || playerOrUUID.length() == 36){ + return getCapesUUID(ctx.getSource(), playerOrUUID); } - return getCapesPlayer(ctx.getSource(), getString(ctx, "player/uuid")); + return getCapesPlayer(ctx.getSource(), playerOrUUID); }))); } private static String identifyCape(@NotNull String url) { - - System.out.println(url); - String cape; for (int i = 0; i < capes.size(); i++){ cape = capes.get(url); @@ -88,7 +86,7 @@ private static void handleResponse(FabricClientCommandSource source, String resp } private static int getCapesUUID(@NotNull FabricClientCommandSource source, @NotNull String uuid) { - if(uuid.length() == 32 || uuid.length() == 36 || isUsingPlayerName){ + if((uuid.length() == 32 || uuid.length() == 36) || isUsingPlayerName){ String url = "https://sessionserver.mojang.com/session/minecraft/profile/" + uuid; //? if >=1.19 { diff --git a/src/main/java/net/notcoded/namefabric/command/GetSkinCommand.java b/src/main/java/net/notcoded/namefabric/command/GetSkinCommand.java index d593137..920d541 100644 --- a/src/main/java/net/notcoded/namefabric/command/GetSkinCommand.java +++ b/src/main/java/net/notcoded/namefabric/command/GetSkinCommand.java @@ -38,10 +38,11 @@ public static void register(CommandDispatcher dispatc .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){ - return getSkinsUUID(ctx.getSource(), getString(ctx, "player/uuid")); + String playerOrUUID = getString(ctx, "player/uuid"); + if(playerOrUUID.length() == 32 || playerOrUUID.length() == 36){ + return getSkinsUUID(ctx.getSource(), playerOrUUID); } - return getSkinsPlayer(ctx.getSource(), getString(ctx, "player/uuid")); + return getSkinsPlayer(ctx.getSource(), playerOrUUID); }))); } @@ -70,18 +71,16 @@ private static void handleResponse(FabricClientCommandSource source, String resp return; } - String finalSkinURL = skinurl; - - if(finalSkinURL == null) { + if(skinurl == null) { sendError(source, "command.all.error"); return; } - sendFeedback(source, "command.getskin.success", playerName, webLinkText(finalSkinURL)); + sendFeedback(source, "command.getskin.success", playerName, webLinkText(skinurl)); } private static int getSkinsUUID(FabricClientCommandSource source, String uuid) { - if(uuid.length() == 32 || uuid.length() == 36 || isUsingPlayerName) { + if((uuid.length() == 32 || uuid.length() == 36) || isUsingPlayerName) { String url = "https://sessionserver.mojang.com/session/minecraft/profile/" + uuid; //? if >=1.19 { diff --git a/src/main/java/net/notcoded/namefabric/command/GetUuidCommand.java b/src/main/java/net/notcoded/namefabric/command/GetUuidCommand.java index 62829a6..06c5b32 100644 --- a/src/main/java/net/notcoded/namefabric/command/GetUuidCommand.java +++ b/src/main/java/net/notcoded/namefabric/command/GetUuidCommand.java @@ -34,12 +34,11 @@ public static void register(CommandDispatcher dispatc } private static int execute(CommandContext ctx) { - String playerUUID = getString(ctx, "player/uuid"); - if (playerUUID.length() == 32 || playerUUID.length() == 36) { - return getNamesUUID(ctx.getSource(), playerUUID); - } else { - return getUUIDName(ctx.getSource(), playerUUID); + String playerOrUUID = getString(ctx, "player/uuid"); + if (playerOrUUID.length() == 32 || playerOrUUID.length() == 36) { + return getNamesUUID(ctx.getSource(), playerOrUUID); } + return getUUIDName(ctx.getSource(), playerOrUUID); } private static int getNamesUUID(FabricClientCommandSource source, @NotNull String uuid) { diff --git a/src/main/java/net/notcoded/namefabric/command/NameHistoryCommand.java b/src/main/java/net/notcoded/namefabric/command/NameHistoryCommand.java index a0ccc77..54df892 100644 --- a/src/main/java/net/notcoded/namefabric/command/NameHistoryCommand.java +++ b/src/main/java/net/notcoded/namefabric/command/NameHistoryCommand.java @@ -37,11 +37,11 @@ public static void register(CommandDispatcher dispatc .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){ - return getNamesUUID(ctx.getSource(), getString(ctx, "player/uuid")); - } else { - return getNamesPlayer(ctx.getSource(), getString(ctx, "player/uuid")); + String playerOrUUID = getString(ctx, "player/uuid"); + if(playerOrUUID.length() == 32 || playerOrUUID.length() == 36){ + return getNamesUUID(ctx.getSource(), playerOrUUID); } + return getNamesPlayer(ctx.getSource(), playerOrUUID); }))); } @@ -73,7 +73,6 @@ private static int getNamesUUID(FabricClientCommandSource source, String uuid) { //?} elif <1.19 { /*handleResponse(source, HttpAPI.get(url)); *///?} - } else { sendError(source, "command.all.invalid.uuid"); return 0;