2021-07-14 15:23:55 +02:00
|
|
|
package net.citizensnpcs.trait;
|
|
|
|
|
2022-02-19 13:27:41 +01:00
|
|
|
import java.util.List;
|
2021-07-14 15:23:55 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
2022-02-19 13:27:41 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2021-07-14 15:23:55 +02:00
|
|
|
|
2022-02-19 13:27:41 +01:00
|
|
|
import com.google.common.collect.Lists;
|
2021-07-14 15:23:55 +02:00
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
|
|
import net.citizensnpcs.api.persistence.Persist;
|
|
|
|
import net.citizensnpcs.api.trait.Trait;
|
|
|
|
import net.citizensnpcs.api.trait.TraitName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shop trait for NPC GUI shops.
|
|
|
|
*/
|
|
|
|
@TraitName("shop")
|
|
|
|
public class ShopTrait extends Trait {
|
|
|
|
public ShopTrait() {
|
|
|
|
super("shop");
|
|
|
|
}
|
|
|
|
|
|
|
|
public NPCShop getDefaultShop() {
|
2022-02-19 13:27:41 +01:00
|
|
|
return NPC_SHOPS.computeIfAbsent(npc.getUniqueId().toString(), NPCShop::new);
|
2021-07-14 15:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public NPCShop getShop(String name) {
|
2022-02-19 13:27:41 +01:00
|
|
|
return SHOPS.computeIfAbsent(name, NPCShop::new);
|
2021-07-14 15:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class NPCShop {
|
|
|
|
@Persist
|
2022-02-19 13:27:41 +01:00
|
|
|
private final String name;
|
|
|
|
@Persist(reify = true)
|
|
|
|
private final List<NPCShopPage> pages = Lists.newArrayList();
|
|
|
|
@Persist
|
|
|
|
private String title;
|
2021-07-14 15:23:55 +02:00
|
|
|
|
|
|
|
private NPCShop(String name) {
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void display(Player sender) {
|
|
|
|
}
|
2022-01-06 12:25:01 +01:00
|
|
|
|
|
|
|
public void displayEditor(Player sender) {
|
|
|
|
}
|
2022-02-19 13:27:41 +01:00
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class NPCShopItem {
|
|
|
|
@Persist
|
|
|
|
private int cost;
|
|
|
|
@Persist
|
|
|
|
private ItemStack display;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class NPCShopPage {
|
|
|
|
@Persist("")
|
|
|
|
private int index;
|
|
|
|
@Persist(reify = true)
|
|
|
|
private final Map<Integer, NPCShopItem> items = Maps.newHashMap();
|
|
|
|
@Persist
|
|
|
|
private String title;
|
2021-07-14 15:23:55 +02:00
|
|
|
}
|
|
|
|
|
2022-03-04 15:14:28 +01:00
|
|
|
@Persist(value = "npcShops", reify = true, namespace = "shopstrait")
|
2021-07-14 15:23:55 +02:00
|
|
|
private static Map<String, NPCShop> NPC_SHOPS = Maps.newHashMap();
|
2022-03-04 15:14:28 +01:00
|
|
|
@Persist(value = "namedShops", reify = true, namespace = "shopstrait")
|
2021-07-14 15:23:55 +02:00
|
|
|
private static Map<String, NPCShop> SHOPS = Maps.newHashMap();
|
|
|
|
}
|