parent
ddd3150732
commit
71a099beeb
@ -26,6 +26,7 @@ import com.massivecraft.factions.discord.CmdInviteBot;
|
|||||||
import com.massivecraft.factions.discord.CmdSetGuild;
|
import com.massivecraft.factions.discord.CmdSetGuild;
|
||||||
import com.massivecraft.factions.missions.CmdMissions;
|
import com.massivecraft.factions.missions.CmdMissions;
|
||||||
import com.massivecraft.factions.shop.CmdShop;
|
import com.massivecraft.factions.shop.CmdShop;
|
||||||
|
import com.massivecraft.factions.shop.ShopGUIFrame;
|
||||||
import com.massivecraft.factions.zcore.util.TL;
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
import me.lucko.commodore.CommodoreProvider;
|
import me.lucko.commodore.CommodoreProvider;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -377,6 +378,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
if (FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled", false) && !fShopEnabled) {
|
if (FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled", false) && !fShopEnabled) {
|
||||||
this.addSubCommand(this.cmdShop);
|
this.addSubCommand(this.cmdShop);
|
||||||
|
new ShopGUIFrame(null).checkShopConfig();
|
||||||
fShopEnabled = true;
|
fShopEnabled = true;
|
||||||
}
|
}
|
||||||
if (FactionsPlugin.getInstance().getConfig().getBoolean("f-inventory-see.Enabled", false) && !invSeeEnabled) {
|
if (FactionsPlugin.getInstance().getConfig().getBoolean("f-inventory-see.Enabled", false) && !invSeeEnabled) {
|
||||||
|
@ -11,6 +11,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;
|
||||||
@ -20,92 +21,210 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ShopGUIFrame {
|
public class ShopGUIFrame
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Driftay
|
* @author Driftay
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private Gui gui;
|
private Gui gui;
|
||||||
|
|
||||||
public ShopGUIFrame(Faction f) {
|
public ShopGUIFrame(Faction f)
|
||||||
gui = new Gui(FactionsPlugin.getInstance(),
|
{
|
||||||
FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Rows", 4),
|
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")));
|
||||||
FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("F-Shop.GUI.Name")));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void buildGUI(FPlayer fplayer) {
|
public void buildGUI(FPlayer fplayer)
|
||||||
PaginatedPane pane = new PaginatedPane(0, 0, 9, gui.getRows());
|
{
|
||||||
List<GuiItem> GUIItems = new ArrayList<>();
|
PaginatedPane pane = new PaginatedPane(0, 0, 9, gui.getRows());
|
||||||
ItemStack dummy = buildDummyItem(fplayer.getFaction());
|
List<GuiItem> GUIItems = new ArrayList<>();
|
||||||
for (int x = 0; x <= (gui.getRows() * 9) - 1; x++) GUIItems.add(new GuiItem(dummy, e -> e.setCancelled(true)));
|
ItemStack dummy = buildDummyItem(fplayer.getFaction());
|
||||||
|
for (int x = 0; x <= (gui.getRows() * 9) - 1; x++)
|
||||||
|
GUIItems.add(new GuiItem(dummy, e -> e.setCancelled(true)));
|
||||||
|
|
||||||
int items = FactionsPlugin.getInstance().getFileManager().getShop().getConfig().getConfigurationSection("items").getKeys(false).size();
|
Set<String> items = FactionsPlugin.getInstance().getFileManager().getShop().getConfig().getConfigurationSection("items").getKeys(false);
|
||||||
for (int a = 1; a <= items; a++) {
|
for (String s : items)
|
||||||
String s = a + "";
|
{
|
||||||
int slot = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".slot");
|
if (!checkShopConfig(s))
|
||||||
ItemStack item = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".block")).get().parseItem();
|
{
|
||||||
int cost = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".cost");
|
continue;
|
||||||
String name = FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".name");
|
}
|
||||||
boolean glowing = FactionsPlugin.getInstance().getFileManager().getShop().fetchBoolean("items." + s + ".glowing");
|
|
||||||
List<String> lore = FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList("items." + s + ".lore");
|
|
||||||
|
|
||||||
|
int slot = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".slot");
|
||||||
|
ItemStack item = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".block")).get().parseItem();
|
||||||
|
int cost = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".cost");
|
||||||
|
String name = FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".name");
|
||||||
|
boolean glowing = FactionsPlugin.getInstance().getFileManager().getShop().fetchBoolean("items." + s + ".glowing");
|
||||||
|
List<String> lore = FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList("items." + s + ".lore");
|
||||||
|
|
||||||
assert item != null;
|
assert item != null;
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
meta.setDisplayName(FactionsPlugin.instance.color(name));
|
meta.setDisplayName(FactionsPlugin.instance.color(name));
|
||||||
meta.addItemFlags();
|
meta.addItemFlags();
|
||||||
if (glowing) {
|
if (glowing)
|
||||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
{
|
||||||
meta.addEnchant(Enchantment.DURABILITY, 1, true);
|
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());
|
if (!glowing)
|
||||||
meta.setLore(FactionsPlugin.instance.colorList(replacedLore));
|
meta.removeEnchant(Enchantment.DURABILITY);
|
||||||
item.setItemMeta(meta);
|
List<String> replacedLore = lore.stream().map(t -> t.replace("{cost}", cost + "")).collect(Collectors.toList());
|
||||||
GUIItems.set(slot, new GuiItem(item, e -> {
|
meta.setLore(FactionsPlugin.instance.colorList(replacedLore));
|
||||||
e.setCancelled(true);
|
item.setItemMeta(meta);
|
||||||
FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getWhoClicked());
|
GUIItems.set(slot, new GuiItem(item, e ->
|
||||||
if (fplayer.getFaction().getPoints() >= cost) {
|
{
|
||||||
fplayer.getFaction().setPoints(fplayer.getFaction().getPoints() - cost);
|
e.setCancelled(true);
|
||||||
runCommands(FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList("items." + s + ".cmds"), fplayer.getPlayer());
|
FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getWhoClicked());
|
||||||
for (FPlayer fplayerBuy : fplayer.getFaction().getFPlayers()) {
|
if (fplayer.getFaction().getPoints() >= cost)
|
||||||
fplayerBuy.getPlayer().sendMessage(TL.SHOP_BOUGHT_BROADCAST_FACTION.toString()
|
{
|
||||||
.replace("{player}", fplayer.getPlayer().getName())
|
if (runCommands(FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList("items." + s + ".cmds"), fplayer.getPlayer()))
|
||||||
.replace("{item}", ChatColor.stripColor(FactionsPlugin.getInstance().color(name)))
|
{
|
||||||
.replace("{cost}", cost + ""));
|
fplayer.getFaction().setPoints(fplayer.getFaction().getPoints() - cost);
|
||||||
}
|
for (FPlayer fplayerBuy : fplayer.getFaction().getFPlayers())
|
||||||
buildGUI(fme);
|
{
|
||||||
} else {
|
fplayerBuy.getPlayer().sendMessage(TL.SHOP_BOUGHT_BROADCAST_FACTION.toString().replace("{player}", fplayer.getPlayer().getName()).replace("{item}", ChatColor.stripColor(FactionsPlugin.getInstance().color(name)))
|
||||||
fplayer.msg(TL.SHOP_NOT_ENOUGH_POINTS);
|
.replace("{cost}", cost + ""));
|
||||||
}
|
}
|
||||||
}));
|
buildGUI(fme);
|
||||||
pane.populateWithGuiItems(GUIItems);
|
}
|
||||||
gui.addPane(pane);
|
else
|
||||||
gui.update();
|
{
|
||||||
gui.show(fplayer.getPlayer());
|
fplayer.msg(TL.SHOP_ERROR_DURING_PURCHASE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fplayer.msg(TL.SHOP_NOT_ENOUGH_POINTS);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
pane.populateWithGuiItems(GUIItems);
|
||||||
|
gui.addPane(pane);
|
||||||
|
gui.update();
|
||||||
|
gui.show(fplayer.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack buildDummyItem(Faction f)
|
||||||
|
{
|
||||||
|
ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("F-Shop.GUI.dummy-item");
|
||||||
|
ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).get().parseItem();
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta != null)
|
||||||
|
{
|
||||||
|
meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("Lore")));
|
||||||
|
meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name").replace("{points}", f.getPoints() + "")));
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
private ItemStack buildDummyItem(Faction f) {
|
public boolean checkShopConfig()
|
||||||
ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("F-Shop.GUI.dummy-item");
|
{
|
||||||
ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).get().parseItem();
|
boolean ret = true;
|
||||||
ItemMeta meta = item.getItemMeta();
|
Set<String> items = FactionsPlugin.getInstance().getFileManager().getShop().getConfig().getConfigurationSection("items").getKeys(false);
|
||||||
if (meta != null) {
|
for (String s : items)
|
||||||
meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("Lore")));
|
{
|
||||||
meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name").replace("{points}", f.getPoints() + "")));
|
if (checkShopConfig(s) == false)
|
||||||
item.setItemMeta(meta);
|
{
|
||||||
}
|
ret = false;
|
||||||
return item;
|
}
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
public void runCommands(List<String> list, Player p) {
|
public boolean checkShopConfig(String s)
|
||||||
for (String cmd : list) {
|
{
|
||||||
cmd = cmd.replace("%player%", p.getName());
|
boolean ret = true;
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
if (!FactionsPlugin.getInstance().getFileManager().getShop().containsKey("items." + s + ".slot"))
|
||||||
}
|
{
|
||||||
}
|
FactionsPlugin.getInstance().log(Level.WARNING, "Problem with config item \'" + s + "\' missing slot variable");
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
if (!FactionsPlugin.getInstance().getFileManager().getShop().containsKey("items." + s + ".block"))
|
||||||
|
{
|
||||||
|
FactionsPlugin.getInstance().log(Level.WARNING, "Problem with config item \'" + s + "\' missing block variable");
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!FactionsPlugin.getInstance().getFileManager().getShop().containsKey("items." + s + ".cmds"))
|
||||||
|
{
|
||||||
|
FactionsPlugin.getInstance().log(Level.WARNING, "Problee with config item \'" + s + "\' missing cmds variable");
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!FactionsPlugin.getInstance().getFileManager().getShop().containsKey("items." + s + ".cost"))
|
||||||
|
{
|
||||||
|
FactionsPlugin.getInstance().log(Level.WARNING, "Problem with config item \'" + s + "\' missing cost variable this item will cost 0");
|
||||||
|
}
|
||||||
|
if (!FactionsPlugin.getInstance().getFileManager().getShop().containsKey("items." + s + ".name"))
|
||||||
|
{
|
||||||
|
FactionsPlugin.getInstance().log(Level.WARNING, "Problem with config item \'" + s + "\' missing name variable");
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param list
|
||||||
|
* The list of commands to be ran.
|
||||||
|
* @param p
|
||||||
|
* The player that is using the shop
|
||||||
|
* @return if all commands are able to be ran or if they did run.
|
||||||
|
*/
|
||||||
|
public boolean runCommands(List<String> list, Player p)
|
||||||
|
{
|
||||||
|
for (String cmd : list)
|
||||||
|
{
|
||||||
|
cmd = cmd.replace("%player%", p.getName());
|
||||||
|
if (cmd.toLowerCase().startsWith("give"))
|
||||||
|
{
|
||||||
|
String[] args = cmd.split(" ");
|
||||||
|
if (args.length == 4)
|
||||||
|
{
|
||||||
|
Material material = Material.matchMaterial(args[2]);
|
||||||
|
int amount = Integer.parseInt(args[3]);
|
||||||
|
Player player = Bukkit.getPlayer(args[1]);
|
||||||
|
if (!player.isOnline())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// See if the player has this item in their inventory;
|
||||||
|
if (player.getInventory().contains(material) && player.getInventory().firstEmpty() < 0)
|
||||||
|
{
|
||||||
|
int spacesAvailable = 0;
|
||||||
|
Map<Integer, ? extends ItemStack> contents = player.getInventory().all(material);
|
||||||
|
for (ItemStack stack : contents.values())
|
||||||
|
{
|
||||||
|
spacesAvailable += stack.getMaxStackSize() - stack.getAmount();
|
||||||
|
}
|
||||||
|
if (spacesAvailable < amount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (player.getInventory().firstEmpty() < 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String cmd : list)
|
||||||
|
{
|
||||||
|
cmd = cmd.replace("%player%", p.getName());
|
||||||
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,10 @@ public class CustomFile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean containsKey(String key) {
|
||||||
|
return getCachedObjects().containsKey(key)|| getConfig().contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
public String fetchString(String key) {
|
public String fetchString(String key) {
|
||||||
return (String) getObj(key, dataTypes.STRING);
|
return (String) getObj(key, dataTypes.STRING);
|
||||||
}
|
}
|
||||||
|
@ -824,6 +824,7 @@ public enum TL {
|
|||||||
COMMAND_STRIKESINFO_DESCRIPTION("Get a faction's strikes"),
|
COMMAND_STRIKESINFO_DESCRIPTION("Get a faction's strikes"),
|
||||||
|
|
||||||
SHOP_NOT_ENOUGH_POINTS("&c&l[!] &7Your faction does not have enough points to purchase this!"),
|
SHOP_NOT_ENOUGH_POINTS("&c&l[!] &7Your faction does not have enough points to purchase this!"),
|
||||||
|
SHOP_ERROR_DURING_PURCHASE("&c&l[!] &7There was an error while trying to give items please check your inventory! Purchase was not completed!"),
|
||||||
SHOP_BOUGHT_BROADCAST_FACTION("\n&c&l[!] &e&lFactionShop » &b{player} &7bought &b{item}&7 for &b{cost} &7points!\n"),
|
SHOP_BOUGHT_BROADCAST_FACTION("\n&c&l[!] &e&lFactionShop » &b{player} &7bought &b{item}&7 for &b{cost} &7points!\n"),
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user