All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.aurelium.auraskills.api.source.CustomSource Maven / Gradle / Ivy

There is a newer version: 2.2.3
Show newest version
package dev.aurelium.auraskills.api.source;

import dev.aurelium.auraskills.api.registry.NamespacedId;
import org.jetbrains.annotations.Nullable;

import java.util.Locale;

public class CustomSource implements XpSource {

    private final SourceValues values;

    public CustomSource(SourceValues values) {
        this.values = values;
    }

    @Override
    public NamespacedId getId() {
        return values.getId();
    }

    @Override
    public SourceType getType() {
        return values.getType();
    }

    @Override
    public String getDisplayName(Locale locale) {
        SourceType sourceType = getType();
        if (sourceType == null) {
            return getId().getKey();
        }
        String messagePath = "sources." + sourceType.toString().toLowerCase(Locale.ROOT) + "." + getId().getKey().toLowerCase(Locale.ROOT);
        String msg = values.getApi().getMessageManager().getMessage(messagePath, locale);
        if (msg.equals(messagePath)) {
            // Try to use defined display name
            if (values.getDisplayName() != null) {
                return values.getDisplayName();
            }
        }
        return msg; // Return if exists in messages
    }

    @Override
    public @Nullable String getUnitName(Locale locale) {
        return values.getApi().getSourceManager().getUnitName(this, locale);
    }

    @Override
    public String name() {
        return getId().getKey().toUpperCase(Locale.ROOT);
    }

    @Override
    public double getXp() {
        return values.getXp();
    }

    @Override
    public SourceIncome getIncome() {
        return values.getIncome();
    }

    public SourceValues getValues() {
        return values;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy