Newer
Older
ChallengesJoinEntities / src / main / java / de / fanta / challengesjoinentities / adventure / AdventureMap.java
@fanta fanta on 29 Nov 2021 2 KB Cleanup Code
package de.fanta.challengesjoinentities.adventure;

import de.fanta.challengesjoinentities.ChallengesJoinEntities;

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

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;

public class AdventureMap {
    private final ChallengesJoinEntities plugin;

    private final String name;

    private final ItemStack item;

    private final String creator;

    private final String webLink;

    public AdventureMap(ChallengesJoinEntities plugin, String name, Material material, String creator, String webLink) {
        this.name = name;
        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());
        List<String> lore = new ArrayList<>();
        lore.add("");
        lore.add(ChatUtil.GREEN + "Erbauer: " + ChatUtil.BLUE + creator);
        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, Material.matchMaterial(Objects.requireNonNull(section.getString("item"))), section.getString("creator"), section.getString("web_link"));
    }

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

    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);
    }
}