Search in sources :

Example 6 with LiteralText

use of net.minecraft.text.LiteralText in project fabric-name-history-lookup by Woolyenough.

the class MojangAPI method get_player_name_history.

public static LiteralText get_player_name_history(String name, String uuid) {
    List<String> playerNameHistory = new ArrayList<>(Arrays.asList(get_raw_response("user/profiles/" + uuid + "/names").split("[\\[\\]{}\",:]")));
    playerNameHistory.removeAll(Arrays.asList("", null, " ", ":"));
    LiteralText output = new LiteralText("");
    for (int i = 0; i < playerNameHistory.size(); i++) {
        switch(playerNameHistory.get(i)) {
            case "name":
                {
                    i++;
                    // If the person has used their current name in previous name changes, this prevents them from also turning green
                    if (playerNameHistory.get(i).toLowerCase().equals(name.toLowerCase()) && (i >= playerNameHistory.size() - 3)) {
                        if (i == 1) {
                            output.append(new LiteralText("§r§l" + playerNameHistory.get(i)).styled(style -> style.withColor(TextColor.fromRgb(0x6ED878))).append(new LiteralText("§r  (Original name)").styled(style -> style.withColor(TextColor.fromRgb(0xBFB8D5)))));
                        } else
                            output.append(new LiteralText("\n§r§l" + playerNameHistory.get(i)).styled(style -> style.withColor(TextColor.fromRgb(0x6ED878))));
                    } else {
                        if (i == 1) {
                            // First name in list
                            output.append(new LiteralText("§r" + playerNameHistory.get(i)).styled(style -> style.withColor(TextColor.fromRgb(0x67AAEC))).append(new LiteralText("§r  (Original name)").styled(style -> style.withColor(TextColor.fromRgb(0xBFB8D5)))));
                        } else {
                            output.append(new LiteralText("\n§r" + playerNameHistory.get(i)).styled(style -> style.withColor(TextColor.fromRgb(0x67AAEC))));
                        }
                    }
                    break;
                }
            case "changedToAt":
                {
                    i++;
                    DateFormat simple = new SimpleDateFormat("dd.MM.yyyy • HH:mm");
                    Date result = new Date(Long.parseLong(playerNameHistory.get(i)));
                    output.append(new LiteralText("  §r§o" + simple.format(result)).styled(style -> style.withColor(TextColor.fromRgb(0x4A143F))));
                    break;
                }
        }
    }
    return output;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JsonObject(com.google.gson.JsonObject) LiteralText(net.minecraft.text.LiteralText) java.util(java.util) Util(net.minecraft.util.Util) URL(java.net.URL) SimpleDateFormat(java.text.SimpleDateFormat) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) TextColor(net.minecraft.text.TextColor) JsonParser(com.google.gson.JsonParser) JsonElement(com.google.gson.JsonElement) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) LiteralText(net.minecraft.text.LiteralText)

Example 7 with LiteralText

use of net.minecraft.text.LiteralText in project UniversalGraves by Patbox.

the class Commands method listOthers.

private static int listOthers(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerPlayerEntity player = context.getSource().getPlayer();
    List<GameProfile> profiles = new ArrayList(context.getArgument("player", GameProfileArgumentType.GameProfileArgument.class).getNames(context.getSource()));
    if (profiles.size() == 0) {
        context.getSource().sendFeedback(new LiteralText("This player doesn't exist!"), false);
        return 0;
    } else if (profiles.size() > 1) {
        context.getSource().sendFeedback(new LiteralText("Only one player can be selected!"), false);
        return 0;
    }
    try {
        new GraveListGui(player, profiles.get(0)).open();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}
Also used : GameProfileArgumentType(net.minecraft.command.argument.GameProfileArgumentType) GameProfile(com.mojang.authlib.GameProfile) ArrayList(java.util.ArrayList) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) LiteralText(net.minecraft.text.LiteralText)

Example 8 with LiteralText

use of net.minecraft.text.LiteralText in project UniversalGraves by Patbox.

the class GraveInfo method getPlaceholders.

public Map<String, Text> getPlaceholders() {
    Config config = ConfigManager.getConfig();
    long currentTime = System.currentTimeMillis() / 1000;
    long protectionTime = config.configData.protectionTime > -1 ? config.configData.protectionTime - currentTime + this.creationTime : Long.MAX_VALUE;
    long breakTime = config.configData.breakingTime > -1 ? config.configData.breakingTime - currentTime + this.creationTime : Long.MAX_VALUE;
    Map<String, Text> values = new HashMap<>();
    values.put("player", new LiteralText(this.gameProfile != null ? this.gameProfile.getName() : "<No player!>"));
    values.put("protection_time", new LiteralText("" + (config.configData.protectionTime > -1 ? config.getFormattedTime(protectionTime) : "∞")));
    values.put("break_time", new LiteralText("" + (config.configData.breakingTime > -1 ? config.getFormattedTime(breakTime) : "∞")));
    values.put("xp", new LiteralText("" + this.xp));
    values.put("item_count", new LiteralText("" + this.itemCount));
    values.put("position", new LiteralText("" + this.position.toShortString()));
    values.put("world", new LiteralText(GraveUtils.toWorldName(this.world)));
    values.put("death_cause", this.deathCause);
    return values;
}
Also used : Config(eu.pb4.graves.config.Config) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText)

Example 9 with LiteralText

use of net.minecraft.text.LiteralText in project meteor-rejects by AntiCope.

the class CoordLogger method formatMessage.

public BaseText formatMessage(String message, Vec3d coords) {
    BaseText text = new LiteralText(message);
    text.append(ChatUtils.formatCoords(coords));
    text.append(Formatting.GRAY.toString() + ".");
    return text;
}
Also used : BaseText(net.minecraft.text.BaseText) LiteralText(net.minecraft.text.LiteralText)

Example 10 with LiteralText

use of net.minecraft.text.LiteralText in project meteor-rejects by AntiCope.

the class HeadScreen method createHeadStack.

private ItemStack createHeadStack(String uuid, String value, String name) {
    ItemStack head = Items.PLAYER_HEAD.getDefaultStack();
    NbtCompound tag = new NbtCompound();
    NbtCompound skullOwner = new NbtCompound();
    skullOwner.putUuid("Id", UUID.fromString(uuid));
    NbtCompound properties = new NbtCompound();
    NbtList textures = new NbtList();
    NbtCompound Value = new NbtCompound();
    Value.putString("Value", value);
    textures.add(Value);
    properties.put("textures", textures);
    skullOwner.put("Properties", properties);
    tag.put("SkullOwner", skullOwner);
    head.setNbt(tag);
    head.setCustomName(new LiteralText(name));
    return head;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText)

Aggregations

LiteralText (net.minecraft.text.LiteralText)249 Text (net.minecraft.text.Text)63 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)51 ItemStack (net.minecraft.item.ItemStack)37 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)34 TranslatableText (net.minecraft.text.TranslatableText)32 MutableText (net.minecraft.text.MutableText)28 BaseText (net.minecraft.text.BaseText)26 NbtCompound (net.minecraft.nbt.NbtCompound)24 HoverEvent (net.minecraft.text.HoverEvent)24 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)23 Screen (net.minecraft.client.gui.screen.Screen)21 ClickEvent (net.minecraft.text.ClickEvent)20 MatrixStack (net.minecraft.client.util.math.MatrixStack)19 Formatting (net.minecraft.util.Formatting)19 Items (net.minecraft.item.Items)18 Inject (org.spongepowered.asm.mixin.injection.Inject)18 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)17 List (java.util.List)16 Identifier (net.minecraft.util.Identifier)15