Search in sources :

Example 1 with LocationProfile

use of com.wynntils.webapi.profiles.LocationProfile in project Wynntils by Wynntils.

the class CommandLocate method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length == 0) {
        throw new WrongUsageException("/" + getUsage(sender));
    }
    List<LocationProfile> knownProfiles = mapFeatures.get(args[0]);
    if (knownProfiles == null) {
        // Try case insensitive search
        Optional<String> match = mapFeatures.keySet().stream().filter(key -> key.toLowerCase().equals(args[0].toLowerCase())).findFirst();
        if (!match.isPresent()) {
            throw new WrongUsageException("Unknown map feature: " + args[0]);
        } else {
            knownProfiles = mapFeatures.get(match.get());
        }
    }
    Map<Double, LocationProfile> distanceToLocations = new TreeMap<>();
    Location currentLocation = new Location(McIf.player());
    for (LocationProfile locationProfile : knownProfiles) {
        Location location = new Location(locationProfile.getX(), currentLocation.getY(), locationProfile.getZ());
        double distance = location.distance(currentLocation);
        distanceToLocations.put(distance, locationProfile);
    }
    int numPrinted = 0;
    for (Map.Entry<Double, LocationProfile> entry : distanceToLocations.entrySet()) {
        double distance = entry.getKey();
        LocationProfile mmp = entry.getValue();
        ITextComponent startingPointMsg = new TextComponentString(mmp.getTranslatedName() + " is located at [" + mmp.getX() + ", " + mmp.getZ() + "] (" + (int) distance + " blocks)");
        startingPointMsg.getStyle().setColor(GRAY);
        sender.sendMessage(startingPointMsg);
        numPrinted++;
        if (numPrinted >= 3)
            break;
    }
}
Also used : java.util(java.util) McIf(com.wynntils.McIf) CommandBase(net.minecraft.command.CommandBase) BlockPos(net.minecraft.util.math.BlockPos) LocationProfile(com.wynntils.webapi.profiles.LocationProfile) ITextComponent(net.minecraft.util.text.ITextComponent) GRAY(net.minecraft.util.text.TextFormatting.GRAY) TextComponentString(net.minecraft.util.text.TextComponentString) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Location(com.wynntils.core.utils.objects.Location) Minecraft(net.minecraft.client.Minecraft) ICommandSender(net.minecraft.command.ICommandSender) WrongUsageException(net.minecraft.command.WrongUsageException) WebManager(com.wynntils.webapi.WebManager) IClientCommand(net.minecraftforge.client.IClientCommand) ITextComponent(net.minecraft.util.text.ITextComponent) LocationProfile(com.wynntils.webapi.profiles.LocationProfile) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) WrongUsageException(net.minecraft.command.WrongUsageException) Location(com.wynntils.core.utils.objects.Location)

Aggregations

McIf (com.wynntils.McIf)1 Location (com.wynntils.core.utils.objects.Location)1 WebManager (com.wynntils.webapi.WebManager)1 LocationProfile (com.wynntils.webapi.profiles.LocationProfile)1 java.util (java.util)1 Minecraft (net.minecraft.client.Minecraft)1 CommandBase (net.minecraft.command.CommandBase)1 CommandException (net.minecraft.command.CommandException)1 ICommandSender (net.minecraft.command.ICommandSender)1 WrongUsageException (net.minecraft.command.WrongUsageException)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 BlockPos (net.minecraft.util.math.BlockPos)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 GRAY (net.minecraft.util.text.TextFormatting.GRAY)1 IClientCommand (net.minecraftforge.client.IClientCommand)1