Search in sources :

Example 1 with Config

use of eu.pb4.armorstandeditor.config.Config 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)

Example 2 with Config

use of eu.pb4.armorstandeditor.config.Config 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 3 with Config

use of eu.pb4.armorstandeditor.config.Config in project UniversalGraves by Patbox.

the class GraveInfo method shouldBreak.

public boolean shouldBreak() {
    Config config = ConfigManager.getConfig();
    if (config.configData.breakingTime > -1) {
        long currentTime = System.currentTimeMillis() / 1000;
        long breakTime = config.configData.breakingTime - currentTime + this.creationTime;
        return breakTime <= 0;
    } else {
        return false;
    }
}
Also used : Config(eu.pb4.graves.config.Config)

Example 4 with Config

use of eu.pb4.armorstandeditor.config.Config in project ArmorStandEditor by Patbox.

the class Events method registerEvents.

public static void registerEvents() {
    if (FabricLoader.getInstance().isModLoaded("disguiselib")) {
        AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
            Config config = ConfigManager.getConfig();
            ItemStack itemStack = player.getMainHandStack();
            if (entity instanceof EntityDisguise && player instanceof ServerPlayerEntity && Permissions.check(player, "armorstandeditor.use", config.configData.toggleAllPermissionOnByDefault) && itemStack.getItem() == config.armorStandTool && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
                EntityDisguise disguise = (EntityDisguise) entity;
                if (disguise.isDisguised() && disguise.getDisguiseType() == EntityType.ARMOR_STAND && Permissions.check(player, "armorstandeditor.useDisguised", 2)) {
                    Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) disguise.getDisguiseEntity(), 1, entity);
                    return ActionResult.SUCCESS;
                } else if (entity instanceof ArmorStandEntity) {
                    Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) entity, 1, null);
                    return ActionResult.SUCCESS;
                }
            }
            return ActionResult.PASS;
        });
        UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
            Config config = ConfigManager.getConfig();
            ItemStack itemStack = player.getMainHandStack();
            if (entity instanceof EntityDisguise && player instanceof ServerPlayerEntity && Permissions.check(player, "armorstandeditor.use", config.configData.toggleAllPermissionOnByDefault) && itemStack.getItem() == config.armorStandTool && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
                EntityDisguise disguise = (EntityDisguise) entity;
                if (disguise.isDisguised() && disguise.getDisguiseType() == EntityType.ARMOR_STAND) {
                    Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) disguise.getDisguiseEntity(), -1, entity);
                    return ActionResult.SUCCESS;
                } else if (entity instanceof ArmorStandEntity) {
                    Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) entity, -1, null);
                    return ActionResult.SUCCESS;
                }
            }
            return ActionResult.PASS;
        });
    } else {
        AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
            Config config = ConfigManager.getConfig();
            ItemStack itemStack = player.getMainHandStack();
            if (entity instanceof ArmorStandEntity && player instanceof ServerPlayerEntity && Permissions.check(player, "armorstandeditor.use", config.configData.toggleAllPermissionOnByDefault) && itemStack.getItem() == config.armorStandTool && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
                Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) entity, 1, null);
                return ActionResult.SUCCESS;
            }
            return ActionResult.PASS;
        });
        UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
            Config config = ConfigManager.getConfig();
            ItemStack itemStack = player.getMainHandStack();
            if (entity instanceof ArmorStandEntity && player instanceof ServerPlayerEntity && Permissions.check(player, "armorstandeditor.use", config.configData.toggleAllPermissionOnByDefault) && itemStack.getItem() == config.armorStandTool && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
                Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) entity, -1, null);
                return ActionResult.SUCCESS;
            }
            return ActionResult.PASS;
        });
    }
    UseItemCallback.EVENT.register((PlayerEntity player, World world, Hand hand) -> {
        Config config = ConfigManager.getConfig();
        ItemStack itemStack = player.getMainHandStack();
        if (player instanceof ServerPlayerEntity && itemStack.getItem() == config.armorStandTool && Permissions.check(player, "armorstandeditor.use", config.configData.toggleAllPermissionOnByDefault) && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
            EditorGuis.openGui((ServerPlayerEntity) player);
            return TypedActionResult.success(player.getMainHandStack());
        }
        return TypedActionResult.pass(player.getMainHandStack());
    });
    AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
        Config config = ConfigManager.getConfig();
        ItemStack itemStack = player.getMainHandStack();
        if (entity instanceof ItemFrameEntity && player instanceof ServerPlayerEntity && Permissions.check(player, "armorstandeditor.useItemFrame", config.configData.toggleAllPermissionOnByDefault) && itemStack.getItem() == config.armorStandTool && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
            EditorGuis.openItemFrameEditor((ServerPlayerEntity) player, (ItemFrameEntity) entity);
            return ActionResult.SUCCESS;
        }
        return ActionResult.PASS;
    });
}
Also used : ItemFrameEntity(net.minecraft.entity.decoration.ItemFrameEntity) Config(eu.pb4.armorstandeditor.config.Config) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity) Hand(net.minecraft.util.Hand) EntityDisguise(xyz.nucleoid.disguiselib.casts.EntityDisguise) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 5 with Config

use of eu.pb4.armorstandeditor.config.Config in project UniversalGraves by Patbox.

the class GraveInfo method isProtected.

public boolean isProtected() {
    Config config = ConfigManager.getConfig();
    if (config.configData.protectionTime > -1 && config.configData.isProtected) {
        long currentTime = System.currentTimeMillis() / 1000;
        long protectionTime = config.configData.protectionTime - currentTime + this.creationTime;
        return protectionTime > 0;
    } else {
        return config.configData.isProtected;
    }
}
Also used : Config(eu.pb4.graves.config.Config)

Aggregations

Config (eu.pb4.graves.config.Config)3 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 LiteralText (net.minecraft.text.LiteralText)2 Text (net.minecraft.text.Text)2 GameProfile (com.mojang.authlib.GameProfile)1 Config (eu.pb4.armorstandeditor.config.Config)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 ArmorStandEntity (net.minecraft.entity.decoration.ArmorStandEntity)1 ItemFrameEntity (net.minecraft.entity.decoration.ItemFrameEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1