Newer
Older
ChallengesJoinEntities / src / main / java / de / fanta / challengesjoinentities / adventure / AdventureMap.java
package de.fanta.challengesjoinentities.adventure;

import de.fanta.challengesjoinentities.ChallengesJoinEntities;
import de.fanta.challengesjoinentities.ChatUtil;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class AdventureMap {
    private final ChallengesJoinEntities plugin;

    private final String name;
    private final String version;

    private final ItemStack item;

    private final String creator;

    private final String webLink;

    public AdventureMap(ChallengesJoinEntities plugin, String name, String version, Material material, String creator, String webLink) {
        this.name = name;
        this.version = version;
        this.creator = creator;
        this.webLink = webLink;
        this.plugin = plugin;
        this.item = new ItemStack((material != null) ? material : Material.STONE);
        ItemMeta meta = this.item.getItemMeta();
        meta.setDisplayName("" + ChatUtil.ORANGE + ChatColor.BOLD + getName().replace("_", " "));
        List<String> lore = new ArrayList<>();
        lore.add("");
        lore.add(ChatUtil.GREEN + "Erbauer: " + ChatUtil.BLUE + creator);
        lore.add(ChatUtil.GREEN + "Version: " + ChatUtil.BLUE + version);
        lore.add(ChatUtil.GREEN + "MapLink: " + ChatUtil.BLUE + "Rechts Klick");
        lore.add(ChatUtil.GREEN + "Map laden: " + ChatUtil.BLUE + "Links Klick");
        meta.setLore(lore);
        this.item.setItemMeta(meta);
    }

    public AdventureMap(ChallengesJoinEntities plugin, String name, ConfigurationSection section) {
        this(plugin, name, section.getString("version"), Material.matchMaterial(Objects.requireNonNull(section.getString("item"))), section.getString("creator"), section.getString("web_link"));
    }

    public String getName() {
        return this.name;
    }

    public String getVersion() {
        return version;
    }

    public ItemStack getItem() {
        return this.item;
    }

    public String getCreator() {
        return this.creator;
    }

    public String getWebLink() {
        return this.webLink;
    }

    public void save(ConfigurationSection section) {
        section.set("item", this.item.getType().getKey().toString());
        section.set("creator", this.creator);
        section.set("web_link", this.webLink);
        section.set("version", this.version);
    }
}