F-Shop Added (Simplistic Version)
This commit is contained in:
parent
bee0bff504
commit
1b02bd89d4
@ -10,6 +10,8 @@ import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.integration.Worldguard;
|
||||
import com.massivecraft.factions.integration.dynmap.EngineDynmap;
|
||||
import com.massivecraft.factions.listeners.*;
|
||||
import com.massivecraft.factions.shop.ShopClickPersistence;
|
||||
import com.massivecraft.factions.shop.ShopConfig;
|
||||
import com.massivecraft.factions.struct.ChatMode;
|
||||
import com.massivecraft.factions.struct.Placeholder;
|
||||
import com.massivecraft.factions.util.*;
|
||||
@ -230,6 +232,8 @@ public class P extends MPlugin {
|
||||
log("Skript addon registered!");
|
||||
}
|
||||
|
||||
ShopConfig.setup();
|
||||
|
||||
getServer().getPluginManager().registerEvents(factionsPlayerListener = new FactionsPlayerListener(), this);
|
||||
|
||||
// Register Event Handlers
|
||||
@ -242,6 +246,7 @@ public class P extends MPlugin {
|
||||
new EXPUpgrade(),
|
||||
new CropUpgrades(),
|
||||
new RedstoneUpgrade(),
|
||||
new ShopClickPersistence(),
|
||||
new SpawnerUpgrades()
|
||||
};
|
||||
|
||||
|
@ -13,6 +13,7 @@ import com.massivecraft.factions.cmd.relational.CmdRelationNeutral;
|
||||
import com.massivecraft.factions.cmd.relational.CmdRelationTruce;
|
||||
import com.massivecraft.factions.cmd.roles.CmdDemote;
|
||||
import com.massivecraft.factions.cmd.roles.CmdPromote;
|
||||
import com.massivecraft.factions.shop.CmdShop;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@ -127,6 +128,7 @@ public class FCmdRoot extends FCommand {
|
||||
public CmdPoints cmdPoints = new CmdPoints();
|
||||
public CmdLogout cmdLogout = new CmdLogout();
|
||||
public CmdNotifications cmdNotifications = new CmdNotifications();
|
||||
public CmdShop cmdShop = new CmdShop();
|
||||
|
||||
|
||||
|
||||
@ -248,6 +250,10 @@ public class FCmdRoot extends FCommand {
|
||||
this.addSubCommand(this.cmdFGlobal);
|
||||
this.addSubCommand(this.cmdViewChest);
|
||||
|
||||
if(P.p.getConfig().getBoolean("F-Shop.Enabled")){
|
||||
this.addSubCommand(this.cmdShop);
|
||||
}
|
||||
|
||||
if (P.p.getConfig().getBoolean("f-inventory-see.Enabled")) {
|
||||
this.addSubCommand(this.cmdInventorySee);
|
||||
}
|
||||
|
36
src/main/java/com/massivecraft/factions/shop/CmdShop.java
Normal file
36
src/main/java/com/massivecraft/factions/shop/CmdShop.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.massivecraft.factions.shop;
|
||||
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.logout.CmdLogout;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
|
||||
public class CmdShop extends FCommand {
|
||||
|
||||
public CmdShop(){
|
||||
super();
|
||||
this.aliases.add("shop");
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = false;
|
||||
senderMustBeColeader = false;
|
||||
senderMustBeAdmin = false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if(!P.p.getConfig().getBoolean("F-Shop.Enabled")){
|
||||
return;
|
||||
}
|
||||
ShopGUI.openShop(fme);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.massivecraft.factions.shop;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.P;
|
||||
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 void runCommands(List<String> list, Player p) {
|
||||
for (int a = 0; a < list.size(); a++) {
|
||||
String cmd = list.get(a);
|
||||
cmd = cmd.replace("%player%", p.getName());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void click(InventoryClickEvent e) {
|
||||
Inventory i = e.getClickedInventory();
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
FileConfiguration config = P.p.getConfig();
|
||||
FPlayer fplayer = FPlayers.getInstance().getByPlayer(p);
|
||||
|
||||
if (e.getView().getTitle().equalsIgnoreCase(color(config.getString("F-Shop.GUI.Name")))) {
|
||||
ItemStack item = e.getCurrentItem();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
53
src/main/java/com/massivecraft/factions/shop/ShopConfig.java
Normal file
53
src/main/java/com/massivecraft/factions/shop/ShopConfig.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.massivecraft.factions.shop;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ShopConfig {
|
||||
|
||||
//TODO: Shop YAML Converter mySQL
|
||||
|
||||
public static File shop = new File("plugins/Factions/shop.yml");
|
||||
public static FileConfiguration s = YamlConfiguration.loadConfiguration(shop);
|
||||
public static FileConfiguration getShop() {
|
||||
return s;
|
||||
}
|
||||
public static void loadShop() {
|
||||
s = YamlConfiguration.loadConfiguration(shop);
|
||||
}
|
||||
|
||||
public static void saveShop() {
|
||||
try {
|
||||
getShop().save(shop);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
if (!shop.exists()) {
|
||||
try {
|
||||
shop.createNewFile();
|
||||
getShop().set("prefix", "&4&lFactionShop&8» &7Purchased &f%item% &7for &b%points% Points&7!");
|
||||
getShop().set("items.1.slot", 1);
|
||||
getShop().set("items.1.block", "STONE");
|
||||
getShop().set("items.1.name", "&aTest Shop");
|
||||
ArrayList lore = new ArrayList();
|
||||
lore.add("&cFully Customizable Lore!");
|
||||
getShop().set("items.1.lore", lore);
|
||||
ArrayList t = new ArrayList();
|
||||
t.add("broadcast %player% bought Test Shop!");
|
||||
getShop().set("items.1.cmds", t);
|
||||
getShop().set("items.1.cost", 5);
|
||||
getShop().set("items.1.glowing", true);
|
||||
saveShop();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
101
src/main/java/com/massivecraft/factions/shop/ShopGUI.java
Normal file
101
src/main/java/com/massivecraft/factions/shop/ShopGUI.java
Normal file
@ -0,0 +1,101 @@
|
||||
package com.massivecraft.factions.shop;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.util.XMaterial;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
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 = P.p.getConfig();
|
||||
Faction fac = p.getFaction();
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, P.p.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 < P.p.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(P.p.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(P.p.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;
|
||||
}
|
||||
|
||||
}
|
@ -673,6 +673,9 @@ public enum TL {
|
||||
COMMAND_STRIKE_NOTFOUND("&c&l[!] &7{faction} does not exist."),
|
||||
COMMAND_STRIKE_NEEDFACTION("&c&l[!] &7&cYou need to join a faction to view your own!"),
|
||||
|
||||
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"),
|
||||
|
||||
COMMAND_STRIKEGIVE_DESCRIPTION("Give a faction strikes"),
|
||||
|
||||
COMMAND_VIEWCHEST_DESCRIPTION("view a factions chest/pv"),
|
||||
|
@ -771,6 +771,24 @@ fnear:
|
||||
Enabled: true
|
||||
Radius: 50
|
||||
|
||||
############################################################
|
||||
# +------------------------------------------------------+ #
|
||||
# | Faction Shop | #
|
||||
# +------------------------------------------------------+ #
|
||||
############################################################
|
||||
F-Shop:
|
||||
Enabled: true
|
||||
GUI:
|
||||
Name: '&b&lFaction Shop'
|
||||
Size: 36
|
||||
Information:
|
||||
name: '&b&lInformation'
|
||||
lore:
|
||||
- '&bPoints &7are gained by capturing koths/conquests.'
|
||||
- ''
|
||||
- '&b&l[!] &bFaction Points: &f%points%'
|
||||
slot: 22
|
||||
|
||||
############################################################
|
||||
# +------------------------------------------------------+ #
|
||||
# | Faction Command Cooldowns | #
|
||||
@ -1118,24 +1136,6 @@ fupgrades:
|
||||
slots:
|
||||
- 22
|
||||
|
||||
############################################################
|
||||
# +------------------------------------------------------+ #
|
||||
# | Faction Shop | #
|
||||
# +------------------------------------------------------+ #
|
||||
############################################################
|
||||
F-Shop:
|
||||
Gui-Title: '&c&lFaction Shop'
|
||||
|
||||
BackButtonSlot: 0
|
||||
BackButton:
|
||||
Material: "ARROW"
|
||||
Name: "&8<< Back"
|
||||
|
||||
PointsSlot: 4
|
||||
PointsItem:
|
||||
Material: "PAPER"
|
||||
Name: "&dYour Faction has &f&n%points% Points"
|
||||
|
||||
#Potions Shop#
|
||||
PotionGUISize: 3
|
||||
PotionsLastHours: 6
|
||||
|
Loading…
Reference in New Issue
Block a user