Fixed Shop Items Sowwy :)

This commit is contained in:
Driftay 2019-09-18 07:43:18 -04:00
parent 0ac6112437
commit 8ec16505c4
3 changed files with 38 additions and 31 deletions

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.shop.ShopConfig;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@ -19,6 +20,7 @@ public class CmdReload extends FCommand {
long timeInitStart = System.currentTimeMillis();
Conf.load();
Conf.save();
ShopConfig.loadShop();
FactionsPlugin.getInstance().reloadConfig();
FactionsPlugin.getInstance().loadLang();

View File

@ -40,6 +40,7 @@ public class ShopConfig {
getShop().set("items.1.name", "&aTest Shop");
ArrayList lore = new ArrayList();
lore.add("&cFully Customizable Lore!");
lore.add("&b&l{cost} &7Points");
getShop().set("items.1.lore", lore);
ArrayList t = new ArrayList();
t.add("broadcast %player% bought Test Shop!");

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.shop;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
import com.google.common.collect.ImmutableList;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
@ -11,6 +12,7 @@ import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
@ -19,16 +21,20 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class ShopGUIFrame {
private Gui gui;
private String s;
public ShopGUIFrame(Faction f) {
gui = new Gui(FactionsPlugin.getInstance(),
FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Rows", 4),
FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("F-Shop.GUI.Name")));
this.s = s;
}
public void buildGUI(FPlayer fplayer) {
@ -38,23 +44,46 @@ public class ShopGUIFrame {
for (int x = 0; x <= (gui.getRows() * 9) - 1; x++) GUIItems.add(new GuiItem(dummy, e -> e.setCancelled(true)));
int items = ShopConfig.getShop().getConfigurationSection("items").getKeys(false).size();
for (int shopitems = 1; shopitems <= items; shopitems++) {
String s = shopitems + "";
String name = ShopConfig.getShop().getString("items." + s + ".name");
for (int a = 1; a <= items; a++) {
String s = a + "";
int slot = ShopConfig.getShop().getInt("items." + s + ".slot");
Material material = XMaterial.matchXMaterial(ShopConfig.getShop().getString("items." + s + ".block")).parseMaterial();
int cost = ShopConfig.getShop().getInt("items." + s + ".cost");
String name = ShopConfig.getShop().getString("items." + s + ".name");
boolean glowing = ShopConfig.getShop().getBoolean("items." + s + ".glowing");
List<String> lore = ShopConfig.getShop().getStringList("items." + s + ".lore");
GUIItems.set(slot, new GuiItem(buildShopAssets(fplayer.getFaction()), e -> {
ItemStack item = new ItemStack(material);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(FactionsPlugin.instance.color(name));
meta.addItemFlags();
if (glowing) {
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addEnchant(Enchantment.DURABILITY, 1, true);
}
if (!glowing) {
meta.removeEnchant(Enchantment.DURABILITY);
}
List<String> replacedLore = lore.stream().map(t -> t.replace("{cost}", cost + "")).collect(Collectors.toList());
meta.setLore(FactionsPlugin.instance.colorList(replacedLore));
item.setItemMeta(meta);
GUIItems.set(slot, new GuiItem(item, e -> {
e.setCancelled(true);
FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getWhoClicked());
int cost = ShopConfig.getShop().getInt("items." + s + ".cost");
if (fplayer.getFaction().getPoints() >= cost) {
fplayer.getFaction().setPoints(fplayer.getFaction().getPoints() - cost);
runCommands(ShopConfig.getShop().getStringList("items." + s + ".cmds"), fplayer.getPlayer());
for (FPlayer fplayerBuy : fplayer.getFaction().getFPlayers()) {
fplayerBuy.getPlayer().sendMessage(TL.SHOP_BOUGHT_BROADCAST_FACTION.toString()
.replace("{player}", fplayer.getPlayer().getName())
.replace("{item}", ChatColor.stripColor(FactionsPlugin.getInstance().color(name))).replace("{cost}", cost + ""));
.replace("{item}", ChatColor.stripColor(FactionsPlugin.getInstance().color(name)))
.replace("{cost}", cost + ""));
}
buildGUI(fme);
} else {
@ -68,31 +97,6 @@ public class ShopGUIFrame {
}
}
private ItemStack buildShopAssets(Faction f) {
int items = ShopConfig.getShop().getConfigurationSection("items").getKeys(false).size();
ItemStack item = null;
for (int shopitems = 1; shopitems <= items; shopitems++) {
String s = shopitems + "";
ConfigurationSection config = ShopConfig.getShop().getConfigurationSection("items." + s);
boolean glowing = config.getBoolean("glowing");
item = XMaterial.matchXMaterial(config.getString("block")).parseItem();
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("lore")));
meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("name")));
if (glowing) {
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addEnchant(Enchantment.DURABILITY, 1, true);
}
if (!glowing) {
meta.removeEnchant(Enchantment.DURABILITY);
}
item.setItemMeta(meta);
}
}
return item;
}
private ItemStack buildDummyItem(Faction f) {
ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("F-Shop.GUI.dummy-item");