Fixed Shop Items Sowwy :)
This commit is contained in:
parent
0ac6112437
commit
8ec16505c4
@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd;
|
|||||||
|
|
||||||
import com.massivecraft.factions.Conf;
|
import com.massivecraft.factions.Conf;
|
||||||
import com.massivecraft.factions.FactionsPlugin;
|
import com.massivecraft.factions.FactionsPlugin;
|
||||||
|
import com.massivecraft.factions.shop.ShopConfig;
|
||||||
import com.massivecraft.factions.struct.Permission;
|
import com.massivecraft.factions.struct.Permission;
|
||||||
import com.massivecraft.factions.zcore.util.TL;
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ public class CmdReload extends FCommand {
|
|||||||
long timeInitStart = System.currentTimeMillis();
|
long timeInitStart = System.currentTimeMillis();
|
||||||
Conf.load();
|
Conf.load();
|
||||||
Conf.save();
|
Conf.save();
|
||||||
|
ShopConfig.loadShop();
|
||||||
FactionsPlugin.getInstance().reloadConfig();
|
FactionsPlugin.getInstance().reloadConfig();
|
||||||
FactionsPlugin.getInstance().loadLang();
|
FactionsPlugin.getInstance().loadLang();
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ public class ShopConfig {
|
|||||||
getShop().set("items.1.name", "&aTest Shop");
|
getShop().set("items.1.name", "&aTest Shop");
|
||||||
ArrayList lore = new ArrayList();
|
ArrayList lore = new ArrayList();
|
||||||
lore.add("&cFully Customizable Lore!");
|
lore.add("&cFully Customizable Lore!");
|
||||||
|
lore.add("&b&l{cost} &7Points");
|
||||||
getShop().set("items.1.lore", lore);
|
getShop().set("items.1.lore", lore);
|
||||||
ArrayList t = new ArrayList();
|
ArrayList t = new ArrayList();
|
||||||
t.add("broadcast %player% bought Test Shop!");
|
t.add("broadcast %player% bought Test Shop!");
|
||||||
|
@ -3,6 +3,7 @@ package com.massivecraft.factions.shop;
|
|||||||
import com.github.stefvanschie.inventoryframework.Gui;
|
import com.github.stefvanschie.inventoryframework.Gui;
|
||||||
import com.github.stefvanschie.inventoryframework.GuiItem;
|
import com.github.stefvanschie.inventoryframework.GuiItem;
|
||||||
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
|
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.massivecraft.factions.FPlayer;
|
import com.massivecraft.factions.FPlayer;
|
||||||
import com.massivecraft.factions.FPlayers;
|
import com.massivecraft.factions.FPlayers;
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
@ -11,6 +12,7 @@ import com.massivecraft.factions.util.XMaterial;
|
|||||||
import com.massivecraft.factions.zcore.util.TL;
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -19,16 +21,20 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ShopGUIFrame {
|
public class ShopGUIFrame {
|
||||||
|
|
||||||
private Gui gui;
|
private Gui gui;
|
||||||
|
private String s;
|
||||||
|
|
||||||
public ShopGUIFrame(Faction f) {
|
public ShopGUIFrame(Faction f) {
|
||||||
gui = new Gui(FactionsPlugin.getInstance(),
|
gui = new Gui(FactionsPlugin.getInstance(),
|
||||||
FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Rows", 4),
|
FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Rows", 4),
|
||||||
FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("F-Shop.GUI.Name")));
|
FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("F-Shop.GUI.Name")));
|
||||||
|
this.s = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buildGUI(FPlayer fplayer) {
|
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)));
|
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();
|
int items = ShopConfig.getShop().getConfigurationSection("items").getKeys(false).size();
|
||||||
for (int shopitems = 1; shopitems <= items; shopitems++) {
|
for (int a = 1; a <= items; a++) {
|
||||||
String s = shopitems + "";
|
String s = a + "";
|
||||||
String name = ShopConfig.getShop().getString("items." + s + ".name");
|
|
||||||
int slot = ShopConfig.getShop().getInt("items." + s + ".slot");
|
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);
|
e.setCancelled(true);
|
||||||
|
|
||||||
FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getWhoClicked());
|
FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getWhoClicked());
|
||||||
int cost = ShopConfig.getShop().getInt("items." + s + ".cost");
|
|
||||||
if (fplayer.getFaction().getPoints() >= cost) {
|
if (fplayer.getFaction().getPoints() >= cost) {
|
||||||
fplayer.getFaction().setPoints(fplayer.getFaction().getPoints() - cost);
|
fplayer.getFaction().setPoints(fplayer.getFaction().getPoints() - cost);
|
||||||
runCommands(ShopConfig.getShop().getStringList("items." + s + ".cmds"), fplayer.getPlayer());
|
runCommands(ShopConfig.getShop().getStringList("items." + s + ".cmds"), fplayer.getPlayer());
|
||||||
for (FPlayer fplayerBuy : fplayer.getFaction().getFPlayers()) {
|
for (FPlayer fplayerBuy : fplayer.getFaction().getFPlayers()) {
|
||||||
fplayerBuy.getPlayer().sendMessage(TL.SHOP_BOUGHT_BROADCAST_FACTION.toString()
|
fplayerBuy.getPlayer().sendMessage(TL.SHOP_BOUGHT_BROADCAST_FACTION.toString()
|
||||||
.replace("{player}", fplayer.getPlayer().getName())
|
.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);
|
buildGUI(fme);
|
||||||
} else {
|
} 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) {
|
private ItemStack buildDummyItem(Faction f) {
|
||||||
ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("F-Shop.GUI.dummy-item");
|
ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("F-Shop.GUI.dummy-item");
|
||||||
|
Loading…
Reference in New Issue
Block a user