Shop GUI Cleaned up :D
This commit is contained in:
parent
c0a9eeca87
commit
bd4e6cb6a8
@ -16,7 +16,6 @@ import com.massivecraft.factions.integration.Worldguard;
|
|||||||
import com.massivecraft.factions.integration.dynmap.EngineDynmap;
|
import com.massivecraft.factions.integration.dynmap.EngineDynmap;
|
||||||
import com.massivecraft.factions.listeners.*;
|
import com.massivecraft.factions.listeners.*;
|
||||||
import com.massivecraft.factions.missions.MissionHandler;
|
import com.massivecraft.factions.missions.MissionHandler;
|
||||||
import com.massivecraft.factions.shop.ShopClickPersistence;
|
|
||||||
import com.massivecraft.factions.shop.ShopConfig;
|
import com.massivecraft.factions.shop.ShopConfig;
|
||||||
import com.massivecraft.factions.struct.ChatMode;
|
import com.massivecraft.factions.struct.ChatMode;
|
||||||
import com.massivecraft.factions.struct.Relation;
|
import com.massivecraft.factions.struct.Relation;
|
||||||
@ -267,7 +266,6 @@ public class FactionsPlugin extends MPlugin {
|
|||||||
new FactionsExploitListener(),
|
new FactionsExploitListener(),
|
||||||
new FactionsBlockListener(),
|
new FactionsBlockListener(),
|
||||||
new FUpgradesGUI(),
|
new FUpgradesGUI(),
|
||||||
new ShopClickPersistence(),
|
|
||||||
new UpgradesListener(),
|
new UpgradesListener(),
|
||||||
new MissionHandler(this),
|
new MissionHandler(this),
|
||||||
new ChestLogsHandler()
|
new ChestLogsHandler()
|
||||||
|
@ -24,7 +24,7 @@ public class CmdShop extends FCommand {
|
|||||||
if (!FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled")) {
|
if (!FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ShopGUI.openShop(context.fPlayer);
|
new ShopGUIFrame(context.faction).buildGUI(context.fPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,93 +0,0 @@
|
|||||||
package com.massivecraft.factions.shop;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.FPlayer;
|
|
||||||
import com.massivecraft.factions.FPlayers;
|
|
||||||
import com.massivecraft.factions.FactionsPlugin;
|
|
||||||
import com.massivecraft.factions.zcore.util.TL;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ShopClickPersistence implements Listener {
|
|
||||||
|
|
||||||
public static String color(String line) {
|
|
||||||
line = ChatColor.translateAlternateColorCodes('&', line);
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> colorList(List<String> lore) {
|
|
||||||
for (int i = 0; i <= lore.size() - 1; i++) {
|
|
||||||
lore.set(i, color(lore.get(i)));
|
|
||||||
}
|
|
||||||
return lore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void runCommands(List<String> list, Player p) {
|
|
||||||
for (String cmd : list) {
|
|
||||||
cmd = cmd.replace("%player%", p.getName());
|
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void click(InventoryClickEvent e) {
|
|
||||||
Inventory i = e.getClickedInventory();
|
|
||||||
Player p = (Player) e.getWhoClicked();
|
|
||||||
FileConfiguration config = FactionsPlugin.getInstance().getConfig();
|
|
||||||
FPlayer fplayer = FPlayers.getInstance().getByPlayer(p);
|
|
||||||
|
|
||||||
if (e.getView().getTitle().equalsIgnoreCase(color(config.getString("F-Shop.GUI.Name")))) {
|
|
||||||
ItemStack item = e.getCurrentItem();
|
|
||||||
if (item == null) return;
|
|
||||||
String name = color(item.getItemMeta().getDisplayName());
|
|
||||||
e.setCancelled(true);
|
|
||||||
int t = e.getSlot();
|
|
||||||
int items = ShopConfig.getShop().getConfigurationSection("items").getKeys(false).size();
|
|
||||||
for (int a = 1; a <= items; a++) {
|
|
||||||
String s = a + "";
|
|
||||||
int slot = ShopConfig.getShop().getInt("items." + s + ".slot");
|
|
||||||
if (t == slot) {
|
|
||||||
String n = ShopConfig.getShop().getString("items." + s + ".name");
|
|
||||||
if (name.contains(color(n))) {
|
|
||||||
String c = ChatColor.stripColor(color(name));
|
|
||||||
c = c.replace(ChatColor.stripColor(color(n)), "");
|
|
||||||
c = c.replace(color(" ("), "");
|
|
||||||
c = c.replace(color(" Points)"), "");
|
|
||||||
int cost = Integer.parseInt(c);
|
|
||||||
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()) {
|
|
||||||
// if (fplayer == fme) { continue; } //Idk if I wanna not send the title to the player
|
|
||||||
fplayerBuy.getPlayer().sendMessage(TL.SHOP_BOUGHT_BROADCAST_FACTION.toString()
|
|
||||||
.replace("{player}", fplayer.getPlayer().getName())
|
|
||||||
.replace("{item}", name));
|
|
||||||
}
|
|
||||||
fplayer.sendMessage(color(ShopConfig.getShop().getString("prefix").replace("%item%", n).replace("%points%", cost + "")));
|
|
||||||
p.closeInventory();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
fplayer.sendMessage(TL.SHOP_NOT_ENOUGH_POINTS.toString());
|
|
||||||
p.closeInventory();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
e.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,100 +0,0 @@
|
|||||||
package com.massivecraft.factions.shop;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.FPlayer;
|
|
||||||
import com.massivecraft.factions.Faction;
|
|
||||||
import com.massivecraft.factions.FactionsPlugin;
|
|
||||||
import com.massivecraft.factions.util.XMaterial;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemFlag;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ShopGUI {
|
|
||||||
/*
|
|
||||||
TODO: OOP Shop, and Clean it Up.
|
|
||||||
Made simplistic format for shop for the time being until I get time.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static void openShop(FPlayer p) {
|
|
||||||
FileConfiguration config = FactionsPlugin.getInstance().getConfig();
|
|
||||||
Faction fac = p.getFaction();
|
|
||||||
|
|
||||||
Inventory i = Bukkit.createInventory(null, FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Size"), color(config.getString("F-Shop.GUI.Name")));
|
|
||||||
ItemStack glass = new ItemStack(XMaterial.BLACK_STAINED_GLASS_PANE.parseMaterial(), 1, (short) 7);
|
|
||||||
ItemMeta glassmeta = glass.getItemMeta();
|
|
||||||
glassmeta.setDisplayName(ChatColor.GOLD + " ");
|
|
||||||
glass.setItemMeta(glassmeta);
|
|
||||||
|
|
||||||
for (int fill = 0; fill < FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Size"); ++fill) {
|
|
||||||
i.setItem(fill, glass);
|
|
||||||
}
|
|
||||||
|
|
||||||
int items = ShopConfig.getShop().getConfigurationSection("items").getKeys(false).size();
|
|
||||||
for (int shopitems = 1; shopitems <= items; shopitems++) {
|
|
||||||
String s = shopitems + "";
|
|
||||||
int slot = ShopConfig.getShop().getInt("items." + s + ".slot");
|
|
||||||
ItemStack material = XMaterial.matchXMaterial(ShopConfig.getShop().getString("items." + s + ".block")).parseItem();
|
|
||||||
// int size = ShopConfig.getShop().getInt("items." + s + ".size");
|
|
||||||
int cost = ShopConfig.getShop().getInt("items." + s + ".cost");
|
|
||||||
String name = ShopConfig.getShop().getString("items." + s + ".name") + " &f(" + cost + " Points)";
|
|
||||||
List<String> lore = ShopConfig.getShop().getStringList("items." + s + ".lore");
|
|
||||||
String command = ShopConfig.getShop().getString("items." + s + ".cmd");
|
|
||||||
String type = ShopConfig.getShop().getString("items." + s + ".type");
|
|
||||||
boolean glowing = ShopConfig.getShop().getBoolean("items." + s + ".glowing");
|
|
||||||
|
|
||||||
|
|
||||||
ItemStack count = new ItemStack(XMaterial.PAPER.parseMaterial(), 1);
|
|
||||||
ItemMeta countmeta = count.getItemMeta();
|
|
||||||
countmeta.setDisplayName(color(config.getString("F-Shop.GUI.Information.name")));
|
|
||||||
List<String> PointInfo = new LinkedList<>();
|
|
||||||
for (String list : config.getStringList("F-Shop.GUI.Information.lore")) {
|
|
||||||
PointInfo.add(list.replace("%points%", fac.getPoints() + ""));
|
|
||||||
}
|
|
||||||
countmeta.setLore(colorList(PointInfo));
|
|
||||||
count.setItemMeta(countmeta);
|
|
||||||
i.setItem(FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Information.slot"), count);
|
|
||||||
|
|
||||||
ItemStack item = new ItemStack(material);
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
meta.setDisplayName(color(name));
|
|
||||||
meta.addItemFlags();
|
|
||||||
|
|
||||||
if (glowing) {
|
|
||||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
|
||||||
meta.addEnchant(Enchantment.DURABILITY, 1, true);
|
|
||||||
}
|
|
||||||
if (!glowing) {
|
|
||||||
meta.removeEnchant(Enchantment.DURABILITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lore.contains("")) {
|
|
||||||
meta.setLore(null);
|
|
||||||
} else {
|
|
||||||
meta.setLore(FactionsPlugin.getInstance().colorList(lore));
|
|
||||||
}
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
i.setItem(slot, item);
|
|
||||||
}
|
|
||||||
p.getPlayer().openInventory(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String color(String line) {
|
|
||||||
line = ChatColor.translateAlternateColorCodes('&', line);
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> colorList(List<String> lore) {
|
|
||||||
for (int i = 0; i <= lore.size() - 1; i++) {
|
|
||||||
lore.set(i, color(lore.get(i)));
|
|
||||||
}
|
|
||||||
return lore;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
115
src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java
Normal file
115
src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
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.massivecraft.factions.FPlayer;
|
||||||
|
import com.massivecraft.factions.FPlayers;
|
||||||
|
import com.massivecraft.factions.Faction;
|
||||||
|
import com.massivecraft.factions.FactionsPlugin;
|
||||||
|
import com.massivecraft.factions.util.XMaterial;
|
||||||
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ShopGUIFrame {
|
||||||
|
|
||||||
|
private Gui gui;
|
||||||
|
|
||||||
|
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")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buildGUI(FPlayer fplayer) {
|
||||||
|
PaginatedPane pane = new PaginatedPane(0, 0, 9, gui.getRows());
|
||||||
|
List<GuiItem> GUIItems = new ArrayList<>();
|
||||||
|
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 = 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");
|
||||||
|
int slot = ShopConfig.getShop().getInt("items." + s + ".slot");
|
||||||
|
|
||||||
|
GUIItems.set(slot, new GuiItem(buildShopAssets(fplayer.getFaction()), 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 + ""));
|
||||||
|
}
|
||||||
|
buildGUI(fme);
|
||||||
|
} else {
|
||||||
|
fplayer.msg(TL.SHOP_NOT_ENOUGH_POINTS);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
pane.populateWithGuiItems(GUIItems);
|
||||||
|
gui.addPane(pane);
|
||||||
|
gui.update();
|
||||||
|
gui.show(fplayer.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runCommands(List<String> list, Player p) {
|
||||||
|
for (String cmd : list) {
|
||||||
|
cmd = cmd.replace("%player%", p.getName());
|
||||||
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -721,7 +721,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_BOUGHT_BROADCAST_FACTION("\n&c&l[!] &e&lFactionShop » &b{player} &7bought &b{item}&7!\n"),
|
SHOP_BOUGHT_BROADCAST_FACTION("\n&c&l[!] &e&lFactionShop » &b{player} &7bought &b{item}&7 for &b{cost} &7points!\n"),
|
||||||
|
|
||||||
|
|
||||||
COMMAND_VIEWCHEST_DESCRIPTION("view a factions chest/pv"),
|
COMMAND_VIEWCHEST_DESCRIPTION("view a factions chest/pv"),
|
||||||
|
@ -683,15 +683,12 @@ F-Shop:
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
GUI:
|
GUI:
|
||||||
Name: '&b&lFaction Shop'
|
Name: '&b&lFaction Shop'
|
||||||
Size: 36
|
Rows: 4
|
||||||
Information:
|
dummy-item:
|
||||||
name: '&b&lInformation'
|
Type: BLACK_STAINED_GLASS_PANE
|
||||||
lore:
|
Name: '&cFaction Points: &b{points}'
|
||||||
- '&bPoints &7are gained by capturing koths/conquests.'
|
Lore:
|
||||||
- ''
|
- ' '
|
||||||
- '&b&l[!] &bFaction Points: &f%points%'
|
|
||||||
slot: 22
|
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# +------------------------------------------------------+ #
|
# +------------------------------------------------------+ #
|
||||||
# | Faction Command Cooldowns | #
|
# | Faction Command Cooldowns | #
|
||||||
|
Loading…
Reference in New Issue
Block a user