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,54 +1,56 @@
package me.zeroeightsix.kami.command.commands;
import me.zeroeightsix.kami.command.Command;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.AbstractHorse;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
* Created by d1gress/Qther on 25/11/2017, updated on 16/12/2019
* Updated by EmotionalLove on 16/12/2019
*/
public class EntityStatsCommand extends Command {
public EntityStatsCommand() {
super("entitystats", null, "estats");
setDescription("Print the statistics of the entity you're currently riding");
}
@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
float maxHealth = horse.getMaxHealth();
double speed = round(43.17 * horse.getAIMoveSpeed(), 2);
double jump = round(-0.1817584952 * Math.pow(horse.getHorseJumpStrength(), 3) + 3.689713992 * Math.pow(horse.getHorseJumpStrength(), 2) + 2.128599134 * horse.getHorseJumpStrength() - 0.343930367, 4);
String ownerId = horse.getOwnerUniqueId() == null ? "Not tamed." : horse.getOwnerUniqueId().toString();
StringBuilder builder = new StringBuilder("&6Entity Statistics:");
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);
Command.sendChatMessage(builder.toString());
} else if (mc.player.getRidingEntity() instanceof EntityLivingBase) {
EntityLivingBase entity = (EntityLivingBase) mc.player.getRidingEntity();
Command.sendChatMessage("&6Entity Stats:\n&cMax Health: &b" + entity.getMaxHealth() + " &2HP" + "\n&cSpeed: &b" + round(43.17 * entity.getAIMoveSpeed(), 2) + " &2m/s");
} else {
Command.sendChatMessage("&4&lError: &cNot riding a compatible entity.");
}
}
public static double round(double value, int places) {
if (places < 0) throw new IllegalArgumentException();
BigDecimal bd = BigDecimal.valueOf(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
}
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;
import java.math.BigDecimal;
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() {
super("entitystats", null, "estats");
setDescription("Print the statistics of the entity you're currently riding");
}
@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
float maxHealth = horse.getMaxHealth();
double speed = round(43.17 * horse.getAIMoveSpeed(), 2);
double jump = round(-0.1817584952 * Math.pow(horse.getHorseJumpStrength(), 3) + 3.689713992 * Math.pow(horse.getHorseJumpStrength(), 2) + 2.128599134 * horse.getHorseJumpStrength() - 0.343930367, 4);
String ownerId = horse.getOwnerUniqueId() == null ? "Not tamed." : horse.getOwnerUniqueId().toString();
StringBuilder builder = new StringBuilder("&6Entity Statistics:");
builder.append("\n&cMax Health: ").append(maxHealth);
builder.append("\n&cSpeed: ").append(speed);
builder.append("\n&cJump: ").append(jump);
builder.append("\n&cOwner: ").append(EntityUtil.getNameFromUUID(ownerId).replace("\"", ""));
Command.sendChatMessage(builder.toString());
} else if (mc.player.getRidingEntity() instanceof EntityLivingBase) {
EntityLivingBase entity = (EntityLivingBase) mc.player.getRidingEntity();
Command.sendChatMessage("&6Entity Stats:\n&cMax Health: &b" + entity.getMaxHealth() + " &2HP" + "\n&cSpeed: &b" + round(43.17 * entity.getAIMoveSpeed(), 2) + " &2m/s");
} else {
Command.sendChatMessage("&4&lError: &cNot riding a compatible entity.");
}
}
public static double round(double value, int places) {
if (places < 0) throw new IllegalArgumentException();
BigDecimal bd = BigDecimal.valueOf(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
}

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;
}
}