Display horse owner name instead of UUID

+ getNameFromUUID(uuid);
- Optimised Imports

Added #282
This commit is contained in:
Dewy REDACTED 2020-04-04 11:56:22 +01:00
parent 2f63e07a3b
commit ddd8050b13
4 changed files with 85 additions and 56 deletions

View File

@ -1,6 +1,7 @@
package me.zeroeightsix.kami.command.commands;
import me.zeroeightsix.kami.command.Command;
import me.zeroeightsix.kami.util.EntityUtil;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.AbstractHorse;
@ -10,8 +11,8 @@ import java.math.RoundingMode;
/**
* Created by d1gress/Qther on 25/11/2017, updated on 16/12/2019
* Updated by EmotionalLove on 16/12/2019
* Updated by Dewy on 4th April, 2020
*/
public class EntityStatsCommand extends Command {
public EntityStatsCommand() {
@ -21,6 +22,7 @@ public class EntityStatsCommand extends Command {
@Override
public void call(String[] args) {
if (mc.player.getRidingEntity() != null && mc.player.getRidingEntity() instanceof AbstractHorse) {
AbstractHorse horse = (AbstractHorse) mc.player.getRidingEntity();
// TODO: Function that resolves UUID's to Minecraft usernames. @bella
@ -33,7 +35,7 @@ public class EntityStatsCommand extends Command {
builder.append("\n&cMax Health: ").append(maxHealth);
builder.append("\n&cSpeed: ").append(speed);
builder.append("\n&cJump: ").append(jump);
builder.append("\n&cOwner: ").append(ownerId);
builder.append("\n&cOwner: ").append(EntityUtil.getNameFromUUID(ownerId).replace("\"", ""));
Command.sendChatMessage(builder.toString());
} else if (mc.player.getRidingEntity() instanceof EntityLivingBase) {

View File

@ -9,7 +9,6 @@ import me.zeroeightsix.kami.gui.kami.KamiGUI;
import me.zeroeightsix.kami.gui.rgui.component.container.use.Frame;
import me.zeroeightsix.kami.module.modules.gui.CommandConfig;
import me.zeroeightsix.kami.module.modules.render.BossStack;
import me.zeroeightsix.kami.module.modules.render.Zoom;
import me.zeroeightsix.kami.util.KamiTessellator;
import me.zeroeightsix.kami.util.Wrapper;
import net.minecraft.client.Minecraft;

View File

@ -11,7 +11,6 @@ import net.minecraft.network.play.client.CPacketChatMessage;
import java.util.Random;
import static me.zeroeightsix.kami.module.modules.gui.InfoOverlay.getItems;
import static me.zeroeightsix.kami.util.InfoCalculator.isNumberEven;
/**

View File

@ -1,5 +1,7 @@
package me.zeroeightsix.kami.util;
import com.google.gson.JsonParser;
import me.zeroeightsix.kami.KamiMod;
import net.minecraft.block.BlockLiquid;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
@ -13,6 +15,10 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.net.URL;
public class EntityUtil {
@ -177,4 +183,27 @@ public class EntityUtil {
return (double) (MathHelper.cos(yaw * 0.017453292F));
}
/**
* Gets the MC username tied to a given UUID.
*
* @param uuid UUID to get name from.
* @return The name tied to the UUID.
*/
public static String getNameFromUUID(String uuid) {
try {
KamiMod.log.info("Attempting to get name from UUID: " + uuid);
String jsonUrl = IOUtils.toString(new URL("https://api.mojang.com/user/profiles/" + uuid.replace("-", "") + "/names"));
JsonParser parser = new JsonParser();
return parser.parse(jsonUrl).getAsJsonArray().get(0).getAsJsonObject().get("name").toString();
} catch (IOException ex) {
KamiMod.log.error(ex.getStackTrace());
KamiMod.log.error("Failed to get username from UUID due to an exception. Maybe your internet is being the big gay? Somehow?");
}
return null;
}
}