Search in sources :

Example 1 with GraveInfo

use of eu.pb4.graves.grave.GraveInfo in project UniversalGraves by Patbox.

the class GraveListGui method updateIcons.

private void updateIcons() {
    var config = ConfigManager.getConfig();
    for (int x = 0; x < this.size; x++) {
        this.clearSlot(x);
    }
    for (GraveInfo graveInfo : GraveManager.INSTANCE.getByUuid(this.targetUUID)) {
        if (this.getFirstEmptySlot() == -1) {
            return;
        }
        Map<String, Text> placeholders = graveInfo.getPlaceholders();
        List<Text> parsed = new ArrayList<>();
        for (Text text : graveInfo.isProtected() ? ConfigManager.getConfig().guiProtectedText : ConfigManager.getConfig().guiText) {
            MutableText out = (MutableText) PlaceholderAPI.parsePredefinedText(text, PlaceholderAPI.PREDEFINED_PLACEHOLDER_PATTERN, placeholders);
            if (out.getStyle().getColor() == null) {
                out.setStyle(out.getStyle().withColor(Formatting.WHITE));
            }
            parsed.add(out);
        }
        var list = graveInfo.isProtected() ? config.guiProtectedItem : config.guiItem;
        this.addSlot(GuiElementBuilder.from(list[Math.abs(graveInfo.hashCode() % list.length)]).setName((MutableText) parsed.remove(0)).setLore(parsed).setCallback((index, type, action) -> {
            if (Permissions.check(this.player, "universal_graves.teleport", 3)) {
                this.close();
                ServerWorld world = this.player.getServer().getWorld(RegistryKey.of(Registry.WORLD_KEY, graveInfo.getWorld()));
                if (world != null) {
                    var pos = graveInfo.getPosition();
                    this.player.teleport(world, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, this.player.getYaw(), this.player.getPitch());
                }
            }
        }));
    }
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText) GameProfile(com.mojang.authlib.GameProfile) ServerWorld(net.minecraft.server.world.ServerWorld) Permissions(me.lucko.fabric.api.permissions.v0.Permissions) UUID(java.util.UUID) Registry(net.minecraft.util.registry.Registry) GraveManager(eu.pb4.graves.grave.GraveManager) ArrayList(java.util.ArrayList) Formatting(net.minecraft.util.Formatting) List(java.util.List) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ConfigManager(eu.pb4.graves.config.ConfigManager) Map(java.util.Map) MutableText(net.minecraft.text.MutableText) RegistryKey(net.minecraft.util.registry.RegistryKey) PlaceholderAPI(eu.pb4.placeholders.PlaceholderAPI) GuiElementBuilder(eu.pb4.sgui.api.elements.GuiElementBuilder) Text(net.minecraft.text.Text) GraveInfo(eu.pb4.graves.grave.GraveInfo) SimpleGui(eu.pb4.sgui.api.gui.SimpleGui) ScreenHandlerType(net.minecraft.screen.ScreenHandlerType) ServerWorld(net.minecraft.server.world.ServerWorld) GraveInfo(eu.pb4.graves.grave.GraveInfo) ArrayList(java.util.ArrayList) LiteralText(net.minecraft.text.LiteralText) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)1 ConfigManager (eu.pb4.graves.config.ConfigManager)1 GraveInfo (eu.pb4.graves.grave.GraveInfo)1 GraveManager (eu.pb4.graves.grave.GraveManager)1 PlaceholderAPI (eu.pb4.placeholders.PlaceholderAPI)1 GuiElementBuilder (eu.pb4.sgui.api.elements.GuiElementBuilder)1 SimpleGui (eu.pb4.sgui.api.gui.SimpleGui)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Permissions (me.lucko.fabric.api.permissions.v0.Permissions)1 ScreenHandlerType (net.minecraft.screen.ScreenHandlerType)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 LiteralText (net.minecraft.text.LiteralText)1 MutableText (net.minecraft.text.MutableText)1 Text (net.minecraft.text.Text)1 Formatting (net.minecraft.util.Formatting)1 Registry (net.minecraft.util.registry.Registry)1